]>
Commit | Line | Data |
---|---|---|
78d14f80 | 1 | ///////////////////////////////////////////////////////////////////////////// |
88a7a4e1 | 2 | // Name: src/xrc/xh_listb.cpp |
b5d6954b | 3 | // Purpose: XRC resource for wxListBox |
78d14f80 VS |
4 | // Author: Bob Mitchell & Vaclav Slavik |
5 | // Created: 2000/07/29 | |
78d14f80 VS |
6 | // Copyright: (c) 2000 Bob Mitchell and Verant Interactive |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
f80ea77b | 9 | |
78d14f80 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
2a673eb1 | 17 | #if wxUSE_XRC && wxUSE_LISTBOX |
a1e4ec87 | 18 | |
78d14f80 | 19 | #include "wx/xrc/xh_listb.h" |
88a7a4e1 WS |
20 | |
21 | #ifndef WX_PRECOMP | |
22 | #include "wx/intl.h" | |
2a673eb1 | 23 | #include "wx/listbox.h" |
88a7a4e1 WS |
24 | #endif |
25 | ||
df27f1dc VZ |
26 | #include "wx/xml/xml.h" |
27 | ||
854e189f VS |
28 | IMPLEMENT_DYNAMIC_CLASS(wxListBoxXmlHandler, wxXmlResourceHandler) |
29 | ||
f80ea77b | 30 | wxListBoxXmlHandler::wxListBoxXmlHandler() |
187d8152 VZ |
31 | : wxXmlResourceHandler(), |
32 | m_insideBox(false) | |
78d14f80 | 33 | { |
544fee32 VS |
34 | XRC_ADD_STYLE(wxLB_SINGLE); |
35 | XRC_ADD_STYLE(wxLB_MULTIPLE); | |
36 | XRC_ADD_STYLE(wxLB_EXTENDED); | |
37 | XRC_ADD_STYLE(wxLB_HSCROLL); | |
38 | XRC_ADD_STYLE(wxLB_ALWAYS_SB); | |
39 | XRC_ADD_STYLE(wxLB_NEEDED_SB); | |
40 | XRC_ADD_STYLE(wxLB_SORT); | |
78d14f80 VS |
41 | AddWindowStyles(); |
42 | } | |
43 | ||
44 | wxObject *wxListBoxXmlHandler::DoCreateResource() | |
f80ea77b | 45 | { |
187d8152 | 46 | if ( m_class == wxT("wxListBox")) |
78d14f80 VS |
47 | { |
48 | // find the selection | |
544fee32 | 49 | long selection = GetLong(wxT("selection"), -1); |
78d14f80 VS |
50 | |
51 | // need to build the list of strings from children | |
f80ea77b | 52 | m_insideBox = true; |
544fee32 | 53 | CreateChildrenPrivately(NULL, GetParamNode(wxT("content"))); |
187d8152 | 54 | m_insideBox = false; |
78d14f80 | 55 | |
544fee32 | 56 | XRC_MAKE_INSTANCE(control, wxListBox) |
f2588180 VS |
57 | |
58 | control->Create(m_parentAsWindow, | |
59 | GetID(), | |
60 | GetPosition(), GetSize(), | |
187d8152 | 61 | strList, |
f2588180 VS |
62 | GetStyle(), |
63 | wxDefaultValidator, | |
64 | GetName()); | |
78d14f80 | 65 | |
544fee32 VS |
66 | if (selection != -1) |
67 | control->SetSelection(selection); | |
78d14f80 VS |
68 | |
69 | SetupWindow(control); | |
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) | |
d4a724d4 | 82 | str = wxGetTranslation(str, m_resource->GetDomain()); |
74c107ba | 83 | strList.Add(str); |
78d14f80 VS |
84 | |
85 | return NULL; | |
86 | } | |
78d14f80 VS |
87 | } |
88 | ||
78d14f80 VS |
89 | bool wxListBoxXmlHandler::CanHandle(wxXmlNode *node) |
90 | { | |
91 | return (IsOfClass(node, wxT("wxListBox")) || | |
544fee32 | 92 | (m_insideBox && node->GetName() == wxT("item"))); |
78d14f80 | 93 | } |
a1e4ec87 | 94 | |
2a673eb1 | 95 | #endif // wxUSE_XRC && wxUSE_LISTBOX |