core/vgui/vgui_dialog.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_dialog.h
00002 #ifndef vgui_dialog_h_
00003 #define vgui_dialog_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00010 // \date   23 Oct 1999
00011 // \brief  Abstract dialog class.
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   23-OCT-1999 P.Pritchett - Initial version.
00016 //   25-JAN-2000 K.Y.McGaul - Added message() to allow text messages in dialogs.
00017 //   27-JAN-2000 K.Y.McGaul - Added set_modal() to allow non-modal dialogs.
00018 //   24-FEB-2000 K.Y.McGaul - Added file browser and color chooser.
00019 //   11-JUL-2000 Marko Bacic - Added inline file browser
00020 //   12-JUL-2000 Marko Bacic - Added inline color chooser
00021 //   26-APR-2002 K.Y.McGaul - Converted to doxygen style comments.
00022 //   02-JAN-2010 Lianqing Yu - Added controls including push button.
00023 // \endverbatim
00024 
00025 #include <vcl_string.h>
00026 #include <vcl_vector.h>
00027 #include <vgui/vgui_tableau.h>
00028 #include <vgui/vgui_command_sptr.h>
00029 
00030 class vgui_dialog_impl;
00031 
00032 //: Abstract dialog class
00033 //
00034 // vgui_dialog allows the user to build a dialog from a collection of fields.
00035 // A field in this context consists of a vcl_string label and a variable.
00036 // The dialog is then posted using the ask() method. If ask returns true then
00037 // any changes to the fields in the dialog are used to update the variables.
00038 // Each vgui_dialog contains an instance of a concrete subclass of
00039 // vgui_dialog_impl. The type of the subclass will be determined by the GUI
00040 // being used.
00041 //
00042 // \par Example
00043 // \code
00044 //   vgui_dialog params("My params");
00045 //   params.field("Table number", the_table);
00046 //   params.choice("Dressing", "French", "Thousand Island", the_dressing);
00047 //   params.checkbox("Mayo?", has_mayo);
00048 //   params.message("No smoking is allowed in the restaurant!");
00049 //   if (!params.ask())
00050 //     return; // cancelled
00051 //   send_order(the_table, the_dressing, has_mayo);
00052 // \endcode
00053 
00054 typedef void (*vgui_dialog_callback)(void const* client_data);
00055 typedef void (*vgui_dialog_callback_no_client_data)();
00056 
00057 class vgui_dialog
00058 {
00059  public:
00060 
00061   //: Constructor - takes the title of the dialog box.
00062   vgui_dialog(const char* name);
00063   virtual ~vgui_dialog();
00064 
00065   // A push button is oftern shown with a label and/or a icon/bitmap
00066   // and a command is executed when the button is clicked.
00067   void pushbutton(vgui_command_sptr cmnd, const char *label, const void* icon);
00068   void pushbutton(vgui_dialog_callback_no_client_data f, const char *label, const void* icon);
00069   void pushbutton(vgui_dialog_callback f, void const *client_data, const char *label, const void* icon);
00070 
00071   void checkbox(const char*, bool&);
00072 
00073   void field(const char*, int&);
00074   void field(const char* c, unsigned int& v) { field(c,*reinterpret_cast<int*>(&v)); }
00075   void field(const char*, long&);
00076   void field(const char*, float&);
00077   void field(const char*, double&);
00078   void field(const char*, vcl_string&);
00079 
00080   //: Multiple choice - with two options.
00081   void choice(const char* label, const char* option1,
00082               const char* option2, int& chosen);
00083 
00084   //: Multiple choice - with three options.
00085   void choice(const char* label, const char* option1,
00086               const char* option2, const char* option3, int& chosen);
00087 
00088   //: Multiple choice - with the list of options given.
00089   void choice(const char*, const vcl_vector<vcl_string>&, int &);
00090 
00091   void choice(const char*s, const vcl_vector<vcl_string>&v, unsigned &r)
00092   { choice(s,v,*reinterpret_cast<int*>(&r)); }
00093 
00094   //: File browsers
00095   void file (const char* label, vcl_string& regexp, vcl_string& filepath);
00096 
00097   //: inline file browser
00098   void inline_file(const char* label, vcl_string& regexp,vcl_string& filepath);
00099 
00100   //: Color chooser
00101   void color (const char* label, vcl_string&);
00102 
00103   //: Inline color chooser
00104   void inline_color(const char *label, vcl_string &);
00105 
00106   //: Text message
00107   void message(const char*);
00108 
00109   void line_break();
00110 
00111   //: Display a tableau in the dialog
00112   void inline_tableau(const vgui_tableau_sptr tab, unsigned width,
00113                       unsigned height);
00114 
00115   //: Set the labels on each button, if 0 that button does not appear.
00116   void set_cancel_button(const char* label);
00117 
00118   //: Set the labels on each button, if 0 that button does not appear.
00119   void set_ok_button(const char* label);
00120 
00121   //: A "modal" dialog captures all events sent to the application.
00122   void set_modal(const bool);
00123 
00124   //: Display the dialog box and wait for the users response.
00125   //  Returns true if the user clicks on the 'OK' button and false if the
00126   //  user clicks on the 'Cancel' button.
00127   bool ask();
00128 
00129  protected:
00130   vgui_dialog() {}
00131   vgui_dialog_impl* impl;
00132 };
00133 
00134 #endif // vgui_dialog_h_