]> git.saurik.com Git - wxWidgets.git/blame - docs/tech/tn0014.txt
Warning fixes for Cygwin
[wxWidgets.git] / docs / tech / tn0014.txt
CommitLineData
50ccbaaa
VS
1 XRC resources format specification
2 ==================================
3
4 !!!!! NOT YET FINISHED !!!!!
5
60. Introduction
2b5f62a0 7===============
50ccbaaa
VS
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)
5a7b6f80
JS
16 c) DialogBlocks (wxPython/tools)
17
18and others listed on the Resources section of the wxWidgets web
19site.
50ccbaaa
VS
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
2b5f62a0 25
b2ec1c82
VS
26Note: see also http://ldaptool.sourceforge.net/XRCGuide/XRCGuideSingle/
27
28
2b5f62a0 29
50ccbaaa 301. Terminology
2b5f62a0 31==============
50ccbaaa
VS
32
33The usual XML terminology applies. In particular, we shall use the terms
2b5f62a0 34NODE, PROPERTY and VALUE in the XML sense:
50ccbaaa
VS
35
36 <node property1="value1" property2="value2">...</node>
37
2b5f62a0
VZ
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>.
984c33c9 40In the example below, <pos>, <label> and <style> are attributes, while neither
2b5f62a0 41<resource> nor either of <object>s is:
50ccbaaa
VS
42
43 <?xml version="1.0" encoding="utf-8">
984c33c9 44 <resource xmlns="http://www.wxwidgets.org/wxxrc" version="2.5.3.0">
50ccbaaa 45 <object class="wxPanel">
2b5f62a0 46 <style>wxSUNKEN_BORDER</style> <!-- attr -->
50ccbaaa 47 <object class="wxStaticText">
2b5f62a0
VZ
48 <label>A label</label> <!-- attr -->
49 <pos>10,10</pos> <!-- attr -->
50ccbaaa
VS
50 </object>
51 </object>
52 </resource>
53
2b5f62a0
VZ
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
50ccbaaa 612. Elementary description
2b5f62a0 62=========================
50ccbaaa 63
432be5aa 64XRC resource file is a well-formed XML 1.0 document. All elements of XRC file
fc2171bd 65are from the http://www.wxwidgets.org/wxxrc namespace.
50ccbaaa
VS
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).
fc2171bd 73The first three integers are major, minor and release number of the wxWidgets
50ccbaaa 74release when the change was introduced, the last one is revision number and
fc2171bd 75is 0 for the first incompatible change in given wxWidgets release, 1 for
50ccbaaa
VS
76the second etc.
77
78Differences between versions are described within this document in paragraphs
2b5f62a0 79entitled "Version Note".
50ccbaaa 80
40e2d134
VS
81The <resource> node contains namespace declaration, too:
82
984c33c9 83 <resource xmlns="http://www.wxwidgets.org/wxxrc" version="2.5.3.0">
40e2d134 84
50ccbaaa
VS
85The <resource> node is only allowed to have <object> and <object_ref>
86subnodes, all of which must have the "name" property.
87
2b5f62a0 88The <object> node represents a single object (GUI element) and it usually maps
fc2171bd
JS
89directly to a wxWidgets class instance. It three properties: "name", "class"
90and "subclass". "class" must always be present, it tells XRC what wxWidgets
432be5aa
VS
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
dbd94b75
KH
94among all children of the nearest container object (wxDialog, wxFrame,
95wxPanel, wxNotebook) upside from the object in XML nodes hierarchy (two distinct
432be5aa
VS
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
fc2171bd 100wxWidgets' RTTI system.
2b5f62a0
VZ
101
102Example:
103
104 <object name="MyList1" class="wxListCtrl" subclass="MyListCtrlClass">
105 ...
106 </object>
107
432be5aa
VS
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
dbd94b75 114"class" property and has additional required property "ref". It's concept is
432be5aa
VS
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
dbd94b75 117(not necessary top-level). Referred node's "class" property and all subnodes
432be5aa
VS
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.
2b5f62a0
VZ
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! -->
0fa2e104 130 </object_ref>
2b5f62a0
VZ
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:
fc2171bd 155 "_" -> "&" ('&' is used to underline e.g. menu items in wxWidgets)
2b5f62a0
VZ
156 "__" -> "_"
157 "\n" -> line break (C character '\n')
158 "\r" -> carriage return (C character '\r')
dbd94b75 159 "\t" -> tab (C character '\t')
984c33c9
VS
160 "\\" -> "\"
161 (introduced in version 2.5.3.0, not done in earlier versions)
2b5f62a0
VZ
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
50ccbaaa 190
2b5f62a0
VZ
191Size
192----
193Syntax is same as Position's syntax, but the values are interpreted as window
194size (wxSize type) and not position (wxPosition type).
50ccbaaa
VS
195
196
2b5f62a0
VZ
197Style[wxSomeClass]
198------------------
199List of style flags that can be passed to wxSomeClass' constructor. Flags are
432be5aa 200written in same way as in C++ code (e.g. "wxSUNKEN_BORDER",
dbd94b75 201"wxHW_SCROLLBAR_NEVER") and are delimited with any combination of whitespaces
432be5aa 202and '|'. Possible flags are class-dependent and are not described in this
fc2171bd
JS
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
432be5aa 205a bug.
2b5f62a0
VZ
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
dbd94b75 214define own constants, effectively any string is legal here). Examples are
2b5f62a0
VZ
215"wxART_FILE_OPEN" (id) or "wxART_MENU" (client).
216
432be5aa
VS
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
984c33c9 221 wxART_OTHER; exceptions are noted in class-specific sections below). If
432be5aa 222 the query fails, continue to 2.
2b5f62a0
VZ
223 2. Load the bitmap from the file in attribute value.
224
225
226Boolean
227-------
228Boolean value, either "0" (false) or "1" (true).
229
50ccbaaa 230
1df61962
VS
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
50ccbaaa
VS
280
2814. Supported classes
2b5f62a0
VZ
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--------
9c0a4cb4 306pos Position -1,-1
2b5f62a0
VZ
307size Size -1,-1
308style Style[wxButton]
309
310label I18nString
311default Boolean false
312 (Is the button default button?)
313
314
315wxCalendarCtrl
316--------------
9c0a4cb4 317pos Position -1,-1
2b5f62a0
VZ
318size Size -1,-1
319style Style[wxCalendarCtrl]
320
321
322wxCheckBox
323----------
9c0a4cb4 324pos Position -1,-1
2b5f62a0
VZ
325size Size -1,-1
326style Style[wxCheckBox]
327checked Boolean false
328
329
330wxCheckList
331-----------
9c0a4cb4 332pos Position -1,-1
2b5f62a0
VZ
333size Size -1,-1
334style Style[wxCheckList]
984c33c9 335content (see below) (empty)
2b5f62a0
VZ
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
310e47b3
VS
355wxDatePickerCtrl
356----------------
357pos Position -1,-1
358size Size -1,-1
359style Style[wxDatePickerCtrl]
360
361
8b34993d
VS
362wxDialog
363--------
9c0a4cb4 364pos Position -1,-1
8b34993d
VS
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--------
9c0a4cb4 376pos Position -1,-1
8b34993d
VS
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
5a0348c4
VS
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
2b5f62a0
VZ
401wxScrolledWindow
402----------------
9c0a4cb4 403pos Position -1,-1
2b5f62a0
VZ
404size Size -1,-1
405style Style[wxScrolledWindow] wxHSCROLL | wxVSCROLL
406
8b34993d
VS
407wxScolledWindow may have children objects.
408
2b5f62a0 409
2f5b93fb
VS
410wxSplitterWindow
411----------------
9c0a4cb4 412pos Position -1,-1
2f5b93fb
VS
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
dbd94b75
KH
423and the splitter is created unsplit. If there are two children, the
424splitter is created split, either horizontally or vertically depending
2f5b93fb
VS
425on the value of "orientation" attribute.
426
8b34993d 427
b0fb0f3c
JS
428wxStatusBar
429-----------
430fields Integer number of fields
431widths Width1, Width2, Width3, ...
2f5b93fb 432
8b34993d 433
432be5aa
VS
434wxToolBar
435---------
9c0a4cb4 436pos Position -1,-1
432be5aa
VS
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
fc2171bd 446may be either "tool", "separator" or any wxWidgets class derived from
432be5aa
VS
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 ""
9c0a4cb4 463 pos Position -1,-1
432be5aa
VS
464
465 Constraints:
466 At most one of "toggle" and "radio" attributes may be 1.
9c0a4cb4 467 Attribute "pos" may not appear if "label" or "radio" attributes
432be5aa
VS
468 are used or if parent wxToolBar's style contains wxTB_TEXT.
469
470 Note:
9c0a4cb4 471 Use of "pos" attribute is strongly discouraged, it is deprecated
432be5aa
VS
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
2b5f62a0
VZ
479
4805. More features
481================
482
483FIXME -- "platform" property handling
50ccbaaa 484
50ccbaaa
VS
485
486=== EOF ===
487
488Version: $Id$