]>
Commit | Line | Data |
---|---|---|
78d14f80 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: xh_choic.cpp | |
b5d6954b | 3 | // Purpose: XRC resource for wxChoice |
78d14f80 VS |
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 | ///////////////////////////////////////////////////////////////////////////// | |
f80ea77b | 10 | |
78d14f80 VS |
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 | ||
621be1ec | 22 | #if wxUSE_XRC |
a1e4ec87 | 23 | |
78d14f80 VS |
24 | #include "wx/xrc/xh_choic.h" |
25 | #include "wx/choice.h" | |
02df3799 | 26 | #include "wx/intl.h" |
78d14f80 | 27 | |
854e189f VS |
28 | IMPLEMENT_DYNAMIC_CLASS(wxChoiceXmlHandler, wxXmlResourceHandler) |
29 | ||
f80ea77b WS |
30 | wxChoiceXmlHandler::wxChoiceXmlHandler() |
31 | : wxXmlResourceHandler() , m_insideBox(false) | |
78d14f80 | 32 | { |
544fee32 | 33 | XRC_ADD_STYLE(wxCB_SORT); |
78d14f80 VS |
34 | AddWindowStyles(); |
35 | } | |
36 | ||
37 | wxObject *wxChoiceXmlHandler::DoCreateResource() | |
f80ea77b | 38 | { |
78d14f80 VS |
39 | if( m_class == wxT("wxChoice")) |
40 | { | |
41 | // find the selection | |
544fee32 | 42 | long selection = GetLong(wxT("selection"), -1); |
78d14f80 VS |
43 | |
44 | // need to build the list of strings from children | |
f80ea77b | 45 | m_insideBox = true; |
544fee32 | 46 | CreateChildrenPrivately(NULL, GetParamNode(wxT("content"))); |
78d14f80 | 47 | wxString *strings = (wxString *) NULL; |
544fee32 | 48 | if (strList.GetCount() > 0) |
78d14f80 VS |
49 | { |
50 | strings = new wxString[strList.GetCount()]; | |
51 | int count = strList.GetCount(); | |
544fee32 | 52 | for (int i = 0; i < count; i++) |
78d14f80 VS |
53 | strings[i]=strList[i]; |
54 | } | |
55 | ||
544fee32 | 56 | XRC_MAKE_INSTANCE(control, wxChoice) |
f2588180 VS |
57 | |
58 | control->Create(m_parentAsWindow, | |
59 | GetID(), | |
60 | GetPosition(), GetSize(), | |
61 | strList.GetCount(), | |
62 | strings, | |
63 | GetStyle(), | |
64 | wxDefaultValidator, | |
65 | GetName()); | |
78d14f80 | 66 | |
544fee32 VS |
67 | if (selection != -1) |
68 | control->SetSelection(selection); | |
78d14f80 VS |
69 | |
70 | SetupWindow(control); | |
71 | ||
544fee32 VS |
72 | if (strings != NULL) |
73 | delete[] strings; | |
f80ea77b | 74 | strList.Clear(); // dump the strings |
78d14f80 VS |
75 | |
76 | return control; | |
77 | } | |
78 | else | |
79 | { | |
80 | // on the inside now. | |
81 | // handle <item>Label</item> | |
f80ea77b | 82 | |
78d14f80 | 83 | // add to the list |
74c107ba VS |
84 | wxString str = GetNodeContent(m_node); |
85 | if (m_resource->GetFlags() & wxXRC_USE_LOCALE) | |
86 | str = wxGetTranslation(str); | |
87 | strList.Add(str); | |
78d14f80 VS |
88 | |
89 | return NULL; | |
90 | } | |
78d14f80 VS |
91 | } |
92 | ||
78d14f80 VS |
93 | bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node) |
94 | { | |
95 | return (IsOfClass(node, wxT("wxChoice")) || | |
544fee32 | 96 | (m_insideBox && node->GetName() == wxT("item"))); |
78d14f80 | 97 | } |
a1e4ec87 | 98 | |
621be1ec | 99 | #endif // wxUSE_XRC |