]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/xml/xh_toolb.cpp
added toolbar handling
[wxWidgets.git] / contrib / src / xml / xh_toolb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_toolb.cpp
3 // Purpose: XML 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/xml/xh_toolb.h"
23 #include "wx/toolbar.h"
24
25
26 #if wxUSE_TOOLBAR
27
28 wxToolBarXmlHandler::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
39 wxObject *wxToolBarXmlHandler::DoCreateResource()
40 {
41 if (m_Node->GetName() == _T("tool"))
42 {
43 wxCHECK_MSG(m_Toolbar, NULL, _T("Incorrect syntax of XML resource: tool not within a toolbar!"));
44 m_Toolbar->AddTool(GetID(),
45 GetBitmap(_T("bitmap")),
46 GetBitmap(_T("bitmap2")),
47 GetBool(_T("toggle")),
48 GetPosition().x,
49 GetPosition().y,
50 NULL,
51 GetText(_T("tooltip")),
52 GetText(_T("longhelp")));
53 return m_Toolbar; // must return non-NULL
54 }
55
56 else if (m_Node->GetName() == _T("separator"))
57 {
58 wxCHECK_MSG(m_Toolbar, NULL, _T("Incorrect syntax of XML resource: separator not within a toolbar!"));
59 m_Toolbar->AddSeparator();
60 return m_Toolbar; // must return non-NULL
61 }
62
63 else /*<toolbar>*/
64 {
65 wxToolBar *toolbar = new wxToolBar(m_ParentAsWindow,
66 GetID(),
67 GetPosition(),
68 GetSize(),
69 GetStyle(),
70 GetName());
71
72 wxSize bmpsize = GetSize(_T("bitmapsize"));
73 if (!(bmpsize == wxDefaultSize))
74 toolbar->SetToolBitmapSize(bmpsize);
75 wxSize margins = GetSize(_T("margins"));
76 if (!(margins == wxDefaultSize))
77 toolbar->SetMargins(margins.x, margins.y);
78 long packing = GetLong(_T("packing"), -1);
79 if (packing != -1)
80 toolbar->SetToolPacking(packing);
81 long separation = GetLong(_T("separation"), -1);
82 if (separation != -1)
83 toolbar->SetToolSeparation(separation);
84
85
86 wxXmlNode *children_node = GetParamNode(_T("children"));
87 if (children_node == NULL) return toolbar;
88
89 m_IsInside = TRUE;
90 m_Toolbar = toolbar;
91
92 wxXmlNode *n = children_node->GetChildren();
93
94 while (n)
95 {
96 if (n->GetType() == wxXML_ELEMENT_NODE)
97 {
98 wxObject *created = CreateResFromNode(n, toolbar, NULL);
99 wxControl *control = wxDynamicCast(created, wxControl);
100 if (n->GetName() != _T("tool") &&
101 n->GetName() != _T("separator") &&
102 control != NULL)
103 toolbar->AddControl(control);
104 }
105 n = n->GetNext();
106 }
107
108 m_IsInside = FALSE;
109 m_Toolbar = NULL;
110
111 toolbar->Realize();
112 return toolbar;
113 }
114 }
115
116
117
118 bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
119 {
120 return ((!m_IsInside && node->GetName() == _T("toolbar")) ||
121 (m_IsInside && node->GetName() == _T("tool")) ||
122 (m_IsInside && node->GetName() == _T("separator")));
123 }
124
125 #endif