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