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