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