skip apple options
[wxWidgets.git] / samples / xrc / derivdlg.cpp
CommitLineData
af1337b0
JS
1//-----------------------------------------------------------------------------
2// Name: derivdlg.cpp
3// Purpose: XML resources sample: A derived dialog
4// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik
af1337b0
JS
5// Copyright: (c) Robert O'Connor and Vaclav Slavik
6// Licence: wxWindows licence
7//-----------------------------------------------------------------------------
8
9//-----------------------------------------------------------------------------
be5a51fb 10// Standard wxWidgets headers
af1337b0
JS
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
be5a51fb 21// need because it includes almost all "standard" wxWidgets headers)
af1337b0
JS
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
42BEGIN_EVENT_TABLE(PreferencesDialog, wxDialog)
f80ea77b 43 EVT_BUTTON( XRCID( "my_button" ), PreferencesDialog::OnMyButtonClicked )
6372b068 44 EVT_UPDATE_UI(XRCID( "my_checkbox" ), PreferencesDialog::OnUpdateUIMyCheckbox )
af1337b0
JS
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 )
47END_EVENT_TABLE()
48
49//-----------------------------------------------------------------------------
50// Public members
51//-----------------------------------------------------------------------------
52// Constructor (Notice how small and easy it is)
53PreferencesDialog::PreferencesDialog(wxWindow* parent)
f80ea77b 54{
2b5f62a0 55 wxXmlResource::Get()->LoadDialog(this, parent, wxT("derived_dialog"));
af1337b0
JS
56}
57
af1337b0
JS
58//-----------------------------------------------------------------------------
59// Private members (including the event handlers)
60//-----------------------------------------------------------------------------
61
87728739 62void PreferencesDialog::OnMyButtonClicked( wxCommandEvent &WXUNUSED(event) )
af1337b0
JS
63{
64 // Construct a message dialog.
f80ea77b
WS
65 wxMessageDialog msgDlg(this, _("You clicked on My Button"));
66
af1337b0
JS
67 // Show it modally.
68 msgDlg.ShowModal();
69}
70
71
f80ea77b 72// Update the enabled/disabled state of the edit/delete buttons depending on
af1337b0 73// whether a row (item) is selected in the listctrl
6372b068 74void PreferencesDialog::OnUpdateUIMyCheckbox( wxUpdateUIEvent &WXUNUSED(event) )
af1337b0
JS
75{
76 // Get a boolean value of whether the checkbox is checked
f80ea77b 77 bool myCheckBoxIsChecked;
af1337b0
JS
78 // You could just write:
79 // myCheckBoxIsChecked = event.IsChecked();
f80ea77b
WS
80 // since the event that was passed into this function already has the
81 // is a pointer to the right control. However,
af1337b0
JS
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
f80ea77b
WS
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);
af1337b0
JS
88}
89
90
87728739 91void PreferencesDialog::OnOK( wxCommandEvent& WXUNUSED(event) )
af1337b0
JS
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 );
f80ea77b 97
af1337b0
JS
98 // Show the message dialog, and if it returns wxID_OK (ie they clicked on OK button)...
99 if (msgDlg2.ShowModal() == wxID_OK)
100 {
f80ea77b 101 // ...then end this Preferences dialog.
af1337b0
JS
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
f80ea77b 105 // handler for wxID_OK and if there was, then execute that code.
af1337b0 106 }
f80ea77b 107
af1337b0
JS
108 // Otherwise do nothing.
109}