]>
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 /////////////////////////////////////////////////////////////////////////////
10 Flags which can be used with wxXmlResource::wxXmlResource.
12 enum wxXmlResourceFlags
14 /** Translatable strings will be translated via _(). */
17 /** Subclass property of object nodes will be ignored (useful for previews in XRC editors). */
18 wxXRC_NO_SUBCLASSING
= 2,
20 /** Prevent the XRC files from being reloaded from disk in case they have been modified there
21 since being last loaded (may slightly speed up loading them). */
22 wxXRC_NO_RELOADING
= 4
29 This is the main class for interacting with the XML-based resource system.
31 The class holds XML resources from one or more .xml files, binary files or zip
34 Note that this is a singleton class and you'll never allocate/deallocate it.
35 Just use the static wxXmlResource::Get() getter.
37 @see @ref overview_xrc, @ref overview_xrcformat
42 class wxXmlResource
: public wxObject
49 The XRC file, archive file, or wildcard specification that will be
50 used to load all resource files inside a zip archive.
52 One or more value of the ::wxXmlResourceFlags enumeration.
54 The name of the gettext catalog to search for translatable strings.
55 By default all loaded catalogs will be searched.
56 This provides a way to allow the strings to only come from a specific catalog.
58 wxXmlResource(const wxString
& filemask
,
59 int flags
= wxXRC_USE_LOCALE
,
60 const wxString
& domain
= wxEmptyString
);
66 One or more value of the ::wxXmlResourceFlags enumeration.
68 The name of the gettext catalog to search for translatable strings.
69 By default all loaded catalogs will be searched.
70 This provides a way to allow the strings to only come from a specific catalog.
72 wxXmlResource(int flags
= wxXRC_USE_LOCALE
,
73 const wxString
& domain
= wxEmptyString
);
78 virtual ~wxXmlResource();
81 Initializes only a specific handler (or custom handler).
82 Convention says that the handler name is equal to the control's name plus
83 'XmlHandler', for example wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler.
85 The XML resource compiler (wxxrc) can create include file that contains
86 initialization code for all controls used within the resource.
87 Note that this handler must be allocated on the heap, since it will be
88 deleted by ClearHandlers() later.
90 void AddHandler(wxXmlResourceHandler
* handler
);
93 Attaches an unknown control to the given panel/window/dialog.
94 Unknown controls are used in conjunction with \<object class="unknown"\>.
96 bool AttachUnknownControl(const wxString
& name
,
98 wxWindow
* parent
= NULL
);
101 Removes all handlers and deletes them (this means that any handlers
102 added using AddHandler() must be allocated on the heap).
104 void ClearHandlers();
107 Compares the XRC version to the argument.
109 Returns -1 if the XRC version is less than the argument,
110 +1 if greater, and 0 if they are equal.
112 int CompareVersion(int major
, int minor
, int release
, int revision
) const;
115 Returns a string ID corresponding to the given numeric ID.
117 The string returned is such that calling GetXRCID() with it as
118 parameter yields @a numId. If there is no string identifier
119 corresponding to the given numeric one, an empty string is returned.
121 Notice that, unlike GetXRCID(), this function is slow as it checks all
122 of the identifiers used in XRC.
126 static wxString
FindXRCIDById(int numId
);
129 Gets the global resources object or creates one if none exists.
131 static wxXmlResource
* Get();
134 Returns the domain (message catalog) that will be used to load
135 translatable strings in the XRC.
137 const wxString
& GetDomain() const;
140 Returns flags, which may be a bitlist of ::wxXmlResourceFlags
143 int GetFlags() const;
146 Returns version information (a.b.c.d = d + 256*c + 2562*b + 2563*a).
148 long GetVersion() const;
151 Returns a numeric ID that is equivalent to the string ID used in an XML resource.
153 If an unknown @a str_id is requested (i.e. other than wxID_XXX or integer),
154 a new record is created which associates the given string with a number.
156 If @a value_if_not_found is @c wxID_NONE, the number is obtained via
157 wxNewId(). Otherwise @a value_if_not_found is used.
158 Macro @c XRCID(name) is provided for convenient use in event tables.
160 static int GetXRCID(const wxString
& str_id
, int value_if_not_found
= wxID_NONE
);
163 Initializes handlers for all supported controls/windows.
165 This will make the executable quite big because it forces linking against
166 most of the wxWidgets library.
168 void InitAllHandlers();
171 Loads resources from XML files that match given filemask.
175 if (!wxXmlResource::Get()->Load("rc/*.xrc"))
176 wxLogError("Couldn't load resources!");
179 This method understands VFS (see wxFileSystem::FindFirst).
181 bool Load(const wxString
& filemask
);
184 Loads a bitmap resource from a file.
186 wxBitmap
LoadBitmap(const wxString
& name
);
189 Loads a dialog. @a parent points to parent window (if any).
191 wxDialog
* LoadDialog(wxWindow
* parent
, const wxString
& name
);
194 Loads a dialog. @a parent points to parent window (if any).
196 This form is used to finish creation of an already existing instance (the main
197 reason for this is that you may want to use derived class with a new event table).
202 wxXmlResource::Get()->LoadDialog(&dlg, mainFrame, "my_dialog");
206 bool LoadDialog(wxDialog
* dlg
, wxWindow
* parent
, const wxString
& name
);
211 bool LoadFrame(wxFrame
* frame
, wxWindow
* parent
,
212 const wxString
& name
);
215 Loads an icon resource from a file.
217 wxIcon
LoadIcon(const wxString
& name
);
220 Loads menu from resource. Returns @NULL on failure.
222 wxMenu
* LoadMenu(const wxString
& name
);
226 Loads a menubar from resource. Returns @NULL on failure.
228 wxMenuBar
* LoadMenuBar(wxWindow
* parent
, const wxString
& name
);
229 wxMenuBar
* LoadMenuBar(const wxString
& name
);
234 Load an object from the resource specifying both the resource name and the
237 The first overload lets you load nonstandard container windows and returns
238 @NULL on failure. The second one lets you finish the creation of an existing
239 instance and returns @false on failure.
241 wxObject
* LoadObject(wxWindow
* parent
, const wxString
& name
,
242 const wxString
& classname
);
243 bool LoadObject(wxObject
* instance
, wxWindow
* parent
,
244 const wxString
& name
,
245 const wxString
& classname
);
249 Loads a panel. @a panel points to parent window (if any).
251 wxPanel
* LoadPanel(wxWindow
* parent
, const wxString
& name
);
254 Loads a panel. @a panel points to parent window (if any).
255 This form is used to finish creation of an already existing instance.
257 bool LoadPanel(wxPanel
* panel
, wxWindow
* parent
, const wxString
& name
);
262 wxToolBar
* LoadToolBar(wxWindow
* parent
, const wxString
& name
);
265 Sets the global resources object and returns a pointer to the previous one
268 static wxXmlResource
* Set(wxXmlResource
* res
);
271 Sets the domain (message catalog) that will be used to load
272 translatable strings in the XRC.
274 void SetDomain(const wxString
& domain
);
277 Sets flags (bitlist of ::wxXmlResourceFlags enumeration values).
279 void SetFlags(int flags
);
282 This function unloads a resource previously loaded by Load().
284 Returns @true if the resource was successfully unloaded and @false if it
285 hasn't been found in the list of loaded resources.
287 bool Unload(const wxString
& filename
);
293 @class wxXmlResourceHandler
295 wxXmlResourceHandler is an abstract base class for resource handlers
296 capable of creating a control from an XML node.
298 See @ref overview_xrc for details.
303 class wxXmlResourceHandler
: public wxObject
309 wxXmlResourceHandler();
314 virtual ~wxXmlResourceHandler();
317 Creates an object (menu, dialog, control, ...) from an XML node.
318 Should check for validity. @a parent is a higher-level object
319 (usually window, dialog or panel) that is often necessary to
322 If @b instance is non-@NULL it should not create a new instance via
323 'new' but should rather use this one, and call its Create method.
325 wxObject
* CreateResource(wxXmlNode
* node
, wxObject
* parent
,
329 Called from CreateResource after variables were filled.
331 virtual wxObject
* DoCreateResource() = 0;
334 Returns @true if it understands this node and can create
335 a resource from it, @false otherwise.
338 You must not call any wxXmlResourceHandler methods except IsOfClass()
339 from this method! The instance is not yet initialized with node data
340 at the time CanHandle() is called and it is only safe to operate on
341 node directly or to call IsOfClass().
343 virtual bool CanHandle(wxXmlNode
* node
) = 0;
346 Sets the parent resource.
348 void SetParentResource(wxXmlResource
* res
);
354 Add a style flag (e.g. @c wxMB_DOCKABLE) to the list of flags
355 understood by this handler.
357 void AddStyle(const wxString
& name
, int value
);
360 Add styles common to all wxWindow-derived classes.
362 void AddWindowStyles();
367 void CreateChildren(wxObject
* parent
, bool this_hnd_only
= false);
372 void CreateChildrenPrivately(wxObject
* parent
,
373 wxXmlNode
* rootnode
= NULL
);
376 Creates a resource from a node.
378 wxObject
* CreateResFromNode(wxXmlNode
* node
, wxObject
* parent
,
379 wxObject
* instance
= NULL
);
382 Creates an animation (see wxAnimation) from the filename specified in @a param.
384 wxAnimation
GetAnimation(const wxString
& param
= "animation");
389 wxBitmap
GetBitmap(const wxString
& param
= "bitmap",
390 const wxArtClient
& defaultArtClient
= wxART_OTHER
,
391 wxSize size
= wxDefaultSize
);
394 Gets a bool flag (1, t, yes, on, true are @true, everything else is @false).
396 bool GetBool(const wxString
& param
, bool defaultv
= false);
399 Gets colour in HTML syntax (\#RRGGBB).
401 wxColour
GetColour(const wxString
& param
,
402 const wxColour
& defaultColour
= wxNullColour
);
405 Returns the current file system.
407 wxFileSystem
& GetCurFileSystem();
410 Gets a dimension (may be in dialog units).
412 wxCoord
GetDimension(const wxString
& param
, wxCoord defaultv
= 0,
413 wxWindow
* windowToUse
= 0);
418 wxFont
GetFont(const wxString
& param
= "font");
428 wxIcon
GetIcon(const wxString
& param
= "icon",
429 const wxArtClient
& defaultArtClient
= wxART_OTHER
,
430 wxSize size
= wxDefaultSize
);
433 Gets the integer value from the parameter.
435 long GetLong(const wxString
& param
, long defaultv
= 0);
438 Returns the resource name.
443 Gets node content from wxXML_ENTITY_NODE.
445 wxString
GetNodeContent(wxXmlNode
* node
);
448 Finds the node or returns @NULL.
450 wxXmlNode
* GetParamNode(const wxString
& param
);
453 Finds the parameter value or returns the empty string.
455 wxString
GetParamValue(const wxString
& param
);
458 Gets the position (may be in dialog units).
460 wxPoint
GetPosition(const wxString
& param
= "pos");
463 Gets the size (may be in dialog units).
465 wxSize
GetSize(const wxString
& param
= "size", wxWindow
* windowToUse
= 0);
468 Gets style flags from text in form "flag | flag2| flag3 |..."
469 Only understands flags added with AddStyle().
471 int GetStyle(const wxString
& param
= "style", int defaults
= 0);
474 Gets text from param and does some conversions:
475 - replaces \\n, \\r, \\t by respective characters (according to C syntax)
476 - replaces @c $ by @c and @c $$ by @c $ (needed for @c _File to @c File
477 translation because of XML syntax)
478 - calls wxGetTranslations (unless disabled in wxXmlResource)
480 wxString
GetText(const wxString
& param
, bool translate
= true);
483 Check to see if a parameter exists.
485 bool HasParam(const wxString
& param
);
488 Convenience function.
489 Returns @true if the node has a property class equal to classname,
490 e.g. object class="wxDialog".
492 bool IsOfClass(wxXmlNode
* node
, const wxString
& classname
);
495 Sets common window options.
497 void SetupWindow(wxWindow
* wnd
);