]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolb.cpp
Cleanup
[wxWidgets.git] / src / xrc / xh_toolb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #include "wx/toolbar.h"
22 #include "wx/frame.h"
23
24 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler)
25
26 wxToolBarXmlHandler::wxToolBarXmlHandler()
27 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL)
28 {
29 XRC_ADD_STYLE(wxTB_FLAT);
30 XRC_ADD_STYLE(wxTB_DOCKABLE);
31 XRC_ADD_STYLE(wxTB_VERTICAL);
32 XRC_ADD_STYLE(wxTB_HORIZONTAL);
33 XRC_ADD_STYLE(wxTB_3DBUTTONS);
34 XRC_ADD_STYLE(wxTB_TEXT);
35 XRC_ADD_STYLE(wxTB_NOICONS);
36 XRC_ADD_STYLE(wxTB_NODIVIDER);
37 XRC_ADD_STYLE(wxTB_NOALIGN);
38 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT);
39 XRC_ADD_STYLE(wxTB_HORZ_TEXT);
40 AddWindowStyles();
41 }
42
43 wxObject *wxToolBarXmlHandler::DoCreateResource()
44 {
45 if (m_class == wxT("tool"))
46 {
47 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
48
49 if (GetPosition() != wxDefaultPosition)
50 {
51 m_toolbar->AddTool(GetID(),
52 GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
53 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
54 GetBool(wxT("toggle")),
55 GetPosition().x,
56 GetPosition().y,
57 NULL,
58 GetText(wxT("tooltip")),
59 GetText(wxT("longhelp")));
60 }
61 else
62 {
63 wxItemKind kind = wxITEM_NORMAL;
64 if (GetBool(wxT("radio")))
65 kind = wxITEM_RADIO;
66 if (GetBool(wxT("toggle")))
67 {
68 wxASSERT_MSG( kind == wxITEM_NORMAL,
69 _T("can't have both toggleable and radion button at once") );
70 kind = wxITEM_CHECK;
71 }
72 m_toolbar->AddTool(GetID(),
73 GetText(wxT("label")),
74 GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
75 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
76 kind,
77 GetText(wxT("tooltip")),
78 GetText(wxT("longhelp")));
79 }
80 return m_toolbar; // must return non-NULL
81 }
82
83 else if (m_class == wxT("separator"))
84 {
85 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
86 m_toolbar->AddSeparator();
87 return m_toolbar; // must return non-NULL
88 }
89
90 else /*<object class="wxToolBar">*/
91 {
92 int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
93 #ifdef __WXMSW__
94 if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
95 #endif
96
97 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
98
99 toolbar->Create(m_parentAsWindow,
100 GetID(),
101 GetPosition(),
102 GetSize(),
103 style,
104 GetName());
105
106 wxSize bmpsize = GetSize(wxT("bitmapsize"));
107 if (!(bmpsize == wxDefaultSize))
108 toolbar->SetToolBitmapSize(bmpsize);
109 wxSize margins = GetSize(wxT("margins"));
110 if (!(margins == wxDefaultSize))
111 toolbar->SetMargins(margins.x, margins.y);
112 long packing = GetLong(wxT("packing"), -1);
113 if (packing != -1)
114 toolbar->SetToolPacking(packing);
115 long separation = GetLong(wxT("separation"), -1);
116 if (separation != -1)
117 toolbar->SetToolSeparation(separation);
118
119 wxXmlNode *children_node = GetParamNode(wxT("object"));
120 if (!children_node)
121 children_node = GetParamNode(wxT("object_ref"));
122
123 if (children_node == NULL) return toolbar;
124
125 m_isInside = true;
126 m_toolbar = toolbar;
127
128 wxXmlNode *n = children_node;
129
130 while (n)
131 {
132 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
133 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
134 {
135 wxObject *created = CreateResFromNode(n, toolbar, NULL);
136 wxControl *control = wxDynamicCast(created, wxControl);
137 if (!IsOfClass(n, wxT("tool")) &&
138 !IsOfClass(n, wxT("separator")) &&
139 control != NULL)
140 toolbar->AddControl(control);
141 }
142 n = n->GetNext();
143 }
144
145 m_isInside = false;
146 m_toolbar = NULL;
147
148 toolbar->Realize();
149
150 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
151 {
152 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
153 if (parentFrame)
154 parentFrame->SetToolBar(toolbar);
155 }
156
157 return toolbar;
158 }
159 }
160
161 bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
162 {
163 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
164 (m_isInside && IsOfClass(node, wxT("tool"))) ||
165 (m_isInside && IsOfClass(node, wxT("separator"))));
166 }
167
168 #endif // wxUSE_XRC && wxUSE_TOOLBAR