]>
Commit | Line | Data |
---|---|---|
78d14f80 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1c067fe3 | 2 | // Name: src/xrc/xh_sizer.cpp |
b5d6954b | 3 | // Purpose: XRC resource for wxBoxSizer |
78d14f80 VS |
4 | // Author: Vaclav Slavik |
5 | // Created: 2000/03/21 | |
78d14f80 VS |
6 | // Copyright: (c) 2000 Vaclav Slavik |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
f80ea77b | 9 | |
78d14f80 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
621be1ec | 17 | #if wxUSE_XRC |
a1e4ec87 | 18 | |
78d14f80 | 19 | #include "wx/xrc/xh_sizer.h" |
e4db172a WS |
20 | |
21 | #ifndef WX_PRECOMP | |
22 | #include "wx/log.h" | |
8e609c82 | 23 | #include "wx/panel.h" |
876cd6f7 | 24 | #include "wx/statbox.h" |
ed2fbeb8 | 25 | #include "wx/sizer.h" |
4107600f MW |
26 | #include "wx/frame.h" |
27 | #include "wx/dialog.h" | |
28 | #include "wx/button.h" | |
5e1a9f05 | 29 | #include "wx/scrolwin.h" |
e4db172a WS |
30 | #endif |
31 | ||
0d077b41 | 32 | #include "wx/gbsizer.h" |
13a38887 | 33 | #include "wx/wrapsizer.h" |
78d14f80 VS |
34 | #include "wx/notebook.h" |
35 | #include "wx/tokenzr.h" | |
36 | ||
df27f1dc | 37 | #include "wx/xml/xml.h" |
78d14f80 | 38 | |
172541f6 VS |
39 | //----------------------------------------------------------------------------- |
40 | // wxSizerXmlHandler | |
41 | //----------------------------------------------------------------------------- | |
78d14f80 | 42 | |
0d077b41 | 43 | IMPLEMENT_DYNAMIC_CLASS(wxSizerXmlHandler, wxXmlResourceHandler) |
78d14f80 | 44 | |
f80ea77b | 45 | wxSizerXmlHandler::wxSizerXmlHandler() |
ed2fbeb8 WS |
46 | :wxXmlResourceHandler(), |
47 | m_isInside(false), | |
48 | m_isGBS(false), | |
49 | m_parentSizer(NULL) | |
78d14f80 | 50 | { |
544fee32 VS |
51 | XRC_ADD_STYLE(wxHORIZONTAL); |
52 | XRC_ADD_STYLE(wxVERTICAL); | |
78d14f80 VS |
53 | |
54 | // and flags | |
544fee32 VS |
55 | XRC_ADD_STYLE(wxLEFT); |
56 | XRC_ADD_STYLE(wxRIGHT); | |
57 | XRC_ADD_STYLE(wxTOP); | |
58 | XRC_ADD_STYLE(wxBOTTOM); | |
59 | XRC_ADD_STYLE(wxNORTH); | |
60 | XRC_ADD_STYLE(wxSOUTH); | |
61 | XRC_ADD_STYLE(wxEAST); | |
62 | XRC_ADD_STYLE(wxWEST); | |
63 | XRC_ADD_STYLE(wxALL); | |
78d14f80 | 64 | |
544fee32 VS |
65 | XRC_ADD_STYLE(wxGROW); |
66 | XRC_ADD_STYLE(wxEXPAND); | |
67 | XRC_ADD_STYLE(wxSHAPED); | |
68 | XRC_ADD_STYLE(wxSTRETCH_NOT); | |
78d14f80 | 69 | |
544fee32 VS |
70 | XRC_ADD_STYLE(wxALIGN_CENTER); |
71 | XRC_ADD_STYLE(wxALIGN_CENTRE); | |
72 | XRC_ADD_STYLE(wxALIGN_LEFT); | |
73 | XRC_ADD_STYLE(wxALIGN_TOP); | |
74 | XRC_ADD_STYLE(wxALIGN_RIGHT); | |
75 | XRC_ADD_STYLE(wxALIGN_BOTTOM); | |
76 | XRC_ADD_STYLE(wxALIGN_CENTER_HORIZONTAL); | |
77 | XRC_ADD_STYLE(wxALIGN_CENTRE_HORIZONTAL); | |
78 | XRC_ADD_STYLE(wxALIGN_CENTER_VERTICAL); | |
79 | XRC_ADD_STYLE(wxALIGN_CENTRE_VERTICAL); | |
f80ea77b | 80 | |
c66b63e5 | 81 | XRC_ADD_STYLE(wxFIXED_MINSIZE); |
a575238f | 82 | XRC_ADD_STYLE(wxRESERVE_SPACE_EVEN_IF_HIDDEN); |
63b37a4e | 83 | |
249259e7 VZ |
84 | // this flag doesn't do anything any more but we can just ignore its |
85 | // occurrences in the old resource files instead of raising a fuss because | |
86 | // of it | |
87 | AddStyle("wxADJUST_MINSIZE", 0); | |
88 | ||
63b37a4e VZ |
89 | // wxWrapSizer-specific flags |
90 | XRC_ADD_STYLE(wxEXTEND_LAST_ON_EACH_LINE); | |
91 | XRC_ADD_STYLE(wxREMOVE_LEADING_SPACES); | |
78d14f80 VS |
92 | } |
93 | ||
94 | ||
95 | ||
0d077b41 RD |
96 | bool wxSizerXmlHandler::CanHandle(wxXmlNode *node) |
97 | { | |
98 | return ( (!m_isInside && IsSizerNode(node)) || | |
99 | (m_isInside && IsOfClass(node, wxT("sizeritem"))) || | |
f80ea77b | 100 | (m_isInside && IsOfClass(node, wxT("spacer"))) |
0d077b41 RD |
101 | ); |
102 | } | |
103 | ||
f80ea77b | 104 | |
0d077b41 | 105 | wxObject* wxSizerXmlHandler::DoCreateResource() |
f80ea77b | 106 | { |
78d14f80 | 107 | if (m_class == wxT("sizeritem")) |
0d077b41 | 108 | return Handle_sizeritem(); |
f80ea77b | 109 | |
78d14f80 | 110 | else if (m_class == wxT("spacer")) |
0d077b41 RD |
111 | return Handle_spacer(); |
112 | ||
113 | else | |
114 | return Handle_sizer(); | |
115 | } | |
116 | ||
117 | ||
40730ad1 VZ |
118 | wxSizer* wxSizerXmlHandler::DoCreateSizer(const wxString& name) |
119 | { | |
120 | if (name == wxT("wxBoxSizer")) | |
121 | return Handle_wxBoxSizer(); | |
122 | #if wxUSE_STATBOX | |
123 | else if (name == wxT("wxStaticBoxSizer")) | |
124 | return Handle_wxStaticBoxSizer(); | |
125 | #endif | |
126 | else if (name == wxT("wxGridSizer")) | |
127 | { | |
128 | if ( !ValidateGridSizerChildren() ) | |
129 | return NULL; | |
130 | return Handle_wxGridSizer(); | |
131 | } | |
132 | else if (name == wxT("wxFlexGridSizer")) | |
133 | { | |
134 | return Handle_wxFlexGridSizer(); | |
135 | } | |
136 | else if (name == wxT("wxGridBagSizer")) | |
137 | { | |
138 | return Handle_wxGridBagSizer(); | |
139 | } | |
140 | else if (name == wxT("wxWrapSizer")) | |
141 | { | |
142 | return Handle_wxWrapSizer(); | |
143 | } | |
144 | ||
145 | ReportError(wxString::Format("unknown sizer class \"%s\"", name)); | |
146 | return NULL; | |
147 | } | |
148 | ||
0d077b41 RD |
149 | |
150 | ||
40730ad1 | 151 | bool wxSizerXmlHandler::IsSizerNode(wxXmlNode *node) const |
0d077b41 RD |
152 | { |
153 | return (IsOfClass(node, wxT("wxBoxSizer"))) || | |
154 | (IsOfClass(node, wxT("wxStaticBoxSizer"))) || | |
155 | (IsOfClass(node, wxT("wxGridSizer"))) || | |
156 | (IsOfClass(node, wxT("wxFlexGridSizer"))) || | |
13a38887 VZ |
157 | (IsOfClass(node, wxT("wxGridBagSizer"))) || |
158 | (IsOfClass(node, wxT("wxWrapSizer"))); | |
0d077b41 RD |
159 | } |
160 | ||
161 | ||
162 | wxObject* wxSizerXmlHandler::Handle_sizeritem() | |
163 | { | |
164 | // find the item to be managed by this sizeritem | |
165 | wxXmlNode *n = GetParamNode(wxT("object")); | |
166 | if ( !n ) | |
167 | n = GetParamNode(wxT("object_ref")); | |
168 | ||
169 | // did we find one? | |
170 | if (n) | |
171 | { | |
172 | // create a sizer item for it | |
173 | wxSizerItem* sitem = MakeSizerItem(); | |
f80ea77b | 174 | |
0d077b41 RD |
175 | // now fetch the item to be managed |
176 | bool old_gbs = m_isGBS; | |
177 | bool old_ins = m_isInside; | |
178 | wxSizer *old_par = m_parentSizer; | |
f80ea77b WS |
179 | m_isInside = false; |
180 | if (!IsSizerNode(n)) m_parentSizer = NULL; | |
0d077b41 RD |
181 | wxObject *item = CreateResFromNode(n, m_parent, NULL); |
182 | m_isInside = old_ins; | |
183 | m_parentSizer = old_par; | |
184 | m_isGBS = old_gbs; | |
185 | ||
186 | // and figure out what type it is | |
187 | wxSizer *sizer = wxDynamicCast(item, wxSizer); | |
188 | wxWindow *wnd = wxDynamicCast(item, wxWindow); | |
f80ea77b | 189 | |
0d077b41 | 190 | if (sizer) |
a50cf60e | 191 | sitem->AssignSizer(sizer); |
0d077b41 | 192 | else if (wnd) |
a50cf60e | 193 | sitem->AssignWindow(wnd); |
f80ea77b | 194 | else |
819559b2 | 195 | ReportError(n, "unexpected item in sizer"); |
0d077b41 | 196 | |
1eba2193 RD |
197 | // finally, set other wxSizerItem attributes |
198 | SetSizerItemAttributes(sitem); | |
199 | ||
0d077b41 RD |
200 | AddSizerItem(sitem); |
201 | return item; | |
202 | } | |
203 | else /*n == NULL*/ | |
78d14f80 | 204 | { |
819559b2 | 205 | ReportError("no window/sizer/spacer within sizeritem object"); |
78d14f80 VS |
206 | return NULL; |
207 | } | |
0d077b41 RD |
208 | } |
209 | ||
210 | ||
211 | wxObject* wxSizerXmlHandler::Handle_spacer() | |
212 | { | |
07acc3cc VZ |
213 | if ( !m_parentSizer ) |
214 | { | |
819559b2 | 215 | ReportError("spacer only allowed inside a sizer"); |
07acc3cc VZ |
216 | return NULL; |
217 | } | |
0d077b41 RD |
218 | |
219 | wxSizerItem* sitem = MakeSizerItem(); | |
220 | SetSizerItemAttributes(sitem); | |
a50cf60e | 221 | sitem->AssignSpacer(GetSize()); |
f80ea77b | 222 | AddSizerItem(sitem); |
0d077b41 RD |
223 | return NULL; |
224 | } | |
225 | ||
78d14f80 | 226 | |
0d077b41 RD |
227 | wxObject* wxSizerXmlHandler::Handle_sizer() |
228 | { | |
0d077b41 | 229 | wxXmlNode *parentNode = m_node->GetParent(); |
78d14f80 | 230 | |
07acc3cc VZ |
231 | if ( !m_parentSizer && |
232 | (!parentNode || parentNode->GetType() != wxXML_ELEMENT_NODE || | |
233 | !m_parentAsWindow) ) | |
234 | { | |
819559b2 | 235 | ReportError("sizer must have a window parent"); |
07acc3cc VZ |
236 | return NULL; |
237 | } | |
78d14f80 | 238 | |
40730ad1 VZ |
239 | // Create the sizer of the appropriate class. |
240 | wxSizer * const sizer = DoCreateSizer(m_class); | |
f80ea77b | 241 | |
afc0db8c VS |
242 | // creation of sizer failed for some (already reported) reason, so exit: |
243 | if ( !sizer ) | |
244 | return NULL; | |
245 | ||
0d077b41 RD |
246 | wxSize minsize = GetSize(wxT("minsize")); |
247 | if (!(minsize == wxDefaultSize)) | |
248 | sizer->SetMinSize(minsize); | |
249 | ||
250 | // save state | |
251 | wxSizer *old_par = m_parentSizer; | |
252 | bool old_ins = m_isInside; | |
0d077b41 RD |
253 | |
254 | // set new state | |
255 | m_parentSizer = sizer; | |
f80ea77b | 256 | m_isInside = true; |
0d077b41 | 257 | m_isGBS = (m_class == wxT("wxGridBagSizer")); |
f80ea77b | 258 | |
ff1aede6 VZ |
259 | wxObject* parent = m_parent; |
260 | #if wxUSE_STATBOX | |
261 | // wxStaticBoxSizer's child controls should be parented by the box itself, | |
262 | // not its parent. | |
263 | wxStaticBoxSizer* const stsizer = wxDynamicCast(sizer, wxStaticBoxSizer); | |
264 | if ( stsizer ) | |
265 | parent = stsizer->GetStaticBox(); | |
266 | #endif // wxUSE_STATBOX | |
267 | ||
268 | CreateChildren(parent, true/*only this handler*/); | |
0d077b41 | 269 | |
5dd238c6 | 270 | // set growable rows and cols for sizers which support this |
40730ad1 | 271 | if ( wxFlexGridSizer *flexsizer = wxDynamicCast(sizer, wxFlexGridSizer) ) |
5dd238c6 | 272 | { |
5a3eee0d | 273 | SetFlexibleMode(flexsizer); |
5dd238c6 VZ |
274 | SetGrowables(flexsizer, wxT("growablerows"), true); |
275 | SetGrowables(flexsizer, wxT("growablecols"), false); | |
276 | } | |
277 | ||
0d077b41 | 278 | // restore state |
0d077b41 RD |
279 | m_isInside = old_ins; |
280 | m_parentSizer = old_par; | |
281 | ||
282 | if (m_parentSizer == NULL) // setup window: | |
283 | { | |
0d077b41 RD |
284 | m_parentAsWindow->SetSizer(sizer); |
285 | ||
286 | wxXmlNode *nd = m_node; | |
287 | m_node = parentNode; | |
288 | if (GetSize() == wxDefaultSize) | |
5e1a9f05 VS |
289 | { |
290 | if ( wxDynamicCast(m_parentAsWindow, wxScrolledWindow) != NULL ) | |
291 | { | |
292 | sizer->FitInside(m_parentAsWindow); | |
293 | } | |
294 | else | |
295 | { | |
296 | sizer->Fit(m_parentAsWindow); | |
297 | } | |
298 | } | |
0d077b41 RD |
299 | m_node = nd; |
300 | ||
ea813d91 VS |
301 | if (m_parentAsWindow->IsTopLevel()) |
302 | { | |
0d077b41 | 303 | sizer->SetSizeHints(m_parentAsWindow); |
ea813d91 | 304 | } |
0d077b41 | 305 | } |
f80ea77b | 306 | |
0d077b41 RD |
307 | return sizer; |
308 | } | |
309 | ||
310 | ||
311 | wxSizer* wxSizerXmlHandler::Handle_wxBoxSizer() | |
312 | { | |
313 | return new wxBoxSizer(GetStyle(wxT("orient"), wxHORIZONTAL)); | |
f80ea77b WS |
314 | } |
315 | ||
627ddac9 | 316 | #if wxUSE_STATBOX |
0d077b41 RD |
317 | wxSizer* wxSizerXmlHandler::Handle_wxStaticBoxSizer() |
318 | { | |
319 | return new wxStaticBoxSizer( | |
320 | new wxStaticBox(m_parentAsWindow, | |
321 | GetID(), | |
322 | GetText(wxT("label")), | |
323 | wxDefaultPosition, wxDefaultSize, | |
324 | 0/*style*/, | |
325 | GetName()), | |
326 | GetStyle(wxT("orient"), wxHORIZONTAL)); | |
327 | } | |
627ddac9 | 328 | #endif // wxUSE_STATBOX |
f80ea77b | 329 | |
0d077b41 RD |
330 | wxSizer* wxSizerXmlHandler::Handle_wxGridSizer() |
331 | { | |
332 | return new wxGridSizer(GetLong(wxT("rows")), GetLong(wxT("cols")), | |
333 | GetDimension(wxT("vgap")), GetDimension(wxT("hgap"))); | |
334 | } | |
335 | ||
336 | ||
5dd238c6 | 337 | wxFlexGridSizer* wxSizerXmlHandler::Handle_wxFlexGridSizer() |
0d077b41 | 338 | { |
afc0db8c VS |
339 | if ( !ValidateGridSizerChildren() ) |
340 | return NULL; | |
5dd238c6 VZ |
341 | return new wxFlexGridSizer(GetLong(wxT("rows")), GetLong(wxT("cols")), |
342 | GetDimension(wxT("vgap")), GetDimension(wxT("hgap"))); | |
0d077b41 RD |
343 | } |
344 | ||
345 | ||
1808bb47 | 346 | wxGridBagSizer* wxSizerXmlHandler::Handle_wxGridBagSizer() |
0d077b41 | 347 | { |
afc0db8c VS |
348 | if ( !ValidateGridSizerChildren() ) |
349 | return NULL; | |
5dd238c6 | 350 | return new wxGridBagSizer(GetDimension(wxT("vgap")), GetDimension(wxT("hgap"))); |
0d077b41 RD |
351 | } |
352 | ||
13a38887 VZ |
353 | wxSizer* wxSizerXmlHandler::Handle_wxWrapSizer() |
354 | { | |
63b37a4e | 355 | wxWrapSizer *sizer = new wxWrapSizer(GetStyle("orient"), GetStyle("flag")); |
13a38887 VZ |
356 | return sizer; |
357 | } | |
0d077b41 RD |
358 | |
359 | ||
afc0db8c VS |
360 | bool wxSizerXmlHandler::ValidateGridSizerChildren() |
361 | { | |
362 | int rows = GetLong("rows"); | |
363 | int cols = GetLong("cols"); | |
364 | ||
365 | if ( rows && cols ) | |
366 | { | |
367 | // fixed number of cells, need to verify children count | |
368 | int children = 0; | |
369 | for ( wxXmlNode *n = m_node->GetChildren(); n; n = n->GetNext() ) | |
370 | { | |
371 | if ( n->GetType() == wxXML_ELEMENT_NODE && | |
372 | (n->GetName() == "object" || n->GetName() == "object_ref") ) | |
373 | { | |
374 | children++; | |
375 | } | |
376 | } | |
377 | ||
378 | if ( children > rows * cols ) | |
379 | { | |
380 | ReportError | |
381 | ( | |
382 | wxString::Format | |
383 | ( | |
384 | "too many children in grid sizer: %d > %d x %d" | |
385 | " (consider omitting the number of rows or columns)", | |
386 | children, | |
387 | cols, | |
388 | rows | |
389 | ) | |
390 | ); | |
391 | return false; | |
392 | } | |
393 | } | |
394 | ||
395 | return true; | |
396 | } | |
397 | ||
0d077b41 | 398 | |
5a3eee0d VZ |
399 | void wxSizerXmlHandler::SetFlexibleMode(wxFlexGridSizer* fsizer) |
400 | { | |
401 | if (HasParam(wxT("flexibledirection"))) | |
402 | { | |
403 | wxString dir = GetParamValue(wxT("flexibledirection")); | |
404 | ||
405 | if (dir == wxT("wxVERTICAL")) | |
406 | fsizer->SetFlexibleDirection(wxVERTICAL); | |
407 | else if (dir == wxT("wxHORIZONTAL")) | |
408 | fsizer->SetFlexibleDirection(wxHORIZONTAL); | |
409 | else if (dir == wxT("wxBOTH")) | |
410 | fsizer->SetFlexibleDirection(wxBOTH); | |
411 | else | |
412 | { | |
413 | ReportParamError | |
414 | ( | |
415 | wxT("flexibledirection"), | |
416 | wxString::Format("unknown direction \"%s\"", dir) | |
417 | ); | |
418 | } | |
419 | } | |
420 | ||
421 | if (HasParam(wxT("nonflexiblegrowmode"))) | |
422 | { | |
423 | wxString mode = GetParamValue(wxT("nonflexiblegrowmode")); | |
424 | ||
425 | if (mode == wxT("wxFLEX_GROWMODE_NONE")) | |
426 | fsizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE); | |
427 | else if (mode == wxT("wxFLEX_GROWMODE_SPECIFIED")) | |
428 | fsizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); | |
429 | else if (mode == wxT("wxFLEX_GROWMODE_ALL")) | |
430 | fsizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL); | |
431 | else | |
432 | { | |
433 | ReportParamError | |
434 | ( | |
435 | wxT("nonflexiblegrowmode"), | |
436 | wxString::Format("unknown grow mode \"%s\"", mode) | |
437 | ); | |
438 | } | |
439 | } | |
440 | } | |
441 | ||
442 | ||
0d077b41 RD |
443 | void wxSizerXmlHandler::SetGrowables(wxFlexGridSizer* sizer, |
444 | const wxChar* param, | |
445 | bool rows) | |
446 | { | |
afc0db8c VS |
447 | int nrows, ncols; |
448 | sizer->CalcRowsCols(nrows, ncols); | |
449 | const int nslots = rows ? nrows : ncols; | |
450 | ||
0d077b41 | 451 | wxStringTokenizer tkn; |
0d077b41 | 452 | tkn.SetString(GetParamValue(param), wxT(",")); |
afc0db8c | 453 | |
0d077b41 RD |
454 | while (tkn.HasMoreTokens()) |
455 | { | |
5a3eee0d VZ |
456 | wxString propStr; |
457 | wxString idxStr = tkn.GetNextToken().BeforeFirst(wxT(':'), &propStr); | |
458 | ||
459 | unsigned long li; | |
460 | if (!idxStr.ToULong(&li)) | |
5dd238c6 | 461 | { |
819559b2 VS |
462 | ReportParamError |
463 | ( | |
464 | param, | |
5a3eee0d | 465 | "value must be a comma-separated list of numbers" |
819559b2 | 466 | ); |
5dd238c6 | 467 | break; |
78d14f80 | 468 | } |
5dd238c6 | 469 | |
5a3eee0d VZ |
470 | unsigned long lp = 0; |
471 | if (!propStr.empty()) | |
472 | { | |
473 | if (!propStr.ToULong(&lp)) | |
474 | { | |
475 | ReportParamError | |
476 | ( | |
477 | param, | |
478 | "value must be a comma-separated list of numbers" | |
479 | ); | |
480 | break; | |
481 | } | |
482 | } | |
483 | ||
484 | const int n = static_cast<int>(li); | |
f33a5bc6 | 485 | if ( n >= nslots ) |
afc0db8c VS |
486 | { |
487 | ReportParamError | |
488 | ( | |
489 | param, | |
490 | wxString::Format | |
491 | ( | |
492 | "invalid %s index %d: must be less than %d", | |
493 | rows ? "row" : "column", | |
f33a5bc6 | 494 | n, |
afc0db8c VS |
495 | nslots |
496 | ) | |
497 | ); | |
498 | ||
499 | // ignore incorrect value, still try to process the rest | |
500 | continue; | |
501 | } | |
502 | ||
5dd238c6 | 503 | if (rows) |
5a3eee0d | 504 | sizer->AddGrowableRow(n, static_cast<int>(lp)); |
5dd238c6 | 505 | else |
5a3eee0d | 506 | sizer->AddGrowableCol(n, static_cast<int>(lp)); |
78d14f80 VS |
507 | } |
508 | } | |
509 | ||
510 | ||
0d077b41 RD |
511 | wxGBPosition wxSizerXmlHandler::GetGBPos(const wxString& param) |
512 | { | |
513 | wxSize sz = GetSize(param); | |
514 | if (sz.x < 0) sz.x = 0; | |
515 | if (sz.y < 0) sz.y = 0; | |
516 | return wxGBPosition(sz.x, sz.y); | |
517 | } | |
78d14f80 | 518 | |
0d077b41 RD |
519 | wxGBSpan wxSizerXmlHandler::GetGBSpan(const wxString& param) |
520 | { | |
521 | wxSize sz = GetSize(param); | |
522 | if (sz.x < 1) sz.x = 1; | |
523 | if (sz.y < 1) sz.y = 1; | |
524 | return wxGBSpan(sz.x, sz.y); | |
525 | } | |
526 | ||
527 | ||
528 | ||
529 | wxSizerItem* wxSizerXmlHandler::MakeSizerItem() | |
530 | { | |
531 | if (m_isGBS) | |
532 | return new wxGBSizerItem(); | |
533 | else | |
534 | return new wxSizerItem(); | |
535 | } | |
536 | ||
537 | void wxSizerXmlHandler::SetSizerItemAttributes(wxSizerItem* sitem) | |
538 | { | |
539 | sitem->SetProportion(GetLong(wxT("option"))); // Should this check for "proportion" too? | |
540 | sitem->SetFlag(GetStyle(wxT("flag"))); | |
541 | sitem->SetBorder(GetDimension(wxT("border"))); | |
542 | wxSize sz = GetSize(wxT("minsize")); | |
543 | if (!(sz == wxDefaultSize)) | |
1eba2193 | 544 | sitem->SetMinSize(sz); |
0d077b41 RD |
545 | sz = GetSize(wxT("ratio")); |
546 | if (!(sz == wxDefaultSize)) | |
547 | sitem->SetRatio(sz); | |
f80ea77b | 548 | |
0d077b41 RD |
549 | if (m_isGBS) |
550 | { | |
551 | wxGBSizerItem* gbsitem = (wxGBSizerItem*)sitem; | |
ea0d8ca6 RD |
552 | gbsitem->SetPos(GetGBPos(wxT("cellpos"))); |
553 | gbsitem->SetSpan(GetGBSpan(wxT("cellspan"))); | |
f80ea77b | 554 | } |
86909f4c VZ |
555 | |
556 | // record the id of the item, if any, for use by XRCSIZERITEM() | |
557 | sitem->SetId(GetID()); | |
0d077b41 RD |
558 | } |
559 | ||
560 | void wxSizerXmlHandler::AddSizerItem(wxSizerItem* sitem) | |
78d14f80 | 561 | { |
0d077b41 RD |
562 | if (m_isGBS) |
563 | ((wxGridBagSizer*)m_parentSizer)->Add((wxGBSizerItem*)sitem); | |
564 | else | |
565 | m_parentSizer->Add(sitem); | |
78d14f80 | 566 | } |
f80ea77b | 567 | |
172541f6 VS |
568 | |
569 | ||
570 | //----------------------------------------------------------------------------- | |
571 | // wxStdDialogButtonSizerXmlHandler | |
572 | //----------------------------------------------------------------------------- | |
dd47af27 | 573 | #if wxUSE_BUTTON |
172541f6 VS |
574 | |
575 | IMPLEMENT_DYNAMIC_CLASS(wxStdDialogButtonSizerXmlHandler, wxXmlResourceHandler) | |
576 | ||
577 | wxStdDialogButtonSizerXmlHandler::wxStdDialogButtonSizerXmlHandler() | |
578 | : m_isInside(false), m_parentSizer(NULL) | |
579 | { | |
580 | } | |
581 | ||
582 | wxObject *wxStdDialogButtonSizerXmlHandler::DoCreateResource() | |
583 | { | |
584 | if (m_class == wxT("wxStdDialogButtonSizer")) | |
585 | { | |
586 | wxASSERT( !m_parentSizer ); | |
587 | ||
588 | wxSizer *s = m_parentSizer = new wxStdDialogButtonSizer; | |
589 | m_isInside = true; | |
590 | ||
591 | CreateChildren(m_parent, true/*only this handler*/); | |
592 | ||
593 | m_parentSizer->Realize(); | |
594 | ||
595 | m_isInside = false; | |
596 | m_parentSizer = NULL; | |
597 | ||
598 | return s; | |
599 | } | |
600 | else // m_class == "button" | |
601 | { | |
602 | wxASSERT( m_parentSizer ); | |
603 | ||
604 | // find the item to be managed by this sizeritem | |
605 | wxXmlNode *n = GetParamNode(wxT("object")); | |
606 | if ( !n ) | |
607 | n = GetParamNode(wxT("object_ref")); | |
608 | ||
609 | // did we find one? | |
610 | if (n) | |
611 | { | |
612 | wxObject *item = CreateResFromNode(n, m_parent, NULL); | |
613 | wxButton *button = wxDynamicCast(item, wxButton); | |
614 | ||
615 | if (button) | |
616 | m_parentSizer->AddButton(button); | |
617 | else | |
819559b2 | 618 | ReportError(n, "expected wxButton"); |
172541f6 VS |
619 | |
620 | return item; | |
621 | } | |
622 | else /*n == NULL*/ | |
623 | { | |
819559b2 | 624 | ReportError("no button within wxStdDialogButtonSizer"); |
172541f6 VS |
625 | return NULL; |
626 | } | |
627 | } | |
628 | } | |
629 | ||
630 | bool wxStdDialogButtonSizerXmlHandler::CanHandle(wxXmlNode *node) | |
631 | { | |
632 | return (!m_isInside && IsOfClass(node, wxT("wxStdDialogButtonSizer"))) || | |
633 | (m_isInside && IsOfClass(node, wxT("button"))); | |
634 | } | |
dd47af27 | 635 | #endif // wxUSE_BUTTON |
172541f6 | 636 | |
621be1ec | 637 | #endif // wxUSE_XRC |