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