00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00030
00031
00032
00033
00034 #if defined(__GNUG__) && !defined(__APPLE__)
00035 #pragma implementation "OptDlg.h"
00036 #endif
00037
00038
00039
00040 #include "mg/mgprec.h"
00041
00042 #ifndef mgPRECOMP
00043 #include "mg/OptDlg.h"
00044 #include "mg/OptBtnPanel.h"
00045 #include "mg/OptTreeCtrl.h"
00046
00047
00048 #include "mg/OptBasePanel.h"
00049 #include "mg/OptGeneral.h"
00050 #include "mg/OptKeyBindings.h"
00051 #include "mg/OptFontSettings.h"
00052 #endif
00053
00054
00055
00056
00057 IMPLEMENT_CLASS(mgOptDlg, wxDialog )
00058 BEGIN_EVENT_TABLE(mgOptDlg,wxDialog)
00059 EVT_BUTTON( OPTIONSDLG_BTN_OK, mgOptDlg::OnOkButton )
00060 EVT_BUTTON( OPTIONSDLG_BTN_CANCEL, mgOptDlg::OnCancelButton )
00061 EVT_BUTTON( OPTIONSDLG_BTN_APPLY, mgOptDlg::OnApplyButton )
00062 EVT_TREE_SEL_CHANGED( OPTIONSDLG_TREELIST, mgOptDlg::OnItemSelected )
00063 END_EVENT_TABLE()
00064
00065
00066 DEFINE_EVENT_TYPE( mgEVT_OPTIONS_CHANGED )
00067
00068
00069
00070
00071
00072
00073
00074
00075 mgOptDlg::mgOptDlg( wxWindow* parent, wxWindowID id, wxConfig* config )
00076 : wxDialog( parent, id, wxT("MathStudio Options"),
00077 wxDefaultPosition, wxSize( 660, 500),
00078 wxCAPTION | wxSYSTEM_MENU | wxRESIZE_BORDER )
00079 {
00080
00081 m_actualPanel = 0;
00082
00083
00084
00085 SetClientEvtHandler(parent);
00086
00087
00088 m_treeWnd = new mgOptionsTreeCtrl( this );
00089 m_buttonWnd = new mgOptionsBtnPanel( this );
00090
00091 CreateLayout( this );
00092
00093
00094
00095
00096
00097
00098
00099 }
00100
00102 mgOptDlg::~mgOptDlg()
00103 {
00104 }
00105
00106
00107
00108
00109 void mgOptDlg::CreateLayout( wxWindow* parent )
00110 {
00111 #ifdef OPTIONSDLG_USE_LAYOUTCONSTRAINTS
00112
00113
00114 wxLayoutConstraints* treeLayout = new wxLayoutConstraints;
00115 wxASSERT( treeLayout );
00116
00117 treeLayout->left.SameAs (parent, wxLeft, 10 );
00118 treeLayout->top.SameAs (parent, wxTop, 10 );
00119 treeLayout->width.Absolute ( 160 );
00120 treeLayout->bottom.SameAs( parent, wxBottom, 10);
00121 m_treeWnd->SetConstraints( treeLayout );
00122
00123
00124
00125
00126
00127 wxLayoutConstraints* buttonLayout = new wxLayoutConstraints;
00128 wxASSERT( buttonLayout );
00129
00130 buttonLayout->left.RightOf ( m_treeWnd, 10 );
00131 buttonLayout->height.Absolute ( 70 );
00132 buttonLayout->right.SameAs ( parent, wxRight, 10 );
00133 buttonLayout->bottom.SameAs( parent, wxBottom, 10);
00134 m_buttonWnd->SetConstraints( buttonLayout );
00135
00136
00137
00138
00139
00140
00141 m_optionLayout = new wxLayoutConstraints;
00142 wxASSERT( m_optionLayout );
00143
00144 m_optionLayout->left.RightOf ( m_treeWnd, 10 );
00145 m_optionLayout->top.SameAs( parent, wxTop, 10 );
00146 m_optionLayout->right.SameAs ( parent, wxRight, 10 );
00147 m_optionLayout->bottom.Above( m_buttonWnd, 10);
00148
00149
00150 SetAutoLayout( TRUE );
00151
00152 #else
00153
00154
00155 m_mainSizer = new wxBoxSizer(wxHORIZONTAL);
00156 m_optionSizer = new wxBoxSizer(wxVERTICAL);
00157
00158
00159 m_optionSizer->Add(m_buttonWnd, 1, wxGROW);
00160
00161
00162
00163 m_mainSizer->Add(m_treeWnd, 2, wxGROW | wxALL, 10);
00164 m_mainSizer->Add(m_optionSizer, 5, wxGROW | wxALL, 5);
00165
00166 SetSizer(m_mainSizer);
00167 m_mainSizer->SetSizeHints(this);
00168
00169 #endif // OPTIONSDLG_USE_LAYOUTCONSTRAINTS
00170
00171
00172
00173
00174
00175 }
00176
00177
00178
00179 mgOptBasePanel *mgOptDlg::CreatePanel( mgOptTreeCtrlItemData *itemData, const wxString &itemLabel )
00180 {
00181 mgLogDebug( wxT("mgOptDlg::CreatePanel() itemData=%p"), itemData );
00182 wxASSERT( itemData );
00183
00184 #ifdef OPTIONSDLG_USE_LAYOUTCONSTRAINTS
00185
00186 wxLayoutConstraints* c = new wxLayoutConstraints( *m_optionLayout );
00187 wxASSERT( c );
00188 #endif
00189
00190 mgOptBasePanel* panel = 0;
00191
00192 #ifdef NOT_DEFINED
00193
00194
00195
00196
00197
00198
00199 wxString className = itemData->m_className;
00200 panel = ( mgOptBasePanel*) ::wxCreateDynamicObject( className );
00201 #endif
00202
00203
00204 IdOptionsPanel id = itemData->m_classID;
00205
00206 switch ( id ) {
00207 case Id_mgOptGeneralPanel :
00208 panel = new mgOptGeneralPanel();
00209 break;
00210 case Id_mgOptKeyBindingsPanel :
00211 panel = new mgOptKeyBindingsPanel();
00212 break;
00213 case Id_mgOptFontSettingsPanel:
00214 panel = new mgOptFontSettingsPanel();
00215 break;
00216 default :
00217 panel = NULL;
00218 break;
00219 }
00220
00221 wxASSERT( panel );
00222
00223
00224
00225
00226
00227
00228
00229
00230 panel->Create( this, -1 );
00231
00232
00233
00234
00235 panel->Setup( itemLabel );
00236
00237 #ifdef OPTIONSDLG_USE_LAYOUTCONSTRAINTS
00238
00239 panel->SetConstraints( c );
00240 #endif
00241
00242 mgLogDebug( wxT("mgOptDlg::CreatePanel() . panel created") );
00243
00244 return panel;
00245 }
00246
00247 void mgOptDlg::DisplayPanel( wxTreeItemId itemId )
00248 {
00249 mgLogDebug( wxT("mgOptDlg::DisplayPanel() - start\n") );
00250 wxASSERT( itemId.IsOk() );
00251
00252
00253 mgOptTreeCtrlItemData *itemData =
00254 ( mgOptTreeCtrlItemData* ) m_treeWnd->GetItemData( itemId );
00255
00256
00257 wxString itemLabel = m_treeWnd->GetItemText( itemId );
00258
00259 mgLogDebug( wxT("mgOptDlg::Display Panel() label=%s, item-data=%p"),
00260 itemLabel.c_str(), itemData );
00261
00262 wxASSERT( itemData != 0 );
00263
00264
00265 mgOptBasePanel* newPanel = itemData->m_panel;
00266 mgLogDebug( wxT("mgOptDlg::DisplayPanel() - itemData=%p panel=%p classname=%s"),
00267 itemData, itemData->m_panel, (itemData->m_className).c_str() );
00268
00269
00270
00271
00272 if ( newPanel == 0 ) {
00273 newPanel = CreatePanel( itemData, itemLabel );
00274 itemData->m_panel = newPanel;
00275 }
00276
00277
00278
00279 if ( m_actualPanel == newPanel )
00280 return;
00281
00282
00283 if ( m_actualPanel != 0 )
00284 m_actualPanel->Show( FALSE );
00285
00286 #ifndef OPTIONSDLG_USE_LAYOUTCONSTRAINTS
00287
00288
00289 if (m_actualPanel)
00290 m_optionSizer->Remove(m_actualPanel);
00291
00292
00293 m_optionSizer->Prepend(newPanel, 7, wxALL | wxGROW, 5);
00294 m_optionSizer->Layout();
00295 m_mainSizer->Layout();
00296
00297
00298
00299
00300 m_mainSizer->SetSizeHints(this);
00301
00302 mgLogDebug( wxT("mgOptDlg::DisplayPanel() - sizer has been prepended") );
00303
00304 #endif
00305
00306 wxASSERT( newPanel != 0 );
00307
00308 mgLogDebug( wxT("mgOptDlg::DisplayPanel() - showing the panel") );
00309
00310
00311 CenterOnScreen();
00312 newPanel->Show( TRUE );
00313 m_actualPanel = newPanel;
00314 Refresh();
00315 }
00316
00317 void mgOptDlg::CommitChanges()
00318 {
00319 mgLogDebug( wxT("Edit - Options dialog box: Committing changes") );
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 wxASSERT( m_treeWnd != 0 );
00334
00335 int depthLevel = 0;
00336
00337 long cookie[OPTIONSDLG_MAX_TREELIST_DEPTH];
00338 wxTreeItemId rootID = m_treeWnd->GetRootItem();
00339 wxTreeItemId childId[OPTIONSDLG_MAX_TREELIST_DEPTH];
00340
00341
00342
00343 childId[0] = m_treeWnd->GetFirstChild( rootID, cookie[0] );
00344 if ( !childId[0].IsOk() ) {
00345 mgLogDebug( wxT("mgOptDlg::CommitChanges() - no items in trelist\n") );
00346 return;
00347 }
00348
00349
00350 while ( 1 ) {
00351
00352
00353
00354
00355 if ( m_treeWnd->ItemHasChildren( childId[depthLevel] )) {
00356 wxTreeItemId temp;
00357 ++depthLevel;
00358 wxASSERT( depthLevel < OPTIONSDLG_MAX_TREELIST_DEPTH );
00359 childId[depthLevel] = m_treeWnd->GetFirstChild( temp, cookie[depthLevel] );
00360 }
00361 else {
00362
00363
00364
00365 mgOptTreeCtrlItemData *itemData =
00366 (mgOptTreeCtrlItemData*) m_treeWnd->GetItemData( childId[depthLevel] );
00367 wxASSERT( itemData != 0 );
00368
00369 if ( itemData->m_panel != 0 ) {
00370 itemData->m_panel->CommitChanges( m_config );
00371 }
00372
00373
00374
00375
00376
00377 childId[depthLevel] = m_treeWnd->GetNextSibling( childId[depthLevel]);
00378 if ( !childId[depthLevel].IsOk() ) {
00379
00380 --depthLevel;
00381
00382
00383 if ( depthLevel < 0 )
00384 break;
00385 }
00386 }
00387 }
00388
00389
00390
00391 wxCommandEvent ev( mgEVT_OPTIONS_CHANGED );
00392 if (m_pClientEvtHandler)
00393 m_pClientEvtHandler->AddPendingEvent( ev );
00394 }
00395
00396
00397
00398 void mgOptDlg::OnOkButton( wxCommandEvent &ev )
00399 {
00400 CommitChanges();
00401 EndModal( wxID_OK );
00402 }
00403
00404 void mgOptDlg::OnCancelButton( wxCommandEvent &ev )
00405 {
00406 EndModal( wxID_CANCEL );
00407 }
00408
00409 void mgOptDlg::OnApplyButton( wxCommandEvent &ev )
00410 {
00411 CommitChanges();
00412 }
00413
00414 void mgOptDlg::OnItemSelected( wxTreeEvent& ev )
00415 {
00416
00417 wxTreeItemId id = ev.GetItem();
00418
00419
00420
00421 DisplayPanel( id );
00422 }
00423
00424
00425
00426
00427
00428