]>
Commit | Line | Data |
---|---|---|
78d14f80 | 1 | ///////////////////////////////////////////////////////////////////////////// |
88a7a4e1 | 2 | // Name: src/xrc/xh_chckl.cpp |
b5d6954b | 3 | // Purpose: XRC resource for wxCheckList |
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 | 28 | IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler) |
854e189f | 29 | |
f80ea77b WS |
30 | wxCheckListBoxXmlHandler::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 | 45 | wxObject *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 VS |
59 | CreateChildrenPrivately(NULL, GetParamNode(wxT("content"))); |
60 | wxString *strings = (wxString *) NULL; | |
544fee32 | 61 | if (strList.GetCount() > 0) |
78d14f80 VS |
62 | { |
63 | strings = new wxString[strList.GetCount()]; | |
64 | int count = strList.GetCount(); | |
544fee32 VS |
65 | for(int i = 0; i < count; i++) |
66 | strings[i] = strList[i]; | |
78d14f80 VS |
67 | } |
68 | ||
544fee32 | 69 | XRC_MAKE_INSTANCE(control, wxCheckListBox) |
f2588180 VS |
70 | |
71 | control->Create(m_parentAsWindow, | |
72 | GetID(), | |
73 | GetPosition(), GetSize(), | |
74 | strList.GetCount(), | |
75 | strings, | |
76 | GetStyle(), | |
77 | wxDefaultValidator, | |
78 | GetName()); | |
78d14f80 VS |
79 | |
80 | // step through children myself (again.) | |
81 | wxXmlNode *n = GetParamNode(wxT("content")); | |
82 | if (n) n = n->GetChildren(); | |
83 | int i = 0; | |
84 | while (n) | |
85 | { | |
86 | if (n->GetType() != wxXML_ELEMENT_NODE || | |
87 | n->GetName() != wxT("item")) | |
88 | { n = n->GetNext(); continue; } | |
89 | ||
90 | // checking boolean is a bit ugly here (see GetBool() ) | |
91 | wxString v = n->GetPropVal(wxT("checked"), wxEmptyString); | |
92 | v.MakeLower(); | |
93 | if (v && v == wxT("1")) | |
f80ea77b | 94 | control->Check( i, true ); |
78d14f80 | 95 | |
f80ea77b | 96 | i++; |
78d14f80 VS |
97 | n = n->GetNext(); |
98 | } | |
f80ea77b | 99 | |
78d14f80 VS |
100 | SetupWindow(control); |
101 | ||
544fee32 VS |
102 | if (strings != NULL) |
103 | delete[] strings; | |
f80ea77b | 104 | strList.Clear(); // dump the strings |
78d14f80 VS |
105 | |
106 | return control; | |
107 | } | |
108 | else | |
109 | { | |
110 | // on the inside now. | |
111 | // handle <item checked="boolean">Label</item> | |
112 | ||
113 | // add to the list | |
74c107ba VS |
114 | wxString str = GetNodeContent(m_node); |
115 | if (m_resource->GetFlags() & wxXRC_USE_LOCALE) | |
d4a724d4 | 116 | str = wxGetTranslation(str, m_resource->GetDomain()); |
74c107ba | 117 | strList.Add(str); |
78d14f80 VS |
118 | return NULL; |
119 | } | |
78d14f80 VS |
120 | } |
121 | ||
56572188 | 122 | bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node) |
78d14f80 | 123 | { |
56572188 VS |
124 | return (IsOfClass(node, wxT("wxCheckListBox")) || |
125 | #if WXWIN_COMPATIBILITY_2_4 | |
126 | IsOfClass(node, wxT("wxCheckList")) || | |
127 | #endif | |
544fee32 | 128 | (m_insideBox && node->GetName() == wxT("item"))); |
78d14f80 VS |
129 | } |
130 | ||
88a7a4e1 | 131 | #endif // wxUSE_XRC && wxUSE_CHECKLISTBOX |