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" 
  28 static bool IsSizerNode(wxXmlNode 
*node
) 
  30     return (node
->GetName() == _T("boxsizer")) || 
  31            (node
->GetName() == _T("staticboxsizer")) || 
  32            (node
->GetName() == _T("gridsizer")) || 
  33            (node
->GetName() == _T("flexgridsizer")); 
  38 wxSizerXmlHandler::wxSizerXmlHandler()  
  39 : wxXmlResourceHandler(), m_IsInside(FALSE
), m_ParentSizer(NULL
) 
  41     ADD_STYLE(wxHORIZONTAL
); 
  42     ADD_STYLE(wxVERTICAL
); 
  58     ADD_STYLE(wxSTRETCH_NOT
); 
  60     ADD_STYLE(wxALIGN_CENTER
); 
  61     ADD_STYLE(wxALIGN_CENTRE
); 
  62     ADD_STYLE(wxALIGN_LEFT
); 
  63     ADD_STYLE(wxALIGN_TOP
); 
  64     ADD_STYLE(wxALIGN_RIGHT
); 
  65     ADD_STYLE(wxALIGN_BOTTOM
); 
  66     ADD_STYLE(wxALIGN_CENTER_HORIZONTAL
); 
  67     ADD_STYLE(wxALIGN_CENTRE_HORIZONTAL
); 
  68     ADD_STYLE(wxALIGN_CENTER_VERTICAL
); 
  69     ADD_STYLE(wxALIGN_CENTRE_VERTICAL
); 
  74 wxObject 
*wxSizerXmlHandler::DoCreateResource() 
  76     if (m_Node
->GetName() == _T("sizeritem")) 
  78         wxXmlNode 
*n 
= GetParamNode(_T("window"))->GetChildren(); 
  82             if (n
->GetType() == wxXML_ELEMENT_NODE
) 
  84                 bool old_ins 
= m_IsInside
; 
  85                 wxSizer 
*old_par 
= m_ParentSizer
; 
  87                 if (!IsSizerNode(n
)) m_ParentSizer 
= NULL
; 
  88                 wxObject 
*item 
= CreateResFromNode(n
, m_Parent
, NULL
); 
  90                 m_ParentSizer 
= old_par
; 
  91                 wxSizer 
*sizer 
= wxDynamicCast(item
, wxSizer
); 
  92                 wxWindow 
*wnd 
= wxDynamicCast(item
, wxWindow
); 
  95                     m_ParentSizer
->Add(sizer
, GetLong(_T("option")),  
  96                                        GetStyle(_T("flag")), GetLong(_T("border"))); 
  98                     m_ParentSizer
->Add(wnd
, GetLong(_T("option")),  
  99                                        GetStyle(_T("flag")), GetLong(_T("border"))); 
 101                     wxLogError(_T("Error in resource.")); 
 107         wxLogError(_T("Error in resource: no control/sizer within sizer's <item> tag.")); 
 111     else if (m_Node
->GetName() == _T("spacer")) 
 113         wxCHECK_MSG(m_ParentSizer
, NULL
, _T("Incorrect syntax of XML resource: spacer not within sizer!")); 
 114         wxSize sz 
= GetSize(); 
 115         m_ParentSizer
->Add(sz
.x
, sz
.y
, 
 116             GetLong(_T("option")), GetStyle(_T("flag")), GetLong(_T("border"))); 
 122         wxSizer 
*sizer 
= NULL
; 
 124         wxXmlNode 
*parentNode 
= m_Node
->GetParent()->GetParent(); 
 126         wxCHECK_MSG(m_ParentSizer 
!= NULL 
|| 
 127                 ((parentNode
->GetName() == _T("panel") || 
 128                   parentNode
->GetName() == _T("dialog")) && 
 129                  parentNode
->GetType() == wxXML_ELEMENT_NODE
), NULL
, 
 130                 _T("Incorrect use of sizer: parent is not 'dialog' or 'panel'.")); 
 132         if (m_Node
->GetName() == _T("boxsizer")) 
 133             sizer 
= new wxBoxSizer(GetStyle(_T("orient"), wxHORIZONTAL
)); 
 135         else if (m_Node
->GetName() == _T("staticboxsizer")) 
 137             sizer 
= new wxStaticBoxSizer( 
 138                          new wxStaticBox(m_ParentAsWindow
, -1, GetText(_T("label"))), 
 139                          GetStyle(_T("orient"), wxHORIZONTAL
)); 
 142         else if (m_Node
->GetName() == _T("gridsizer")) 
 143             sizer 
= new wxGridSizer(GetLong(_T("rows")), GetLong(_T("cols")), 
 144                                     GetLong(_T("vgap")), GetLong(_T("hgap"))); 
 146         else if (m_Node
->GetName() == _T("flexgridsizer")) 
 147             sizer 
= new wxFlexGridSizer(GetLong(_T("rows")), GetLong(_T("cols")), 
 148                                     GetLong(_T("vgap")), GetLong(_T("hgap"))); 
 150         wxSizer 
*old_par 
= m_ParentSizer
; 
 151         m_ParentSizer 
= sizer
; 
 152         bool old_ins 
= m_IsInside
; 
 154         CreateChildren(m_Parent
, TRUE
/*only this handler*/); 
 155         m_IsInside 
= old_ins
; 
 156         m_ParentSizer 
= old_par
; 
 158         if (m_ParentSizer 
== NULL
) // setup window: 
 160             m_ParentAsWindow
->SetAutoLayout(TRUE
); 
 161             m_ParentAsWindow
->SetSizer(sizer
); 
 163             wxXmlNode 
*nd 
= m_Node
; 
 165             if (GetSize() == wxDefaultSize
) 
 166                 sizer
->Fit(m_ParentAsWindow
); 
 169             if (m_ParentAsWindow
->GetWindowStyle() & (wxRESIZE_BOX 
| wxRESIZE_BORDER
)) 
 170                 sizer
->SetSizeHints(m_ParentAsWindow
); 
 179 bool wxSizerXmlHandler::CanHandle(wxXmlNode 
*node
) 
 181     return ((!m_IsInside 
&& IsSizerNode(node
)) || 
 182             (m_IsInside 
&& node
->GetName() == _T("sizeritem")) || 
 183             (m_IsInside 
&& node
->GetName() == _T("spacer")));