]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_chckl.cpp
GetNumberOfLines on GTK doesn't count wrapped lines again...
[wxWidgets.git] / src / xrc / xh_chckl.cpp
CommitLineData
78d14f80 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/xrc/xh_chckl.cpp
dd47af27 3// Purpose: XRC resource for wxCheckListBox
78d14f80
VS
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/////////////////////////////////////////////////////////////////////////////
f80ea77b 10
78d14f80
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
88a7a4e1 18#if wxUSE_XRC && wxUSE_CHECKLISTBOX
3037523a 19
78d14f80 20#include "wx/xrc/xh_chckl.h"
88a7a4e1
WS
21
22#ifndef WX_PRECOMP
23 #include "wx/intl.h"
e4db172a 24 #include "wx/log.h"
e6e83933 25 #include "wx/checklst.h"
88a7a4e1
WS
26#endif
27
56572188 28IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler)
854e189f 29
f80ea77b
WS
30wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler()
31: wxXmlResourceHandler(), m_insideBox(false)
78d14f80 32{
6ea1280c
VS
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);
88a7a4e1 41
78d14f80
VS
42 AddWindowStyles();
43}
44
56572188 45wxObject *wxCheckListBoxXmlHandler::DoCreateResource()
f80ea77b 46{
56572188
VS
47 if (m_class == wxT("wxCheckListBox")
48#if WXWIN_COMPATIBILITY_2_4
49 || m_class == wxT("wxCheckList")
50#endif
51 )
78d14f80 52 {
56572188
VS
53#if WXWIN_COMPATIBILITY_2_4
54 if (m_class == wxT("wxCheckList"))
55 wxLogDebug(wxT("'wxCheckList' name is deprecated, use 'wxCheckListBox' instead."));
56#endif
78d14f80 57 // need to build the list of strings from children
f80ea77b 58 m_insideBox = true;
78d14f80 59 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
78d14f80 60
544fee32 61 XRC_MAKE_INSTANCE(control, wxCheckListBox)
f2588180
VS
62
63 control->Create(m_parentAsWindow,
64 GetID(),
65 GetPosition(), GetSize(),
187d8152 66 strList,
f2588180
VS
67 GetStyle(),
68 wxDefaultValidator,
69 GetName());
78d14f80
VS
70
71 // step through children myself (again.)
72 wxXmlNode *n = GetParamNode(wxT("content"));
187d8152
VZ
73 if (n)
74 n = n->GetChildren();
78d14f80
VS
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"))
f80ea77b 86 control->Check( i, true );
78d14f80 87
f80ea77b 88 i++;
78d14f80
VS
89 n = n->GetNext();
90 }
f80ea77b 91
78d14f80
VS
92 SetupWindow(control);
93
f80ea77b 94 strList.Clear(); // dump the strings
78d14f80
VS
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
74c107ba
VS
104 wxString str = GetNodeContent(m_node);
105 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
d4a724d4 106 str = wxGetTranslation(str, m_resource->GetDomain());
74c107ba 107 strList.Add(str);
78d14f80
VS
108 return NULL;
109 }
78d14f80
VS
110}
111
56572188 112bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
78d14f80 113{
56572188
VS
114 return (IsOfClass(node, wxT("wxCheckListBox")) ||
115#if WXWIN_COMPATIBILITY_2_4
116 IsOfClass(node, wxT("wxCheckList")) ||
117#endif
544fee32 118 (m_insideBox && node->GetName() == wxT("item")));
78d14f80
VS
119}
120
88a7a4e1 121#endif // wxUSE_XRC && wxUSE_CHECKLISTBOX