1 /////////////////////////////////////////////////////////////////////////////
2 // Name: settingsdialog.cpp
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "settingsdialog.h"
17 #include "wx/cshelp.h"
18 #include "wx/statline.h"
19 #include "wx/splitter.h"
20 #include "wx/scrolwin.h"
21 #include "wx/spinctrl.h"
22 #include "wx/spinbutt.h"
23 #include "wx/valgen.h"
24 #include "wx/notebook.h"
26 #include "wxconfigtool.h"
27 #include "settingsdialog.h"
33 * ctSettingsDialog type definition
36 IMPLEMENT_CLASS( ctSettingsDialog
, wxDialog
)
39 * ctSettingsDialog event table definition
42 BEGIN_EVENT_TABLE( ctSettingsDialog
, wxDialog
)
44 ////@begin ctSettingsDialog event table entries
45 EVT_BUTTON( wxID_OK
, ctSettingsDialog::OnOk
)
47 EVT_BUTTON( wxID_CANCEL
, ctSettingsDialog::OnCancel
)
49 EVT_BUTTON( wxID_HELP
, ctSettingsDialog::OnHelp
)
51 ////@end ctSettingsDialog event table entries
56 * ctSettingsDialog constructor
59 ctSettingsDialog::ctSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
61 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
62 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
68 * Control creation for ctSettingsDialog
71 void ctSettingsDialog::CreateControls()
73 ////@begin ctSettingsDialog content construction
75 ctSettingsDialog
* item1
= this;
77 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
78 item1
->SetSizer(item2
);
79 item1
->SetAutoLayout(TRUE
);
81 wxNotebook
* item3
= new wxNotebook(item1
, ID_NOTEBOOK
, wxDefaultPosition
, wxSize(200, 200), wxNB_TOP
);
82 wxNotebookSizer
* item3Sizer
= new wxNotebookSizer(item3
);
83 ctGeneralSettingsDialog
* item4
= new ctGeneralSettingsDialog(item3
, ID_GENERAL_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
84 item3
->AddPage(item4
, _("General"));
85 ctLocationSettingsDialog
* item9
= new ctLocationSettingsDialog(item3
, ID_LOCATION_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
86 item3
->AddPage(item9
, _("Locations"));
87 item2
->Add(item3Sizer
, 0, wxGROW
|wxALL
, 5);
89 wxBoxSizer
* item19
= new wxBoxSizer(wxHORIZONTAL
);
90 item2
->Add(item19
, 0, wxGROW
|wxALL
, 5);
92 item19
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
94 wxButton
* item21
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
96 item19
->Add(item21
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
98 wxButton
* item22
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
99 item19
->Add(item22
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
101 wxButton
* item23
= new wxButton(item1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0);
102 item19
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
104 #if defined(__WXGTK__) || defined(__WXMAC__)
105 wxContextHelpButton
* item24
= new wxContextHelpButton(item1
, wxID_CONTEXT_HELP
, wxDefaultPosition
, wxSize(20, -1), wxBU_AUTODRAW
);
106 item19
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
109 GetSizer()->Fit(this);
110 GetSizer()->SetSizeHints(this);
112 ////@end ctSettingsDialog content construction
116 * Event handler for wxID_OK
119 void ctSettingsDialog::OnOk( wxCommandEvent
& event
)
121 // Replace with custom code
126 * Event handler for wxID_CANCEL
129 void ctSettingsDialog::OnCancel( wxCommandEvent
& event
)
131 // Replace with custom code
136 * Event handler for wxID_HELP
139 void ctSettingsDialog::OnHelp( wxCommandEvent
& event
)
141 wxNotebook
* notebook
= (wxNotebook
*) FindWindow(ID_NOTEBOOK
);
143 int sel
= notebook
->GetSelection();
145 wxASSERT_MSG( (sel
!= -1), wxT("A notebook tab should always be selected."));
147 wxWindow
* page
= (wxWindow
*) notebook
->GetPage(sel
);
150 if (page
->GetId() == ID_GENERAL_SETTINGS_DIALOG
)
152 helpTopic
= wxT("General settings dialog");
154 else if (page
->GetId() == ID_LOCATION_SETTINGS_DIALOG
)
156 helpTopic
= wxT("Location dialog");
159 if (!helpTopic
.IsEmpty())
161 wxGetApp().GetHelpController().DisplaySection(helpTopic
);
166 * Should we show tooltips?
169 bool ctSettingsDialog::ShowToolTips()
175 * ctGeneralSettingsDialog type definition
178 IMPLEMENT_CLASS( ctGeneralSettingsDialog
, wxPanel
)
181 * ctGeneralSettingsDialog event table definition
184 BEGIN_EVENT_TABLE( ctGeneralSettingsDialog
, wxPanel
)
186 ////@begin ctGeneralSettingsDialog event table entries
187 ////@end ctGeneralSettingsDialog event table entries
192 * ctGeneralSettingsDialog constructor
195 ctGeneralSettingsDialog::ctGeneralSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
197 wxPanel::Create( parent
, id
, pos
, size
, style
);
203 * Control creation for ctGeneralSettingsDialog
206 void ctGeneralSettingsDialog::CreateControls()
208 ////@begin ctGeneralSettingsDialog content construction
210 ctGeneralSettingsDialog
* item4
= this;
212 wxBoxSizer
* item5
= new wxBoxSizer(wxVERTICAL
);
213 item4
->SetSizer(item5
);
214 item4
->SetAutoLayout(TRUE
);
216 wxStaticBox
* item6Static
= new wxStaticBox(item4
, -1, _("General settings"));
217 wxStaticBoxSizer
* item6
= new wxStaticBoxSizer(item6Static
, wxVERTICAL
);
218 item5
->Add(item6
, 1, wxGROW
|wxALL
, 5);
220 wxCheckBox
* item7
= new wxCheckBox(item4
, ID_LOAD_LAST_DOCUMENT
, _("&Load last document"), wxDefaultPosition
, wxDefaultSize
, 0);
221 item7
->SetValue(FALSE
);
222 item6
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
, 5);
224 wxCheckBox
* item8
= new wxCheckBox(item4
, ID_SHOW_TOOLTIPS
, _("&Show tooltips"), wxDefaultPosition
, wxDefaultSize
, 0);
225 item8
->SetValue(FALSE
);
226 item6
->Add(item8
, 0, wxALIGN_LEFT
|wxALL
, 5);
228 GetSizer()->Fit(this);
229 ////@end ctGeneralSettingsDialog content construction
231 FindWindow(ID_LOAD_LAST_DOCUMENT
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_loadLastDocument
));
232 FindWindow(ID_SHOW_TOOLTIPS
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useToolTips
));
236 * Should we show tooltips?
239 bool ctGeneralSettingsDialog::ShowToolTips()
245 * ctLocationSettingsDialog type definition
248 IMPLEMENT_CLASS( ctLocationSettingsDialog
, wxPanel
)
251 * ctLocationSettingsDialog event table definition
254 BEGIN_EVENT_TABLE( ctLocationSettingsDialog
, wxPanel
)
256 ////@begin ctLocationSettingsDialog event table entries
257 EVT_UPDATE_UI( ID_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateWxwinHierarchy
)
259 EVT_BUTTON( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnChooseWxwinHierarchy
)
260 EVT_UPDATE_UI( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy
)
262 ////@end ctLocationSettingsDialog event table entries
267 * ctLocationSettingsDialog constructor
270 ctLocationSettingsDialog::ctLocationSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
272 wxPanel::Create( parent
, id
, pos
, size
, style
);
278 * Control creation for ctLocationSettingsDialog
281 void ctLocationSettingsDialog::CreateControls()
283 ////@begin ctLocationSettingsDialog content construction
285 ctLocationSettingsDialog
* item9
= this;
287 wxBoxSizer
* item10
= new wxBoxSizer(wxVERTICAL
);
288 item9
->SetSizer(item10
);
289 item9
->SetAutoLayout(TRUE
);
291 wxStaticBox
* item11Static
= new wxStaticBox(item9
, -1, _("Locations"));
292 wxStaticBoxSizer
* item11
= new wxStaticBoxSizer(item11Static
, wxVERTICAL
);
293 item10
->Add(item11
, 1, wxGROW
|wxALL
, 5);
295 wxStaticText
* item12
= new wxStaticText(item9
, wxID_STATIC
, _("&wxWindows hierarchy:"), wxDefaultPosition
, wxDefaultSize
, 0);
296 item11
->Add(item12
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
298 wxBoxSizer
* item13
= new wxBoxSizer(wxHORIZONTAL
);
299 item11
->Add(item13
, 0, wxGROW
, 5);
301 wxTextCtrl
* item14
= new wxTextCtrl(item9
, ID_WXWIN_HIERARCHY
, _(""), wxDefaultPosition
, wxSize(200, -1), 0);
302 item13
->Add(item14
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
304 wxButton
* item15
= new wxButton(item9
, ID_CHOOSE_WXWIN_HIERARCHY
, _("&Choose..."), wxDefaultPosition
, wxDefaultSize
, 0);
305 item13
->Add(item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
307 wxBoxSizer
* item16
= new wxBoxSizer(wxHORIZONTAL
);
308 item11
->Add(item16
, 0, wxGROW
, 5);
310 item16
->Add(60, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
312 wxCheckBox
* item18
= new wxCheckBox(item9
, ID_USE_WXWIN
, _("&Use WXWIN environment variable"), wxDefaultPosition
, wxDefaultSize
, 0);
313 item18
->SetValue(FALSE
);
314 item16
->Add(item18
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
316 GetSizer()->Fit(this);
317 ////@end ctLocationSettingsDialog content construction
319 FindWindow(ID_WXWIN_HIERARCHY
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_frameworkDir
));
320 FindWindow(ID_USE_WXWIN
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useEnvironmentVariable
));
324 * Update event handler for ID_WXWIN_HIERARCHY
327 void ctLocationSettingsDialog::OnUpdateWxwinHierarchy( wxUpdateUIEvent
& event
)
329 wxCheckBox
* checkbox
= (wxCheckBox
*) FindWindow(ID_USE_WXWIN
);
330 event
.Enable(!checkbox
->GetValue());
334 * Event handler for ID_CHOOSE_WXWIN_HIERARCHY
337 void ctLocationSettingsDialog::OnChooseWxwinHierarchy( wxCommandEvent
& event
)
339 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow( ID_WXWIN_HIERARCHY
);
340 wxASSERT( textCtrl
!= NULL
);
341 wxString defaultPath
= textCtrl
->GetValue();
343 wxDirDialog
dialog(this, _("Choose the location of the wxWindows hierarchy"),
345 if (dialog
.ShowModal() == wxID_OK
)
347 textCtrl
->SetValue(dialog
.GetPath());
352 * Update event handler for ID_CHOOSE_WXWIN_HIERARCHY
355 void ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy( wxUpdateUIEvent
& event
)
357 wxCheckBox
* checkbox
= (wxCheckBox
*) FindWindow(ID_USE_WXWIN
);
358 event
.Enable(!checkbox
->GetValue());
362 * Should we show tooltips?
365 bool ctLocationSettingsDialog::ShowToolTips()
367 return wxGetApp().GetSettings().m_useToolTips
;