]>
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"
26 #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 if ( GetBool(wxT("disabled")) )
85 m_toolbar
->EnableTool(GetID(), false);
87 return m_toolbar
; // must return non-NULL
90 else if (m_class
== wxT("separator"))
92 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
93 m_toolbar
->AddSeparator();
94 return m_toolbar
; // must return non-NULL
97 else /*<object class="wxToolBar">*/
99 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
101 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
104 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
106 toolbar
->Create(m_parentAsWindow
,
113 wxSize bmpsize
= GetSize(wxT("bitmapsize"));
114 if (!(bmpsize
== wxDefaultSize
))
115 toolbar
->SetToolBitmapSize(bmpsize
);
116 wxSize margins
= GetSize(wxT("margins"));
117 if (!(margins
== wxDefaultSize
))
118 toolbar
->SetMargins(margins
.x
, margins
.y
);
119 long packing
= GetLong(wxT("packing"), -1);
121 toolbar
->SetToolPacking(packing
);
122 long separation
= GetLong(wxT("separation"), -1);
123 if (separation
!= -1)
124 toolbar
->SetToolSeparation(separation
);
125 if (HasParam(wxT("bg")))
126 toolbar
->SetBackgroundColour(GetColour(wxT("bg")));
128 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
130 children_node
= GetParamNode(wxT("object_ref"));
132 if (children_node
== NULL
) return toolbar
;
137 wxXmlNode
*n
= children_node
;
141 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
142 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
144 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
145 wxControl
*control
= wxDynamicCast(created
, wxControl
);
146 if (!IsOfClass(n
, wxT("tool")) &&
147 !IsOfClass(n
, wxT("separator")) &&
149 toolbar
->AddControl(control
);
159 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
161 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
163 parentFrame
->SetToolBar(toolbar
);
170 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
172 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
173 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
174 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
177 #endif // wxUSE_XRC && wxUSE_TOOLBAR