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