]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/xrc/xh_chckl.cpp | |
3 | // Purpose: XRC resource for wxCheckList | |
4 | // Author: Bob Mitchell | |
5 | // Created: 2000/03/21 | |
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_CHECKLISTBOX | |
19 | ||
20 | #include "wx/xrc/xh_chckl.h" | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/intl.h" | |
24 | #include "wx/log.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/checklst.h" | |
28 | ||
29 | IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler) | |
30 | ||
31 | wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler() | |
32 | : wxXmlResourceHandler(), m_insideBox(false) | |
33 | { | |
34 | // wxListBox styles: | |
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 | ||
43 | AddWindowStyles(); | |
44 | } | |
45 | ||
46 | wxObject *wxCheckListBoxXmlHandler::DoCreateResource() | |
47 | { | |
48 | if (m_class == wxT("wxCheckListBox") | |
49 | #if WXWIN_COMPATIBILITY_2_4 | |
50 | || m_class == wxT("wxCheckList") | |
51 | #endif | |
52 | ) | |
53 | { | |
54 | #if WXWIN_COMPATIBILITY_2_4 | |
55 | if (m_class == wxT("wxCheckList")) | |
56 | wxLogDebug(wxT("'wxCheckList' name is deprecated, use 'wxCheckListBox' instead.")); | |
57 | #endif | |
58 | // need to build the list of strings from children | |
59 | m_insideBox = true; | |
60 | CreateChildrenPrivately(NULL, GetParamNode(wxT("content"))); | |
61 | wxString *strings = (wxString *) NULL; | |
62 | if (strList.GetCount() > 0) | |
63 | { | |
64 | strings = new wxString[strList.GetCount()]; | |
65 | int count = strList.GetCount(); | |
66 | for(int i = 0; i < count; i++) | |
67 | strings[i] = strList[i]; | |
68 | } | |
69 | ||
70 | XRC_MAKE_INSTANCE(control, wxCheckListBox) | |
71 | ||
72 | control->Create(m_parentAsWindow, | |
73 | GetID(), | |
74 | GetPosition(), GetSize(), | |
75 | strList.GetCount(), | |
76 | strings, | |
77 | GetStyle(), | |
78 | wxDefaultValidator, | |
79 | GetName()); | |
80 | ||
81 | // step through children myself (again.) | |
82 | wxXmlNode *n = GetParamNode(wxT("content")); | |
83 | if (n) n = n->GetChildren(); | |
84 | int i = 0; | |
85 | while (n) | |
86 | { | |
87 | if (n->GetType() != wxXML_ELEMENT_NODE || | |
88 | n->GetName() != wxT("item")) | |
89 | { n = n->GetNext(); continue; } | |
90 | ||
91 | // checking boolean is a bit ugly here (see GetBool() ) | |
92 | wxString v = n->GetPropVal(wxT("checked"), wxEmptyString); | |
93 | v.MakeLower(); | |
94 | if (v && v == wxT("1")) | |
95 | control->Check( i, true ); | |
96 | ||
97 | i++; | |
98 | n = n->GetNext(); | |
99 | } | |
100 | ||
101 | SetupWindow(control); | |
102 | ||
103 | if (strings != NULL) | |
104 | delete[] strings; | |
105 | strList.Clear(); // dump the strings | |
106 | ||
107 | return control; | |
108 | } | |
109 | else | |
110 | { | |
111 | // on the inside now. | |
112 | // handle <item checked="boolean">Label</item> | |
113 | ||
114 | // add to the list | |
115 | wxString str = GetNodeContent(m_node); | |
116 | if (m_resource->GetFlags() & wxXRC_USE_LOCALE) | |
117 | str = wxGetTranslation(str); | |
118 | strList.Add(str); | |
119 | return NULL; | |
120 | } | |
121 | } | |
122 | ||
123 | bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node) | |
124 | { | |
125 | return (IsOfClass(node, wxT("wxCheckListBox")) || | |
126 | #if WXWIN_COMPATIBILITY_2_4 | |
127 | IsOfClass(node, wxT("wxCheckList")) || | |
128 | #endif | |
129 | (m_insideBox && node->GetName() == wxT("item"))); | |
130 | } | |
131 | ||
132 | #endif // wxUSE_XRC && wxUSE_CHECKLISTBOX |