]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_chckl.cpp
Applied patch [ 607261 ] Fix: wxGrid: row and cell selection
[wxWidgets.git] / 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"
02df3799 24#include "wx/intl.h"
78d14f80
VS
25
26wxCheckListXmlHandler::wxCheckListXmlHandler()
27: wxXmlResourceHandler(), m_insideBox(FALSE)
28{
29 // no styles
30 AddWindowStyles();
31}
32
33wxObject *wxCheckListXmlHandler::DoCreateResource()
34{
35 if (m_class == wxT("wxCheckList"))
36 {
37 // need to build the list of strings from children
38 m_insideBox = TRUE;
39 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
40 wxString *strings = (wxString *) NULL;
544fee32 41 if (strList.GetCount() > 0)
78d14f80
VS
42 {
43 strings = new wxString[strList.GetCount()];
44 int count = strList.GetCount();
544fee32
VS
45 for(int i = 0; i < count; i++)
46 strings[i] = strList[i];
78d14f80
VS
47 }
48
544fee32 49 XRC_MAKE_INSTANCE(control, wxCheckListBox)
f2588180
VS
50
51 control->Create(m_parentAsWindow,
52 GetID(),
53 GetPosition(), GetSize(),
54 strList.GetCount(),
55 strings,
56 GetStyle(),
57 wxDefaultValidator,
58 GetName());
78d14f80
VS
59
60 // step through children myself (again.)
61 wxXmlNode *n = GetParamNode(wxT("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() != wxT("item"))
68 { n = n->GetNext(); continue; }
69
70 // checking boolean is a bit ugly here (see GetBool() )
71 wxString v = n->GetPropVal(wxT("checked"), wxEmptyString);
72 v.MakeLower();
73 if (v && v == wxT("1"))
74 control->Check( i, TRUE );
75
76 i++;
77 n = n->GetNext();
78 }
79
80 SetupWindow(control);
81
544fee32
VS
82 if (strings != NULL)
83 delete[] strings;
78d14f80
VS
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
74c107ba
VS
94 wxString str = GetNodeContent(m_node);
95 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
96 str = wxGetTranslation(str);
97 strList.Add(str);
78d14f80
VS
98 return NULL;
99 }
78d14f80
VS
100}
101
78d14f80
VS
102bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
103{
104 return (IsOfClass(node, wxT("wxCheckList")) ||
544fee32 105 (m_insideBox && node->GetName() == wxT("item")));
78d14f80
VS
106}
107
108