1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XML resource for wxBoxSizer
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "xh_sizer.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/xml/xh_sizer.h"
25 #include "wx/statbox.h"
26 #include "wx/notebook.h"
27 #include "wx/tokenzr.h"
29 bool wxSizerXmlHandler::IsSizerNode(wxXmlNode
*node
)
31 return (IsOfClass(node
, wxT("wxBoxSizer"))) ||
32 (IsOfClass(node
, wxT("wxStaticBoxSizer"))) ||
33 (IsOfClass(node
, wxT("wxGridSizer"))) ||
34 (IsOfClass(node
, wxT("wxFlexGridSizer")));
39 wxSizerXmlHandler::wxSizerXmlHandler()
40 : wxXmlResourceHandler(), m_IsInside(FALSE
), m_ParentSizer(NULL
)
42 ADD_STYLE(wxHORIZONTAL
);
43 ADD_STYLE(wxVERTICAL
);
59 ADD_STYLE(wxSTRETCH_NOT
);
61 ADD_STYLE(wxALIGN_CENTER
);
62 ADD_STYLE(wxALIGN_CENTRE
);
63 ADD_STYLE(wxALIGN_LEFT
);
64 ADD_STYLE(wxALIGN_TOP
);
65 ADD_STYLE(wxALIGN_RIGHT
);
66 ADD_STYLE(wxALIGN_BOTTOM
);
67 ADD_STYLE(wxALIGN_CENTER_HORIZONTAL
);
68 ADD_STYLE(wxALIGN_CENTRE_HORIZONTAL
);
69 ADD_STYLE(wxALIGN_CENTER_VERTICAL
);
70 ADD_STYLE(wxALIGN_CENTRE_VERTICAL
);
75 wxObject
*wxSizerXmlHandler::DoCreateResource()
77 if (m_Class
== wxT("sizeritem"))
79 wxXmlNode
*n
= GetParamNode(wxT("object"));
83 bool old_ins
= m_IsInside
;
84 wxSizer
*old_par
= m_ParentSizer
;
86 if (!IsSizerNode(n
)) m_ParentSizer
= NULL
;
87 wxObject
*item
= CreateResFromNode(n
, m_Parent
, NULL
);
89 m_ParentSizer
= old_par
;
90 wxSizer
*sizer
= wxDynamicCast(item
, wxSizer
);
91 wxWindow
*wnd
= wxDynamicCast(item
, wxWindow
);
92 wxSize minsize
= GetSize(wxT("minsize"));
96 m_ParentSizer
->Add(sizer
, GetLong(wxT("option")),
97 GetStyle(wxT("flag")), GetDimension(wxT("border")));
98 if (!(minsize
== wxDefaultSize
))
99 m_ParentSizer
->SetItemMinSize(sizer
, minsize
.x
, minsize
.y
);
103 m_ParentSizer
->Add(wnd
, GetLong(wxT("option")),
104 GetStyle(wxT("flag")), GetDimension(wxT("border")));
105 if (!(minsize
== wxDefaultSize
))
106 m_ParentSizer
->SetItemMinSize(wnd
, minsize
.x
, minsize
.y
);
109 wxLogError(wxT("Error in resource."));
115 wxLogError(wxT("Error in resource: no control/sizer within sizer's <item> tag."));
120 else if (m_Class
== wxT("spacer"))
122 wxCHECK_MSG(m_ParentSizer
, NULL
, wxT("Incorrect syntax of XML resource: spacer not within sizer!"));
123 wxSize sz
= GetSize();
124 m_ParentSizer
->Add(sz
.x
, sz
.y
,
125 GetLong(wxT("option")), GetStyle(wxT("flag")), GetDimension(wxT("border")));
131 wxSizer
*sizer
= NULL
;
133 wxXmlNode
*parentNode
= m_Node
->GetParent();
135 wxCHECK_MSG(m_ParentSizer
!= NULL
||
136 ((IsOfClass(parentNode
, wxT("wxPanel")) ||
137 IsOfClass(parentNode
, wxT("wxDialog"))) &&
138 parentNode
->GetType() == wxXML_ELEMENT_NODE
), NULL
,
139 wxT("Incorrect use of sizer: parent is not 'wxDialog' or 'wxPanel'."));
141 if (m_Class
== wxT("wxBoxSizer"))
142 sizer
= new wxBoxSizer(GetStyle(wxT("orient"), wxHORIZONTAL
));
144 else if (m_Class
== wxT("wxStaticBoxSizer"))
146 sizer
= new wxStaticBoxSizer(
147 new wxStaticBox(m_ParentAsWindow
, -1, GetText(wxT("label"))),
148 GetStyle(wxT("orient"), wxHORIZONTAL
));
151 else if (m_Class
== wxT("wxGridSizer"))
152 sizer
= new wxGridSizer(GetLong(wxT("rows")), GetLong(wxT("cols")),
153 GetDimension(wxT("vgap")), GetDimension(wxT("hgap")));
155 else if (m_Class
== wxT("wxFlexGridSizer"))
157 wxFlexGridSizer
*fsizer
=
158 new wxFlexGridSizer(GetLong(wxT("rows")), GetLong(wxT("cols")),
159 GetDimension(wxT("vgap")), GetDimension(wxT("hgap")));
161 wxStringTokenizer tkn
;
163 tkn
.SetString(GetParamValue(wxT("growablerows")), wxT(","));
164 while (tkn
.HasMoreTokens())
166 if (!tkn
.GetNextToken().ToULong(&l
))
167 wxLogError(wxT("growablerows must be comma-separated list of row numbers"));
169 fsizer
->AddGrowableRow(l
);
171 tkn
.SetString(GetParamValue(wxT("growablecols")), wxT(","));
172 while (tkn
.HasMoreTokens())
174 if (!tkn
.GetNextToken().ToULong(&l
))
175 wxLogError(wxT("growablecols must be comma-separated list of column numbers"));
177 fsizer
->AddGrowableCol(l
);
181 wxSize minsize
= GetSize(wxT("minsize"));
182 if (!(minsize
== wxDefaultSize
))
183 sizer
->SetMinSize(minsize
);
185 wxSizer
*old_par
= m_ParentSizer
;
186 m_ParentSizer
= sizer
;
187 bool old_ins
= m_IsInside
;
189 CreateChildren(m_Parent
, TRUE
/*only this handler*/);
190 m_IsInside
= old_ins
;
191 m_ParentSizer
= old_par
;
193 if (m_ParentSizer
== NULL
) // setup window:
195 m_ParentAsWindow
->SetAutoLayout(TRUE
);
196 m_ParentAsWindow
->SetSizer(sizer
);
198 wxXmlNode
*nd
= m_Node
;
200 if (GetSize() == wxDefaultSize
)
201 sizer
->Fit(m_ParentAsWindow
);
204 if (m_ParentAsWindow
->GetWindowStyle() & (wxRESIZE_BOX
| wxRESIZE_BORDER
))
205 sizer
->SetSizeHints(m_ParentAsWindow
);
214 bool wxSizerXmlHandler::CanHandle(wxXmlNode
*node
)
216 return ((!m_IsInside
&& IsSizerNode(node
)) ||
217 (m_IsInside
&& IsOfClass(node
, wxT("sizeritem"))) ||
218 (m_IsInside
&& IsOfClass(node
, wxT("spacer"))));