From af1337b041be734b7e64bcf7a06086268ae6895e Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Fri, 16 Aug 2002 11:24:46 +0000 Subject: [PATCH] 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: somefallbackicon.png 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 1 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 --- contrib/include/wx/xrc/xmlres.h | 7 + contrib/samples/xrc/Makefile.in | 28 +- contrib/samples/xrc/XrcDemoVC.dsp | 24 + contrib/samples/xrc/custclas.cpp | 162 ++++++ contrib/samples/xrc/custclas.h | 97 ++++ contrib/samples/xrc/derivdlg.cpp | 123 +++++ contrib/samples/xrc/derivdlg.h | 71 +++ contrib/samples/xrc/makefile.b32 | 6 +- contrib/samples/xrc/makefile.g95 | 6 +- contrib/samples/xrc/makefile.vc | 4 +- contrib/samples/xrc/myframe.cpp | 271 ++++++++++ contrib/samples/xrc/myframe.h | 67 +++ contrib/samples/xrc/rc/appicon.ico | Bin 2238 -> 1078 bytes contrib/samples/xrc/rc/appicon.xpm | 113 ++-- contrib/samples/xrc/rc/artprov.xpm | 23 + contrib/samples/xrc/rc/artprov.xrc | 67 +++ contrib/samples/xrc/rc/basicdlg.xpm | 24 + contrib/samples/xrc/rc/basicdlg.xrc | 48 ++ contrib/samples/xrc/rc/controls.xpm | 25 + contrib/samples/xrc/rc/controls.xrc | 801 ++++++++++++++++++++++++++++ contrib/samples/xrc/rc/custclas.xpm | 26 + contrib/samples/xrc/rc/custclas.xrc | 42 ++ contrib/samples/xrc/rc/derivdlg.xpm | 25 + contrib/samples/xrc/rc/derivdlg.xrc | 78 +++ contrib/samples/xrc/rc/frame.xrc | 27 + contrib/samples/xrc/rc/menu.xrc | 72 +++ contrib/samples/xrc/rc/platform.xpm | 21 + contrib/samples/xrc/rc/platform.xrc | 145 +++++ contrib/samples/xrc/rc/sppicon.ico | Bin 0 -> 1078 bytes contrib/samples/xrc/rc/toolbar.xrc | 51 ++ contrib/samples/xrc/rc/uncenter.xpm | 24 + contrib/samples/xrc/rc/uncenter.xrc | 47 ++ contrib/samples/xrc/rc/variable.xpm | 21 + contrib/samples/xrc/rc/variable.xrc | 59 ++ contrib/samples/xrc/xrcdemo.cpp | 220 +++----- contrib/samples/xrc/xrcdemo.h | 54 ++ contrib/src/xrc/xmlres.cpp | 77 ++- include/wx/xrc/xmlres.h | 7 + samples/xrc/Makefile.in | 28 +- samples/xrc/XrcDemoVC.dsp | 24 + samples/xrc/custclas.cpp | 162 ++++++ samples/xrc/custclas.h | 97 ++++ samples/xrc/derivdlg.cpp | 123 +++++ samples/xrc/derivdlg.h | 71 +++ samples/xrc/makefile.b32 | 6 +- samples/xrc/makefile.g95 | 6 +- samples/xrc/makefile.vc | 4 +- samples/xrc/myframe.cpp | 271 ++++++++++ samples/xrc/myframe.h | 67 +++ samples/xrc/rc/appicon.ico | Bin 2238 -> 1078 bytes samples/xrc/rc/appicon.xpm | 113 ++-- samples/xrc/rc/artprov.xpm | 23 + samples/xrc/rc/artprov.xrc | 67 +++ samples/xrc/rc/basicdlg.xpm | 24 + samples/xrc/rc/basicdlg.xrc | 48 ++ samples/xrc/rc/controls.xpm | 25 + samples/xrc/rc/controls.xrc | 801 ++++++++++++++++++++++++++++ samples/xrc/rc/custclas.xpm | 26 + samples/xrc/rc/custclas.xrc | 42 ++ samples/xrc/rc/derivdlg.xpm | 25 + samples/xrc/rc/derivdlg.xrc | 78 +++ samples/xrc/rc/frame.xrc | 27 + samples/xrc/rc/menu.xrc | 72 +++ samples/xrc/rc/platform.xpm | 21 + samples/xrc/rc/platform.xrc | 145 +++++ samples/xrc/rc/sppicon.ico | Bin 0 -> 1078 bytes samples/xrc/rc/toolbar.xrc | 51 ++ samples/xrc/rc/uncenter.xpm | 24 + samples/xrc/rc/uncenter.xrc | 47 ++ samples/xrc/rc/variable.xpm | 21 + samples/xrc/rc/variable.xrc | 59 ++ samples/xrc/xrcdemo.cpp | 220 +++----- samples/xrc/xrcdemo.h | 54 ++ src/xrc/xmlres.cpp | 77 ++- 74 files changed, 5512 insertions(+), 400 deletions(-) create mode 100644 contrib/samples/xrc/custclas.cpp create mode 100644 contrib/samples/xrc/custclas.h create mode 100644 contrib/samples/xrc/derivdlg.cpp create mode 100644 contrib/samples/xrc/derivdlg.h create mode 100644 contrib/samples/xrc/myframe.cpp create mode 100644 contrib/samples/xrc/myframe.h create mode 100644 contrib/samples/xrc/rc/artprov.xpm create mode 100644 contrib/samples/xrc/rc/artprov.xrc create mode 100644 contrib/samples/xrc/rc/basicdlg.xpm create mode 100644 contrib/samples/xrc/rc/basicdlg.xrc create mode 100644 contrib/samples/xrc/rc/controls.xpm create mode 100644 contrib/samples/xrc/rc/controls.xrc create mode 100644 contrib/samples/xrc/rc/custclas.xpm create mode 100644 contrib/samples/xrc/rc/custclas.xrc create mode 100644 contrib/samples/xrc/rc/derivdlg.xpm create mode 100644 contrib/samples/xrc/rc/derivdlg.xrc create mode 100644 contrib/samples/xrc/rc/frame.xrc create mode 100644 contrib/samples/xrc/rc/menu.xrc create mode 100644 contrib/samples/xrc/rc/platform.xpm create mode 100644 contrib/samples/xrc/rc/platform.xrc create mode 100644 contrib/samples/xrc/rc/sppicon.ico create mode 100644 contrib/samples/xrc/rc/toolbar.xrc create mode 100644 contrib/samples/xrc/rc/uncenter.xpm create mode 100644 contrib/samples/xrc/rc/uncenter.xrc create mode 100644 contrib/samples/xrc/rc/variable.xpm create mode 100644 contrib/samples/xrc/rc/variable.xrc create mode 100644 contrib/samples/xrc/xrcdemo.h create mode 100644 samples/xrc/custclas.cpp create mode 100644 samples/xrc/custclas.h create mode 100644 samples/xrc/derivdlg.cpp create mode 100644 samples/xrc/derivdlg.h create mode 100644 samples/xrc/myframe.cpp create mode 100644 samples/xrc/myframe.h create mode 100644 samples/xrc/rc/artprov.xpm create mode 100644 samples/xrc/rc/artprov.xrc create mode 100644 samples/xrc/rc/basicdlg.xpm create mode 100644 samples/xrc/rc/basicdlg.xrc create mode 100644 samples/xrc/rc/controls.xpm create mode 100644 samples/xrc/rc/controls.xrc create mode 100644 samples/xrc/rc/custclas.xpm create mode 100644 samples/xrc/rc/custclas.xrc create mode 100644 samples/xrc/rc/derivdlg.xpm create mode 100644 samples/xrc/rc/derivdlg.xrc create mode 100644 samples/xrc/rc/frame.xrc create mode 100644 samples/xrc/rc/menu.xrc create mode 100644 samples/xrc/rc/platform.xpm create mode 100644 samples/xrc/rc/platform.xrc create mode 100644 samples/xrc/rc/sppicon.ico create mode 100644 samples/xrc/rc/toolbar.xrc create mode 100644 samples/xrc/rc/uncenter.xpm create mode 100644 samples/xrc/rc/uncenter.xrc create mode 100644 samples/xrc/rc/variable.xpm create mode 100644 samples/xrc/rc/variable.xrc create mode 100644 samples/xrc/xrcdemo.h diff --git a/contrib/include/wx/xrc/xmlres.h b/contrib/include/wx/xrc/xmlres.h index 95e06f6711..7719fe4afb 100644 --- a/contrib/include/wx/xrc/xmlres.h +++ b/contrib/include/wx/xrc/xmlres.h @@ -24,6 +24,7 @@ #include "wx/filesys.h" #include "wx/bitmap.h" #include "wx/icon.h" +#include "wx/artprov.h" #include "wx/xrc/xml.h" @@ -351,6 +352,12 @@ protected: // Returns the XRCID. int GetID(); + // Returns the wxArtID for a wxArtProvider-managed bitmap. + wxArtID GetStockID(const wxString& param); + + // Returns the wxArtClient for a wxArtProvider-managed bitmap. + wxArtClient GetStockClient(const wxString& param); + // Returns the resource name. wxString GetName(); diff --git a/contrib/samples/xrc/Makefile.in b/contrib/samples/xrc/Makefile.in index 6d7da4cb7c..74b1001946 100644 --- a/contrib/samples/xrc/Makefile.in +++ b/contrib/samples/xrc/Makefile.in @@ -11,13 +11,35 @@ program_dir = contrib/samples/xrc PROGRAM=xrcdemo -OBJECTS=$(PROGRAM).o +OBJECTS=$(PROGRAM).o \ + myframe.o \ + derivdlg.o \ + custclas.o APPEXTRALIBS=$(top_builddir)/lib/libwxxrc.@WX_TARGET_LIBRARY_TYPE@ APPEXTRADEFS=-I$(top_srcdir)/contrib/include DATADIRS = rc -DATAFILES = rc/resource.xrc rc/fileopen.gif rc/filesave.gif rc/fuzzy.gif \ - rc/quotes.gif rc/scanning.gif rc/update.gif +DATAFILES = rc/artprov.xrc \ + rc/basicdlg.xrc \ + rc/controls.xrc \ + rc/custclas.xrc \ + rc/derivdlg.xrc \ + rc/frame.xrc \ + rc/menu.xrc \ + rc/platform.xrc \ + rc/toolbar.xrc \ + rc/uncenter.xrc \ + rc/variable.xrc \ + rc/artprov.xpm \ + rc/basicdlg.xpm \ + rc/controls.xpm \ + rc/custclas.xpm \ + rc/derivdlg.xpm \ + rc/platform.xpm \ + rc/uncenter.xpm \ + rc/variable.xpm include $(top_builddir)/src/makeprog.env + + diff --git a/contrib/samples/xrc/XrcDemoVC.dsp b/contrib/samples/xrc/XrcDemoVC.dsp index 68e553b8a7..5bef50036a 100644 --- a/contrib/samples/xrc/XrcDemoVC.dsp +++ b/contrib/samples/xrc/XrcDemoVC.dsp @@ -148,6 +148,30 @@ LINK32=link.exe # Name "XrcDemoVC - Win32 Release DLL" # Begin Source File +SOURCE=.\custclas.cpp +# End Source File +# Begin Source File + +SOURCE=.\custclas.h +# End Source File +# Begin Source File + +SOURCE=.\derivdlg.cpp +# End Source File +# Begin Source File + +SOURCE=.\derivdlg.h +# End Source File +# Begin Source File + +SOURCE=.\myframe.cpp +# End Source File +# Begin Source File + +SOURCE=.\myframe.h +# End Source File +# Begin Source File + SOURCE=.\xrcdemo.cpp !IF "$(CFG)" == "XrcDemoVC - Win32 Release" diff --git a/contrib/samples/xrc/custclas.cpp b/contrib/samples/xrc/custclas.cpp new file mode 100644 index 0000000000..020a14e4b5 --- /dev/null +++ b/contrib/samples/xrc/custclas.cpp @@ -0,0 +1,162 @@ +//----------------------------------------------------------------------------- +// Name: custclass.cpp +// Purpose: XML resources sample: A custom class to insert into a XRC file +// 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 "custclas.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 "custclas.h" + +//----------------------------------------------------------------------------- +// Internal constants +//----------------------------------------------------------------------------- + +// Popup menu (PU) item control IDs. In this example, they aren't hooked up +// to any functions. Normally you would use these IDs in your event table, so +// that if one of these menu items is clicked, then a certain function is +// called. +enum { + PU_ADD_RECORD = wxID_HIGHEST + 1, + PU_EDIT_RECORD, + PU_DELETE_RECORD +}; + +// Columns of the listctrl (the leftmost one starts at 0, and so on). +// Allows easier code maintenance if want to add/rearrangement of listctrl's +// columns. +enum { + RECORD_COLUMN = 0, + ACTION_COLUMN, + PRIORITY_COLUMN +}; + +//----------------------------------------------------------------------------- +// wxWindows macro: implement dynamic class +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS( MyResizableListCtrl, wxListCtrl ) + +//----------------------------------------------------------------------------- +// Event table: connect the events to the handler functions to process them +//----------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE( MyResizableListCtrl, wxListCtrl ) + // Something to do when right mouse down + EVT_RIGHT_DOWN( MyResizableListCtrl::ContextSensitiveMenu ) + // Something to do when resized + EVT_SIZE( MyResizableListCtrl::OnSize ) +END_EVENT_TABLE() + +//----------------------------------------------------------------------------- +// Public methods +//----------------------------------------------------------------------------- + +// Constructor, including setting the dialog's m_configuration_section member +// to the incoming configuration_section string. +MyResizableListCtrl::MyResizableListCtrl( wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxValidator& validator, + const wxString& name ) + : wxListCtrl( parent, id, pos, size, style, validator, name ) +{ + + // This listctrl needs to insert its columns in the constructor, since + // as soon as the listctrl is built, it is resized and grafted onto an + // "unknown" XRC placeholder. This induces an OnSize() event, calling the + // overrriden OnSize function for this class, which needs to have 3 + // columns to resize (else an assert on WXGTK debug build). + InsertColumn( RECORD_COLUMN, _("Record"), wxLIST_FORMAT_LEFT, 140); + InsertColumn( ACTION_COLUMN, _("Action"), wxLIST_FORMAT_LEFT, 70); + InsertColumn( PRIORITY_COLUMN, _("Priority"), wxLIST_FORMAT_LEFT, 70 ); +} + + +MyResizableListCtrl::~MyResizableListCtrl() +{ +} + + +void MyResizableListCtrl::ContextSensitiveMenu( wxMouseEvent& event ) +{ + // Make an instance of a menu. + wxMenu a_menu; + + a_menu.Append( PU_ADD_RECORD, _( "Add a new record...") ); + a_menu.Append( PU_EDIT_RECORD, _( "Edit selected record..." ) ); + a_menu.Append( PU_DELETE_RECORD, _( "Delete selected record" ) ); + + // If no listctrl rows selected, then disable the menu items that + // require selection + if ( GetSelectedItemCount() == 0 ) { + a_menu.Enable( PU_EDIT_RECORD, FALSE ); + a_menu.Enable( PU_DELETE_RECORD, FALSE ); + } + + // Show the popup menu (wxWindow::PopupMenu ), at the x,y position + // of the click event + PopupMenu( &a_menu, event.GetPosition() ); +} + + +void MyResizableListCtrl::OnSize( wxSizeEvent &event ) +{ + // Call our custom width setting function. + SetColumnWidths(); + // REQURED event.Skip() call to allow this event to propagate + // upwards so others can do what they need to do in response to + // this size event. + event.Skip(); +} + + +void MyResizableListCtrl::SetColumnWidths() +{ + // Get width of entire listctrl + int leftmostColumnWidth = GetSize().x; + + // Subtract width of other columns, scrollbar, and some padding + leftmostColumnWidth -= GetColumnWidth( ACTION_COLUMN ); + leftmostColumnWidth -= GetColumnWidth( PRIORITY_COLUMN ); + leftmostColumnWidth -= wxSystemSettings::GetSystemMetric( wxSYS_VSCROLL_X ); + leftmostColumnWidth -= 5; + + // Set the column width to the new value. + SetColumnWidth( RECORD_COLUMN, leftmostColumnWidth ); + + // This is just a debug message in case you want to watch the + // events scroll by as you resize. + wxLogDebug( "Successfully set column widths" ); +} + + diff --git a/contrib/samples/xrc/custclas.h b/contrib/samples/xrc/custclas.h new file mode 100644 index 0000000000..bce98c906d --- /dev/null +++ b/contrib/samples/xrc/custclas.h @@ -0,0 +1,97 @@ +//----------------------------------------------------------------------------- +// Name: custclas.h +// Purpose: XML resources sample: A custom class to insert into a XRC file +// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik +// RCS-ID: $Id$ +// Copyright: (c) Robert O'Connor and Vaclav Slavik +// Licence: wxWindows licence +//----------------------------------------------------------------------------- + +//---------------------------------------------------------------------------------------- +// Begin single inclusion of this .h file condition +//---------------------------------------------------------------------------------------- + +#ifndef _CUSTCLAS_H_ +#define _CUSTCLAS_H_ + +//---------------------------------------------------------------------------------------- +// GCC interface +//---------------------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma interface "custclas.h" +#endif + +//---------------------------------------------------------------------------------------- +// Headers +//---------------------------------------------------------------------------------------- + +#include "wx/listctrl.h" + +//---------------------------------------------------------------------------------------- +// Class definition: MyResizableListCtrl +//---------------------------------------------------------------------------------------- + +//! A custom listctrl that resizes itself and pops up a context-sensitive menu. +class MyResizableListCtrl : public wxListCtrl +{ + // Very helpful wxWindows macro required for wxWindows-RTTI tracing: By using this + // you will see "Leaked one object of type myResizeableListCtrl" in the debug log, + // along with which line you if was created, but you forget to free the memory. + // NOTE: Using this REQUIRES a default constructor: that means either: giving a + // default value for all parameters in your constructor, or else having a dummy + // MyResizableListCtrl(){} constructor in addition to your regular one. + DECLARE_DYNAMIC_CLASS( MyResizableListCtrl ) + +public: + + // Constructor. + /* + These parameters are the same as a wxWindows constructor. + \param parent The parent window. + \param id The id of the progress_listbox. Will usually be -1 unless multiple + of them on the same dialog. + \param pos The pixel position of the listctrl on its parent window + \param size The pixel size of the listctrl + \param style Style of the listbox. See wxWindows wxListBox docs for details. + \param validator Window validator. See wxWindows docs for details. + \param name Windows name (rarely used). + \param exclusion_column_caption The label of header of listctrl's exclusion + column. + */ + MyResizableListCtrl( wxWindow *parent = NULL, + wxWindowID id = -1, + const wxPoint &pos = wxDefaultPosition, + const wxSize &size = wxDefaultSize, + long style = wxLC_REPORT, + const wxValidator& validator = wxDefaultValidator, + const wxString &name = wxT("myResizableListCtrl") + ); + + // Destuctor. + ~MyResizableListCtrl(); + +protected: + + // A custom function for a context sensitive menu. + void ContextSensitiveMenu( wxMouseEvent& event ); + + // This is a wxWindows function that we are going to override with our own behaviour. + void OnSize( wxSizeEvent &event ); + + // A custom function. What is called in the constructor, and in an OnSize() + void SetColumnWidths(); + +private: + + // wxWindows macro, required to be able to use Event tables in the .cpp file. + DECLARE_EVENT_TABLE() + +}; + +//---------------------------------------------------------------------------------------- +// End single inclusion of this .h file condition +//---------------------------------------------------------------------------------------- + +#endif //_CUSTCLAS_H_ + diff --git a/contrib/samples/xrc/derivdlg.cpp b/contrib/samples/xrc/derivdlg.cpp new file mode 100644 index 0000000000..a9a719c49d --- /dev/null +++ b/contrib/samples/xrc/derivdlg.cpp @@ -0,0 +1,123 @@ +//----------------------------------------------------------------------------- +// 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, "derived_dialog"); +} + +// 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. +} diff --git a/contrib/samples/xrc/derivdlg.h b/contrib/samples/xrc/derivdlg.h new file mode 100644 index 0000000000..ca580eed79 --- /dev/null +++ b/contrib/samples/xrc/derivdlg.h @@ -0,0 +1,71 @@ +//----------------------------------------------------------------------------- +// Name: xmldemo.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 +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Begin single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#ifndef _DERIVDLG_H_ +#define _DERIVDLG_H_ + +//----------------------------------------------------------------------------- +// GCC interface +//----------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma interface "derivdlg.h" +#endif + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "wx/dialog.h" + +//----------------------------------------------------------------------------- +// Class definition: PreferencesDialog +//----------------------------------------------------------------------------- + +// A derived dialog. +class PreferencesDialog : public wxDialog +{ + +public: + + // Constructor. + /* + \param parent The parent window. Simple constructor. + */ + PreferencesDialog( wxWindow* parent ); + + // Destructor. + ~PreferencesDialog(); + +private: + + // Stuff to do when "My Button" gets clicked + void OnMyButtonClicked( wxCommandEvent &event ); + + // Stuff to do when a "My Checkbox" gets updated + // (drawn, or it changes its value) + void OuUpdateUIMyCheckbox( wxUpdateUIEvent &event ); + + // Override base class functions of a wxDialog. + void OnOK( wxCommandEvent &event ); + + // Any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + +}; + +//----------------------------------------------------------------------------- +// End single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#endif //_DERIVDLG_H_ diff --git a/contrib/samples/xrc/makefile.b32 b/contrib/samples/xrc/makefile.b32 index 717e97799b..08cbbee374 100644 --- a/contrib/samples/xrc/makefile.b32 +++ b/contrib/samples/xrc/makefile.b32 @@ -12,7 +12,11 @@ WXDIR = $(WXWIN) TARGET=xrcdemo EXTRALIBS=$(WXDIR)\lib\wxxrc.lib -OBJECTS = $(TARGET).obj +OBJECTS = $(TARGET).obj \ + myframe.obj \ + derivdlg.obj \ + custclas.obj !include $(WXDIR)\src\makeprog.b32 + diff --git a/contrib/samples/xrc/makefile.g95 b/contrib/samples/xrc/makefile.g95 index c78a91f737..6d649c1773 100644 --- a/contrib/samples/xrc/makefile.g95 +++ b/contrib/samples/xrc/makefile.g95 @@ -6,9 +6,13 @@ WXDIR = ../../.. TARGET = xrcdemo -OBJECTS = $(TARGET).o +OBJECTS = $(TARGET).o \ + myframe.o \ + derivdlg.o \ + custclas.o EXTRAINC = -I$(WXDIR)/contrib/include EXTRALIBS = -lwxxrc include $(WXDIR)/src/makeprog.g95 + diff --git a/contrib/samples/xrc/makefile.vc b/contrib/samples/xrc/makefile.vc index e0130b2180..42fea985a3 100644 --- a/contrib/samples/xrc/makefile.vc +++ b/contrib/samples/xrc/makefile.vc @@ -6,9 +6,11 @@ WXDIR = $(WXWIN) PROGRAM = xrcdemo -OBJECTS = $(PROGRAM).obj +OBJECTS = $(PROGRAM).obj myframe.obj derivdlg.obj custclas.obj + EXTRALIBS = $(WXDIR)\lib\wxxrc$(LIBEXT).lib EXTRAINC = -I$(WXDIR)\contrib\include !include $(WXDIR)\src\makeprog.vc + diff --git a/contrib/samples/xrc/myframe.cpp b/contrib/samples/xrc/myframe.cpp new file mode 100644 index 0000000000..2d03b22e44 --- /dev/null +++ b/contrib/samples/xrc/myframe.cpp @@ -0,0 +1,271 @@ +//----------------------------------------------------------------------------- +// Name: myframe.cpp +// Purpose: XML resources sample: A derived frame, called MyFrame +// 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 "myframe.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 "myframe.h" + +//----------------------------------------------------------------------------- +// Remaining headers: Needed wx headers, then wx/contrib headers, then application headers +//----------------------------------------------------------------------------- + +// Since setting an icon +#include "wx/image.h" + +//----------------------------------------------------------------------------- + +#include "wx/xrc/xmlres.h" // XRC XML resouces + +//----------------------------------------------------------------------------- + +// Our derived dialog for the derived dialog example. +#include "derivdlg.h" +// Our custom class, for the custom class example. +#include "custclas.h" +// For functions to manipulate our wxTreeCtrl and wxListCtrl +#include "wx/treectrl.h" +#include "wx/listctrl.h" + +//----------------------------------------------------------------------------- +// Regular resources (the non-XRC kind). +//----------------------------------------------------------------------------- + +// The application icon +// All non-MSW platforms use an xpm. MSW uses an .ico file +#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) + #include "rc/appicon.xpm" +#endif + +//----------------------------------------------------------------------------- +// Event table: connect the events to the handler functions to process them +//----------------------------------------------------------------------------- + +// The event tables connect the wxWindows events with the functions (event +// handlers) which process them. It can be also done at run-time, but for the +// simple menu events like this the static method is much simpler. +// The reason why the menuitems and tools are given the same name in the +// XRC file, is that both a tool (a toolbar item) and a menuitem are designed +// to fire the same kind of event (an EVT_MENU) and thus I give them the same +// ID name to help new users emphasize this point which is often overlooked +// when starting out with wxWindows. +BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(XRCID("exit_tool_or_menuitem"), MyFrame::OnExitToolOrMenuCommand) + EVT_MENU(XRCID("non_derived_dialog_tool_or_menuitem"), MyFrame::OnNonDerivedDialogToolOrMenuCommand) + EVT_MENU(XRCID("derived_tool_or_menuitem"), MyFrame::OnDerivedDialogToolOrMenuCommand) + EVT_MENU(XRCID("controls_tool_or_menuitem"), MyFrame::OnControlsToolOrMenuCommand) + EVT_MENU(XRCID("uncentered_tool_or_menuitem"), MyFrame::OnUncenteredToolOrMenuCommand) + EVT_MENU(XRCID("custom_class_tool_or_menuitem"), MyFrame::OnCustomClassToolOrMenuCommand) + EVT_MENU(XRCID("platform_property_tool_or_menuitem"), MyFrame::OnPlatformPropertyToolOrMenuCommand) + EVT_MENU(XRCID("art_provider_tool_or_menuitem"), MyFrame::OnArtProviderToolOrMenuCommand) + EVT_MENU(XRCID("variable_expansion_tool_or_menuitem"), MyFrame::OnVariableExpansionToolOrMenuCommand) + EVT_MENU(XRCID("about_tool_or_menuitem"), MyFrame::OnAboutToolOrMenuCommand) +END_EVENT_TABLE() + +//----------------------------------------------------------------------------- +// Public methods +//----------------------------------------------------------------------------- + +// Constructor +MyFrame::MyFrame(wxWindow* parent) +{ + // Load up this frame from XRC. [Note, instead of making a class's + // constructor take a wxWindow* parent with a default value of NULL, + // we could have just had designed MyFrame class with an empty + // constructor and then written here: + // wxXmlResource::Get()->LoadFrame(this, (wxWindow* )NULL, "main_frame"); + // since this frame will always be the top window, and thus parentless. + // However, the current approach has source code that can be recycled + // for other frames that aren't the top level window.] + wxXmlResource::Get()->LoadFrame(this, parent, "main_frame"); + + // Set the icon for the frame. + SetIcon(wxICON(appicon)); + + // Load the menubar from XRC and set this frame's menubar to it. + SetMenuBar(wxXmlResource::Get()->LoadMenuBar("main_menu")); + // Load the toolbar from XRC and set this frame's toolbar to it. + // NOTE: For toolbars you currently should do it exactly like this. + // With toolbars, you currently can't create one, and set it later. It + // needs to be all in one step. + SetToolBar(wxXmlResource::Get()->LoadToolBar(this, "main_toolbar")); + + // Give the frame a optional statusbar. The '1' just means one field. + // A gripsizer will automatically get put on into the corner, if that + // is the normal OS behaviour for frames on that platform. Helptext + // for menu items and toolbar tools will automatically get displayed + // here. + CreateStatusBar( 1 ); +} + +//----------------------------------------------------------------------------- +// Private methods +//----------------------------------------------------------------------------- + +void MyFrame::OnExitToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + // TRUE is to force the frame to close. + Close(TRUE); +} + + +void MyFrame::OnNonDerivedDialogToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + // "non_derived_dialog" is the name of the wxDialog XRC node that should + // be loaded. + wxXmlResource::Get()->LoadDialog(&dlg, this, "non_derived_dialog"); + dlg.ShowModal(); + +} + + +void MyFrame::OnDerivedDialogToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + // Make an instance of our derived dialog, passing it "this" window + // (the main frame) as the parent of the dialog. This allows the dialog + // to be destructed automatically when the parent is destroyed. + PreferencesDialog preferencesDialog(this); + // Show the instance of the dialog, modally. + preferencesDialog.ShowModal(); +} + + +void MyFrame::OnControlsToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "controls_dialog"); + +#if wxUSE_LISTCTRL + // There is no data in the listctrl. This will add some columns + // and some data. You don't need use any pointers + // at all to manipulate the controls, just simply use the XRCCTL(...) macros. + // "controls_treectrl" is the name of this control in the XRC. + // (1) Insert a column, with the column header of "Name" + // (The '_' function around "Name" marks this string as one to translate). + XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertColumn( 0, + _("Name"), + wxLIST_FORMAT_LEFT, + ( 200 ) + ); + // (2) Insert some items into the listctrl + XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(0,wxT("Todd Hope")); + XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(1,wxT("Kim Wynd")); + XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(2,wxT("Leon Li")); +#endif + +#if wxUSE_TREECTRL + // There is no data in the tree ctrl. These lines will add some. + // (1) Instead of having to write out + // XRCCTRL(dlg, "controls_treectrl", wxTreeCtrl)->SomeFunction() + // each time (which is also OK), this example code will shown how + // to make a pointer to the XRC control, so we can use + // treectrl->SomeFunction() as a short cut. This is useful if you + // will be referring to this control often in the code. + wxTreeCtrl* treectrl = XRCCTRL(dlg, "controls_treectrl", wxTreeCtrl); + // (2) Add a root node + treectrl->AddRoot(_("Godfather")); + // (3)Append some items to the root node. + treectrl->AppendItem(treectrl->GetRootItem(), _("Evil henchman 1")); + treectrl->AppendItem(treectrl->GetRootItem(), _("Evil henchman 2")); + treectrl->AppendItem(treectrl->GetRootItem(), _("Evil accountant")); +#endif + + // All done. Show the dialog. + dlg.ShowModal(); +} + + +void MyFrame::OnUncenteredToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "uncentered_dialog"); + dlg.ShowModal(); +} + + +void MyFrame::OnCustomClassToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "custom_class_dialog"); + + // Make an instance of our new custom class. + MyResizableListCtrl* a_myResizableListCtrl = new MyResizableListCtrl(&dlg, + -1, + wxDefaultPosition, + wxDefaultSize, + wxLC_REPORT, + wxDefaultValidator); + + // "custom_control_placeholder" is the name of the "unknown" tag in the + // custctrl.xrc XRC file. + wxXmlResource::Get()->AttachUnknownControl("custom_control_placeholder", + a_myResizableListCtrl); + dlg.ShowModal(); +} + + +void MyFrame::OnPlatformPropertyToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "platform_property_dialog"); + dlg.ShowModal(); +} + + +void MyFrame::OnArtProviderToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "art_provider_dialog"); + dlg.ShowModal(); +} + + +void MyFrame::OnVariableExpansionToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "variable_expansion_dialog"); + dlg.ShowModal(); +} + + +void MyFrame::OnAboutToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxString msg; + msg.Printf( _T("This is the about dialog of XML resources demo.\n") + _T("Welcome to %s"), wxVERSION_STRING); + + wxMessageBox(msg, "About XML resources demo", wxOK | wxICON_INFORMATION, this); +} diff --git a/contrib/samples/xrc/myframe.h b/contrib/samples/xrc/myframe.h new file mode 100644 index 0000000000..c2246335b5 --- /dev/null +++ b/contrib/samples/xrc/myframe.h @@ -0,0 +1,67 @@ +//----------------------------------------------------------------------------- +// Name: myframe.h +// Purpose: XML resources sample: A derived frame, called MyFrame +// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik +// RCS-ID: $Id$ +// Copyright: (c) Robert O'Connor and Vaclav Slavik +// Licence: wxWindows licence +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Begin single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#ifndef _MYFRAME_H_ +#define _MYFRAME_H_ + +//----------------------------------------------------------------------------- +// GCC interface +//----------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma interface "myframe.h" +#endif + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "wx/frame.h" + +//----------------------------------------------------------------------------- +// Class definition: MyFrame +//----------------------------------------------------------------------------- + +// Define a new frame type: this is going to be our main frame +class MyFrame : public wxFrame +{ + +public: + + // Constructor. + MyFrame( wxWindow* parent=(wxWindow *)NULL); + +private: + + // Event handlers (these functions should _not_ be virtual) + void OnExitToolOrMenuCommand(wxCommandEvent& event); + void OnAboutToolOrMenuCommand(wxCommandEvent& event); + void OnNonDerivedDialogToolOrMenuCommand(wxCommandEvent& event); + void OnDerivedDialogToolOrMenuCommand(wxCommandEvent& event); + void OnControlsToolOrMenuCommand(wxCommandEvent& event); + void OnUncenteredToolOrMenuCommand(wxCommandEvent& event); + void OnCustomClassToolOrMenuCommand(wxCommandEvent& event); + void OnPlatformPropertyToolOrMenuCommand(wxCommandEvent& event); + void OnArtProviderToolOrMenuCommand(wxCommandEvent& event); + void OnVariableExpansionToolOrMenuCommand(wxCommandEvent& event); + + // Any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + +}; + +//----------------------------------------------------------------------------- +// End single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#endif // _MYFRAME_H_ diff --git a/contrib/samples/xrc/rc/appicon.ico b/contrib/samples/xrc/rc/appicon.ico index 6082b2fd0ad8699499e1fd873f9a0d49994d312c..f3ef7918d273b912ce9d18f570cec891290ad3c7 100644 GIT binary patch literal 1078 zcmcgqF>ZuF3^b=mX?X%wbkEoVDP7)j9j&{i%a?cn65mKkmj-DwW8({}i%zE~%7E=1 zukH03L>f6s+qOcS8<7{-u5(3Rk;$|xj}C{5;1yLj&{)beO|aZ3 z_DU&SLGaK;z5{N<=+Nwb+GQ&R7J8vw3YG^R`<9?N^83C|DQSiUG!F*d>yO{(dME7W zH^Mn}kOYZ2DP|b>t2srzM{V45w{d@;!Z2ulj|tFzKE^S60NUd>=W}o@2)J#3TUP6~ z%+BYs;!Bhj0o+H}&ddB0M_Lt+w7MPws`Gd-aqWkl0@r?xnezVc@_K-`^RwTID)Ex> epMk$#hUd#2ZizSb>f=Ub(IcYQqwl}gJo^hm2;JWR literal 2238 zcmcgtO=uit7=C7E{}XrTXLlzthYeVk-YQy(vel+(D1sr~L!hPX$sBUgnl1zbIiv}5 z@Zd$8&>lR5HU$xdVi$LBlQa_*TJTchO`-?|Q)EG86C5%=-#4?_4G7+Rmv`p--sgSZ zzwg^!K;dU}6jHuO0Y$D(Q%9*|R0T8&iG{EJXH1PDw&K83Jve;F#$)gvdx%}9s@!vZ z_O-L{k9_!#ebm16@zu{hF%PxtHNGdv_pxzrgWL&niP3k0abl_u^{4`@pM%rsKy_U- zYYxtPDo_urXx=h#entUqa=#2*n*`q22ksmKHuvwfpJS~R;OnUXZ*B#+Q)|NZDyY`$ zSj26{pJjXn`3^Ae0;)X?Jle)=rw)bt&)K~?M?2%Gj3=fc8DK{_bVPcjXK;_8fHHu z@C~Y9!>rG#Zo=Q+MVavx5x;c=ZJ0GMKbRkP$5R}1TI5}yD_(l zYSiDf^BdagHp)C8k$((4Kb)h6`OtEJVV+;K{cv{$rl>2Dxjn!XvBGiS=?B2h5Vw*4 z#by%^Di!wgEBj&J;Q29Al}{np8Xg|3Zlm)f`+ZAT%G9CbelK0-mg&24Njb$O3y5r! z)fZ?lj-$*27w4yb-{Kcy7T~2#=pS$Y_N?6c6c6jhx6eDxeAY#GCI}> z+=nZiRh#9tP}Qe^wJm%%Bk`Ag*6f`5c}v5tACgJso44S81U@wyP_y;(nKU}$*; z2i2Q!7neEPP5Ph0JVtn(R^X^@_-LW*OhHk%P$K^Z`5nP$XH$&dW_(s8`?>$SjWbss zVO$Rf`t%tv!V6k`@-pjO!9{XzP&;`Z?>taao7{8W`S-bB#kx8xzY}!%Uqy?unWp)# zc?|{e2r!IP^n2CkX&45CM!==EJ64!EOCc;^>xS=fr=M zlr-rX=tVjRPLY8%EoX_LNQr4?CNmHhbdfX1DP`hjE?0~)NPd2hW`PUX&IpHy4$)pF zFU+GPg=tgg?IJB77#U+IE8B z)%?Iqg5FCH9xg2`FsW%~Tsp_KUV7OE`%&%QMEk0bx->bE~ AumAu6 diff --git a/contrib/samples/xrc/rc/appicon.xpm b/contrib/samples/xrc/rc/appicon.xpm index 948961fe5c..dd66f6e8c4 100644 --- a/contrib/samples/xrc/rc/appicon.xpm +++ b/contrib/samples/xrc/rc/appicon.xpm @@ -1,61 +1,52 @@ -/* XPM */ -static char* appicon_xpm[]={ -"32 32 26 1", -"s c #000000", -"u c #ff8000", -"m c #ffc0ff", -"q c #400000", -". c None", -"t c #004040", -"d c #303030", -"n c #ffdca8", -"e c #c0c0c0", -"x c #808000", -"o c #c00000", -"c c #585858", -"b c #a0a0a4", -"f c #c000c0", -"# c #000000", -"i c #808080", -"p c #ffa858", -"v c #ffff00", -"k c #800000", -"w c #c0c000", -"r c #004000", -"h c #404000", -"j c #ffc0c0", -"a c #ffffff", -"l c #c05800", -"g c #ff0000", -".....#####...........##.........", -"...##abbccd........##c#.........", -"###aaaebfgh########abi#.........", -"#cbaaaejggkiibeeaaaeeic#........", -"#ieaaaefggldggfjmnaaeei#........", -"#ibeaajggggcggggfmaaabi#b.......", -"#iieaajggggolgggggmaaeec#.......", -"#cieaajgggggdgggggpmaeec#.......", -"#cieaajgggggqgggggggaabi#.......", -"#dieaajpgggcc##cggggaaebc###....", -"#ribaamecccccs##cgggaebccth##...", -"#dieaa#qtdcch###tcs#iichd####...", -"##cbea##dccccs##qhhccccct#####..", -"##iiea##rhccch##tsdtcccdh#####..", -"##cbea###tccookk#hrdhccccs####..", -"##ciea###koogookkddtcccch###q#..", -"##tiea##qoggggokkqhqccccckokkk#.", -"##hbeb#qkoogggookkqkoklkoookkk#.", -"###icb#kkooggggokkdkogggggookk#.", -"###d..#kkoogggouukqkooggggookk#.", -"##....#kkkoguvvvwuhkogggggooko#.", -"##....##kolwvvvvvulcllggggulll#.", -"##....##kuuvvvvvuvudwuuuuuvuuu#.", -"......##uuuuvvvvvuuqivvvvvvuuu#.", -"......##uuuvvwwiqcllhuvvvvvuuu#.", -"......##uuuwl##xuphdivvvvvvvul#.", -"......##uuu##e.#vltcuvuvvvvux#..", -"......##ux#e....###uuww######...", -"......##i#......bbb####.........", -"......###.......................", -"......##........................", -"......##........................"}; +/* XPM */ +static char * appicon_xpm[] = { +"32 32 17 1", +" c None", +". c #000000", +"+ c #800000", +"@ c #008000", +"# c #808000", +"$ c #000080", +"% c #800080", +"& c #008080", +"* c #C0C0C0", +"= c #808080", +"- c #FF0000", +"; c #00FF00", +"> c #FFFF00", +", c #0000FF", +"' c #FF00FF", +") c #00FFFF", +"! c #FFFFFF", +" ", +"===============================.", +"=*****************************=.", +"=*$$$$$$$$$$$$$$$$$$$$$$$$$$$$=.", +"=*$$$$$$$$$$$$$$$$$$$**.**.**.=.", +"=*$$$$$$$$$$$$$$$$$$$**.**.**.=.", +"=*$$$$$$$$$$$$$$$$$$$.........=.", +"=*****************************=.", +"=*=============================.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!,!!!!!!!!!!!,!!!!!!*=.", +"=*=!!!!!!,,!!!!!!!!!!!,,!!!!!*=.", +"=*=!!!!!,,!!!!!!!!!!!!!,,!!!!*=.", +"=*=!!!!,,!!...........!!,,!!!*=.", +"=*=!!!,,!!!.$$$$$$!!!.!!!,,!!*=.", +"=*=!!,,!!!!.$$$$$$!!!.!!!!,,!*=.", +"=*=!!,,!!!!.$$$$$$!!!.!!!!,,!*=.", +"=*=!!!,,!!!.$$$$$$!!!.!!!,,!!*=.", +"=*=!!!!,,!!...........!!,,!!!*=.", +"=*=!!!!!,,!!!!!!!!!!!!!,,!!!!*=.", +"=*=!!!!!!,,!!!!!!!!!!!,,!!!!!*=.", +"=*=!!!!!!!,!!!!!!!!!!!,!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*****************************=.", +"===============================.", +"................................", +" ", +" "}; diff --git a/contrib/samples/xrc/rc/artprov.xpm b/contrib/samples/xrc/rc/artprov.xpm new file mode 100644 index 0000000000..63ba702fe7 --- /dev/null +++ b/contrib/samples/xrc/rc/artprov.xpm @@ -0,0 +1,23 @@ +/* XPM */ +static char * artprov_xpm[] = { +"16 16 4 1", +" c None", +". c #000000", +"+ c #0E2CEF", +"@ c #FFFFFF", +" . ", +" . . ", +" . . ", +"++++++++++++++++", +"+@@@@@@@@@@@@@@+", +"+@@@@@@++@@@@@@+", +"+@@@@@@@@@@@@@@+", +"+@@@@@+++@@@@@@+", +"+@@@@@@++@@@@@@+", +"+@@@@@@++@@@@@@+", +"+@@@@@@++@@@@@@+", +"+@@@@@++++@@@@@+", +"+@@@@@@@@@@@@@@+", +"++++++++++++++++", +" ", +" "}; diff --git a/contrib/samples/xrc/rc/artprov.xrc b/contrib/samples/xrc/rc/artprov.xrc new file mode 100644 index 0000000000..629c86bcd3 --- /dev/null +++ b/contrib/samples/xrc/rc/artprov.xrc @@ -0,0 +1,67 @@ + + + + + + wxArtProvider Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + You can specify wxArtProvider icons in your XRC resources. These icons will be retrieved from the active wxArtProvider (see wxArtProvider in docs and /samples/artprov for more information on wxArtProvider).\n\nThe most common usage for this is that you want a dialog, toolbar or menu item to have the correct platform-specific icon in your interface, such as a custom "Don't show this again" checkbox message dialog that has the appropriate icon, as shown below.\n\nYou can also use it to manage your own custom bitmaps though, too--instead of having to write multiple versions of an XRC file that only differ in their bitmaps, you can instead just write one XRC file with the bitmap to be retrieved from the wxArtProvider at runtime, having your custom wxArtProvider use some code to serve out the desired bitmap based on such things as a wxConfig n entry of a desired icon set, what OS the application is running on, what size or resolution the display is, and so on.\n\nNote that your application's custom bitmaps are the only thing that will differ between OS's in order to ensure proper Look And Feel, as everything else: windows decoration, colors, fonts, widgets, etc already match perfectly since wxWindows runs natively.\n\nTo use a wxArtProvider bitmap instead of usual bitmap, in your XRC, instead of <bitmap>somefile.png</bitmap>, use <bitmap stock__id="SOME__ART__ID" client="SOME__CLIENT__ID">somefile.png</bitmap>. The stock__id parameter is required for a bitmap to be read from wxArtProvider, stock__client is optional. The image filename is also optional, and is just used as a fallback in case the wxArtProvider couldn't return a bitmap for that particular stock__id (and particular stock__client if your wxArtProvider is set up to also filter stock__client). + + + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 2 + 0 + 0 + 0 + 1 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + derivdlg.xpm + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + diff --git a/contrib/samples/xrc/rc/basicdlg.xpm b/contrib/samples/xrc/rc/basicdlg.xpm new file mode 100644 index 0000000000..fd6d714496 --- /dev/null +++ b/contrib/samples/xrc/rc/basicdlg.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * basicdlg_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #808080", +"@ c #0000FF", +"# c #FFFFFF", +" ", +"................", +".++++++++++++++.", +".+@@@@@@@@@@@@+.", +".++++++++++++++.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".++++++++++++++.", +"................", +" "}; diff --git a/contrib/samples/xrc/rc/basicdlg.xrc b/contrib/samples/xrc/rc/basicdlg.xrc new file mode 100644 index 0000000000..9cea321aa7 --- /dev/null +++ b/contrib/samples/xrc/rc/basicdlg.xrc @@ -0,0 +1,48 @@ + + + + + + Non-Derived Dialog Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + This is the basic non-derived XRC dialog. It is just an instance of wxDialog, not a instance of a class derived from wxDialog that was given some added functionality.\n\nYou can put whatever controls you want on these non-derived dialogs, but the dialog won't interact with the controls, nor do anything in response to any of their events. It only has the built-in functionality of a wxDialog, and that is it. A non-derived dialog can automatically close itself when you hit either the OK or Cancel button (returning a return code of what button you pressed), and not much else.\n\nThese are useful for an About dialog, or a message dialog popup, but that's about it. For the rest you will almost certainly use a derived dialog (see next example). + + + + wxALIGN_CENTRE|wxALL + 5 + + wxHORIZONTAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + diff --git a/contrib/samples/xrc/rc/controls.xpm b/contrib/samples/xrc/rc/controls.xpm new file mode 100644 index 0000000000..acb1c77516 --- /dev/null +++ b/contrib/samples/xrc/rc/controls.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char * controls_xpm[] = { +"16 16 6 1", +" c None", +". c #000000", +"+ c #808080", +"@ c #0000FF", +"# c #FFFFFF", +"$ c #0E2CEF", +" ", +" ", +" ", +" ", +" ", +"................", +".++++++++++++++.", +".+@@@@@@@@####+.", +".+$$$$$$$$####+.", +".+$$$$$$$$####+.", +".++++++++++++++.", +"................", +" ", +" ", +" ", +" "}; diff --git a/contrib/samples/xrc/rc/controls.xrc b/contrib/samples/xrc/rc/controls.xrc new file mode 100644 index 0000000000..119716ad1b --- /dev/null +++ b/contrib/samples/xrc/rc/controls.xrc @@ -0,0 +1,801 @@ + + + + + + Controls Example + + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 1 + 550,200 + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + controls.xpm + + + + + + + + + + 2 + 0 + 0 + 0 + 0,1 + 0,1 + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + -1,-1 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + 1 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 180,180 + + Download library + Compile samples + Skim docs + Finish project + Wash car + + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 180,-1 + + See + Hear + Feel + Smell + Taste + The Sixth Sense! + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 200,-1 + + 4 + + vim + emacs + notepad.exe + bbedit + nedit + + + + + + + + + + + 2 + 0 + 0 + 0 + 0,1 + 0,1 + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + 100,-1 + 100 + 50 + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + 40,60 + 100 + 40 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 200,200 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 450,250 + + <h2>XRC Resources HTML</h2> + <p><font color="#0000FF">XRC=Blue skies ahead.</font> + <p>Italics useful for quoted or emphasized text:<i>"Some see things as they are and say why. + I dream things that never were, and say why not"</i> + <p><pre>Fixed width for code snippets.</pre> + <p>Horizontal rules to organize sections: <hr> + <p>A wxImage is worth a thousand words and can be also used. + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTER|wxALL + 5 + + 250,160 + + + Milk + Pizza + Bread + Orange juice + Paper towels + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTER|wxALL + 5 + + 220,160 + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 200,160 + #0000FF + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + 1 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + + 1 + 0 + + Power 108 + WMMS 100.7 + Energy 98.3 + CHUM FM + 92FM + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + -1,160 + 50 + 100 + 30 + + + + + + + + + + + 2 + 0 + 0 + 0 + 0,1 + 0,1 + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 100,-1 + + 100 + 0 + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 100,-1 + + 100 + 0 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + 100 + 0 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 100,-1 + 100 + 0 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + appicon.xpm + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + wxVERTICAL + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0,1 + + wxALIGN_CENTRE|wxALL + 5 + + -1,100 + + + + + wxALIGN_CENTRE|wxALL + 5 + + 150,-1 + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + 2 + 0 + 0 + 0 + 0,1 + 0,1,2 + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 180,-1 + A.A. Milne + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 180,-1 + + TooManySecrets + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 180,90 + + "So many pretty widgets" said Pooh, said he. "So many pretty widgets", said Pooh. + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 280,180 + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0,1,2,3,4,5,6 + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + diff --git a/contrib/samples/xrc/rc/custclas.xpm b/contrib/samples/xrc/rc/custclas.xpm new file mode 100644 index 0000000000..597bfb3bf3 --- /dev/null +++ b/contrib/samples/xrc/rc/custclas.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static char * custclas_xpm[] = { +"16 16 7 1", +" c None", +". c #EBF70E", +"+ c #000000", +"@ c #808080", +"# c #0000FF", +"$ c #FFFFFF", +"% c #0E2CEF", +" ", +" . ", +" . ", +" . . . ", +" ... ", +"...+....++++++++", +"+@...@@@@@@@@@@+", +"+.#.#.####$$$$@+", +"+@%.%%%%%%$$$$@+", +"+@%.%%%%%%$$$$@+", +"+@@@@@@@@@@@@@@+", +"++++++++++++++++", +" ", +" ", +" ", +" "}; diff --git a/contrib/samples/xrc/rc/custclas.xrc b/contrib/samples/xrc/rc/custclas.xrc new file mode 100644 index 0000000000..1d7b21134e --- /dev/null +++ b/contrib/samples/xrc/rc/custclas.xrc @@ -0,0 +1,42 @@ + + + + + + Custom Class Example + 1 + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + You can embed your own custom classes into an XRC file. This is referred to as attaching an unknown control.\n\nThere are 3 main cases when you would want to do this:\n\n(A) Most commonly: you have derived a class from one of the main wxWindows controls, so that it can manage its own state and look after its own events, because it is better management to have a portable class with all the code for that control in there with the class, instead of being having many event handlers for that control scattered up in its parent dialog (which is allowed, but gets messy if a control has alot of methods). For example, if you require a wxListCtrl that popups a menu when right-clicked on an item, and you want the wxListCtrl to resize its columns in response to an OnSize(), and a few more methods, it makes better sourcecode logic to package all these methods into by a standalone derived wxListCtrl class, instead of having the parent dialog manage all these events and other functions. This is what the example below shows: it does a custom behaviour of resizing its first column to appropriately fill up the width of the control on a resize event, and it pops up a context-menu in response to a left click (and shades out popup menu item appropriately if there is no item currenty selected in the listctrl).\n\n(B)You have an utterly new widget that has no equivalent in the wxWindows class heirarchy, so you thus need to embed your class to get the needed functionality.\n\n(C) You are using one of the rarely used wxWindows controls that doesn't have an XRC handler in the XRC library. However, all of the major controls: wxButton, wxTextCtrl, etc have an XRC handler, so this is pretty rare, and you could always write your own XRC handler for that control if you wanted. You can choose the "Controls example" from the XRC demo menu to see all the controls that have an XRC handler.\n\nThe typical formula for attaching an unknown control is:\n\n(1) If you are deriving your own custom class to be embedded into the XRC, describe that class with its own .cpp and .h file. In this example it is custclass.cpp and custclass.h\n\n(2)Specify an "unknown" tag in the XRC file that you want to embed it into (see the unknown tag in custclass.xrc). This will be the placeholder of the new class.\n\n(3) Load the XRC dialog as usual, but before you show the dialog to the user, construct an instance of your custom control, and then use wxXmlResource::Get()->AttachUnknownControl() to put the custom class into its "unknown" placeholder in the XRC file.\n\nThe result is what you see below, a custom class control that fits in seemlessly with the whole dialog, the same as if it was read from XRC directly. Try out resizing this dialog, and watch the listctrl column resize, and right-click to call up its popup menu. By the way, if you look at the source of this XRC dialog, you will that this dialog node has a set of style flags that includes wxRESIZE__BORDER--that is why this dialog is resizable, whereas most of the rest of the dialogs in the XRC sample that don't include this tag, are not resizable. + + + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 100,100 + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + diff --git a/contrib/samples/xrc/rc/derivdlg.xpm b/contrib/samples/xrc/rc/derivdlg.xpm new file mode 100644 index 0000000000..aa1aeadb79 --- /dev/null +++ b/contrib/samples/xrc/rc/derivdlg.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char * derivdlg_xpm[] = { +"16 16 6 1", +" c None", +". c #EBF70E", +"+ c #000000", +"@ c #808080", +"# c #0000FF", +"$ c #FFFFFF", +" . ", +"+++.++++++++++++", +"+.@.@.@@@@@@@@@+", +"+@...#########@+", +"...@....@@@@@@@+", +"+@...$$$$$$$$$@+", +"+.$.@.@@@@@@$$@+", +"+@$.@@@@@@@@$$@+", +"+@$.$$$$$$$$$$@+", +"+@$$$$$$$$$$$$@+", +"+@$$$$@@@@$$$$@+", +"+@$$$$@@@@$$$$@+", +"+@$$$$$$$$$$$$@+", +"+@@@@@@@@@@@@@@+", +"++++++++++++++++", +" "}; diff --git a/contrib/samples/xrc/rc/derivdlg.xrc b/contrib/samples/xrc/rc/derivdlg.xrc new file mode 100644 index 0000000000..cbf8318c7a --- /dev/null +++ b/contrib/samples/xrc/rc/derivdlg.xrc @@ -0,0 +1,78 @@ + + + + + + Derived Dialog Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + This is a derived dialog using XRC. This type of derived dialog will likely be the heart of your project, and thus is the most important example in this demonstration.\n\nIt is recommeded to open up derivdlg.cpp, derivdlg.h and derivdlg.xrc and follow along what is going on.\n\nThe steps to use a derived dialog are:\n\n(1) Derive your own dialog from wxDialog (derivdlg.cpp and derivdlg.h are an example).\n\n(2) In the source of the constructor of the derived dialog, load the XRC into the file, using the code as shown in the derivdlg.cpp\n\n(3)Add to the derived dilog's sourcecode some event handlers and other methods you want the dialog to do.\n\n(4)You can now just make an instance of the derived dialog and show it using ShowModal(), as is done in the MyFrame::OnDerivedDialogToolOrMenuCommand() method.\n\nThe remainder of this docuent will talk about how to use events with derived dialogs and XRC. There are 3 bits of a extra event functionality that this derived derived dialog can do, these will be described in turn:\n\n(A) Something to do when a user clicks on your custom button: This is straightforward. You name a control in the XRC file (in this example it is "my__button"). Then in the .cpp file, put an entry in the event table that will connect button clicks with that ID to a function that will be fired. The event table entry in the example is EVT__BUTTON( XRCID( "my__button" ), PreferencesDialog::OnMyButtonClicked ) This event table entry has 3 parts: The first part, EVT__BUTTON tells that you are describing a button click event. The final part, PreferencesDialog::OnMyButtonClicked() is what you want done in response to a buttun event. The middle part, XRCID( "my__button" ) is the restriction that only button events generated by a wxButton of that ID should trigger go on to do the function. This XRCID is the name of the wxButton in your XRC file. Now just describe, in the .h file and .cpp file, what you want your custom OnMyButtonClicked() function to do.\n\n(B) The second example is a very common requirement: that a checkbox or radiobutton disables some other control. The event table is set up the same as the "My Button" example above. However, it isn't a EVT__BUTTON event, it is a EVT__UPDATE__UI event: when the dialog does an updating of ts UI (and thus fires this event) if the updating if of a control matching that XRCID, then it will do the specified function (which in this case looks at whether or not the checkbox is checked, and if it isn't checked, then disable the textctrl).\n\n(C) The last example shows how to handle the OK button. You will likely want to do something when the user presses OK, like save preferences or start some action (this example shows a simple case of just popping up a dialog and stopping a close). OK buttons are always named wxID__OK, so the XRC file should have it as wxID__OK also. The Event table has a EVT__BUTTON entry for wxID__OK (no XRCID though). Since this is a derived dialog with an event table, in response to a EVT__BUTTON event from a wxID__OK button, it will first look around in its own event table to see if there was any EVT__BUTTON entries, and since there is, it will do that one--if there wasn't it then check out the base class's event table and see if there was one there, and so on up the chain of inherited classes. Note that this is exactly what happens with the derived dialog's wxID__CANCEL button. You didn't put any EVT__BUTTON entries with an identifier of wxID__CANCEL, so after it scans your derived dialog's event table, it will then look at wxDialog's event table and see if there is one in that event table, and so on until it finds one. It will find a wxID__CANCEL handler, which will connect to the proper function (which causes the dialog to close). + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + wxHORIZONTAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + 80,-1 + + + + + + + wxALIGN_CENTRE|wxALL + 5 + + wxHORIZONTAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + diff --git a/contrib/samples/xrc/rc/frame.xrc b/contrib/samples/xrc/rc/frame.xrc new file mode 100644 index 0000000000..8b9c8ca5b8 --- /dev/null +++ b/contrib/samples/xrc/rc/frame.xrc @@ -0,0 +1,27 @@ + + + + + + XML Resources Demo + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,280 + + Welcome to the wxWindows XmlResource (XRC) sample! Using wxWindows XML resources makes your GUI C++ programming much faster and easier.\n\nView the examples under the "Basic" menu to learn how to get up and running with XRC quickly, and later have a look at the examples under the "Advanced" menu for advanced techniques.\n\nThe XML file that described this frame is the sample's frame.xrc file, with the menu in menu.xrc, and the toolbar in toolbar.xrc. The frame XRC file structure is exactly the same as the XRC files for the dialogs, except that the top level node is a wxFrame, not a wxDialog. Each of the other dialog in this example is a separate XRC file, each of which can be examined for how they work. + + + + + + diff --git a/contrib/samples/xrc/rc/menu.xrc b/contrib/samples/xrc/rc/menu.xrc new file mode 100644 index 0000000000..64d3ccbf04 --- /dev/null +++ b/contrib/samples/xrc/rc/menu.xrc @@ -0,0 +1,72 @@ + + + + + + + + + + + + Exit this application + + + + + Basic techniques with XRC + + + basicdlg.xpm + The basic instance of wxDialog loaded via XRC + + + + derivdlg.xpm + The most important example: load an XRC for a derived dialog + + + + controls.xpm + A notebook displaying all the wxWindows controls + + + + uncenter.xpm + Disable autocentering of a dialog on its parent + + + + + Advanced techniques with XRC + + + custclas.xpm + Embed your own custom classes into an XRC + + + + platform.xpm + Customize parts of an interface for a desired platform + + + + artprov.xpm + Use wxArtProvider to insert desired icons at runtime + + + + variable.xpm + Replace variables in the XRC file at runtime + + + + + + + About this application + + + + + diff --git a/contrib/samples/xrc/rc/platform.xpm b/contrib/samples/xrc/rc/platform.xpm new file mode 100644 index 0000000000..8702c4bbf2 --- /dev/null +++ b/contrib/samples/xrc/rc/platform.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static char * platform_xpm[] = { +"16 16 2 1", +" c None", +". c #0000FF", +" ", +" .. ", +" .. ", +" . ", +" ... .... ", +" ........... ", +" .......... ", +" .......... ", +" .......... ", +" .......... ", +" ........... ", +" ........... ", +" ........... ", +" ......... ", +" ... ... ", +" "}; diff --git a/contrib/samples/xrc/rc/platform.xrc b/contrib/samples/xrc/rc/platform.xrc new file mode 100644 index 0000000000..9f143bf5a8 --- /dev/null +++ b/contrib/samples/xrc/rc/platform.xrc @@ -0,0 +1,145 @@ + + + + + + Platform Property Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + You can specify certain nodes of an XRC file to only be used for a certain platform.\n\nTo do this, there is a "platform" property that can be placed in any node [ie inside an opening tag]. The value of the tag can be any combination of the following: mac, win, unix, or os2. Use a | symbol between multiple platforms, for example <label platform="win|mac">\n\nAt runtime, if there is a platform property in the tag, if it matches the current operating system, that node will be included, otherwise it won't.\n\nThe notebook example below shows how you can specify a high level node to only appear on a certain platform: the example here being a page of preferences that only make sense on a certain platform.\n\nThe second example shows how to replace a single attribute of a control: here the label of a download link. It is also very useful for specifying menu item accelerators keystrokes on the target platform. + + + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 1 + 200,160 + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + diff --git a/contrib/samples/xrc/rc/sppicon.ico b/contrib/samples/xrc/rc/sppicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..f3ef7918d273b912ce9d18f570cec891290ad3c7 GIT binary patch literal 1078 zcmcgqF>ZuF3^b=mX?X%wbkEoVDP7)j9j&{i%a?cn65mKkmj-DwW8({}i%zE~%7E=1 zukH03L>f6s+qOcS8<7{-u5(3Rk;$|xj}C{5;1yLj&{)beO|aZ3 z_DU&SLGaK;z5{N<=+Nwb+GQ&R7J8vw3YG^R`<9?N^83C|DQSiUG!F*d>yO{(dME7W zH^Mn}kOYZ2DP|b>t2srzM{V45w{d@;!Z2ulj|tFzKE^S60NUd>=W}o@2)J#3TUP6~ z%+BYs;!Bhj0o+H}&ddB0M_Lt+w7MPws`Gd-aqWkl0@r?xnezVc@_K-`^RwTID)Ex> epMk$#hUd#2ZizSb>f=Ub(IcYQqwl}gJo^hm2;JWR literal 0 HcmV?d00001 diff --git a/contrib/samples/xrc/rc/toolbar.xrc b/contrib/samples/xrc/rc/toolbar.xrc new file mode 100644 index 0000000000..9bc8082182 --- /dev/null +++ b/contrib/samples/xrc/rc/toolbar.xrc @@ -0,0 +1,51 @@ + + + + + + + 2,2 + + Non-Derived Dialog Example + basicdlg.xpm + The basic instance of wxDialog loaded via XRC + + + Derived Dialog Example + derivdlg.xpm + The most important example: load an XRC for a derived dialog + + + Controls Example + controls.xpm + A notebook displaying all the wxWindows controls + + + Uncentered Example + uncenter.xpm + Disable autocentering of a dialog on its parent + + + + Custom Class Example + custclas.xpm + Embed your own custom classes into an XRC + + + Platform Specific Example + platform.xpm + Customize parts of an interface for a desired platform + + + wxArtProvider Example + artprov.xpm + Use wxArtProvider to insert desired icons at runtime + + + Variable Expansion Example + variable.xpm + Replace variables in the XRC file at runtime + + + + diff --git a/contrib/samples/xrc/rc/uncenter.xpm b/contrib/samples/xrc/rc/uncenter.xpm new file mode 100644 index 0000000000..3ad911f2c6 --- /dev/null +++ b/contrib/samples/xrc/rc/uncenter.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * uncenter_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #808080", +"@ c #0000FF", +"# c #FFFFFF", +" ", +"................", +".++++++++++++++.", +".+@@@@@@@@@@@@+.", +".++++++++++++++.", +".+############+.", +".+###....#####+.", +".+###..#######+.", +".+###.#.######+.", +".+###.##.#####+.", +".+#######.####+.", +".+########.###+.", +".+############+.", +".++++++++++++++.", +"................", +" "}; diff --git a/contrib/samples/xrc/rc/uncenter.xrc b/contrib/samples/xrc/rc/uncenter.xrc new file mode 100644 index 0000000000..b1613d8ef5 --- /dev/null +++ b/contrib/samples/xrc/rc/uncenter.xrc @@ -0,0 +1,47 @@ + + + + + + Uncentered Example + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + All of the dialogs in the XRC demo, except for this dialog, center themselves automatically on their parent window, since that is what is most commonly needed. The centering for the other dialogs was done automatically simply by including a <centered>1</centered> as a tag directly under the dialog node.\n\nHowever, there may be some times when you don't want autocentering. If you don't want the dialog centered, just don't use the <centered> tag and the dialog will be placed in the default window position (which is at screen coordinate 0,0 in the upper left corner of the screen). This dialog is an example of when centering is turned off. + + + + wxALIGN_CENTRE|wxALL + 5 + + wxHORIZONTAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + diff --git a/contrib/samples/xrc/rc/variable.xpm b/contrib/samples/xrc/rc/variable.xpm new file mode 100644 index 0000000000..fdf792d3ad --- /dev/null +++ b/contrib/samples/xrc/rc/variable.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static char * variable_xpm[] = { +"16 16 2 1", +" c None", +". c #0E2CEF", +" ", +" . ", +" ... .. ", +" .... .. ", +" ...... .. ", +" . ... .. ", +" . ..... ", +" ... ", +" .... ", +" ..... . ", +" .. ... . ", +" .. ..... ", +" .. ... ", +" . ... ", +" ", +" "}; diff --git a/contrib/samples/xrc/rc/variable.xrc b/contrib/samples/xrc/rc/variable.xrc new file mode 100644 index 0000000000..b2d54bf4e9 --- /dev/null +++ b/contrib/samples/xrc/rc/variable.xrc @@ -0,0 +1,59 @@ + + + + + + Variable Expansion Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + VARIABLE EXPANSION ISN'T IMPLEMENTED CURRENTLY. You can use variable expansion in your XRC files. The steps to do this are:\n\n(1)Enclose a variable inside a dollarsign and round brackets, like this: dollarsign(version).\n\n(2) Set the XmlResource flags to allow expansion of variables.\n\n(3)Before you use that XML resource, inform the XmlResourceHandler what you want that variable's value to be, via wxResourceHandler::Get()->SetVariable( "version", "2.4.0")\n\n Now, at runtime, the variable will be automatically replace by its value before the control is constructed.\n\nThe number in the version at the bottom of this dialog is an example of this expansion in action.\n\nThis is very handy for things like replacing the text in a wxStaticText, since it is a much simpler way to make a wxStaticText be a proper size: by creating it the proper size. This is in contrast to the alternative way of having using some static non-variable value in your XRC, having XRC construct it, then your application having code to change the text of it, then your app getting its best size, then setting the statictext's size, then laying out the dialog's sizer again, and other work. + + + + wxGROW|wxALIGN_BOTTOM + + 3 + 0 + 0 + 0 + 2 + 0 + + wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + + + + + diff --git a/contrib/samples/xrc/xrcdemo.cpp b/contrib/samples/xrc/xrcdemo.cpp index ba5e147e43..f7d755352c 100644 --- a/contrib/samples/xrc/xrcdemo.cpp +++ b/contrib/samples/xrc/xrcdemo.cpp @@ -1,24 +1,24 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: xmldemo.cpp -// Purpose: XML resources sample -// Author: Vaclav Slavik +//----------------------------------------------------------------------------- +// Name: xrcdemo.cpp +// Purpose: XML resources sample: Main application file +// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik // RCS-ID: $Id$ -// Copyright: (c) Vaclav Slavik +// Copyright: (c) Robert O'Connor and Vaclav Slavik // Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// +//----------------------------------------------------------------------------- -// ============================================================================ -// declarations -// ============================================================================ +//----------------------------------------------------------------------------- +// GCC implementation +//----------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- #ifdef __GNUG__ - #pragma implementation "xrcdemo.cpp" - #pragma interface "xrcdemo.cpp" + #pragma implementation "xrcdemo.h" #endif +//----------------------------------------------------------------------------- +// Standard wxWindows headers +//----------------------------------------------------------------------------- + // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -26,143 +26,99 @@ #pragma hdrstop #endif -// for all others, include the necessary headers (this file is usually all you +// 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 -#include "wx/image.h" -#include "wx/xrc/xmlres.h" +//----------------------------------------------------------------------------- +// Header of this .cpp file +//----------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -// resources -// ---------------------------------------------------------------------------- -// the application icon -#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) - #include "rc/appicon.xpm" -#endif +#include "xrcdemo.h" -// ---------------------------------------------------------------------------- -// private classes -// ---------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Remaining headers: Needed wx headers, then wx/contrib headers, then application headers +//----------------------------------------------------------------------------- -// Define a new application type, each program should derive a class from wxApp -class MyApp : public wxApp -{ -public: - // override base class virtuals - // ---------------------------- - - // this one is called on application startup and is a good place for the app - // initialization (doing it here and not in the ctor allows to have an error - // return: if OnInit() returns false, the application terminates) - virtual bool OnInit(); -}; - -// Define a new frame type: this is going to be our main frame -class MyFrame : public wxFrame -{ -public: - // ctor(s) - MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); - - // event handlers (these functions should _not_ be virtual) - void OnQuit(wxCommandEvent& event); - void OnAbout(wxCommandEvent& event); - void OnDlg1(wxCommandEvent& event); - void OnDlg2(wxCommandEvent& event); - -private: - // any class wishing to process wxWindows events must use this macro - DECLARE_EVENT_TABLE() -}; - -// ---------------------------------------------------------------------------- -// event tables and other macros for wxWindows -// ---------------------------------------------------------------------------- - -// the event tables connect the wxWindows events with the functions (event -// handlers) which process them. It can be also done at run-time, but for the -// simple menu events like this the static method is much simpler. -BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MENU(XRCID("menu_quit"), MyFrame::OnQuit) - EVT_MENU(XRCID("menu_about"), MyFrame::OnAbout) - EVT_MENU(XRCID("menu_dlg1"), MyFrame::OnDlg1) - EVT_MENU(XRCID("menu_dlg2"), MyFrame::OnDlg2) -END_EVENT_TABLE() +#include "wx/image.h" // wxImage + +//----------------------------------------------------------------------------- + +#include "wx/xrc/xmlres.h" // XRC XML resouces + +//----------------------------------------------------------------------------- + +#include "myframe.h" + +//----------------------------------------------------------------------------- +// wxWindows macro: Declare the application. +//----------------------------------------------------------------------------- // Create a new application object: this macro will allow wxWindows to create // the application object during program execution (it's better than using a // static object for many reasons) and also declares the accessor function -// wxGetApp() which will return the reference of the right type (i.e. MyApp and -// not wxApp) +// wxGetApp() which will return the reference of the right type (i.e. the_app and +// not wxApp). IMPLEMENT_APP(MyApp) -// ============================================================================ -// implementation -// ============================================================================ - -// ---------------------------------------------------------------------------- -// the application class -// ---------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Public methods +//----------------------------------------------------------------------------- // 'Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { - wxImage::AddHandler(new wxGIFHandler); - wxXmlResource::Get()->InitAllHandlers(); - wxXmlResource::Get()->Load("rc/resource.xrc"); - - MyFrame *frame = new MyFrame("XML resources demo", - wxPoint(50, 50), wxSize(450, 340)); + // If there is any of a certain format of image in the xrcs, then first + // load a handler for that image type. This example uses XPMs, but if + // you want PNGs, then add a PNG handler, etc. See wxImage::AddHandler() + // documentation for the types of image handlers available. + wxImage::AddHandler(new wxXPMHandler); + + // Initialize all the XRC handlers. Always required (unless you feel like + // going through and initializing a handler of each control type you will + // be using (ie initialize the spinctrl handler, initialize the textctrl + // handler). However, if you are only using a few control types, it will + // save some space to only initialize the ones you will be using. See + // wxXRC docs for details. + wxXmlResource::Get()->InitAllHandlers(); + + // Load all of the XRC files that will be used. You can put everything + // into one giant XRC file if you wanted, but then they become more + // diffcult to manage, and harder to reuse in later projects. + // The menubar + wxXmlResource::Get()->Load("rc/menu.xrc"); + // The toolbar + wxXmlResource::Get()->Load("rc/toolbar.xrc"); + // Non-derived dialog example + wxXmlResource::Get()->Load("rc/basicdlg.xrc"); + // Derived dialog example + wxXmlResource::Get()->Load("rc/derivdlg.xrc"); + // Controls property example + wxXmlResource::Get()->Load("rc/controls.xrc"); + // Frame example + wxXmlResource::Get()->Load("rc/frame.xrc"); + // Uncentered example + wxXmlResource::Get()->Load("rc/uncenter.xrc"); + // Custom class example + wxXmlResource::Get()->Load("rc/custclas.xrc"); + // wxArtProvider example + wxXmlResource::Get()->Load("rc/artprov.xrc"); + // Platform property example + wxXmlResource::Get()->Load("rc/platform.xrc"); + // Variable expansion example + wxXmlResource::Get()->Load("rc/variable.xrc"); + + // Make an instance of your derived frame. Passing NULL (the default value + // of MyFrame's constructor is NULL) as the frame doesn't have a frame + // since it is the first window. + MyFrame *frame = new MyFrame(); + + // Show the frame. frame->Show(TRUE); + + // Return TRUE to tell program to continue (FALSE would terminate). return TRUE; } -// ---------------------------------------------------------------------------- -// main frame -// ---------------------------------------------------------------------------- - -// frame constructor -MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame((wxFrame *)NULL, -1, title, pos, size) -{ - SetIcon(wxICON(appicon)); - - SetMenuBar(wxXmlResource::Get()->LoadMenuBar("mainmenu")); - SetToolBar(wxXmlResource::Get()->LoadToolBar(this, "toolbar")); -} - - -// event handlers - -void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) -{ - // TRUE is to force the frame to close - Close(TRUE); -} - -void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) -{ - wxString msg; - msg.Printf( _T("This is the about dialog of XML resources demo.\n") - _T("Welcome to %s"), wxVERSION_STRING); - - wxMessageBox(msg, "About XML resources demo", wxOK | wxICON_INFORMATION, this); -} - -void MyFrame::OnDlg1(wxCommandEvent& WXUNUSED(event)) -{ - wxDialog dlg; - wxXmlResource::Get()->LoadDialog(&dlg, this, "dlg1"); - dlg.ShowModal(); -} - - -void MyFrame::OnDlg2(wxCommandEvent& WXUNUSED(event)) -{ - wxDialog dlg; - wxXmlResource::Get()->LoadDialog(&dlg, this, "dlg2"); - dlg.ShowModal(); -} diff --git a/contrib/samples/xrc/xrcdemo.h b/contrib/samples/xrc/xrcdemo.h new file mode 100644 index 0000000000..c201be31b4 --- /dev/null +++ b/contrib/samples/xrc/xrcdemo.h @@ -0,0 +1,54 @@ +//----------------------------------------------------------------------------- +// Name: xmldemo.cpp +// Purpose: XML resources sample: Main application file +// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik +// RCS-ID: $Id$ +// Copyright: (c) Robert O'Connor and Vaclav Slavik +// Licence: wxWindows licence +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Begin single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#ifndef _XRCDEMO_H_ +#define _XRCDEMO_H_ + +//----------------------------------------------------------------------------- +// GCC interface +//----------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma interface "xrcdemo.h" +#endif + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "wx/app.h" // wxApp + +//----------------------------------------------------------------------------- +// Class definition: MyApp +//----------------------------------------------------------------------------- + +// Define a new application type, each program should derive a class from wxApp +class MyApp : public wxApp +{ + +public: + + // Override base class virtuals: + // wxApp::OnInit() is called on application startup and is a good place + // for the app initialization (doing it here and not in the ctor + // allows to have an error return: if OnInit() returns false, the + // application terminates) + virtual bool OnInit(); + +}; + +//----------------------------------------------------------------------------- +// End single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#endif //_XRCDEMO_H_ diff --git a/contrib/src/xrc/xmlres.cpp b/contrib/src/xrc/xmlres.cpp index 33a33edc34..2106d04ff7 100644 --- a/contrib/src/xrc/xmlres.cpp +++ b/contrib/src/xrc/xmlres.cpp @@ -32,6 +32,7 @@ #include "wx/bitmap.h" #include "wx/image.h" #include "wx/fontmap.h" +#include "wx/artprov.h" #include "wx/xrc/xml.h" #include "wx/xrc/xmlres.h" @@ -690,6 +691,7 @@ long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv) } + int wxXmlResourceHandler::GetID() { wxString sid = GetName(); @@ -716,6 +718,68 @@ int wxXmlResourceHandler::GetID() } + +wxArtID wxXmlResourceHandler::GetStockID(const wxString& param) +{ + wxXmlNode *stockIDNode = GetParamNode(param); + if (stockIDNode == NULL) + return wxEmptyString; + + wxXmlNode *oldnode = m_node; + m_node = stockIDNode; + + wxArtID sid = m_node->GetPropVal(wxT("stock_id"), wxT("")); + + m_node = oldnode; + + if (sid.IsEmpty()) return wxEmptyString; +#define stdID(id) else if (sid == wxT(#id)) return id + stdID(wxART_ADD_BOOKMARK); stdID(wxART_DEL_BOOKMARK); + stdID(wxART_HELP_SIDE_PANEL); stdID(wxART_HELP_SETTINGS); + stdID(wxART_HELP_BOOK); stdID(wxART_HELP_FOLDER); + stdID(wxART_HELP_PAGE); stdID(wxART_GO_BACK); + stdID(wxART_GO_FORWARD); stdID(wxART_GO_UP); + stdID(wxART_GO_DOWN); stdID(wxART_GO_TO_PARENT); + stdID(wxART_GO_HOME); stdID(wxART_FILE_OPEN); + stdID(wxART_PRINT); stdID(wxART_HELP); stdID(wxART_TIP); + stdID(wxART_REPORT_VIEW); stdID(wxART_LIST_VIEW); + stdID(wxART_NEW_DIR); stdID(wxART_FOLDER); + stdID(wxART_GO_DIR_UP); stdID(wxART_EXECUTABLE_FILE); + stdID(wxART_NORMAL_FILE); stdID(wxART_TICK_MARK); + stdID(wxART_CROSS_MARK); stdID(wxART_ERROR); + stdID(wxART_QUESTION); stdID(wxART_WARNING); + stdID(wxART_INFORMATION); +#undef stdID + else return sid; +} + + + +wxArtClient wxXmlResourceHandler::GetStockClient(const wxString& param) +{ + wxXmlNode *stockClientNode = GetParamNode(param); + if (stockClientNode == NULL) + return wxEmptyString; + + wxXmlNode *oldnode = m_node; + m_node = stockClientNode; + + wxArtClient sid = m_node->GetPropVal(wxT("stock_client"), wxT("wxART_OTHER")); + + m_node = oldnode; + + if (sid.IsEmpty()) return wxEmptyString; +#define stdID(id) else if (sid == wxT(#id)) return id + stdID(wxART_TOOLBAR); stdID(wxART_MENU); + stdID(wxART_FRAME_ICON); stdID(wxART_CMN_DIALOG); + stdID(wxART_HELP_BROWSER); stdID(wxART_MESSAGE_BOX); + stdID(wxART_OTHER); +#undef stdID + else return sid; +} + + + wxString wxXmlResourceHandler::GetName() { return m_node->GetPropVal(wxT("name"), wxT("-1")); @@ -755,8 +819,17 @@ wxColour wxXmlResourceHandler::GetColour(const wxString& param) wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size) { + wxString stk = param; + if (!GetStockID(stk).IsEmpty()) + { + wxBitmap stockArt = wxArtProvider::GetBitmap(GetStockID(stk), + GetStockClient(stk), size); + if (stockArt != wxNullBitmap) + return stockArt; + } + wxString name = GetParamValue(param); - if (name.IsEmpty()) return wxNullBitmap; + if (name.IsEmpty()) return wxNullBitmap; #if wxUSE_FILESYSTEM wxFSFile *fsfile = GetCurFileSystem().OpenFile(name); if (fsfile == NULL) @@ -769,6 +842,7 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size) #else wxImage img(GetParamValue(wxT("bitmap"))); #endif + if (!img.Ok()) { wxLogError(_("XRC resource: Cannot create bitmap from '%s'."), param.c_str()); @@ -776,6 +850,7 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size) } if (!(size == wxDefaultSize)) img.Rescale(size.x, size.y); return wxBitmap(img); + } diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 95e06f6711..7719fe4afb 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -24,6 +24,7 @@ #include "wx/filesys.h" #include "wx/bitmap.h" #include "wx/icon.h" +#include "wx/artprov.h" #include "wx/xrc/xml.h" @@ -351,6 +352,12 @@ protected: // Returns the XRCID. int GetID(); + // Returns the wxArtID for a wxArtProvider-managed bitmap. + wxArtID GetStockID(const wxString& param); + + // Returns the wxArtClient for a wxArtProvider-managed bitmap. + wxArtClient GetStockClient(const wxString& param); + // Returns the resource name. wxString GetName(); diff --git a/samples/xrc/Makefile.in b/samples/xrc/Makefile.in index 6d7da4cb7c..74b1001946 100644 --- a/samples/xrc/Makefile.in +++ b/samples/xrc/Makefile.in @@ -11,13 +11,35 @@ program_dir = contrib/samples/xrc PROGRAM=xrcdemo -OBJECTS=$(PROGRAM).o +OBJECTS=$(PROGRAM).o \ + myframe.o \ + derivdlg.o \ + custclas.o APPEXTRALIBS=$(top_builddir)/lib/libwxxrc.@WX_TARGET_LIBRARY_TYPE@ APPEXTRADEFS=-I$(top_srcdir)/contrib/include DATADIRS = rc -DATAFILES = rc/resource.xrc rc/fileopen.gif rc/filesave.gif rc/fuzzy.gif \ - rc/quotes.gif rc/scanning.gif rc/update.gif +DATAFILES = rc/artprov.xrc \ + rc/basicdlg.xrc \ + rc/controls.xrc \ + rc/custclas.xrc \ + rc/derivdlg.xrc \ + rc/frame.xrc \ + rc/menu.xrc \ + rc/platform.xrc \ + rc/toolbar.xrc \ + rc/uncenter.xrc \ + rc/variable.xrc \ + rc/artprov.xpm \ + rc/basicdlg.xpm \ + rc/controls.xpm \ + rc/custclas.xpm \ + rc/derivdlg.xpm \ + rc/platform.xpm \ + rc/uncenter.xpm \ + rc/variable.xpm include $(top_builddir)/src/makeprog.env + + diff --git a/samples/xrc/XrcDemoVC.dsp b/samples/xrc/XrcDemoVC.dsp index 68e553b8a7..5bef50036a 100644 --- a/samples/xrc/XrcDemoVC.dsp +++ b/samples/xrc/XrcDemoVC.dsp @@ -148,6 +148,30 @@ LINK32=link.exe # Name "XrcDemoVC - Win32 Release DLL" # Begin Source File +SOURCE=.\custclas.cpp +# End Source File +# Begin Source File + +SOURCE=.\custclas.h +# End Source File +# Begin Source File + +SOURCE=.\derivdlg.cpp +# End Source File +# Begin Source File + +SOURCE=.\derivdlg.h +# End Source File +# Begin Source File + +SOURCE=.\myframe.cpp +# End Source File +# Begin Source File + +SOURCE=.\myframe.h +# End Source File +# Begin Source File + SOURCE=.\xrcdemo.cpp !IF "$(CFG)" == "XrcDemoVC - Win32 Release" diff --git a/samples/xrc/custclas.cpp b/samples/xrc/custclas.cpp new file mode 100644 index 0000000000..020a14e4b5 --- /dev/null +++ b/samples/xrc/custclas.cpp @@ -0,0 +1,162 @@ +//----------------------------------------------------------------------------- +// Name: custclass.cpp +// Purpose: XML resources sample: A custom class to insert into a XRC file +// 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 "custclas.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 "custclas.h" + +//----------------------------------------------------------------------------- +// Internal constants +//----------------------------------------------------------------------------- + +// Popup menu (PU) item control IDs. In this example, they aren't hooked up +// to any functions. Normally you would use these IDs in your event table, so +// that if one of these menu items is clicked, then a certain function is +// called. +enum { + PU_ADD_RECORD = wxID_HIGHEST + 1, + PU_EDIT_RECORD, + PU_DELETE_RECORD +}; + +// Columns of the listctrl (the leftmost one starts at 0, and so on). +// Allows easier code maintenance if want to add/rearrangement of listctrl's +// columns. +enum { + RECORD_COLUMN = 0, + ACTION_COLUMN, + PRIORITY_COLUMN +}; + +//----------------------------------------------------------------------------- +// wxWindows macro: implement dynamic class +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS( MyResizableListCtrl, wxListCtrl ) + +//----------------------------------------------------------------------------- +// Event table: connect the events to the handler functions to process them +//----------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE( MyResizableListCtrl, wxListCtrl ) + // Something to do when right mouse down + EVT_RIGHT_DOWN( MyResizableListCtrl::ContextSensitiveMenu ) + // Something to do when resized + EVT_SIZE( MyResizableListCtrl::OnSize ) +END_EVENT_TABLE() + +//----------------------------------------------------------------------------- +// Public methods +//----------------------------------------------------------------------------- + +// Constructor, including setting the dialog's m_configuration_section member +// to the incoming configuration_section string. +MyResizableListCtrl::MyResizableListCtrl( wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxValidator& validator, + const wxString& name ) + : wxListCtrl( parent, id, pos, size, style, validator, name ) +{ + + // This listctrl needs to insert its columns in the constructor, since + // as soon as the listctrl is built, it is resized and grafted onto an + // "unknown" XRC placeholder. This induces an OnSize() event, calling the + // overrriden OnSize function for this class, which needs to have 3 + // columns to resize (else an assert on WXGTK debug build). + InsertColumn( RECORD_COLUMN, _("Record"), wxLIST_FORMAT_LEFT, 140); + InsertColumn( ACTION_COLUMN, _("Action"), wxLIST_FORMAT_LEFT, 70); + InsertColumn( PRIORITY_COLUMN, _("Priority"), wxLIST_FORMAT_LEFT, 70 ); +} + + +MyResizableListCtrl::~MyResizableListCtrl() +{ +} + + +void MyResizableListCtrl::ContextSensitiveMenu( wxMouseEvent& event ) +{ + // Make an instance of a menu. + wxMenu a_menu; + + a_menu.Append( PU_ADD_RECORD, _( "Add a new record...") ); + a_menu.Append( PU_EDIT_RECORD, _( "Edit selected record..." ) ); + a_menu.Append( PU_DELETE_RECORD, _( "Delete selected record" ) ); + + // If no listctrl rows selected, then disable the menu items that + // require selection + if ( GetSelectedItemCount() == 0 ) { + a_menu.Enable( PU_EDIT_RECORD, FALSE ); + a_menu.Enable( PU_DELETE_RECORD, FALSE ); + } + + // Show the popup menu (wxWindow::PopupMenu ), at the x,y position + // of the click event + PopupMenu( &a_menu, event.GetPosition() ); +} + + +void MyResizableListCtrl::OnSize( wxSizeEvent &event ) +{ + // Call our custom width setting function. + SetColumnWidths(); + // REQURED event.Skip() call to allow this event to propagate + // upwards so others can do what they need to do in response to + // this size event. + event.Skip(); +} + + +void MyResizableListCtrl::SetColumnWidths() +{ + // Get width of entire listctrl + int leftmostColumnWidth = GetSize().x; + + // Subtract width of other columns, scrollbar, and some padding + leftmostColumnWidth -= GetColumnWidth( ACTION_COLUMN ); + leftmostColumnWidth -= GetColumnWidth( PRIORITY_COLUMN ); + leftmostColumnWidth -= wxSystemSettings::GetSystemMetric( wxSYS_VSCROLL_X ); + leftmostColumnWidth -= 5; + + // Set the column width to the new value. + SetColumnWidth( RECORD_COLUMN, leftmostColumnWidth ); + + // This is just a debug message in case you want to watch the + // events scroll by as you resize. + wxLogDebug( "Successfully set column widths" ); +} + + diff --git a/samples/xrc/custclas.h b/samples/xrc/custclas.h new file mode 100644 index 0000000000..bce98c906d --- /dev/null +++ b/samples/xrc/custclas.h @@ -0,0 +1,97 @@ +//----------------------------------------------------------------------------- +// Name: custclas.h +// Purpose: XML resources sample: A custom class to insert into a XRC file +// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik +// RCS-ID: $Id$ +// Copyright: (c) Robert O'Connor and Vaclav Slavik +// Licence: wxWindows licence +//----------------------------------------------------------------------------- + +//---------------------------------------------------------------------------------------- +// Begin single inclusion of this .h file condition +//---------------------------------------------------------------------------------------- + +#ifndef _CUSTCLAS_H_ +#define _CUSTCLAS_H_ + +//---------------------------------------------------------------------------------------- +// GCC interface +//---------------------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma interface "custclas.h" +#endif + +//---------------------------------------------------------------------------------------- +// Headers +//---------------------------------------------------------------------------------------- + +#include "wx/listctrl.h" + +//---------------------------------------------------------------------------------------- +// Class definition: MyResizableListCtrl +//---------------------------------------------------------------------------------------- + +//! A custom listctrl that resizes itself and pops up a context-sensitive menu. +class MyResizableListCtrl : public wxListCtrl +{ + // Very helpful wxWindows macro required for wxWindows-RTTI tracing: By using this + // you will see "Leaked one object of type myResizeableListCtrl" in the debug log, + // along with which line you if was created, but you forget to free the memory. + // NOTE: Using this REQUIRES a default constructor: that means either: giving a + // default value for all parameters in your constructor, or else having a dummy + // MyResizableListCtrl(){} constructor in addition to your regular one. + DECLARE_DYNAMIC_CLASS( MyResizableListCtrl ) + +public: + + // Constructor. + /* + These parameters are the same as a wxWindows constructor. + \param parent The parent window. + \param id The id of the progress_listbox. Will usually be -1 unless multiple + of them on the same dialog. + \param pos The pixel position of the listctrl on its parent window + \param size The pixel size of the listctrl + \param style Style of the listbox. See wxWindows wxListBox docs for details. + \param validator Window validator. See wxWindows docs for details. + \param name Windows name (rarely used). + \param exclusion_column_caption The label of header of listctrl's exclusion + column. + */ + MyResizableListCtrl( wxWindow *parent = NULL, + wxWindowID id = -1, + const wxPoint &pos = wxDefaultPosition, + const wxSize &size = wxDefaultSize, + long style = wxLC_REPORT, + const wxValidator& validator = wxDefaultValidator, + const wxString &name = wxT("myResizableListCtrl") + ); + + // Destuctor. + ~MyResizableListCtrl(); + +protected: + + // A custom function for a context sensitive menu. + void ContextSensitiveMenu( wxMouseEvent& event ); + + // This is a wxWindows function that we are going to override with our own behaviour. + void OnSize( wxSizeEvent &event ); + + // A custom function. What is called in the constructor, and in an OnSize() + void SetColumnWidths(); + +private: + + // wxWindows macro, required to be able to use Event tables in the .cpp file. + DECLARE_EVENT_TABLE() + +}; + +//---------------------------------------------------------------------------------------- +// End single inclusion of this .h file condition +//---------------------------------------------------------------------------------------- + +#endif //_CUSTCLAS_H_ + diff --git a/samples/xrc/derivdlg.cpp b/samples/xrc/derivdlg.cpp new file mode 100644 index 0000000000..a9a719c49d --- /dev/null +++ b/samples/xrc/derivdlg.cpp @@ -0,0 +1,123 @@ +//----------------------------------------------------------------------------- +// 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, "derived_dialog"); +} + +// 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. +} diff --git a/samples/xrc/derivdlg.h b/samples/xrc/derivdlg.h new file mode 100644 index 0000000000..ca580eed79 --- /dev/null +++ b/samples/xrc/derivdlg.h @@ -0,0 +1,71 @@ +//----------------------------------------------------------------------------- +// Name: xmldemo.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 +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Begin single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#ifndef _DERIVDLG_H_ +#define _DERIVDLG_H_ + +//----------------------------------------------------------------------------- +// GCC interface +//----------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma interface "derivdlg.h" +#endif + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "wx/dialog.h" + +//----------------------------------------------------------------------------- +// Class definition: PreferencesDialog +//----------------------------------------------------------------------------- + +// A derived dialog. +class PreferencesDialog : public wxDialog +{ + +public: + + // Constructor. + /* + \param parent The parent window. Simple constructor. + */ + PreferencesDialog( wxWindow* parent ); + + // Destructor. + ~PreferencesDialog(); + +private: + + // Stuff to do when "My Button" gets clicked + void OnMyButtonClicked( wxCommandEvent &event ); + + // Stuff to do when a "My Checkbox" gets updated + // (drawn, or it changes its value) + void OuUpdateUIMyCheckbox( wxUpdateUIEvent &event ); + + // Override base class functions of a wxDialog. + void OnOK( wxCommandEvent &event ); + + // Any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + +}; + +//----------------------------------------------------------------------------- +// End single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#endif //_DERIVDLG_H_ diff --git a/samples/xrc/makefile.b32 b/samples/xrc/makefile.b32 index 717e97799b..08cbbee374 100644 --- a/samples/xrc/makefile.b32 +++ b/samples/xrc/makefile.b32 @@ -12,7 +12,11 @@ WXDIR = $(WXWIN) TARGET=xrcdemo EXTRALIBS=$(WXDIR)\lib\wxxrc.lib -OBJECTS = $(TARGET).obj +OBJECTS = $(TARGET).obj \ + myframe.obj \ + derivdlg.obj \ + custclas.obj !include $(WXDIR)\src\makeprog.b32 + diff --git a/samples/xrc/makefile.g95 b/samples/xrc/makefile.g95 index c78a91f737..6d649c1773 100644 --- a/samples/xrc/makefile.g95 +++ b/samples/xrc/makefile.g95 @@ -6,9 +6,13 @@ WXDIR = ../../.. TARGET = xrcdemo -OBJECTS = $(TARGET).o +OBJECTS = $(TARGET).o \ + myframe.o \ + derivdlg.o \ + custclas.o EXTRAINC = -I$(WXDIR)/contrib/include EXTRALIBS = -lwxxrc include $(WXDIR)/src/makeprog.g95 + diff --git a/samples/xrc/makefile.vc b/samples/xrc/makefile.vc index e0130b2180..42fea985a3 100644 --- a/samples/xrc/makefile.vc +++ b/samples/xrc/makefile.vc @@ -6,9 +6,11 @@ WXDIR = $(WXWIN) PROGRAM = xrcdemo -OBJECTS = $(PROGRAM).obj +OBJECTS = $(PROGRAM).obj myframe.obj derivdlg.obj custclas.obj + EXTRALIBS = $(WXDIR)\lib\wxxrc$(LIBEXT).lib EXTRAINC = -I$(WXDIR)\contrib\include !include $(WXDIR)\src\makeprog.vc + diff --git a/samples/xrc/myframe.cpp b/samples/xrc/myframe.cpp new file mode 100644 index 0000000000..2d03b22e44 --- /dev/null +++ b/samples/xrc/myframe.cpp @@ -0,0 +1,271 @@ +//----------------------------------------------------------------------------- +// Name: myframe.cpp +// Purpose: XML resources sample: A derived frame, called MyFrame +// 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 "myframe.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 "myframe.h" + +//----------------------------------------------------------------------------- +// Remaining headers: Needed wx headers, then wx/contrib headers, then application headers +//----------------------------------------------------------------------------- + +// Since setting an icon +#include "wx/image.h" + +//----------------------------------------------------------------------------- + +#include "wx/xrc/xmlres.h" // XRC XML resouces + +//----------------------------------------------------------------------------- + +// Our derived dialog for the derived dialog example. +#include "derivdlg.h" +// Our custom class, for the custom class example. +#include "custclas.h" +// For functions to manipulate our wxTreeCtrl and wxListCtrl +#include "wx/treectrl.h" +#include "wx/listctrl.h" + +//----------------------------------------------------------------------------- +// Regular resources (the non-XRC kind). +//----------------------------------------------------------------------------- + +// The application icon +// All non-MSW platforms use an xpm. MSW uses an .ico file +#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) + #include "rc/appicon.xpm" +#endif + +//----------------------------------------------------------------------------- +// Event table: connect the events to the handler functions to process them +//----------------------------------------------------------------------------- + +// The event tables connect the wxWindows events with the functions (event +// handlers) which process them. It can be also done at run-time, but for the +// simple menu events like this the static method is much simpler. +// The reason why the menuitems and tools are given the same name in the +// XRC file, is that both a tool (a toolbar item) and a menuitem are designed +// to fire the same kind of event (an EVT_MENU) and thus I give them the same +// ID name to help new users emphasize this point which is often overlooked +// when starting out with wxWindows. +BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(XRCID("exit_tool_or_menuitem"), MyFrame::OnExitToolOrMenuCommand) + EVT_MENU(XRCID("non_derived_dialog_tool_or_menuitem"), MyFrame::OnNonDerivedDialogToolOrMenuCommand) + EVT_MENU(XRCID("derived_tool_or_menuitem"), MyFrame::OnDerivedDialogToolOrMenuCommand) + EVT_MENU(XRCID("controls_tool_or_menuitem"), MyFrame::OnControlsToolOrMenuCommand) + EVT_MENU(XRCID("uncentered_tool_or_menuitem"), MyFrame::OnUncenteredToolOrMenuCommand) + EVT_MENU(XRCID("custom_class_tool_or_menuitem"), MyFrame::OnCustomClassToolOrMenuCommand) + EVT_MENU(XRCID("platform_property_tool_or_menuitem"), MyFrame::OnPlatformPropertyToolOrMenuCommand) + EVT_MENU(XRCID("art_provider_tool_or_menuitem"), MyFrame::OnArtProviderToolOrMenuCommand) + EVT_MENU(XRCID("variable_expansion_tool_or_menuitem"), MyFrame::OnVariableExpansionToolOrMenuCommand) + EVT_MENU(XRCID("about_tool_or_menuitem"), MyFrame::OnAboutToolOrMenuCommand) +END_EVENT_TABLE() + +//----------------------------------------------------------------------------- +// Public methods +//----------------------------------------------------------------------------- + +// Constructor +MyFrame::MyFrame(wxWindow* parent) +{ + // Load up this frame from XRC. [Note, instead of making a class's + // constructor take a wxWindow* parent with a default value of NULL, + // we could have just had designed MyFrame class with an empty + // constructor and then written here: + // wxXmlResource::Get()->LoadFrame(this, (wxWindow* )NULL, "main_frame"); + // since this frame will always be the top window, and thus parentless. + // However, the current approach has source code that can be recycled + // for other frames that aren't the top level window.] + wxXmlResource::Get()->LoadFrame(this, parent, "main_frame"); + + // Set the icon for the frame. + SetIcon(wxICON(appicon)); + + // Load the menubar from XRC and set this frame's menubar to it. + SetMenuBar(wxXmlResource::Get()->LoadMenuBar("main_menu")); + // Load the toolbar from XRC and set this frame's toolbar to it. + // NOTE: For toolbars you currently should do it exactly like this. + // With toolbars, you currently can't create one, and set it later. It + // needs to be all in one step. + SetToolBar(wxXmlResource::Get()->LoadToolBar(this, "main_toolbar")); + + // Give the frame a optional statusbar. The '1' just means one field. + // A gripsizer will automatically get put on into the corner, if that + // is the normal OS behaviour for frames on that platform. Helptext + // for menu items and toolbar tools will automatically get displayed + // here. + CreateStatusBar( 1 ); +} + +//----------------------------------------------------------------------------- +// Private methods +//----------------------------------------------------------------------------- + +void MyFrame::OnExitToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + // TRUE is to force the frame to close. + Close(TRUE); +} + + +void MyFrame::OnNonDerivedDialogToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + // "non_derived_dialog" is the name of the wxDialog XRC node that should + // be loaded. + wxXmlResource::Get()->LoadDialog(&dlg, this, "non_derived_dialog"); + dlg.ShowModal(); + +} + + +void MyFrame::OnDerivedDialogToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + // Make an instance of our derived dialog, passing it "this" window + // (the main frame) as the parent of the dialog. This allows the dialog + // to be destructed automatically when the parent is destroyed. + PreferencesDialog preferencesDialog(this); + // Show the instance of the dialog, modally. + preferencesDialog.ShowModal(); +} + + +void MyFrame::OnControlsToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "controls_dialog"); + +#if wxUSE_LISTCTRL + // There is no data in the listctrl. This will add some columns + // and some data. You don't need use any pointers + // at all to manipulate the controls, just simply use the XRCCTL(...) macros. + // "controls_treectrl" is the name of this control in the XRC. + // (1) Insert a column, with the column header of "Name" + // (The '_' function around "Name" marks this string as one to translate). + XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertColumn( 0, + _("Name"), + wxLIST_FORMAT_LEFT, + ( 200 ) + ); + // (2) Insert some items into the listctrl + XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(0,wxT("Todd Hope")); + XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(1,wxT("Kim Wynd")); + XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(2,wxT("Leon Li")); +#endif + +#if wxUSE_TREECTRL + // There is no data in the tree ctrl. These lines will add some. + // (1) Instead of having to write out + // XRCCTRL(dlg, "controls_treectrl", wxTreeCtrl)->SomeFunction() + // each time (which is also OK), this example code will shown how + // to make a pointer to the XRC control, so we can use + // treectrl->SomeFunction() as a short cut. This is useful if you + // will be referring to this control often in the code. + wxTreeCtrl* treectrl = XRCCTRL(dlg, "controls_treectrl", wxTreeCtrl); + // (2) Add a root node + treectrl->AddRoot(_("Godfather")); + // (3)Append some items to the root node. + treectrl->AppendItem(treectrl->GetRootItem(), _("Evil henchman 1")); + treectrl->AppendItem(treectrl->GetRootItem(), _("Evil henchman 2")); + treectrl->AppendItem(treectrl->GetRootItem(), _("Evil accountant")); +#endif + + // All done. Show the dialog. + dlg.ShowModal(); +} + + +void MyFrame::OnUncenteredToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "uncentered_dialog"); + dlg.ShowModal(); +} + + +void MyFrame::OnCustomClassToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "custom_class_dialog"); + + // Make an instance of our new custom class. + MyResizableListCtrl* a_myResizableListCtrl = new MyResizableListCtrl(&dlg, + -1, + wxDefaultPosition, + wxDefaultSize, + wxLC_REPORT, + wxDefaultValidator); + + // "custom_control_placeholder" is the name of the "unknown" tag in the + // custctrl.xrc XRC file. + wxXmlResource::Get()->AttachUnknownControl("custom_control_placeholder", + a_myResizableListCtrl); + dlg.ShowModal(); +} + + +void MyFrame::OnPlatformPropertyToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "platform_property_dialog"); + dlg.ShowModal(); +} + + +void MyFrame::OnArtProviderToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "art_provider_dialog"); + dlg.ShowModal(); +} + + +void MyFrame::OnVariableExpansionToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxDialog dlg; + wxXmlResource::Get()->LoadDialog(&dlg, this, "variable_expansion_dialog"); + dlg.ShowModal(); +} + + +void MyFrame::OnAboutToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) +{ + wxString msg; + msg.Printf( _T("This is the about dialog of XML resources demo.\n") + _T("Welcome to %s"), wxVERSION_STRING); + + wxMessageBox(msg, "About XML resources demo", wxOK | wxICON_INFORMATION, this); +} diff --git a/samples/xrc/myframe.h b/samples/xrc/myframe.h new file mode 100644 index 0000000000..c2246335b5 --- /dev/null +++ b/samples/xrc/myframe.h @@ -0,0 +1,67 @@ +//----------------------------------------------------------------------------- +// Name: myframe.h +// Purpose: XML resources sample: A derived frame, called MyFrame +// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik +// RCS-ID: $Id$ +// Copyright: (c) Robert O'Connor and Vaclav Slavik +// Licence: wxWindows licence +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Begin single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#ifndef _MYFRAME_H_ +#define _MYFRAME_H_ + +//----------------------------------------------------------------------------- +// GCC interface +//----------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma interface "myframe.h" +#endif + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "wx/frame.h" + +//----------------------------------------------------------------------------- +// Class definition: MyFrame +//----------------------------------------------------------------------------- + +// Define a new frame type: this is going to be our main frame +class MyFrame : public wxFrame +{ + +public: + + // Constructor. + MyFrame( wxWindow* parent=(wxWindow *)NULL); + +private: + + // Event handlers (these functions should _not_ be virtual) + void OnExitToolOrMenuCommand(wxCommandEvent& event); + void OnAboutToolOrMenuCommand(wxCommandEvent& event); + void OnNonDerivedDialogToolOrMenuCommand(wxCommandEvent& event); + void OnDerivedDialogToolOrMenuCommand(wxCommandEvent& event); + void OnControlsToolOrMenuCommand(wxCommandEvent& event); + void OnUncenteredToolOrMenuCommand(wxCommandEvent& event); + void OnCustomClassToolOrMenuCommand(wxCommandEvent& event); + void OnPlatformPropertyToolOrMenuCommand(wxCommandEvent& event); + void OnArtProviderToolOrMenuCommand(wxCommandEvent& event); + void OnVariableExpansionToolOrMenuCommand(wxCommandEvent& event); + + // Any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() + +}; + +//----------------------------------------------------------------------------- +// End single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#endif // _MYFRAME_H_ diff --git a/samples/xrc/rc/appicon.ico b/samples/xrc/rc/appicon.ico index 6082b2fd0ad8699499e1fd873f9a0d49994d312c..f3ef7918d273b912ce9d18f570cec891290ad3c7 100644 GIT binary patch literal 1078 zcmcgqF>ZuF3^b=mX?X%wbkEoVDP7)j9j&{i%a?cn65mKkmj-DwW8({}i%zE~%7E=1 zukH03L>f6s+qOcS8<7{-u5(3Rk;$|xj}C{5;1yLj&{)beO|aZ3 z_DU&SLGaK;z5{N<=+Nwb+GQ&R7J8vw3YG^R`<9?N^83C|DQSiUG!F*d>yO{(dME7W zH^Mn}kOYZ2DP|b>t2srzM{V45w{d@;!Z2ulj|tFzKE^S60NUd>=W}o@2)J#3TUP6~ z%+BYs;!Bhj0o+H}&ddB0M_Lt+w7MPws`Gd-aqWkl0@r?xnezVc@_K-`^RwTID)Ex> epMk$#hUd#2ZizSb>f=Ub(IcYQqwl}gJo^hm2;JWR literal 2238 zcmcgtO=uit7=C7E{}XrTXLlzthYeVk-YQy(vel+(D1sr~L!hPX$sBUgnl1zbIiv}5 z@Zd$8&>lR5HU$xdVi$LBlQa_*TJTchO`-?|Q)EG86C5%=-#4?_4G7+Rmv`p--sgSZ zzwg^!K;dU}6jHuO0Y$D(Q%9*|R0T8&iG{EJXH1PDw&K83Jve;F#$)gvdx%}9s@!vZ z_O-L{k9_!#ebm16@zu{hF%PxtHNGdv_pxzrgWL&niP3k0abl_u^{4`@pM%rsKy_U- zYYxtPDo_urXx=h#entUqa=#2*n*`q22ksmKHuvwfpJS~R;OnUXZ*B#+Q)|NZDyY`$ zSj26{pJjXn`3^Ae0;)X?Jle)=rw)bt&)K~?M?2%Gj3=fc8DK{_bVPcjXK;_8fHHu z@C~Y9!>rG#Zo=Q+MVavx5x;c=ZJ0GMKbRkP$5R}1TI5}yD_(l zYSiDf^BdagHp)C8k$((4Kb)h6`OtEJVV+;K{cv{$rl>2Dxjn!XvBGiS=?B2h5Vw*4 z#by%^Di!wgEBj&J;Q29Al}{np8Xg|3Zlm)f`+ZAT%G9CbelK0-mg&24Njb$O3y5r! z)fZ?lj-$*27w4yb-{Kcy7T~2#=pS$Y_N?6c6c6jhx6eDxeAY#GCI}> z+=nZiRh#9tP}Qe^wJm%%Bk`Ag*6f`5c}v5tACgJso44S81U@wyP_y;(nKU}$*; z2i2Q!7neEPP5Ph0JVtn(R^X^@_-LW*OhHk%P$K^Z`5nP$XH$&dW_(s8`?>$SjWbss zVO$Rf`t%tv!V6k`@-pjO!9{XzP&;`Z?>taao7{8W`S-bB#kx8xzY}!%Uqy?unWp)# zc?|{e2r!IP^n2CkX&45CM!==EJ64!EOCc;^>xS=fr=M zlr-rX=tVjRPLY8%EoX_LNQr4?CNmHhbdfX1DP`hjE?0~)NPd2hW`PUX&IpHy4$)pF zFU+GPg=tgg?IJB77#U+IE8B z)%?Iqg5FCH9xg2`FsW%~Tsp_KUV7OE`%&%QMEk0bx->bE~ AumAu6 diff --git a/samples/xrc/rc/appicon.xpm b/samples/xrc/rc/appicon.xpm index 948961fe5c..dd66f6e8c4 100644 --- a/samples/xrc/rc/appicon.xpm +++ b/samples/xrc/rc/appicon.xpm @@ -1,61 +1,52 @@ -/* XPM */ -static char* appicon_xpm[]={ -"32 32 26 1", -"s c #000000", -"u c #ff8000", -"m c #ffc0ff", -"q c #400000", -". c None", -"t c #004040", -"d c #303030", -"n c #ffdca8", -"e c #c0c0c0", -"x c #808000", -"o c #c00000", -"c c #585858", -"b c #a0a0a4", -"f c #c000c0", -"# c #000000", -"i c #808080", -"p c #ffa858", -"v c #ffff00", -"k c #800000", -"w c #c0c000", -"r c #004000", -"h c #404000", -"j c #ffc0c0", -"a c #ffffff", -"l c #c05800", -"g c #ff0000", -".....#####...........##.........", -"...##abbccd........##c#.........", -"###aaaebfgh########abi#.........", -"#cbaaaejggkiibeeaaaeeic#........", -"#ieaaaefggldggfjmnaaeei#........", -"#ibeaajggggcggggfmaaabi#b.......", -"#iieaajggggolgggggmaaeec#.......", -"#cieaajgggggdgggggpmaeec#.......", -"#cieaajgggggqgggggggaabi#.......", -"#dieaajpgggcc##cggggaaebc###....", -"#ribaamecccccs##cgggaebccth##...", -"#dieaa#qtdcch###tcs#iichd####...", -"##cbea##dccccs##qhhccccct#####..", -"##iiea##rhccch##tsdtcccdh#####..", -"##cbea###tccookk#hrdhccccs####..", -"##ciea###koogookkddtcccch###q#..", -"##tiea##qoggggokkqhqccccckokkk#.", -"##hbeb#qkoogggookkqkoklkoookkk#.", -"###icb#kkooggggokkdkogggggookk#.", -"###d..#kkoogggouukqkooggggookk#.", -"##....#kkkoguvvvwuhkogggggooko#.", -"##....##kolwvvvvvulcllggggulll#.", -"##....##kuuvvvvvuvudwuuuuuvuuu#.", -"......##uuuuvvvvvuuqivvvvvvuuu#.", -"......##uuuvvwwiqcllhuvvvvvuuu#.", -"......##uuuwl##xuphdivvvvvvvul#.", -"......##uuu##e.#vltcuvuvvvvux#..", -"......##ux#e....###uuww######...", -"......##i#......bbb####.........", -"......###.......................", -"......##........................", -"......##........................"}; +/* XPM */ +static char * appicon_xpm[] = { +"32 32 17 1", +" c None", +". c #000000", +"+ c #800000", +"@ c #008000", +"# c #808000", +"$ c #000080", +"% c #800080", +"& c #008080", +"* c #C0C0C0", +"= c #808080", +"- c #FF0000", +"; c #00FF00", +"> c #FFFF00", +", c #0000FF", +"' c #FF00FF", +") c #00FFFF", +"! c #FFFFFF", +" ", +"===============================.", +"=*****************************=.", +"=*$$$$$$$$$$$$$$$$$$$$$$$$$$$$=.", +"=*$$$$$$$$$$$$$$$$$$$**.**.**.=.", +"=*$$$$$$$$$$$$$$$$$$$**.**.**.=.", +"=*$$$$$$$$$$$$$$$$$$$.........=.", +"=*****************************=.", +"=*=============================.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!,!!!!!!!!!!!,!!!!!!*=.", +"=*=!!!!!!,,!!!!!!!!!!!,,!!!!!*=.", +"=*=!!!!!,,!!!!!!!!!!!!!,,!!!!*=.", +"=*=!!!!,,!!...........!!,,!!!*=.", +"=*=!!!,,!!!.$$$$$$!!!.!!!,,!!*=.", +"=*=!!,,!!!!.$$$$$$!!!.!!!!,,!*=.", +"=*=!!,,!!!!.$$$$$$!!!.!!!!,,!*=.", +"=*=!!!,,!!!.$$$$$$!!!.!!!,,!!*=.", +"=*=!!!!,,!!...........!!,,!!!*=.", +"=*=!!!!!,,!!!!!!!!!!!!!,,!!!!*=.", +"=*=!!!!!!,,!!!!!!!!!!!,,!!!!!*=.", +"=*=!!!!!!!,!!!!!!!!!!!,!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*=!!!!!!!!!!!!!!!!!!!!!!!!!!*=.", +"=*****************************=.", +"===============================.", +"................................", +" ", +" "}; diff --git a/samples/xrc/rc/artprov.xpm b/samples/xrc/rc/artprov.xpm new file mode 100644 index 0000000000..63ba702fe7 --- /dev/null +++ b/samples/xrc/rc/artprov.xpm @@ -0,0 +1,23 @@ +/* XPM */ +static char * artprov_xpm[] = { +"16 16 4 1", +" c None", +". c #000000", +"+ c #0E2CEF", +"@ c #FFFFFF", +" . ", +" . . ", +" . . ", +"++++++++++++++++", +"+@@@@@@@@@@@@@@+", +"+@@@@@@++@@@@@@+", +"+@@@@@@@@@@@@@@+", +"+@@@@@+++@@@@@@+", +"+@@@@@@++@@@@@@+", +"+@@@@@@++@@@@@@+", +"+@@@@@@++@@@@@@+", +"+@@@@@++++@@@@@+", +"+@@@@@@@@@@@@@@+", +"++++++++++++++++", +" ", +" "}; diff --git a/samples/xrc/rc/artprov.xrc b/samples/xrc/rc/artprov.xrc new file mode 100644 index 0000000000..629c86bcd3 --- /dev/null +++ b/samples/xrc/rc/artprov.xrc @@ -0,0 +1,67 @@ + + + + + + wxArtProvider Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + You can specify wxArtProvider icons in your XRC resources. These icons will be retrieved from the active wxArtProvider (see wxArtProvider in docs and /samples/artprov for more information on wxArtProvider).\n\nThe most common usage for this is that you want a dialog, toolbar or menu item to have the correct platform-specific icon in your interface, such as a custom "Don't show this again" checkbox message dialog that has the appropriate icon, as shown below.\n\nYou can also use it to manage your own custom bitmaps though, too--instead of having to write multiple versions of an XRC file that only differ in their bitmaps, you can instead just write one XRC file with the bitmap to be retrieved from the wxArtProvider at runtime, having your custom wxArtProvider use some code to serve out the desired bitmap based on such things as a wxConfig n entry of a desired icon set, what OS the application is running on, what size or resolution the display is, and so on.\n\nNote that your application's custom bitmaps are the only thing that will differ between OS's in order to ensure proper Look And Feel, as everything else: windows decoration, colors, fonts, widgets, etc already match perfectly since wxWindows runs natively.\n\nTo use a wxArtProvider bitmap instead of usual bitmap, in your XRC, instead of <bitmap>somefile.png</bitmap>, use <bitmap stock__id="SOME__ART__ID" client="SOME__CLIENT__ID">somefile.png</bitmap>. The stock__id parameter is required for a bitmap to be read from wxArtProvider, stock__client is optional. The image filename is also optional, and is just used as a fallback in case the wxArtProvider couldn't return a bitmap for that particular stock__id (and particular stock__client if your wxArtProvider is set up to also filter stock__client). + + + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 2 + 0 + 0 + 0 + 1 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + derivdlg.xpm + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + diff --git a/samples/xrc/rc/basicdlg.xpm b/samples/xrc/rc/basicdlg.xpm new file mode 100644 index 0000000000..fd6d714496 --- /dev/null +++ b/samples/xrc/rc/basicdlg.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * basicdlg_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #808080", +"@ c #0000FF", +"# c #FFFFFF", +" ", +"................", +".++++++++++++++.", +".+@@@@@@@@@@@@+.", +".++++++++++++++.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".+############+.", +".++++++++++++++.", +"................", +" "}; diff --git a/samples/xrc/rc/basicdlg.xrc b/samples/xrc/rc/basicdlg.xrc new file mode 100644 index 0000000000..9cea321aa7 --- /dev/null +++ b/samples/xrc/rc/basicdlg.xrc @@ -0,0 +1,48 @@ + + + + + + Non-Derived Dialog Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + This is the basic non-derived XRC dialog. It is just an instance of wxDialog, not a instance of a class derived from wxDialog that was given some added functionality.\n\nYou can put whatever controls you want on these non-derived dialogs, but the dialog won't interact with the controls, nor do anything in response to any of their events. It only has the built-in functionality of a wxDialog, and that is it. A non-derived dialog can automatically close itself when you hit either the OK or Cancel button (returning a return code of what button you pressed), and not much else.\n\nThese are useful for an About dialog, or a message dialog popup, but that's about it. For the rest you will almost certainly use a derived dialog (see next example). + + + + wxALIGN_CENTRE|wxALL + 5 + + wxHORIZONTAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + diff --git a/samples/xrc/rc/controls.xpm b/samples/xrc/rc/controls.xpm new file mode 100644 index 0000000000..acb1c77516 --- /dev/null +++ b/samples/xrc/rc/controls.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char * controls_xpm[] = { +"16 16 6 1", +" c None", +". c #000000", +"+ c #808080", +"@ c #0000FF", +"# c #FFFFFF", +"$ c #0E2CEF", +" ", +" ", +" ", +" ", +" ", +"................", +".++++++++++++++.", +".+@@@@@@@@####+.", +".+$$$$$$$$####+.", +".+$$$$$$$$####+.", +".++++++++++++++.", +"................", +" ", +" ", +" ", +" "}; diff --git a/samples/xrc/rc/controls.xrc b/samples/xrc/rc/controls.xrc new file mode 100644 index 0000000000..119716ad1b --- /dev/null +++ b/samples/xrc/rc/controls.xrc @@ -0,0 +1,801 @@ + + + + + + Controls Example + + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 1 + 550,200 + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + controls.xpm + + + + + + + + + + 2 + 0 + 0 + 0 + 0,1 + 0,1 + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + -1,-1 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + 1 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 180,180 + + Download library + Compile samples + Skim docs + Finish project + Wash car + + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 180,-1 + + See + Hear + Feel + Smell + Taste + The Sixth Sense! + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 200,-1 + + 4 + + vim + emacs + notepad.exe + bbedit + nedit + + + + + + + + + + + 2 + 0 + 0 + 0 + 0,1 + 0,1 + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + 100,-1 + 100 + 50 + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + 40,60 + 100 + 40 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 200,200 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 450,250 + + <h2>XRC Resources HTML</h2> + <p><font color="#0000FF">XRC=Blue skies ahead.</font> + <p>Italics useful for quoted or emphasized text:<i>"Some see things as they are and say why. + I dream things that never were, and say why not"</i> + <p><pre>Fixed width for code snippets.</pre> + <p>Horizontal rules to organize sections: <hr> + <p>A wxImage is worth a thousand words and can be also used. + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTER|wxALL + 5 + + 250,160 + + + Milk + Pizza + Bread + Orange juice + Paper towels + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTER|wxALL + 5 + + 220,160 + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 200,160 + #0000FF + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + 1 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + + 1 + 0 + + Power 108 + WMMS 100.7 + Energy 98.3 + CHUM FM + 92FM + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + -1,160 + 50 + 100 + 30 + + + + + + + + + + + 2 + 0 + 0 + 0 + 0,1 + 0,1 + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 100,-1 + + 100 + 0 + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 100,-1 + + 100 + 0 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + 100 + 0 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 100,-1 + 100 + 0 + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + appicon.xpm + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + wxVERTICAL + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0,1 + + wxALIGN_CENTRE|wxALL + 5 + + -1,100 + + + + + wxALIGN_CENTRE|wxALL + 5 + + 150,-1 + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + 2 + 0 + 0 + 0 + 0,1 + 0,1,2 + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 180,-1 + A.A. Milne + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 180,-1 + + TooManySecrets + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 180,90 + + "So many pretty widgets" said Pooh, said he. "So many pretty widgets", said Pooh. + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxALIGN_CENTRE|wxALL + 5 + + 280,180 + + + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0,1,2,3,4,5,6 + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + diff --git a/samples/xrc/rc/custclas.xpm b/samples/xrc/rc/custclas.xpm new file mode 100644 index 0000000000..597bfb3bf3 --- /dev/null +++ b/samples/xrc/rc/custclas.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static char * custclas_xpm[] = { +"16 16 7 1", +" c None", +". c #EBF70E", +"+ c #000000", +"@ c #808080", +"# c #0000FF", +"$ c #FFFFFF", +"% c #0E2CEF", +" ", +" . ", +" . ", +" . . . ", +" ... ", +"...+....++++++++", +"+@...@@@@@@@@@@+", +"+.#.#.####$$$$@+", +"+@%.%%%%%%$$$$@+", +"+@%.%%%%%%$$$$@+", +"+@@@@@@@@@@@@@@+", +"++++++++++++++++", +" ", +" ", +" ", +" "}; diff --git a/samples/xrc/rc/custclas.xrc b/samples/xrc/rc/custclas.xrc new file mode 100644 index 0000000000..1d7b21134e --- /dev/null +++ b/samples/xrc/rc/custclas.xrc @@ -0,0 +1,42 @@ + + + + + + Custom Class Example + 1 + + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + You can embed your own custom classes into an XRC file. This is referred to as attaching an unknown control.\n\nThere are 3 main cases when you would want to do this:\n\n(A) Most commonly: you have derived a class from one of the main wxWindows controls, so that it can manage its own state and look after its own events, because it is better management to have a portable class with all the code for that control in there with the class, instead of being having many event handlers for that control scattered up in its parent dialog (which is allowed, but gets messy if a control has alot of methods). For example, if you require a wxListCtrl that popups a menu when right-clicked on an item, and you want the wxListCtrl to resize its columns in response to an OnSize(), and a few more methods, it makes better sourcecode logic to package all these methods into by a standalone derived wxListCtrl class, instead of having the parent dialog manage all these events and other functions. This is what the example below shows: it does a custom behaviour of resizing its first column to appropriately fill up the width of the control on a resize event, and it pops up a context-menu in response to a left click (and shades out popup menu item appropriately if there is no item currenty selected in the listctrl).\n\n(B)You have an utterly new widget that has no equivalent in the wxWindows class heirarchy, so you thus need to embed your class to get the needed functionality.\n\n(C) You are using one of the rarely used wxWindows controls that doesn't have an XRC handler in the XRC library. However, all of the major controls: wxButton, wxTextCtrl, etc have an XRC handler, so this is pretty rare, and you could always write your own XRC handler for that control if you wanted. You can choose the "Controls example" from the XRC demo menu to see all the controls that have an XRC handler.\n\nThe typical formula for attaching an unknown control is:\n\n(1) If you are deriving your own custom class to be embedded into the XRC, describe that class with its own .cpp and .h file. In this example it is custclass.cpp and custclass.h\n\n(2)Specify an "unknown" tag in the XRC file that you want to embed it into (see the unknown tag in custclass.xrc). This will be the placeholder of the new class.\n\n(3) Load the XRC dialog as usual, but before you show the dialog to the user, construct an instance of your custom control, and then use wxXmlResource::Get()->AttachUnknownControl() to put the custom class into its "unknown" placeholder in the XRC file.\n\nThe result is what you see below, a custom class control that fits in seemlessly with the whole dialog, the same as if it was read from XRC directly. Try out resizing this dialog, and watch the listctrl column resize, and right-click to call up its popup menu. By the way, if you look at the source of this XRC dialog, you will that this dialog node has a set of style flags that includes wxRESIZE__BORDER--that is why this dialog is resizable, whereas most of the rest of the dialogs in the XRC sample that don't include this tag, are not resizable. + + + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 100,100 + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + diff --git a/samples/xrc/rc/derivdlg.xpm b/samples/xrc/rc/derivdlg.xpm new file mode 100644 index 0000000000..aa1aeadb79 --- /dev/null +++ b/samples/xrc/rc/derivdlg.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char * derivdlg_xpm[] = { +"16 16 6 1", +" c None", +". c #EBF70E", +"+ c #000000", +"@ c #808080", +"# c #0000FF", +"$ c #FFFFFF", +" . ", +"+++.++++++++++++", +"+.@.@.@@@@@@@@@+", +"+@...#########@+", +"...@....@@@@@@@+", +"+@...$$$$$$$$$@+", +"+.$.@.@@@@@@$$@+", +"+@$.@@@@@@@@$$@+", +"+@$.$$$$$$$$$$@+", +"+@$$$$$$$$$$$$@+", +"+@$$$$@@@@$$$$@+", +"+@$$$$@@@@$$$$@+", +"+@$$$$$$$$$$$$@+", +"+@@@@@@@@@@@@@@+", +"++++++++++++++++", +" "}; diff --git a/samples/xrc/rc/derivdlg.xrc b/samples/xrc/rc/derivdlg.xrc new file mode 100644 index 0000000000..cbf8318c7a --- /dev/null +++ b/samples/xrc/rc/derivdlg.xrc @@ -0,0 +1,78 @@ + + + + + + Derived Dialog Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + This is a derived dialog using XRC. This type of derived dialog will likely be the heart of your project, and thus is the most important example in this demonstration.\n\nIt is recommeded to open up derivdlg.cpp, derivdlg.h and derivdlg.xrc and follow along what is going on.\n\nThe steps to use a derived dialog are:\n\n(1) Derive your own dialog from wxDialog (derivdlg.cpp and derivdlg.h are an example).\n\n(2) In the source of the constructor of the derived dialog, load the XRC into the file, using the code as shown in the derivdlg.cpp\n\n(3)Add to the derived dilog's sourcecode some event handlers and other methods you want the dialog to do.\n\n(4)You can now just make an instance of the derived dialog and show it using ShowModal(), as is done in the MyFrame::OnDerivedDialogToolOrMenuCommand() method.\n\nThe remainder of this docuent will talk about how to use events with derived dialogs and XRC. There are 3 bits of a extra event functionality that this derived derived dialog can do, these will be described in turn:\n\n(A) Something to do when a user clicks on your custom button: This is straightforward. You name a control in the XRC file (in this example it is "my__button"). Then in the .cpp file, put an entry in the event table that will connect button clicks with that ID to a function that will be fired. The event table entry in the example is EVT__BUTTON( XRCID( "my__button" ), PreferencesDialog::OnMyButtonClicked ) This event table entry has 3 parts: The first part, EVT__BUTTON tells that you are describing a button click event. The final part, PreferencesDialog::OnMyButtonClicked() is what you want done in response to a buttun event. The middle part, XRCID( "my__button" ) is the restriction that only button events generated by a wxButton of that ID should trigger go on to do the function. This XRCID is the name of the wxButton in your XRC file. Now just describe, in the .h file and .cpp file, what you want your custom OnMyButtonClicked() function to do.\n\n(B) The second example is a very common requirement: that a checkbox or radiobutton disables some other control. The event table is set up the same as the "My Button" example above. However, it isn't a EVT__BUTTON event, it is a EVT__UPDATE__UI event: when the dialog does an updating of ts UI (and thus fires this event) if the updating if of a control matching that XRCID, then it will do the specified function (which in this case looks at whether or not the checkbox is checked, and if it isn't checked, then disable the textctrl).\n\n(C) The last example shows how to handle the OK button. You will likely want to do something when the user presses OK, like save preferences or start some action (this example shows a simple case of just popping up a dialog and stopping a close). OK buttons are always named wxID__OK, so the XRC file should have it as wxID__OK also. The Event table has a EVT__BUTTON entry for wxID__OK (no XRCID though). Since this is a derived dialog with an event table, in response to a EVT__BUTTON event from a wxID__OK button, it will first look around in its own event table to see if there was any EVT__BUTTON entries, and since there is, it will do that one--if there wasn't it then check out the base class's event table and see if there was one there, and so on up the chain of inherited classes. Note that this is exactly what happens with the derived dialog's wxID__CANCEL button. You didn't put any EVT__BUTTON entries with an identifier of wxID__CANCEL, so after it scans your derived dialog's event table, it will then look at wxDialog's event table and see if there is one in that event table, and so on until it finds one. It will find a wxID__CANCEL handler, which will connect to the proper function (which causes the dialog to close). + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + wxHORIZONTAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + 80,-1 + + + + + + + wxALIGN_CENTRE|wxALL + 5 + + wxHORIZONTAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + diff --git a/samples/xrc/rc/frame.xrc b/samples/xrc/rc/frame.xrc new file mode 100644 index 0000000000..8b9c8ca5b8 --- /dev/null +++ b/samples/xrc/rc/frame.xrc @@ -0,0 +1,27 @@ + + + + + + XML Resources Demo + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,280 + + Welcome to the wxWindows XmlResource (XRC) sample! Using wxWindows XML resources makes your GUI C++ programming much faster and easier.\n\nView the examples under the "Basic" menu to learn how to get up and running with XRC quickly, and later have a look at the examples under the "Advanced" menu for advanced techniques.\n\nThe XML file that described this frame is the sample's frame.xrc file, with the menu in menu.xrc, and the toolbar in toolbar.xrc. The frame XRC file structure is exactly the same as the XRC files for the dialogs, except that the top level node is a wxFrame, not a wxDialog. Each of the other dialog in this example is a separate XRC file, each of which can be examined for how they work. + + + + + + diff --git a/samples/xrc/rc/menu.xrc b/samples/xrc/rc/menu.xrc new file mode 100644 index 0000000000..64d3ccbf04 --- /dev/null +++ b/samples/xrc/rc/menu.xrc @@ -0,0 +1,72 @@ + + + + + + + + + + + + Exit this application + + + + + Basic techniques with XRC + + + basicdlg.xpm + The basic instance of wxDialog loaded via XRC + + + + derivdlg.xpm + The most important example: load an XRC for a derived dialog + + + + controls.xpm + A notebook displaying all the wxWindows controls + + + + uncenter.xpm + Disable autocentering of a dialog on its parent + + + + + Advanced techniques with XRC + + + custclas.xpm + Embed your own custom classes into an XRC + + + + platform.xpm + Customize parts of an interface for a desired platform + + + + artprov.xpm + Use wxArtProvider to insert desired icons at runtime + + + + variable.xpm + Replace variables in the XRC file at runtime + + + + + + + About this application + + + + + diff --git a/samples/xrc/rc/platform.xpm b/samples/xrc/rc/platform.xpm new file mode 100644 index 0000000000..8702c4bbf2 --- /dev/null +++ b/samples/xrc/rc/platform.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static char * platform_xpm[] = { +"16 16 2 1", +" c None", +". c #0000FF", +" ", +" .. ", +" .. ", +" . ", +" ... .... ", +" ........... ", +" .......... ", +" .......... ", +" .......... ", +" .......... ", +" ........... ", +" ........... ", +" ........... ", +" ......... ", +" ... ... ", +" "}; diff --git a/samples/xrc/rc/platform.xrc b/samples/xrc/rc/platform.xrc new file mode 100644 index 0000000000..9f143bf5a8 --- /dev/null +++ b/samples/xrc/rc/platform.xrc @@ -0,0 +1,145 @@ + + + + + + Platform Property Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + You can specify certain nodes of an XRC file to only be used for a certain platform.\n\nTo do this, there is a "platform" property that can be placed in any node [ie inside an opening tag]. The value of the tag can be any combination of the following: mac, win, unix, or os2. Use a | symbol between multiple platforms, for example <label platform="win|mac">\n\nAt runtime, if there is a platform property in the tag, if it matches the current operating system, that node will be included, otherwise it won't.\n\nThe notebook example below shows how you can specify a high level node to only appear on a certain platform: the example here being a page of preferences that only make sense on a certain platform.\n\nThe second example shows how to replace a single attribute of a control: here the label of a download link. It is also very useful for specifying menu item accelerators keystrokes on the target platform. + + + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 1 + 200,160 + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + + wxVERTICAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + diff --git a/samples/xrc/rc/sppicon.ico b/samples/xrc/rc/sppicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..f3ef7918d273b912ce9d18f570cec891290ad3c7 GIT binary patch literal 1078 zcmcgqF>ZuF3^b=mX?X%wbkEoVDP7)j9j&{i%a?cn65mKkmj-DwW8({}i%zE~%7E=1 zukH03L>f6s+qOcS8<7{-u5(3Rk;$|xj}C{5;1yLj&{)beO|aZ3 z_DU&SLGaK;z5{N<=+Nwb+GQ&R7J8vw3YG^R`<9?N^83C|DQSiUG!F*d>yO{(dME7W zH^Mn}kOYZ2DP|b>t2srzM{V45w{d@;!Z2ulj|tFzKE^S60NUd>=W}o@2)J#3TUP6~ z%+BYs;!Bhj0o+H}&ddB0M_Lt+w7MPws`Gd-aqWkl0@r?xnezVc@_K-`^RwTID)Ex> epMk$#hUd#2ZizSb>f=Ub(IcYQqwl}gJo^hm2;JWR literal 0 HcmV?d00001 diff --git a/samples/xrc/rc/toolbar.xrc b/samples/xrc/rc/toolbar.xrc new file mode 100644 index 0000000000..9bc8082182 --- /dev/null +++ b/samples/xrc/rc/toolbar.xrc @@ -0,0 +1,51 @@ + + + + + + + 2,2 + + Non-Derived Dialog Example + basicdlg.xpm + The basic instance of wxDialog loaded via XRC + + + Derived Dialog Example + derivdlg.xpm + The most important example: load an XRC for a derived dialog + + + Controls Example + controls.xpm + A notebook displaying all the wxWindows controls + + + Uncentered Example + uncenter.xpm + Disable autocentering of a dialog on its parent + + + + Custom Class Example + custclas.xpm + Embed your own custom classes into an XRC + + + Platform Specific Example + platform.xpm + Customize parts of an interface for a desired platform + + + wxArtProvider Example + artprov.xpm + Use wxArtProvider to insert desired icons at runtime + + + Variable Expansion Example + variable.xpm + Replace variables in the XRC file at runtime + + + + diff --git a/samples/xrc/rc/uncenter.xpm b/samples/xrc/rc/uncenter.xpm new file mode 100644 index 0000000000..3ad911f2c6 --- /dev/null +++ b/samples/xrc/rc/uncenter.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * uncenter_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #808080", +"@ c #0000FF", +"# c #FFFFFF", +" ", +"................", +".++++++++++++++.", +".+@@@@@@@@@@@@+.", +".++++++++++++++.", +".+############+.", +".+###....#####+.", +".+###..#######+.", +".+###.#.######+.", +".+###.##.#####+.", +".+#######.####+.", +".+########.###+.", +".+############+.", +".++++++++++++++.", +"................", +" "}; diff --git a/samples/xrc/rc/uncenter.xrc b/samples/xrc/rc/uncenter.xrc new file mode 100644 index 0000000000..b1613d8ef5 --- /dev/null +++ b/samples/xrc/rc/uncenter.xrc @@ -0,0 +1,47 @@ + + + + + + Uncentered Example + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + All of the dialogs in the XRC demo, except for this dialog, center themselves automatically on their parent window, since that is what is most commonly needed. The centering for the other dialogs was done automatically simply by including a <centered>1</centered> as a tag directly under the dialog node.\n\nHowever, there may be some times when you don't want autocentering. If you don't want the dialog centered, just don't use the <centered> tag and the dialog will be placed in the default window position (which is at screen coordinate 0,0 in the upper left corner of the screen). This dialog is an example of when centering is turned off. + + + + wxALIGN_CENTRE|wxALL + 5 + + wxHORIZONTAL + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + + + + + diff --git a/samples/xrc/rc/variable.xpm b/samples/xrc/rc/variable.xpm new file mode 100644 index 0000000000..fdf792d3ad --- /dev/null +++ b/samples/xrc/rc/variable.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static char * variable_xpm[] = { +"16 16 2 1", +" c None", +". c #0E2CEF", +" ", +" . ", +" ... .. ", +" .... .. ", +" ...... .. ", +" . ... .. ", +" . ..... ", +" ... ", +" .... ", +" ..... . ", +" .. ... . ", +" .. ..... ", +" .. ... ", +" . ... ", +" ", +" "}; diff --git a/samples/xrc/rc/variable.xrc b/samples/xrc/rc/variable.xrc new file mode 100644 index 0000000000..b2d54bf4e9 --- /dev/null +++ b/samples/xrc/rc/variable.xrc @@ -0,0 +1,59 @@ + + + + + + Variable Expansion Example + 1 + + 1 + 0 + 0 + 0 + 0 + 0 + + wxGROW|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + 500,150 + + VARIABLE EXPANSION ISN'T IMPLEMENTED CURRENTLY. You can use variable expansion in your XRC files. The steps to do this are:\n\n(1)Enclose a variable inside a dollarsign and round brackets, like this: dollarsign(version).\n\n(2) Set the XmlResource flags to allow expansion of variables.\n\n(3)Before you use that XML resource, inform the XmlResourceHandler what you want that variable's value to be, via wxResourceHandler::Get()->SetVariable( "version", "2.4.0")\n\n Now, at runtime, the variable will be automatically replace by its value before the control is constructed.\n\nThe number in the version at the bottom of this dialog is an example of this expansion in action.\n\nThis is very handy for things like replacing the text in a wxStaticText, since it is a much simpler way to make a wxStaticText be a proper size: by creating it the proper size. This is in contrast to the alternative way of having using some static non-variable value in your XRC, having XRC construct it, then your application having code to change the text of it, then your app getting its best size, then setting the statictext's size, then laying out the dialog's sizer again, and other work. + + + + wxGROW|wxALIGN_BOTTOM + + 3 + 0 + 0 + 0 + 2 + 0 + + wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM + 5 + + + + + + wxALIGN_CENTRE|wxALL + 5 + + + + + + wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL + 5 + + + + + + + + + + diff --git a/samples/xrc/xrcdemo.cpp b/samples/xrc/xrcdemo.cpp index ba5e147e43..f7d755352c 100644 --- a/samples/xrc/xrcdemo.cpp +++ b/samples/xrc/xrcdemo.cpp @@ -1,24 +1,24 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: xmldemo.cpp -// Purpose: XML resources sample -// Author: Vaclav Slavik +//----------------------------------------------------------------------------- +// Name: xrcdemo.cpp +// Purpose: XML resources sample: Main application file +// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik // RCS-ID: $Id$ -// Copyright: (c) Vaclav Slavik +// Copyright: (c) Robert O'Connor and Vaclav Slavik // Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// +//----------------------------------------------------------------------------- -// ============================================================================ -// declarations -// ============================================================================ +//----------------------------------------------------------------------------- +// GCC implementation +//----------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- #ifdef __GNUG__ - #pragma implementation "xrcdemo.cpp" - #pragma interface "xrcdemo.cpp" + #pragma implementation "xrcdemo.h" #endif +//----------------------------------------------------------------------------- +// Standard wxWindows headers +//----------------------------------------------------------------------------- + // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -26,143 +26,99 @@ #pragma hdrstop #endif -// for all others, include the necessary headers (this file is usually all you +// 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 -#include "wx/image.h" -#include "wx/xrc/xmlres.h" +//----------------------------------------------------------------------------- +// Header of this .cpp file +//----------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -// resources -// ---------------------------------------------------------------------------- -// the application icon -#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) - #include "rc/appicon.xpm" -#endif +#include "xrcdemo.h" -// ---------------------------------------------------------------------------- -// private classes -// ---------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Remaining headers: Needed wx headers, then wx/contrib headers, then application headers +//----------------------------------------------------------------------------- -// Define a new application type, each program should derive a class from wxApp -class MyApp : public wxApp -{ -public: - // override base class virtuals - // ---------------------------- - - // this one is called on application startup and is a good place for the app - // initialization (doing it here and not in the ctor allows to have an error - // return: if OnInit() returns false, the application terminates) - virtual bool OnInit(); -}; - -// Define a new frame type: this is going to be our main frame -class MyFrame : public wxFrame -{ -public: - // ctor(s) - MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); - - // event handlers (these functions should _not_ be virtual) - void OnQuit(wxCommandEvent& event); - void OnAbout(wxCommandEvent& event); - void OnDlg1(wxCommandEvent& event); - void OnDlg2(wxCommandEvent& event); - -private: - // any class wishing to process wxWindows events must use this macro - DECLARE_EVENT_TABLE() -}; - -// ---------------------------------------------------------------------------- -// event tables and other macros for wxWindows -// ---------------------------------------------------------------------------- - -// the event tables connect the wxWindows events with the functions (event -// handlers) which process them. It can be also done at run-time, but for the -// simple menu events like this the static method is much simpler. -BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MENU(XRCID("menu_quit"), MyFrame::OnQuit) - EVT_MENU(XRCID("menu_about"), MyFrame::OnAbout) - EVT_MENU(XRCID("menu_dlg1"), MyFrame::OnDlg1) - EVT_MENU(XRCID("menu_dlg2"), MyFrame::OnDlg2) -END_EVENT_TABLE() +#include "wx/image.h" // wxImage + +//----------------------------------------------------------------------------- + +#include "wx/xrc/xmlres.h" // XRC XML resouces + +//----------------------------------------------------------------------------- + +#include "myframe.h" + +//----------------------------------------------------------------------------- +// wxWindows macro: Declare the application. +//----------------------------------------------------------------------------- // Create a new application object: this macro will allow wxWindows to create // the application object during program execution (it's better than using a // static object for many reasons) and also declares the accessor function -// wxGetApp() which will return the reference of the right type (i.e. MyApp and -// not wxApp) +// wxGetApp() which will return the reference of the right type (i.e. the_app and +// not wxApp). IMPLEMENT_APP(MyApp) -// ============================================================================ -// implementation -// ============================================================================ - -// ---------------------------------------------------------------------------- -// the application class -// ---------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Public methods +//----------------------------------------------------------------------------- // 'Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { - wxImage::AddHandler(new wxGIFHandler); - wxXmlResource::Get()->InitAllHandlers(); - wxXmlResource::Get()->Load("rc/resource.xrc"); - - MyFrame *frame = new MyFrame("XML resources demo", - wxPoint(50, 50), wxSize(450, 340)); + // If there is any of a certain format of image in the xrcs, then first + // load a handler for that image type. This example uses XPMs, but if + // you want PNGs, then add a PNG handler, etc. See wxImage::AddHandler() + // documentation for the types of image handlers available. + wxImage::AddHandler(new wxXPMHandler); + + // Initialize all the XRC handlers. Always required (unless you feel like + // going through and initializing a handler of each control type you will + // be using (ie initialize the spinctrl handler, initialize the textctrl + // handler). However, if you are only using a few control types, it will + // save some space to only initialize the ones you will be using. See + // wxXRC docs for details. + wxXmlResource::Get()->InitAllHandlers(); + + // Load all of the XRC files that will be used. You can put everything + // into one giant XRC file if you wanted, but then they become more + // diffcult to manage, and harder to reuse in later projects. + // The menubar + wxXmlResource::Get()->Load("rc/menu.xrc"); + // The toolbar + wxXmlResource::Get()->Load("rc/toolbar.xrc"); + // Non-derived dialog example + wxXmlResource::Get()->Load("rc/basicdlg.xrc"); + // Derived dialog example + wxXmlResource::Get()->Load("rc/derivdlg.xrc"); + // Controls property example + wxXmlResource::Get()->Load("rc/controls.xrc"); + // Frame example + wxXmlResource::Get()->Load("rc/frame.xrc"); + // Uncentered example + wxXmlResource::Get()->Load("rc/uncenter.xrc"); + // Custom class example + wxXmlResource::Get()->Load("rc/custclas.xrc"); + // wxArtProvider example + wxXmlResource::Get()->Load("rc/artprov.xrc"); + // Platform property example + wxXmlResource::Get()->Load("rc/platform.xrc"); + // Variable expansion example + wxXmlResource::Get()->Load("rc/variable.xrc"); + + // Make an instance of your derived frame. Passing NULL (the default value + // of MyFrame's constructor is NULL) as the frame doesn't have a frame + // since it is the first window. + MyFrame *frame = new MyFrame(); + + // Show the frame. frame->Show(TRUE); + + // Return TRUE to tell program to continue (FALSE would terminate). return TRUE; } -// ---------------------------------------------------------------------------- -// main frame -// ---------------------------------------------------------------------------- - -// frame constructor -MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame((wxFrame *)NULL, -1, title, pos, size) -{ - SetIcon(wxICON(appicon)); - - SetMenuBar(wxXmlResource::Get()->LoadMenuBar("mainmenu")); - SetToolBar(wxXmlResource::Get()->LoadToolBar(this, "toolbar")); -} - - -// event handlers - -void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) -{ - // TRUE is to force the frame to close - Close(TRUE); -} - -void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) -{ - wxString msg; - msg.Printf( _T("This is the about dialog of XML resources demo.\n") - _T("Welcome to %s"), wxVERSION_STRING); - - wxMessageBox(msg, "About XML resources demo", wxOK | wxICON_INFORMATION, this); -} - -void MyFrame::OnDlg1(wxCommandEvent& WXUNUSED(event)) -{ - wxDialog dlg; - wxXmlResource::Get()->LoadDialog(&dlg, this, "dlg1"); - dlg.ShowModal(); -} - - -void MyFrame::OnDlg2(wxCommandEvent& WXUNUSED(event)) -{ - wxDialog dlg; - wxXmlResource::Get()->LoadDialog(&dlg, this, "dlg2"); - dlg.ShowModal(); -} diff --git a/samples/xrc/xrcdemo.h b/samples/xrc/xrcdemo.h new file mode 100644 index 0000000000..c201be31b4 --- /dev/null +++ b/samples/xrc/xrcdemo.h @@ -0,0 +1,54 @@ +//----------------------------------------------------------------------------- +// Name: xmldemo.cpp +// Purpose: XML resources sample: Main application file +// Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik +// RCS-ID: $Id$ +// Copyright: (c) Robert O'Connor and Vaclav Slavik +// Licence: wxWindows licence +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Begin single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#ifndef _XRCDEMO_H_ +#define _XRCDEMO_H_ + +//----------------------------------------------------------------------------- +// GCC interface +//----------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma interface "xrcdemo.h" +#endif + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "wx/app.h" // wxApp + +//----------------------------------------------------------------------------- +// Class definition: MyApp +//----------------------------------------------------------------------------- + +// Define a new application type, each program should derive a class from wxApp +class MyApp : public wxApp +{ + +public: + + // Override base class virtuals: + // wxApp::OnInit() is called on application startup and is a good place + // for the app initialization (doing it here and not in the ctor + // allows to have an error return: if OnInit() returns false, the + // application terminates) + virtual bool OnInit(); + +}; + +//----------------------------------------------------------------------------- +// End single inclusion of this .h file condition +//----------------------------------------------------------------------------- + +#endif //_XRCDEMO_H_ diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 33a33edc34..2106d04ff7 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -32,6 +32,7 @@ #include "wx/bitmap.h" #include "wx/image.h" #include "wx/fontmap.h" +#include "wx/artprov.h" #include "wx/xrc/xml.h" #include "wx/xrc/xmlres.h" @@ -690,6 +691,7 @@ long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv) } + int wxXmlResourceHandler::GetID() { wxString sid = GetName(); @@ -716,6 +718,68 @@ int wxXmlResourceHandler::GetID() } + +wxArtID wxXmlResourceHandler::GetStockID(const wxString& param) +{ + wxXmlNode *stockIDNode = GetParamNode(param); + if (stockIDNode == NULL) + return wxEmptyString; + + wxXmlNode *oldnode = m_node; + m_node = stockIDNode; + + wxArtID sid = m_node->GetPropVal(wxT("stock_id"), wxT("")); + + m_node = oldnode; + + if (sid.IsEmpty()) return wxEmptyString; +#define stdID(id) else if (sid == wxT(#id)) return id + stdID(wxART_ADD_BOOKMARK); stdID(wxART_DEL_BOOKMARK); + stdID(wxART_HELP_SIDE_PANEL); stdID(wxART_HELP_SETTINGS); + stdID(wxART_HELP_BOOK); stdID(wxART_HELP_FOLDER); + stdID(wxART_HELP_PAGE); stdID(wxART_GO_BACK); + stdID(wxART_GO_FORWARD); stdID(wxART_GO_UP); + stdID(wxART_GO_DOWN); stdID(wxART_GO_TO_PARENT); + stdID(wxART_GO_HOME); stdID(wxART_FILE_OPEN); + stdID(wxART_PRINT); stdID(wxART_HELP); stdID(wxART_TIP); + stdID(wxART_REPORT_VIEW); stdID(wxART_LIST_VIEW); + stdID(wxART_NEW_DIR); stdID(wxART_FOLDER); + stdID(wxART_GO_DIR_UP); stdID(wxART_EXECUTABLE_FILE); + stdID(wxART_NORMAL_FILE); stdID(wxART_TICK_MARK); + stdID(wxART_CROSS_MARK); stdID(wxART_ERROR); + stdID(wxART_QUESTION); stdID(wxART_WARNING); + stdID(wxART_INFORMATION); +#undef stdID + else return sid; +} + + + +wxArtClient wxXmlResourceHandler::GetStockClient(const wxString& param) +{ + wxXmlNode *stockClientNode = GetParamNode(param); + if (stockClientNode == NULL) + return wxEmptyString; + + wxXmlNode *oldnode = m_node; + m_node = stockClientNode; + + wxArtClient sid = m_node->GetPropVal(wxT("stock_client"), wxT("wxART_OTHER")); + + m_node = oldnode; + + if (sid.IsEmpty()) return wxEmptyString; +#define stdID(id) else if (sid == wxT(#id)) return id + stdID(wxART_TOOLBAR); stdID(wxART_MENU); + stdID(wxART_FRAME_ICON); stdID(wxART_CMN_DIALOG); + stdID(wxART_HELP_BROWSER); stdID(wxART_MESSAGE_BOX); + stdID(wxART_OTHER); +#undef stdID + else return sid; +} + + + wxString wxXmlResourceHandler::GetName() { return m_node->GetPropVal(wxT("name"), wxT("-1")); @@ -755,8 +819,17 @@ wxColour wxXmlResourceHandler::GetColour(const wxString& param) wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size) { + wxString stk = param; + if (!GetStockID(stk).IsEmpty()) + { + wxBitmap stockArt = wxArtProvider::GetBitmap(GetStockID(stk), + GetStockClient(stk), size); + if (stockArt != wxNullBitmap) + return stockArt; + } + wxString name = GetParamValue(param); - if (name.IsEmpty()) return wxNullBitmap; + if (name.IsEmpty()) return wxNullBitmap; #if wxUSE_FILESYSTEM wxFSFile *fsfile = GetCurFileSystem().OpenFile(name); if (fsfile == NULL) @@ -769,6 +842,7 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size) #else wxImage img(GetParamValue(wxT("bitmap"))); #endif + if (!img.Ok()) { wxLogError(_("XRC resource: Cannot create bitmap from '%s'."), param.c_str()); @@ -776,6 +850,7 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size) } if (!(size == wxDefaultSize)) img.Rescale(size.x, size.y); return wxBitmap(img); + } -- 2.45.2