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