]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/xrc/xh_chckl.cpp
implemented subclassing in XRC
[wxWidgets.git] / contrib / src / xrc / xh_chckl.cpp
CommitLineData
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
22#include "wx/xrc/xh_chckl.h"
23#include "wx/checklst.h"
24
25wxCheckListXmlHandler::wxCheckListXmlHandler()
26: wxXmlResourceHandler(), m_insideBox(FALSE)
27{
28 // no styles
29 AddWindowStyles();
30}
31
32wxObject *wxCheckListXmlHandler::DoCreateResource()
33{
34 if (m_class == wxT("wxCheckList"))
35 {
36 // need to build the list of strings from children
37 m_insideBox = TRUE;
38 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
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
f2588180 48 wxCheckListBox *control = wxStaticCast(m_instance, wxCheckListBox);
78d14f80 49
f2588180
VS
50 if (!control)
51 control = new wxCheckListBox;
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
84 if( strings != NULL )
85 delete [] strings;
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
96 strList.Add( GetNodeContent(m_node) );
97
98 return NULL;
99 }
100
101}
102
103
104
105bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
106{
107 return (IsOfClass(node, wxT("wxCheckList")) ||
108 (m_insideBox && node->GetName() == wxT("item"))
109 );
110}
111
112