]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/xrc/xh_chckl.cpp
must convert filename to URL
[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
5e7ea8eb 22#if wxUSE_OWNER_DRAWN || !defined(__WXMSW__)
3037523a 23
78d14f80
VS
24#include "wx/xrc/xh_chckl.h"
25#include "wx/checklst.h"
02df3799 26#include "wx/intl.h"
78d14f80 27
854e189f
VS
28IMPLEMENT_DYNAMIC_CLASS(wxCheckListXmlHandler, wxXmlResourceHandler)
29
78d14f80
VS
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;
544fee32 45 if (strList.GetCount() > 0)
78d14f80
VS
46 {
47 strings = new wxString[strList.GetCount()];
48 int count = strList.GetCount();
544fee32
VS
49 for(int i = 0; i < count; i++)
50 strings[i] = strList[i];
78d14f80
VS
51 }
52
544fee32 53 XRC_MAKE_INSTANCE(control, wxCheckListBox)
f2588180
VS
54
55 control->Create(m_parentAsWindow,
56 GetID(),
57 GetPosition(), GetSize(),
58 strList.GetCount(),
59 strings,
60 GetStyle(),
61 wxDefaultValidator,
62 GetName());
78d14f80
VS
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
544fee32
VS
86 if (strings != NULL)
87 delete[] strings;
78d14f80
VS
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
74c107ba
VS
98 wxString str = GetNodeContent(m_node);
99 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
100 str = wxGetTranslation(str);
101 strList.Add(str);
78d14f80
VS
102 return NULL;
103 }
78d14f80
VS
104}
105
78d14f80
VS
106bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
107{
108 return (IsOfClass(node, wxT("wxCheckList")) ||
544fee32 109 (m_insideBox && node->GetName() == wxT("item")));
78d14f80
VS
110}
111
9a8ffadd 112#endif
84969af7 113