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