Debian Codegraph @

wxcrafter/xrc_handlers/MyRearrangeListXmlHandler.cpp

raw
1 #include "MyRearrangeListXmlHandler.h"
2 #include <wx/defs.h>
3 #include <wx/rearrangectrl.h>
4 #include <wx/xml/xml.h>
5 #include <wx/xrc/xmlres.h>
6
7 MyRearrangeListXmlHandler::MyRearrangeListXmlHandler()
8 : wxXmlResourceHandler()
9 , m_insideBox(false)
10 {
11 // wxListBox styles:
12 XRC_ADD_STYLE(wxLB_SINGLE);
13 XRC_ADD_STYLE(wxLB_MULTIPLE);
14 XRC_ADD_STYLE(wxLB_EXTENDED);
15 XRC_ADD_STYLE(wxLB_HSCROLL);
16 XRC_ADD_STYLE(wxLB_ALWAYS_SB);
17 XRC_ADD_STYLE(wxLB_NEEDED_SB);
18 XRC_ADD_STYLE(wxLB_SORT);
19 AddWindowStyles();
20 }
21
22 MyRearrangeListXmlHandler::~MyRearrangeListXmlHandler() {}
23
24 bool MyRearrangeListXmlHandler::CanHandle(wxXmlNode* node)
25 {
26 return (IsOfClass(node, wxT("wxRearrangeList")) || (m_insideBox && node->GetName() == wxT("item")));
27 }
28
29 wxObject* MyRearrangeListXmlHandler::DoCreateResource()
30 {
31 if(m_class == wxT("wxRearrangeList")) {
32 // need to build the list of strings from children
33 m_insideBox = true;
34 CreateChildrenPrivately(NULL, GetParamNode(wxT("content")));
35
36 wxArrayInt order;
37 for(size_t i = 0; i < strList.GetCount(); ++i) {
38 order.push_back((int)i);
39 }
40
41 XRC_MAKE_INSTANCE(control, wxRearrangeList)
42 control->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), order, strList, GetStyle(),
43 wxDefaultValidator, GetName());
44
45 // step through children myself (again.)
46 wxXmlNode* n = GetParamNode(wxT("content"));
47 if(n) n = n->GetChildren();
48 int i = 0;
49 while(n) {
50 if(n->GetType() != wxXML_ELEMENT_NODE || n->GetName() != wxT("item")) {
51 n = n->GetNext();
52 continue;
53 }
54
55 // checking boolean is a bit ugly here (see GetBool() )
56 wxString v = n->GetAttribute(wxT("checked"), wxEmptyString);
57 v.MakeLower();
58 if(v == wxT("1")) control->Check(i, true);
59
60 i++;
61 n = n->GetNext();
62 }
63
64 SetupWindow(control);
65 strList.Clear(); // dump the strings
66 return control;
67
68 } else {
69 // on the inside now.
70 // handle <item checked="boolean">Label</item>
71
72 // add to the list
73 wxString str = GetNodeContent(m_node);
74 if(m_resource->GetFlags() & wxXRC_USE_LOCALE) str = wxGetTranslation(str, m_resource->GetDomain());
75 strList.Add(str);
76 return NULL;
77 }
78 }