]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_chckl.cpp
positioning of the insertion point at the end
[wxWidgets.git] / 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 #if wxUSE_OWNER_DRAWN || !defined(__WXMSW__)
23
24 #include "wx/xrc/xh_chckl.h"
25 #include "wx/checklst.h"
26 #include "wx/intl.h"
27 #include "wx/log.h"
28
29 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler)
30
31 wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler()
32 : wxXmlResourceHandler(), m_insideBox(FALSE)
33 {
34 // no styles
35 AddWindowStyles();
36 }
37
38 wxObject *wxCheckListBoxXmlHandler::DoCreateResource()
39 {
40 if (m_class == wxT("wxCheckListBox")
41 #if WXWIN_COMPATIBILITY_2_4
42 || m_class == wxT("wxCheckList")
43 #endif
44 )
45 {
46 #if WXWIN_COMPATIBILITY_2_4
47 if (m_class == wxT("wxCheckList"))
48 wxLogDebug(wxT("'wxCheckList' name is deprecated, use 'wxCheckListBox' instead."));
49 #endif
50 // need to build the list of strings from children
51 m_insideBox = TRUE;
52 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
53 wxString *strings = (wxString *) NULL;
54 if (strList.GetCount() > 0)
55 {
56 strings = new wxString[strList.GetCount()];
57 int count = strList.GetCount();
58 for(int i = 0; i < count; i++)
59 strings[i] = strList[i];
60 }
61
62 XRC_MAKE_INSTANCE(control, wxCheckListBox)
63
64 control->Create(m_parentAsWindow,
65 GetID(),
66 GetPosition(), GetSize(),
67 strList.GetCount(),
68 strings,
69 GetStyle(),
70 wxDefaultValidator,
71 GetName());
72
73 // step through children myself (again.)
74 wxXmlNode *n = GetParamNode(wxT("content"));
75 if (n) n = n->GetChildren();
76 int i = 0;
77 while (n)
78 {
79 if (n->GetType() != wxXML_ELEMENT_NODE ||
80 n->GetName() != wxT("item"))
81 { n = n->GetNext(); continue; }
82
83 // checking boolean is a bit ugly here (see GetBool() )
84 wxString v = n->GetPropVal(wxT("checked"), wxEmptyString);
85 v.MakeLower();
86 if (v && v == wxT("1"))
87 control->Check( i, TRUE );
88
89 i++;
90 n = n->GetNext();
91 }
92
93 SetupWindow(control);
94
95 if (strings != NULL)
96 delete[] strings;
97 strList.Clear(); // dump the strings
98
99 return control;
100 }
101 else
102 {
103 // on the inside now.
104 // handle <item checked="boolean">Label</item>
105
106 // add to the list
107 wxString str = GetNodeContent(m_node);
108 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
109 str = wxGetTranslation(str);
110 strList.Add(str);
111 return NULL;
112 }
113 }
114
115 bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
116 {
117 return (IsOfClass(node, wxT("wxCheckListBox")) ||
118 #if WXWIN_COMPATIBILITY_2_4
119 IsOfClass(node, wxT("wxCheckList")) ||
120 #endif
121 (m_insideBox && node->GetName() == wxT("item")));
122 }
123
124 #endif
125