| 1 |
#include "choice_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_defs.h" |
| 7 |
#include "wxgui_helpers.h" |
| 8 |
#include "xmlutils.h" |
| 9 |
|
| 10 |
ChoiceWrapper::ChoiceWrapper() |
| 11 |
: wxcWidget(ID_WXCHOICE) |
| 12 |
{ |
| 13 |
SetPropertyString(_("Common Settings"), "wxChoice"); |
| 14 |
AddProperty( |
| 15 |
new MultiStringsProperty(PROP_OPTIONS, _("The Choice drop down options. A semi-colon list of strings"))); |
| 16 |
AddProperty(new StringProperty(PROP_SELECTION, wxT(""), _("Selected string index"))); |
| 17 |
|
| 18 |
RegisterEventCommand(wxT("wxEVT_COMMAND_CHOICE_SELECTED"), |
| 19 |
_("Process a wxEVT_COMMAND_CHOICE_SELECTED event, when an item on the list is selected.")); |
| 20 |
|
| 21 |
m_namePattern = wxT("m_choice"); |
| 22 |
SetName(GenerateName()); |
| 23 |
} |
| 24 |
|
| 25 |
ChoiceWrapper::~ChoiceWrapper() {} |
| 26 |
|
| 27 |
wxcWidget* ChoiceWrapper::Clone() const { return new ChoiceWrapper(); } |
| 28 |
|
| 29 |
wxString ChoiceWrapper::CppCtorCode() const |
| 30 |
{ |
| 31 |
wxString code; |
| 32 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_OPTIONS), wxT(";")); |
| 33 |
|
| 34 |
code << wxT("wxArrayString ") << GetName() << wxT("Arr;\n"); |
| 35 |
for(size_t i = 0; i < options.GetCount(); i++) { |
| 36 |
code << GetName() << wxT("Arr.Add(") << wxCrafter::UNDERSCORE(options.Item(i)) << wxT(");\n"); |
| 37 |
} |
| 38 |
|
| 39 |
code << GetName() << wxT(" = new ") << GetRealClassName() << "(" << GetWindowParent() << wxT(", ") << WindowID() |
| 40 |
<< wxT(", ") << wxT("wxDefaultPosition, ") << SizeAsString() << wxT(", ") << GetName() << wxT("Arr") |
| 41 |
<< wxT(", ") << StyleFlags(wxT("0")) << wxT(");\n"); |
| 42 |
|
| 43 |
code << CPPCommonAttributes(); |
| 44 |
long sel = wxCrafter::ToNumber(PropertyString(PROP_SELECTION), -1); |
| 45 |
if(sel != -1 && sel < (long)options.GetCount()) { |
| 46 |
code << GetName() << wxT("->SetSelection(") << sel << wxT(");\n"); |
| 47 |
} |
| 48 |
return code; |
| 49 |
} |
| 50 |
|
| 51 |
void ChoiceWrapper::GetIncludeFile(wxArrayString& headers) const |
| 52 |
{ |
| 53 |
headers.Add(wxT("#include <wx/choice.h>")); |
| 54 |
headers.Add(wxT("#include <wx/arrstr.h>")); |
| 55 |
} |
| 56 |
|
| 57 |
wxString ChoiceWrapper::GetWxClassName() const { return wxT("wxChoice"); } |
| 58 |
|
| 59 |
void ChoiceWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 60 |
{ |
| 61 |
text << XRCPrefix() << XRCCommonAttributes() << XRCStyle() << XRCSize() << XRCContentItems() << XRCSelection() |
| 62 |
<< XRCSuffix(); |
| 63 |
} |
| 64 |
|
| 65 |
void ChoiceWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 66 |
{ |
| 67 |
// First call the base-class for the standard things |
| 68 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 69 |
|
| 70 |
// The Options (content) property has a default, so we must clear it even if the node is absent |
| 71 |
wxString multistring; |
| 72 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content")); |
| 73 |
if(propertynode) { multistring = XmlUtils::ChildNodesContentToString(propertynode); } |
| 74 |
SetPropertyString(PROP_OPTIONS, multistring); |
| 75 |
|
| 76 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("selection")); |
| 77 |
if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); } |
| 78 |
} |
| 79 |
|
| 80 |
void ChoiceWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 81 |
{ |
| 82 |
// First call the base-class for the standard things |
| 83 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 84 |
|
| 85 |
// The Options (content) property has a default, so we must clear it even if the node is absent |
| 86 |
wxString multistring; |
| 87 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content")); |
| 88 |
if(propertynode) { multistring = XmlUtils::ChildNodesContentToString(propertynode); } |
| 89 |
SetPropertyString(PROP_OPTIONS, multistring); |
| 90 |
|
| 91 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("selection")); |
| 92 |
if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); } |
| 93 |
} |
| 94 |
|
| 95 |
void ChoiceWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 96 |
{ |
| 97 |
// First call the base-class for the standard things |
| 98 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 99 |
|
| 100 |
// The "choices" property has a default, so we should clear it even if the node was absent |
| 101 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "choices"); |
| 102 |
wxString content; |
| 103 |
if(propertynode) { content = ImportFromwxFB::ConvertFBOptionsString(propertynode->GetNodeContent()); } |
| 104 |
SetPropertyString(PROP_OPTIONS, content); |
| 105 |
|
| 106 |
propertynode = XmlUtils::FindNodeByName(node, "property", "selection"); |
| 107 |
if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); } |
| 108 |
} |