]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/xrc/xh_chckl.cpp
regenerated
[wxWidgets.git] / src / xrc / xh_chckl.cpp
... / ...
CommitLineData
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
28IMPLEMENT_DYNAMIC_CLASS(wxCheckListXmlHandler, wxXmlResourceHandler)
29
30wxCheckListXmlHandler::wxCheckListXmlHandler()
31: wxXmlResourceHandler(), m_insideBox(FALSE)
32{
33 // no styles
34 AddWindowStyles();
35}
36
37wxObject *wxCheckListXmlHandler::DoCreateResource()
38{
39 if (m_class == wxT("wxCheckList"))
40 {
41 // need to build the list of strings from children
42 m_insideBox = TRUE;
43 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
44 wxString *strings = (wxString *) NULL;
45 if (strList.GetCount() > 0)
46 {
47 strings = new wxString[strList.GetCount()];
48 int count = strList.GetCount();
49 for(int i = 0; i < count; i++)
50 strings[i] = strList[i];
51 }
52
53 XRC_MAKE_INSTANCE(control, wxCheckListBox)
54
55 control->Create(m_parentAsWindow,
56 GetID(),
57 GetPosition(), GetSize(),
58 strList.GetCount(),
59 strings,
60 GetStyle(),
61 wxDefaultValidator,
62 GetName());
63
64 // step through children myself (again.)
65 wxXmlNode *n = GetParamNode(wxT("content"));
66 if (n) n = n->GetChildren();
67 int i = 0;
68 while (n)
69 {
70 if (n->GetType() != wxXML_ELEMENT_NODE ||
71 n->GetName() != wxT("item"))
72 { n = n->GetNext(); continue; }
73
74 // checking boolean is a bit ugly here (see GetBool() )
75 wxString v = n->GetPropVal(wxT("checked"), wxEmptyString);
76 v.MakeLower();
77 if (v && v == wxT("1"))
78 control->Check( i, TRUE );
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 wxString str = GetNodeContent(m_node);
99 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
100 str = wxGetTranslation(str);
101 strList.Add(str);
102 return NULL;
103 }
104}
105
106bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
107{
108 return (IsOfClass(node, wxT("wxCheckList")) ||
109 (m_insideBox && node->GetName() == wxT("item")));
110}
111
112#endif
113