wxWidgets/samples/xrc/derivdlg.cpp

124 lines
4.9 KiB
C++
Raw Normal View History

Applied [ 594925 ] Implement wxArtProvider and XRC together By Robert O'Connor (robertoconnor) This patch is a draft which successfully allows a wxArtProvider to serve out icons to bitmaps for XRC files. The syntax to use a wxArtProvider bitmap is: <bitmap stock_id="wxART_INFORMATION" stock_client="wxART_TOOLBAR">somefallbackicon.png</bitmap> The bitmap is optional, and will only be used as a fallback image, if the wxArtProvider returned a wxNullBitmap for some reason. The client attribute, if not specified, currently will be wxART_OTHER. Perhaps there should be a guessing heuristic of it being in a menu node to call wxART_MENU. Usage of XRC resouces and wxArtProvider together can be seen in an updated /contrib/samples/xrc demo, which is a separate patch. Search the wx-dev mailing lists for "wxArtProvider" and "XRC" for the full discussions on this feature's API design. Applied patch [ 594932 ] Extended XRC XML resources sample By Robert O'Connor (robertoconnor) This is a more comprehensive introduction to how to get up and running using XRC in your new wxWindows project. It describes both the basics (for new users) and advanced features. It consists of a demo of dialogs and frames loaded from XRC. Each dialog has a textctrl at the top of the dialog, which walks the new user through that feature. There are 8 demos: The 4 basic ones: -A non-derived dialog, as typically used for an about dialog. -A derived dialog that loads its resources from an XRC (a frequently-asked question on the mailing lists), and responds to some simple events, including the disable-another-control-via-EVT_UPDATE_UI that is another FAQ, and powerful and simple-to-use feature. -A XRC reference "Controls" dialog, using a notebook. Each tab has a single control. All XRC handled widgets can be seen at a glance, and how to use them under XRC. -An uncentered dialog, to demonstrate the easy use of <centered>1</centered> to automatically place a Dialog centered on its parent.. The 4 advanced ones: -Embedding a custom class into an XRC dialog, by using the "unknown" class. -Using wxArtProvider to use stock icons from within your your XRC resources. -Using the platform attribute to selectively show a part of XRC based on the current OS. -Runtime variable expansion (demo only. Not implemented at this time). Also: -The main frame is now demonstrated as being loaded as an XRC. - The toolbar has longhelp tag demonstrated, and are hooked up to the same events as the menu to show how XRCID() works on the same tool and menuitem XRCID. -Some custom icons for the demonstration were created, and put into the toolbar and menubar. A custom icon also for the demonstration. -The example code has been put in 1 class per file (both .cpp and a matching .xrc), to make it much less confusing for a newcomer to figure out what class is what, expecially with all the wx macros for declaration and implementation. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16542 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2002-08-16 07:24:46 -04:00
//-----------------------------------------------------------------------------
// Name: derivdlg.cpp
// Purpose: XML resources sample: A derived dialog
// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) Robert O'Connor and Vaclav Slavik
// Licence: wxWindows licence
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// GCC implementation
//-----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "derivdlg.h"
#endif
//-----------------------------------------------------------------------------
// Standard wxWindows headers
//-----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// For all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
//-----------------------------------------------------------------------------
// Header of this .cpp file
//-----------------------------------------------------------------------------
#include "derivdlg.h"
//-----------------------------------------------------------------------------
// Remaining headers: Needed wx headers, then wx/contrib headers, then application headers
//-----------------------------------------------------------------------------
#include "wx/xrc/xmlres.h" // XRC XML resouces
//-----------------------------------------------------------------------------
// Event table: connect the events to the handler functions to process them
//-----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(PreferencesDialog, wxDialog)
EVT_BUTTON( XRCID( "my_button" ), PreferencesDialog::OnMyButtonClicked )
EVT_UPDATE_UI(XRCID( "my_checkbox" ), PreferencesDialog::OuUpdateUIMyCheckbox )
// Note that the ID here isn't a XRCID, it is one of the standard wx ID's.
EVT_BUTTON( wxID_OK, PreferencesDialog::OnOK )
END_EVENT_TABLE()
//-----------------------------------------------------------------------------
// Public members
//-----------------------------------------------------------------------------
// Constructor (Notice how small and easy it is)
PreferencesDialog::PreferencesDialog(wxWindow* parent)
{
wxXmlResource::Get()->LoadDialog(this, parent, wxT("derived_dialog"));
Applied [ 594925 ] Implement wxArtProvider and XRC together By Robert O'Connor (robertoconnor) This patch is a draft which successfully allows a wxArtProvider to serve out icons to bitmaps for XRC files. The syntax to use a wxArtProvider bitmap is: <bitmap stock_id="wxART_INFORMATION" stock_client="wxART_TOOLBAR">somefallbackicon.png</bitmap> The bitmap is optional, and will only be used as a fallback image, if the wxArtProvider returned a wxNullBitmap for some reason. The client attribute, if not specified, currently will be wxART_OTHER. Perhaps there should be a guessing heuristic of it being in a menu node to call wxART_MENU. Usage of XRC resouces and wxArtProvider together can be seen in an updated /contrib/samples/xrc demo, which is a separate patch. Search the wx-dev mailing lists for "wxArtProvider" and "XRC" for the full discussions on this feature's API design. Applied patch [ 594932 ] Extended XRC XML resources sample By Robert O'Connor (robertoconnor) This is a more comprehensive introduction to how to get up and running using XRC in your new wxWindows project. It describes both the basics (for new users) and advanced features. It consists of a demo of dialogs and frames loaded from XRC. Each dialog has a textctrl at the top of the dialog, which walks the new user through that feature. There are 8 demos: The 4 basic ones: -A non-derived dialog, as typically used for an about dialog. -A derived dialog that loads its resources from an XRC (a frequently-asked question on the mailing lists), and responds to some simple events, including the disable-another-control-via-EVT_UPDATE_UI that is another FAQ, and powerful and simple-to-use feature. -A XRC reference "Controls" dialog, using a notebook. Each tab has a single control. All XRC handled widgets can be seen at a glance, and how to use them under XRC. -An uncentered dialog, to demonstrate the easy use of <centered>1</centered> to automatically place a Dialog centered on its parent.. The 4 advanced ones: -Embedding a custom class into an XRC dialog, by using the "unknown" class. -Using wxArtProvider to use stock icons from within your your XRC resources. -Using the platform attribute to selectively show a part of XRC based on the current OS. -Runtime variable expansion (demo only. Not implemented at this time). Also: -The main frame is now demonstrated as being loaded as an XRC. - The toolbar has longhelp tag demonstrated, and are hooked up to the same events as the menu to show how XRCID() works on the same tool and menuitem XRCID. -Some custom icons for the demonstration were created, and put into the toolbar and menubar. A custom icon also for the demonstration. -The example code has been put in 1 class per file (both .cpp and a matching .xrc), to make it much less confusing for a newcomer to figure out what class is what, expecially with all the wx macros for declaration and implementation. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16542 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2002-08-16 07:24:46 -04:00
}
// Destructor. (Empty, as I don't need anything special done when destructing).
PreferencesDialog::~PreferencesDialog()
{
}
//-----------------------------------------------------------------------------
// Private members (including the event handlers)
//-----------------------------------------------------------------------------
void PreferencesDialog::OnMyButtonClicked( wxCommandEvent &event )
{
// Construct a message dialog.
wxMessageDialog msgDlg(this, _("You clicked on My Button"));
// Show it modally.
msgDlg.ShowModal();
}
// Update the enabled/disabled state of the edit/delete buttons depending on
// whether a row (item) is selected in the listctrl
void PreferencesDialog::OuUpdateUIMyCheckbox( wxUpdateUIEvent &event )
{
// Get a boolean value of whether the checkbox is checked
bool myCheckBoxIsChecked;
// You could just write:
// myCheckBoxIsChecked = event.IsChecked();
// since the event that was passed into this function already has the
// is a pointer to the right control. However,
// this is the XRCCTRL way (which is more obvious as to what is going on).
myCheckBoxIsChecked = XRCCTRL(*this, "my_checkbox", wxCheckBox)->IsChecked();
// Now call either Enable(TRUE) or Enable(FALSE) on the textctrl, depending
// on the value of that boolean.
XRCCTRL(*this, "my_textctrl", wxTextCtrl)->Enable(myCheckBoxIsChecked);
}
void PreferencesDialog::OnOK( wxCommandEvent& event )
{
// Construct a message dialog (An extra parameters to put a cancel button on).
wxMessageDialog msgDlg2(this, _("Press OK to close Derived dialog, or Cancel to abort"),
_("Overriding base class OK button handler"),
wxOK | wxCANCEL | wxCENTER );
// Show the message dialog, and if it returns wxID_OK (ie they clicked on OK button)...
if (msgDlg2.ShowModal() == wxID_OK)
{
// ...then end this Preferences dialog.
EndModal( wxID_OK );
// You could also have used event.Skip() which would then skip up
// to the wxDialog's event table and see if there was a EVT_BUTTON
// handler for wxID_OK and if there was, then execute that code.
}
// Otherwise do nothing.
}