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