]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_listb.cpp
Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / src / xrc / xh_listb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_listb.cpp
3 // Purpose: XRC resource for wxListBox
4 // Author: Bob Mitchell & Vaclav Slavik
5 // Created: 2000/07/29
6 // Copyright: (c) 2000 Bob Mitchell and Verant Interactive
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_XRC && wxUSE_LISTBOX
18
19 #include "wx/xrc/xh_listb.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/intl.h"
23 #include "wx/listbox.h"
24 #endif
25
26 #include "wx/xml/xml.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxListBoxXmlHandler, wxXmlResourceHandler)
29
30 wxListBoxXmlHandler::wxListBoxXmlHandler()
31 : wxXmlResourceHandler(),
32 m_insideBox(false)
33 {
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);
41 AddWindowStyles();
42 }
43
44 wxObject *wxListBoxXmlHandler::DoCreateResource()
45 {
46 if ( m_class == wxT("wxListBox"))
47 {
48 // find the selection
49 long selection = GetLong(wxT("selection"), -1);
50
51 // need to build the list of strings from children
52 m_insideBox = true;
53 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
54 m_insideBox = false;
55
56 XRC_MAKE_INSTANCE(control, wxListBox)
57
58 control->Create(m_parentAsWindow,
59 GetID(),
60 GetPosition(), GetSize(),
61 strList,
62 GetStyle(),
63 wxDefaultValidator,
64 GetName());
65
66 if (selection != -1)
67 control->SetSelection(selection);
68
69 SetupWindow(control);
70 strList.Clear(); // dump the strings
71
72 return control;
73 }
74 else
75 {
76 // on the inside now.
77 // handle <item>Label</item>
78
79 // add to the list
80 wxString str = GetNodeContent(m_node);
81 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
82 str = wxGetTranslation(str, m_resource->GetDomain());
83 strList.Add(str);
84
85 return NULL;
86 }
87 }
88
89 bool wxListBoxXmlHandler::CanHandle(wxXmlNode *node)
90 {
91 return (IsOfClass(node, wxT("wxListBox")) ||
92 (m_insideBox && node->GetName() == wxT("item")));
93 }
94
95 #endif // wxUSE_XRC && wxUSE_LISTBOX