| 1 |
#include "radio_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 |
RadioBoxWrapper::RadioBoxWrapper() |
| 10 |
: wxcWidget(ID_WXRADIOBOX) |
| 11 |
{ |
| 12 |
PREPEND_STYLE(wxRA_SPECIFY_ROWS, false); |
| 13 |
PREPEND_STYLE(wxRA_SPECIFY_COLS, false); |
| 14 |
|
| 15 |
SetPropertyString(_("Common Settings"), "wxRadioBox"); |
| 16 |
AddProperty(new StringProperty(PROP_LABEL, _("My RadioBox"), _("Label"))); |
| 17 |
AddProperty(new MultiStringsProperty(PROP_OPTIONS, _("An array of choices with which to initialize the radiobox"))); |
| 18 |
AddProperty(new StringProperty(PROP_SELECTION, wxT("0"), _("The zero-based position of the selected button"))); |
| 19 |
AddProperty(new StringProperty(PROP_MAJORDIM, wxT("1"), |
| 20 |
_("Specifies the maximum number of rows (if style contains wxRA_SPECIFY_ROWS) or " |
| 21 |
"columns (if style contains wxRA_SPECIFY_COLS) for a two-dimensional radiobox"))); |
| 22 |
|
| 23 |
RegisterEventCommand(wxT("wxEVT_COMMAND_RADIOBOX_SELECTED"), |
| 24 |
_("Process a wxEVT_COMMAND_RADIOBOX_SELECTED event, when a radiobutton is clicked.")); |
| 25 |
DoSetPropertyStringValue(PROP_OPTIONS, wxT("An option;Second Option")); |
| 26 |
|
| 27 |
m_namePattern = wxT("m_radioBox"); |
| 28 |
SetName(GenerateName()); |
| 29 |
} |
| 30 |
|
| 31 |
RadioBoxWrapper::~RadioBoxWrapper() {} |
| 32 |
|
| 33 |
wxcWidget* RadioBoxWrapper::Clone() const { return new RadioBoxWrapper(); } |
| 34 |
|
| 35 |
wxString RadioBoxWrapper::CppCtorCode() const |
| 36 |
{ |
| 37 |
wxString code, arrname; |
| 38 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_OPTIONS), wxT(";")); |
| 39 |
|
| 40 |
arrname << GetName() << wxT("Arr"); |
| 41 |
|
| 42 |
code << wxT("wxArrayString ") << arrname << wxT(";\n"); |
| 43 |
|
| 44 |
for(size_t i = 0; i < options.GetCount(); i++) { |
| 45 |
code << arrname << wxT(".Add(") << wxCrafter::UNDERSCORE(options.Item(i)) << wxT(");\n"); |
| 46 |
} |
| 47 |
|
| 48 |
// wxRadioBox(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& point, const wxSize& size, |
| 49 |
// const wxArrayString& choices, int majorDimension = 0, long style = wxRA_SPECIFY_COLS, const wxValidator& |
| 50 |
// validator = wxDefaultValidator, const wxString& name = "radioBox") |
| 51 |
code << GetName() << wxT(" = new ") << GetRealClassName() << "(" << GetWindowParent() << wxT(", ") << WindowID() |
| 52 |
<< wxT(", ") << Label() << wxT(", ") << wxT("wxDefaultPosition, ") << SizeAsString() << wxT(", ") << arrname |
| 53 |
<< wxT(", ") << PropertyString(PROP_MAJORDIM) << wxT(", ") << StyleFlags(wxT("0")) << wxT(");\n"); |
| 54 |
code << CPPCommonAttributes(); |
| 55 |
int sel = wxCrafter::ToNumber(PropertyString(PROP_SELECTION), -1); |
| 56 |
if(sel >= 0 && sel < (int)options.GetCount()) { |
| 57 |
code << GetName() << wxT("->SetSelection(") << PropertyString(PROP_SELECTION) << wxT(");\n"); |
| 58 |
} |
| 59 |
return code; |
| 60 |
} |
| 61 |
|
| 62 |
void RadioBoxWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/radiobox.h>")); } |
| 63 |
|
| 64 |
wxString RadioBoxWrapper::GetWxClassName() const { return wxT("wxRadioBox"); } |
| 65 |
|
| 66 |
void RadioBoxWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 67 |
{ |
| 68 |
text << XRCPrefix() << XRCLabel() << XRCSize() << XRCStyle() << XRCCommonAttributes() << wxT("<dimension>") |
| 69 |
<< PropertyString(PROP_MAJORDIM) << wxT("</dimension>") << XRCSelection() << XRCContentItems(true) |
| 70 |
<< XRCSuffix(); |
| 71 |
} |
| 72 |
|
| 73 |
void RadioBoxWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 74 |
{ |
| 75 |
// First call the base-class for the standard things |
| 76 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 77 |
|
| 78 |
// The Options (content) property has a default, so we must clear it even if the node is absent |
| 79 |
wxString multistring; |
| 80 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content")); |
| 81 |
if(propertynode) { multistring = XmlUtils::ChildNodesContentToString(propertynode); } |
| 82 |
SetPropertyString(PROP_OPTIONS, multistring); |
| 83 |
|
| 84 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("selection")); |
| 85 |
if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); } |
| 86 |
|
| 87 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("dimension")); |
| 88 |
if(propertynode) { SetPropertyString(PROP_MAJORDIM, propertynode->GetNodeContent()); } |
| 89 |
} |
| 90 |
|
| 91 |
void RadioBoxWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 92 |
{ |
| 93 |
// First call the base-class for the standard things |
| 94 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 95 |
|
| 96 |
// The Options (content) property has a default, so we must clear it even if the node is absent |
| 97 |
wxString multistring; |
| 98 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("content")); |
| 99 |
if(propertynode) { multistring = XmlUtils::ChildNodesContentToString(propertynode); } |
| 100 |
SetPropertyString(PROP_OPTIONS, multistring); |
| 101 |
|
| 102 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("default")); |
| 103 |
if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); } |
| 104 |
|
| 105 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("dimension")); |
| 106 |
if(propertynode) { SetPropertyString(PROP_MAJORDIM, propertynode->GetNodeContent()); } |
| 107 |
} |
| 108 |
|
| 109 |
void RadioBoxWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 110 |
{ |
| 111 |
// First call the base-class for the standard things |
| 112 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 113 |
|
| 114 |
// The "choices" property has a default, so we should clear it even if the node was absent |
| 115 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "choices"); |
| 116 |
wxString content; |
| 117 |
if(propertynode) { content = ImportFromwxFB::ConvertFBOptionsString(propertynode->GetNodeContent()); } |
| 118 |
SetPropertyString(PROP_OPTIONS, content); |
| 119 |
|
| 120 |
propertynode = XmlUtils::FindNodeByName(node, "property", "selection"); |
| 121 |
if(propertynode) { SetPropertyString(PROP_SELECTION, propertynode->GetNodeContent()); } |
| 122 |
|
| 123 |
propertynode = XmlUtils::FindNodeByName(node, "property", "majorDimension"); |
| 124 |
if(propertynode) { SetPropertyString(PROP_MAJORDIM, propertynode->GetNodeContent()); } |
| 125 |
} |