]> git.saurik.com Git - wxWidgets.git/blame - docs/tech/tn0014.txt
Now scaling doesn't scale GetTextExtent() anymore. This
[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)
16 c) wxWorkshop (http://wxworkshop.sf.net)
17 b) wxrcedit (contrib/utils/wxrcedit)
18
19The XRC format is based on XML 1.0 (please consult W3C's specification). There
20is no DTD available since it is not possible to fully describe the format with
21the limited expressive power of DTDs.
22
2b5f62a0
VZ
23
24
50ccbaaa 251. Terminology
2b5f62a0 26==============
50ccbaaa
VS
27
28The usual XML terminology applies. In particular, we shall use the terms
2b5f62a0 29NODE, PROPERTY and VALUE in the XML sense:
50ccbaaa
VS
30
31 <node property1="value1" property2="value2">...</node>
32
2b5f62a0
VZ
33The term ATTRIBUTE is specific to XRC and refers to a subnode
34of an <object> or <object_ref> node that is itself not <object> or <object_ref>.
35In the example bellow, <pos>, <label> and <style> are attributes, while neither
36<resource> nor either of <object>s is:
50ccbaaa
VS
37
38 <?xml version="1.0" encoding="utf-8">
40e2d134 39 <resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
50ccbaaa 40 <object class="wxPanel">
2b5f62a0 41 <style>wxSUNKEN_BORDER</style> <!-- attr -->
50ccbaaa 42 <object class="wxStaticText">
2b5f62a0
VZ
43 <label>A label</label> <!-- attr -->
44 <pos>10,10</pos> <!-- attr -->
50ccbaaa
VS
45 </object>
46 </object>
47 </resource>
48
2b5f62a0
VZ
49ATTRIBUTE VALUE is the content of all text elements within attribute tag. In the
50above example, "wxSUNKEN_BORDER", "A label" and "10,10" are attribute values.
51ATTRIBUTE TYPE defines what attribute values are valid for given attribute (you
52can think of it as attribute value syntax definition).
53
54
55
50ccbaaa 562. Elementary description
2b5f62a0 57=========================
50ccbaaa 58
432be5aa
VS
59XRC resource file is a well-formed XML 1.0 document. All elements of XRC file
60are from the http://www.wxwindows.org/wxxrc namespace.
50ccbaaa
VS
61
62The root node of XRC document must be <resource>. The <resource> node has
63optional "version" property. Default version (in absence of the version
64property) is "0.0.0.0". The version consists of four integers separated by
65periods. Version of XRC format changes only if there was an incompatible
66change introduced (i.e. either the library cannot understand old resource
67files or older versions of the library wouldn't understand the new format).
68The first three integers are major, minor and release number of the wxWindows
69release when the change was introduced, the last one is revision number and
70is 0 for the first incompatible change in given wxWindows release, 1 for
71the second etc.
72
73Differences between versions are described within this document in paragraphs
2b5f62a0 74entitled "Version Note".
50ccbaaa 75
40e2d134
VS
76The <resource> node contains namespace declaration, too:
77
78 <resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
79
50ccbaaa
VS
80The <resource> node is only allowed to have <object> and <object_ref>
81subnodes, all of which must have the "name" property.
82
2b5f62a0
VZ
83The <object> node represents a single object (GUI element) and it usually maps
84directly to a wxWindows class instance. It three properties: "name", "class"
85and "subclass". "class" must always be present, it tells XRC what wxWindows
432be5aa
VS
86object should be created in this place. The other two are optional. "name" is
87ID used to identify the object. It is the value passed to the XRCID() macro and
88is also used to construct wxWindow's id and name attributes and must be unique
89among all children of the neareset container object (wxDialog, wxFrame,
90wxPanel, wxNotebook) upside from the object in XML nodes hiearchy (two distinct
91containers may contain objects with same "name", though). "subclass" is
92optional name of class whose constructor will be called instead of the
93constructor for "class". Subclass must be available in the program that loads
94the resource, must be derived from "class" and must be registered within
95wxWindows' RTTI system.
2b5f62a0
VZ
96
97Example:
98
99 <object name="MyList1" class="wxListCtrl" subclass="MyListCtrlClass">
100 ...
101 </object>
102
432be5aa
VS
103<object> node may have arbitrary child nodes. What child nodes and their
104semantics are class-dependent and are defined later in this document. The user
105is allowed to register new object handlers within XRC and extend it to accept
106new <object> classes (and therefore different <object>'s child nodes).
107
108<object_ref> node is identical to <object>, except that it does _not_ have
109"class" property and has additonal required property "ref". It's concept is
110similar to Unix symlinks: value of the "ref" property is equal to the value of
111"name" property of some existing node (called referred node) in the resources
112(not neccessary top-level). Referred node's "class" property and all subnodes
113are copied in place of the referee <object_ref> node which is then processed as
114regular <object> node. If the <object_ref> node itself has child nodes, then
115these nodes _override_ any nodes from the referred node.
2b5f62a0
VZ
116
117Example:
118
119 <object name="foo" class="wxTextCtrl">
120 <value>hello</value>
121 <size>100,-1d</size>
122 </object>
123 <object_ref name="bar" ref="foo">
124 <value>bar</value> <!-- override! -->
0fa2e104 125 </object_ref>
2b5f62a0
VZ
126
127is identical to:
128
129 <object name="foo" class="wxTextCtrl">
130 <value>hello</value>
131 <size>100,-1d</size>
132 </object>
133 <object name="bar" class="wxTextCtrl">
134 <value>bar</value>
135 <size>100,-1d</size>
136 </object>
137
138
139
1403. Common attribute types
141=========================
142
143There are several attribute types (see section 1. Terminology) that are common
144to many attributes of different classes:
145
146String
147------
148Any text. Some characters have special interpretation and are translated
149by XRC parser according to this table:
150 "_" -> "&" ('&' is used to underline e.g. menu items in wxWindows)
151 "__" -> "_"
152 "\n" -> line break (C character '\n')
153 "\r" -> carriage return (C character '\r')
154 "\t" -> tabelator (C character '\t')
155
156Version Note:
157 '$' was used instead of '_' prior to version 2.3.0.1.
158
159
160I18nString
161----------
162Like String, but the value is translated to native language using wxLocale
163at runtime (unless it was disabled by not passing wxXRC_USE_LOCALE flag to
164wxXmlResource constructor). Used for strings that are "visible" in the GUI.
165
166
167UnsignedInteger
168---------------
169This is obvious. Only digits 0-9 may be present and there must be at least
170one digit.
171
172
173Integer
174-------
175Like UnsignedInteger but may be prefixed with '-' (ints less than zero).
176
177
178Position
179--------
180Specifies (window's) position in 2D space. Syntax is <integer>,<integer>[d]
181where <integer> is valid value of Integer type.
182
50ccbaaa 183
2b5f62a0
VZ
184Size
185----
186Syntax is same as Position's syntax, but the values are interpreted as window
187size (wxSize type) and not position (wxPosition type).
50ccbaaa
VS
188
189
2b5f62a0
VZ
190Style[wxSomeClass]
191------------------
192List of style flags that can be passed to wxSomeClass' constructor. Flags are
432be5aa
VS
193written in same way as in C++ code (e.g. "wxSUNKEN_BORDER",
194"wxHW_SCROLLBAR_NEVER") and are delimined with any combination of whitespaces
195and '|'. Possible flags are class-dependent and are not described in this
196technote. Please refer to wxWindows manual for all styles that given class can
197accept; if XRC does not accept a flag listed in wxWindows documentation, it is
198a bug.
2b5f62a0
VZ
199
200
201Bitmap
202------
203Attribute value is interpreted as filename (either absolute or relative to
204the location of XRC resource file). In addition, attribute node may have
205"stock_id" and "stock_client" properties. Their values may be any of wxArtID (or
206wxArtClient respectively) values as used by wxArtProvider (because the user may
207define own constants, efectively any string is legal here). Examples are
208"wxART_FILE_OPEN" (id) or "wxART_MENU" (client).
209
432be5aa
VS
210Any of "stock_id" or "stock_client" properties or the filename may be omitted.
211XRC determines the bitmap to use according to this algorithm:
212 1. If there is non-empty "stock_id" property, query wxArtProvider for the
213 bitmap (if there is no "stock_client", use default one, which is usually
214 wxART_OTHER; exceptions are noted in class-specific sections bellow). If
215 the query fails, continue to 2.
2b5f62a0
VZ
216 2. Load the bitmap from the file in attribute value.
217
218
219Boolean
220-------
221Boolean value, either "0" (false) or "1" (true).
222
50ccbaaa 223
50ccbaaa
VS
224
2254. Supported classes
2b5f62a0
VZ
226====================
227
228Attributes are listed in tables in the following format:
229attribute name attribute type default value, if any
230 [(optional remarks....................
231 ...................................)]
232
233wxBitmap
234--------
235This is a special case, because it does not create a wxWindow instance but
236creates wxBitmap instead. Another exceptional thing is that it does not have
237any attributes. Instead, the node itself is interpreted as if it were attribute
238of type Bitmap.
239
240Example: <object class="wxBitmap">bitmaps/foo.gif</object>
241
242
243wxIcon
244------
245Identical to wxBitmap class, except that it creates wxIcon instead of wxBitmap.
246
247
248wxButton
249--------
250position Position -1,-1
251size Size -1,-1
252style Style[wxButton]
253
254label I18nString
255default Boolean false
256 (Is the button default button?)
257
258
259wxCalendarCtrl
260--------------
261position Position -1,-1
262size Size -1,-1
263style Style[wxCalendarCtrl]
264
265
266wxCheckBox
267----------
268position Position -1,-1
269size Size -1,-1
270style Style[wxCheckBox]
271checked Boolean false
272
273
274wxCheckList
275-----------
276position Position -1,-1
277size Size -1,-1
278style Style[wxCheckList]
279content (see bellow) (empty)
280
281Optional "content" attribute does not have attribute value. Instead,
282arbitrary number of <item> nodes may be rooted under it (the control
283is filled with strings contained in these nodes). Each <item>
284node must contain I18nString value and may have "checked" property
285with possible values "0" or "1" indicating the the item is initially
286checked.
287
288Example:
289<object class="wxCheckList">
290 <content>
291 <item>One</item>
292 <item checked="1">Two</item>
293 <item checked="1">Three</item>
294 <item>Four</item>
295 </content>
296</object>
297
298
299wxScrolledWindow
300----------------
301position Position -1,-1
302size Size -1,-1
303style Style[wxScrolledWindow] wxHSCROLL | wxVSCROLL
304
305
432be5aa
VS
306wxToolBar
307---------
308position Position -1,-1
309size Size -1,-1
310style Style[wxToolBar] wxNO_BORDER|wxTB_HORIZONTAL
311bitmapsize Size -1,-1
312 (Size of contained bitmaps)
313margins Size -1,-1
314packing Integer -1
315separation Integer -1
316
317wxToolBar node may have children <object> and <object_ref> nodes. Their class
318may be either "tool", "separator" or any wxWindows class derived from
319wxControl. "tool" and "separator" are special pseudo-classes that may only
320appear within wxToolBar node. Their attributes are as follows:
321
322 separator
323 ---------
324 (doesn't have any attributes)
325
326 tool
327 ----
328 bitmap Bitmap
329 bitmap2 Bitmap wxNullBitmap
330 toggle Boolean 0
331 radio Boolean 0
332 label I18nString ""
333 tooltip I18nString ""
334 longhelp I18nString ""
335 position Position -1,-1
336
337 Constraints:
338 At most one of "toggle" and "radio" attributes may be 1.
339 Attribute "position" may not appear if "label" or "radio" attributes
340 are used or if parent wxToolBar's style contains wxTB_TEXT.
341
342 Note:
343 Use of "position" attribute is strongly discouraged, it is deprecated
344 usage of wxToolBar and it is not supported by MSW and GTK
345 implementations.
346
347Children objects are added to the toolbar using AddTool for "tool" class,
348AddSeparator for "separator" and AddControl for other classes.
349
350
2b5f62a0
VZ
351
3525. More features
353================
354
355FIXME -- "platform" property handling
50ccbaaa 356
50ccbaaa
VS
357
358=== EOF ===
359
360Version: $Id$