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