]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_chckl.cpp
Further refine of #15226: wxRichTextCtrl: Implement setting properties with undo...
[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
78d14f80
VS
6// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
f80ea77b 9
78d14f80
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
88a7a4e1 17#if wxUSE_XRC && wxUSE_CHECKLISTBOX
3037523a 18
78d14f80 19#include "wx/xrc/xh_chckl.h"
88a7a4e1
WS
20
21#ifndef WX_PRECOMP
22 #include "wx/intl.h"
e4db172a 23 #include "wx/log.h"
e6e83933 24 #include "wx/checklst.h"
88a7a4e1
WS
25#endif
26
df27f1dc
VZ
27#include "wx/xml/xml.h"
28
56572188 29IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler)
854e189f 30
f80ea77b
WS
31wxCheckListBoxXmlHandler::wxCheckListBoxXmlHandler()
32: wxXmlResourceHandler(), m_insideBox(false)
78d14f80 33{
6ea1280c
VS
34 // wxListBox styles:
35 XRC_ADD_STYLE(wxLB_SINGLE);
36 XRC_ADD_STYLE(wxLB_MULTIPLE);
37 XRC_ADD_STYLE(wxLB_EXTENDED);
38 XRC_ADD_STYLE(wxLB_HSCROLL);
39 XRC_ADD_STYLE(wxLB_ALWAYS_SB);
40 XRC_ADD_STYLE(wxLB_NEEDED_SB);
41 XRC_ADD_STYLE(wxLB_SORT);
88a7a4e1 42
78d14f80
VS
43 AddWindowStyles();
44}
45
56572188 46wxObject *wxCheckListBoxXmlHandler::DoCreateResource()
f80ea77b 47{
c1dc9f83 48 if (m_class == wxT("wxCheckListBox"))
78d14f80
VS
49 {
50 // need to build the list of strings from children
f80ea77b 51 m_insideBox = true;
78d14f80 52 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
78d14f80 53
544fee32 54 XRC_MAKE_INSTANCE(control, wxCheckListBox)
f2588180
VS
55
56 control->Create(m_parentAsWindow,
57 GetID(),
58 GetPosition(), GetSize(),
187d8152 59 strList,
f2588180
VS
60 GetStyle(),
61 wxDefaultValidator,
62 GetName());
78d14f80
VS
63
64 // step through children myself (again.)
65 wxXmlNode *n = GetParamNode(wxT("content"));
187d8152
VZ
66 if (n)
67 n = n->GetChildren();
78d14f80
VS
68 int i = 0;
69 while (n)
70 {
71 if (n->GetType() != wxXML_ELEMENT_NODE ||
72 n->GetName() != wxT("item"))
73 { n = n->GetNext(); continue; }
74
75 // checking boolean is a bit ugly here (see GetBool() )
288b6107 76 wxString v = n->GetAttribute(wxT("checked"), wxEmptyString);
78d14f80 77 v.MakeLower();
11aac4ba 78 if (v == wxT("1"))
f80ea77b 79 control->Check( i, true );
78d14f80 80
f80ea77b 81 i++;
78d14f80
VS
82 n = n->GetNext();
83 }
f80ea77b 84
78d14f80
VS
85 SetupWindow(control);
86
f80ea77b 87 strList.Clear(); // dump the strings
78d14f80
VS
88
89 return control;
90 }
91 else
92 {
93 // on the inside now.
94 // handle <item checked="boolean">Label</item>
95
96 // add to the list
74c107ba
VS
97 wxString str = GetNodeContent(m_node);
98 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
d4a724d4 99 str = wxGetTranslation(str, m_resource->GetDomain());
74c107ba 100 strList.Add(str);
78d14f80
VS
101 return NULL;
102 }
78d14f80
VS
103}
104
56572188 105bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node)
78d14f80 106{
56572188 107 return (IsOfClass(node, wxT("wxCheckListBox")) ||
544fee32 108 (m_insideBox && node->GetName() == wxT("item")));
78d14f80
VS
109}
110
88a7a4e1 111#endif // wxUSE_XRC && wxUSE_CHECKLISTBOX