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