| 1 |
#include "flexgridsizer_wrapper.h" |
| 2 |
|
| 3 |
#include "allocator_mgr.h" |
| 4 |
#include "wxgui_helpers.h" |
| 5 |
#include "xmlutils.h" |
| 6 |
|
| 7 |
FlexGridSizerWrapper::FlexGridSizerWrapper() |
| 8 |
{ |
| 9 |
m_type = ID_WXFLEXGRIDSIZER; |
| 10 |
m_styles.Clear(); // Sizer has no styles |
| 11 |
|
| 12 |
SetPropertyString(_("Common Settings"), "wxFlexGridSizer"); |
| 13 |
AddProperty(new StringProperty(PROP_COLS, "2", _("Number of columns in the grid"))); |
| 14 |
AddProperty(new StringProperty(PROP_ROWS, "0", _("Number of rows in the grid"))); |
| 15 |
AddProperty(new StringProperty(PROP_GROW_COLS, "", _("Which columns are allowed to grow. Comma separated list"))); |
| 16 |
AddProperty(new StringProperty(PROP_GROW_ROWS, "", _("Which rows are allowed to grow. Comma separated list"))); |
| 17 |
AddProperty(new StringProperty(PROP_HGAP, "0", _("The horizontal gap between grid cells"))); |
| 18 |
AddProperty(new StringProperty(PROP_VGAP, "0", _("The vertical gap between grid cells"))); |
| 19 |
|
| 20 |
EnableSizerFlag("wxEXPAND", true); |
| 21 |
m_sizerItem.SetProportion(1); |
| 22 |
|
| 23 |
m_namePattern = "flexGridSizer"; |
| 24 |
SetName(GenerateName()); |
| 25 |
} |
| 26 |
|
| 27 |
FlexGridSizerWrapper::~FlexGridSizerWrapper() {} |
| 28 |
|
| 29 |
wxString FlexGridSizerWrapper::CppCtorCode() const |
| 30 |
{ |
| 31 |
wxString code; |
| 32 |
|
| 33 |
wxArrayString growCols = wxCrafter::Split(PropertyString(PROP_GROW_COLS), ","); |
| 34 |
wxArrayString growRows = wxCrafter::Split(PropertyString(PROP_GROW_ROWS), ","); |
| 35 |
|
| 36 |
if(!KeepAsClassMember()) { |
| 37 |
code << "wxFlexGridSizer* "; |
| 38 |
} |
| 39 |
|
| 40 |
code << GetName() << " = new wxFlexGridSizer(" << PropertyString(PROP_ROWS) << ", " << PropertyString(PROP_COLS) |
| 41 |
<< ", " << PropertyString(PROP_VGAP) << ", " << PropertyString(PROP_HGAP) << ");\n" |
| 42 |
<< GetName() << "->SetFlexibleDirection( wxBOTH );\n" |
| 43 |
<< GetName() << "->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );\n"; |
| 44 |
|
| 45 |
for(size_t i = 0; i < growCols.GetCount(); i++) { |
| 46 |
code << GetName() << "->AddGrowableCol(" << growCols.Item(i) << ");\n"; |
| 47 |
} |
| 48 |
|
| 49 |
for(size_t i = 0; i < growRows.GetCount(); i++) { |
| 50 |
code << GetName() << "->AddGrowableRow(" << growRows.Item(i) << ");\n"; |
| 51 |
} |
| 52 |
code << GenerateMinSizeCode(); |
| 53 |
if(IsMainSizer()) { |
| 54 |
if(GetParent()->IsTopWindow()) { |
| 55 |
code << "this->SetSizer(" << GetName() << ");\n"; |
| 56 |
} else { |
| 57 |
code << GetWindowParent() << "->SetSizer(" << GetName() << ");\n"; |
| 58 |
} |
| 59 |
} |
| 60 |
return code; |
| 61 |
} |
| 62 |
|
| 63 |
void FlexGridSizerWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 64 |
{ |
| 65 |
text << wxT("<object class=\"wxFlexGridSizer\">") << GenerateMinSizeXRC() << "<cols>" << PropertyString(PROP_COLS) |
| 66 |
<< "</cols>" |
| 67 |
<< "<rows>" << PropertyString(PROP_ROWS) << "</rows>" |
| 68 |
<< "<vgap>" << PropertyString(PROP_VGAP) << "</vgap>" |
| 69 |
<< "<hgap>" << PropertyString(PROP_HGAP) << "</hgap>" |
| 70 |
<< "<growablecols>" << PropertyString(PROP_GROW_COLS) << "</growablecols>" |
| 71 |
<< "<growablerows>" << PropertyString(PROP_GROW_ROWS) << "</growablerows>"; |
| 72 |
ChildrenXRC(text, type); |
| 73 |
text << "</object>"; |
| 74 |
} |
| 75 |
|
| 76 |
wxString FlexGridSizerWrapper::GetWxClassName() const { return "wxFlexGridSizer"; } |
| 77 |
|
| 78 |
void FlexGridSizerWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 79 |
{ |
| 80 |
wxcWidget::LoadPropertiesFromXRC(node); // Baseclass stuff first |
| 81 |
|
| 82 |
DoLoadXRCProperties(node); |
| 83 |
} |
| 84 |
|
| 85 |
void FlexGridSizerWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 86 |
{ |
| 87 |
wxcWidget::LoadPropertiesFromwxSmith(node); // Baseclass stuff first |
| 88 |
|
| 89 |
DoLoadXRCProperties(node); |
| 90 |
} |
| 91 |
|
| 92 |
void FlexGridSizerWrapper::DoLoadXRCProperties(const wxXmlNode* node) |
| 93 |
{ |
| 94 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, "cols"); |
| 95 |
if(propertynode) { |
| 96 |
SetPropertyString(PROP_COLS, propertynode->GetNodeContent()); |
| 97 |
} |
| 98 |
|
| 99 |
propertynode = XmlUtils::FindFirstByTagName(node, "rows"); |
| 100 |
if(propertynode) { |
| 101 |
SetPropertyString(PROP_ROWS, propertynode->GetNodeContent()); |
| 102 |
} |
| 103 |
|
| 104 |
propertynode = XmlUtils::FindFirstByTagName(node, "vgap"); |
| 105 |
if(propertynode) { |
| 106 |
SetPropertyString(PROP_VGAP, propertynode->GetNodeContent()); |
| 107 |
} |
| 108 |
|
| 109 |
propertynode = XmlUtils::FindFirstByTagName(node, "hgap"); |
| 110 |
if(propertynode) { |
| 111 |
SetPropertyString(PROP_HGAP, propertynode->GetNodeContent()); |
| 112 |
} |
| 113 |
|
| 114 |
propertynode = XmlUtils::FindFirstByTagName(node, "growablecols"); |
| 115 |
if(propertynode) { |
| 116 |
SetPropertyString(PROP_GROW_COLS, propertynode->GetNodeContent()); |
| 117 |
} |
| 118 |
|
| 119 |
propertynode = XmlUtils::FindFirstByTagName(node, "growablerows"); |
| 120 |
if(propertynode) { |
| 121 |
SetPropertyString(PROP_GROW_ROWS, propertynode->GetNodeContent()); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
void FlexGridSizerWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 126 |
{ |
| 127 |
// First call the base-class for the standard things |
| 128 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 129 |
|
| 130 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "cols"); |
| 131 |
if(propertynode) { |
| 132 |
SetPropertyString(PROP_COLS, propertynode->GetNodeContent()); |
| 133 |
} |
| 134 |
|
| 135 |
propertynode = XmlUtils::FindNodeByName(node, "property", "rows"); |
| 136 |
if(propertynode) { |
| 137 |
SetPropertyString(PROP_ROWS, propertynode->GetNodeContent()); |
| 138 |
} |
| 139 |
|
| 140 |
propertynode = XmlUtils::FindNodeByName(node, "property", "vgap"); |
| 141 |
if(propertynode) { |
| 142 |
SetPropertyString(PROP_VGAP, propertynode->GetNodeContent()); |
| 143 |
} |
| 144 |
|
| 145 |
propertynode = XmlUtils::FindNodeByName(node, "property", "hgap"); |
| 146 |
if(propertynode) { |
| 147 |
SetPropertyString(PROP_HGAP, propertynode->GetNodeContent()); |
| 148 |
} |
| 149 |
|
| 150 |
propertynode = XmlUtils::FindNodeByName(node, "property", "growablecols"); |
| 151 |
if(propertynode) { |
| 152 |
SetPropertyString(PROP_GROW_COLS, propertynode->GetNodeContent()); |
| 153 |
} |
| 154 |
|
| 155 |
propertynode = XmlUtils::FindNodeByName(node, "property", "growablerows"); |
| 156 |
if(propertynode) { |
| 157 |
SetPropertyString(PROP_GROW_ROWS, propertynode->GetNodeContent()); |
| 158 |
} |
| 159 |
} |