]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/xrc/xh_chckl.cpp
fixed loading of resource from ZIP files on MacOS
[wxWidgets.git] / contrib / 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 #include "wx/xrc/xh_chckl.h"
23 #include "wx/checklst.h"
24 #include "wx/intl.h"
25
26 wxCheckListXmlHandler::wxCheckListXmlHandler()
27 : wxXmlResourceHandler(), m_insideBox(FALSE)
28 {
29 // no styles
30 AddWindowStyles();
31 }
32
33 wxObject *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;
41 if (strList.GetCount() > 0)
42 {
43 strings = new wxString[strList.GetCount()];
44 int count = strList.GetCount();
45 for(int i = 0; i < count; i++)
46 strings[i] = strList[i];
47 }
48
49 XRC_MAKE_INSTANCE(control, wxCheckListBox)
50
51 control->Create(m_parentAsWindow,
52 GetID(),
53 GetPosition(), GetSize(),
54 strList.GetCount(),
55 strings,
56 GetStyle(),
57 wxDefaultValidator,
58 GetName());
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
82 if (strings != NULL)
83 delete[] strings;
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
94 wxString str = GetNodeContent(m_node);
95 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
96 str = wxGetTranslation(str);
97 strList.Add(str);
98 return NULL;
99 }
100 }
101
102 bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
103 {
104 return (IsOfClass(node, wxT("wxCheckList")) ||
105 (m_insideBox && node->GetName() == wxT("item")));
106 }
107
108