1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utils/configtool/src/settingsdialog.cpp
3 // Purpose: Settings dialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/statline.h"
23 #include "wx/splitter.h"
24 #include "wx/scrolwin.h"
25 #include "wx/spinctrl.h"
26 #include "wx/spinbutt.h"
28 #include "wx/statbox.h"
29 #include "wx/dirdlg.h"
30 #include "wx/stattext.h"
31 #include "wx/choice.h"
35 #include "wx/cshelp.h"
36 #include "wx/notebook.h"
37 #include "wx/valgen.h"
38 #include "wxconfigtool.h"
39 #include "settingsdialog.h"
45 * ctSettingsDialog type definition
48 IMPLEMENT_CLASS( ctSettingsDialog
, wxDialog
)
51 * ctSettingsDialog event table definition
54 BEGIN_EVENT_TABLE( ctSettingsDialog
, wxDialog
)
56 ////@begin ctSettingsDialog event table entries
57 EVT_BUTTON( wxID_OK
, ctSettingsDialog::OnOk
)
59 EVT_BUTTON( wxID_CANCEL
, ctSettingsDialog::OnCancel
)
61 EVT_BUTTON( wxID_HELP
, ctSettingsDialog::OnHelp
)
63 ////@end ctSettingsDialog event table entries
68 * ctSettingsDialog constructor
71 ctSettingsDialog::ctSettingsDialog( wxWindow
* parent
)
73 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
74 wxDialog::Create( parent
, wxID_ANY
, _("Configuration Settings"));
79 * Control creation for ctSettingsDialog
82 void ctSettingsDialog::CreateControls()
84 ////@begin ctSettingsDialog content construction
86 ctSettingsDialog
* item1
= this;
88 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
89 item1
->SetSizer(item2
);
91 m_notebook
= new wxNotebook(item1
, wxID_ANY
, wxDefaultPosition
, wxSize(200, 200), wxBK_TOP
);
92 ctGeneralSettingsDialog
* item4
= new ctGeneralSettingsDialog(m_notebook
, ID_GENERAL_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
93 m_notebook
->AddPage(item4
, _("General"));
94 ctLocationSettingsDialog
* item11
= new ctLocationSettingsDialog(m_notebook
, ID_LOCATION_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
95 m_notebook
->AddPage(item11
, _("Locations"));
96 item2
->Add(m_notebook
, 0, wxGROW
|wxALL
, 5);
98 wxBoxSizer
* item21
= new wxBoxSizer(wxHORIZONTAL
);
99 item2
->Add(item21
, 0, wxGROW
|wxALL
, 5);
101 item21
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
103 wxButton
* item23
= new wxButton(item1
, wxID_OK
);
104 item23
->SetDefault();
105 item21
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
107 wxButton
* item24
= new wxButton(item1
, wxID_CANCEL
);
108 item21
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
110 wxButton
* item25
= new wxButton(item1
, wxID_HELP
);
111 item21
->Add(item25
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
113 #if defined(__WXGTK__) || defined(__WXMAC__)
114 wxContextHelpButton
* item26
= new wxContextHelpButton(item1
, wxID_CONTEXT_HELP
, wxDefaultPosition
, wxSize(20, wxDefaultCoord
), wxBU_AUTODRAW
);
115 item21
->Add(item26
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
118 GetSizer()->Fit(this);
119 GetSizer()->SetSizeHints(this);
121 ////@end ctSettingsDialog content construction
125 * Event handler for wxID_OK
128 void ctSettingsDialog::OnOk( wxCommandEvent
& event
)
130 // Replace with custom code
135 * Event handler for wxID_CANCEL
138 void ctSettingsDialog::OnCancel( wxCommandEvent
& event
)
140 // Replace with custom code
145 * Event handler for wxID_HELP
148 void ctSettingsDialog::OnHelp( wxCommandEvent
& WXUNUSED(event
) )
152 int sel
= m_notebook
->GetSelection();
154 wxASSERT_MSG( (sel
!= -1), wxT("A notebook tab should always be selected."));
156 wxWindow
* page
= (wxWindow
*) m_notebook
->GetPage(sel
);
159 if (page
->GetId() == ID_GENERAL_SETTINGS_DIALOG
)
161 helpTopic
= wxT("General settings dialog");
163 else if (page
->GetId() == ID_LOCATION_SETTINGS_DIALOG
)
165 helpTopic
= wxT("Location settings dialog");
168 if (!helpTopic
.empty())
170 wxGetApp().GetHelpController().DisplaySection(helpTopic
);
176 * Should we show tooltips?
179 bool ctSettingsDialog::ShowToolTips()
185 * ctGeneralSettingsDialog type definition
188 IMPLEMENT_CLASS( ctGeneralSettingsDialog
, wxPanel
)
191 * ctGeneralSettingsDialog event table definition
194 BEGIN_EVENT_TABLE( ctGeneralSettingsDialog
, wxPanel
)
196 ////@begin ctGeneralSettingsDialog event table entries
197 ////@end ctGeneralSettingsDialog event table entries
202 * ctGeneralSettingsDialog constructor
205 ctGeneralSettingsDialog::ctGeneralSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
207 wxPanel::Create( parent
, id
, pos
, size
, style
);
213 * Control creation for ctGeneralSettingsDialog
216 void ctGeneralSettingsDialog::CreateControls()
218 ////@begin ctGeneralSettingsDialog content construction
220 ctGeneralSettingsDialog
* item4
= this;
222 wxBoxSizer
* item5
= new wxBoxSizer(wxVERTICAL
);
223 item4
->SetSizer(item5
);
225 wxStaticBox
* item6Static
= new wxStaticBox(item4
, wxID_ANY
, _("General settings"));
226 wxStaticBoxSizer
* item6
= new wxStaticBoxSizer(item6Static
, wxVERTICAL
);
227 item5
->Add(item6
, 1, wxGROW
|wxALL
, 5);
229 wxCheckBox
* item7
= new wxCheckBox(item4
, ID_LOAD_LAST_DOCUMENT
, _("&Load last document"), wxDefaultPosition
, wxDefaultSize
, 0);
230 item7
->SetValue(false);
231 item7
->SetHelpText(_("Check to load the last document on startup"));
234 item7
->SetToolTip(_("Check to load the last document on startup"));
236 item6
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
, 5);
238 wxCheckBox
* item8
= new wxCheckBox(item4
, ID_SHOW_TOOLTIPS
, _("&Show tooltips"), wxDefaultPosition
, wxDefaultSize
, 0);
239 item8
->SetValue(false);
240 item8
->SetHelpText(_("Check to show tooltips"));
243 item8
->SetToolTip(_("Check to show tooltips"));
245 item6
->Add(item8
, 0, wxALIGN_LEFT
|wxALL
, 5);
247 wxStaticText
* item9
= new wxStaticText(item4
, wxID_STATIC
, _("&Default file kind to save when using the Go command:"), wxDefaultPosition
, wxDefaultSize
, 0);
248 item6
->Add(item9
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
250 wxString item10Strings
[] = {
252 _("Configure script")
254 wxChoice
* item10
= new wxChoice(item4
, ID_DEFAULT_FILE_KIND
, wxDefaultPosition
, wxSize(200, wxDefaultCoord
), 2, item10Strings
, 0);
255 item10
->SetStringSelection(_("Setup file"));
256 item10
->SetHelpText(_("Select the default kind of file to save using Go"));
259 item10
->SetToolTip(_("Select the default kind of file to save using Go"));
261 item6
->Add(item10
, 0, wxGROW
|wxALL
, 5);
263 GetSizer()->Fit(this);
264 ////@end ctGeneralSettingsDialog content construction
266 item7
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_loadLastDocument
));
267 item8
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useToolTips
));
268 item10
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_defaultFileKind
));
272 * Should we show tooltips?
275 bool ctGeneralSettingsDialog::ShowToolTips()
281 * ctLocationSettingsDialog type definition
284 IMPLEMENT_CLASS( ctLocationSettingsDialog
, wxPanel
)
287 * ctLocationSettingsDialog event table definition
290 BEGIN_EVENT_TABLE( ctLocationSettingsDialog
, wxPanel
)
292 ////@begin ctLocationSettingsDialog event table entries
293 EVT_UPDATE_UI( ID_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateWxwinHierarchy
)
295 EVT_BUTTON( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnChooseWxwinHierarchy
)
296 EVT_UPDATE_UI( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy
)
298 ////@end ctLocationSettingsDialog event table entries
303 * ctLocationSettingsDialog constructor
306 ctLocationSettingsDialog::ctLocationSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
308 wxPanel::Create( parent
, id
, pos
, size
, style
);
314 * Control creation for ctLocationSettingsDialog
317 void ctLocationSettingsDialog::CreateControls()
319 ////@begin ctLocationSettingsDialog content construction
321 ctLocationSettingsDialog
* item11
= this;
323 wxBoxSizer
* item12
= new wxBoxSizer(wxVERTICAL
);
324 item11
->SetSizer(item12
);
326 wxStaticBox
* item13Static
= new wxStaticBox(item11
, wxID_ANY
, _("Locations"));
327 wxStaticBoxSizer
* item13
= new wxStaticBoxSizer(item13Static
, wxVERTICAL
);
328 item12
->Add(item13
, 1, wxGROW
|wxALL
, 5);
330 wxStaticText
* item14
= new wxStaticText(item11
, wxID_STATIC
, _("&wxWidgets hierarchy:"), wxDefaultPosition
, wxDefaultSize
, 0);
331 item13
->Add(item14
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
333 wxBoxSizer
* item15
= new wxBoxSizer(wxHORIZONTAL
);
334 item13
->Add(item15
, 0, wxGROW
, 5);
336 m_wxWinHierarchy
= new wxTextCtrl(item11
, ID_WXWIN_HIERARCHY
, wxEmptyString
, wxDefaultPosition
, wxSize(200, wxDefaultCoord
), 0);
337 m_wxWinHierarchy
->SetHelpText(_("Enter the root path of the wxWidgets hierarchy"));
340 m_wxWinHierarchy
->SetToolTip(_("Enter the root path of the wxWidgets hierarchy"));
342 item15
->Add(m_wxWinHierarchy
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
344 wxButton
* item17
= new wxButton(item11
, ID_CHOOSE_WXWIN_HIERARCHY
, _("&Choose..."), wxDefaultPosition
, wxDefaultSize
, 0);
345 item17
->SetHelpText(_("Click to choose the root path of the wxWidgets hierarchy\\n"));
348 item17
->SetToolTip(_("Click to choose the root path of the wxWidgets hierarchy\\n"));
350 item15
->Add(item17
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
352 wxBoxSizer
* item18
= new wxBoxSizer(wxHORIZONTAL
);
353 item13
->Add(item18
, 0, wxGROW
, 5);
355 item18
->Add(60, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
357 m_wxWinUse
= new wxCheckBox(item11
, ID_USE_WXWIN
, _("&Use WXWIN environment variable"));
358 m_wxWinUse
->SetValue(false);
359 m_wxWinUse
->SetHelpText(_("Check to use the value of WXWIN instead"));
362 m_wxWinUse
->SetToolTip(_("Check to use the value of WXWIN instead"));
364 item18
->Add(m_wxWinUse
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
366 GetSizer()->Fit(this);
367 ////@end ctLocationSettingsDialog content construction
369 m_wxWinHierarchy
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_frameworkDir
));
370 m_wxWinUse
->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useEnvironmentVariable
));
374 * Update event handler for ID_WXWIN_HIERARCHY
377 void ctLocationSettingsDialog::OnUpdateWxwinHierarchy( wxUpdateUIEvent
& event
)
380 event
.Enable(!m_wxWinUse
->GetValue());
384 * Event handler for ID_CHOOSE_WXWIN_HIERARCHY
387 void ctLocationSettingsDialog::OnChooseWxwinHierarchy( wxCommandEvent
& WXUNUSED(event
) )
389 if (m_wxWinHierarchy
)
391 wxString defaultPath
= m_wxWinHierarchy
->GetValue();
393 wxDirDialog
dialog(this, _("Choose the location of the wxWidgets hierarchy"),
395 if (dialog
.ShowModal() == wxID_OK
)
397 m_wxWinHierarchy
->SetValue(dialog
.GetPath());
403 * Update event handler for ID_CHOOSE_WXWIN_HIERARCHY
406 void ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy( wxUpdateUIEvent
& event
)
409 event
.Enable(!m_wxWinUse
->GetValue());
413 * Should we show tooltips?
416 bool ctLocationSettingsDialog::ShowToolTips()
418 return wxGetApp().GetSettings().m_useToolTips
;