]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/xrc/xmlres.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxXmlResource
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 This is the main class for interacting with the XML-based resource system.
14 The class holds XML resources from one or more .xml files, binary files or zip
17 See @ref overview_xrcoverview "XML-based resource system overview" for details.
22 class wxXmlResource
: public wxObject
30 wxXRC_USE_LOCALE: translatable strings will be translated via _().
31 wxXRC_NO_SUBCLASSING: subclass property of object nodes will be ignored
32 (useful for previews in XRC editors). wxXRC_NO_RELOADING will prevent the
33 XRC files from being reloaded from disk in case they have been modified
35 since being last loaded (may slightly speed up loading them).
37 The name of the gettext catalog to search for
38 translatable strings. By default all loaded catalogs will be
39 searched. This provides a way to allow the strings to only come
40 from a specific catalog.
42 wxXmlResource(const wxString
& filemask
,
43 int flags
= wxXRC_USE_LOCALE
,
44 const wxString domain
= wxEmptyString
);
45 wxXmlResource(int flags
= wxXRC_USE_LOCALE
,
46 const wxString domain
= wxEmptyString
);
55 Initializes only a specific handler (or custom handler). Convention says
56 that the handler name is equal to the control's name plus 'XmlHandler', for
58 wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. The XML resource compiler
59 (wxxrc) can create include file that contains initialization code for
60 all controls used within the resource. Note that this handler should be
61 allocated on the heap, since it will be delete by
62 ClearHandlers() later.
64 void AddHandler(wxXmlResourceHandler
* handler
);
67 Attaches an unknown control to the given panel/window/dialog.
68 Unknown controls are used in conjunction with object class="unknown".
70 bool AttachUnknownControl(const wxString
& name
,
72 wxWindow
* parent
= NULL
);
75 Removes all handlers and deletes them (this means that any handlers added using
76 AddHandler() must be allocated on the heap).
81 Compares the XRC version to the argument. Returns -1 if the XRC version
82 is less than the argument, +1 if greater, and 0 if they equal.
84 int CompareVersion(int major
, int minor
, int release
,
88 Gets the global resources object or creates one if none exists.
93 Returns the domain (message catalog) that will be used to load
94 translatable strings in the XRC.
99 Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and
100 wxXRC_NO_SUBCLASSING.
105 Returns version information (a.b.c.d = d+ 256*c + 256@c 2*b + 256@c 3*a).
107 long GetVersion() const;
110 Returns a numeric ID that is equivalent to the string ID used in an XML
111 resource. If an unknown @a str_id is requested (i.e. other than wxID_XXX
112 or integer), a new record is created which associates the given string with
113 a number. If @a value_if_not_found is @c wxID_NONE, the number is obtained via
114 wxNewId(). Otherwise @a value_if_not_found is used.
115 Macro @c XRCID(name) is provided for convenient use in event tables.
117 #define int GetXRCID(const wxString& str_id, int value_if_not_found = -2) /* implementation is private */
120 Initializes handlers for all supported controls/windows. This will
121 make the executable quite big because it forces linking against
122 most of the wxWidgets library.
124 void InitAllHandlers();
127 Loads resources from XML files that match given filemask.
128 This method understands VFS (see filesys.h).
130 bool Load(const wxString
& filemask
);
133 Loads a bitmap resource from a file.
135 wxBitmap
LoadBitmap(const wxString
& name
);
139 Loads a dialog. @a dlg points to parent window (if any).
140 This form is used to finish creation of an already existing instance (the main
142 for this is that you may want to use derived class with a new event table).
145 wxDialog
* LoadDialog(wxWindow
* parent
, const wxString
& name
);
146 bool LoadDialog(wxDialog
* dlg
, wxWindow
* parent
,
147 const wxString
& name
);
153 bool LoadFrame(wxFrame
* frame
, wxWindow
* parent
,
154 const wxString
& name
);
157 Loads an icon resource from a file.
159 wxIcon
LoadIcon(const wxString
& name
);
162 Loads menu from resource. Returns @NULL on failure.
164 wxMenu
* LoadMenu(const wxString
& name
);
168 Loads a menubar from resource. Returns @NULL on failure.
170 wxMenuBar
* LoadMenuBar(wxWindow
* parent
, const wxString
& name
);
171 wxMenuBar
* LoadMenuBar(const wxString
& name
);
176 Load an object from the resource specifying both the resource name and the
178 The first overload lets you load nonstandard container windows and returns @c
180 on failure. The second one lets you finish the creation of an existing
181 instance and returns @false on failure.
183 wxObject
* LoadObject(wxWindow
* parent
, const wxString
& name
,
184 const wxString
& classname
);
185 bool LoadObject(wxObject
* instance
, wxWindow
* parent
,
186 const wxString
& name
,
187 const wxString
& classname
);
192 Loads a panel. @a panel points to parent window (if any). This form
193 is used to finish creation of an already existing instance.
195 wxPanel
* LoadPanel(wxWindow
* parent
, const wxString
& name
);
196 bool LoadPanel(wxPanel
* panel
, wxWindow
* parent
,
197 const wxString
& name
);
203 wxToolBar
* LoadToolBar(wxWindow
* parent
, const wxString
& name
);
206 Sets the global resources object and returns a pointer to the previous one (may
209 wxXmlResource
* Set(wxXmlResource
* res
);
212 Sets the domain (message catalog) that will be used to load
213 translatable strings in the XRC.
215 wxChar
* SetDomain(const wxChar
* domain
);
218 Sets flags (bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING).
220 void SetFlags(int flags
);
223 This function unloads a resource previously loaded by
225 Returns @true if the resource was successfully unloaded and @false if it
227 been found in the list of loaded resources.
229 bool Unload(const wxString
& filename
);
235 @class wxXmlResourceHandler
237 wxXmlResourceHandler is an abstract base class for resource handlers
238 capable of creating a control from an XML node.
240 See @ref overview_xrcoverview "XML-based resource system overview" for details.
245 class wxXmlResourceHandler
: public wxObject
251 wxXmlResourceHandler();
256 ~wxXmlResourceHandler();
259 Add a style flag (e.g. wxMB_DOCKABLE) to the list of flags
260 understood by this handler.
262 void AddStyle(const wxString
& name
, int value
);
265 Add styles common to all wxWindow-derived classes.
267 void AddWindowStyles();
270 Returns @true if it understands this node and can create
271 a resource from it, @false otherwise.
273 bool CanHandle(wxXmlNode
* node
);
278 void CreateChildren(wxObject
* parent
, bool this_hnd_only
= false);
283 void CreateChildrenPrivately(wxObject
* parent
,
284 wxXmlNode
* rootnode
= NULL
);
287 Creates a resource from a node.
289 wxObject
* CreateResFromNode(wxXmlNode
* node
, wxObject
* parent
,
290 wxObject
* instance
= NULL
);
293 Creates an object (menu, dialog, control, ...) from an XML node.
294 Should check for validity. @a parent is a higher-level object (usually window,
296 that is often necessary to create the resource.
297 If @b instance is non-@NULL it should not create a new instance via 'new' but
298 should rather use this one, and call its Create method.
300 wxObject
* CreateResource(wxXmlNode
* node
, wxObject
* parent
,
304 Called from CreateResource after variables
307 wxObject
* DoCreateResource();
311 Creates a animation() from the filename specified in @e param.
313 wxAnimation
GetAnimation();
316 , @b wxSize@e size = wxDefaultSize)
319 wxBitmap
GetBitmap();
322 Gets a bool flag (1, t, yes, on, @true are @true, everything else is @false).
324 bool GetBool(const wxString
& param
, bool defaultv
= false);
327 Gets colour in HTML syntax (#RRGGBB).
329 wxColour
GetColour(const wxString
& param
,
330 const wxColour
& default = wxNullColour
);
333 Returns the current file system.
335 wxFileSystem
GetCurFileSystem();
338 Gets a dimension (may be in dialog units).
340 wxCoord
GetDimension(const wxString
& param
, wxCoord defaultv
= 0);
354 , @b wxSize@e size = wxDefaultSize)
360 Gets the integer value from the parameter.
362 long GetLong(const wxString
& param
, long defaultv
= 0);
365 Returns the resource name.
370 Gets node content from wxXML_ENTITY_NODE.
372 wxString
GetNodeContent(wxXmlNode
* node
);
375 Finds the node or returns @NULL.
377 wxXmlNode
* GetParamNode(const wxString
& param
);
380 Finds the parameter value or returns the empty string.
382 wxString
GetParamValue(const wxString
& param
);
386 Gets the position (may be in dialog units).
388 wxPoint
GetPosition();
392 Gets the size (may be in dialog units).
397 , @b int@e defaults = 0)
398 Gets style flags from text in form "flag | flag2| flag3 |..."
399 Only understands flags added with AddStyle.
404 Gets text from param and does some conversions:
405 replaces \n, \r, \t by respective characters (according to C syntax)
406 replaces @c $ by @c and @c $$ by @c $ (needed for @c _File to @c File
407 translation because of XML syntax)
408 calls wxGetTranslations (unless disabled in wxXmlResource)
410 wxString
GetText(const wxString
& param
);
413 Check to see if a parameter exists.
415 bool HasParam(const wxString
& param
);
418 Convenience function. Returns @true if the node has a property class equal to
420 e.g. object class="wxDialog".
422 bool IsOfClass(wxXmlNode
* node
, const wxString
& classname
);
425 Sets the parent resource.
427 void SetParentResource(wxXmlResource
* res
);
430 Sets common window options.
432 void SetupWindow(wxWindow
* wnd
);