| 1 |
#include "list_box_wrapper.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "import_from_wxFB.h" |
| 4 |
#include "multi_strings_property.h" |
| 5 |
#include "wxgui_defs.h" |
| 6 |
#include "wxgui_helpers.h" |
| 7 |
#include "xmlutils.h" |
| 8 |
|
| 9 |
ListBoxWrapper::ListBoxWrapper() |
| 10 |
: wxcWidget(ID_WXLISTBOX) |
| 11 |
{ |
| 12 |
PREPEND_STYLE(wxLB_SINGLE, true); |
| 13 |
PREPEND_STYLE(wxLB_MULTIPLE, false); |
| 14 |
PREPEND_STYLE(wxLB_EXTENDED, false); |
| 15 |
PREPEND_STYLE(wxLB_HSCROLL, false); |
| 16 |
PREPEND_STYLE(wxLB_ALWAYS_SB, false); |
| 17 |
PREPEND_STYLE(wxLB_NEEDED_SB, false); |
| 18 |
PREPEND_STYLE(wxLB_SORT, false); |
| 19 |
|
| 20 |
RegisterEventCommand(wxT("wxEVT_COMMAND_LISTBOX_SELECTED"), |
| 21 |
_("Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the list is selected or " |
| 22 |
"the selection changes.")); |
| 23 |
RegisterEventCommand( |
| 24 |
wxT("wxEVT_COMMAND_LISTBOX_DOUBLECLICKED"), |
| 25 |
_("Process a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox is double-clicked.")); |
| 26 |
|
| 27 |
SetPropertyString(_("Common Settings"), "wxListBox"); |
| 28 |
AddProperty(new MultiStringsProperty(PROP_OPTIONS, _("The List Box Items. A semi-colon list of strings"))); |
| 29 |
AddProperty(new StringProperty( |
| 30 |
PROP_SELECTION, wxT("-1"), |
| 31 |
_("The zero-based position of any initially selected string, or -1 if none are to be selected"))); |
| 32 |
|
| 33 |
m_namePattern = wxT("m_listBox"); |
| 34 |
SetName(GenerateName()); |
| 35 |
} |
| 36 |
|
| 37 |
ListBoxWrapper::~ListBoxWrapper() {} |
| 38 |
|
| 39 |
wxcWidget* ListBoxWrapper::Clone() const { return new ListBoxWrapper(); } |
| 40 |
|
| 41 |
wxString ListBoxWrapper::CppCtorCode() const |
| 42 |
{ |
| 43 |
wxString code; |
| 44 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_OPTIONS), wxT(";")); |
| 45 |
|
| 46 |
wxString optionsArr; |
| 47 |
optionsArr << GetName() << wxT("Arr"); |
| 48 |
|
| 49 |
code << wxT("wxArrayString ") << optionsArr << wxT(";\n"); |
| 50 |
for(size_t i = 0; i < options.GetCount(); i++) { |
| 51 |
code << optionsArr << wxT(".Add(") << wxCrafter::UNDERSCORE(options.Item(i)) << wxT(");\n"); |
| 52 |
} |
| 53 |
|
| 54 |
code << GetName() << wxT(" = new ") << GetRealClassName() << "(" << GetWindowParent() << wxT(", ") << WindowID() |
| 55 |
<< wxT(", ") << wxT("wxDefaultPosition, ") << SizeAsString() << wxT(", ") << optionsArr << wxT(", ") |
| 56 |
<< StyleFlags(wxT("0")) << wxT(");\n"); |
| 57 |
code << CPPCommonAttributes(); |
| 58 |
|
| 59 |
int sel = wxCrafter::ToNumber(PropertyString(PROP_SELECTION), -1); |
| 60 |
if(sel >= 0 && sel < (int)options.GetCount()) { |
| 61 |
code << GetName() << wxT("->SetSelection(") << PropertyString(PROP_SELECTION) << wxT(");\n"); |
| 62 |
} |
| 63 |
return code; |
| 64 |
} |
| 65 |
|
| 66 |
void ListBoxWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/listbox.h>")); } |
| 67 |
|
| 68 |
wxString ListBoxWrapper::GetWxClassName() const { return wxT("wxListBox"); } |
| 69 |
|
| 70 |
void ListBoxWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 71 |
{ |
| 72 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_OPTIONS), wxT(";")); |
| 73 |
text << XRCPrefix() << XRCStyle() << XRCSize() << XRCCommonAttributes() << XRCContentItems() << XRCSelection() |
| 74 |
<< XRCSuffix(); |
| 75 |
} |
| 76 |
|
| 77 |
void ListBoxWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 78 |
{ |
| 79 |
// First call the base-class for the standard things |
| 80 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 81 |
|
| 82 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content")); |
| 83 |
if(propertynode) { SetPropertyString(PROP_OPTIONS, XmlUtils::ChildNodesContentToString(propertynode)); } |
| 84 |
|
| 85 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("selection")); |
| 86 |
if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); } |
| 87 |
} |
| 88 |
|
| 89 |
void ListBoxWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 90 |
{ |
| 91 |
// First call the base-class for the standard things |
| 92 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 93 |
|
| 94 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("default")); |
| 95 |
if(propertynode) { SetPropertyString(PROP_OPTIONS, XmlUtils::ChildNodesContentToString(propertynode)); } |
| 96 |
|
| 97 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("selection")); |
| 98 |
if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); } |
| 99 |
} |
| 100 |
|
| 101 |
void ListBoxWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 102 |
{ |
| 103 |
// First call the base-class for the standard things |
| 104 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 105 |
|
| 106 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "choices"); |
| 107 |
if(propertynode) { |
| 108 |
SetPropertyString(PROP_OPTIONS, ImportFromwxFB::ConvertFBOptionsString(propertynode->GetNodeContent())); |
| 109 |
} |
| 110 |
|
| 111 |
// NB wxFb doesn't do 'selection' for listboxes |
| 112 |
} |