]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/tech/tn0014.txt
changed exceptions handling to work under wxGTK
[wxWidgets.git] / docs / tech / tn0014.txt
... / ...
CommitLineData
1 XRC resources format specification
2 ==================================
3
4 !!!!! NOT YET FINISHED !!!!!
5
60. Introduction
7===============
8
9This note describes the file format used for storing XRC resources that are
10used by wxXmlResource class. It is probably only useful for those implementing
11dialog editors with XRC support.
12
13If you only want to use the resources, you can choose from a number of editors:
14 a) wxDesigner (http://www.roebling.de)
15 b) XRCed (wxPython/tools)
16 c) DialogBlocks (wxPython/tools)
17
18and others listed on the Resources section of the wxWidgets web
19site.
20
21The XRC format is based on XML 1.0 (please consult W3C's specification). There
22is no DTD available since it is not possible to fully describe the format with
23the limited expressive power of DTDs.
24
25
26Note: see also http://ldaptool.sourceforge.net/XRCGuide/XRCGuideSingle/
27
28
29
301. Terminology
31==============
32
33The usual XML terminology applies. In particular, we shall use the terms
34NODE, PROPERTY and VALUE in the XML sense:
35
36 <node property1="value1" property2="value2">...</node>
37
38The term ATTRIBUTE is specific to XRC and refers to a subnode
39of an <object> or <object_ref> node that is itself not <object> or <object_ref>.
40In the example below, <pos>, <label> and <style> are attributes, while neither
41<resource> nor either of <object>s is:
42
43 <?xml version="1.0" encoding="utf-8">
44 <resource xmlns="http://www.wxwidgets.org/wxxrc" version="2.5.3.0">
45 <object class="wxPanel">
46 <style>wxSUNKEN_BORDER</style> <!-- attr -->
47 <object class="wxStaticText">
48 <label>A label</label> <!-- attr -->
49 <pos>10,10</pos> <!-- attr -->
50 </object>
51 </object>
52 </resource>
53
54ATTRIBUTE VALUE is the content of all text elements within attribute tag. In the
55above example, "wxSUNKEN_BORDER", "A label" and "10,10" are attribute values.
56ATTRIBUTE TYPE defines what attribute values are valid for given attribute (you
57can think of it as attribute value syntax definition).
58
59
60
612. Elementary description
62=========================
63
64XRC resource file is a well-formed XML 1.0 document. All elements of XRC file
65are from the http://www.wxwidgets.org/wxxrc namespace.
66
67The root node of XRC document must be <resource>. The <resource> node has
68optional "version" property. Default version (in absence of the version
69property) is "0.0.0.0". The version consists of four integers separated by
70periods. Version of XRC format changes only if there was an incompatible
71change introduced (i.e. either the library cannot understand old resource
72files or older versions of the library wouldn't understand the new format).
73The first three integers are major, minor and release number of the wxWidgets
74release when the change was introduced, the last one is revision number and
75is 0 for the first incompatible change in given wxWidgets release, 1 for
76the second etc.
77
78Differences between versions are described within this document in paragraphs
79entitled "Version Note".
80
81The <resource> node contains namespace declaration, too:
82
83 <resource xmlns="http://www.wxwidgets.org/wxxrc" version="2.5.3.0">
84
85The <resource> node is only allowed to have <object> and <object_ref>
86subnodes, all of which must have the "name" property.
87
88The <object> node represents a single object (GUI element) and it usually maps
89directly to a wxWidgets class instance. It three properties: "name", "class"
90and "subclass". "class" must always be present, it tells XRC what wxWidgets
91object should be created in this place. The other two are optional. "name" is
92ID used to identify the object. It is the value passed to the XRCID() macro and
93is also used to construct wxWindow's id and name attributes and must be unique
94among all children of the nearest container object (wxDialog, wxFrame,
95wxPanel, wxNotebook) upside from the object in XML nodes hierarchy (two distinct
96containers may contain objects with same "name", though). "subclass" is
97optional name of class whose constructor will be called instead of the
98constructor for "class". Subclass must be available in the program that loads
99the resource, must be derived from "class" and must be registered within
100wxWidgets' RTTI system.
101
102Example:
103
104 <object name="MyList1" class="wxListCtrl" subclass="MyListCtrlClass">
105 ...
106 </object>
107
108<object> node may have arbitrary child nodes. What child nodes and their
109semantics are class-dependent and are defined later in this document. The user
110is allowed to register new object handlers within XRC and extend it to accept
111new <object> classes (and therefore different <object>'s child nodes).
112
113<object_ref> node is identical to <object>, except that it does _not_ have
114"class" property and has additional required property "ref". Its concept is
115similar to Unix symlinks: value of the "ref" property is equal to the value of
116"name" property of some existing node (called referred node) in the resources
117(not necessary top-level). Referred node's "class" property and all subnodes
118are copied in place of the referee <object_ref> node which is then processed as
119regular <object> node. If the <object_ref> node itself has child nodes, then
120these nodes _override_ any nodes from the referred node.
121
122Example:
123
124 <object name="foo" class="wxTextCtrl">
125 <value>hello</value>
126 <size>100,-1d</size>
127 </object>
128 <object_ref name="bar" ref="foo">
129 <value>bar</value> <!-- override! -->
130 </object_ref>
131
132is identical to:
133
134 <object name="foo" class="wxTextCtrl">
135 <value>hello</value>
136 <size>100,-1d</size>
137 </object>
138 <object name="bar" class="wxTextCtrl">
139 <value>bar</value>
140 <size>100,-1d</size>
141 </object>
142
143
144
1453. Common attribute types
146=========================
147
148There are several attribute types (see section 1. Terminology) that are common
149to many attributes of different classes:
150
151String
152------
153Any text. Some characters have special interpretation and are translated
154by XRC parser according to this table:
155 "_" -> "&" ('&' is used to underline e.g. menu items in wxWidgets)
156 "__" -> "_"
157 "\n" -> line break (C character '\n')
158 "\r" -> carriage return (C character '\r')
159 "\t" -> tab (C character '\t')
160 "\\" -> "\"
161 (introduced in version 2.5.3.0, not done in earlier versions)
162
163Version Note:
164 '$' was used instead of '_' prior to version 2.3.0.1.
165
166
167I18nString
168----------
169Like String, but the value is translated to native language using wxLocale
170at runtime (unless it was disabled by not passing wxXRC_USE_LOCALE flag to
171wxXmlResource constructor). Used for strings that are "visible" in the GUI.
172
173
174UnsignedInteger
175---------------
176This is obvious. Only digits 0-9 may be present and there must be at least
177one digit.
178
179
180Integer
181-------
182Like UnsignedInteger but may be prefixed with '-' (ints less than zero).
183
184
185Position
186--------
187Specifies (window's) position in 2D space. Syntax is <integer>,<integer>[d]
188where <integer> is valid value of Integer type.
189
190
191Size
192----
193Syntax is same as Position's syntax, but the values are interpreted as window
194size (wxSize type) and not position (wxPosition type).
195
196
197Style[wxSomeClass]
198------------------
199List of style flags that can be passed to wxSomeClass' constructor. Flags are
200written in same way as in C++ code (e.g. "wxSUNKEN_BORDER",
201"wxHW_SCROLLBAR_NEVER") and are delimited with any combination of whitespaces
202and '|'. Possible flags are class-dependent and are not described in this
203technote. Please refer to wxWidgets manual for all styles that given class can
204accept; if XRC does not accept a flag listed in wxWidgets documentation, it is
205a bug.
206
207
208Bitmap
209------
210Attribute value is interpreted as filename (either absolute or relative to
211the location of XRC resource file). In addition, attribute node may have
212"stock_id" and "stock_client" properties. Their values may be any of wxArtID (or
213wxArtClient respectively) values as used by wxArtProvider (because the user may
214define own constants, effectively any string is legal here). Examples are
215"wxART_FILE_OPEN" (id) or "wxART_MENU" (client).
216
217Any of "stock_id" or "stock_client" properties or the filename may be omitted.
218XRC determines the bitmap to use according to this algorithm:
219 1. If there is non-empty "stock_id" property, query wxArtProvider for the
220 bitmap (if there is no "stock_client", use default one, which is usually
221 wxART_OTHER; exceptions are noted in class-specific sections below). If
222 the query fails, continue to 2.
223 2. Load the bitmap from the file in attribute value.
224
225
226Boolean
227-------
228Boolean value, either "0" (false) or "1" (true).
229
230
231Font
232----
233Font value. A font can be described either in terms of its elementary
234properties, or it can be derived from one of system fonts. The font node
235may contain following subnodes (the table lists subnode name on the left and
236variable type as per the definitions above on the right side):
237
238size UnsignedInteger
239style normal | italic | slant
240weight normal | bold | light
241family roman | script | decorative | swiss | modern | teletype
242underlined Boolean
243face comma-separated list of faces
244encoding charset of the font (meaningless in Unicode build), as string
245sysfont symbolic name of system standard font
246 (one of wxSYS_*_FONT constants)
247relativesize Float, font size relative to choosen system font's size;
248 can only be used when 'sysfont' is used and when 'size' is not
249 used
250
251All of them are optional, if they are missing, wxFont default is used.
252
253Examples:
254
255 <font>
256 <face>arial,helvetica</face>
257 <size>12</size>
258 </font>
259
260 <font>
261 <sysfont>wxSYS_DEFAULT_GUI_FONT</sysfont>
262 <weight>bold</weight>
263 <relativesize>1.5</relativesize>
264 </font>
265
266
267Colour
268------
269A colour value is either explicit RGB value in the standard #rrggbb format
270where rr, gg and bb are hexadecimal case-insensitive values in the 00..FF
271range, or a symbolic name. Symbolic names are wxSYS_COLOUR_* constants defined
272by wxWidgets, written as strings.
273
274Example:
275
276 <bg>wxSYS_COLOUR_SCROLLBAR</bg>
277 <fg>#FF0000</fg>
278
279
280
2814. Supported classes
282====================
283
284Attributes are listed in tables in the following format:
285attribute name attribute type default value, if any
286 [(optional remarks....................
287 ...................................)]
288
289wxBitmap
290--------
291This is a special case, because it does not create a wxWindow instance but
292creates wxBitmap instead. Another exceptional thing is that it does not have
293any attributes. Instead, the node itself is interpreted as if it were attribute
294of type Bitmap.
295
296Example: <object class="wxBitmap">bitmaps/foo.gif</object>
297
298
299wxIcon
300------
301Identical to wxBitmap class, except that it creates wxIcon instead of wxBitmap.
302
303
304wxButton
305--------
306pos Position -1,-1
307size Size -1,-1
308style Style[wxButton]
309
310label I18nString
311default Boolean false
312 (Is the button default button?)
313
314
315wxCalendarCtrl
316--------------
317pos Position -1,-1
318size Size -1,-1
319style Style[wxCalendarCtrl]
320
321
322wxCheckBox
323----------
324pos Position -1,-1
325size Size -1,-1
326style Style[wxCheckBox]
327checked Boolean false
328
329
330wxCheckList
331-----------
332pos Position -1,-1
333size Size -1,-1
334style Style[wxCheckList]
335content (see below) (empty)
336
337Optional "content" attribute does not have attribute value. Instead,
338arbitrary number of <item> nodes may be rooted under it (the control
339is filled with strings contained in these nodes). Each <item>
340node must contain I18nString value and may have "checked" property
341with possible values "0" or "1" indicating the the item is initially
342checked.
343
344Example:
345<object class="wxCheckList">
346 <content>
347 <item>One</item>
348 <item checked="1">Two</item>
349 <item checked="1">Three</item>
350 <item>Four</item>
351 </content>
352</object>
353
354
355wxDatePickerCtrl
356----------------
357pos Position -1,-1
358size Size -1,-1
359style Style[wxDatePickerCtrl]
360
361
362wxDialog
363--------
364pos Position -1,-1
365size Size -1,-1
366style Style[wxDialog] wxDEFAULT_DIALOG_STYLE
367title I18nString ""
368icon Bitmap (empty)
369centered Boolean false
370
371wxDialog may have children objects.
372
373
374wxFrame
375--------
376pos Position -1,-1
377size Size -1,-1
378style Style[wxDialog] wxDEFAULT_FRAME_STYLE
379title I18nString ""
380icon Bitmap (empty)
381centered Boolean false
382
383wxFrame may have children objects. There can be at most one wxToolBar,
384wxMenuBar and wxStatusBar children; objects of these types are automatically
385set as frame's tool-, menu- and statusbar respectively.
386
387
388wxMDIParentFrame
389----------------
390
391Supports same attributes and children nodes as wxFrame. Additionally, children
392may be of the wxMDIChildFrame type.
393
394
395wxMDIChildFrame
396---------------
397
398Supports same attributes and children nodes as wxFrame.
399
400
401wxScrolledWindow
402----------------
403pos Position -1,-1
404size Size -1,-1
405style Style[wxScrolledWindow] wxHSCROLL | wxVSCROLL
406
407wxScolledWindow may have children objects.
408
409
410wxSplitterWindow
411----------------
412pos Position -1,-1
413size Size -1,-1
414style Style[wxSplitterWindow] wxSP_3D
415sashpos Integer 0
416 (Initial sash position)
417minsize Integer -1
418 (Minimal panel size)
419orientation "horizontal"|"vertical" horizontal
420
421wxSplitterWindow must have at least one and at most two children objects.
422If there's only one child object, it is passed to wxSplitterWindow::Initialize
423and the splitter is created unsplit. If there are two children, the
424splitter is created split, either horizontally or vertically depending
425on the value of "orientation" attribute.
426
427
428wxStatusBar
429-----------
430fields Integer number of fields
431widths Width1, Width2, Width3, ...
432
433
434wxToolBar
435---------
436pos Position -1,-1
437size Size -1,-1
438style Style[wxToolBar] wxNO_BORDER|wxTB_HORIZONTAL
439bitmapsize Size -1,-1
440 (Size of contained bitmaps)
441margins Size -1,-1
442packing Integer -1
443separation Integer -1
444
445wxToolBar node may have children <object> and <object_ref> nodes. Their class
446may be either "tool", "separator" or any wxWidgets class derived from
447wxControl. "tool" and "separator" are special pseudo-classes that may only
448appear within wxToolBar node. Their attributes are as follows:
449
450 separator
451 ---------
452 (doesn't have any attributes)
453
454 tool
455 ----
456 bitmap Bitmap
457 bitmap2 Bitmap wxNullBitmap
458 toggle Boolean 0
459 radio Boolean 0
460 label I18nString ""
461 tooltip I18nString ""
462 longhelp I18nString ""
463 pos Position -1,-1
464
465 Constraints:
466 At most one of "toggle" and "radio" attributes may be 1.
467 Attribute "pos" may not appear if "label" or "radio" attributes
468 are used or if parent wxToolBar's style contains wxTB_TEXT.
469
470 Note:
471 Use of "pos" attribute is strongly discouraged, it is deprecated
472 usage of wxToolBar and it is not supported by MSW and GTK
473 implementations.
474
475Children objects are added to the toolbar using AddTool for "tool" class,
476AddSeparator for "separator" and AddControl for other classes.
477
478
479
4805. More features
481================
482
483FIXME -- "platform" property handling
484
485
486=== EOF ===
487
488Version: $Id$