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