]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_toolb.cpp
ReadChar() is called GetChar() in fact
[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#ifdef __GNUG__
12#pragma implementation "xh_toolb.h"
13#endif
14
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
18#ifdef __BORLANDC__
19 #pragma hdrstop
20#endif
21
621be1ec 22#if wxUSE_XRC && wxUSE_TOOLBAR
a1e4ec87 23
78d14f80
VS
24#include "wx/xrc/xh_toolb.h"
25#include "wx/toolbar.h"
f2588180 26#include "wx/frame.h"
78d14f80 27
854e189f
VS
28IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler)
29
f80ea77b
WS
30wxToolBarXmlHandler::wxToolBarXmlHandler()
31: wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL)
78d14f80 32{
544fee32
VS
33 XRC_ADD_STYLE(wxTB_FLAT);
34 XRC_ADD_STYLE(wxTB_DOCKABLE);
35 XRC_ADD_STYLE(wxTB_VERTICAL);
36 XRC_ADD_STYLE(wxTB_HORIZONTAL);
c37ffc1f
VS
37 XRC_ADD_STYLE(wxTB_3DBUTTONS);
38 XRC_ADD_STYLE(wxTB_TEXT);
39 XRC_ADD_STYLE(wxTB_NOICONS);
40 XRC_ADD_STYLE(wxTB_NODIVIDER);
41 XRC_ADD_STYLE(wxTB_NOALIGN);
b29c9f3b 42 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT);
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")));
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);
121
122 wxXmlNode *children_node = GetParamNode(wxT("object"));
f2588180
VS
123 if (!children_node)
124 children_node = GetParamNode(wxT("object_ref"));
125
78d14f80
VS
126 if (children_node == NULL) return toolbar;
127
f80ea77b 128 m_isInside = true;
78d14f80
VS
129 m_toolbar = toolbar;
130
131 wxXmlNode *n = children_node;
132
133 while (n)
134 {
f80ea77b 135 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
f2588180 136 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
78d14f80
VS
137 {
138 wxObject *created = CreateResFromNode(n, toolbar, NULL);
139 wxControl *control = wxDynamicCast(created, wxControl);
a42aa5d7
VS
140 if (!IsOfClass(n, wxT("tool")) &&
141 !IsOfClass(n, wxT("separator")) &&
78d14f80
VS
142 control != NULL)
143 toolbar->AddControl(control);
144 }
145 n = n->GetNext();
146 }
147
f80ea77b 148 m_isInside = false;
78d14f80
VS
149 m_toolbar = NULL;
150
151 toolbar->Realize();
f2588180 152
017b6a0d 153 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
f2588180
VS
154 {
155 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
156 if (parentFrame)
157 parentFrame->SetToolBar(toolbar);
158 }
159
78d14f80
VS
160 return toolbar;
161 }
162}
163
78d14f80
VS
164bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
165{
166 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
f80ea77b 167 (m_isInside && IsOfClass(node, wxT("tool"))) ||
78d14f80
VS
168 (m_isInside && IsOfClass(node, wxT("separator"))));
169}
170
a1e4ec87 171#endif // wxUSE_XRC && wxUSE_TOOLBAR