]>
Commit | Line | Data |
---|---|---|
78d14f80 | 1 | ///////////////////////////////////////////////////////////////////////////// |
76b49cf4 | 2 | // Name: src/xrc/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 | ///////////////////////////////////////////////////////////////////////////// | |
f80ea77b | 10 | |
78d14f80 VS |
11 | // For compilers that support precompilation, includes "wx.h". |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
621be1ec | 18 | #if wxUSE_XRC && wxUSE_TOOLBAR |
a1e4ec87 | 19 | |
78d14f80 | 20 | #include "wx/xrc/xh_toolb.h" |
76b49cf4 WS |
21 | |
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/frame.h" | |
24 | #endif | |
25 | ||
78d14f80 | 26 | #include "wx/toolbar.h" |
78d14f80 | 27 | |
854e189f VS |
28 | IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler) |
29 | ||
f80ea77b WS |
30 | wxToolBarXmlHandler::wxToolBarXmlHandler() |
31 | : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL) | |
78d14f80 | 32 | { |
544fee32 VS |
33 | XRC_ADD_STYLE(wxTB_FLAT); |
34 | XRC_ADD_STYLE(wxTB_DOCKABLE); | |
35 | XRC_ADD_STYLE(wxTB_VERTICAL); | |
36 | XRC_ADD_STYLE(wxTB_HORIZONTAL); | |
c37ffc1f VS |
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); | |
b29c9f3b | 42 | XRC_ADD_STYLE(wxTB_HORZ_LAYOUT); |
61b52e46 | 43 | XRC_ADD_STYLE(wxTB_HORZ_TEXT); |
ace1785b | 44 | AddWindowStyles(); |
78d14f80 VS |
45 | } |
46 | ||
78d14f80 | 47 | wxObject *wxToolBarXmlHandler::DoCreateResource() |
f80ea77b | 48 | { |
78d14f80 VS |
49 | if (m_class == wxT("tool")) |
50 | { | |
b5d6954b | 51 | wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!")); |
f80ea77b | 52 | |
c37ffc1f VS |
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 | |
f80ea77b | 66 | { |
c37ffc1f VS |
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; | |
f80ea77b | 75 | } |
c37ffc1f VS |
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"))); | |
114807c0 VZ |
83 | |
84 | if ( GetBool(wxT("disabled")) ) | |
85 | m_toolbar->EnableTool(GetID(), false); | |
c37ffc1f | 86 | } |
78d14f80 VS |
87 | return m_toolbar; // must return non-NULL |
88 | } | |
f80ea77b | 89 | |
78d14f80 VS |
90 | else if (m_class == wxT("separator")) |
91 | { | |
b5d6954b | 92 | wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!")); |
78d14f80 VS |
93 | m_toolbar->AddSeparator(); |
94 | return m_toolbar; // must return non-NULL | |
95 | } | |
f80ea77b | 96 | |
78d14f80 VS |
97 | else /*<object class="wxToolBar">*/ |
98 | { | |
99 | int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL); | |
100 | #ifdef __WXMSW__ | |
101 | if (!(style & wxNO_BORDER)) style |= wxNO_BORDER; | |
102 | #endif | |
f2588180 | 103 | |
544fee32 | 104 | XRC_MAKE_INSTANCE(toolbar, wxToolBar) |
f80ea77b | 105 | |
f2588180 VS |
106 | toolbar->Create(m_parentAsWindow, |
107 | GetID(), | |
108 | GetPosition(), | |
109 | GetSize(), | |
110 | style, | |
111 | GetName()); | |
78d14f80 VS |
112 | |
113 | wxSize bmpsize = GetSize(wxT("bitmapsize")); | |
114 | if (!(bmpsize == wxDefaultSize)) | |
115 | toolbar->SetToolBitmapSize(bmpsize); | |
116 | wxSize margins = GetSize(wxT("margins")); | |
117 | if (!(margins == wxDefaultSize)) | |
118 | toolbar->SetMargins(margins.x, margins.y); | |
119 | long packing = GetLong(wxT("packing"), -1); | |
120 | if (packing != -1) | |
121 | toolbar->SetToolPacking(packing); | |
122 | long separation = GetLong(wxT("separation"), -1); | |
123 | if (separation != -1) | |
124 | toolbar->SetToolSeparation(separation); | |
700dbceb VZ |
125 | if (HasParam(wxT("bg"))) |
126 | toolbar->SetBackgroundColour(GetColour(wxT("bg"))); | |
78d14f80 VS |
127 | |
128 | wxXmlNode *children_node = GetParamNode(wxT("object")); | |
f2588180 VS |
129 | if (!children_node) |
130 | children_node = GetParamNode(wxT("object_ref")); | |
131 | ||
78d14f80 VS |
132 | if (children_node == NULL) return toolbar; |
133 | ||
f80ea77b | 134 | m_isInside = true; |
78d14f80 VS |
135 | m_toolbar = toolbar; |
136 | ||
137 | wxXmlNode *n = children_node; | |
138 | ||
139 | while (n) | |
140 | { | |
f80ea77b | 141 | if ((n->GetType() == wxXML_ELEMENT_NODE) && |
f2588180 | 142 | (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref"))) |
78d14f80 VS |
143 | { |
144 | wxObject *created = CreateResFromNode(n, toolbar, NULL); | |
145 | wxControl *control = wxDynamicCast(created, wxControl); | |
a42aa5d7 VS |
146 | if (!IsOfClass(n, wxT("tool")) && |
147 | !IsOfClass(n, wxT("separator")) && | |
78d14f80 VS |
148 | control != NULL) |
149 | toolbar->AddControl(control); | |
150 | } | |
151 | n = n->GetNext(); | |
152 | } | |
153 | ||
f80ea77b | 154 | m_isInside = false; |
78d14f80 VS |
155 | m_toolbar = NULL; |
156 | ||
157 | toolbar->Realize(); | |
f2588180 | 158 | |
017b6a0d | 159 | if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe"))) |
f2588180 VS |
160 | { |
161 | wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame); | |
162 | if (parentFrame) | |
163 | parentFrame->SetToolBar(toolbar); | |
164 | } | |
165 | ||
78d14f80 VS |
166 | return toolbar; |
167 | } | |
168 | } | |
169 | ||
78d14f80 VS |
170 | bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node) |
171 | { | |
172 | return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) || | |
f80ea77b | 173 | (m_isInside && IsOfClass(node, wxT("tool"))) || |
78d14f80 VS |
174 | (m_isInside && IsOfClass(node, wxT("separator")))); |
175 | } | |
176 | ||
a1e4ec87 | 177 | #endif // wxUSE_XRC && wxUSE_TOOLBAR |