]>
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 @see @ref overview_xrc, @ref xrc_format
39 class wxXmlResource
: public wxObject
47 The XRC file, archive file, or wildcard specification that will be
48 used to load all resource files inside a zip archive.
50 One or more value of the ::wxXmlResourceFlags enumeration.
52 The name of the gettext catalog to search for translatable strings.
53 By default all loaded catalogs will be searched.
54 This provides a way to allow the strings to only come from a specific catalog.
56 wxXmlResource(const wxString
& filemask
,
57 int flags
= wxXRC_USE_LOCALE
,
58 const wxString domain
= wxEmptyString
);
59 wxXmlResource(int flags
= wxXRC_USE_LOCALE
,
60 const wxString domain
= wxEmptyString
);
66 virtual ~wxXmlResource();
69 Initializes only a specific handler (or custom handler).
70 Convention says that the handler name is equal to the control's name plus
71 'XmlHandler', for example wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler.
73 The XML resource compiler (wxxrc) can create include file that contains
74 initialization code for all controls used within the resource.
75 Note that this handler must be allocated on the heap, since it will be
76 deleted by ClearHandlers() later.
78 void AddHandler(wxXmlResourceHandler
* handler
);
81 Attaches an unknown control to the given panel/window/dialog.
82 Unknown controls are used in conjunction with \<object class="unknown"\>.
84 bool AttachUnknownControl(const wxString
& name
,
86 wxWindow
* parent
= NULL
);
89 Removes all handlers and deletes them (this means that any handlers
90 added using AddHandler() must be allocated on the heap).
95 Compares the XRC version to the argument.
97 Returns -1 if the XRC version is less than the argument,
98 +1 if greater, and 0 if they are equal.
100 int CompareVersion(int major
, int minor
, int release
, int revision
) const;
103 Gets the global resources object or creates one if none exists.
105 static wxXmlResource
* Get();
108 Returns the domain (message catalog) that will be used to load
109 translatable strings in the XRC.
111 const wxString
& GetDomain() const;
114 Returns flags, which may be a bitlist of ::wxXmlResourceFlags
117 int GetFlags() const;
120 Returns version information (a.b.c.d = d + 256*c + 2562*b + 2563*a).
122 long GetVersion() const;
125 Returns a numeric ID that is equivalent to the string ID used in an XML resource.
127 If an unknown @a str_id is requested (i.e. other than wxID_XXX or integer),
128 a new record is created which associates the given string with a number.
130 If @a value_if_not_found is @c wxID_NONE, the number is obtained via
131 wxNewId(). Otherwise @a value_if_not_found is used.
132 Macro @c XRCID(name) is provided for convenient use in event tables.
134 static int GetXRCID(const wxString
& str_id
, int value_if_not_found
= wxID_NONE
);
137 Initializes handlers for all supported controls/windows.
139 This will make the executable quite big because it forces linking against
140 most of the wxWidgets library.
142 void InitAllHandlers();
145 Loads resources from XML files that match given filemask.
146 This method understands VFS (see filesys.h).
148 bool Load(const wxString
& filemask
);
151 Loads a bitmap resource from a file.
153 wxBitmap
LoadBitmap(const wxString
& name
);
156 Loads a dialog. @a parent points to parent window (if any).
158 wxDialog
* LoadDialog(wxWindow
* parent
, const wxString
& name
);
161 Loads a dialog. @a parent points to parent window (if any).
163 This form is used to finish creation of an already existing instance (the main
164 reason for this is that you may want to use derived class with a new event table).
169 wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
173 bool LoadDialog(wxDialog
* dlg
, wxWindow
* parent
, const wxString
& name
);
178 bool LoadFrame(wxFrame
* frame
, wxWindow
* parent
,
179 const wxString
& name
);
182 Loads an icon resource from a file.
184 wxIcon
LoadIcon(const wxString
& name
);
187 Loads menu from resource. Returns @NULL on failure.
189 wxMenu
* LoadMenu(const wxString
& name
);
193 Loads a menubar from resource. Returns @NULL on failure.
195 wxMenuBar
* LoadMenuBar(wxWindow
* parent
, const wxString
& name
);
196 wxMenuBar
* LoadMenuBar(const wxString
& name
);
201 Load an object from the resource specifying both the resource name and the
204 The first overload lets you load nonstandard container windows and returns
205 @NULL on failure. The second one lets you finish the creation of an existing
206 instance and returns @false on failure.
208 wxObject
* LoadObject(wxWindow
* parent
, const wxString
& name
,
209 const wxString
& classname
);
210 bool LoadObject(wxObject
* instance
, wxWindow
* parent
,
211 const wxString
& name
,
212 const wxString
& classname
);
216 Loads a panel. @a panel points to parent window (if any).
218 wxPanel
* LoadPanel(wxWindow
* parent
, const wxString
& name
);
221 Loads a panel. @a panel points to parent window (if any).
222 This form is used to finish creation of an already existing instance.
224 bool LoadPanel(wxPanel
* panel
, wxWindow
* parent
, const wxString
& name
);
229 wxToolBar
* LoadToolBar(wxWindow
* parent
, const wxString
& name
);
232 Sets the global resources object and returns a pointer to the previous one
235 static wxXmlResource
* Set(wxXmlResource
* res
);
238 Sets the domain (message catalog) that will be used to load
239 translatable strings in the XRC.
241 void SetDomain(const wxString
& domain
);
244 Sets flags (bitlist of ::wxXmlResourceFlags enumeration values).
246 void SetFlags(int flags
);
249 This function unloads a resource previously loaded by Load().
251 Returns @true if the resource was successfully unloaded and @false if it
252 hasn't been found in the list of loaded resources.
254 bool Unload(const wxString
& filename
);
260 @class wxXmlResourceHandler
262 wxXmlResourceHandler is an abstract base class for resource handlers
263 capable of creating a control from an XML node.
265 See @ref overview_xrc for details.
270 class wxXmlResourceHandler
: public wxObject
276 wxXmlResourceHandler();
281 virtual ~wxXmlResourceHandler();
284 Creates an object (menu, dialog, control, ...) from an XML node.
285 Should check for validity. @a parent is a higher-level object
286 (usually window, dialog or panel) that is often necessary to
289 If @b instance is non-@NULL it should not create a new instance via
290 'new' but should rather use this one, and call its Create method.
292 wxObject
* CreateResource(wxXmlNode
* node
, wxObject
* parent
,
296 Called from CreateResource after variables were filled.
298 virtual wxObject
* DoCreateResource() = 0;
301 Returns @true if it understands this node and can create
302 a resource from it, @false otherwise.
305 You must not call any wxXmlResourceHandler methods except IsOfClass()
306 from this method! The instance is not yet initialized with node data
307 at the time CanHandle() is called and it is only safe to operate on
308 node directly or to call IsOfClass().
310 virtual bool CanHandle(wxXmlNode
* node
) = 0;
313 Sets the parent resource.
315 void SetParentResource(wxXmlResource
* res
);
321 Add a style flag (e.g. @c wxMB_DOCKABLE) to the list of flags
322 understood by this handler.
324 void AddStyle(const wxString
& name
, int value
);
327 Add styles common to all wxWindow-derived classes.
329 void AddWindowStyles();
334 void CreateChildren(wxObject
* parent
, bool this_hnd_only
= false);
339 void CreateChildrenPrivately(wxObject
* parent
,
340 wxXmlNode
* rootnode
= NULL
);
343 Creates a resource from a node.
345 wxObject
* CreateResFromNode(wxXmlNode
* node
, wxObject
* parent
,
346 wxObject
* instance
= NULL
);
349 Creates an animation (see wxAnimation) from the filename specified in @a param.
351 wxAnimation
GetAnimation(const wxString
& param
= wxT("animation"));
356 wxBitmap
GetBitmap(const wxString
& param
= "bitmap",
357 const wxArtClient
& defaultArtClient
= wxART_OTHER
,
358 wxSize size
= wxDefaultSize
);
361 Gets a bool flag (1, t, yes, on, true are @true, everything else is @false).
363 bool GetBool(const wxString
& param
, bool defaultv
= false);
366 Gets colour in HTML syntax (\#RRGGBB).
368 wxColour
GetColour(const wxString
& param
,
369 const wxColour
& defaultColour
= wxNullColour
);
372 Returns the current file system.
374 wxFileSystem
& GetCurFileSystem();
377 Gets a dimension (may be in dialog units).
379 wxCoord
GetDimension(const wxString
& param
, wxCoord defaultv
= 0,
380 wxWindow
* windowToUse
= 0);
385 wxFont
GetFont(const wxString
& param
= "font");
395 wxIcon
GetIcon(const wxString
& param
= "icon",
396 const wxArtClient
& defaultArtClient
= wxART_OTHER
,
397 wxSize size
= wxDefaultSize
);
400 Gets the integer value from the parameter.
402 long GetLong(const wxString
& param
, long defaultv
= 0);
405 Returns the resource name.
410 Gets node content from wxXML_ENTITY_NODE.
412 wxString
GetNodeContent(wxXmlNode
* node
);
415 Finds the node or returns @NULL.
417 wxXmlNode
* GetParamNode(const wxString
& param
);
420 Finds the parameter value or returns the empty string.
422 wxString
GetParamValue(const wxString
& param
);
425 Gets the position (may be in dialog units).
427 wxPoint
GetPosition(const wxString
& param
= wxT("pos"));
430 Gets the size (may be in dialog units).
432 wxSize
GetSize(const wxString
& param
= "size", wxWindow
* windowToUse
= 0);
435 Gets style flags from text in form "flag | flag2| flag3 |..."
436 Only understands flags added with AddStyle().
438 int GetStyle(const wxString
& param
= wxT("style"), int defaults
= 0);
441 Gets text from param and does some conversions:
442 - replaces \\n, \\r, \\t by respective characters (according to C syntax)
443 - replaces @c $ by @c and @c $$ by @c $ (needed for @c _File to @c File
444 translation because of XML syntax)
445 - calls wxGetTranslations (unless disabled in wxXmlResource)
447 wxString
GetText(const wxString
& param
, bool translate
= true);
450 Check to see if a parameter exists.
452 bool HasParam(const wxString
& param
);
455 Convenience function.
456 Returns @true if the node has a property class equal to classname,
457 e.g. object class="wxDialog".
459 bool IsOfClass(wxXmlNode
* node
, const wxString
& classname
);
462 Sets common window options.
464 void SetupWindow(wxWindow
* wnd
);