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