]>
git.saurik.com Git - wxWidgets.git/blob - contrib/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
)
31 XRC_ADD_STYLE(wxTB_FLAT
);
32 XRC_ADD_STYLE(wxTB_DOCKABLE
);
33 XRC_ADD_STYLE(wxTB_VERTICAL
);
34 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
35 XRC_ADD_STYLE(wxTB_3DBUTTONS
);
36 XRC_ADD_STYLE(wxTB_TEXT
);
37 XRC_ADD_STYLE(wxTB_NOICONS
);
38 XRC_ADD_STYLE(wxTB_NODIVIDER
);
39 XRC_ADD_STYLE(wxTB_NOALIGN
);
42 wxObject
*wxToolBarXmlHandler::DoCreateResource()
44 if (m_class
== wxT("tool"))
46 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
48 if (GetPosition() != wxDefaultPosition
)
50 m_toolbar
->AddTool(GetID(),
51 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
52 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
53 GetBool(wxT("toggle")),
57 GetText(wxT("tooltip")),
58 GetText(wxT("longhelp")));
62 wxItemKind kind
= wxITEM_NORMAL
;
63 if (GetBool(wxT("radio")))
65 if (GetBool(wxT("toggle")))
67 wxASSERT_MSG( kind
== wxITEM_NORMAL
,
68 _T("can't have both toggleable and radion button at once") );
71 m_toolbar
->AddTool(GetID(),
72 GetText(wxT("label")),
73 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
74 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
76 GetText(wxT("tooltip")),
77 GetText(wxT("longhelp")));
79 return m_toolbar
; // must return non-NULL
82 else if (m_class
== wxT("separator"))
84 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
85 m_toolbar
->AddSeparator();
86 return m_toolbar
; // must return non-NULL
89 else /*<object class="wxToolBar">*/
91 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
93 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
96 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
98 toolbar
->Create(m_parentAsWindow
,
105 wxSize bmpsize
= GetSize(wxT("bitmapsize"));
106 if (!(bmpsize
== wxDefaultSize
))
107 toolbar
->SetToolBitmapSize(bmpsize
);
108 wxSize margins
= GetSize(wxT("margins"));
109 if (!(margins
== wxDefaultSize
))
110 toolbar
->SetMargins(margins
.x
, margins
.y
);
111 long packing
= GetLong(wxT("packing"), -1);
113 toolbar
->SetToolPacking(packing
);
114 long separation
= GetLong(wxT("separation"), -1);
115 if (separation
!= -1)
116 toolbar
->SetToolSeparation(separation
);
118 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
120 children_node
= GetParamNode(wxT("object_ref"));
122 if (children_node
== NULL
) return toolbar
;
127 wxXmlNode
*n
= children_node
;
131 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
132 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
134 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
135 wxControl
*control
= wxDynamicCast(created
, wxControl
);
136 if (!IsOfClass(n
, wxT("tool")) &&
137 !IsOfClass(n
, wxT("separator")) &&
139 toolbar
->AddControl(control
);
149 // FIXME: how can I create a toolbar without immediately setting it to the frame?
150 if (m_parentAsWindow
)
152 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
154 parentFrame
->SetToolBar(toolbar
);
161 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
163 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
164 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
165 (m_isInside
&& IsOfClass(node
, wxT("separator"))));