]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolb.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XRC resource for wxBoxSizer
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "xh_toolb.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/xrc/xh_toolb.h"
23 #include "wx/toolbar.h"
28 wxToolBarXmlHandler::wxToolBarXmlHandler()
29 : wxXmlResourceHandler(), m_isInside(FALSE
), m_toolbar(NULL
)
32 ADD_STYLE(wxTB_DOCKABLE
);
33 ADD_STYLE(wxTB_VERTICAL
);
34 ADD_STYLE(wxTB_HORIZONTAL
);
39 wxObject
*wxToolBarXmlHandler::DoCreateResource()
41 if (m_class
== wxT("tool"))
43 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
44 m_toolbar
->AddTool(GetID(),
45 GetBitmap(wxT("bitmap")),
46 GetBitmap(wxT("bitmap2")),
47 GetBool(wxT("toggle")),
51 GetText(wxT("tooltip")),
52 GetText(wxT("longhelp")));
53 return m_toolbar
; // must return non-NULL
56 else if (m_class
== wxT("separator"))
58 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
59 m_toolbar
->AddSeparator();
60 return m_toolbar
; // must return non-NULL
63 else /*<object class="wxToolBar">*/
65 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
67 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
70 wxToolBar
*toolbar
= wxStaticCast(m_instance
, wxToolBar
);
73 toolbar
= new wxToolBar
;
75 toolbar
->Create(m_parentAsWindow
,
82 wxSize bmpsize
= GetSize(wxT("bitmapsize"));
83 if (!(bmpsize
== wxDefaultSize
))
84 toolbar
->SetToolBitmapSize(bmpsize
);
85 wxSize margins
= GetSize(wxT("margins"));
86 if (!(margins
== wxDefaultSize
))
87 toolbar
->SetMargins(margins
.x
, margins
.y
);
88 long packing
= GetLong(wxT("packing"), -1);
90 toolbar
->SetToolPacking(packing
);
91 long separation
= GetLong(wxT("separation"), -1);
93 toolbar
->SetToolSeparation(separation
);
95 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
97 children_node
= GetParamNode(wxT("object_ref"));
99 if (children_node
== NULL
) return toolbar
;
104 wxXmlNode
*n
= children_node
;
108 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
109 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
111 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
112 wxControl
*control
= wxDynamicCast(created
, wxControl
);
113 if (!IsOfClass(n
, wxT("tool")) &&
114 !IsOfClass(n
, wxT("separator")) &&
116 toolbar
->AddControl(control
);
126 // FIXME: how can I create a toolbar without immediately setting it to the frame?
127 if (m_parentAsWindow
)
129 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
131 parentFrame
->SetToolBar(toolbar
);
140 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
142 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
143 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
144 (m_isInside
&& IsOfClass(node
, wxT("separator"))));