]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolb.cpp
a7a569ead4fba2a5a403506b137bfaec176c422e
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 #if wxUSE_XRC && wxUSE_TOOLBAR
24 #include "wx/xrc/xh_toolb.h"
25 #include "wx/toolbar.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler
, wxXmlResourceHandler
)
30 wxToolBarXmlHandler::wxToolBarXmlHandler()
31 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL
)
33 XRC_ADD_STYLE(wxTB_FLAT
);
34 XRC_ADD_STYLE(wxTB_DOCKABLE
);
35 XRC_ADD_STYLE(wxTB_VERTICAL
);
36 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
37 XRC_ADD_STYLE(wxTB_3DBUTTONS
);
38 XRC_ADD_STYLE(wxTB_TEXT
);
39 XRC_ADD_STYLE(wxTB_NOICONS
);
40 XRC_ADD_STYLE(wxTB_NODIVIDER
);
41 XRC_ADD_STYLE(wxTB_NOALIGN
);
45 wxObject
*wxToolBarXmlHandler::DoCreateResource()
47 if (m_class
== wxT("tool"))
49 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
51 if (GetPosition() != wxDefaultPosition
)
53 m_toolbar
->AddTool(GetID(),
54 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
55 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
56 GetBool(wxT("toggle")),
60 GetText(wxT("tooltip")),
61 GetText(wxT("longhelp")));
65 wxItemKind kind
= wxITEM_NORMAL
;
66 if (GetBool(wxT("radio")))
68 if (GetBool(wxT("toggle")))
70 wxASSERT_MSG( kind
== wxITEM_NORMAL
,
71 _T("can't have both toggleable and radion button at once") );
74 m_toolbar
->AddTool(GetID(),
75 GetText(wxT("label")),
76 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
77 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
79 GetText(wxT("tooltip")),
80 GetText(wxT("longhelp")));
82 return m_toolbar
; // must return non-NULL
85 else if (m_class
== wxT("separator"))
87 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
88 m_toolbar
->AddSeparator();
89 return m_toolbar
; // must return non-NULL
92 else /*<object class="wxToolBar">*/
94 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
96 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
99 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
101 toolbar
->Create(m_parentAsWindow
,
108 wxSize bmpsize
= GetSize(wxT("bitmapsize"));
109 if (!(bmpsize
== wxDefaultSize
))
110 toolbar
->SetToolBitmapSize(bmpsize
);
111 wxSize margins
= GetSize(wxT("margins"));
112 if (!(margins
== wxDefaultSize
))
113 toolbar
->SetMargins(margins
.x
, margins
.y
);
114 long packing
= GetLong(wxT("packing"), -1);
116 toolbar
->SetToolPacking(packing
);
117 long separation
= GetLong(wxT("separation"), -1);
118 if (separation
!= -1)
119 toolbar
->SetToolSeparation(separation
);
121 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
123 children_node
= GetParamNode(wxT("object_ref"));
125 if (children_node
== NULL
) return toolbar
;
130 wxXmlNode
*n
= children_node
;
134 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
135 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
137 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
138 wxControl
*control
= wxDynamicCast(created
, wxControl
);
139 if (!IsOfClass(n
, wxT("tool")) &&
140 !IsOfClass(n
, wxT("separator")) &&
142 toolbar
->AddControl(control
);
152 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
154 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
156 parentFrame
->SetToolBar(toolbar
);
163 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
165 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
166 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
167 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
170 #endif // wxUSE_XRC && wxUSE_TOOLBAR