]>
Commit | Line | Data |
---|---|---|
8576d6a4 VS |
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() | |
ab708d5d | 29 | : wxXmlResourceHandler(), m_isInside(FALSE), m_toolbar(NULL) |
8576d6a4 VS |
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 | { | |
ab708d5d | 41 | if (m_class == wxT("tool")) |
8576d6a4 | 42 | { |
ab708d5d VS |
43 | wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XML resource: tool not within a toolbar!")); |
44 | m_toolbar->AddTool(GetID(), | |
a559d708 VS |
45 | GetBitmap(wxT("bitmap")), |
46 | GetBitmap(wxT("bitmap2")), | |
47 | GetBool(wxT("toggle")), | |
8576d6a4 VS |
48 | GetPosition().x, |
49 | GetPosition().y, | |
50 | NULL, | |
a559d708 VS |
51 | GetText(wxT("tooltip")), |
52 | GetText(wxT("longhelp"))); | |
ab708d5d | 53 | return m_toolbar; // must return non-NULL |
8576d6a4 VS |
54 | } |
55 | ||
ab708d5d | 56 | else if (m_class == wxT("separator")) |
8576d6a4 | 57 | { |
ab708d5d VS |
58 | wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XML resource: separator not within a toolbar!")); |
59 | m_toolbar->AddSeparator(); | |
60 | return m_toolbar; // must return non-NULL | |
8576d6a4 VS |
61 | } |
62 | ||
e066e256 | 63 | else /*<object class="wxToolBar">*/ |
8576d6a4 | 64 | { |
a559d708 | 65 | int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL); |
81dc0f5d VS |
66 | #ifdef __WXMSW__ |
67 | if (!(style & wxNO_BORDER)) style |= wxNO_BORDER; | |
68 | #endif | |
ab708d5d | 69 | wxToolBar *toolbar = new wxToolBar(m_parentAsWindow, |
81dc0f5d VS |
70 | GetID(), |
71 | GetPosition(), | |
72 | GetSize(), | |
73 | style, | |
74 | GetName()); | |
8576d6a4 | 75 | |
a559d708 | 76 | wxSize bmpsize = GetSize(wxT("bitmapsize")); |
8576d6a4 VS |
77 | if (!(bmpsize == wxDefaultSize)) |
78 | toolbar->SetToolBitmapSize(bmpsize); | |
a559d708 | 79 | wxSize margins = GetSize(wxT("margins")); |
8576d6a4 VS |
80 | if (!(margins == wxDefaultSize)) |
81 | toolbar->SetMargins(margins.x, margins.y); | |
a559d708 | 82 | long packing = GetLong(wxT("packing"), -1); |
8576d6a4 VS |
83 | if (packing != -1) |
84 | toolbar->SetToolPacking(packing); | |
a559d708 | 85 | long separation = GetLong(wxT("separation"), -1); |
8576d6a4 VS |
86 | if (separation != -1) |
87 | toolbar->SetToolSeparation(separation); | |
88 | ||
a559d708 | 89 | wxXmlNode *children_node = GetParamNode(wxT("object")); |
8576d6a4 VS |
90 | if (children_node == NULL) return toolbar; |
91 | ||
ab708d5d VS |
92 | m_isInside = TRUE; |
93 | m_toolbar = toolbar; | |
8576d6a4 | 94 | |
e066e256 | 95 | wxXmlNode *n = children_node; |
8576d6a4 VS |
96 | |
97 | while (n) | |
98 | { | |
e066e256 | 99 | if (n->GetType() == wxXML_ELEMENT_NODE && |
a559d708 | 100 | n->GetName() == wxT("object")) |
8576d6a4 VS |
101 | { |
102 | wxObject *created = CreateResFromNode(n, toolbar, NULL); | |
103 | wxControl *control = wxDynamicCast(created, wxControl); | |
a559d708 VS |
104 | if (IsOfClass(n, wxT("tool")) && |
105 | IsOfClass(n, wxT("separator")) && | |
8576d6a4 VS |
106 | control != NULL) |
107 | toolbar->AddControl(control); | |
108 | } | |
109 | n = n->GetNext(); | |
110 | } | |
111 | ||
ab708d5d VS |
112 | m_isInside = FALSE; |
113 | m_toolbar = NULL; | |
8576d6a4 VS |
114 | |
115 | toolbar->Realize(); | |
116 | return toolbar; | |
117 | } | |
118 | } | |
119 | ||
120 | ||
121 | ||
122 | bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node) | |
123 | { | |
ab708d5d VS |
124 | return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) || |
125 | (m_isInside && IsOfClass(node, wxT("tool"))) || | |
126 | (m_isInside && IsOfClass(node, wxT("separator")))); | |
8576d6a4 VS |
127 | } |
128 | ||
129 | #endif |