]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_toolb.cpp
3 // Purpose: XRC resource for wxToolBar
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_XRC && wxUSE_TOOLBAR
20 #include "wx/xrc/xh_toolb.h"
24 #include "wx/toolbar.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler
, wxXmlResourceHandler
)
29 wxToolBarXmlHandler::wxToolBarXmlHandler()
30 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL
)
32 XRC_ADD_STYLE(wxTB_FLAT
);
33 XRC_ADD_STYLE(wxTB_DOCKABLE
);
34 XRC_ADD_STYLE(wxTB_VERTICAL
);
35 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
36 XRC_ADD_STYLE(wxTB_3DBUTTONS
);
37 XRC_ADD_STYLE(wxTB_TEXT
);
38 XRC_ADD_STYLE(wxTB_NOICONS
);
39 XRC_ADD_STYLE(wxTB_NODIVIDER
);
40 XRC_ADD_STYLE(wxTB_NOALIGN
);
41 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT
);
42 XRC_ADD_STYLE(wxTB_HORZ_TEXT
);
44 XRC_ADD_STYLE(wxTB_TOP
);
45 XRC_ADD_STYLE(wxTB_LEFT
);
46 XRC_ADD_STYLE(wxTB_RIGHT
);
47 XRC_ADD_STYLE(wxTB_BOTTOM
);
52 wxObject
*wxToolBarXmlHandler::DoCreateResource()
54 if (m_class
== wxT("tool"))
56 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
58 if (GetPosition() != wxDefaultPosition
)
60 m_toolbar
->AddTool(GetID(),
61 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
62 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
63 GetBool(wxT("toggle")),
67 GetText(wxT("tooltip")),
68 GetText(wxT("longhelp")));
72 wxItemKind kind
= wxITEM_NORMAL
;
73 if (GetBool(wxT("radio")))
75 if (GetBool(wxT("toggle")))
77 wxASSERT_MSG( kind
== wxITEM_NORMAL
,
78 _T("can't have both toggle and radio button at once") );
81 m_toolbar
->AddTool(GetID(),
82 GetText(wxT("label")),
83 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
84 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
86 GetText(wxT("tooltip")),
87 GetText(wxT("longhelp")));
89 if ( GetBool(wxT("disabled")) )
90 m_toolbar
->EnableTool(GetID(), false);
92 return m_toolbar
; // must return non-NULL
95 else if (m_class
== wxT("separator"))
97 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
98 m_toolbar
->AddSeparator();
99 return m_toolbar
; // must return non-NULL
102 else /*<object class="wxToolBar">*/
104 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
106 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
109 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
111 toolbar
->Create(m_parentAsWindow
,
118 wxSize bmpsize
= GetSize(wxT("bitmapsize"));
119 if (!(bmpsize
== wxDefaultSize
))
120 toolbar
->SetToolBitmapSize(bmpsize
);
121 wxSize margins
= GetSize(wxT("margins"));
122 if (!(margins
== wxDefaultSize
))
123 toolbar
->SetMargins(margins
.x
, margins
.y
);
124 long packing
= GetLong(wxT("packing"), -1);
126 toolbar
->SetToolPacking(packing
);
127 long separation
= GetLong(wxT("separation"), -1);
128 if (separation
!= -1)
129 toolbar
->SetToolSeparation(separation
);
130 if (HasParam(wxT("bg")))
131 toolbar
->SetBackgroundColour(GetColour(wxT("bg")));
133 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
135 children_node
= GetParamNode(wxT("object_ref"));
137 if (children_node
== NULL
) return toolbar
;
142 wxXmlNode
*n
= children_node
;
146 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
147 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
149 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
150 wxControl
*control
= wxDynamicCast(created
, wxControl
);
151 if (!IsOfClass(n
, wxT("tool")) &&
152 !IsOfClass(n
, wxT("separator")) &&
154 toolbar
->AddControl(control
);
164 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
166 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
168 parentFrame
->SetToolBar(toolbar
);
175 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
177 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
178 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
179 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
182 #endif // wxUSE_XRC && wxUSE_TOOLBAR