]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_toolb.cpp
make sure all wxDefault* and all wxNull* global instances are documented
[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
c37ffc1f
VS
58 if (GetPosition() != wxDefaultPosition)
59 {
60 m_toolbar->AddTool(GetID(),
61 GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
62 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
63 GetBool(wxT("toggle")),
64 GetPosition().x,
65 GetPosition().y,
66 NULL,
67 GetText(wxT("tooltip")),
68 GetText(wxT("longhelp")));
69 }
70 else
f80ea77b 71 {
c37ffc1f
VS
72 wxItemKind kind = wxITEM_NORMAL;
73 if (GetBool(wxT("radio")))
74 kind = wxITEM_RADIO;
75 if (GetBool(wxT("toggle")))
76 {
77 wxASSERT_MSG( kind == wxITEM_NORMAL,
4efffd87 78 _T("can't have both toggle and radio button at once") );
c37ffc1f 79 kind = wxITEM_CHECK;
f80ea77b 80 }
c37ffc1f
VS
81 m_toolbar->AddTool(GetID(),
82 GetText(wxT("label")),
83 GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
84 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
85 kind,
86 GetText(wxT("tooltip")),
87 GetText(wxT("longhelp")));
114807c0
VZ
88
89 if ( GetBool(wxT("disabled")) )
90 m_toolbar->EnableTool(GetID(), false);
c37ffc1f 91 }
78d14f80
VS
92 return m_toolbar; // must return non-NULL
93 }
f80ea77b 94
78d14f80
VS
95 else if (m_class == wxT("separator"))
96 {
b5d6954b 97 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
78d14f80
VS
98 m_toolbar->AddSeparator();
99 return m_toolbar; // must return non-NULL
100 }
f80ea77b 101
78d14f80
VS
102 else /*<object class="wxToolBar">*/
103 {
104 int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
105#ifdef __WXMSW__
106 if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
107#endif
f2588180 108
544fee32 109 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
f80ea77b 110
f2588180
VS
111 toolbar->Create(m_parentAsWindow,
112 GetID(),
113 GetPosition(),
114 GetSize(),
115 style,
116 GetName());
78d14f80
VS
117
118 wxSize bmpsize = GetSize(wxT("bitmapsize"));
119 if (!(bmpsize == wxDefaultSize))
120 toolbar->SetToolBitmapSize(bmpsize);
121 wxSize margins = GetSize(wxT("margins"));
122 if (!(margins == wxDefaultSize))
123 toolbar->SetMargins(margins.x, margins.y);
124 long packing = GetLong(wxT("packing"), -1);
125 if (packing != -1)
126 toolbar->SetToolPacking(packing);
127 long separation = GetLong(wxT("separation"), -1);
128 if (separation != -1)
129 toolbar->SetToolSeparation(separation);
700dbceb
VZ
130 if (HasParam(wxT("bg")))
131 toolbar->SetBackgroundColour(GetColour(wxT("bg")));
78d14f80
VS
132
133 wxXmlNode *children_node = GetParamNode(wxT("object"));
f2588180
VS
134 if (!children_node)
135 children_node = GetParamNode(wxT("object_ref"));
136
78d14f80
VS
137 if (children_node == NULL) return toolbar;
138
f80ea77b 139 m_isInside = true;
78d14f80
VS
140 m_toolbar = toolbar;
141
142 wxXmlNode *n = children_node;
143
144 while (n)
145 {
f80ea77b 146 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
f2588180 147 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
78d14f80
VS
148 {
149 wxObject *created = CreateResFromNode(n, toolbar, NULL);
150 wxControl *control = wxDynamicCast(created, wxControl);
a42aa5d7
VS
151 if (!IsOfClass(n, wxT("tool")) &&
152 !IsOfClass(n, wxT("separator")) &&
78d14f80
VS
153 control != NULL)
154 toolbar->AddControl(control);
155 }
156 n = n->GetNext();
157 }
158
f80ea77b 159 m_isInside = false;
78d14f80
VS
160 m_toolbar = NULL;
161
162 toolbar->Realize();
f2588180 163
017b6a0d 164 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
f2588180
VS
165 {
166 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
167 if (parentFrame)
168 parentFrame->SetToolBar(toolbar);
169 }
170
78d14f80
VS
171 return toolbar;
172 }
173}
174
78d14f80
VS
175bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
176{
177 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
f80ea77b 178 (m_isInside && IsOfClass(node, wxT("tool"))) ||
78d14f80
VS
179 (m_isInside && IsOfClass(node, wxT("separator"))));
180}
181
a1e4ec87 182#endif // wxUSE_XRC && wxUSE_TOOLBAR