core/vgui/impl/mfc/vgui_mfc_dialog_extensions_impl.cxx
Go to the documentation of this file.
00001 // This is core/vgui/impl/mfc/vgui_mfc_dialog_extensions_impl.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Gamze Tunali, LEMS, Brown University
00008 // \date   16 Nov 2007
00009 //
00010 // See vgui_mfc_dialog_extensions_impl.h for a description of this file.
00011 
00012 #include "vgui_mfc_dialog_extensions_impl.h"
00013 
00014 #include <vcl_string.h>
00015 #include <vcl_iostream.h>
00016 #include <vcl_vector.h>
00017 #include <vcl_cstdio.h> // for sprintf()
00018 #include <vcl_cstring.h>
00019 
00020 #include <vgui/internals/vgui_dialog_field.h>
00021 #include <vgui/internals/vgui_simple_field.h>
00022 #include <vgui/impl/mfc/vgui_mfc_adaptor.h>
00023 #include <vgui/impl/mfc/vgui_dir_dialog.h>
00024 #include <winuser.h>
00025 
00026 static bool debug = false;
00027 
00028 CString TempsNewClass2;
00029 BEGIN_MESSAGE_MAP(vgui_mfc_dialog_extensions_impl, CWnd)
00030         ON_COMMAND(IDOK,OnOk)
00031         ON_COMMAND(IDCANCEL,OnCancel)
00032         ON_WM_CLOSE()
00033         ON_CONTROL_RANGE(BN_CLICKED,ID_BROWSE_FILES,ID_BROWSE_FILES+100, OnBrowse)
00034         ON_CONTROL_RANGE(BN_CLICKED,ID_BROWSE_DIRS,ID_BROWSE_DIRS+100, OnBrowseDir)
00035         ON_CONTROL_RANGE(BN_CLICKED,ID_CHOOSE_COLOUR,ID_CHOOSE_COLOUR+100,OnChooseColour)
00036 END_MESSAGE_MAP()
00037 
00038 //------------------------------------------------------------------------------
00039 //: Constructor
00040 vgui_mfc_dialog_extensions_impl::vgui_mfc_dialog_extensions_impl(const char* name)
00041   : CWnd(),vgui_dialog_extensions_impl(name)
00042 {
00043   // Set some default parameters
00044   count_fbsr = 0;
00045   count_csr = 0;
00046   count_dbsr = 0;
00047   nResult = 0;
00048   ok_clicked = false;
00049 }
00050 
00051 //------------------------------------------------------------------------------
00052 //: Destructor
00053 vgui_mfc_dialog_extensions_impl::~vgui_mfc_dialog_extensions_impl()
00054 {
00055 }
00056 
00057 //: Structure to contain data for a choice field.
00058 struct vgui_mfc_dialog_choice
00059 {
00060   vcl_vector<vcl_string> names;
00061   int index;
00062 };
00063 
00064 
00065 //------------------------------------------------------------------------------
00066 //: Make a choice widget
00067 void* vgui_mfc_dialog_extensions_impl::choice_field_widget(const char* /*txt*/,
00068                                                            const vcl_vector<vcl_string>& labels,
00069                                                            int& val)
00070 {
00071   vgui_mfc_dialog_choice *ch = new vgui_mfc_dialog_choice;
00072   ch->names = labels;
00073   ch->index = val;
00074 
00075   return (void*)ch;
00076 }
00077 
00078 //: Structure to contain data for an inline tableau.
00079 struct vgui_mfc_dialog_inline_tab
00080 {
00081   vgui_tableau_sptr tab;
00082   unsigned height;
00083   unsigned width;
00084 };
00085 
00086 //------------------------------------------------------------------------------
00087 //: Make a tableau widget.
00088 void* vgui_mfc_dialog_extensions_impl::inline_tableau_widget(const vgui_tableau_sptr tab,
00089                                                              unsigned width, unsigned height)
00090 {
00091   vgui_mfc_dialog_inline_tab* tab_data = new vgui_mfc_dialog_inline_tab;
00092   tab_data->tab = tab;
00093   tab_data->height = height;
00094   tab_data->width =  width;
00095   TempsNewClass2 = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_GLOBALCLASS);
00096   return (void*)tab_data;
00097 }
00098 
00099 #if 0 // is_modal is not used anywhere
00100 //: Sets the modality of the dialog box.
00101 //  True makes the dialog modal (i.e. the dialog 'grabs' all events), this is
00102 //  the default.  False makes the dialog non-modal.  WARNING: It is dangerous to
00103 //  make a dialog that changes data non-modal, only messages should be non-modal.
00104 static bool is_modal = true;
00105 void vgui_mfc_dialog_extensions_impl::modal(bool m)
00106 {
00107   is_modal = m;
00108 }
00109 #endif // 0
00110 
00111 //: Called by MFC when the user clicks the OK button.
00112 void vgui_mfc_dialog_extensions_impl::OnOk()
00113 {
00114   ASSERT(::IsWindow(m_hWnd));
00115 
00116   if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL))
00117     EndModalLoop(nResult);
00118 
00119   ::EndDialog(m_hWnd, nResult);
00120   ok_clicked = true;
00121 }
00122 
00123 //: Called by MFC when the user clicks the cancel button.
00124 void vgui_mfc_dialog_extensions_impl::OnCancel()
00125 {
00126   ASSERT(::IsWindow(m_hWnd));
00127 
00128   if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL))
00129     EndModalLoop(nResult);
00130 
00131   ::EndDialog(m_hWnd, nResult);
00132   ok_clicked = false;
00133 }
00134 
00135 //: Called by MFC when the user clicks the (file) browse button.
00136 //  Fires up File browser dialog box
00137 void vgui_mfc_dialog_extensions_impl::OnBrowse(UINT uID)
00138 {
00139   int which = uID-ID_BROWSE_FILES;
00140    ASSERT(which>=0 && which<100);
00141    vcl_cerr<<"File browser loading...";
00142    CFileDialog file_dialog(TRUE,"*.*",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "All Files (*.*)|*.*||", this);
00143    file_dialog.DoModal();
00144    CString s(file_dialog.GetPathName());
00145    fbsrs[which]->SetWindowText(s);
00146 }
00147 
00148 //: Called by MFC when the user clicks the (directory) browse button.
00149 //  Fires up directory browser dialog box
00150 void vgui_mfc_dialog_extensions_impl::OnBrowseDir(UINT uID)
00151 {
00152   int which = uID-ID_BROWSE_DIRS;
00153   ASSERT(which>=0 && which<100);
00154   vcl_cerr<<"Directory browser loading...";
00155   vgui_dir_dialog dir_dialog(NULL,"All Files |*.*|", this);
00156   if (dir_dialog.DoModal() == IDOK) {
00157     CString s(dir_dialog.GetPath());
00158     s.TrimRight('\\');
00159     dbsrs[which]->SetWindowText(s);
00160   }
00161 }
00162 
00163 //: Called by MFC when the user clicks the colour chooser button.
00164 //  Fires up Colour chooser dialog box
00165 void vgui_mfc_dialog_extensions_impl::OnChooseColour(UINT uID)
00166 {
00167   char buffer[20];
00168   int which = uID-ID_CHOOSE_COLOUR;
00169   ASSERT(which>=0 && which<100);
00170   vcl_cerr<<"File browser loading...";
00171   CColorDialog colour_dialog(0,0, this);
00172   colour_dialog.DoModal();
00173   COLORREF colour = colour_dialog.GetColor();
00174   vcl_sprintf(buffer,"%4.3f",float(colour&0xff)/255.0);
00175   CString s(buffer);
00176   s+=" ";
00177   vcl_sprintf(buffer,"%4.3f",float((colour>>8)&0xff)/255.0);
00178   s+=buffer;
00179   s+=" ";
00180   vcl_sprintf(buffer,"%4.3f",float((colour>>16)&0xff)/255.0);
00181   s+=buffer;
00182   csrs[which]->SetWindowText(s);
00183 }
00184 
00185 //: Called by MFC when the application is about to terminate.
00186 void vgui_mfc_dialog_extensions_impl::OnClose()
00187 {
00188   OnCancel();
00189 }
00190 
00191 //: Display the dialog in a user formatted box.
00192 // Line breaks are used to separate lines of elements
00193 bool vgui_mfc_dialog_extensions_impl::ask()
00194 {
00195   // Get the pointer to the main window
00196   CWnd *main_window = AfxGetApp()->GetMainWnd();
00197 
00198   // Find out the size of the dialog box needed
00199   int width=32, max_length = 0,fbsr_count = 0, dbsr_count=0;
00200   int height = 40 + 6*8;
00201 
00202   for (vcl_vector<element>::iterator e_iter1 = elements.begin();
00203        e_iter1 != elements.end(); ++e_iter1)
00204   {
00205     element l = *e_iter1;
00206     vgui_dialog_field *field = l.field;
00207 
00208     if (l.type == bool_elem)
00209     {
00210       vgui_bool_field *field = static_cast<vgui_bool_field*>(l.field);
00211       int field_length = vcl_strlen(field->label.c_str());
00212       width += 24 + (field_length+3)* 8;
00213     }
00214     else if (l.type == inline_tabl)
00215     {
00216       vgui_mfc_dialog_inline_tab* tab_data = (vgui_mfc_dialog_inline_tab*)l.widget;
00217       //if (max_length < int(tab_data->width/8 + 5))
00218        // max_length = int((7+tab_data->width)/8) + 5;
00219       height += int((tab_data->height) + 20); //??
00220       width += (int(7+tab_data->width) + 5)*8;
00221     }
00222     else if (l.type == text_msg)
00223     {
00224       vgui_int_field *field = static_cast<vgui_int_field*>(l.field);
00225       //if (max_length<int(field->label.size()+field->current_value().size()))
00226       //  max_length = field->label.size()+field->current_value().size();
00227       width += 24 + field->label.size()*8;
00228     }
00229 
00230     else if (l.type == line_br) {
00231       width += 32;
00232       if (max_length< width)
00233         max_length = width;
00234       width = 32;
00235       height += 40;
00236     }
00237 
00238     else // Remaining types are text with user input boxes:
00239     {
00240       // Add 40 extra characters to the length to leave space for
00241       // the user response box:
00242       int field_length = vcl_strlen(field->label.c_str()) + 20;
00243       //if (max_length<field_length)
00244       //  max_length = field_length;
00245       width += 24 + field_length*8 ;
00246     }
00247 
00248     if (l.type == file_bsr || l.type == inline_file_bsr ||
00249         l.type == color_csr || l.type == inline_color_csr)
00250     {
00251       fbsr_count++;
00252       width += 8 + (20+10)*8; // 20 extra for path entry, 20 was counted in text field
00253     }
00254     else if (l.type == dir_bsr) {
00255       dbsr_count++;
00256       width += 8 + (20+10)*8;
00257     }
00258   }
00259 
00260   // Width of the dialog box is approx 8 times the number of characters:
00261   width = max_length;
00262   // If the width is too small to contain the buttons then make it bigger:
00263   if (width < 200)
00264     width = 200;
00265   fbsr_count++;
00266 
00267   // Create dialog box window
00268   CreateEx(WS_EX_CONTROLPARENT,
00269            AfxRegisterWndClass(0,::LoadCursor(NULL, IDC_ARROW),(HBRUSH)(COLOR_WINDOW)),
00270            _T(vgui_dialog_impl::name.c_str()),
00271            WS_CAPTION|WS_VISIBLE|WS_SYSMENU|WS_POPUP|DS_MODALFRAME,
00272            100, 100, width, height, NULL, NULL, 0);
00273   UpdateWindow();
00274   ShowWindow(SW_SHOW);
00275 
00276   // determine default font for document
00277   vcl_memset(&m_logfont, 0, sizeof m_logfont);
00278   m_logfont.lfHeight = -8;
00279   lstrcpy(m_logfont.lfFaceName, _T("Microsoft Sans Serif Regular"));
00280   m_logfont.lfOutPrecision = OUT_TT_PRECIS;
00281   m_logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
00282   m_logfont.lfQuality = PROOF_QUALITY;
00283   m_logfont.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
00284   m_logfont.lfHeight = -::MulDiv(-m_logfont.lfHeight,GetDC()->GetDeviceCaps(LOGPIXELSY), 72);
00285   font = new CFont();
00286   font->CreateFontIndirect(&m_logfont);
00287   SetFont(font);
00288 
00289   // Attach basic buttons "OK" and "Cancel" at the bottom of the dialog
00290 
00291   // Ok button
00292   CButton* accept = 0;
00293   int right_of_ok_button;
00294   if (ok_button_text_.size() > 0)
00295   {
00296     CRect r;
00297     // center the buttons at the bottom
00298     r.left = (width -1)/2 - (ok_button_text_.size()+4)*8;
00299     r.right = r.left+(ok_button_text_.size()+4)*8;//r.left+10*8;
00300     r.top = height-9*8;
00301     r.bottom = height-5*8;
00302     right_of_ok_button = r.right;
00303     accept = new CButton();
00304     accept->Create(_T(ok_button_text_.c_str()),
00305                    WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_PUSHBUTTON,
00306                    r,this,IDOK);
00307     accept->SetFocus();
00308     accept->SetFont(font);
00309   }
00310 
00311   // Cancel button
00312   CButton* cancel = 0;
00313   if (cancel_button_text_.size() > 0)
00314   {
00315     CRect r;
00316     r.left = right_of_ok_button+1*8;
00317     r.right = r.left+(cancel_button_text_.size()+4)*8; //r.left+10*8;
00318     r.top = height-9*8;
00319     r.bottom = height-5*8;
00320     cancel = new CButton();
00321     cancel->Create(_T(cancel_button_text_.c_str()),
00322                    WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_PUSHBUTTON,
00323                    r,this,IDCANCEL);
00324     cancel->SetFont(font);
00325   }
00326 
00327   // Add elements from top to bottom
00328   CRect r;
00329   r.left = 0; // set later
00330   r.right = 999; //
00331   r.top = 32;
00332   r.bottom = 3*8+2+32;
00333   for (vcl_vector<element>::iterator e_iter2 = elements.begin();
00334        e_iter2 != elements.end(); ++e_iter2)
00335   {
00336     element l = *e_iter2;
00337     vgui_dialog_field *field = l.field;
00338 
00339     if (l.type == int_elem ||
00340         l.type == long_elem ||
00341         l.type == float_elem ||
00342         l.type == double_elem ||
00343         l.type == string_elem)
00344     {
00345       // Hard coded coordinates
00346       r.left += 3*8;
00347       r.right = r.left+field->label.size()*8;
00348       // Set static text first
00349       CStatic *text = new CStatic();
00350       text->Create(_T(field->label.c_str()),WS_CHILD|WS_VISIBLE|SS_LEFT,r,this);
00351       text->SetFont(font);
00352       awlist.push_back(text);
00353       // Now set the line editor next
00354       CEdit *edit = new CEdit();
00355       r.left = r.right+2*4;
00356       r.right = r.left+20*8;
00357 
00358       // CEdit::Create does not support extended window styles
00359       //MFC impl:Create(_T("EDIT"), NULL, dwStyle, rect, pParentWnd, nID);
00360       // So we use CWnd::CreateEx. Note that the class name is EDIT
00361       edit->CreateEx(WS_EX_CLIENTEDGE,_T("EDIT"),NULL,
00362                      WS_CHILD|WS_BORDER|WS_TABSTOP|ES_LEFT|ES_AUTOHSCROLL,r,this,IDOK);
00363       edit->SetFont(font);
00364       edit->SetWindowText(l.field->current_value().c_str());
00365       edit->UpdateWindow();
00366       edit->ShowWindow(SW_SHOW);
00367       text->UpdateWindow();
00368       text->ShowWindow(SW_SHOW);
00369       awlist.push_back(edit);
00370       wlist.push_back(edit);
00371       r.left = r.right;
00372     }
00373     else if (l.type == bool_elem)
00374     {
00375       r.left += 3*8;
00376       r.right = r.left+(field->label.size()+3)*8;
00377       vgui_bool_field *field = static_cast<vgui_bool_field*>(l.field);
00378       CButton *checkbox = new CButton();
00379       checkbox->Create(_T(field->label.c_str()),
00380                           WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_AUTOCHECKBOX, r,this,4);
00381       checkbox->SetFont(font);
00382       checkbox->SetCheck(field->var); // Make sure checkbox displays current bool value.
00383       checkbox->UpdateWindow();
00384       checkbox->ShowWindow(SW_SHOW);
00385       awlist.push_back(checkbox);
00386       wlist.push_back(checkbox);
00387       r.left = r.right;
00388     }
00389     else if (l.type == choice_elem)
00390     {
00391       vgui_int_field *field = static_cast<vgui_int_field*>(l.field);
00392       r.left += 3*8;
00393       r.right = r.left+field->label.size()*8;
00394       // Set static text first
00395       CStatic *text = new CStatic();
00396       text->Create(_T(field->label.c_str()),WS_CHILD|WS_VISIBLE|SS_LEFT,r,this);
00397       text->SetFont(font);
00398       awlist.push_back(text);
00399 
00400       r.left = r.right + 2*4;
00401       r.right = r.left+20*8;
00402       vgui_mfc_dialog_choice *ch = (vgui_mfc_dialog_choice*)l.widget;
00403       r.bottom+=__min(ch->names.size(),4)*32;
00404       CComboBox *combobox = new CComboBox();
00405       combobox->CreateEx(WS_EX_CLIENTEDGE,_T("COMBOBOX"),NULL,
00406                          WS_CHILD|WS_BORDER|CBS_DROPDOWNLIST|WS_VSCROLL,r,this,4);
00407       combobox->SetFont(font);
00408       r.bottom-=__min(ch->names.size(),4)*32;
00409 
00410       int count = 0;
00411       for (vcl_vector<vcl_string>::iterator s_iter =  ch->names.begin();
00412            s_iter != ch->names.end(); ++s_iter, ++count)
00413         combobox->AddString(_T(s_iter->c_str()));
00414 
00415       combobox->SetCurSel(ch->index);
00416       combobox->UpdateWindow();
00417       combobox->ShowWindow(SW_SHOW);
00418       awlist.push_back(combobox);
00419       wlist.push_back(combobox);
00420       r.left = r.right;
00421     }
00422     else if (l.type == text_msg)
00423     {
00424       r.left += 3*8;
00425       r.right = r.left+field->label.size()*8;
00426 
00427       CStatic *text = new CStatic();
00428       text->Create(_T(field->label.c_str()),WS_CHILD|WS_VISIBLE|SS_LEFT,r,this);
00429       text->SetFont(font);
00430       awlist.push_back(text);
00431       wlist.push_back(text);
00432       r.left = r.right;
00433     }
00434     else if (l.type == file_bsr || l.type == inline_file_bsr)
00435     {
00436       r.left += 3*8;
00437       r.right = r.left+field->label.size()*8;
00438 
00439       CStatic *text = new CStatic();
00440       text->Create(_T(field->label.c_str()),WS_CHILD|WS_VISIBLE|SS_LEFT,r,this);
00441       text->SetFont(font);
00442       awlist.push_back(text);
00443 
00444       // Now set the line editor next
00445       CEdit *edit = new CEdit();
00446       int savey = r.top;
00447       r.left  = r.right+2*4;
00448       r.right = r.left+40*8;
00449 
00450       // CEdit::Create does not support extended window styles
00451       //MFC impl:Create(_T("EDIT"), NULL, dwStyle, rect, pParentWnd, nID);
00452       // So we use CWnd::CreateEx. Note that the class name is EDIT
00453       edit->CreateEx(WS_EX_CLIENTEDGE,_T("EDIT"),NULL,
00454                      WS_CHILD|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,r,this,IDOK);
00455       edit->SetFont(font);
00456       edit->SetWindowText(l.field->current_value().c_str());
00457       edit->UpdateWindow();
00458       edit->ShowWindow(SW_SHOW);
00459       CButton *button = new CButton();
00460 
00461       r.left = r.right+2*4;
00462       r.right = r.left+10*8;
00463       button->Create(_T("Browse..."),WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_PUSHBUTTON,
00464                      r,this,ID_BROWSE_FILES+count_fbsr);
00465       fbsrs[count_fbsr++] = edit;
00466 
00467       button->SetFont(font);
00468       button->UpdateWindow();
00469       button->ShowWindow(SW_SHOW);
00470       awlist.push_back(edit);
00471       awlist.push_back(button);
00472       wlist.push_back(edit);
00473       r.left = r.right;
00474     }
00475     else if (l.type == color_csr || l.type == inline_color_csr)
00476     {
00477       r.left += 3*8;
00478       r.right = r.left+field->label.size()*8;
00479 
00480       CStatic *text = new CStatic();
00481       text->Create(_T(field->label.c_str()),WS_CHILD|WS_VISIBLE|SS_LEFT,r,this);
00482       text->SetFont(font);
00483       awlist.push_back(text);
00484 
00485       // Now set the line editor next
00486       CEdit *edit = new CEdit();
00487       r.left  = r.right+2*4;
00488       r.right = r.left + 10*8; //width-2*8;//r.left+(l.field->current_value().size()+2)*8;
00489       // CEdit::Create does not support extended window styles
00490       //MFC impl:Create(_T("EDIT"), NULL, dwStyle, rect, pParentWnd, nID);
00491       // So we use CWnd::CreateEx. Note that the class name is EDIT
00492       edit->CreateEx(WS_EX_CLIENTEDGE,_T("EDIT"),NULL,
00493                      WS_CHILD|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,r,this,IDOK);
00494       edit->SetFont(font);
00495       edit->SetWindowText(l.field->current_value().c_str());
00496       edit->UpdateWindow();
00497       edit->ShowWindow(SW_SHOW);
00498       CButton *button = new CButton();
00499 
00500       r.left = r.right+2*4;
00501       r.right = r.left+10*8;
00502       button->Create(_T("Colour..."),WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_PUSHBUTTON,
00503                      r,this,ID_CHOOSE_COLOUR+count_csr);
00504       csrs[count_csr++] = edit;
00505       button->SetFont(font);
00506       button->UpdateWindow();
00507       button->ShowWindow(SW_SHOW);
00508       awlist.push_back(edit);
00509       awlist.push_back(button);
00510       wlist.push_back(edit);
00511       r.left = r.right;
00512     }
00513     else if (l.type == dir_bsr)
00514     {
00515       r.left += 3*8;
00516       r.right = r.left+field->label.size()*8;
00517 
00518       CStatic *text = new CStatic();
00519       text->Create(_T(field->label.c_str()),WS_CHILD|WS_VISIBLE|SS_LEFT,r,this);
00520       text->SetFont(font);
00521       awlist.push_back(text);
00522 
00523       // Now set the line editor next
00524       CEdit *edit = new CEdit();
00525       int savey = r.top;
00526       r.left  = r.right+2*4;
00527       r.right = r.left+40*8;
00528 
00529       // CEdit::Create does not support extended window styles
00530       //MFC impl:Create(_T("EDIT"), NULL, dwStyle, rect, pParentWnd, nID);
00531       // So we use CWnd::CreateEx. Note that the class name is EDIT
00532       edit->CreateEx(WS_EX_CLIENTEDGE,_T("EDIT"),NULL,
00533                      WS_CHILD|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,r,this,IDOK);
00534       edit->SetFont(font);
00535       edit->SetWindowText(l.field->current_value().c_str());
00536       edit->UpdateWindow();
00537       edit->ShowWindow(SW_SHOW);
00538       CButton *button = new CButton();
00539 
00540       r.left = r.right+2*4;
00541       r.right = r.left+10*8;
00542       button->Create(_T("Browse..."),WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_PUSHBUTTON,
00543                      r,this,ID_BROWSE_DIRS+count_dbsr);
00544       dbsrs[count_dbsr++] = edit;
00545 
00546       button->SetFont(font);
00547       button->UpdateWindow();
00548       button->ShowWindow(SW_SHOW);
00549       awlist.push_back(edit);
00550       awlist.push_back(button);
00551       wlist.push_back(edit);
00552       r.left = r.right;
00553     }
00554     else if (l.type == inline_tabl)
00555     {
00556       vgui_mfc_dialog_inline_tab* tab_data
00557         = (vgui_mfc_dialog_inline_tab*)l.widget;
00558       vgui_mfc_adaptor *widg = new vgui_mfc_adaptor();
00559       widg->set_tableau(tab_data->tab);
00560       // because this adaptor is not in the main window we need to call setup_adaptor:
00561       widg->setup_adaptor(this, wglGetCurrentDC(), wglGetCurrentContext());
00562       r.left+=3*8;
00563       r.right=r.left + long(tab_data->width);
00564       widg->CreateEx(WS_EX_CLIENTEDGE,TempsNewClass2,NULL,
00565                      WS_CHILD|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,r,this,IDOK);
00566 
00567       widg->ShowWindow(SW_SHOW);
00568       awlist.push_back(widg);
00569       wlist.push_back(widg);
00570       delete tab_data;
00571       r.left = r.right;
00572     }
00573     else if (l.type == line_br ) {
00574       // put a line break i.e. start a new line to put the elements
00575       r.top+=4*8;
00576       r.bottom+=4*8;
00577       r.left=0;
00578     }
00579   }
00580   if (accept)
00581   {
00582     accept->UpdateWindow();
00583     accept->ShowWindow(SW_SHOW);
00584   }
00585   if (cancel)
00586   {
00587     cancel->UpdateWindow();
00588     cancel->ShowWindow(SW_SHOW);
00589   }
00590   AfxGetApp()->EnableModeless(FALSE);
00591   AfxGetApp()->GetMainWnd()->EnableWindow(FALSE);
00592   nResult = RunModalLoop(MLF_SHOWONIDLE);
00593   if (m_hWnd != NULL)
00594     SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
00595                  SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
00596   if (ok_clicked)
00597   {
00598     int i=0, w=0;
00599     vcl_vector<CWnd *>::iterator w_iter = wlist.begin();
00600     for (vcl_vector<element>::iterator e_iter3 = elements.begin();
00601          e_iter3 != elements.end(); ++e_iter3)
00602     {
00603       element l = *e_iter3;
00604 
00605       // line break does not have a widget element, go on to the next element
00606       if (l.type == line_br)
00607         continue;
00608 
00609       CWnd *input = *w_iter;
00610 
00611       if (l.type == int_elem ||
00612           l.type == long_elem ||
00613           l.type == float_elem ||
00614           l.type == double_elem ||
00615           l.type == string_elem ||
00616           l.type == file_bsr ||
00617           l.type == dir_bsr ||
00618           l.type == color_csr ||
00619           l.type == inline_color_csr ||
00620           l.type == inline_file_bsr)
00621       {
00622         CString s;
00623         input->GetWindowText(s);
00624         l.field->update_value((LPCSTR)s);
00625       }
00626       else if (l.type == bool_elem)
00627       {
00628         vgui_bool_field *field = static_cast<vgui_bool_field*>(l.field);
00629         field->var =((CButton *)input)->GetCheck()!=0;
00630       }
00631       if (l.type == choice_elem)
00632       {
00633         vgui_int_field *field = static_cast<vgui_int_field*>(l.field);
00634         field->var = ((CComboBox *)input)->GetCurSel();
00635       }
00636       w_iter++;
00637     }
00638   }
00639   // Remove all the created objects from the heap
00640   for (vcl_vector<CWnd *>::iterator w_iter = awlist.begin();w_iter!=awlist.end();++w_iter)
00641     delete *w_iter;
00642 
00643   awlist.clear();
00644   wlist.clear();
00645 
00646   count_fbsr = 0;
00647   count_dbsr = 0;
00648   count_csr  = 0;
00649 
00650   delete accept;
00651   delete cancel;
00652   DestroyWindow();
00653 
00654   delete font;
00655 
00656   // Enable the parent window
00657   AfxGetApp()->EnableModeless(TRUE);
00658   AfxGetApp()->GetMainWnd()->EnableWindow(TRUE);
00659   main_window->SetActiveWindow();
00660   return ok_clicked;
00661 }