]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_chckl.cpp
set command int (indicating whether the item is checked) correctly for the menu event...
[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 #if WXWIN_COMPATIBILITY_2_4
49 || m_class == wxT("wxCheckList")
50 #endif
51 )
52 {
53 #if WXWIN_COMPATIBILITY_2_4
54 if (m_class == wxT("wxCheckList"))
55 wxLogDebug(wxT("'wxCheckList' name is deprecated, use 'wxCheckListBox' instead."));
56 #endif
57 // need to build the list of strings from children
58 m_insideBox = true;
59 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
60
61 XRC_MAKE_INSTANCE(control, wxCheckListBox)
62
63 control->Create(m_parentAsWindow,
64 GetID(),
65 GetPosition(), GetSize(),
66 strList,
67 GetStyle(),
68 wxDefaultValidator,
69 GetName());
70
71 // step through children myself (again.)
72 wxXmlNode *n = GetParamNode(wxT("content"));
73 if (n)
74 n = n->GetChildren();
75 int i = 0;
76 while (n)
77 {
78 if (n->GetType() != wxXML_ELEMENT_NODE ||
79 n->GetName() != wxT("item"))
80 { n = n->GetNext(); continue; }
81
82 // checking boolean is a bit ugly here (see GetBool() )
83 wxString v = n->GetPropVal(wxT("checked"), wxEmptyString);
84 v.MakeLower();
85 if (v && v == wxT("1"))
86 control->Check( i, true );
87
88 i++;
89 n = n->GetNext();
90 }
91
92 SetupWindow(control);
93
94 strList.Clear(); // dump the strings
95
96 return control;
97 }
98 else
99 {
100 // on the inside now.
101 // handle <item checked="boolean">Label</item>
102
103 // add to the list
104 wxString str = GetNodeContent(m_node);
105 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
106 str = wxGetTranslation(str, m_resource->GetDomain());
107 strList.Add(str);
108 return NULL;
109 }
110 }
111
112 bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
113 {
114 return (IsOfClass(node, wxT("wxCheckListBox")) ||
115 #if WXWIN_COMPATIBILITY_2_4
116 IsOfClass(node, wxT("wxCheckList")) ||
117 #endif
118 (m_insideBox && node->GetName() == wxT("item")));
119 }
120
121 #endif // wxUSE_XRC && wxUSE_CHECKLISTBOX