]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_chckl.cpp
include vms_jackets.h directly from wx/platform.h instead of doing it before wx/wxpre...
[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 // RCS-ID: $Id$
7 // Copyright: (c) 2000 Bob Mitchell and Verant Interactive
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_XRC && wxUSE_CHECKLISTBOX
19
20 #include "wx/xrc/xh_chckl.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/intl.h"
24 #include "wx/log.h"
25 #include "wx/checklst.h"
26 #endif
27
28 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler)
29
30 wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler()
31 : wxXmlResourceHandler(), m_insideBox(false)
32 {
33 // wxListBox styles:
34 XRC_ADD_STYLE(wxLB_SINGLE);
35 XRC_ADD_STYLE(wxLB_MULTIPLE);
36 XRC_ADD_STYLE(wxLB_EXTENDED);
37 XRC_ADD_STYLE(wxLB_HSCROLL);
38 XRC_ADD_STYLE(wxLB_ALWAYS_SB);
39 XRC_ADD_STYLE(wxLB_NEEDED_SB);
40 XRC_ADD_STYLE(wxLB_SORT);
41
42 AddWindowStyles();
43 }
44
45 wxObject *wxCheckListBoxXmlHandler::DoCreateResource()
46 {
47 if (m_class == wxT("wxCheckListBox"))
48 {
49 // need to build the list of strings from children
50 m_insideBox = true;
51 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
52
53 XRC_MAKE_INSTANCE(control, wxCheckListBox)
54
55 control->Create(m_parentAsWindow,
56 GetID(),
57 GetPosition(), GetSize(),
58 strList,
59 GetStyle(),
60 wxDefaultValidator,
61 GetName());
62
63 // step through children myself (again.)
64 wxXmlNode *n = GetParamNode(wxT("content"));
65 if (n)
66 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->GetAttribute(wxT("checked"), wxEmptyString);
76 v.MakeLower();
77 if (v == wxT("1"))
78 control->Check( i, true );
79
80 i++;
81 n = n->GetNext();
82 }
83
84 SetupWindow(control);
85
86 strList.Clear(); // dump the strings
87
88 return control;
89 }
90 else
91 {
92 // on the inside now.
93 // handle <item checked="boolean">Label</item>
94
95 // add to the list
96 wxString str = GetNodeContent(m_node);
97 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
98 str = wxGetTranslation(str, m_resource->GetDomain());
99 strList.Add(str);
100 return NULL;
101 }
102 }
103
104 bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
105 {
106 return (IsOfClass(node, wxT("wxCheckListBox")) ||
107 (m_insideBox && node->GetName() == wxT("item")));
108 }
109
110 #endif // wxUSE_XRC && wxUSE_CHECKLISTBOX