]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_choic.cpp
fixed XP sash rendering to really do something (using REBAR style didn't work but...
[wxWidgets.git] / src / xrc / xh_choic.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_choic.cpp
3 // Purpose: XRC resource for wxChoice
4 // Author: Bob Mitchell
5 // Created: 2000/03/21
6 // RCS-ID: $Id$
7 // Copyright: (c) 2000 Bob Mitchell and Verant Interactive
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "xh_choic.h"
13 #endif
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #if wxUSE_XRC
23
24 #include "wx/xrc/xh_choic.h"
25 #include "wx/choice.h"
26 #include "wx/intl.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler, wxXmlResourceHandler)
29
30 wxChoiceXmlHandler::wxChoiceXmlHandler()
31 : wxXmlResourceHandler() , m_insideBox(false)
32 {
33 XRC_ADD_STYLE(wxCB_SORT);
34 AddWindowStyles();
35 }
36
37 wxObject *wxChoiceXmlHandler::DoCreateResource()
38 {
39 if( m_class == wxT("wxChoice"))
40 {
41 // find the selection
42 long selection = GetLong(wxT("selection"), -1);
43
44 // need to build the list of strings from children
45 m_insideBox = true;
46 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
47 wxString *strings = (wxString *) NULL;
48 if (strList.GetCount() > 0)
49 {
50 strings = new wxString[strList.GetCount()];
51 int count = strList.GetCount();
52 for (int i = 0; i < count; i++)
53 strings[i]=strList[i];
54 }
55
56 XRC_MAKE_INSTANCE(control, wxChoice)
57
58 control->Create(m_parentAsWindow,
59 GetID(),
60 GetPosition(), GetSize(),
61 strList.GetCount(),
62 strings,
63 GetStyle(),
64 wxDefaultValidator,
65 GetName());
66
67 if (selection != -1)
68 control->SetSelection(selection);
69
70 SetupWindow(control);
71
72 if (strings != NULL)
73 delete[] strings;
74 strList.Clear(); // dump the strings
75
76 return control;
77 }
78 else
79 {
80 // on the inside now.
81 // handle <item>Label</item>
82
83 // add to the list
84 wxString str = GetNodeContent(m_node);
85 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
86 str = wxGetTranslation(str);
87 strList.Add(str);
88
89 return NULL;
90 }
91 }
92
93 bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
94 {
95 return (IsOfClass(node, wxT("wxChoice")) ||
96 (m_insideBox && node->GetName() == wxT("item")));
97 }
98
99 #endif // wxUSE_XRC