]>
Commit | Line | Data |
---|---|---|
78d14f80 | 1 | ///////////////////////////////////////////////////////////////////////////// |
76b49cf4 | 2 | // Name: src/xrc/xh_toolb.cpp |
dd47af27 | 3 | // Purpose: XRC resource for wxToolBar |
78d14f80 VS |
4 | // Author: Vaclav Slavik |
5 | // Created: 2000/08/11 | |
78d14f80 VS |
6 | // Copyright: (c) 2000 Vaclav Slavik |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
f80ea77b | 9 | |
78d14f80 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
621be1ec | 17 | #if wxUSE_XRC && wxUSE_TOOLBAR |
a1e4ec87 | 18 | |
78d14f80 | 19 | #include "wx/xrc/xh_toolb.h" |
76b49cf4 WS |
20 | |
21 | #ifndef WX_PRECOMP | |
22 | #include "wx/frame.h" | |
b935c45d VZ |
23 | #include "wx/log.h" |
24 | #include "wx/menu.h" | |
4e3e485b | 25 | #include "wx/toolbar.h" |
76b49cf4 WS |
26 | #endif |
27 | ||
df27f1dc VZ |
28 | #include "wx/xml/xml.h" |
29 | ||
854e189f VS |
30 | IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler) |
31 | ||
f80ea77b WS |
32 | wxToolBarXmlHandler::wxToolBarXmlHandler() |
33 | : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL) | |
78d14f80 | 34 | { |
544fee32 VS |
35 | XRC_ADD_STYLE(wxTB_FLAT); |
36 | XRC_ADD_STYLE(wxTB_DOCKABLE); | |
37 | XRC_ADD_STYLE(wxTB_VERTICAL); | |
38 | XRC_ADD_STYLE(wxTB_HORIZONTAL); | |
c37ffc1f VS |
39 | XRC_ADD_STYLE(wxTB_3DBUTTONS); |
40 | XRC_ADD_STYLE(wxTB_TEXT); | |
41 | XRC_ADD_STYLE(wxTB_NOICONS); | |
42 | XRC_ADD_STYLE(wxTB_NODIVIDER); | |
43 | XRC_ADD_STYLE(wxTB_NOALIGN); | |
b29c9f3b | 44 | XRC_ADD_STYLE(wxTB_HORZ_LAYOUT); |
61b52e46 | 45 | XRC_ADD_STYLE(wxTB_HORZ_TEXT); |
9583e4f4 VZ |
46 | |
47 | XRC_ADD_STYLE(wxTB_TOP); | |
48 | XRC_ADD_STYLE(wxTB_LEFT); | |
49 | XRC_ADD_STYLE(wxTB_RIGHT); | |
50 | XRC_ADD_STYLE(wxTB_BOTTOM); | |
51 | ||
ace1785b | 52 | AddWindowStyles(); |
78d14f80 VS |
53 | } |
54 | ||
78d14f80 | 55 | wxObject *wxToolBarXmlHandler::DoCreateResource() |
f80ea77b | 56 | { |
78d14f80 VS |
57 | if (m_class == wxT("tool")) |
58 | { | |
07acc3cc VZ |
59 | if ( !m_toolbar ) |
60 | { | |
819559b2 | 61 | ReportError("tool only allowed inside a wxToolBar"); |
07acc3cc VZ |
62 | return NULL; |
63 | } | |
f80ea77b | 64 | |
e13edb66 VZ |
65 | wxItemKind kind = wxITEM_NORMAL; |
66 | if (GetBool(wxT("radio"))) | |
67 | kind = wxITEM_RADIO; | |
e2517f17 | 68 | |
e13edb66 | 69 | if (GetBool(wxT("toggle"))) |
c37ffc1f | 70 | { |
07acc3cc VZ |
71 | if ( kind != wxITEM_NORMAL ) |
72 | { | |
819559b2 VS |
73 | ReportParamError |
74 | ( | |
75 | "toggle", | |
76 | "tool can't have both <radio> and <toggle> properties" | |
77 | ); | |
07acc3cc VZ |
78 | } |
79 | ||
e13edb66 | 80 | kind = wxITEM_CHECK; |
c37ffc1f | 81 | } |
f72ed385 | 82 | |
073e1041 | 83 | #if wxUSE_MENUS |
e2517f17 VZ |
84 | // check whether we have dropdown tag inside |
85 | wxMenu *menu = NULL; // menu for drop down items | |
86 | wxXmlNode * const nodeDropdown = GetParamNode("dropdown"); | |
87 | if ( nodeDropdown ) | |
88 | { | |
07acc3cc VZ |
89 | if ( kind != wxITEM_NORMAL ) |
90 | { | |
819559b2 VS |
91 | ReportParamError |
92 | ( | |
93 | "dropdown", | |
94 | "drop-down tool can't have neither <radio> nor <toggle> properties" | |
95 | ); | |
07acc3cc | 96 | } |
e2517f17 VZ |
97 | |
98 | kind = wxITEM_DROPDOWN; | |
99 | ||
100 | // also check for the menu specified inside dropdown (it is | |
101 | // optional and may be absent for e.g. dynamically-created | |
102 | // menus) | |
103 | wxXmlNode * const nodeMenu = nodeDropdown->GetChildren(); | |
104 | if ( nodeMenu ) | |
105 | { | |
106 | wxObject *res = CreateResFromNode(nodeMenu, NULL); | |
107 | menu = wxDynamicCast(res, wxMenu); | |
07acc3cc VZ |
108 | if ( !menu ) |
109 | { | |
819559b2 VS |
110 | ReportError |
111 | ( | |
112 | nodeMenu, | |
113 | "drop-down tool contents can only be a wxMenu" | |
114 | ); | |
07acc3cc VZ |
115 | } |
116 | ||
117 | if ( nodeMenu->GetNext() ) | |
118 | { | |
819559b2 VS |
119 | ReportError |
120 | ( | |
121 | nodeMenu->GetNext(), | |
122 | "unexpected extra contents under drop-down tool" | |
123 | ); | |
07acc3cc | 124 | } |
e2517f17 VZ |
125 | } |
126 | } | |
073e1041 | 127 | #endif |
d0f06302 VS |
128 | wxToolBarToolBase * const tool = |
129 | m_toolbar->AddTool | |
130 | ( | |
131 | GetID(), | |
132 | GetText(wxT("label")), | |
133 | GetBitmap(wxT("bitmap"), wxART_TOOLBAR, m_toolSize), | |
134 | GetBitmap(wxT("bitmap2"), wxART_TOOLBAR, m_toolSize), | |
135 | kind, | |
136 | GetText(wxT("tooltip")), | |
137 | GetText(wxT("longhelp")) | |
138 | ); | |
e13edb66 VZ |
139 | |
140 | if ( GetBool(wxT("disabled")) ) | |
141 | m_toolbar->EnableTool(GetID(), false); | |
f72ed385 VZ |
142 | |
143 | if ( GetBool(wxS("checked")) ) | |
144 | { | |
145 | if ( kind == wxITEM_NORMAL ) | |
146 | { | |
147 | ReportParamError | |
148 | ( | |
149 | "checked", | |
150 | "only <radio> nor <toggle> tools can be checked" | |
151 | ); | |
152 | } | |
153 | else | |
154 | { | |
155 | m_toolbar->ToggleTool(GetID(), true); | |
156 | } | |
157 | } | |
158 | ||
073e1041 | 159 | #if wxUSE_MENUS |
e2517f17 VZ |
160 | if ( menu ) |
161 | tool->SetDropdownMenu(menu); | |
073e1041 | 162 | #endif |
ce00f59b | 163 | |
78d14f80 VS |
164 | return m_toolbar; // must return non-NULL |
165 | } | |
f80ea77b | 166 | |
5852e62f | 167 | else if (m_class == wxT("separator") || m_class == wxT("space")) |
78d14f80 | 168 | { |
07acc3cc VZ |
169 | if ( !m_toolbar ) |
170 | { | |
5852e62f | 171 | ReportError("separators only allowed inside wxToolBar"); |
07acc3cc VZ |
172 | return NULL; |
173 | } | |
5852e62f VZ |
174 | |
175 | if ( m_class == wxT("separator") ) | |
176 | m_toolbar->AddSeparator(); | |
177 | else | |
178 | m_toolbar->AddStretchableSpace(); | |
179 | ||
78d14f80 VS |
180 | return m_toolbar; // must return non-NULL |
181 | } | |
f80ea77b | 182 | |
78d14f80 VS |
183 | else /*<object class="wxToolBar">*/ |
184 | { | |
185 | int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL); | |
186 | #ifdef __WXMSW__ | |
187 | if (!(style & wxNO_BORDER)) style |= wxNO_BORDER; | |
188 | #endif | |
f2588180 | 189 | |
544fee32 | 190 | XRC_MAKE_INSTANCE(toolbar, wxToolBar) |
f80ea77b | 191 | |
f2588180 VS |
192 | toolbar->Create(m_parentAsWindow, |
193 | GetID(), | |
194 | GetPosition(), | |
195 | GetSize(), | |
196 | style, | |
197 | GetName()); | |
62311405 | 198 | SetupWindow(toolbar); |
78d14f80 | 199 | |
d0f06302 VS |
200 | m_toolSize = GetSize(wxT("bitmapsize")); |
201 | if (!(m_toolSize == wxDefaultSize)) | |
202 | toolbar->SetToolBitmapSize(m_toolSize); | |
78d14f80 VS |
203 | wxSize margins = GetSize(wxT("margins")); |
204 | if (!(margins == wxDefaultSize)) | |
205 | toolbar->SetMargins(margins.x, margins.y); | |
206 | long packing = GetLong(wxT("packing"), -1); | |
207 | if (packing != -1) | |
208 | toolbar->SetToolPacking(packing); | |
209 | long separation = GetLong(wxT("separation"), -1); | |
210 | if (separation != -1) | |
211 | toolbar->SetToolSeparation(separation); | |
212 | ||
213 | wxXmlNode *children_node = GetParamNode(wxT("object")); | |
f2588180 VS |
214 | if (!children_node) |
215 | children_node = GetParamNode(wxT("object_ref")); | |
216 | ||
78d14f80 VS |
217 | if (children_node == NULL) return toolbar; |
218 | ||
f80ea77b | 219 | m_isInside = true; |
78d14f80 VS |
220 | m_toolbar = toolbar; |
221 | ||
222 | wxXmlNode *n = children_node; | |
223 | ||
224 | while (n) | |
225 | { | |
f80ea77b | 226 | if ((n->GetType() == wxXML_ELEMENT_NODE) && |
f2588180 | 227 | (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref"))) |
78d14f80 VS |
228 | { |
229 | wxObject *created = CreateResFromNode(n, toolbar, NULL); | |
230 | wxControl *control = wxDynamicCast(created, wxControl); | |
a42aa5d7 VS |
231 | if (!IsOfClass(n, wxT("tool")) && |
232 | !IsOfClass(n, wxT("separator")) && | |
5852e62f | 233 | !IsOfClass(n, wxT("space")) && |
78d14f80 VS |
234 | control != NULL) |
235 | toolbar->AddControl(control); | |
236 | } | |
237 | n = n->GetNext(); | |
238 | } | |
239 | ||
f80ea77b | 240 | m_isInside = false; |
78d14f80 VS |
241 | m_toolbar = NULL; |
242 | ||
017b6a0d | 243 | if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe"))) |
f2588180 VS |
244 | { |
245 | wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame); | |
246 | if (parentFrame) | |
247 | parentFrame->SetToolBar(toolbar); | |
248 | } | |
249 | ||
5c413e62 VS |
250 | toolbar->Realize(); |
251 | ||
78d14f80 VS |
252 | return toolbar; |
253 | } | |
254 | } | |
255 | ||
78d14f80 VS |
256 | bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node) |
257 | { | |
258 | return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) || | |
f80ea77b | 259 | (m_isInside && IsOfClass(node, wxT("tool"))) || |
5852e62f | 260 | (m_isInside && IsOfClass(node, wxT("space"))) || |
78d14f80 VS |
261 | (m_isInside && IsOfClass(node, wxT("separator")))); |
262 | } | |
263 | ||
a1e4ec87 | 264 | #endif // wxUSE_XRC && wxUSE_TOOLBAR |