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