]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_chckl.cpp
todos, cleanups, detabified
[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_XRC
23
24 #if wxUSE_OWNER_DRAWN || !defined(__WXMSW__)
25
26 #include "wx/xrc/xh_chckl.h"
27 #include "wx/checklst.h"
28 #include "wx/intl.h"
29 #include "wx/log.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler)
32
33 wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler()
34 : wxXmlResourceHandler(), m_insideBox(false)
35 {
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
45 AddWindowStyles();
46 }
47
48 wxObject *wxCheckListBoxXmlHandler::DoCreateResource()
49 {
50 if (m_class == wxT("wxCheckListBox")
51 #if WXWIN_COMPATIBILITY_2_4
52 || m_class == wxT("wxCheckList")
53 #endif
54 )
55 {
56 #if WXWIN_COMPATIBILITY_2_4
57 if (m_class == wxT("wxCheckList"))
58 wxLogDebug(wxT("'wxCheckList' name is deprecated, use 'wxCheckListBox' instead."));
59 #endif
60 // need to build the list of strings from children
61 m_insideBox = true;
62 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
63 wxString *strings = (wxString *) NULL;
64 if (strList.GetCount() > 0)
65 {
66 strings = new wxString[strList.GetCount()];
67 int count = strList.GetCount();
68 for(int i = 0; i < count; i++)
69 strings[i] = strList[i];
70 }
71
72 XRC_MAKE_INSTANCE(control, wxCheckListBox)
73
74 control->Create(m_parentAsWindow,
75 GetID(),
76 GetPosition(), GetSize(),
77 strList.GetCount(),
78 strings,
79 GetStyle(),
80 wxDefaultValidator,
81 GetName());
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"))
97 control->Check( i, true );
98
99 i++;
100 n = n->GetNext();
101 }
102
103 SetupWindow(control);
104
105 if (strings != NULL)
106 delete[] strings;
107 strList.Clear(); // dump the strings
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
117 wxString str = GetNodeContent(m_node);
118 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
119 str = wxGetTranslation(str);
120 strList.Add(str);
121 return NULL;
122 }
123 }
124
125 bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
126 {
127 return (IsOfClass(node, wxT("wxCheckListBox")) ||
128 #if WXWIN_COMPATIBILITY_2_4
129 IsOfClass(node, wxT("wxCheckList")) ||
130 #endif
131 (m_insideBox && node->GetName() == wxT("item")));
132 }
133
134 #endif // wxUSE_OWNER_DRAWN || !defined(__WXMSW__)
135
136 #endif // wxUSE_XRC