]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolb.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XRC resource for wxBoxSizer
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "xh_toolb.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #if wxUSE_XRC && wxUSE_TOOLBAR
24 #include "wx/xrc/xh_toolb.h"
25 #include "wx/toolbar.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler
, wxXmlResourceHandler
)
30 wxToolBarXmlHandler::wxToolBarXmlHandler()
31 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL
)
33 XRC_ADD_STYLE(wxTB_FLAT
);
34 XRC_ADD_STYLE(wxTB_DOCKABLE
);
35 XRC_ADD_STYLE(wxTB_VERTICAL
);
36 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
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
);
42 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT
);
43 XRC_ADD_STYLE(wxTB_HORZ_TEXT
);
47 wxObject
*wxToolBarXmlHandler::DoCreateResource()
49 if (m_class
== wxT("tool"))
51 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
53 if (GetPosition() != wxDefaultPosition
)
55 m_toolbar
->AddTool(GetID(),
56 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
57 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
58 GetBool(wxT("toggle")),
62 GetText(wxT("tooltip")),
63 GetText(wxT("longhelp")));
67 wxItemKind kind
= wxITEM_NORMAL
;
68 if (GetBool(wxT("radio")))
70 if (GetBool(wxT("toggle")))
72 wxASSERT_MSG( kind
== wxITEM_NORMAL
,
73 _T("can't have both toggleable and radion button at once") );
76 m_toolbar
->AddTool(GetID(),
77 GetText(wxT("label")),
78 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
79 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
81 GetText(wxT("tooltip")),
82 GetText(wxT("longhelp")));
84 return m_toolbar
; // must return non-NULL
87 else if (m_class
== wxT("separator"))
89 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
90 m_toolbar
->AddSeparator();
91 return m_toolbar
; // must return non-NULL
94 else /*<object class="wxToolBar">*/
96 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
98 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
101 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
103 toolbar
->Create(m_parentAsWindow
,
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);
118 toolbar
->SetToolPacking(packing
);
119 long separation
= GetLong(wxT("separation"), -1);
120 if (separation
!= -1)
121 toolbar
->SetToolSeparation(separation
);
123 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
125 children_node
= GetParamNode(wxT("object_ref"));
127 if (children_node
== NULL
) return toolbar
;
132 wxXmlNode
*n
= children_node
;
136 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
137 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
139 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
140 wxControl
*control
= wxDynamicCast(created
, wxControl
);
141 if (!IsOfClass(n
, wxT("tool")) &&
142 !IsOfClass(n
, wxT("separator")) &&
144 toolbar
->AddControl(control
);
154 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
156 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
158 parentFrame
->SetToolBar(toolbar
);
165 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
167 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
168 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
169 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
172 #endif // wxUSE_XRC && wxUSE_TOOLBAR