]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_chckl.cpp
Added some missing copyright lines
[wxWidgets.git] / src / xrc / xh_chckl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_chckl.cpp
3 // Purpose: XRC 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 #if wxUSE_OWNER_DRAWN || !defined(__WXMSW__)
23
24 #include "wx/xrc/xh_chckl.h"
25 #include "wx/checklst.h"
26 #include "wx/intl.h"
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;
43 if (strList.GetCount() > 0)
44 {
45 strings = new wxString[strList.GetCount()];
46 int count = strList.GetCount();
47 for(int i = 0; i < count; i++)
48 strings[i] = strList[i];
49 }
50
51 XRC_MAKE_INSTANCE(control, wxCheckListBox)
52
53 control->Create(m_parentAsWindow,
54 GetID(),
55 GetPosition(), GetSize(),
56 strList.GetCount(),
57 strings,
58 GetStyle(),
59 wxDefaultValidator,
60 GetName());
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 wxString str = GetNodeContent(m_node);
97 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
98 str = wxGetTranslation(str);
99 strList.Add(str);
100 return NULL;
101 }
102 }
103
104 bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
105 {
106 return (IsOfClass(node, wxT("wxCheckList")) ||
107 (m_insideBox && node->GetName() == wxT("item")));
108 }
109
110 #endif
111