]>
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 | } |
073e1041 | 81 | #if wxUSE_MENUS |
e2517f17 VZ |
82 | // check whether we have dropdown tag inside |
83 | wxMenu *menu = NULL; // menu for drop down items | |
84 | wxXmlNode * const nodeDropdown = GetParamNode("dropdown"); | |
85 | if ( nodeDropdown ) | |
86 | { | |
07acc3cc VZ |
87 | if ( kind != wxITEM_NORMAL ) |
88 | { | |
819559b2 VS |
89 | ReportParamError |
90 | ( | |
91 | "dropdown", | |
92 | "drop-down tool can't have neither <radio> nor <toggle> properties" | |
93 | ); | |
07acc3cc | 94 | } |
e2517f17 VZ |
95 | |
96 | kind = wxITEM_DROPDOWN; | |
97 | ||
98 | // also check for the menu specified inside dropdown (it is | |
99 | // optional and may be absent for e.g. dynamically-created | |
100 | // menus) | |
101 | wxXmlNode * const nodeMenu = nodeDropdown->GetChildren(); | |
102 | if ( nodeMenu ) | |
103 | { | |
104 | wxObject *res = CreateResFromNode(nodeMenu, NULL); | |
105 | menu = wxDynamicCast(res, wxMenu); | |
07acc3cc VZ |
106 | if ( !menu ) |
107 | { | |
819559b2 VS |
108 | ReportError |
109 | ( | |
110 | nodeMenu, | |
111 | "drop-down tool contents can only be a wxMenu" | |
112 | ); | |
07acc3cc VZ |
113 | } |
114 | ||
115 | if ( nodeMenu->GetNext() ) | |
116 | { | |
819559b2 VS |
117 | ReportError |
118 | ( | |
119 | nodeMenu->GetNext(), | |
120 | "unexpected extra contents under drop-down tool" | |
121 | ); | |
07acc3cc | 122 | } |
e2517f17 VZ |
123 | } |
124 | } | |
073e1041 | 125 | #endif |
d0f06302 VS |
126 | wxToolBarToolBase * const tool = |
127 | m_toolbar->AddTool | |
128 | ( | |
129 | GetID(), | |
130 | GetText(wxT("label")), | |
131 | GetBitmap(wxT("bitmap"), wxART_TOOLBAR, m_toolSize), | |
132 | GetBitmap(wxT("bitmap2"), wxART_TOOLBAR, m_toolSize), | |
133 | kind, | |
134 | GetText(wxT("tooltip")), | |
135 | GetText(wxT("longhelp")) | |
136 | ); | |
e13edb66 VZ |
137 | |
138 | if ( GetBool(wxT("disabled")) ) | |
139 | m_toolbar->EnableTool(GetID(), false); | |
073e1041 | 140 | #if wxUSE_MENUS |
e2517f17 VZ |
141 | if ( menu ) |
142 | tool->SetDropdownMenu(menu); | |
073e1041 SC |
143 | #endif |
144 | ||
78d14f80 VS |
145 | return m_toolbar; // must return non-NULL |
146 | } | |
f80ea77b | 147 | |
5852e62f | 148 | else if (m_class == wxT("separator") || m_class == wxT("space")) |
78d14f80 | 149 | { |
07acc3cc VZ |
150 | if ( !m_toolbar ) |
151 | { | |
5852e62f | 152 | ReportError("separators only allowed inside wxToolBar"); |
07acc3cc VZ |
153 | return NULL; |
154 | } | |
5852e62f VZ |
155 | |
156 | if ( m_class == wxT("separator") ) | |
157 | m_toolbar->AddSeparator(); | |
158 | else | |
159 | m_toolbar->AddStretchableSpace(); | |
160 | ||
78d14f80 VS |
161 | return m_toolbar; // must return non-NULL |
162 | } | |
f80ea77b | 163 | |
78d14f80 VS |
164 | else /*<object class="wxToolBar">*/ |
165 | { | |
166 | int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL); | |
167 | #ifdef __WXMSW__ | |
168 | if (!(style & wxNO_BORDER)) style |= wxNO_BORDER; | |
169 | #endif | |
f2588180 | 170 | |
544fee32 | 171 | XRC_MAKE_INSTANCE(toolbar, wxToolBar) |
f80ea77b | 172 | |
f2588180 VS |
173 | toolbar->Create(m_parentAsWindow, |
174 | GetID(), | |
175 | GetPosition(), | |
176 | GetSize(), | |
177 | style, | |
178 | GetName()); | |
62311405 | 179 | SetupWindow(toolbar); |
78d14f80 | 180 | |
d0f06302 VS |
181 | m_toolSize = GetSize(wxT("bitmapsize")); |
182 | if (!(m_toolSize == wxDefaultSize)) | |
183 | toolbar->SetToolBitmapSize(m_toolSize); | |
78d14f80 VS |
184 | wxSize margins = GetSize(wxT("margins")); |
185 | if (!(margins == wxDefaultSize)) | |
186 | toolbar->SetMargins(margins.x, margins.y); | |
187 | long packing = GetLong(wxT("packing"), -1); | |
188 | if (packing != -1) | |
189 | toolbar->SetToolPacking(packing); | |
190 | long separation = GetLong(wxT("separation"), -1); | |
191 | if (separation != -1) | |
192 | toolbar->SetToolSeparation(separation); | |
193 | ||
194 | wxXmlNode *children_node = GetParamNode(wxT("object")); | |
f2588180 VS |
195 | if (!children_node) |
196 | children_node = GetParamNode(wxT("object_ref")); | |
197 | ||
78d14f80 VS |
198 | if (children_node == NULL) return toolbar; |
199 | ||
f80ea77b | 200 | m_isInside = true; |
78d14f80 VS |
201 | m_toolbar = toolbar; |
202 | ||
203 | wxXmlNode *n = children_node; | |
204 | ||
205 | while (n) | |
206 | { | |
f80ea77b | 207 | if ((n->GetType() == wxXML_ELEMENT_NODE) && |
f2588180 | 208 | (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref"))) |
78d14f80 VS |
209 | { |
210 | wxObject *created = CreateResFromNode(n, toolbar, NULL); | |
211 | wxControl *control = wxDynamicCast(created, wxControl); | |
a42aa5d7 VS |
212 | if (!IsOfClass(n, wxT("tool")) && |
213 | !IsOfClass(n, wxT("separator")) && | |
5852e62f | 214 | !IsOfClass(n, wxT("space")) && |
78d14f80 VS |
215 | control != NULL) |
216 | toolbar->AddControl(control); | |
217 | } | |
218 | n = n->GetNext(); | |
219 | } | |
220 | ||
f80ea77b | 221 | m_isInside = false; |
78d14f80 VS |
222 | m_toolbar = NULL; |
223 | ||
224 | toolbar->Realize(); | |
f2588180 | 225 | |
017b6a0d | 226 | if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe"))) |
f2588180 VS |
227 | { |
228 | wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame); | |
229 | if (parentFrame) | |
230 | parentFrame->SetToolBar(toolbar); | |
231 | } | |
232 | ||
78d14f80 VS |
233 | return toolbar; |
234 | } | |
235 | } | |
236 | ||
78d14f80 VS |
237 | bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node) |
238 | { | |
239 | return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) || | |
f80ea77b | 240 | (m_isInside && IsOfClass(node, wxT("tool"))) || |
5852e62f | 241 | (m_isInside && IsOfClass(node, wxT("space"))) || |
78d14f80 VS |
242 | (m_isInside && IsOfClass(node, wxT("separator")))); |
243 | } | |
244 | ||
a1e4ec87 | 245 | #endif // wxUSE_XRC && wxUSE_TOOLBAR |