]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_listb.cpp
corrected Get() return value
[wxWidgets.git] / src / xrc / xh_listb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_listb.cpp
3 // Purpose: XRC resource for wxListBox
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 /////////////////////////////////////////////////////////////////////////////
10
11 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
22 #if wxUSE_XRC
23
24 #include "wx/xrc/xh_listb.h"
25 #include "wx/listbox.h"
26 #include "wx/intl.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxListBoxXmlHandler, wxXmlResourceHandler)
29
30 wxListBoxXmlHandler::wxListBoxXmlHandler()
31 : wxXmlResourceHandler() , m_insideBox(false)
32 {
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);
40 AddWindowStyles();
41 }
42
43 wxObject *wxListBoxXmlHandler::DoCreateResource()
44 {
45 if( m_class == wxT("wxListBox"))
46 {
47 // find the selection
48 long selection = GetLong(wxT("selection"), -1);
49
50 // need to build the list of strings from children
51 m_insideBox = true;
52 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
53 wxString *strings = (wxString *) NULL;
54 if (strList.GetCount() > 0)
55 {
56 strings = new wxString[strList.GetCount()];
57 int count = strList.GetCount();
58 for (int i = 0; i < count; i++)
59 strings[i]=strList[i];
60 }
61
62 XRC_MAKE_INSTANCE(control, wxListBox)
63
64 control->Create(m_parentAsWindow,
65 GetID(),
66 GetPosition(), GetSize(),
67 strList.GetCount(),
68 strings,
69 GetStyle(),
70 wxDefaultValidator,
71 GetName());
72
73 if (selection != -1)
74 control->SetSelection(selection);
75
76 SetupWindow(control);
77
78 if (strings != NULL)
79 delete[] strings;
80 strList.Clear(); // dump the strings
81
82 return control;
83 }
84 else
85 {
86 // on the inside now.
87 // handle <item>Label</item>
88
89 // add to the list
90 wxString str = GetNodeContent(m_node);
91 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
92 str = wxGetTranslation(str);
93 strList.Add(str);
94
95 return NULL;
96 }
97 }
98
99 bool wxListBoxXmlHandler::CanHandle(wxXmlNode *node)
100 {
101 return (IsOfClass(node, wxT("wxListBox")) ||
102 (m_insideBox && node->GetName() == wxT("item")));
103 }
104
105 #endif // wxUSE_XRC