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