1 /////////////////////////////////////////////////////////////////////////////
2 // Name: settingsdialog.cpp
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
* item11
= new ctLocationSettingsDialog(item3
, ID_LOCATION_SETTINGS_DIALOG
, wxDefaultPosition
, wxSize(100, 80), 0);
86 item3
->AddPage(item11
, _("Locations"));
87 item2
->Add(item3Sizer
, 0, wxGROW
|wxALL
, 5);
89 wxBoxSizer
* item21
= new wxBoxSizer(wxHORIZONTAL
);
90 item2
->Add(item21
, 0, wxGROW
|wxALL
, 5);
92 item21
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
94 wxButton
* item23
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
96 item21
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
98 wxButton
* item24
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
99 item21
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
101 wxButton
* item25
= new wxButton(item1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0);
102 item21
->Add(item25
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
104 #if defined(__WXGTK__) || defined(__WXMAC__)
105 wxContextHelpButton
* item26
= new wxContextHelpButton(item1
, wxID_CONTEXT_HELP
, wxDefaultPosition
, wxSize(20, -1), wxBU_AUTODRAW
);
106 item21
->Add(item26
, 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
& WXUNUSED(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 settings 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 item7
->SetHelpText(_("Check to load the last document on startup"));
225 item7
->SetToolTip(_("Check to load the last document on startup"));
227 item6
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
, 5);
229 wxCheckBox
* item8
= new wxCheckBox(item4
, ID_SHOW_TOOLTIPS
, _("&Show tooltips"), wxDefaultPosition
, wxDefaultSize
, 0);
230 item8
->SetValue(FALSE
);
231 item8
->SetHelpText(_("Check to show tooltips"));
234 item8
->SetToolTip(_("Check to show tooltips"));
236 item6
->Add(item8
, 0, wxALIGN_LEFT
|wxALL
, 5);
238 wxStaticText
* item9
= new wxStaticText(item4
, wxID_STATIC
, _("&Default file kind to save when using the Go command:"), wxDefaultPosition
, wxDefaultSize
, 0);
239 item6
->Add(item9
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
|wxADJUST_MINSIZE
, 5);
241 wxString item10Strings
[] = {
243 _("Configure script")
245 wxChoice
* item10
= new wxChoice(item4
, ID_DEFAULT_FILE_KIND
, wxDefaultPosition
, wxSize(200, -1), 2, item10Strings
, 0);
246 item10
->SetStringSelection(_("Setup file"));
247 item10
->SetHelpText(_("Select the default kind of file to save using Go"));
250 item10
->SetToolTip(_("Select the default kind of file to save using Go"));
252 item6
->Add(item10
, 0, wxGROW
|wxALL
, 5);
254 GetSizer()->Fit(this);
255 ////@end ctGeneralSettingsDialog content construction
257 FindWindow(ID_LOAD_LAST_DOCUMENT
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_loadLastDocument
));
258 FindWindow(ID_SHOW_TOOLTIPS
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useToolTips
));
259 FindWindow(ID_DEFAULT_FILE_KIND
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_defaultFileKind
));
263 * Should we show tooltips?
266 bool ctGeneralSettingsDialog::ShowToolTips()
272 * ctLocationSettingsDialog type definition
275 IMPLEMENT_CLASS( ctLocationSettingsDialog
, wxPanel
)
278 * ctLocationSettingsDialog event table definition
281 BEGIN_EVENT_TABLE( ctLocationSettingsDialog
, wxPanel
)
283 ////@begin ctLocationSettingsDialog event table entries
284 EVT_UPDATE_UI( ID_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateWxwinHierarchy
)
286 EVT_BUTTON( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnChooseWxwinHierarchy
)
287 EVT_UPDATE_UI( ID_CHOOSE_WXWIN_HIERARCHY
, ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy
)
289 ////@end ctLocationSettingsDialog event table entries
294 * ctLocationSettingsDialog constructor
297 ctLocationSettingsDialog::ctLocationSettingsDialog( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
299 wxPanel::Create( parent
, id
, pos
, size
, style
);
305 * Control creation for ctLocationSettingsDialog
308 void ctLocationSettingsDialog::CreateControls()
310 ////@begin ctLocationSettingsDialog content construction
312 ctLocationSettingsDialog
* item11
= this;
314 wxBoxSizer
* item12
= new wxBoxSizer(wxVERTICAL
);
315 item11
->SetSizer(item12
);
316 item11
->SetAutoLayout(TRUE
);
318 wxStaticBox
* item13Static
= new wxStaticBox(item11
, -1, _("Locations"));
319 wxStaticBoxSizer
* item13
= new wxStaticBoxSizer(item13Static
, wxVERTICAL
);
320 item12
->Add(item13
, 1, wxGROW
|wxALL
, 5);
322 wxStaticText
* item14
= new wxStaticText(item11
, wxID_STATIC
, _("&wxWindows hierarchy:"), wxDefaultPosition
, wxDefaultSize
, 0);
323 item13
->Add(item14
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
325 wxBoxSizer
* item15
= new wxBoxSizer(wxHORIZONTAL
);
326 item13
->Add(item15
, 0, wxGROW
, 5);
328 wxTextCtrl
* item16
= new wxTextCtrl(item11
, ID_WXWIN_HIERARCHY
, _(""), wxDefaultPosition
, wxSize(200, -1), 0);
329 item16
->SetHelpText(_("Enter the root path of the wxWindows hierarchy"));
332 item16
->SetToolTip(_("Enter the root path of the wxWindows hierarchy"));
334 item15
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
336 wxButton
* item17
= new wxButton(item11
, ID_CHOOSE_WXWIN_HIERARCHY
, _("&Choose..."), wxDefaultPosition
, wxDefaultSize
, 0);
337 item17
->SetHelpText(_("Click to choose the root path of the wxWindows hierarchy\\n"));
340 item17
->SetToolTip(_("Click to choose the root path of the wxWindows hierarchy\\n"));
342 item15
->Add(item17
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
344 wxBoxSizer
* item18
= new wxBoxSizer(wxHORIZONTAL
);
345 item13
->Add(item18
, 0, wxGROW
, 5);
347 item18
->Add(60, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
349 wxCheckBox
* item20
= new wxCheckBox(item11
, ID_USE_WXWIN
, _("&Use WXWIN environment variable"), wxDefaultPosition
, wxDefaultSize
, 0);
350 item20
->SetValue(FALSE
);
351 item20
->SetHelpText(_("Check to use the value of WXWIN instead"));
354 item20
->SetToolTip(_("Check to use the value of WXWIN instead"));
356 item18
->Add(item20
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
358 GetSizer()->Fit(this);
359 ////@end ctLocationSettingsDialog content construction
361 FindWindow(ID_WXWIN_HIERARCHY
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_frameworkDir
));
362 FindWindow(ID_USE_WXWIN
)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_useEnvironmentVariable
));
366 * Update event handler for ID_WXWIN_HIERARCHY
369 void ctLocationSettingsDialog::OnUpdateWxwinHierarchy( wxUpdateUIEvent
& event
)
371 wxCheckBox
* checkbox
= (wxCheckBox
*) FindWindow(ID_USE_WXWIN
);
372 event
.Enable(!checkbox
->GetValue());
376 * Event handler for ID_CHOOSE_WXWIN_HIERARCHY
379 void ctLocationSettingsDialog::OnChooseWxwinHierarchy( wxCommandEvent
& WXUNUSED(event
) )
381 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow( ID_WXWIN_HIERARCHY
);
382 wxASSERT( textCtrl
!= NULL
);
383 wxString defaultPath
= textCtrl
->GetValue();
385 wxDirDialog
dialog(this, _("Choose the location of the wxWindows hierarchy"),
387 if (dialog
.ShowModal() == wxID_OK
)
389 textCtrl
->SetValue(dialog
.GetPath());
394 * Update event handler for ID_CHOOSE_WXWIN_HIERARCHY
397 void ctLocationSettingsDialog::OnUpdateChooseWxwinHierarchy( wxUpdateUIEvent
& event
)
399 wxCheckBox
* checkbox
= (wxCheckBox
*) FindWindow(ID_USE_WXWIN
);
400 event
.Enable(!checkbox
->GetValue());
404 * Should we show tooltips?
407 bool ctLocationSettingsDialog::ShowToolTips()
409 return wxGetApp().GetSettings().m_useToolTips
;