]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_chckl.cpp
we need our own implementation because in wxmac wxIcon does not inherit from wxBitmap...
[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/////////////////////////////////////////////////////////////////////////////
f80ea77b 10
c575e45a 11#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
78d14f80
VS
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
621be1ec 22#if wxUSE_XRC
a1e4ec87 23
5e7ea8eb 24#if wxUSE_OWNER_DRAWN || !defined(__WXMSW__)
3037523a 25
78d14f80
VS
26#include "wx/xrc/xh_chckl.h"
27#include "wx/checklst.h"
02df3799 28#include "wx/intl.h"
56572188 29#include "wx/log.h"
78d14f80 30
56572188 31IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler)
854e189f 32
f80ea77b
WS
33wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler()
34: wxXmlResourceHandler(), m_insideBox(false)
78d14f80 35{
6ea1280c
VS
36 // wxListBox styles:
37 XRC_ADD_STYLE(wxLB_SINGLE);
38 XRC_ADD_STYLE(wxLB_MULTIPLE);
39 XRC_ADD_STYLE(wxLB_EXTENDED);
40 XRC_ADD_STYLE(wxLB_HSCROLL);
41 XRC_ADD_STYLE(wxLB_ALWAYS_SB);
42 XRC_ADD_STYLE(wxLB_NEEDED_SB);
43 XRC_ADD_STYLE(wxLB_SORT);
44
78d14f80
VS
45 AddWindowStyles();
46}
47
56572188 48wxObject *wxCheckListBoxXmlHandler::DoCreateResource()
f80ea77b 49{
56572188
VS
50 if (m_class == wxT("wxCheckListBox")
51#if WXWIN_COMPATIBILITY_2_4
52 || m_class == wxT("wxCheckList")
53#endif
54 )
78d14f80 55 {
56572188
VS
56#if WXWIN_COMPATIBILITY_2_4
57 if (m_class == wxT("wxCheckList"))
58 wxLogDebug(wxT("'wxCheckList' name is deprecated, use 'wxCheckListBox' instead."));
59#endif
78d14f80 60 // need to build the list of strings from children
f80ea77b 61 m_insideBox = true;
78d14f80
VS
62 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
63 wxString *strings = (wxString *) NULL;
544fee32 64 if (strList.GetCount() > 0)
78d14f80
VS
65 {
66 strings = new wxString[strList.GetCount()];
67 int count = strList.GetCount();
544fee32
VS
68 for(int i = 0; i < count; i++)
69 strings[i] = strList[i];
78d14f80
VS
70 }
71
544fee32 72 XRC_MAKE_INSTANCE(control, wxCheckListBox)
f2588180
VS
73
74 control->Create(m_parentAsWindow,
75 GetID(),
76 GetPosition(), GetSize(),
77 strList.GetCount(),
78 strings,
79 GetStyle(),
80 wxDefaultValidator,
81 GetName());
78d14f80
VS
82
83 // step through children myself (again.)
84 wxXmlNode *n = GetParamNode(wxT("content"));
85 if (n) n = n->GetChildren();
86 int i = 0;
87 while (n)
88 {
89 if (n->GetType() != wxXML_ELEMENT_NODE ||
90 n->GetName() != wxT("item"))
91 { n = n->GetNext(); continue; }
92
93 // checking boolean is a bit ugly here (see GetBool() )
94 wxString v = n->GetPropVal(wxT("checked"), wxEmptyString);
95 v.MakeLower();
96 if (v && v == wxT("1"))
f80ea77b 97 control->Check( i, true );
78d14f80 98
f80ea77b 99 i++;
78d14f80
VS
100 n = n->GetNext();
101 }
f80ea77b 102
78d14f80
VS
103 SetupWindow(control);
104
544fee32
VS
105 if (strings != NULL)
106 delete[] strings;
f80ea77b 107 strList.Clear(); // dump the strings
78d14f80
VS
108
109 return control;
110 }
111 else
112 {
113 // on the inside now.
114 // handle <item checked="boolean">Label</item>
115
116 // add to the list
74c107ba
VS
117 wxString str = GetNodeContent(m_node);
118 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
119 str = wxGetTranslation(str);
120 strList.Add(str);
78d14f80
VS
121 return NULL;
122 }
78d14f80
VS
123}
124
56572188 125bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
78d14f80 126{
56572188
VS
127 return (IsOfClass(node, wxT("wxCheckListBox")) ||
128#if WXWIN_COMPATIBILITY_2_4
129 IsOfClass(node, wxT("wxCheckList")) ||
130#endif
544fee32 131 (m_insideBox && node->GetName() == wxT("item")));
78d14f80
VS
132}
133
a1e4ec87 134#endif // wxUSE_OWNER_DRAWN || !defined(__WXMSW__)
84969af7 135
621be1ec 136#endif // wxUSE_XRC