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