]>
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"
18 #if wxUSE_XRC && wxUSE_CHOICE
20 #include "wx/xrc/xh_choic.h"
24 #include "wx/choice.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler
, wxXmlResourceHandler
)
29 wxChoiceXmlHandler::wxChoiceXmlHandler()
30 : wxXmlResourceHandler() , m_insideBox(false)
32 XRC_ADD_STYLE(wxCB_SORT
);
36 wxObject
*wxChoiceXmlHandler::DoCreateResource()
38 if( m_class
== wxT("wxChoice"))
41 long selection
= GetLong(wxT("selection"), -1);
43 // need to build the list of strings from children
45 CreateChildrenPrivately(NULL
, GetParamNode(wxT("content")));
46 wxString
*strings
= (wxString
*) NULL
;
47 if (strList
.GetCount() > 0)
49 strings
= new wxString
[strList
.GetCount()];
50 int count
= strList
.GetCount();
51 for (int i
= 0; i
< count
; i
++)
52 strings
[i
]=strList
[i
];
55 XRC_MAKE_INSTANCE(control
, wxChoice
)
57 control
->Create(m_parentAsWindow
,
59 GetPosition(), GetSize(),
67 control
->SetSelection(selection
);
73 strList
.Clear(); // dump the strings
80 // handle <item>Label</item>
83 wxString str
= GetNodeContent(m_node
);
84 if (m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
85 str
= wxGetTranslation(str
, m_resource
->GetDomain());
92 bool wxChoiceXmlHandler::CanHandle(wxXmlNode
*node
)
94 return (IsOfClass(node
, wxT("wxChoice")) ||
95 (m_insideBox
&& node
->GetName() == wxT("item")));
98 #endif // wxUSE_XRC && wxUSE_CHOICE