1 /////////////////////////////////////////////////////////////////////////////
2 // Name: settingsdialog.cpp
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/cshelp.h"
14 #include "wx/statline.h"
15 #include "wx/splitter.h"
16 #include "wx/scrolwin.h"
17 #include "wx/spinctrl.h"
18 #include "wx/spinbutt.h"
19 #include "wx/valgen.h"
20 #include "wx/notebook.h"
22 #include "wxconfigtool.h"
23 #include "settingsdialog.h"
29 * ctSettingsDialog type definition
32 IMPLEMENT_CLASS( ctSettingsDialog
, wxDialog
)
35 * ctSettingsDialog event table definition
38 BEGIN_EVENT_TABLE( ctSettingsDialog
, wxDialog
)
40 ////@begin ctSettingsDialog event table entries
41 EVT_BUTTON( wxID_OK
, ctSettingsDialog::OnOk
)
43 EVT_BUTTON( wxID_CANCEL
, ctSettingsDialog::OnCancel
)
45 EVT_BUTTON( wxID_HELP
, ctSettingsDialog::OnHelp
)
47 ////@end ctSettingsDialog event table entries
52 * ctSettingsDialog constructor
55 ctSettingsDialog::ctSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
57 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
58 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
64 * Control creation for ctSettingsDialog
67 void ctSettingsDialog::CreateControls()
69 ////@begin ctSettingsDialog content construction
71 ctSettingsDialog
* item1
= this;
73 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
74 item1
->SetSizer(item2
);
75 item1
->SetAutoLayout(TRUE
);
77 wxNotebook
* item3
= new wxNotebook(item1
, ID_NOTEBOOK
, wxDefaultPosition
, wxSize(200, 200), wxNB_TOP
);
78 wxNotebookSizer
* item3Sizer
= new wxNotebookSizer(item3
);
79 ctGeneralSettingsDialog
* item4
= new ctGeneralSettingsDialog(item3
, ID_GENERAL_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
80 item3
->AddPage(item4
, _("General"));
81 ctLocationSettingsDialog
* item9
= new ctLocationSettingsDialog(item3
, ID_LOCATION_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
82 item3
->AddPage(item9
, _("Locations"));
83 item2
->Add(item3Sizer
, 0, wxGROW
|wxALL
, 5);
85 wxBoxSizer
* item19
= new wxBoxSizer(wxHORIZONTAL
);
86 item2
->Add(item19
, 0, wxGROW
|wxALL
, 5);
88 item19
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
90 wxButton
* item21
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
92 item19
->Add(item21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
94 wxButton
* item22
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
95 item19
->Add(item22
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
97 wxButton
* item23
= new wxButton(item1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0);
98 item19
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
100 #if defined(__WXGTK__) || defined(__WXMAC__)
101 wxContextHelpButton
* item24
= new wxContextHelpButton(item1
, wxID_CONTEXT_HELP
, wxDefaultPosition
, wxSize(20, -1), wxBU_AUTODRAW
);
102 item19
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
105 GetSizer()->Fit(this);
106 GetSizer()->SetSizeHints(this);
108 ////@end ctSettingsDialog content construction
112 * Event handler for wxID_OK
115 void ctSettingsDialog::OnOk( wxCommandEvent
& event
)
117 // Replace with custom code
122 * Event handler for wxID_CANCEL
125 void ctSettingsDialog::OnCancel( wxCommandEvent
& event
)
127 // Replace with custom code
132 * Event handler for wxID_HELP
135 void ctSettingsDialog::OnHelp( wxCommandEvent
& event
)
137 wxNotebook
* notebook
= (wxNotebook
*) FindWindow(ID_NOTEBOOK
);
139 int sel
= notebook
->GetSelection();
141 wxASSERT_MSG( (sel
!= -1), wxT("A notebook tab should always be selected."));
143 wxWindow
* page
= (wxWindow
*) notebook
->GetPage(sel
);
146 if (page
->GetId() == ID_GENERAL_SETTINGS_DIALOG
)
148 helpTopic
= wxT("General settings dialog");
150 else if (page
->GetId() == ID_LOCATION_SETTINGS_DIALOG
)
152 helpTopic
= wxT("Location dialog");
155 if (!helpTopic
.IsEmpty())
157 wxGetApp().GetHelpController().DisplaySection(helpTopic
);
162 * Should we show tooltips?
165 bool ctSettingsDialog::ShowToolTips()
171 * ctGeneralSettingsDialog type definition
174 IMPLEMENT_CLASS( ctGeneralSettingsDialog
, wxPanel
)
177 * ctGeneralSettingsDialog event table definition
180 BEGIN_EVENT_TABLE( ctGeneralSettingsDialog
, wxPanel
)
182 ////@begin ctGeneralSettingsDialog event table entries
183 ////@end ctGeneralSettingsDialog event table entries
188 * ctGeneralSettingsDialog constructor
191 ctGeneralSettingsDialog::ctGeneralSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
193 wxPanel::Create( parent
, id
, pos
, size
, style
);
199 * Control creation for ctGeneralSettingsDialog
202 void ctGeneralSettingsDialog::CreateControls()
204 ////@begin ctGeneralSettingsDialog content construction
206 ctGeneralSettingsDialog
* item4
= this;
208 wxBoxSizer
* item5
= new wxBoxSizer(wxVERTICAL
);
209 item4
->SetSizer(item5
);
210 item4
->SetAutoLayout(TRUE
);
212 wxStaticBox
* item6Static
= new wxStaticBox(item4
, -1, _("General settings"));
213 wxStaticBoxSizer
* item6
= new wxStaticBoxSizer(item6Static
, wxVERTICAL
);
214 item5
->Add(item6
, 1, wxGROW
|wxALL
, 5);
216 wxCheckBox
* item7
= new wxCheckBox(item4
, ID_LOAD_LAST_DOCUMENT
, _("&Load last document"), wxDefaultPosition
, wxDefaultSize
, 0);
217 item7
->SetValue(FALSE
);
218 item6
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
, 5);
220 wxCheckBox
* item8
= new wxCheckBox(item4
, ID_SHOW_TOOLTIPS
, _("&Show tooltips"), wxDefaultPosition
, wxDefaultSize
, 0);
221 item8
->SetValue(FALSE
);
222 item6
->Add(item8
, 0, wxALIGN_LEFT
|wxALL
, 5);
224 GetSizer()->Fit(this);
225 ////@end ctGeneralSettingsDialog content construction
227 FindWindow(ID_LOAD_LAST_DOCUMENT
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_loadLastDocument
));
228 FindWindow(ID_SHOW_TOOLTIPS
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useToolTips
));
232 * Should we show tooltips?
235 bool ctGeneralSettingsDialog::ShowToolTips()
241 * ctLocationSettingsDialog type definition
244 IMPLEMENT_CLASS( ctLocationSettingsDialog
, wxPanel
)
247 * ctLocationSettingsDialog event table definition
250 BEGIN_EVENT_TABLE( ctLocationSettingsDialog
, wxPanel
)
252 ////@begin ctLocationSettingsDialog event table entries
253 EVT_UPDATE_UI( ID_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateWxwinHierarchy
)
255 EVT_BUTTON( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnChooseWxwinHierarchy
)
256 EVT_UPDATE_UI( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy
)
258 ////@end ctLocationSettingsDialog event table entries
263 * ctLocationSettingsDialog constructor
266 ctLocationSettingsDialog::ctLocationSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
268 wxPanel::Create( parent
, id
, pos
, size
, style
);
274 * Control creation for ctLocationSettingsDialog
277 void ctLocationSettingsDialog::CreateControls()
279 ////@begin ctLocationSettingsDialog content construction
281 ctLocationSettingsDialog
* item9
= this;
283 wxBoxSizer
* item10
= new wxBoxSizer(wxVERTICAL
);
284 item9
->SetSizer(item10
);
285 item9
->SetAutoLayout(TRUE
);
287 wxStaticBox
* item11Static
= new wxStaticBox(item9
, -1, _("Locations"));
288 wxStaticBoxSizer
* item11
= new wxStaticBoxSizer(item11Static
, wxVERTICAL
);
289 item10
->Add(item11
, 1, wxGROW
|wxALL
, 5);
291 wxStaticText
* item12
= new wxStaticText(item9
, wxID_STATIC
, _("&wxWindows hierarchy:"), wxDefaultPosition
, wxDefaultSize
, 0);
292 item11
->Add(item12
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
294 wxBoxSizer
* item13
= new wxBoxSizer(wxHORIZONTAL
);
295 item11
->Add(item13
, 0, wxGROW
, 5);
297 wxTextCtrl
* item14
= new wxTextCtrl(item9
, ID_WXWIN_HIERARCHY
, _(""), wxDefaultPosition
, wxSize(200, -1), 0);
298 item13
->Add(item14
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
300 wxButton
* item15
= new wxButton(item9
, ID_CHOOSE_WXWIN_HIERARCHY
, _("&Choose..."), wxDefaultPosition
, wxDefaultSize
, 0);
301 item13
->Add(item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
303 wxBoxSizer
* item16
= new wxBoxSizer(wxHORIZONTAL
);
304 item11
->Add(item16
, 0, wxGROW
, 5);
306 item16
->Add(60, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
308 wxCheckBox
* item18
= new wxCheckBox(item9
, ID_USE_WXWIN
, _("&Use WXWIN environment variable"), wxDefaultPosition
, wxDefaultSize
, 0);
309 item18
->SetValue(FALSE
);
310 item16
->Add(item18
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
312 GetSizer()->Fit(this);
313 ////@end ctLocationSettingsDialog content construction
315 FindWindow(ID_WXWIN_HIERARCHY
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_frameworkDir
));
316 FindWindow(ID_USE_WXWIN
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useEnvironmentVariable
));
320 * Update event handler for ID_WXWIN_HIERARCHY
323 void ctLocationSettingsDialog::OnUpdateWxwinHierarchy( wxUpdateUIEvent
& event
)
325 wxCheckBox
* checkbox
= (wxCheckBox
*) FindWindow(ID_USE_WXWIN
);
326 event
.Enable(!checkbox
->GetValue());
330 * Event handler for ID_CHOOSE_WXWIN_HIERARCHY
333 void ctLocationSettingsDialog::OnChooseWxwinHierarchy( wxCommandEvent
& event
)
335 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow( ID_WXWIN_HIERARCHY
);
336 wxASSERT( textCtrl
!= NULL
);
337 wxString defaultPath
= textCtrl
->GetValue();
339 wxDirDialog
dialog(this, _("Choose the location of the wxWindows hierarchy"),
341 if (dialog
.ShowModal() == wxID_OK
)
343 textCtrl
->SetValue(dialog
.GetPath());
348 * Update event handler for ID_CHOOSE_WXWIN_HIERARCHY
351 void ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy( wxUpdateUIEvent
& event
)
353 wxCheckBox
* checkbox
= (wxCheckBox
*) FindWindow(ID_USE_WXWIN
);
354 event
.Enable(!checkbox
->GetValue());
358 * Should we show tooltips?
361 bool ctLocationSettingsDialog::ShowToolTips()
363 return wxGetApp().GetSettings().m_useToolTips
;