]>
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 wxBoxSizer
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
);
46 wxObject
*wxToolBarXmlHandler::DoCreateResource()
48 if (m_class
== wxT("tool"))
50 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
52 if (GetPosition() != wxDefaultPosition
)
54 m_toolbar
->AddTool(GetID(),
55 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
56 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
57 GetBool(wxT("toggle")),
61 GetText(wxT("tooltip")),
62 GetText(wxT("longhelp")));
66 wxItemKind kind
= wxITEM_NORMAL
;
67 if (GetBool(wxT("radio")))
69 if (GetBool(wxT("toggle")))
71 wxASSERT_MSG( kind
== wxITEM_NORMAL
,
72 _T("can't have both toggleable and radion button at once") );
75 m_toolbar
->AddTool(GetID(),
76 GetText(wxT("label")),
77 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
78 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
80 GetText(wxT("tooltip")),
81 GetText(wxT("longhelp")));
83 if ( GetBool(wxT("disabled")) )
84 m_toolbar
->EnableTool(GetID(), false);
86 return m_toolbar
; // must return non-NULL
89 else if (m_class
== wxT("separator"))
91 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
92 m_toolbar
->AddSeparator();
93 return m_toolbar
; // must return non-NULL
96 else /*<object class="wxToolBar">*/
98 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
100 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
103 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
105 toolbar
->Create(m_parentAsWindow
,
112 wxSize bmpsize
= GetSize(wxT("bitmapsize"));
113 if (!(bmpsize
== wxDefaultSize
))
114 toolbar
->SetToolBitmapSize(bmpsize
);
115 wxSize margins
= GetSize(wxT("margins"));
116 if (!(margins
== wxDefaultSize
))
117 toolbar
->SetMargins(margins
.x
, margins
.y
);
118 long packing
= GetLong(wxT("packing"), -1);
120 toolbar
->SetToolPacking(packing
);
121 long separation
= GetLong(wxT("separation"), -1);
122 if (separation
!= -1)
123 toolbar
->SetToolSeparation(separation
);
124 if (HasParam(wxT("bg")))
125 toolbar
->SetBackgroundColour(GetColour(wxT("bg")));
127 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
129 children_node
= GetParamNode(wxT("object_ref"));
131 if (children_node
== NULL
) return toolbar
;
136 wxXmlNode
*n
= children_node
;
140 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
141 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
143 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
144 wxControl
*control
= wxDynamicCast(created
, wxControl
);
145 if (!IsOfClass(n
, wxT("tool")) &&
146 !IsOfClass(n
, wxT("separator")) &&
148 toolbar
->AddControl(control
);
158 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
160 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
162 parentFrame
->SetToolBar(toolbar
);
169 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
171 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
172 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
173 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
176 #endif // wxUSE_XRC && wxUSE_TOOLBAR