fixed anchor link naming, indentation in some places, added the <hr> divisor, fixed the <>& removal in sample XRC and C++ code, wrapped long lines
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52068 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: xrc
|
// Name: xrc.h
|
||||||
// Purpose: topic overview
|
// Purpose: topic overview
|
||||||
// Author: wxWidgets team
|
// Author: wxWidgets team
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
@@ -11,11 +11,12 @@
|
|||||||
@page overview_xrc XML-based resource system overview
|
@page overview_xrc XML-based resource system overview
|
||||||
|
|
||||||
Classes: #wxXmlResource, #wxXmlResourceHandler
|
Classes: #wxXmlResource, #wxXmlResourceHandler
|
||||||
The XML-based resource system, known as XRC, allows user interface elements such as
|
|
||||||
dialogs, menu bars and toolbars, to be stored in text files and loaded into
|
The XML-based resource system, known as XRC, allows user interface elements such
|
||||||
the application at run-time. XRC files can also be compiled into binary XRS files or C++
|
as dialogs, menu bars and toolbars, to be stored in text files and loaded into
|
||||||
code (the former makes it possible to store all resources in a single file and the latter
|
the application at run-time. XRC files can also be compiled into binary XRS files
|
||||||
is useful when you want to embed the resources into the executable).
|
or C++ code (the former makes it possible to store all resources in a single file
|
||||||
|
and the latter is useful when you want to embed the resources into the executable).
|
||||||
|
|
||||||
There are several advantages to using XRC resources.
|
There are several advantages to using XRC resources.
|
||||||
|
|
||||||
@@ -24,79 +25,87 @@
|
|||||||
@li If you use a dialog designer that generates C++ code, it can be hard
|
@li If you use a dialog designer that generates C++ code, it can be hard
|
||||||
to reintegrate this into existing C++ code. Separation of resources and code
|
to reintegrate this into existing C++ code. Separation of resources and code
|
||||||
is a more elegant solution.
|
is a more elegant solution.
|
||||||
@li You can choose between different alternative resource files at run time, if necessary.
|
@li You can choose between different alternative resource files at run time,
|
||||||
|
if necessary.
|
||||||
@li The XRC format uses sizers for flexibility, allowing dialogs to be resizable
|
@li The XRC format uses sizers for flexibility, allowing dialogs to be resizable
|
||||||
and highly portable.
|
and highly portable.
|
||||||
@li The XRC format is a wxWidgets standard,
|
@li The XRC format is a wxWidgets standard,
|
||||||
and can be generated or postprocessed by any program that understands it. As it is based
|
and can be generated or postprocessed by any program that understands it.
|
||||||
on the XML standard, existing XML editors can be used for simple editing purposes.
|
As it is basedon the XML standard, existing XML editors can be used for
|
||||||
|
simple editing purposes.
|
||||||
|
|
||||||
XRC was written by Vaclav Slavik.
|
XRC was written by Vaclav Slavik.
|
||||||
@li @ref overview_xrcconcepts
|
|
||||||
@li @ref overview_binaryresourcefiles
|
@li @ref overview_xrc_concepts
|
||||||
@li @ref overview_embeddedresource
|
@li @ref overview_xrc_binaryresourcefiles
|
||||||
@li @ref overview_xrccppsample
|
@li @ref overview_xrc_embeddedresource
|
||||||
@li @ref overview_xrcsample
|
@li @ref overview_xrc_cppsample
|
||||||
@li @ref overview_xrcfileformat
|
@li @ref overview_xrc_sample
|
||||||
@li @ref overview_xrccppheader
|
@li @ref overview_xrc_fileformat
|
||||||
@li @ref overview_newresourcehandlers
|
@li @ref overview_xrc_cppheader
|
||||||
|
@li @ref overview_xrc_newresourcehandlers
|
||||||
|
|
||||||
|
|
||||||
@section overview_xrcconcepts XRC concepts
|
<hr>
|
||||||
|
|
||||||
|
|
||||||
|
@section overview_xrc_concepts XRC concepts
|
||||||
|
|
||||||
These are the typical steps for using XRC files in your application.
|
These are the typical steps for using XRC files in your application.
|
||||||
|
|
||||||
|
|
||||||
@li Include the appropriate headers: normally "wx/xrc/xmlres.h" will suffice;
|
@li Include the appropriate headers: normally "wx/xrc/xmlres.h" will suffice;
|
||||||
@li If you are going to use @ref binaryresourcefiles_overview, install
|
@li If you are going to use XRS files (see @ref overview_xrc_binaryresourcefiles), install
|
||||||
wxFileSystem archive handler first with @c wxFileSystem::AddHandler(new wxArchiveFSHandler);
|
wxFileSystem archive handler first with @c wxFileSystem::AddHandler(new wxArchiveFSHandler);
|
||||||
@li call @c wxXmlResource::Get()-InitAllHandlers() from your wxApp::OnInit function,
|
@li call @c wxXmlResource::Get()->InitAllHandlers() from your wxApp::OnInit function,
|
||||||
and then call @c wxXmlResource::Get()-Load("myfile.xrc") to load the resource file;
|
and then call @c wxXmlResource::Get()->Load("myfile.xrc") to load the resource file;
|
||||||
@li to create a dialog from a resource, create it using the default constructor, and then
|
@li to create a dialog from a resource, create it using the default constructor, and then
|
||||||
load it using for example @c wxXmlResource::Get()-LoadDialog(dlg, this, "dlg1");
|
load it using for example @c wxXmlResource::Get()->LoadDialog(dlg, this, "dlg1");
|
||||||
@li set up event tables as usual but use the @c XRCID(str) macro to translate from XRC string names
|
@li set up event tables as usual but use the @c XRCID(str) macro to translate from XRC string names
|
||||||
to a suitable integer identifier, for example @c EVT_MENU(XRCID("quit"), MyFrame::OnQuit).
|
to a suitable integer identifier, for example <tt>EVT_MENU(XRCID("quit"), MyFrame::OnQuit)</tt>.
|
||||||
|
|
||||||
To create an XRC file, you can use one of the following methods.
|
To create an XRC file, you can use one of the following methods.
|
||||||
|
|
||||||
@li Create the file by hand;
|
@li Create the file by hand;
|
||||||
@li use #wxDesigner, a commercial dialog designer/RAD tool;
|
@li use wxDesigner (http://www.roebling.de), a commercial dialog designer/RAD tool;
|
||||||
@li use #DialogBlocks, a commercial dialog editor;
|
@li use DialogBlocks (http://www.anthemion.co.uk/dialogblocks), a commercial dialog editor;
|
||||||
@li use #XRCed, a wxPython-based
|
@li use XRCed (http://xrced.sf.net), a wxPython-based dialog editor that you can find in the
|
||||||
dialog editor that you can find in the @c wxPython/tools subdirectory of the wxWidgets
|
@c wxPython/tools subdirectory of the wxWidgets SVN archive;
|
||||||
CVS archive;
|
@li use wxGlade (http://wxglade.sf.net), a GUI designer written in wxPython.
|
||||||
@li use #wxGlade, a GUI designer written in wxPython. At the moment it can generate Python, C++ and XRC;
|
At the moment it can generate Python, C++ and XRC;
|
||||||
|
|
||||||
|
A complete list of third-party tools that write to XRC can be found at
|
||||||
|
http://www.wxwidgets.org/wiki/index.php/Tools.
|
||||||
|
|
||||||
A complete list of third-party tools that write to XRC can be found at #www.wxwidgets.org/lnk_tool.htm.
|
It is highly recommended that you use a resource editing tool, since it's fiddly
|
||||||
|
writing XRC files by hand.
|
||||||
It is highly recommended that you use a resource editing tool, since it's fiddly writing
|
|
||||||
XRC files by hand.
|
|
||||||
|
|
||||||
You can use wxXmlResource::Load in a number of ways.
|
You can use wxXmlResource::Load in a number of ways.
|
||||||
You can pass an XRC file (XML-based text resource file)
|
You can pass an XRC file (XML-based text resource file) or a zip-compressed file
|
||||||
or a @ref binaryresourcefiles_overview (extension ZIP or XRS) containing other XRC.
|
(see @ref overview_xrc_binaryresourcefiles), with extension ZIP or XRS, containing
|
||||||
|
other XRC.
|
||||||
|
|
||||||
You can also use @ref embeddedresource_overview
|
You can also use embedded C++ resources (see @ref overview_xrc_embeddedresource).
|
||||||
|
|
||||||
@section overview_binaryresourcefiles Using binary resource files
|
|
||||||
|
|
||||||
To compile binary resource files, use the command-line wxrc utility. It takes one or more file parameters
|
@section overview_xrc_binaryresourcefiles Using binary resource files
|
||||||
(the input XRC files) and the following switches and options:
|
|
||||||
|
To compile binary resource files, use the command-line @c wxrc utility.
|
||||||
|
It takes one or more file parameters (the input XRC files) and the following
|
||||||
|
switches and options:
|
||||||
|
|
||||||
@li -h (--help): show a help message
|
@li -h (--help): show a help message
|
||||||
@li -v (--verbose): show verbose logging information
|
@li -v (--verbose): show verbose logging information
|
||||||
@li -c (--cpp-code): write C++ source rather than a XRS file
|
@li -c (--cpp-code): write C++ source rather than a XRS file
|
||||||
@li -e (--extra-cpp-code): if used together with -c, generates C++ header file
|
@li -e (--extra-cpp-code): if used together with -c, generates C++ header file
|
||||||
containing class definitions for the windows defined by the XRC file (see special subsection)
|
containing class definitions for the windows defined by the XRC file
|
||||||
|
(see special subsection)
|
||||||
@li -u (--uncompressed): do not compress XML files (C++ only)
|
@li -u (--uncompressed): do not compress XML files (C++ only)
|
||||||
@li -g (--gettext): output underscore-wrapped strings that poEdit or gettext can scan. Outputs to stdout, or a file if -o is used
|
@li -g (--gettext): output underscore-wrapped strings that poEdit or gettext can scan.
|
||||||
|
Outputs to stdout, or a file if -o is used
|
||||||
@li -n (--function) name: specify C++ function name (use with -c)
|
@li -n (--function) name: specify C++ function name (use with -c)
|
||||||
@li -o (--output) filename: specify the output file, such as resource.xrs or resource.cpp
|
@li -o (--output) filename: specify the output file, such as resource.xrs or resource.cpp
|
||||||
@li -l (--list-of-handlers) filename: output a list of necessary handlers to this file
|
@li -l (--list-of-handlers) filename: output a list of necessary handlers to this file
|
||||||
|
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
@code
|
@code
|
||||||
@@ -110,6 +119,7 @@
|
|||||||
it with standard ZIP tools. Note that if you are using XRS files, you have
|
it with standard ZIP tools. Note that if you are using XRS files, you have
|
||||||
to initialize the #wxFileSystem archive handler first! It is a simple
|
to initialize the #wxFileSystem archive handler first! It is a simple
|
||||||
thing to do:
|
thing to do:
|
||||||
|
|
||||||
@code
|
@code
|
||||||
#include wx/filesys.h
|
#include wx/filesys.h
|
||||||
#include wx/fs_arc.h
|
#include wx/fs_arc.h
|
||||||
@@ -118,7 +128,7 @@
|
|||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
|
|
||||||
@section overview_embeddedresource Using embedded resources
|
@section overview_xrc_embeddedresource Using embedded resources
|
||||||
|
|
||||||
It is sometimes useful to embed resources in the executable itself instead
|
It is sometimes useful to embed resources in the executable itself instead
|
||||||
of loading an external file (e.g. when your app is small and consists only of one
|
of loading an external file (e.g. when your app is small and consists only of one
|
||||||
@@ -139,7 +149,7 @@
|
|||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
|
|
||||||
@section overview_xrccppsample XRC C++ sample
|
@section overview_xrc_cppsample XRC C++ sample
|
||||||
|
|
||||||
This is the C++ source file (xrcdemo.cpp) for the XRC sample.
|
This is the C++ source file (xrcdemo.cpp) for the XRC sample.
|
||||||
|
|
||||||
@@ -209,13 +219,13 @@
|
|||||||
bool MyApp::OnInit()
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
wxImage::AddHandler(new wxGIFHandler);
|
wxImage::AddHandler(new wxGIFHandler);
|
||||||
wxXmlResource::Get()-InitAllHandlers();
|
wxXmlResource::Get()->InitAllHandlers();
|
||||||
wxXmlResource::Get()-Load("rc/resource.xrc");
|
wxXmlResource::Get()->Load("rc/resource.xrc");
|
||||||
|
|
||||||
MyFrame *frame = new MyFrame("XML resources demo",
|
MyFrame *frame = new MyFrame("XML resources demo",
|
||||||
wxPoint(50, 50), wxSize(450, 340));
|
wxPoint(50, 50), wxSize(450, 340));
|
||||||
frame-Show(@true);
|
frame->Show(true);
|
||||||
return @true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -224,19 +234,19 @@
|
|||||||
|
|
||||||
// frame constructor
|
// frame constructor
|
||||||
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||||
: wxFrame((wxFrame *)@NULL, -1, title, pos, size)
|
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
|
||||||
{
|
{
|
||||||
SetIcon(wxICON(appicon));
|
SetIcon(wxICON(appicon));
|
||||||
|
|
||||||
SetMenuBar(wxXmlResource::Get()-LoadMenuBar("mainmenu"));
|
SetMenuBar(wxXmlResource::Get()->LoadMenuBar("mainmenu"));
|
||||||
SetToolBar(wxXmlResource::Get()-LoadToolBar(this, "toolbar"));
|
SetToolBar(wxXmlResource::Get()->LoadToolBar(this, "toolbar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
// @true is to force the frame to close
|
// true is to force the frame to close
|
||||||
Close(@true);
|
Close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||||
@@ -251,187 +261,188 @@
|
|||||||
void MyFrame::OnDlg1(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnDlg1(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxDialog dlg;
|
wxDialog dlg;
|
||||||
wxXmlResource::Get()-LoadDialog(, this, "dlg1");
|
wxXmlResource::Get()->LoadDialog(&dlg, this, "dlg1");
|
||||||
dlg.ShowModal();
|
dlg.ShowModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnDlg2(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnDlg2(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxDialog dlg;
|
wxDialog dlg;
|
||||||
wxXmlResource::Get()-LoadDialog(, this, "dlg2");
|
wxXmlResource::Get()->LoadDialog(&dlg, this, "dlg2");
|
||||||
dlg.ShowModal();
|
dlg.ShowModal();
|
||||||
}
|
}
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
|
|
||||||
@section overview_xrcsample XRC resource file sample
|
@section overview_xrc_sample XRC resource file sample
|
||||||
|
|
||||||
This is the XML file (resource.xrc) for the XRC sample.
|
This is the XML file (resource.xrc) for the XRC sample.
|
||||||
|
|
||||||
@code
|
@code
|
||||||
?xml version="1.0"?
|
<?xml version="1.0"?>
|
||||||
resource version="2.3.0.1"
|
<resource version="2.3.0.1">
|
||||||
object class="wxMenuBar" name="mainmenu"
|
<object class="wxMenuBar" name="mainmenu">
|
||||||
stylewxMB_DOCKABLE/style
|
<style>wxMB_DOCKABLE</style>
|
||||||
object class="wxMenu" name="menu_file"
|
<object class="wxMenu" name="menu_file">
|
||||||
label_File/label
|
<label>_File</label>
|
||||||
stylewxMENU_TEAROFF/style
|
<style>wxMENU_TEAROFF</style>
|
||||||
object class="wxMenuItem" name="menu_about"
|
<object class="wxMenuItem" name="menu_about">
|
||||||
label_About.../label
|
<label>_About...</label>
|
||||||
bitmapfilesave.gif/bitmap
|
<bitmap>filesave.gif</bitmap>
|
||||||
/object
|
</object>
|
||||||
object class="separator"/
|
<object class="separator"/>
|
||||||
object class="wxMenuItem" name="menu_dlg1"
|
<object class="wxMenuItem" name="menu_dlg1">
|
||||||
labelDialog 1/label
|
<label>Dialog 1</label>
|
||||||
/object
|
</object>
|
||||||
object class="wxMenuItem" name="menu_dlg2"
|
<object class="wxMenuItem" name="menu_dlg2">
|
||||||
labelDialog 2/label
|
<label>Dialog 2</label>
|
||||||
/object
|
</object>
|
||||||
object class="separator"/
|
<object class="separator"/>
|
||||||
object class="wxMenuItem" name="menu_quit"
|
<object class="wxMenuItem" name="menu_quit">
|
||||||
labelE_xit\tAlt-X/label
|
<label>E_xit\tAlt-X</label>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
object class="wxToolBar" name="toolbar"
|
<object class="wxToolBar" name="toolbar">
|
||||||
stylewxTB_FLAT|wxTB_DOCKABLE/style
|
<style>wxTB_FLAT|wxTB_DOCKABLE</style>
|
||||||
margins2,2/margins
|
<margins>2,2</margins>
|
||||||
object class="tool" name="menu_open"
|
<object class="tool" name="menu_open">
|
||||||
bitmapfileopen.gif/bitmap
|
<bitmap>fileopen.gif</bitmap>
|
||||||
tooltipOpen catalog/tooltip
|
<tooltip>Open catalog</tooltip>
|
||||||
/object
|
</object>
|
||||||
object class="tool" name="menu_save"
|
<object class="tool" name="menu_save">
|
||||||
bitmapfilesave.gif/bitmap
|
<bitmap>filesave.gif</bitmap>
|
||||||
tooltipSave catalog/tooltip
|
<tooltip>Save catalog</tooltip>
|
||||||
/object
|
</object>
|
||||||
object class="tool" name="menu_update"
|
<object class="tool" name="menu_update">
|
||||||
bitmapupdate.gif/bitmap
|
<bitmap>update.gif</bitmap>
|
||||||
tooltipUpdate catalog - synchronize it with sources/tooltip
|
<tooltip>Update catalog - synchronize it with sources</tooltip>
|
||||||
/object
|
</object>
|
||||||
separator/
|
<separator/>
|
||||||
object class="tool" name="menu_quotes"
|
<object class="tool" name="menu_quotes">
|
||||||
bitmapquotes.gif/bitmap
|
<bitmap>quotes.gif</bitmap>
|
||||||
toggle1/toggle
|
<toggle>1</toggle>
|
||||||
tooltipDisplay quotes around the string?/tooltip
|
<tooltip>Display quotes around the string?</tooltip>
|
||||||
/object
|
</object>
|
||||||
object class="separator"/
|
<object class="separator"/>
|
||||||
object class="tool" name="menu_fuzzy"
|
<object class="tool" name="menu_fuzzy">
|
||||||
bitmapfuzzy.gif/bitmap
|
<bitmap>fuzzy.gif</bitmap>
|
||||||
tooltipToggled if selected string is fuzzy translation/tooltip
|
<tooltip>Toggled if selected string is fuzzy translation</tooltip>
|
||||||
toggle1/toggle
|
<toggle>1</toggle>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
object class="wxDialog" name="dlg1"
|
<object class="wxDialog" name="dlg1">
|
||||||
object class="wxBoxSizer"
|
<object class="wxBoxSizer">
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxBitmapButton"
|
<object class="wxBitmapButton">
|
||||||
bitmapfuzzy.gif/bitmap
|
<bitmap>fuzzy.gif</bitmap>
|
||||||
focusfileopen.gif/focus
|
<focus>fileopen.gif</focus>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxPanel"
|
<object class="wxPanel">
|
||||||
object class="wxStaticText"
|
<object class="wxStaticText">
|
||||||
labelfdgdfgdfgdfg/label
|
<label>fdgdfgdfgdfg</label>
|
||||||
/object
|
</object>
|
||||||
stylewxBORDER\_SUNKEN/style
|
<style>wxBORDER\_SUNKEN</style>
|
||||||
/object
|
</object>
|
||||||
flagwxALIGN_CENTER/flag
|
<flag>wxALIGN_CENTER</flag>
|
||||||
/object
|
</object>
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxButton"
|
<object class="wxButton">
|
||||||
labelButtonek/label
|
<label>Buttonek</label>
|
||||||
/object
|
</object>
|
||||||
border10d/border
|
<border>10d</border>
|
||||||
flagwxALL/flag
|
<flag>wxALL</flag>
|
||||||
/object
|
</object>
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxHtmlWindow"
|
<object class="wxHtmlWindow">
|
||||||
htmlcodeh1Hi,/h1man/htmlcode
|
<htmlcode><h1>Hi,</h1>man</htmlcode>
|
||||||
size100,45d/size
|
<size>100,45d</size>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxNotebook"
|
<object class="wxNotebook">
|
||||||
object class="notebookpage"
|
<object class="notebookpage">
|
||||||
object class="wxPanel"
|
<object class="wxPanel">
|
||||||
object class="wxBoxSizer"
|
<object class="wxBoxSizer">
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxHtmlWindow"
|
<object class="wxHtmlWindow">
|
||||||
htmlcodeHello, we are inside a uNOTEBOOK/u.../htmlcode
|
<htmlcode>Hello, we are inside a <u>NOTEBOOK</u>...</htmlcode>
|
||||||
size50,50d/size
|
<size>50,50d</size>
|
||||||
/object
|
</object>
|
||||||
option1/option
|
<option>1</option>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
labelPage/label
|
<label>Page</label>
|
||||||
/object
|
</object>
|
||||||
object class="notebookpage"
|
<object class="notebookpage">
|
||||||
object class="wxPanel"
|
<object class="wxPanel">
|
||||||
object class="wxBoxSizer"
|
<object class="wxBoxSizer">
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxHtmlWindow"
|
<object class="wxHtmlWindow">
|
||||||
htmlcodeHello, we are inside a uNOTEBOOK/u.../htmlcode
|
<htmlcode>Hello, we are inside a <u>NOTEBOOK</u>...</htmlcode>
|
||||||
size50,50d/size
|
<size>50,50d</size>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
labelPage 2/label
|
<label>Page 2</label>
|
||||||
/object
|
</object>
|
||||||
usenotebooksizer1/usenotebooksizer
|
<usenotebooksizer>1</usenotebooksizer>
|
||||||
/object
|
</object>
|
||||||
flagwxEXPAND/flag
|
<flag>wxEXPAND</flag>
|
||||||
/object
|
</object>
|
||||||
orientwxVERTICAL/orient
|
<orient>wxVERTICAL</orient>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
object class="wxDialog" name="dlg2"
|
<object class="wxDialog" name="dlg2">
|
||||||
object class="wxBoxSizer"
|
<object class="wxBoxSizer">
|
||||||
orientwxVERTICAL/orient
|
<orient>wxVERTICAL</orient>
|
||||||
object class="sizeritem" name="dfgdfg"
|
<object class="sizeritem" name="dfgdfg">
|
||||||
object class="wxTextCtrl"
|
<object class="wxTextCtrl">
|
||||||
size200,200d/size
|
<size>200,200d</size>
|
||||||
stylewxTE_MULTILINE|wxBORDER_SUNKEN/style
|
<style>wxTE_MULTILINE|wxBORDER_SUNKEN</style>
|
||||||
valueHello, this is an ordinary multiline\n textctrl..../value
|
<value>Hello, this is an ordinary multiline\n textctrl....</value>
|
||||||
/object
|
</object>
|
||||||
option1/option
|
<option>1</option>
|
||||||
flagwxEXPAND|wxALL/flag
|
<flag>wxEXPAND|wxALL</flag>
|
||||||
border10/border
|
<border>10</border>
|
||||||
/object
|
</object>
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxBoxSizer"
|
<object class="wxBoxSizer">
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxButton" name="wxID_OK"
|
<object class="wxButton" name="wxID_OK">
|
||||||
labelOk/label
|
<label>Ok</label>
|
||||||
default1/default
|
<default>1</default>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxButton" name="wxID_CANCEL"
|
<object class="wxButton" name="wxID_CANCEL">
|
||||||
labelCancel/label
|
<label>Cancel</label>
|
||||||
/object
|
</object>
|
||||||
border10/border
|
<border>10</border>
|
||||||
flagwxLEFT/flag
|
<flag>wxLEFT</flag>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
flagwxLEFT|wxRIGHT|wxBOTTOM|wxALIGN_RIGHT/flag
|
<flag>wxLEFT|wxRIGHT|wxBOTTOM|wxALIGN_RIGHT</flag>
|
||||||
border10/border
|
<border>10</border>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
titleSecond testing dialog/title
|
<title>Second testing dialog</title>
|
||||||
/object
|
</object>
|
||||||
/resource
|
</resource>
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
|
|
||||||
@section overview_xrcfileformat XRC file format
|
@section overview_xrc_fileformat XRC file format
|
||||||
|
|
||||||
Please see Technical Note 14 (docs/tech/tn0014.txt) in your wxWidgets
|
Please see Technical Note 14 (docs/tech/tn0014.txt) in your wxWidgets
|
||||||
distribution.
|
distribution.
|
||||||
|
|
||||||
@section overview_xrccppheader C++ header file generation
|
|
||||||
|
@section overview_xrc_cppheader C++ header file generation
|
||||||
|
|
||||||
Using the @c -e switch together with @c -c, a C++ header file is written
|
Using the @c -e switch together with @c -c, a C++ header file is written
|
||||||
containing class definitions for the GUI windows defined in the XRC file.
|
containing class definitions for the GUI windows defined in the XRC file.
|
||||||
@@ -446,31 +457,34 @@
|
|||||||
all XRC loading is done and all class members representing widgets are initialized.
|
all XRC loading is done and all class members representing widgets are initialized.
|
||||||
|
|
||||||
A simple example will help understand how the scheme works. Suppose you have
|
A simple example will help understand how the scheme works. Suppose you have
|
||||||
a XRC file defining a top level window @c TestWnd_Base, which subclasses @c wxFrame (any
|
a XRC file defining a top level window @c TestWnd_Base, which subclasses @c wxFrame
|
||||||
other class like @c wxDialog will do also), and has subwidgets @c wxTextCtrl A and @c wxButton B.
|
(any other class like @c wxDialog will do also), and has subwidgets @c wxTextCtrl A
|
||||||
The XRC file and corresponding class definition in the header file will be something like:
|
and @c wxButton B.
|
||||||
|
|
||||||
|
The XRC file and corresponding class definition in the header file will
|
||||||
|
be something like:
|
||||||
|
|
||||||
@code
|
@code
|
||||||
?xml version="1.0"?
|
<?xml version="1.0"?>
|
||||||
resource version="2.3.0.1"
|
<resource version="2.3.0.1">
|
||||||
object class="wxFrame" name="TestWnd_Base"
|
<object class="wxFrame" name="TestWnd_Base">
|
||||||
size-1,-1/size
|
<size>-1,-1</size>
|
||||||
titleTest/title
|
<title>Test</title>
|
||||||
object class="wxBoxSizer"
|
<object class="wxBoxSizer">
|
||||||
orientwxHORIZONTAL/orient
|
<orient>wxHORIZONTAL</orient>
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxTextCtrl" name="A"
|
<object class="wxTextCtrl" name="A">
|
||||||
labelTest label/label
|
<label>Test label</label>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
object class="sizeritem"
|
<object class="sizeritem">
|
||||||
object class="wxButton" name="B"
|
<object class="wxButton" name="B">
|
||||||
labelTest button/label
|
<label>Test button</label>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
/object
|
</object>
|
||||||
/resource
|
</resource>
|
||||||
|
|
||||||
|
|
||||||
class TestWnd_Base : public wxFrame {
|
class TestWnd_Base : public wxFrame {
|
||||||
@@ -480,7 +494,7 @@
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void InitWidgetsFromXRC(){
|
void InitWidgetsFromXRC(){
|
||||||
wxXmlResource::Get()-LoadObject(this,@NULL,"TestWnd","wxFrame");
|
wxXmlResource::Get()->LoadObject(this,NULL,"TestWnd","wxFrame");
|
||||||
A = XRCCTRL(*this,"A",wxTextCtrl);
|
A = XRCCTRL(*this,"A",wxTextCtrl);
|
||||||
B = XRCCTRL(*this,"B",wxButton);
|
B = XRCCTRL(*this,"B",wxButton);
|
||||||
}
|
}
|
||||||
@@ -493,9 +507,10 @@
|
|||||||
|
|
||||||
The generated window class can be used as basis for the full window class. The
|
The generated window class can be used as basis for the full window class. The
|
||||||
class members which represent widgets may be accessed by name instead of using
|
class members which represent widgets may be accessed by name instead of using
|
||||||
@c XRCCTRL every time you wish to reference them (note that they are @c protected class members),
|
@c XRCCTRL every time you wish to reference them (note that they are @c protected
|
||||||
though you must still use @c XRCID to refer to widget IDs in the event
|
class members), though you must still use @c XRCID to refer to widget IDs in the
|
||||||
table.
|
event table.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@code
|
@code
|
||||||
@@ -505,8 +520,8 @@
|
|||||||
public:
|
public:
|
||||||
TestWnd(){
|
TestWnd(){
|
||||||
// A, B already initialised at this point
|
// A, B already initialised at this point
|
||||||
A-SetValue("Updated in TestWnd::TestWnd");
|
A->SetValue("Updated in TestWnd::TestWnd");
|
||||||
B-SetValue("Nice :)");
|
B->SetValue("Nice :)");
|
||||||
}
|
}
|
||||||
void OnBPressed(wxEvent& event){
|
void OnBPressed(wxEvent& event){
|
||||||
Close();
|
Close();
|
||||||
@@ -520,13 +535,14 @@
|
|||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
It is also possible to access the wxSizerItem of a sizer that is part of
|
It is also possible to access the wxSizerItem of a sizer that is part of
|
||||||
a resource. This can be done using @c XRCSIZERITEM as shown. The
|
a resource. This can be done using @c XRCSIZERITEM as shown.
|
||||||
resource file can have something like this for a sizer item.
|
|
||||||
|
The resource file can have something like this for a sizer item.
|
||||||
|
|
||||||
@code
|
@code
|
||||||
object class="spacer" name="area"
|
<object class="spacer" name="area">
|
||||||
size400, 300/size
|
<size>400, 300</size>
|
||||||
/object
|
</object>
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
The code can then access the sizer item by using @c XRCSIZERITEM and
|
The code can then access the sizer item by using @c XRCSIZERITEM and
|
||||||
@@ -537,11 +553,12 @@
|
|||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
|
|
||||||
@section overview_newresourcehandlers Adding new resource handlers
|
@section overview_xrc_newresourcehandlers Adding new resource handlers
|
||||||
|
|
||||||
Adding a new resource handler is pretty easy.
|
Adding a new resource handler is pretty easy.
|
||||||
|
|
||||||
Typically, to add an handler for the @c MyControl class, you'll want to create
|
Typically, to add an handler for the @c MyControl class, you'll want to create
|
||||||
the @c xh_mycontrol.h @c xh_mycontrol.cpp files.
|
the @c xh_mycontrol.h and @c xh_mycontrol.cpp files.
|
||||||
|
|
||||||
The header needs to contains the @c MyControlXmlHandler class definition:
|
The header needs to contains the @c MyControlXmlHandler class definition:
|
||||||
|
|
||||||
@@ -604,21 +621,21 @@
|
|||||||
//
|
//
|
||||||
// then the XRC for your component should look like:
|
// then the XRC for your component should look like:
|
||||||
//
|
//
|
||||||
// object class="MyControl" name="some_name"
|
// <object class="MyControl" name="some_name">
|
||||||
// first-bitmapfirst.xpm/first-bitmap
|
// <first-bitmap>first.xpm</first-bitmap>
|
||||||
// second-bitmaptext.xpm/second-bitmap
|
// <second-bitmap>text.xpm</second-bitmap>
|
||||||
// first-pos3,3/first-pos
|
// <first-pos>3,3</first-pos>
|
||||||
// second-pos4,4/second-pos
|
// <second-pos>4,4</second-pos>
|
||||||
// the-titlea title/the-title
|
// <the-title>a title</the-title>
|
||||||
// title-font
|
// <title-font>
|
||||||
// !-- the standard XRC tags for describing a font: size, style, weight, etc --
|
// <!-- the standard XRC tags for describing a font: <size>, <style>, <weight>, etc -->
|
||||||
// /title-font
|
// </title-font>
|
||||||
// !-- XRC also accepts other usual tags for wxWindow-derived classes:
|
// <!-- XRC also accepts other usual tags for wxWindow-derived classes:
|
||||||
// like e.g. name, style, size, position, etc --
|
// like e.g. <name>, <style>, <size>, <position>, etc -->
|
||||||
// /object
|
// </object>
|
||||||
//
|
//
|
||||||
// and the code to read your custom tags from the XRC file is just:
|
// and the code to read your custom tags from the XRC file is just:
|
||||||
control-Create(m_parentAsWindow, GetID(),
|
control->Create(m_parentAsWindow, GetID(),
|
||||||
GetBitmap(wxT("first-bitmap")),
|
GetBitmap(wxT("first-bitmap")),
|
||||||
GetPosition(wxT("first-pos")),
|
GetPosition(wxT("first-pos")),
|
||||||
GetBitmap(wxT("second-bitmap")),
|
GetBitmap(wxT("second-bitmap")),
|
||||||
@@ -641,9 +658,8 @@
|
|||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
You may want to check the #wxXmlResourceHandler documentation
|
You may want to check the #wxXmlResourceHandler documentation
|
||||||
to see how many built-in getters it contains. It's very easy to retrieve also complex structures
|
to see how many built-in getters it contains. It's very easy to retrieve also
|
||||||
out of XRC files using them.
|
complex structures out of XRC files using them.
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user