]>
Commit | Line | Data |
---|---|---|
78d14f80 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | ///////////////////////////////////////////////////////////////////////////// | |
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" | |
f2588180 | 24 | #include "wx/frame.h" |
78d14f80 VS |
25 | |
26 | #if wxUSE_TOOLBAR | |
27 | ||
28 | wxToolBarXmlHandler::wxToolBarXmlHandler() | |
29 | : wxXmlResourceHandler(), m_isInside(FALSE), m_toolbar(NULL) | |
30 | { | |
544fee32 VS |
31 | XRC_ADD_STYLE(wxTB_FLAT); |
32 | XRC_ADD_STYLE(wxTB_DOCKABLE); | |
33 | XRC_ADD_STYLE(wxTB_VERTICAL); | |
34 | XRC_ADD_STYLE(wxTB_HORIZONTAL); | |
78d14f80 VS |
35 | } |
36 | ||
78d14f80 VS |
37 | wxObject *wxToolBarXmlHandler::DoCreateResource() |
38 | { | |
39 | if (m_class == wxT("tool")) | |
40 | { | |
b5d6954b | 41 | wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!")); |
78d14f80 VS |
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 | { | |
b5d6954b | 56 | wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!")); |
78d14f80 VS |
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 | |
f2588180 | 67 | |
544fee32 | 68 | XRC_MAKE_INSTANCE(toolbar, wxToolBar) |
f2588180 VS |
69 | |
70 | toolbar->Create(m_parentAsWindow, | |
71 | GetID(), | |
72 | GetPosition(), | |
73 | GetSize(), | |
74 | style, | |
75 | GetName()); | |
78d14f80 VS |
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")); | |
f2588180 VS |
91 | if (!children_node) |
92 | children_node = GetParamNode(wxT("object_ref")); | |
93 | ||
78d14f80 VS |
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 | { | |
f2588180 VS |
103 | if ((n->GetType() == wxXML_ELEMENT_NODE) && |
104 | (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref"))) | |
78d14f80 VS |
105 | { |
106 | wxObject *created = CreateResFromNode(n, toolbar, NULL); | |
107 | wxControl *control = wxDynamicCast(created, wxControl); | |
a42aa5d7 VS |
108 | if (!IsOfClass(n, wxT("tool")) && |
109 | !IsOfClass(n, wxT("separator")) && | |
78d14f80 VS |
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(); | |
f2588180 VS |
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 | ||
78d14f80 VS |
129 | return toolbar; |
130 | } | |
131 | } | |
132 | ||
78d14f80 VS |
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 |