core/vgui/internals/vgui_dialog_impl.cxx
Go to the documentation of this file.
00001 // This is core/vgui/internals/vgui_dialog_impl.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Philip C. Pritchett, RRG, University of Oxford
00008 // \date   25 Oct 1999
00009 // \brief  See vgui_dialog_impl.h for a description of this file
00010 
00011 #include "vgui_dialog_impl.h"
00012 #include <vcl_iostream.h>
00013 #include <vcl_cassert.h>
00014 #include <vgui/internals/vgui_simple_field.h>
00015 #include <vgui/internals/vgui_string_field.h>
00016 #include <vgui/internals/vgui_file_field.h>
00017 #include <vgui/internals/vgui_button_field.h>
00018 #include <vgui/vgui_tableau_sptr.h>
00019 
00020 vgui_dialog_impl::vgui_dialog_impl(const char* n)
00021   : name(n)
00022   , cancel_button_text_("Cancel")
00023   , ok_button_text_("OK")
00024   , use_line_break(false)
00025 {
00026   assert(n);
00027 }
00028 
00029 
00030 vgui_dialog_impl::~vgui_dialog_impl()
00031 {
00032   for (vcl_vector<element>::iterator iter = elements.begin();
00033        iter != elements.end(); ++iter)
00034   {
00035     delete iter->field;
00036   }
00037 }
00038 
00039 //------------------------------------------------------------------------------
00040 //: Add a boolean field to the dialog box.
00041 void vgui_dialog_impl::bool_field(const char* txt, bool& val)
00042 {
00043   vgui_bool_field *field = new vgui_bool_field(txt, val);
00044 
00045   element l;
00046   l.type = bool_elem;
00047   l.widget = bool_field_widget(txt, val);
00048   l.field = field;
00049 
00050   elements.push_back(l);
00051 }
00052 
00053 //------------------------------------------------------------------------------
00054 //: Add a push button field to the dialog box.
00055 void vgui_dialog_impl::pushbutton_field(vgui_command_sptr cmnd, const char* txt, const void* icon)
00056 {
00057   vgui_button_field *field = new vgui_button_field(cmnd, txt);
00058 
00059   element l;
00060   l.type = button_elem;
00061   l.widget = pushbutton_field_widget(txt, icon);
00062   l.field = field;
00063 
00064   elements.push_back(l);
00065 }
00066 
00067 //------------------------------------------------------------------------------
00068 //: Add an integer field to the dialog box.
00069 void vgui_dialog_impl::int_field(const char* txt, int& val)
00070 {
00071   vgui_int_field *field = new vgui_int_field(txt, val);
00072 
00073   element l;
00074   l.type = int_elem;
00075   l.widget = int_field_widget(txt, val);
00076   l.field = field;
00077 
00078   elements.push_back(l);
00079 }
00080 
00081 //------------------------------------------------------------------------------
00082 //: Add a long field to the dialog box.
00083 void vgui_dialog_impl::long_field(const char* txt, long& val)
00084 {
00085   vgui_long_field *field = new vgui_long_field(txt, val);
00086 
00087   element l;
00088   l.type = long_elem;
00089   l.widget = long_field_widget(txt, val);
00090   l.field = field;
00091 
00092   elements.push_back(l);
00093 }
00094 
00095 //------------------------------------------------------------------------------
00096 //: Add a float field to the dialog box.
00097 void vgui_dialog_impl::float_field(const char* txt, float& val)
00098 {
00099   vgui_float_field *field = new vgui_float_field(txt, val);
00100 
00101   element l;
00102   l.type = float_elem;
00103   l.widget = float_field_widget(txt, val);
00104   l.field = field;
00105 
00106   elements.push_back(l);
00107 }
00108 
00109 //------------------------------------------------------------------------------
00110 //: Add a double field to the dialog box.
00111 void vgui_dialog_impl::double_field(const char* txt, double& val)
00112 {
00113   vgui_double_field *field = new vgui_double_field(txt, val);
00114 
00115   element l;
00116   l.type = double_elem;
00117   l.widget = double_field_widget(txt, val);
00118   l.field = field;
00119 
00120   elements.push_back(l);
00121 }
00122 
00123 //------------------------------------------------------------------------------
00124 //: Add a vcl_string field to the dialog box.
00125 void vgui_dialog_impl::string_field(const char* txt, vcl_string& val)
00126 {
00127   vgui_string_field *field = new vgui_string_field(txt, val);
00128 
00129   element l;
00130   l.type = string_elem;
00131   l.widget = string_field_widget(txt, val);
00132   l.field = field;
00133 
00134   elements.push_back(l);
00135 }
00136 
00137 //------------------------------------------------------------------------------
00138 //: Add a choice field to the dialog box.
00139 void vgui_dialog_impl::choice_field(const char* txt,
00140                                     const vcl_vector<vcl_string>& labels, int& val)
00141 {
00142   vgui_int_field *field = new vgui_int_field(txt, val);
00143 
00144   element l;
00145   l.type = choice_elem;
00146   l.widget = choice_field_widget(txt, labels, val);
00147   l.field = field;
00148 
00149   elements.push_back(l);
00150 }
00151 
00152 void vgui_dialog_impl::file_browser(const char* txt, vcl_string& regexp, vcl_string& val)
00153 {
00154   vgui_file_field *field = new vgui_file_field(txt, regexp, val);
00155 
00156   element l;
00157   l.type = file_bsr;
00158   l.widget = file_browser_widget(txt, regexp, val);
00159   l.field = field;
00160 
00161   elements.push_back(l);
00162 }
00163 
00164 void vgui_dialog_impl::inline_file_browser(const char *txt,vcl_string & regexp,
00165                                            vcl_string& val)
00166 {
00167   vgui_file_field *field = new vgui_file_field(txt, regexp, val);
00168 
00169   element l;
00170   l.type = inline_file_bsr;
00171   l.widget = inline_file_browser_widget(txt, regexp, val);
00172   l.field = field;
00173 
00174   elements.push_back(l);
00175 }
00176 
00177 void vgui_dialog_impl::color_chooser(const char* txt, vcl_string& val)
00178 {
00179   vgui_string_field *field = new vgui_string_field(txt, val);
00180 
00181   element l;
00182   l.type = color_csr;
00183   l.widget = color_chooser_widget(txt, val);
00184   l.field = field;
00185 
00186   elements.push_back(l);
00187 }
00188 
00189 void vgui_dialog_impl::inline_color_chooser(const char* txt, vcl_string& val)
00190 {
00191   vgui_string_field *field = new vgui_string_field(txt, val);
00192 
00193   element l;
00194   l.type = inline_color_csr;
00195   l.widget = inline_color_chooser_widget(txt, val);
00196   l.field = field;
00197 
00198   elements.push_back(l);
00199 }
00200 
00201 void vgui_dialog_impl::inline_tab(const vgui_tableau_sptr tab, unsigned width,
00202                                   unsigned height)
00203 {
00204   // kym - don't use the field - store the tableau in the widget variable(?).
00205   // Since the OpenGL window in the inline tableau doesn't have any
00206   //variables, it doesn't make sense for it to have a field.
00207 
00208   element l;
00209   l.type = inline_tabl;
00210   l.widget = inline_tableau_widget(tab, width, height);
00211   l.field = 0;
00212 
00213   elements.push_back(l);
00214 }
00215 
00216 //------------------------------------------------------------------------------
00217 //: Add a text message to the dialog box.
00218 void vgui_dialog_impl::text_message(const char* txt)
00219 {
00220   int dummy_int = 0;
00221   vgui_int_field *field = new vgui_int_field(txt, dummy_int);
00222 
00223   element l;
00224   l.type = text_msg;
00225   l.widget = text_message_widget(txt);
00226   l.field = field;
00227 
00228   elements.push_back(l);
00229 }
00230 
00231 void vgui_dialog_impl::line_break()
00232 {
00233   element l;
00234   l.type = line_br;
00235 
00236   elements.push_back(l);
00237 }
00238 
00239 void* vgui_dialog_impl::bool_field_widget(const char*, bool&) { return 0; }
00240 void* vgui_dialog_impl::int_field_widget(const char*, int&) { return 0; }
00241 void* vgui_dialog_impl::long_field_widget(const char*, long&) { return 0; }
00242 void* vgui_dialog_impl::float_field_widget(const char*, float&) { return 0; }
00243 void* vgui_dialog_impl::double_field_widget(const char*, double&) { return 0; }
00244 void* vgui_dialog_impl::string_field_widget(const char*, vcl_string&) { return 0; }
00245 void* vgui_dialog_impl::choice_field_widget(const char*, const vcl_vector<vcl_string>&, int&) { return 0; }
00246 void* vgui_dialog_impl::text_message_widget(const char*) { return 0; }
00247 void* vgui_dialog_impl::file_browser_widget(const char*, vcl_string&, vcl_string&) { return 0; }
00248 void* vgui_dialog_impl::inline_file_browser_widget(const char*, vcl_string&, vcl_string&) { return 0; }
00249 void* vgui_dialog_impl::color_chooser_widget(const char* txt, vcl_string& val) { return string_field_widget(txt, val); }
00250 void* vgui_dialog_impl::inline_color_chooser_widget(const char* txt, vcl_string& val) { return string_field_widget(txt, val); }
00251 void* vgui_dialog_impl::inline_tableau_widget(const vgui_tableau_sptr, unsigned /*width*/, unsigned /*height*/) { return 0; }
00252 void* vgui_dialog_impl::pushbutton_field_widget(const char*, const void*) { return 0; }
00253 
00254 //------------------------------------------------------------------------------
00255 //: Changes the modality of the dialog.  True makes the dialog modal
00256 // (i.e. the dialog 'grabs' all events), this is the default.
00257 // False makes the dialog non-modal.
00258 void vgui_dialog_impl::modal(bool)
00259 {
00260   vcl_cerr << "No function defined to change dialog modality, by default dialogs are modal\n";
00261 }