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