]>
Commit | Line | Data |
---|---|---|
1 | //----------------------------------------------------------------------------- | |
2 | // Name: derivdlg.cpp | |
3 | // Purpose: XML resources sample: A derived dialog | |
4 | // Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) Robert O'Connor and Vaclav Slavik | |
7 | // Licence: wxWindows licence | |
8 | //----------------------------------------------------------------------------- | |
9 | ||
10 | //----------------------------------------------------------------------------- | |
11 | // GCC implementation | |
12 | //----------------------------------------------------------------------------- | |
13 | ||
14 | #ifdef __GNUG__ | |
15 | #pragma implementation "derivdlg.h" | |
16 | #endif | |
17 | ||
18 | //----------------------------------------------------------------------------- | |
19 | // Standard wxWidgets headers | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
22 | // For compilers that support precompilation, includes "wx/wx.h". | |
23 | #include "wx/wxprec.h" | |
24 | ||
25 | #ifdef __BORLANDC__ | |
26 | #pragma hdrstop | |
27 | #endif | |
28 | ||
29 | // For all others, include the necessary headers (this file is usually all you | |
30 | // need because it includes almost all "standard" wxWidgets headers) | |
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/wx.h" | |
33 | #endif | |
34 | ||
35 | //----------------------------------------------------------------------------- | |
36 | // Header of this .cpp file | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
39 | #include "derivdlg.h" | |
40 | ||
41 | //----------------------------------------------------------------------------- | |
42 | // Remaining headers: Needed wx headers, then wx/contrib headers, then application headers | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
45 | #include "wx/xrc/xmlres.h" // XRC XML resouces | |
46 | ||
47 | //----------------------------------------------------------------------------- | |
48 | // Event table: connect the events to the handler functions to process them | |
49 | //----------------------------------------------------------------------------- | |
50 | ||
51 | BEGIN_EVENT_TABLE(PreferencesDialog, wxDialog) | |
52 | EVT_BUTTON( XRCID( "my_button" ), PreferencesDialog::OnMyButtonClicked ) | |
53 | EVT_UPDATE_UI(XRCID( "my_checkbox" ), PreferencesDialog::OnUpdateUIMyCheckbox ) | |
54 | // Note that the ID here isn't a XRCID, it is one of the standard wx ID's. | |
55 | EVT_BUTTON( wxID_OK, PreferencesDialog::OnOK ) | |
56 | END_EVENT_TABLE() | |
57 | ||
58 | //----------------------------------------------------------------------------- | |
59 | // Public members | |
60 | //----------------------------------------------------------------------------- | |
61 | // Constructor (Notice how small and easy it is) | |
62 | PreferencesDialog::PreferencesDialog(wxWindow* parent) | |
63 | { | |
64 | wxXmlResource::Get()->LoadDialog(this, parent, wxT("derived_dialog")); | |
65 | } | |
66 | ||
67 | //----------------------------------------------------------------------------- | |
68 | // Private members (including the event handlers) | |
69 | //----------------------------------------------------------------------------- | |
70 | ||
71 | void PreferencesDialog::OnMyButtonClicked( wxCommandEvent &WXUNUSED(event) ) | |
72 | { | |
73 | // Construct a message dialog. | |
74 | wxMessageDialog msgDlg(this, _("You clicked on My Button")); | |
75 | ||
76 | // Show it modally. | |
77 | msgDlg.ShowModal(); | |
78 | } | |
79 | ||
80 | ||
81 | // Update the enabled/disabled state of the edit/delete buttons depending on | |
82 | // whether a row (item) is selected in the listctrl | |
83 | void PreferencesDialog::OnUpdateUIMyCheckbox( wxUpdateUIEvent &WXUNUSED(event) ) | |
84 | { | |
85 | // Get a boolean value of whether the checkbox is checked | |
86 | bool myCheckBoxIsChecked; | |
87 | // You could just write: | |
88 | // myCheckBoxIsChecked = event.IsChecked(); | |
89 | // since the event that was passed into this function already has the | |
90 | // is a pointer to the right control. However, | |
91 | // this is the XRCCTRL way (which is more obvious as to what is going on). | |
92 | myCheckBoxIsChecked = XRCCTRL(*this, "my_checkbox", wxCheckBox)->IsChecked(); | |
93 | ||
94 | // Now call either Enable(true) or Enable(false) on the textctrl, depending | |
95 | // on the value of that boolean. | |
96 | XRCCTRL(*this, "my_textctrl", wxTextCtrl)->Enable(myCheckBoxIsChecked); | |
97 | } | |
98 | ||
99 | ||
100 | void PreferencesDialog::OnOK( wxCommandEvent& WXUNUSED(event) ) | |
101 | { | |
102 | // Construct a message dialog (An extra parameters to put a cancel button on). | |
103 | wxMessageDialog msgDlg2(this, _("Press OK to close Derived dialog, or Cancel to abort"), | |
104 | _("Overriding base class OK button handler"), | |
105 | wxOK | wxCANCEL | wxCENTER ); | |
106 | ||
107 | // Show the message dialog, and if it returns wxID_OK (ie they clicked on OK button)... | |
108 | if (msgDlg2.ShowModal() == wxID_OK) | |
109 | { | |
110 | // ...then end this Preferences dialog. | |
111 | EndModal( wxID_OK ); | |
112 | // You could also have used event.Skip() which would then skip up | |
113 | // to the wxDialog's event table and see if there was a EVT_BUTTON | |
114 | // handler for wxID_OK and if there was, then execute that code. | |
115 | } | |
116 | ||
117 | // Otherwise do nothing. | |
118 | } |