]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_toolb.cpp
rebaked makefiles with 0.2.4 (and now with forgotten files)
[wxWidgets.git] / src / xrc / xh_toolb.cpp
CommitLineData
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"
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);
9583e4f4
VZ
43
44 XRC_ADD_STYLE(wxTB_TOP);
45 XRC_ADD_STYLE(wxTB_LEFT);
46 XRC_ADD_STYLE(wxTB_RIGHT);
47 XRC_ADD_STYLE(wxTB_BOTTOM);
48
ace1785b 49 AddWindowStyles();
78d14f80
VS
50}
51
78d14f80 52wxObject *wxToolBarXmlHandler::DoCreateResource()
f80ea77b 53{
78d14f80
VS
54 if (m_class == wxT("tool"))
55 {
b5d6954b 56 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
f80ea77b 57
e13edb66
VZ
58 wxItemKind kind = wxITEM_NORMAL;
59 if (GetBool(wxT("radio")))
60 kind = wxITEM_RADIO;
61 if (GetBool(wxT("toggle")))
c37ffc1f 62 {
e13edb66
VZ
63 wxASSERT_MSG( kind == wxITEM_NORMAL,
64 _T("can't have both toggle and radio button at once") );
65 kind = wxITEM_CHECK;
c37ffc1f 66 }
e13edb66
VZ
67 m_toolbar->AddTool(GetID(),
68 GetText(wxT("label")),
69 GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
70 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
71 kind,
72 GetText(wxT("tooltip")),
73 GetText(wxT("longhelp")));
74
75 if ( GetBool(wxT("disabled")) )
76 m_toolbar->EnableTool(GetID(), false);
77
78d14f80
VS
78 return m_toolbar; // must return non-NULL
79 }
f80ea77b 80
78d14f80
VS
81 else if (m_class == wxT("separator"))
82 {
b5d6954b 83 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
78d14f80
VS
84 m_toolbar->AddSeparator();
85 return m_toolbar; // must return non-NULL
86 }
f80ea77b 87
78d14f80
VS
88 else /*<object class="wxToolBar">*/
89 {
90 int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
91#ifdef __WXMSW__
92 if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
93#endif
f2588180 94
544fee32 95 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
f80ea77b 96
f2588180
VS
97 toolbar->Create(m_parentAsWindow,
98 GetID(),
99 GetPosition(),
100 GetSize(),
101 style,
102 GetName());
62311405 103 SetupWindow(toolbar);
78d14f80
VS
104
105 wxSize bmpsize = GetSize(wxT("bitmapsize"));
106 if (!(bmpsize == wxDefaultSize))
107 toolbar->SetToolBitmapSize(bmpsize);
108 wxSize margins = GetSize(wxT("margins"));
109 if (!(margins == wxDefaultSize))
110 toolbar->SetMargins(margins.x, margins.y);
111 long packing = GetLong(wxT("packing"), -1);
112 if (packing != -1)
113 toolbar->SetToolPacking(packing);
114 long separation = GetLong(wxT("separation"), -1);
115 if (separation != -1)
116 toolbar->SetToolSeparation(separation);
117
118 wxXmlNode *children_node = GetParamNode(wxT("object"));
f2588180
VS
119 if (!children_node)
120 children_node = GetParamNode(wxT("object_ref"));
121
78d14f80
VS
122 if (children_node == NULL) return toolbar;
123
f80ea77b 124 m_isInside = true;
78d14f80
VS
125 m_toolbar = toolbar;
126
127 wxXmlNode *n = children_node;
128
129 while (n)
130 {
f80ea77b 131 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
f2588180 132 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
78d14f80
VS
133 {
134 wxObject *created = CreateResFromNode(n, toolbar, NULL);
135 wxControl *control = wxDynamicCast(created, wxControl);
a42aa5d7
VS
136 if (!IsOfClass(n, wxT("tool")) &&
137 !IsOfClass(n, wxT("separator")) &&
78d14f80
VS
138 control != NULL)
139 toolbar->AddControl(control);
140 }
141 n = n->GetNext();
142 }
143
f80ea77b 144 m_isInside = false;
78d14f80
VS
145 m_toolbar = NULL;
146
147 toolbar->Realize();
f2588180 148
017b6a0d 149 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
f2588180
VS
150 {
151 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
152 if (parentFrame)
153 parentFrame->SetToolBar(toolbar);
154 }
155
78d14f80
VS
156 return toolbar;
157 }
158}
159
78d14f80
VS
160bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
161{
162 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
f80ea77b 163 (m_isInside && IsOfClass(node, wxT("tool"))) ||
78d14f80
VS
164 (m_isInside && IsOfClass(node, wxT("separator"))));
165}
166
a1e4ec87 167#endif // wxUSE_XRC && wxUSE_TOOLBAR