]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolb.cpp
Include wx/radiobut.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / xrc / xh_toolb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_toolb.cpp
3 // Purpose: XRC resource for wxBoxSizer
4 // Author: Vaclav Slavik
5 // Created: 2000/08/11
6 // RCS-ID: $Id$
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_XRC && wxUSE_TOOLBAR
19
20 #include "wx/xrc/xh_toolb.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/frame.h"
24 #endif
25
26 #include "wx/toolbar.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler)
29
30 wxToolBarXmlHandler::wxToolBarXmlHandler()
31 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL)
32 {
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);
42 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT);
43 XRC_ADD_STYLE(wxTB_HORZ_TEXT);
44 AddWindowStyles();
45 }
46
47 wxObject *wxToolBarXmlHandler::DoCreateResource()
48 {
49 if (m_class == wxT("tool"))
50 {
51 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
52
53 if (GetPosition() != wxDefaultPosition)
54 {
55 m_toolbar->AddTool(GetID(),
56 GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
57 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
58 GetBool(wxT("toggle")),
59 GetPosition().x,
60 GetPosition().y,
61 NULL,
62 GetText(wxT("tooltip")),
63 GetText(wxT("longhelp")));
64 }
65 else
66 {
67 wxItemKind kind = wxITEM_NORMAL;
68 if (GetBool(wxT("radio")))
69 kind = wxITEM_RADIO;
70 if (GetBool(wxT("toggle")))
71 {
72 wxASSERT_MSG( kind == wxITEM_NORMAL,
73 _T("can't have both toggleable and radion button at once") );
74 kind = wxITEM_CHECK;
75 }
76 m_toolbar->AddTool(GetID(),
77 GetText(wxT("label")),
78 GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
79 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
80 kind,
81 GetText(wxT("tooltip")),
82 GetText(wxT("longhelp")));
83
84 if ( GetBool(wxT("disabled")) )
85 m_toolbar->EnableTool(GetID(), false);
86 }
87 return m_toolbar; // must return non-NULL
88 }
89
90 else if (m_class == wxT("separator"))
91 {
92 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
93 m_toolbar->AddSeparator();
94 return m_toolbar; // must return non-NULL
95 }
96
97 else /*<object class="wxToolBar">*/
98 {
99 int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
100 #ifdef __WXMSW__
101 if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
102 #endif
103
104 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
105
106 toolbar->Create(m_parentAsWindow,
107 GetID(),
108 GetPosition(),
109 GetSize(),
110 style,
111 GetName());
112
113 wxSize bmpsize = GetSize(wxT("bitmapsize"));
114 if (!(bmpsize == wxDefaultSize))
115 toolbar->SetToolBitmapSize(bmpsize);
116 wxSize margins = GetSize(wxT("margins"));
117 if (!(margins == wxDefaultSize))
118 toolbar->SetMargins(margins.x, margins.y);
119 long packing = GetLong(wxT("packing"), -1);
120 if (packing != -1)
121 toolbar->SetToolPacking(packing);
122 long separation = GetLong(wxT("separation"), -1);
123 if (separation != -1)
124 toolbar->SetToolSeparation(separation);
125 if (HasParam(wxT("bg")))
126 toolbar->SetBackgroundColour(GetColour(wxT("bg")));
127
128 wxXmlNode *children_node = GetParamNode(wxT("object"));
129 if (!children_node)
130 children_node = GetParamNode(wxT("object_ref"));
131
132 if (children_node == NULL) return toolbar;
133
134 m_isInside = true;
135 m_toolbar = toolbar;
136
137 wxXmlNode *n = children_node;
138
139 while (n)
140 {
141 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
142 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
143 {
144 wxObject *created = CreateResFromNode(n, toolbar, NULL);
145 wxControl *control = wxDynamicCast(created, wxControl);
146 if (!IsOfClass(n, wxT("tool")) &&
147 !IsOfClass(n, wxT("separator")) &&
148 control != NULL)
149 toolbar->AddControl(control);
150 }
151 n = n->GetNext();
152 }
153
154 m_isInside = false;
155 m_toolbar = NULL;
156
157 toolbar->Realize();
158
159 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
160 {
161 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
162 if (parentFrame)
163 parentFrame->SetToolBar(toolbar);
164 }
165
166 return toolbar;
167 }
168 }
169
170 bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
171 {
172 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
173 (m_isInside && IsOfClass(node, wxT("tool"))) ||
174 (m_isInside && IsOfClass(node, wxT("separator"))));
175 }
176
177 #endif // wxUSE_XRC && wxUSE_TOOLBAR