]>
Commit | Line | Data |
---|---|---|
78d14f80 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: xh_chckl.cpp | |
b5d6954b | 3 | // Purpose: XRC resource for wxCheckList |
78d14f80 VS |
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 | #ifdef __GNUG__ | |
12 | #pragma implementation "xh_chckl.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 | ||
5e7ea8eb | 22 | #if wxUSE_OWNER_DRAWN || !defined(__WXMSW__) |
3037523a | 23 | |
78d14f80 VS |
24 | #include "wx/xrc/xh_chckl.h" |
25 | #include "wx/checklst.h" | |
02df3799 | 26 | #include "wx/intl.h" |
78d14f80 VS |
27 | |
28 | wxCheckListXmlHandler::wxCheckListXmlHandler() | |
29 | : wxXmlResourceHandler(), m_insideBox(FALSE) | |
30 | { | |
31 | // no styles | |
32 | AddWindowStyles(); | |
33 | } | |
34 | ||
35 | wxObject *wxCheckListXmlHandler::DoCreateResource() | |
36 | { | |
37 | if (m_class == wxT("wxCheckList")) | |
38 | { | |
39 | // need to build the list of strings from children | |
40 | m_insideBox = TRUE; | |
41 | CreateChildrenPrivately(NULL, GetParamNode(wxT("content"))); | |
42 | wxString *strings = (wxString *) NULL; | |
544fee32 | 43 | if (strList.GetCount() > 0) |
78d14f80 VS |
44 | { |
45 | strings = new wxString[strList.GetCount()]; | |
46 | int count = strList.GetCount(); | |
544fee32 VS |
47 | for(int i = 0; i < count; i++) |
48 | strings[i] = strList[i]; | |
78d14f80 VS |
49 | } |
50 | ||
544fee32 | 51 | XRC_MAKE_INSTANCE(control, wxCheckListBox) |
f2588180 VS |
52 | |
53 | control->Create(m_parentAsWindow, | |
54 | GetID(), | |
55 | GetPosition(), GetSize(), | |
56 | strList.GetCount(), | |
57 | strings, | |
58 | GetStyle(), | |
59 | wxDefaultValidator, | |
60 | GetName()); | |
78d14f80 VS |
61 | |
62 | // step through children myself (again.) | |
63 | wxXmlNode *n = GetParamNode(wxT("content")); | |
64 | if (n) n = n->GetChildren(); | |
65 | int i = 0; | |
66 | while (n) | |
67 | { | |
68 | if (n->GetType() != wxXML_ELEMENT_NODE || | |
69 | n->GetName() != wxT("item")) | |
70 | { n = n->GetNext(); continue; } | |
71 | ||
72 | // checking boolean is a bit ugly here (see GetBool() ) | |
73 | wxString v = n->GetPropVal(wxT("checked"), wxEmptyString); | |
74 | v.MakeLower(); | |
75 | if (v && v == wxT("1")) | |
76 | control->Check( i, TRUE ); | |
77 | ||
78 | i++; | |
79 | n = n->GetNext(); | |
80 | } | |
81 | ||
82 | SetupWindow(control); | |
83 | ||
544fee32 VS |
84 | if (strings != NULL) |
85 | delete[] strings; | |
78d14f80 VS |
86 | strList.Clear(); // dump the strings |
87 | ||
88 | return control; | |
89 | } | |
90 | else | |
91 | { | |
92 | // on the inside now. | |
93 | // handle <item checked="boolean">Label</item> | |
94 | ||
95 | // add to the list | |
74c107ba VS |
96 | wxString str = GetNodeContent(m_node); |
97 | if (m_resource->GetFlags() & wxXRC_USE_LOCALE) | |
98 | str = wxGetTranslation(str); | |
99 | strList.Add(str); | |
78d14f80 VS |
100 | return NULL; |
101 | } | |
78d14f80 VS |
102 | } |
103 | ||
78d14f80 VS |
104 | bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node) |
105 | { | |
106 | return (IsOfClass(node, wxT("wxCheckList")) || | |
544fee32 | 107 | (m_insideBox && node->GetName() == wxT("item"))); |
78d14f80 VS |
108 | } |
109 | ||
9a8ffadd | 110 | #endif |