]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_toolb.cpp
fixed incorrect XtVaXXX() function call (thanks to g++ 4 for detecting this!)
[wxWidgets.git] / src / xrc / xh_toolb.cpp
CommitLineData
78d14f80
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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
VS
20#include "wx/xrc/xh_toolb.h"
21#include "wx/toolbar.h"
f2588180 22#include "wx/frame.h"
78d14f80 23
854e189f
VS
24IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler)
25
f80ea77b
WS
26wxToolBarXmlHandler::wxToolBarXmlHandler()
27: wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL)
78d14f80 28{
544fee32
VS
29 XRC_ADD_STYLE(wxTB_FLAT);
30 XRC_ADD_STYLE(wxTB_DOCKABLE);
31 XRC_ADD_STYLE(wxTB_VERTICAL);
32 XRC_ADD_STYLE(wxTB_HORIZONTAL);
c37ffc1f
VS
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);
b29c9f3b 38 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT);
61b52e46 39 XRC_ADD_STYLE(wxTB_HORZ_TEXT);
ace1785b 40 AddWindowStyles();
78d14f80
VS
41}
42
78d14f80 43wxObject *wxToolBarXmlHandler::DoCreateResource()
f80ea77b 44{
78d14f80
VS
45 if (m_class == wxT("tool"))
46 {
b5d6954b 47 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
f80ea77b 48
c37ffc1f
VS
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
f80ea77b 62 {
c37ffc1f
VS
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;
f80ea77b 71 }
c37ffc1f
VS
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")));
114807c0
VZ
79
80 if ( GetBool(wxT("disabled")) )
81 m_toolbar->EnableTool(GetID(), false);
c37ffc1f 82 }
78d14f80
VS
83 return m_toolbar; // must return non-NULL
84 }
f80ea77b 85
78d14f80
VS
86 else if (m_class == wxT("separator"))
87 {
b5d6954b 88 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
78d14f80
VS
89 m_toolbar->AddSeparator();
90 return m_toolbar; // must return non-NULL
91 }
f80ea77b 92
78d14f80
VS
93 else /*<object class="wxToolBar">*/
94 {
95 int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
96#ifdef __WXMSW__
97 if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
98#endif
f2588180 99
544fee32 100 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
f80ea77b 101
f2588180
VS
102 toolbar->Create(m_parentAsWindow,
103 GetID(),
104 GetPosition(),
105 GetSize(),
106 style,
107 GetName());
78d14f80
VS
108
109 wxSize bmpsize = GetSize(wxT("bitmapsize"));
110 if (!(bmpsize == wxDefaultSize))
111 toolbar->SetToolBitmapSize(bmpsize);
112 wxSize margins = GetSize(wxT("margins"));
113 if (!(margins == wxDefaultSize))
114 toolbar->SetMargins(margins.x, margins.y);
115 long packing = GetLong(wxT("packing"), -1);
116 if (packing != -1)
117 toolbar->SetToolPacking(packing);
118 long separation = GetLong(wxT("separation"), -1);
119 if (separation != -1)
120 toolbar->SetToolSeparation(separation);
700dbceb
VZ
121 if (HasParam(wxT("bg")))
122 toolbar->SetBackgroundColour(GetColour(wxT("bg")));
78d14f80
VS
123
124 wxXmlNode *children_node = GetParamNode(wxT("object"));
f2588180
VS
125 if (!children_node)
126 children_node = GetParamNode(wxT("object_ref"));
127
78d14f80
VS
128 if (children_node == NULL) return toolbar;
129
f80ea77b 130 m_isInside = true;
78d14f80
VS
131 m_toolbar = toolbar;
132
133 wxXmlNode *n = children_node;
134
135 while (n)
136 {
f80ea77b 137 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
f2588180 138 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
78d14f80
VS
139 {
140 wxObject *created = CreateResFromNode(n, toolbar, NULL);
141 wxControl *control = wxDynamicCast(created, wxControl);
a42aa5d7
VS
142 if (!IsOfClass(n, wxT("tool")) &&
143 !IsOfClass(n, wxT("separator")) &&
78d14f80
VS
144 control != NULL)
145 toolbar->AddControl(control);
146 }
147 n = n->GetNext();
148 }
149
f80ea77b 150 m_isInside = false;
78d14f80
VS
151 m_toolbar = NULL;
152
153 toolbar->Realize();
f2588180 154
017b6a0d 155 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
f2588180
VS
156 {
157 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
158 if (parentFrame)
159 parentFrame->SetToolBar(toolbar);
160 }
161
78d14f80
VS
162 return toolbar;
163 }
164}
165
78d14f80
VS
166bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
167{
168 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
f80ea77b 169 (m_isInside && IsOfClass(node, wxT("tool"))) ||
78d14f80
VS
170 (m_isInside && IsOfClass(node, wxT("separator"))));
171}
172
a1e4ec87 173#endif // wxUSE_XRC && wxUSE_TOOLBAR