]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_toolb.cpp
synthesize NM_RCLICK ourselves now that def window proc doesn't do it as we don't...
[wxWidgets.git] / src / xrc / xh_toolb.cpp
CommitLineData
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/////////////////////////////////////////////////////////////////////////////
f80ea77b 10
c575e45a 11#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
78d14f80
VS
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
621be1ec 22#if wxUSE_XRC && wxUSE_TOOLBAR
a1e4ec87 23
78d14f80
VS
24#include "wx/xrc/xh_toolb.h"
25#include "wx/toolbar.h"
f2588180 26#include "wx/frame.h"
78d14f80 27
854e189f
VS
28IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler)
29
f80ea77b
WS
30wxToolBarXmlHandler::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 47wxObject *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")));
83 }
78d14f80
VS
84 return m_toolbar; // must return non-NULL
85 }
f80ea77b 86
78d14f80
VS
87 else if (m_class == wxT("separator"))
88 {
b5d6954b 89 wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
78d14f80
VS
90 m_toolbar->AddSeparator();
91 return m_toolbar; // must return non-NULL
92 }
f80ea77b 93
78d14f80
VS
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
f2588180 100
544fee32 101 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
f80ea77b 102
f2588180
VS
103 toolbar->Create(m_parentAsWindow,
104 GetID(),
105 GetPosition(),
106 GetSize(),
107 style,
108 GetName());
78d14f80
VS
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"));
f2588180
VS
124 if (!children_node)
125 children_node = GetParamNode(wxT("object_ref"));
126
78d14f80
VS
127 if (children_node == NULL) return toolbar;
128
f80ea77b 129 m_isInside = true;
78d14f80
VS
130 m_toolbar = toolbar;
131
132 wxXmlNode *n = children_node;
133
134 while (n)
135 {
f80ea77b 136 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
f2588180 137 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
78d14f80
VS
138 {
139 wxObject *created = CreateResFromNode(n, toolbar, NULL);
140 wxControl *control = wxDynamicCast(created, wxControl);
a42aa5d7
VS
141 if (!IsOfClass(n, wxT("tool")) &&
142 !IsOfClass(n, wxT("separator")) &&
78d14f80
VS
143 control != NULL)
144 toolbar->AddControl(control);
145 }
146 n = n->GetNext();
147 }
148
f80ea77b 149 m_isInside = false;
78d14f80
VS
150 m_toolbar = NULL;
151
152 toolbar->Realize();
f2588180 153
017b6a0d 154 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
f2588180
VS
155 {
156 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
157 if (parentFrame)
158 parentFrame->SetToolBar(toolbar);
159 }
160
78d14f80
VS
161 return toolbar;
162 }
163}
164
78d14f80
VS
165bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
166{
167 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
f80ea77b 168 (m_isInside && IsOfClass(node, wxT("tool"))) ||
78d14f80
VS
169 (m_isInside && IsOfClass(node, wxT("separator"))));
170}
171
a1e4ec87 172#endif // wxUSE_XRC && wxUSE_TOOLBAR