]>
git.saurik.com Git - wxWidgets.git/blob - interface/xrc/xmlres.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxXmlResource class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 @headerfile xmlres.h wx/xrc/xmlres.h
13 This is the main class for interacting with the XML-based resource system.
15 The class holds XML resources from one or more .xml files, binary files or zip
18 See @ref overview_xrcoverview "XML-based resource system overview" for details.
23 class wxXmlResource
: public wxObject
31 wxXRC_USE_LOCALE: translatable strings will be translated via _().
32 wxXRC_NO_SUBCLASSING: subclass property of object nodes will be ignored
33 (useful for previews in XRC editors). wxXRC_NO_RELOADING will prevent the
34 XRC files from being reloaded from disk in case they have been modified there
35 since being last loaded (may slightly speed up loading them).
38 The name of the gettext catalog to search for
39 translatable strings. By default all loaded catalogs will be
40 searched. This provides a way to allow the strings to only come
41 from a specific catalog.
43 wxXmlResource(const wxString
& filemask
,
44 int flags
= wxXRC_USE_LOCALE
,
45 const wxString domain
= wxEmptyString
);
46 wxXmlResource(int flags
= wxXRC_USE_LOCALE
,
47 const wxString domain
= wxEmptyString
);
56 Initializes only a specific handler (or custom handler). Convention says
57 that the handler name is equal to the control's name plus 'XmlHandler', for
59 wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. The XML resource compiler
60 (wxxrc) can create include file that contains initialization code for
61 all controls used within the resource. Note that this handler should be
62 allocated on the heap, since it will be delete by
63 ClearHandlers() later.
65 void AddHandler(wxXmlResourceHandler
* handler
);
68 Attaches an unknown control to the given panel/window/dialog.
69 Unknown controls are used in conjunction with object class="unknown".
71 bool AttachUnknownControl(const wxString
& name
,
73 wxWindow
* parent
= @NULL
);
76 Removes all handlers and deletes them (this means that any handlers added using
77 AddHandler() must be allocated on the heap).
82 Compares the XRC version to the argument. Returns -1 if the XRC version
83 is less than the argument, +1 if greater, and 0 if they equal.
85 int CompareVersion(int major
, int minor
, int release
,
89 Gets the global resources object or creates one if none exists.
91 #define wxXmlResource* Get() /* implementation is private */
94 Returns the domain (message catalog) that will be used to load
95 translatable strings in the XRC.
100 Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and
101 wxXRC_NO_SUBCLASSING.
106 Returns version information (a.b.c.d = d+ 256*c + 256@c 2*b + 256@c 3*a).
111 Returns a numeric ID that is equivalent to the string ID used in an XML
112 resource. If an unknown @e str_id is requested (i.e. other than wxID_XXX
113 or integer), a new record is created which associates the given string with
114 a number. If @e value_if_not_found is @c wxID_NONE, the number is obtained via
115 wxNewId. Otherwise @e value_if_not_found is used.
116 Macro @c XRCID(name) is provided for convenient use in event tables.
118 #define int GetXRCID(const wxString& str_id, int value_if_not_found = -2) /* implementation is private */
121 Initializes handlers for all supported controls/windows. This will
122 make the executable quite big because it forces linking against
123 most of the wxWidgets library.
125 void InitAllHandlers();
128 Loads resources from XML files that match given filemask.
129 This method understands VFS (see filesys.h).
131 bool Load(const wxString
& filemask
);
134 Loads a bitmap resource from a file.
136 wxBitmap
LoadBitmap(const wxString
& name
);
140 Loads a dialog. @e dlg points to parent window (if any).
142 This form is used to finish creation of an already existing instance (the main
144 for this is that you may want to use derived class with a new event table).
148 wxDialog
* LoadDialog(wxWindow
* parent
, const wxString
& name
);
149 bool LoadDialog(wxDialog
* dlg
, wxWindow
* parent
,
150 const wxString
& name
);
156 bool LoadFrame(wxFrame
* frame
, wxWindow
* parent
,
157 const wxString
& name
);
160 Loads an icon resource from a file.
162 wxIcon
LoadIcon(const wxString
& name
);
165 Loads menu from resource. Returns @NULL on failure.
167 wxMenu
* LoadMenu(const wxString
& name
);
171 Loads a menubar from resource. Returns @NULL on failure.
173 wxMenuBar
* LoadMenuBar(wxWindow
* parent
, const wxString
& name
);
174 wxMenuBar
* LoadMenuBar(const wxString
& name
);
179 Load an object from the resource specifying both the resource name and the
182 The first overload lets you load nonstandard container windows and returns @c
184 on failure. The second one lets you finish the creation of an existing
185 instance and returns @false on failure.
187 wxObject
* LoadObject(wxWindow
* parent
, const wxString
& name
,
188 const wxString
& classname
);
189 bool LoadObject(wxObject
* instance
, wxWindow
* parent
,
190 const wxString
& name
,
191 const wxString
& classname
);
196 Loads a panel. @e panel points to parent window (if any). This form
197 is used to finish creation of an already existing instance.
199 wxPanel
* LoadPanel(wxWindow
* parent
, const wxString
& name
);
200 bool LoadPanel(wxPanel
* panel
, wxWindow
* parent
,
201 const wxString
& name
);
207 wxToolBar
* LoadToolBar(wxWindow
* parent
, const wxString
& name
);
210 Sets the global resources object and returns a pointer to the previous one (may
213 #define wxXmlResource* Set(wxXmlResource* res) /* implementation is private */
216 Sets the domain (message catalog) that will be used to load
217 translatable strings in the XRC.
219 wxChar
* SetDomain(const wxChar
* domain
);
222 Sets flags (bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING).
224 void SetFlags(int flags
);
227 This function unloads a resource previously loaded by
230 Returns @true if the resource was successfully unloaded and @false if it
232 been found in the list of loaded resources.
234 bool Unload(const wxString
& filename
);
239 @class wxXmlResourceHandler
240 @headerfile xmlres.h wx/xrc/xmlres.h
242 wxXmlResourceHandler is an abstract base class for resource handlers
243 capable of creating a control from an XML node.
245 See @ref overview_xrcoverview "XML-based resource system overview" for details.
250 class wxXmlResourceHandler
: public wxObject
256 wxXmlResourceHandler();
261 ~wxXmlResourceHandler();
264 Add a style flag (e.g. wxMB_DOCKABLE) to the list of flags
265 understood by this handler.
267 void AddStyle(const wxString
& name
, int value
);
270 Add styles common to all wxWindow-derived classes.
272 void AddWindowStyles();
275 Returns @true if it understands this node and can create
276 a resource from it, @false otherwise.
278 bool CanHandle(wxXmlNode
* node
);
283 void CreateChildren(wxObject
* parent
, bool this_hnd_only
= @
false);
288 void CreateChildrenPrivately(wxObject
* parent
,
289 wxXmlNode
* rootnode
= @NULL
);
292 Creates a resource from a node.
294 wxObject
* CreateResFromNode(wxXmlNode
* node
, wxObject
* parent
,
295 wxObject
* instance
= @NULL
);
298 Creates an object (menu, dialog, control, ...) from an XML node.
299 Should check for validity. @e parent is a higher-level object (usually window,
301 that is often necessary to create the resource.
302 If @b instance is non-@NULL it should not create a new instance via 'new' but
303 should rather use this one, and call its Create method.
305 wxObject
* CreateResource(wxXmlNode
* node
, wxObject
* parent
,
309 Called from CreateResource after variables
312 wxObject
* DoCreateResource();
317 Creates a animation from the filename specified in @e param.
319 wxAnimation
GetAnimation();
322 , @b wxSize@e size = wxDefaultSize)
326 wxBitmap
GetBitmap();
329 Gets a bool flag (1, t, yes, on, @true are @true, everything else is @false).
331 bool GetBool(const wxString
& param
, bool defaultv
= @
false);
334 Gets colour in HTML syntax (#RRGGBB).
336 wxColour
GetColour(const wxString
& param
,
337 const wxColour
& default = wxNullColour
);
340 Returns the current file system.
342 wxFileSystem
GetCurFileSystem();
345 Gets a dimension (may be in dialog units).
347 wxCoord
GetDimension(const wxString
& param
, wxCoord defaultv
= 0);
359 #define int GetID() /* implementation is private */
362 , @b wxSize@e size = wxDefaultSize)
369 Gets the integer value from the parameter.
371 long GetLong(const wxString
& param
, long defaultv
= 0);
374 Returns the resource name.
379 Gets node content from wxXML_ENTITY_NODE.
381 wxString
GetNodeContent(wxXmlNode
* node
);
384 Finds the node or returns @NULL.
386 wxXmlNode
* GetParamNode(const wxString
& param
);
389 Finds the parameter value or returns the empty string.
391 wxString
GetParamValue(const wxString
& param
);
396 Gets the position (may be in dialog units).
398 wxPoint
GetPosition();
403 Gets the size (may be in dialog units).
408 , @b int@e defaults = 0)
410 Gets style flags from text in form "flag | flag2| flag3 |..."
411 Only understands flags added with AddStyle.
416 Gets text from param and does some conversions:
418 replaces \n, \r, \t by respective characters (according to C syntax)
419 replaces @c $ by @c and @c $$ by @c $ (needed for @c _File to @c File
420 translation because of XML syntax)
421 calls wxGetTranslations (unless disabled in wxXmlResource)
423 wxString
GetText(const wxString
& param
);
426 Check to see if a parameter exists.
428 bool HasParam(const wxString
& param
);
431 Convenience function. Returns @true if the node has a property class equal to
433 e.g. object class="wxDialog".
435 bool IsOfClass(wxXmlNode
* node
, const wxString
& classname
);
438 Sets the parent resource.
440 void SetParentResource(wxXmlResource
* res
);
443 Sets common window options.
445 void SetupWindow(wxWindow
* wnd
);