]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_chckl.cpp
Vietnamese translations update from Trần Ngọc Quân.
[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{
c1dc9f83 47 if (m_class == wxT("wxCheckListBox"))
78d14f80
VS
48 {
49 // need to build the list of strings from children
f80ea77b 50 m_insideBox = true;
78d14f80 51 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
78d14f80 52
544fee32 53 XRC_MAKE_INSTANCE(control, wxCheckListBox)
f2588180
VS
54
55 control->Create(m_parentAsWindow,
56 GetID(),
57 GetPosition(), GetSize(),
187d8152 58 strList,
f2588180
VS
59 GetStyle(),
60 wxDefaultValidator,
61 GetName());
78d14f80
VS
62
63 // step through children myself (again.)
64 wxXmlNode *n = GetParamNode(wxT("content"));
187d8152
VZ
65 if (n)
66 n = n->GetChildren();
78d14f80
VS
67 int i = 0;
68 while (n)
69 {
70 if (n->GetType() != wxXML_ELEMENT_NODE ||
71 n->GetName() != wxT("item"))
72 { n = n->GetNext(); continue; }
73
74 // checking boolean is a bit ugly here (see GetBool() )
288b6107 75 wxString v = n->GetAttribute(wxT("checked"), wxEmptyString);
78d14f80 76 v.MakeLower();
11aac4ba 77 if (v == wxT("1"))
f80ea77b 78 control->Check( i, true );
78d14f80 79
f80ea77b 80 i++;
78d14f80
VS
81 n = n->GetNext();
82 }
f80ea77b 83
78d14f80
VS
84 SetupWindow(control);
85
f80ea77b 86 strList.Clear(); // dump the strings
78d14f80
VS
87
88 return control;
89 }
90 else
91 {
92 // on the inside now.
93 // handle <item checked="boolean">Label</item>
94
95 // add to the list
74c107ba
VS
96 wxString str = GetNodeContent(m_node);
97 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
d4a724d4 98 str = wxGetTranslation(str, m_resource->GetDomain());
74c107ba 99 strList.Add(str);
78d14f80
VS
100 return NULL;
101 }
78d14f80
VS
102}
103
56572188 104bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
78d14f80 105{
56572188 106 return (IsOfClass(node, wxT("wxCheckListBox")) ||
544fee32 107 (m_insideBox && node->GetName() == wxT("item")));
78d14f80
VS
108}
109
88a7a4e1 110#endif // wxUSE_XRC && wxUSE_CHECKLISTBOX