]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_choic.cpp
don't reset the selection after event was vetoed if there is no old selection
[wxWidgets.git] / src / xrc / xh_choic.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/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 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_XRC && wxUSE_CHOICE
19
20 #include "wx/xrc/xh_choic.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/intl.h"
24 #include "wx/choice.h"
25 #endif
26
27 IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler, wxXmlResourceHandler)
28
29 wxChoiceXmlHandler::wxChoiceXmlHandler()
30 : wxXmlResourceHandler() , m_insideBox(false)
31 {
32 XRC_ADD_STYLE(wxCB_SORT);
33 AddWindowStyles();
34 }
35
36 wxObject *wxChoiceXmlHandler::DoCreateResource()
37 {
38 if( m_class == wxT("wxChoice"))
39 {
40 // find the selection
41 long selection = GetLong(wxT("selection"), -1);
42
43 // need to build the list of strings from children
44 m_insideBox = true;
45 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
46 wxString *strings = (wxString *) NULL;
47 if (strList.GetCount() > 0)
48 {
49 strings = new wxString[strList.GetCount()];
50 int count = strList.GetCount();
51 for (int i = 0; i < count; i++)
52 strings[i]=strList[i];
53 }
54
55 XRC_MAKE_INSTANCE(control, wxChoice)
56
57 control->Create(m_parentAsWindow,
58 GetID(),
59 GetPosition(), GetSize(),
60 strList.GetCount(),
61 strings,
62 GetStyle(),
63 wxDefaultValidator,
64 GetName());
65
66 if (selection != -1)
67 control->SetSelection(selection);
68
69 SetupWindow(control);
70
71 if (strings != NULL)
72 delete[] strings;
73 strList.Clear(); // dump the strings
74
75 return control;
76 }
77 else
78 {
79 // on the inside now.
80 // handle <item>Label</item>
81
82 // add to the list
83 wxString str = GetNodeContent(m_node);
84 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
85 str = wxGetTranslation(str, m_resource->GetDomain());
86 strList.Add(str);
87
88 return NULL;
89 }
90 }
91
92 bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
93 {
94 return (IsOfClass(node, wxT("wxChoice")) ||
95 (m_insideBox && node->GetName() == wxT("item")));
96 }
97
98 #endif // wxUSE_XRC && wxUSE_CHOICE