]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_chckl.cpp
Implement wxComboCtrl::GetSizeFromTextSize().
[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 #include "wx/xml/xml.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler)
31
32 wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler()
33 : wxXmlResourceHandler(), m_insideBox(false)
34 {
35 // wxListBox styles:
36 XRC_ADD_STYLE(wxLB_SINGLE);
37 XRC_ADD_STYLE(wxLB_MULTIPLE);
38 XRC_ADD_STYLE(wxLB_EXTENDED);
39 XRC_ADD_STYLE(wxLB_HSCROLL);
40 XRC_ADD_STYLE(wxLB_ALWAYS_SB);
41 XRC_ADD_STYLE(wxLB_NEEDED_SB);
42 XRC_ADD_STYLE(wxLB_SORT);
43
44 AddWindowStyles();
45 }
46
47 wxObject *wxCheckListBoxXmlHandler::DoCreateResource()
48 {
49 if (m_class == wxT("wxCheckListBox"))
50 {
51 // need to build the list of strings from children
52 m_insideBox = true;
53 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
54
55 XRC_MAKE_INSTANCE(control, wxCheckListBox)
56
57 control->Create(m_parentAsWindow,
58 GetID(),
59 GetPosition(), GetSize(),
60 strList,
61 GetStyle(),
62 wxDefaultValidator,
63 GetName());
64
65 // step through children myself (again.)
66 wxXmlNode *n = GetParamNode(wxT("content"));
67 if (n)
68 n = n->GetChildren();
69 int i = 0;
70 while (n)
71 {
72 if (n->GetType() != wxXML_ELEMENT_NODE ||
73 n->GetName() != wxT("item"))
74 { n = n->GetNext(); continue; }
75
76 // checking boolean is a bit ugly here (see GetBool() )
77 wxString v = n->GetAttribute(wxT("checked"), wxEmptyString);
78 v.MakeLower();
79 if (v == wxT("1"))
80 control->Check( i, true );
81
82 i++;
83 n = n->GetNext();
84 }
85
86 SetupWindow(control);
87
88 strList.Clear(); // dump the strings
89
90 return control;
91 }
92 else
93 {
94 // on the inside now.
95 // handle <item checked="boolean">Label</item>
96
97 // add to the list
98 wxString str = GetNodeContent(m_node);
99 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
100 str = wxGetTranslation(str, m_resource->GetDomain());
101 strList.Add(str);
102 return NULL;
103 }
104 }
105
106 bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
107 {
108 return (IsOfClass(node, wxT("wxCheckListBox")) ||
109 (m_insideBox && node->GetName() == wxT("item")));
110 }
111
112 #endif // wxUSE_XRC && wxUSE_CHECKLISTBOX