1 /////////////////////////////////////////////////////////////////////////////
2 // Name: settingsdialog.cpp
3 // Purpose: Settings dialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "settingsdialog.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/statline.h"
27 #include "wx/splitter.h"
28 #include "wx/scrolwin.h"
29 #include "wx/spinctrl.h"
30 #include "wx/spinbutt.h"
32 #include "wx/statbox.h"
33 #include "wx/dirdlg.h"
34 #include "wx/stattext.h"
35 #include "wx/choice.h"
39 #include "wx/cshelp.h"
40 #include "wx/notebook.h"
41 #include "wx/valgen.h"
42 #include "wxconfigtool.h"
43 #include "settingsdialog.h"
49 * ctSettingsDialog type definition
52 IMPLEMENT_CLASS( ctSettingsDialog
, wxDialog
)
55 * ctSettingsDialog event table definition
58 BEGIN_EVENT_TABLE( ctSettingsDialog
, wxDialog
)
60 ////@begin ctSettingsDialog event table entries
61 EVT_BUTTON( wxID_OK
, ctSettingsDialog::OnOk
)
63 EVT_BUTTON( wxID_CANCEL
, ctSettingsDialog::OnCancel
)
65 EVT_BUTTON( wxID_HELP
, ctSettingsDialog::OnHelp
)
67 ////@end ctSettingsDialog event table entries
72 * ctSettingsDialog constructor
75 ctSettingsDialog::ctSettingsDialog( wxWindow
* parent
)
77 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
78 wxDialog::Create( parent
, wxID_ANY
, _("Configuration Settings"));
83 * Control creation for ctSettingsDialog
86 void ctSettingsDialog::CreateControls()
88 ////@begin ctSettingsDialog content construction
90 ctSettingsDialog
* item1
= this;
92 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
93 item1
->SetSizer(item2
);
95 m_notebook
= new wxNotebook(item1
, wxID_ANY
, wxDefaultPosition
, wxSize(200, 200), wxNB_TOP
);
96 ctGeneralSettingsDialog
* item4
= new ctGeneralSettingsDialog(m_notebook
, ID_GENERAL_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
97 m_notebook
->AddPage(item4
, _("General"));
98 ctLocationSettingsDialog
* item11
= new ctLocationSettingsDialog(m_notebook
, ID_LOCATION_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
99 m_notebook
->AddPage(item11
, _("Locations"));
100 item2
->Add(m_notebook
, 0, wxGROW
|wxALL
, 5);
102 wxBoxSizer
* item21
= new wxBoxSizer(wxHORIZONTAL
);
103 item2
->Add(item21
, 0, wxGROW
|wxALL
, 5);
105 item21
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
107 wxButton
* item23
= new wxButton(item1
, wxID_OK
);
108 item23
->SetDefault();
109 item21
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
111 wxButton
* item24
= new wxButton(item1
, wxID_CANCEL
);
112 item21
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
114 wxButton
* item25
= new wxButton(item1
, wxID_HELP
);
115 item21
->Add(item25
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
117 #if defined(__WXGTK__) || defined(__WXMAC__)
118 wxContextHelpButton
* item26
= new wxContextHelpButton(item1
, wxID_CONTEXT_HELP
, wxDefaultPosition
, wxSize(20, wxDefaultCoord
), wxBU_AUTODRAW
);
119 item21
->Add(item26
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
122 GetSizer()->Fit(this);
123 GetSizer()->SetSizeHints(this);
125 ////@end ctSettingsDialog content construction
129 * Event handler for wxID_OK
132 void ctSettingsDialog::OnOk( wxCommandEvent
& event
)
134 // Replace with custom code
139 * Event handler for wxID_CANCEL
142 void ctSettingsDialog::OnCancel( wxCommandEvent
& event
)
144 // Replace with custom code
149 * Event handler for wxID_HELP
152 void ctSettingsDialog::OnHelp( wxCommandEvent
& WXUNUSED(event
) )
156 int sel
= m_notebook
->GetSelection();
158 wxASSERT_MSG( (sel
!= -1), wxT("A notebook tab should always be selected."));
160 wxWindow
* page
= (wxWindow
*) m_notebook
->GetPage(sel
);
163 if (page
->GetId() == ID_GENERAL_SETTINGS_DIALOG
)
165 helpTopic
= wxT("General settings dialog");
167 else if (page
->GetId() == ID_LOCATION_SETTINGS_DIALOG
)
169 helpTopic
= wxT("Location settings dialog");
172 if (!helpTopic
.empty())
174 wxGetApp().GetHelpController().DisplaySection(helpTopic
);
180 * Should we show tooltips?
183 bool ctSettingsDialog::ShowToolTips()
189 * ctGeneralSettingsDialog type definition
192 IMPLEMENT_CLASS( ctGeneralSettingsDialog
, wxPanel
)
195 * ctGeneralSettingsDialog event table definition
198 BEGIN_EVENT_TABLE( ctGeneralSettingsDialog
, wxPanel
)
200 ////@begin ctGeneralSettingsDialog event table entries
201 ////@end ctGeneralSettingsDialog event table entries
206 * ctGeneralSettingsDialog constructor
209 ctGeneralSettingsDialog::ctGeneralSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
211 wxPanel::Create( parent
, id
, pos
, size
, style
);
217 * Control creation for ctGeneralSettingsDialog
220 void ctGeneralSettingsDialog::CreateControls()
222 ////@begin ctGeneralSettingsDialog content construction
224 ctGeneralSettingsDialog
* item4
= this;
226 wxBoxSizer
* item5
= new wxBoxSizer(wxVERTICAL
);
227 item4
->SetSizer(item5
);
229 wxStaticBox
* item6Static
= new wxStaticBox(item4
, wxID_ANY
, _("General settings"));
230 wxStaticBoxSizer
* item6
= new wxStaticBoxSizer(item6Static
, wxVERTICAL
);
231 item5
->Add(item6
, 1, wxGROW
|wxALL
, 5);
233 wxCheckBox
* item7
= new wxCheckBox(item4
, ID_LOAD_LAST_DOCUMENT
, _("&Load last document"), wxDefaultPosition
, wxDefaultSize
, 0);
234 item7
->SetValue(false);
235 item7
->SetHelpText(_("Check to load the last document on startup"));
238 item7
->SetToolTip(_("Check to load the last document on startup"));
240 item6
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
, 5);
242 wxCheckBox
* item8
= new wxCheckBox(item4
, ID_SHOW_TOOLTIPS
, _("&Show tooltips"), wxDefaultPosition
, wxDefaultSize
, 0);
243 item8
->SetValue(false);
244 item8
->SetHelpText(_("Check to show tooltips"));
247 item8
->SetToolTip(_("Check to show tooltips"));
249 item6
->Add(item8
, 0, wxALIGN_LEFT
|wxALL
, 5);
251 wxStaticText
* item9
= new wxStaticText(item4
, wxID_STATIC
, _("&Default file kind to save when using the Go command:"), wxDefaultPosition
, wxDefaultSize
, 0);
252 item6
->Add(item9
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
254 wxString item10Strings
[] = {
256 _("Configure script")
258 wxChoice
* item10
= new wxChoice(item4
, ID_DEFAULT_FILE_KIND
, wxDefaultPosition
, wxSize(200, wxDefaultCoord
), 2, item10Strings
, 0);
259 item10
->SetStringSelection(_("Setup file"));
260 item10
->SetHelpText(_("Select the default kind of file to save using Go"));
263 item10
->SetToolTip(_("Select the default kind of file to save using Go"));
265 item6
->Add(item10
, 0, wxGROW
|wxALL
, 5);
267 GetSizer()->Fit(this);
268 ////@end ctGeneralSettingsDialog content construction
270 item7
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_loadLastDocument
));
271 item8
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useToolTips
));
272 item10
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_defaultFileKind
));
276 * Should we show tooltips?
279 bool ctGeneralSettingsDialog::ShowToolTips()
285 * ctLocationSettingsDialog type definition
288 IMPLEMENT_CLASS( ctLocationSettingsDialog
, wxPanel
)
291 * ctLocationSettingsDialog event table definition
294 BEGIN_EVENT_TABLE( ctLocationSettingsDialog
, wxPanel
)
296 ////@begin ctLocationSettingsDialog event table entries
297 EVT_UPDATE_UI( ID_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateWxwinHierarchy
)
299 EVT_BUTTON( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnChooseWxwinHierarchy
)
300 EVT_UPDATE_UI( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy
)
302 ////@end ctLocationSettingsDialog event table entries
307 * ctLocationSettingsDialog constructor
310 ctLocationSettingsDialog::ctLocationSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
312 wxPanel::Create( parent
, id
, pos
, size
, style
);
318 * Control creation for ctLocationSettingsDialog
321 void ctLocationSettingsDialog::CreateControls()
323 ////@begin ctLocationSettingsDialog content construction
325 ctLocationSettingsDialog
* item11
= this;
327 wxBoxSizer
* item12
= new wxBoxSizer(wxVERTICAL
);
328 item11
->SetSizer(item12
);
330 wxStaticBox
* item13Static
= new wxStaticBox(item11
, wxID_ANY
, _("Locations"));
331 wxStaticBoxSizer
* item13
= new wxStaticBoxSizer(item13Static
, wxVERTICAL
);
332 item12
->Add(item13
, 1, wxGROW
|wxALL
, 5);
334 wxStaticText
* item14
= new wxStaticText(item11
, wxID_STATIC
, _("&wxWidgets hierarchy:"), wxDefaultPosition
, wxDefaultSize
, 0);
335 item13
->Add(item14
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
337 wxBoxSizer
* item15
= new wxBoxSizer(wxHORIZONTAL
);
338 item13
->Add(item15
, 0, wxGROW
, 5);
340 m_wxWinHierarchy
= new wxTextCtrl(item11
, ID_WXWIN_HIERARCHY
, wxEmptyString
, wxDefaultPosition
, wxSize(200, wxDefaultCoord
), 0);
341 m_wxWinHierarchy
->SetHelpText(_("Enter the root path of the wxWidgets hierarchy"));
344 m_wxWinHierarchy
->SetToolTip(_("Enter the root path of the wxWidgets hierarchy"));
346 item15
->Add(m_wxWinHierarchy
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
348 wxButton
* item17
= new wxButton(item11
, ID_CHOOSE_WXWIN_HIERARCHY
, _("&Choose..."), wxDefaultPosition
, wxDefaultSize
, 0);
349 item17
->SetHelpText(_("Click to choose the root path of the wxWidgets hierarchy\\n"));
352 item17
->SetToolTip(_("Click to choose the root path of the wxWidgets hierarchy\\n"));
354 item15
->Add(item17
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
356 wxBoxSizer
* item18
= new wxBoxSizer(wxHORIZONTAL
);
357 item13
->Add(item18
, 0, wxGROW
, 5);
359 item18
->Add(60, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
361 m_wxWinUse
= new wxCheckBox(item11
, ID_USE_WXWIN
, _("&Use WXWIN environment variable"));
362 m_wxWinUse
->SetValue(false);
363 m_wxWinUse
->SetHelpText(_("Check to use the value of WXWIN instead"));
366 m_wxWinUse
->SetToolTip(_("Check to use the value of WXWIN instead"));
368 item18
->Add(m_wxWinUse
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
370 GetSizer()->Fit(this);
371 ////@end ctLocationSettingsDialog content construction
373 m_wxWinHierarchy
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_frameworkDir
));
374 m_wxWinUse
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useEnvironmentVariable
));
378 * Update event handler for ID_WXWIN_HIERARCHY
381 void ctLocationSettingsDialog::OnUpdateWxwinHierarchy( wxUpdateUIEvent
& event
)
384 event
.Enable(!m_wxWinUse
->GetValue());
388 * Event handler for ID_CHOOSE_WXWIN_HIERARCHY
391 void ctLocationSettingsDialog::OnChooseWxwinHierarchy( wxCommandEvent
& WXUNUSED(event
) )
393 if (m_wxWinHierarchy
)
395 wxString defaultPath
= m_wxWinHierarchy
->GetValue();
397 wxDirDialog
dialog(this, _("Choose the location of the wxWidgets hierarchy"),
399 if (dialog
.ShowModal() == wxID_OK
)
401 m_wxWinHierarchy
->SetValue(dialog
.GetPath());
407 * Update event handler for ID_CHOOSE_WXWIN_HIERARCHY
410 void ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy( wxUpdateUIEvent
& event
)
413 event
.Enable(!m_wxWinUse
->GetValue());
417 * Should we show tooltips?
420 bool ctLocationSettingsDialog::ShowToolTips()
422 return wxGetApp().GetSettings().m_useToolTips
;