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