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