]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_chckl.cpp
Include wx/mdi.h according to precompiled headers of wx/wx.h (with other minor cleaning).
[wxWidgets.git] / src / xrc / xh_chckl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/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 // 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 wxString *strings = (wxString *) NULL;
61 if (strList.GetCount() > 0)
62 {
63 strings = new wxString[strList.GetCount()];
64 int count = strList.GetCount();
65 for(int i = 0; i < count; i++)
66 strings[i] = strList[i];
67 }
68
69 XRC_MAKE_INSTANCE(control, wxCheckListBox)
70
71 control->Create(m_parentAsWindow,
72 GetID(),
73 GetPosition(), GetSize(),
74 strList.GetCount(),
75 strings,
76 GetStyle(),
77 wxDefaultValidator,
78 GetName());
79
80 // step through children myself (again.)
81 wxXmlNode *n = GetParamNode(wxT("content"));
82 if (n) n = n->GetChildren();
83 int i = 0;
84 while (n)
85 {
86 if (n->GetType() != wxXML_ELEMENT_NODE ||
87 n->GetName() != wxT("item"))
88 { n = n->GetNext(); continue; }
89
90 // checking boolean is a bit ugly here (see GetBool() )
91 wxString v = n->GetPropVal(wxT("checked"), wxEmptyString);
92 v.MakeLower();
93 if (v && v == wxT("1"))
94 control->Check( i, true );
95
96 i++;
97 n = n->GetNext();
98 }
99
100 SetupWindow(control);
101
102 if (strings != NULL)
103 delete[] strings;
104 strList.Clear(); // dump the strings
105
106 return control;
107 }
108 else
109 {
110 // on the inside now.
111 // handle <item checked="boolean">Label</item>
112
113 // add to the list
114 wxString str = GetNodeContent(m_node);
115 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
116 str = wxGetTranslation(str);
117 strList.Add(str);
118 return NULL;
119 }
120 }
121
122 bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
123 {
124 return (IsOfClass(node, wxT("wxCheckListBox")) ||
125 #if WXWIN_COMPATIBILITY_2_4
126 IsOfClass(node, wxT("wxCheckList")) ||
127 #endif
128 (m_insideBox && node->GetName() == wxT("item")));
129 }
130
131 #endif // wxUSE_XRC && wxUSE_CHECKLISTBOX