]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_choic.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_choic.cpp
3 // Purpose: XRC resource for wxChoice
4 // Author: Bob Mitchell
7 // Copyright: (c) 2000 Bob Mitchell and Verant Interactive
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/xrc/xh_choic.h"
26 #include "wx/choice.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler
, wxXmlResourceHandler
)
30 wxChoiceXmlHandler::wxChoiceXmlHandler()
31 : wxXmlResourceHandler() , m_insideBox(false)
33 XRC_ADD_STYLE(wxCB_SORT
);
37 wxObject
*wxChoiceXmlHandler::DoCreateResource()
39 if( m_class
== wxT("wxChoice"))
42 long selection
= GetLong(wxT("selection"), -1);
44 // need to build the list of strings from children
46 CreateChildrenPrivately(NULL
, GetParamNode(wxT("content")));
47 wxString
*strings
= (wxString
*) NULL
;
48 if (strList
.GetCount() > 0)
50 strings
= new wxString
[strList
.GetCount()];
51 int count
= strList
.GetCount();
52 for (int i
= 0; i
< count
; i
++)
53 strings
[i
]=strList
[i
];
56 XRC_MAKE_INSTANCE(control
, wxChoice
)
58 control
->Create(m_parentAsWindow
,
60 GetPosition(), GetSize(),
68 control
->SetSelection(selection
);
74 strList
.Clear(); // dump the strings
81 // handle <item>Label</item>
84 wxString str
= GetNodeContent(m_node
);
85 if (m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
86 str
= wxGetTranslation(str
);
93 bool wxChoiceXmlHandler::CanHandle(wxXmlNode
*node
)
95 return (IsOfClass(node
, wxT("wxChoice")) ||
96 (m_insideBox
&& node
->GetName() == wxT("item")));