]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/xml/xh_chckl.cpp
added xml resources readme
[wxWidgets.git] / contrib / src / xml / xh_chckl.cpp
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()
26 : wxXmlResourceHandler(), m_InsideBox(FALSE)
27 {
28 // no styles
29 }
30
31 wxObject *wxCheckListXmlHandler::DoCreateResource()
32 {
33 if( m_Node->GetName() == _T("checklist"))
34 {
35 // need to build the list of strings from children
36 m_InsideBox = TRUE;
37 CreateChildren( NULL, TRUE /* only this handler */);
38 wxString *strings = (wxString *) NULL;
39 if( strList.GetCount() > 0 )
40 {
41 strings = new wxString[strList.GetCount()];
42 int count = strList.GetCount();
43 for( int i = 0; i < count; i++ )
44 strings[i]=strList[i];
45 }
46
47
48 wxCheckListBox *control = new wxCheckListBox(m_ParentAsWindow,
49 GetID(),
50 GetPosition(), GetSize(),
51 strList.GetCount(),
52 strings,
53 GetStyle(),
54 wxDefaultValidator,
55 GetName()
56 );
57
58 // step through children myself (again.)
59 wxXmlNode *n = GetParamNode(_T("children"));
60 if (n) n = n->GetChildren();
61 int i = 0;
62 while (n)
63 {
64 if (n->GetType() != wxXML_ELEMENT_NODE ||
65 n->GetName() != _T("item" ))
66 { n = n->GetNext(); continue; }
67
68 // checking boolean is a bit ugly here (see GetBool() )
69 wxString v = n->GetPropVal(_T("checked"), wxEmptyString);
70 v.MakeLower();
71 if (v)
72 {
73 if( v == _T("1") || v == _T("t") || v == _T("yes") ||
74 v == _T("on") || v == _T("true") )
75 {
76 control->Check( i, TRUE );
77 }
78 }
79
80 i++;
81 n = n->GetNext();
82 }
83
84 SetupWindow(control);
85
86 if( strings != NULL )
87 delete [] strings;
88 strList.Clear(); // dump the strings
89
90 return control;
91 }
92 else
93 {
94 // on the inside now.
95 // handle <item checked="boolean">Label</item>
96
97 // add to the list
98 strList.Add( GetNodeContent(m_Node) );
99
100 return NULL;
101 }
102
103 }
104
105
106
107 bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
108 {
109 return( node->GetName() == _T("checklist") ||
110 ( m_InsideBox &&
111 node->GetName() == _T("item" ))
112 );
113 }
114
115