core/vgui/internals/vgui_dialog_impl.h
Go to the documentation of this file.
00001 // This is core/vgui/internals/vgui_dialog_impl.h
00002 #ifndef vgui_dialog_impl_h_
00003 #define vgui_dialog_impl_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief vgui_dialog_impl is the abstract base class for dialog implementation.
00010 // \author Philip C. Pritchett, RRG, University of Oxford
00011 // \date   25 Oct 99
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   K.Y.McGaul  25-JAN-2000  Moved field functions to this class to save repetition.
00016 //                            Added virtual ..._widget functions.
00017 //                            Added text_message function.
00018 //   K.Y.McGaul  27-JAN-2000  Added modal function.
00019 //   Marko Bacic 11-JUL-2000  Added support for inline file browser
00020 //   Marko Bacic 12-JUL-2000  Added support for inline color chooser
00021 //   Joris Sch.  09-NOV-2000  Fixed weird color browser things
00022 //   K.Y.McGaul  22-MAY-2001  Added tableau field.
00023 //   Lianqing Yu 02-JAN-2010  Added push button.
00024 // \endverbatim
00025 
00026 #include <vcl_string.h>
00027 #include <vcl_vector.h>
00028 #include <vgui/vgui_tableau.h>
00029 #include <vgui/vgui_command_sptr.h>
00030 
00031 class vgui_dialog_field;
00032 
00033 //: vgui_dialog_impl is the abstract base class for dialog implementation.
00034 //
00035 //  It contains methods for adding fields corresponding to those in
00036 //  vgui_dialog. It also contains a vcl_vector of elements which are tuples of
00037 //  vgui_dialog_field and a variable indicating what type of field they are. The
00038 //  elements also contain void* for implementors to add any gui specific
00039 //  information/class to the element.
00040 class vgui_dialog_impl
00041 {
00042  public:
00043   //: Constructor - create an empty dialog with the given title.
00044   vgui_dialog_impl(const char* dialog_name);
00045 
00046   //: Destructor - delete this dialog box.
00047   virtual ~vgui_dialog_impl();
00048 
00049   //: Add a boolean field to the dialog box.
00050   void bool_field(const char*, bool&);
00051 
00052   //: Add an integer field to the dialog box.
00053   void int_field(const char*, int&);
00054 
00055   //: Add a long integer field to the dialog box.
00056   void long_field(const char*, long&);
00057 
00058   //: Add a float field to the dialog box.
00059   void float_field(const char*, float&);
00060 
00061   //: Add a double field to the dialog box.
00062   void double_field(const char*, double&);
00063 
00064   //: Add a vcl_string field to the dialog box.
00065   void string_field(const char*, vcl_string&);
00066 
00067   //: Add a choice (selection box) to the dialog box.
00068   void choice_field(const char*, const vcl_vector<vcl_string>&, int&);
00069 
00070   //: Add a text message to the dialog box.
00071   void text_message(const char*);
00072 
00073   //: Add a popup file browser to the dialog box.
00074   void file_browser(const char*, vcl_string&, vcl_string&);
00075 
00076   //: Add an inline file browser to the dialog box.
00077   void inline_file_browser(const char *, vcl_string&, vcl_string&);
00078 
00079   //: Add a popup colour chooser to the dialog box.
00080   void color_chooser(const char*, vcl_string&);
00081 
00082   //: Add an inline colour chooser to the dialog box.
00083   void inline_color_chooser(const char*, vcl_string&);
00084 
00085   //: Add a tableau (OpenGL area) to the dialog box.
00086   void inline_tab(const vgui_tableau_sptr tab, unsigned width, unsigned height);
00087 
00088   //: Add a line break to the dialog box
00089   void line_break();
00090 
00091   //: Add a push button field to the dialog box.
00092   void pushbutton_field(vgui_command_sptr cmnd, const char* label, const void* icon);
00093 
00094   //: Pointer to a GUI widget for a bool field.
00095   virtual void* bool_field_widget(const char*, bool&);
00096 
00097   //: Pointer to a GUI widget for an integer field.
00098   virtual void* int_field_widget(const char*, int&);
00099 
00100   //: Pointer to a GUI widget for a long integer field.
00101   virtual void* long_field_widget(const char*, long&);
00102 
00103   //: Pointer to a GUI widget for a float field.
00104   virtual void* float_field_widget(const char*, float&);
00105 
00106   //: Pointer to a GUI widget for a double field.
00107   virtual void* double_field_widget(const char*, double&);
00108 
00109   //: Pointer to a GUI widget for a string field.
00110   virtual void* string_field_widget(const char*, vcl_string&);
00111 
00112   //: Pointer to a GUI widget for a choice field.
00113   virtual void* choice_field_widget(const char*, const vcl_vector<vcl_string>&, int&);
00114 
00115   //: Pointer to a GUI widget for a text message.
00116   virtual void* text_message_widget(const char*);
00117 
00118   //: Pointer to a GUI widget for a file browser.
00119   virtual void* file_browser_widget(const char*, vcl_string&, vcl_string&);
00120 
00121   //: Pointer to a GUI widget for an inline file browser.
00122   virtual void* inline_file_browser_widget(const char *,vcl_string&, vcl_string&);
00123 
00124   //: Pointer to a GUI widget for a colour chooser.
00125   virtual void* color_chooser_widget(const char*, vcl_string&);
00126 
00127   //: Pointer to a GUI widget for an inline colour chooser.
00128   virtual void* inline_color_chooser_widget(const char *,vcl_string&);
00129 
00130   //: Pointer to a GUI widget for a tableau (OpenGL area).
00131   virtual void* inline_tableau_widget(const vgui_tableau_sptr tab, unsigned width, unsigned height);
00132 
00133   //: Pointer to a GUI widget for a push button.
00134   virtual void* pushbutton_field_widget(const char*, const void*);
00135 
00136   //: Set the modality of the dialog box.
00137   //  True makes the dialog modal (i.e. the dialog 'grabs' all events) and
00138   //  this is the default.  WARNING: It is dangerous to make a dialog that
00139   //  changes data non-modal, only messages should be non-modal.
00140   virtual void modal(bool);
00141 
00142   //: Set the text on the cancel button.
00143   virtual void set_cancel_button(const char* msg) { cancel_button_text_ = msg ? msg : ""; }
00144 
00145   //: Set the text on the OK button.
00146   virtual void set_ok_button(const char* msg) { ok_button_text_ = msg?msg:""; }
00147 
00148   //: Display the dialog box and collect data from the user.
00149   virtual bool ask() = 0;
00150 
00151   //: Enum of possible element types.
00152   enum element_type {bool_elem, int_elem, long_elem, float_elem,
00153                      double_elem, string_elem, choice_elem, text_msg,
00154                      file_bsr, color_csr,inline_file_bsr,inline_color_csr,
00155                      inline_tabl, dir_bsr, line_br, button_elem, unknown};
00156 
00157   //: Data associated with each field in the dialog box.
00158   //  The representation of a dialog box in vgui is simply as a list
00159   //  of these elements.
00160   struct element
00161   {
00162     //: What type of field this is (int, bool, file browser, etc)
00163     element_type type;
00164     //: A pointer to a GUI widget for this field, if one exists.
00165     //  This is null in most cases since it is easier to construct
00166     //  widgets as we need them, except perhaps for something
00167     //  complicated like a file browser or colour chooser. The GUI
00168     //  implementation is completely responsible for this pointer
00169     //  (i.e. ensuring memory deallocation when the dialog closes,
00170     //  etc.)
00171     void *widget;
00172     //: Field to collect data from the user.
00173     // The derived GUI implementation should not delete these.
00174     vgui_dialog_field *field;
00175 
00176     element() : type(unknown), widget(0), field(0) {}
00177   };
00178 
00179  protected:
00180   vcl_string name;
00181   vcl_vector<element> elements;
00182   vcl_string cancel_button_text_;
00183   vcl_string ok_button_text_;
00184 
00185   bool use_line_break;
00186 };
00187 
00188 #endif // vgui_dialog_impl_h_