]>
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 #include "wx/xrc/xh_toolb.h"
23 #include "wx/toolbar.h"
28 wxToolBarXmlHandler::wxToolBarXmlHandler()
29 : wxXmlResourceHandler(), m_isInside(FALSE
), m_toolbar(NULL
)
31 XRC_ADD_STYLE(wxTB_FLAT
);
32 XRC_ADD_STYLE(wxTB_DOCKABLE
);
33 XRC_ADD_STYLE(wxTB_VERTICAL
);
34 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
37 wxObject
*wxToolBarXmlHandler::DoCreateResource()
39 if (m_class
== wxT("tool"))
41 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));
42 m_toolbar
->AddTool(GetID(),
43 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
44 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
45 GetBool(wxT("toggle")),
49 GetText(wxT("tooltip")),
50 GetText(wxT("longhelp")));
51 return m_toolbar
; // must return non-NULL
54 else if (m_class
== wxT("separator"))
56 wxCHECK_MSG(m_toolbar
, NULL
, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
57 m_toolbar
->AddSeparator();
58 return m_toolbar
; // must return non-NULL
61 else /*<object class="wxToolBar">*/
63 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
65 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
68 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
70 toolbar
->Create(m_parentAsWindow
,
77 wxSize bmpsize
= GetSize(wxT("bitmapsize"));
78 if (!(bmpsize
== wxDefaultSize
))
79 toolbar
->SetToolBitmapSize(bmpsize
);
80 wxSize margins
= GetSize(wxT("margins"));
81 if (!(margins
== wxDefaultSize
))
82 toolbar
->SetMargins(margins
.x
, margins
.y
);
83 long packing
= GetLong(wxT("packing"), -1);
85 toolbar
->SetToolPacking(packing
);
86 long separation
= GetLong(wxT("separation"), -1);
88 toolbar
->SetToolSeparation(separation
);
90 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
92 children_node
= GetParamNode(wxT("object_ref"));
94 if (children_node
== NULL
) return toolbar
;
99 wxXmlNode
*n
= children_node
;
103 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
104 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
106 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
107 wxControl
*control
= wxDynamicCast(created
, wxControl
);
108 if (!IsOfClass(n
, wxT("tool")) &&
109 !IsOfClass(n
, wxT("separator")) &&
111 toolbar
->AddControl(control
);
121 // FIXME: how can I create a toolbar without immediately setting it to the frame?
122 if (m_parentAsWindow
)
124 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
126 parentFrame
->SetToolBar(toolbar
);
133 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
135 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
136 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
137 (m_isInside
&& IsOfClass(node
, wxT("separator"))));