]>
Commit | Line | Data |
---|---|---|
78d14f80 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | #ifdef __GNUG__ |
12 | #pragma implementation "xh_chckl.h" | |
13 | #endif | |
14 | ||
15 | // For compilers that support precompilation, includes "wx.h". | |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
5e7ea8eb | 22 | #if wxUSE_OWNER_DRAWN || !defined(__WXMSW__) |
3037523a | 23 | |
78d14f80 VS |
24 | #include "wx/xrc/xh_chckl.h" |
25 | #include "wx/checklst.h" | |
02df3799 | 26 | #include "wx/intl.h" |
56572188 | 27 | #include "wx/log.h" |
78d14f80 | 28 | |
56572188 | 29 | IMPLEMENT_DYNAMIC_CLASS(wxCheckListBoxXmlHandler, wxXmlResourceHandler) |
854e189f | 30 | |
f80ea77b WS |
31 | wxCheckListBoxXmlHandler::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); | |
42 | ||
78d14f80 VS |
43 | AddWindowStyles(); |
44 | } | |
45 | ||
56572188 | 46 | wxObject *wxCheckListBoxXmlHandler::DoCreateResource() |
f80ea77b | 47 | { |
56572188 VS |
48 | if (m_class == wxT("wxCheckListBox") |
49 | #if WXWIN_COMPATIBILITY_2_4 | |
50 | || m_class == wxT("wxCheckList") | |
51 | #endif | |
52 | ) | |
78d14f80 | 53 | { |
56572188 VS |
54 | #if WXWIN_COMPATIBILITY_2_4 |
55 | if (m_class == wxT("wxCheckList")) | |
56 | wxLogDebug(wxT("'wxCheckList' name is deprecated, use 'wxCheckListBox' instead.")); | |
57 | #endif | |
78d14f80 | 58 | // need to build the list of strings from children |
f80ea77b | 59 | m_insideBox = true; |
78d14f80 VS |
60 | CreateChildrenPrivately(NULL, GetParamNode(wxT("content"))); |
61 | wxString *strings = (wxString *) NULL; | |
544fee32 | 62 | if (strList.GetCount() > 0) |
78d14f80 VS |
63 | { |
64 | strings = new wxString[strList.GetCount()]; | |
65 | int count = strList.GetCount(); | |
544fee32 VS |
66 | for(int i = 0; i < count; i++) |
67 | strings[i] = strList[i]; | |
78d14f80 VS |
68 | } |
69 | ||
544fee32 | 70 | XRC_MAKE_INSTANCE(control, wxCheckListBox) |
f2588180 VS |
71 | |
72 | control->Create(m_parentAsWindow, | |
73 | GetID(), | |
74 | GetPosition(), GetSize(), | |
75 | strList.GetCount(), | |
76 | strings, | |
77 | GetStyle(), | |
78 | wxDefaultValidator, | |
79 | GetName()); | |
78d14f80 VS |
80 | |
81 | // step through children myself (again.) | |
82 | wxXmlNode *n = GetParamNode(wxT("content")); | |
83 | if (n) n = n->GetChildren(); | |
84 | int i = 0; | |
85 | while (n) | |
86 | { | |
87 | if (n->GetType() != wxXML_ELEMENT_NODE || | |
88 | n->GetName() != wxT("item")) | |
89 | { n = n->GetNext(); continue; } | |
90 | ||
91 | // checking boolean is a bit ugly here (see GetBool() ) | |
92 | wxString v = n->GetPropVal(wxT("checked"), wxEmptyString); | |
93 | v.MakeLower(); | |
94 | if (v && v == wxT("1")) | |
f80ea77b | 95 | control->Check( i, true ); |
78d14f80 | 96 | |
f80ea77b | 97 | i++; |
78d14f80 VS |
98 | n = n->GetNext(); |
99 | } | |
f80ea77b | 100 | |
78d14f80 VS |
101 | SetupWindow(control); |
102 | ||
544fee32 VS |
103 | if (strings != NULL) |
104 | delete[] strings; | |
f80ea77b | 105 | strList.Clear(); // dump the strings |
78d14f80 VS |
106 | |
107 | return control; | |
108 | } | |
109 | else | |
110 | { | |
111 | // on the inside now. | |
112 | // handle <item checked="boolean">Label</item> | |
113 | ||
114 | // add to the list | |
74c107ba VS |
115 | wxString str = GetNodeContent(m_node); |
116 | if (m_resource->GetFlags() & wxXRC_USE_LOCALE) | |
117 | str = wxGetTranslation(str); | |
118 | strList.Add(str); | |
78d14f80 VS |
119 | return NULL; |
120 | } | |
78d14f80 VS |
121 | } |
122 | ||
56572188 | 123 | bool wxCheckListBoxXmlHandler::CanHandle(wxXmlNode *node) |
78d14f80 | 124 | { |
56572188 VS |
125 | return (IsOfClass(node, wxT("wxCheckListBox")) || |
126 | #if WXWIN_COMPATIBILITY_2_4 | |
127 | IsOfClass(node, wxT("wxCheckList")) || | |
128 | #endif | |
544fee32 | 129 | (m_insideBox && node->GetName() == wxT("item"))); |
78d14f80 VS |
130 | } |
131 | ||
9a8ffadd | 132 | #endif |
84969af7 | 133 |