1 // This is core/vgui/vgui_dialog.h 2 #ifndef vgui_dialog_h_ 3 #define vgui_dialog_h_ 4 //: 5 // \file 6 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford 7 // \date 23 Oct 1999 8 // \brief Abstract dialog class. 9 // 10 // \verbatim 11 // Modifications 12 // 23-OCT-1999 P.Pritchett - Initial version. 13 // 25-JAN-2000 K.Y.McGaul - Added message() to allow text messages in dialogs. 14 // 27-JAN-2000 K.Y.McGaul - Added set_modal() to allow non-modal dialogs. 15 // 24-FEB-2000 K.Y.McGaul - Added file browser and color chooser. 16 // 11-JUL-2000 Marko Bacic - Added inline file browser 17 // 12-JUL-2000 Marko Bacic - Added inline color chooser 18 // 26-APR-2002 K.Y.McGaul - Converted to doxygen style comments. 19 // 02-JAN-2010 Lianqing Yu - Added controls including push button. 20 // \endverbatim 21 22 #include <string> 23 #include <vector> 24 #ifdef _MSC_VER 25 # include <vcl_msvc_warnings.h> 26 #endif 27 #include "vgui_tableau.h" 28 #include "vgui_command_sptr.h" 29 30 class vgui_dialog_impl; 31 32 //: Abstract dialog class 33 // 34 // vgui_dialog allows the user to build a dialog from a collection of fields. 35 // A field in this context consists of a std::string label and a variable. 36 // The dialog is then posted using the ask() method. If ask returns true then 37 // any changes to the fields in the dialog are used to update the variables. 38 // Each vgui_dialog contains an instance of a concrete subclass of 39 // vgui_dialog_impl. The type of the subclass will be determined by the GUI 40 // being used. 41 // 42 // \par Example 43 // \code 44 // vgui_dialog params("My params"); 45 // params.field("Table number", the_table); 46 // params.choice("Dressing", "French", "Thousand Island", the_dressing); 47 // params.checkbox("Mayo?", has_mayo); 48 // params.message("No smoking is allowed in the restaurant!"); 49 // if (!params.ask()) 50 // return; // cancelled 51 // send_order(the_table, the_dressing, has_mayo); 52 // \endcode 53 54 typedef void (*vgui_dialog_callback)(void const* client_data); 55 typedef void (*vgui_dialog_callback_no_client_data)(); 56 57 class vgui_dialog 58 { 59 public: 60 61 //: Constructor - takes the title of the dialog box. 62 vgui_dialog(const char* name); 63 virtual ~vgui_dialog(); 64 65 // A push button is oftern shown with a label and/or a icon/bitmap 66 // and a command is executed when the button is clicked. 67 void pushbutton(vgui_command_sptr cmnd, const char *label, const void* icon); 68 void pushbutton(vgui_dialog_callback_no_client_data f, const char *label, const void* icon); 69 void pushbutton(vgui_dialog_callback f, void const *client_data, const char *label, const void* icon); 70 71 void checkbox(const char*, bool&); 72 73 void field(const char*, int&); field(const char * c,unsigned int & v)74 void field(const char* c, unsigned int& v) { field(c,*reinterpret_cast<int*>(&v)); } 75 void field(const char*, long&); 76 void field(const char*, float&); 77 void field(const char*, double&); 78 void field(const char*, std::string&); 79 80 //: Multiple choice - with two options. 81 void choice(const char* label, const char* option1, 82 const char* option2, int& chosen); 83 84 //: Multiple choice - with three options. 85 void choice(const char* label, const char* option1, 86 const char* option2, const char* option3, int& chosen); 87 88 //: Multiple choice - with the list of options given. 89 void choice(const char*, const std::vector<std::string>&, int &); 90 choice(const char * s,const std::vector<std::string> & v,unsigned & r)91 void choice(const char*s, const std::vector<std::string>&v, unsigned &r) 92 { choice(s,v,*reinterpret_cast<int*>(&r)); } 93 94 //: File browsers 95 void file (const char* label, std::string& regexp, std::string& filepath); 96 97 //: inline file browser 98 void inline_file(const char* label, std::string& regexp,std::string& filepath); 99 100 //: Color chooser 101 void color (const char* label, std::string&); 102 103 //: Inline color chooser 104 void inline_color(const char *label, std::string &); 105 106 //: Text message 107 void message(const char*); 108 109 void line_break(); 110 111 //: Display a tableau in the dialog 112 void inline_tableau(const vgui_tableau_sptr tab, unsigned width, 113 unsigned height); 114 115 //: Set the labels on each button, if 0 that button does not appear. 116 void set_cancel_button(const char* label); 117 118 //: Set the labels on each button, if 0 that button does not appear. 119 void set_ok_button(const char* label); 120 121 //: A "modal" dialog captures all events sent to the application. 122 void set_modal(const bool); 123 124 //: Display the dialog box and wait for the users response. 125 // Returns true if the user clicks on the 'OK' button and false if the 126 // user clicks on the 'Cancel' button. 127 bool ask(); 128 129 protected: vgui_dialog()130 vgui_dialog() {} 131 vgui_dialog_impl* impl; 132 }; 133 134 #endif // vgui_dialog_h_ 135