Debian Codegraph @

wxcrafter/controls/combox_wrapper.cpp

raw
1 #include "combox_wrapper.h"
2 #include "allocator_mgr.h"
3 #include "import_from_wxFB.h"
4 #include "multi_strings_property.h"
5 #include "string_property.h"
6 #include "wxgui_helpers.h"
7 #include "xmlutils.h"
8 #include <wx/textctrl.h>
9
10 ComboxWrapper::ComboxWrapper()
11 : wxcWidget(ID_WXCOMBOBOX)
12 {
13 SetPropertyString(_("Common Settings"), "wxComboBox");
14 AddProperty(new MultiStringsProperty(PROP_CB_CHOICES, _("Combobox drop down choices")));
15 AddProperty(new StringProperty(PROP_HINT, "", _("Sets a hint shown in an empty unfocused text control")));
16 AddProperty(new StringProperty(
17 PROP_SELECTION, wxT("-1"),
18 _("The zero-based position of any initially selected string, or -1 if none are to be selected")));
19 AddProperty(new StringProperty(PROP_VALUE, "", _("The combobox initial value")));
20
21 RegisterEventCommand(wxT("wxEVT_COMMAND_COMBOBOX_SELECTED"),
22 _("Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on the list is selected. "
23 "Note that calling GetValue returns the new value of selection."));
24 RegisterEventCommand(wxT("wxEVT_COMMAND_TEXT_UPDATED"),
25 _("Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text changes."));
26 RegisterEventCommand(wxT("wxEVT_COMMAND_TEXT_ENTER"),
27 _("Process a wxEVT_COMMAND_TEXT_ENTER event, when <RETURN> is pressed in the combobox."));
28
29 PREPEND_STYLE(wxCB_DROPDOWN, false);
30 PREPEND_STYLE(wxCB_READONLY, false);
31 PREPEND_STYLE(wxCB_SIMPLE, false);
32 PREPEND_STYLE(wxCB_SORT, false);
33 PREPEND_STYLE(wxTE_PROCESS_ENTER, false);
34
35 m_namePattern = wxT("m_comboBox");
36 SetName(GenerateName());
37 }
38
39 ComboxWrapper::~ComboxWrapper() {}
40
41 wxcWidget* ComboxWrapper::Clone() const { return new ComboxWrapper(); }
42
43 void ComboxWrapper::GetIncludeFile(wxArrayString& headers) const
44 {
45 headers.Add(wxT("#include <wx/combobox.h>"));
46 headers.Add(wxT("#include <wx/arrstr.h>"));
47 }
48
49 wxString ComboxWrapper::GetWxClassName() const { return wxT("wxComboBox"); }
50
51 wxString ComboxWrapper::CppCtorCode() const
52 {
53 wxString code;
54 wxArrayString options = wxCrafter::SplitByString(PropertyString(PROP_CB_CHOICES), wxT("\\n"));
55
56 code << wxT("wxArrayString ") << GetName() << wxT("Arr;\n");
57 for(size_t i = 0; i < options.GetCount(); i++) {
58 code << GetName() << wxT("Arr.Add(") << wxCrafter::UNDERSCORE(options.Item(i)) << wxT(");\n");
59 }
60
61 code << GetName() << wxT(" = new ") << GetRealClassName() << "(" << GetWindowParent() << wxT(", ") << WindowID()
62 << wxT(", ") << ValueAsString() << wxT(", ") << wxT("wxDefaultPosition, ") << SizeAsString() << wxT(", ")
63 << GetName() << wxT("Arr") << wxT(", ") << StyleFlags(wxT("0")) << wxT(");\n");
64 code << CPPCommonAttributes();
65
66 if(!HasStyle(wxCB_READONLY)) {
67 code << wxCrafter::WX30_BLOCK_START();
68 code << GetName() << "->SetHint(" << wxCrafter::UNDERSCORE(PropertyString(PROP_HINT)) << ");\n";
69 code << wxCrafter::WXVER_CHECK_BLOCK_END();
70 }
71
72 int sel = wxCrafter::ToNumber(PropertyString(PROP_SELECTION), -1);
73 if(sel >= 0 && sel < (int)options.GetCount()) {
74 code << GetName() << wxT("->SetSelection(") << PropertyString(PROP_SELECTION) << wxT(");\n");
75 }
76 return code;
77 }
78
79 void ComboxWrapper::ToXRC(wxString& text, XRC_TYPE type) const
80 {
81 wxArrayString options = wxCrafter::SplitByString(PropertyString(PROP_CB_CHOICES), wxT("\\n"));
82 wxString str;
83 str << wxT("<content>");
84 for(size_t i = 0; i < options.GetCount(); i++) {
85 str << wxT("<item>") << wxCrafter::CDATA(options.Item(i)) << wxT("</item>");
86 }
87 str << wxT("</content>");
88
89 text << XRCPrefix() << XRCValue() << XRCStyle() << XRCSize() << XRCCommonAttributes();
90 if(!HasStyle(wxCB_READONLY) && !PropertyString(PROP_HINT).empty()) {
91 // set hint for non-readonly combobox
92 text << "<hint>" << wxCrafter::CDATA(PropertyString(PROP_HINT)) << "</hint>";
93 }
94 text << XRCSelection() << str << XRCSuffix();
95 }
96
97 void ComboxWrapper::LoadPropertiesFromXRC(const wxXmlNode* node)
98 {
99 // First call the base-class for the standard things
100 wxcWidget::LoadPropertiesFromXRC(node);
101
102 // The Options (content) property has a default, so we must clear it even if the node is absent
103 wxString multistring;
104 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content"));
105 if(propertynode) {
106 multistring = XmlUtils::ChildNodesContentToString(
107 propertynode, "", "\\n"); // wxC stores combobox items as a \n-separated string, not ';' like wxChoice
108 }
109 SetPropertyString(PROP_CB_CHOICES, multistring);
110
111 propertynode = XmlUtils::FindFirstByTagName(node, wxT("selection"));
112 if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); }
113
114 propertynode = XmlUtils::FindFirstByTagName(node, wxT("value"));
115 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
116 }
117
118 void ComboxWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node)
119 {
120 // First call the base-class for the standard things
121 wxcWidget::LoadPropertiesFromwxSmith(node);
122
123 // The Options (content) property has a default, so we must clear it even if the node is absent
124 wxString multistring;
125 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content"));
126 if(propertynode) { multistring = XmlUtils::ChildNodesContentToString(propertynode, "", "\\n"); }
127 SetPropertyString(PROP_CB_CHOICES, multistring);
128
129 propertynode = XmlUtils::FindFirstByTagName(node, wxT("selection"));
130 if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); }
131
132 propertynode = XmlUtils::FindFirstByTagName(node, wxT("value")); // wxSmith doesn't seem to do this, but...
133 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
134 }
135
136 void ComboxWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node)
137 {
138 // First call the base-class for the standard things
139 wxcWidget::LoadPropertiesFromwxFB(node);
140
141 // The "choices" property has a default, so we should clear it even if the node was absent
142 wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "choices");
143 wxString content;
144 if(propertynode) { content = ImportFromwxFB::ConvertFBOptionsString(propertynode->GetNodeContent(), "\\n"); }
145 SetPropertyString(PROP_CB_CHOICES, content);
146
147 propertynode = XmlUtils::FindNodeByName(node, "property", "selection");
148 if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); }
149
150 propertynode = XmlUtils::FindNodeByName(node, "property", "value");
151 if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); }
152 }