| 1 |
#include "check_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 |
CheckListBoxWrapper::CheckListBoxWrapper() |
| 10 |
: wxcWidget(ID_WXCHECKLISTBOX) |
| 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\nwhen 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\nwhen the listbox is double-clicked.")); |
| 26 |
RegisterEventCommand(wxT("wxEVT_COMMAND_CHECKLISTBOX_TOGGLED"), |
| 27 |
_("Process a wxEVT_COMMAND_CHECKLISTBOX_TOGGLED event\nwhen an item in the check list box " |
| 28 |
"is checked or unchecked.")); |
| 29 |
|
| 30 |
SetPropertyString(_("Common Settings"), "wxCheckListBox"); |
| 31 |
AddProperty(new MultiStringsProperty(PROP_OPTIONS, _("The List Box Items. A semi-colon list of strings"))); |
| 32 |
|
| 33 |
m_namePattern = wxT("m_checkListBox"); |
| 34 |
SetName(GenerateName()); |
| 35 |
} |
| 36 |
|
| 37 |
CheckListBoxWrapper::~CheckListBoxWrapper() {} |
| 38 |
|
| 39 |
wxcWidget* CheckListBoxWrapper::Clone() const { return new CheckListBoxWrapper(); } |
| 40 |
|
| 41 |
wxString CheckListBoxWrapper::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 |
return code; |
| 59 |
} |
| 60 |
|
| 61 |
void CheckListBoxWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/checklst.h>")); } |
| 62 |
|
| 63 |
wxString CheckListBoxWrapper::GetWxClassName() const { return wxT("wxCheckListBox"); } |
| 64 |
|
| 65 |
void CheckListBoxWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 66 |
{ |
| 67 |
wxUnusedVar(type); |
| 68 |
text << XRCPrefix() << XRCCommonAttributes() << XRCSize() << XRCStyle(); |
| 69 |
|
| 70 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_OPTIONS), wxT(";")); |
| 71 |
text << wxT("<content>"); |
| 72 |
|
| 73 |
for(size_t i = 0; i < options.GetCount(); i++) { |
| 74 |
text << wxT("<item checked=\"0\">") << wxCrafter::XMLEncode(options.Item(i)) << wxT("</item>"); |
| 75 |
} |
| 76 |
text << wxT("</content>"); |
| 77 |
|
| 78 |
text << XRCSuffix(); |
| 79 |
} |
| 80 |
|
| 81 |
void CheckListBoxWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 82 |
{ |
| 83 |
// First call the base-class for the standard things |
| 84 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 85 |
|
| 86 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content")); |
| 87 |
if(propertynode) { SetPropertyString(PROP_OPTIONS, XmlUtils::ChildNodesContentToString(propertynode)); } |
| 88 |
// XRC also allows a 'checked' property for each item, but as neither XRCed, wxFB or (atm) wxC support this... |
| 89 |
} |
| 90 |
|
| 91 |
void CheckListBoxWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 92 |
{ |
| 93 |
// First call the base-class for the standard things |
| 94 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 95 |
|
| 96 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content")); |
| 97 |
if(propertynode) { |
| 98 |
wxString t = XmlUtils::ChildNodesContentToString(propertynode); |
| 99 |
SetPropertyString(PROP_OPTIONS, XmlUtils::ChildNodesContentToString(propertynode)); |
| 100 |
} |
| 101 |
// XRC also allows a 'checked' property for each item. wxSmith implements this, by: |
| 102 |
// <item checked="1">Content string</item> |
| 103 |
// but (atm) wxC doesn't support this |
| 104 |
} |
| 105 |
|
| 106 |
void CheckListBoxWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 107 |
{ |
| 108 |
// First call the base-class for the standard things |
| 109 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 110 |
|
| 111 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "choices"); |
| 112 |
if(propertynode) { |
| 113 |
SetPropertyString(PROP_OPTIONS, ImportFromwxFB::ConvertFBOptionsString(propertynode->GetNodeContent())); |
| 114 |
} |
| 115 |
} |