derivdlg.cpp 4.5 KB

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