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