]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_chckl.cpp
first attempt at adding the minimal set needed for dead-key support, see #15345
[wxWidgets.git] / src / xrc / xh_chckl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_chckl.cpp
3 // Purpose: XRC resource for wxCheckListBox
4 // Author: Bob Mitchell
5 // Created: 2000/03/21
6 // Copyright: (c) 2000 Bob Mitchell and Verant Interactive
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_XRC && wxUSE_CHECKLISTBOX
18
19 #include "wx/xrc/xh_chckl.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/intl.h"
23 #include "wx/log.h"
24 #include "wx/checklst.h"
25 #endif
26
27 #include "wx/xml/xml.h"
28
29 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler)
30
31 wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler()
32 : wxXmlResourceHandler(), m_insideBox(false)
33 {
34 // wxListBox styles:
35 XRC_ADD_STYLE(wxLB_SINGLE);
36 XRC_ADD_STYLE(wxLB_MULTIPLE);
37 XRC_ADD_STYLE(wxLB_EXTENDED);
38 XRC_ADD_STYLE(wxLB_HSCROLL);
39 XRC_ADD_STYLE(wxLB_ALWAYS_SB);
40 XRC_ADD_STYLE(wxLB_NEEDED_SB);
41 XRC_ADD_STYLE(wxLB_SORT);
42
43 AddWindowStyles();
44 }
45
46 wxObject *wxCheckListBoxXmlHandler::DoCreateResource()
47 {
48 if (m_class == wxT("wxCheckListBox"))
49 {
50 // need to build the list of strings from children
51 m_insideBox = true;
52 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
53
54 XRC_MAKE_INSTANCE(control, wxCheckListBox)
55
56 control->Create(m_parentAsWindow,
57 GetID(),
58 GetPosition(), GetSize(),
59 strList,
60 GetStyle(),
61 wxDefaultValidator,
62 GetName());
63
64 // step through children myself (again.)
65 wxXmlNode *n = GetParamNode(wxT("content"));
66 if (n)
67 n = n->GetChildren();
68 int i = 0;
69 while (n)
70 {
71 if (n->GetType() != wxXML_ELEMENT_NODE ||
72 n->GetName() != wxT("item"))
73 { n = n->GetNext(); continue; }
74
75 // checking boolean is a bit ugly here (see GetBool() )
76 wxString v = n->GetAttribute(wxT("checked"), wxEmptyString);
77 v.MakeLower();
78 if (v == wxT("1"))
79 control->Check( i, true );
80
81 i++;
82 n = n->GetNext();
83 }
84
85 SetupWindow(control);
86
87 strList.Clear(); // dump the strings
88
89 return control;
90 }
91 else
92 {
93 // on the inside now.
94 // handle <item checked="boolean">Label</item>
95
96 // add to the list
97 wxString str = GetNodeContent(m_node);
98 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
99 str = wxGetTranslation(str, m_resource->GetDomain());
100 strList.Add(str);
101 return NULL;
102 }
103 }
104
105 bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
106 {
107 return (IsOfClass(node, wxT("wxCheckListBox")) ||
108 (m_insideBox && node->GetName() == wxT("item")));
109 }
110
111 #endif // wxUSE_XRC && wxUSE_CHECKLISTBOX