| 1 |
#include "property_grid_wrapper.h" |
| 2 |
|
| 3 |
#include "allocator_mgr.h" |
| 4 |
#include "bool_property.h" |
| 5 |
#include "choice_property.h" |
| 6 |
#include "color_property.h" |
| 7 |
#include "font_property.h" |
| 8 |
#include "int_property.h" |
| 9 |
#include "multi_strings_property.h" |
| 10 |
#include "string_property.h" |
| 11 |
#include "wxgui_helpers.h" |
| 12 |
|
| 13 |
#define PROP_PG_BOOL_VALUE "Bool Value" |
| 14 |
#define PROP_PG_STRING_VALUE "String Value" |
| 15 |
#define PROP_PG_CHOICES PROP_OPTIONS |
| 16 |
#define PROP_PG_ENUM_CHOICES PROP_OPTIONS |
| 17 |
#define PROP_PG_CHOICES_VALUES "Array Integer Values" |
| 18 |
#define PROP_PG_WILDCARD "Wildcard" |
| 19 |
#define PROP_PG_COLOUR_DEFAULT "Initial Colour" |
| 20 |
|
| 21 |
PropertyGridWrapper::PropertyGridWrapper() |
| 22 |
: wxcWidget(ID_WXPGPROPERTY) |
| 23 |
{ |
| 24 |
m_properties.DeleteValues(); |
| 25 |
m_sizerFlags.Clear(); |
| 26 |
m_styles.Clear(); |
| 27 |
static int labelCount = 0; |
| 28 |
|
| 29 |
wxArrayString customEditors; |
| 30 |
customEditors.Add(""); // 0 |
| 31 |
customEditors.Add("TextCtrl"); // 1 |
| 32 |
customEditors.Add("Choice"); // 2 |
| 33 |
customEditors.Add("ComboBox"); // 3 |
| 34 |
customEditors.Add("CheckBox"); // 4 |
| 35 |
customEditors.Add("TextCtrlAndButton"); // 5 (default) |
| 36 |
customEditors.Add("ChoiceAndButton"); // 6 |
| 37 |
customEditors.Add("SpinCtrl"); // 7 |
| 38 |
customEditors.Add("DatePickerCtrl"); // 8 |
| 39 |
|
| 40 |
SetPropertyString(_("Common Settings"), "wxPropertyGrid"); |
| 41 |
AddProperty(new CategoryProperty("wxPGProperty")); |
| 42 |
AddProperty(new StringProperty(PROP_NAME, "", _("The property name"))); |
| 43 |
AddProperty(new StringProperty(PROP_LABEL, wxString("My Label") << ++labelCount, _("The property label"))); |
| 44 |
AddProperty(new MultiStringsProperty(PROP_TOOLTIP, _("The property help string"))); |
| 45 |
AddProperty(new ColorProperty(PROP_BG, "<Default>", _("Property background colour"))); |
| 46 |
AddProperty(new ChoiceProperty(PROP_CUSTOM_EDITOR, customEditors, 0, _("Set custom editor control to a property"))); |
| 47 |
|
| 48 |
wxArrayString kindArr; |
| 49 |
kindArr.Add("wxPropertyCategory"); // 0 |
| 50 |
kindArr.Add("wxIntProperty"); // 1 |
| 51 |
kindArr.Add("wxFloatProperty"); // 2 |
| 52 |
kindArr.Add("wxBoolProperty"); // 3 |
| 53 |
kindArr.Add("wxStringProperty"); // 4 (default) |
| 54 |
kindArr.Add("wxLongStringProperty"); // 5 |
| 55 |
kindArr.Add("wxDirProperty"); // 6 |
| 56 |
kindArr.Add("wxArrayStringProperty"); // 7 |
| 57 |
kindArr.Add("wxFileProperty"); // 8 |
| 58 |
kindArr.Add("wxEnumProperty"); // 9 |
| 59 |
kindArr.Add("wxEditEnumProperty"); // 10 |
| 60 |
kindArr.Add("wxFlagsProperty"); // 11 |
| 61 |
kindArr.Add("wxDateProperty"); // 12 |
| 62 |
kindArr.Add("wxImageFileProperty"); // 13 |
| 63 |
kindArr.Add("wxFontProperty"); // 14 |
| 64 |
kindArr.Add("wxSystemColourProperty"); // 15 |
| 65 |
|
| 66 |
AddProperty(new ChoiceProperty(PROP_KIND, kindArr, 4, _("The property kind"))); |
| 67 |
|
| 68 |
AddProperty(new CategoryProperty("wxPGProperty")); |
| 69 |
AddProperty(new StringProperty(PROP_PG_STRING_VALUE, "", _("Initial string value"))); |
| 70 |
AddProperty(new MultiStringsProperty(PROP_PG_CHOICES, |
| 71 |
_("For properties that accepts array of strings (wxEnumProperty, " |
| 72 |
"wxEditEnumProperty and wxFlagsProperty) set the strings display name"))); |
| 73 |
AddProperty(new MultiStringsProperty( |
| 74 |
PROP_PG_CHOICES_VALUES, |
| 75 |
_("For properties that accepts array of strings (wxEnumProperty, wxEditEnumProperty and wxFlagsProperty) set " |
| 76 |
"the strings values (optional for wxEnumProperty and wxEditEnumProperty)"))); |
| 77 |
|
| 78 |
AddProperty(new CategoryProperty("wxBoolProperty")); |
| 79 |
AddProperty(new BoolProperty(PROP_PG_BOOL_VALUE, true, _("Initial value, relevant to wxBoolProperty"))); |
| 80 |
|
| 81 |
AddProperty(new CategoryProperty("wxFileProperty")); |
| 82 |
AddProperty(new StringProperty(PROP_PG_WILDCARD, "", _("wxFileProperty's wildcard"))); |
| 83 |
|
| 84 |
AddProperty(new CategoryProperty("wxFontProperty")); |
| 85 |
AddProperty(new FontProperty(PROP_FONT, "", _("Initial font"))); |
| 86 |
|
| 87 |
AddProperty(new CategoryProperty("wxSystemColourProperty")); |
| 88 |
AddProperty(new ColorProperty(PROP_PG_COLOUR_DEFAULT, "<Default>", _("Initial Colour"))); |
| 89 |
|
| 90 |
m_namePattern = "m_pgProp"; |
| 91 |
SetName(GenerateName()); |
| 92 |
} |
| 93 |
|
| 94 |
PropertyGridWrapper::~PropertyGridWrapper() {} |
| 95 |
|
| 96 |
wxcWidget* PropertyGridWrapper::Clone() const { return new PropertyGridWrapper(); } |
| 97 |
|
| 98 |
wxString PropertyGridWrapper::CppCtorCode() const |
| 99 |
{ |
| 100 |
wxString grid = GetWindowParent(); |
| 101 |
wxString appendFunc = "Append( "; |
| 102 |
if(GetParent()->GetType() == ID_WXPGPROPERTY) { |
| 103 |
appendFunc = "AppendIn( " + GetParent()->GetName() + ", "; |
| 104 |
} |
| 105 |
|
| 106 |
wxString cppCode; |
| 107 |
|
| 108 |
wxString proptype = PropertyString(PROP_KIND); |
| 109 |
wxString strvalue; |
| 110 |
wxString arrName = grid + "Arr"; |
| 111 |
wxString arrIntName = grid + "IntArr"; |
| 112 |
wxString propName = GetName(); |
| 113 |
|
| 114 |
if(proptype == "wxBoolProperty") { |
| 115 |
strvalue = PropertyString(PROP_PG_BOOL_VALUE); |
| 116 |
|
| 117 |
} else if(proptype == "wxIntProperty" || proptype == "wxFloatProperty") { |
| 118 |
strvalue = PropertyString(PROP_PG_STRING_VALUE); |
| 119 |
strvalue.Trim().Trim(false); |
| 120 |
if(strvalue.IsEmpty()) { |
| 121 |
strvalue = "0"; |
| 122 |
} |
| 123 |
|
| 124 |
} else if(proptype == "wxFlagsProperty") { |
| 125 |
strvalue = PropertyString(PROP_PG_STRING_VALUE); |
| 126 |
strvalue.Trim().Trim(false); |
| 127 |
if(strvalue.IsEmpty()) { |
| 128 |
strvalue = "0"; |
| 129 |
} |
| 130 |
|
| 131 |
} else { |
| 132 |
strvalue = wxCrafter::UNDERSCORE(PropertyString(PROP_PG_STRING_VALUE)); |
| 133 |
} |
| 134 |
|
| 135 |
if(proptype == "wxIntProperty" || proptype == "wxFloatProperty" || proptype == "wxBoolProperty" || |
| 136 |
proptype == "wxStringProperty" || proptype == "wxLongStringProperty" || proptype == "wxDirProperty" || |
| 137 |
proptype == "wxFileProperty") { |
| 138 |
|
| 139 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new " << proptype << "( " |
| 140 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ", wxPG_LABEL, " << strvalue << ") );\n"; |
| 141 |
|
| 142 |
if(proptype == "wxFileProperty") { |
| 143 |
cppCode << "#if !defined(__WXOSX__) && !defined(_WIN64)\n"; |
| 144 |
cppCode << propName << "->SetAttribute(wxPG_FILE_WILDCARD, " |
| 145 |
<< wxCrafter::WXT(PropertyString(PROP_PG_WILDCARD)) << ");\n"; |
| 146 |
cppCode << "#endif // !defined(__WXOSX__) && !defined(_WIN64)\n"; |
| 147 |
cppCode << propName << "->SetAttribute(\"ShowFullPath\", 1);\n"; |
| 148 |
} |
| 149 |
|
| 150 |
} else if(proptype == "wxPropertyCategory") { |
| 151 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new wxPropertyCategory( " |
| 152 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << " ) );\n"; |
| 153 |
|
| 154 |
} else if(proptype == "wxArrayStringProperty") { |
| 155 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_PG_CHOICES), ";"); |
| 156 |
cppCode << arrName << ".Clear();\n"; |
| 157 |
for(size_t i = 0; i < options.GetCount(); ++i) { |
| 158 |
cppCode << arrName << ".Add(" << wxCrafter::UNDERSCORE(options.Item(i)) << ");\n"; |
| 159 |
} |
| 160 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new " << proptype << "( " |
| 161 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ", wxPG_LABEL, " << arrName << ") );\n"; |
| 162 |
|
| 163 |
} else if(proptype == "wxEnumProperty") { |
| 164 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_PG_CHOICES), ";"); |
| 165 |
cppCode << arrName << ".Clear();\n"; |
| 166 |
cppCode << arrIntName << ".Clear();\n"; |
| 167 |
size_t selection = 0; |
| 168 |
for(size_t i = 0; i < options.GetCount(); ++i) { |
| 169 |
cppCode << arrName << ".Add(" << wxCrafter::UNDERSCORE(options.Item(i)) << ");\n"; |
| 170 |
if(wxCrafter::UNDERSCORE(options.Item(i)) == strvalue) { |
| 171 |
selection = i; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
options = wxCrafter::Split(PropertyString(PROP_PG_CHOICES_VALUES), ";"); |
| 176 |
for(size_t i = 0; i < options.GetCount(); ++i) { |
| 177 |
cppCode << arrIntName << ".Add(" << options.Item(i) << ");\n"; |
| 178 |
} |
| 179 |
|
| 180 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new " << proptype << "( " |
| 181 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ", wxPG_LABEL, " << arrName << ", " |
| 182 |
<< arrIntName << ", " << selection << ") );\n"; |
| 183 |
|
| 184 |
} else if(proptype == "wxEditEnumProperty") { |
| 185 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_PG_CHOICES), ";"); |
| 186 |
cppCode << arrName << ".Clear();\n"; |
| 187 |
cppCode << arrIntName << ".Clear();\n"; |
| 188 |
for(size_t i = 0; i < options.GetCount(); ++i) { |
| 189 |
cppCode << arrName << ".Add(" << wxCrafter::UNDERSCORE(options.Item(i)) << ");\n"; |
| 190 |
} |
| 191 |
|
| 192 |
options = wxCrafter::Split(PropertyString(PROP_PG_CHOICES_VALUES), ";"); |
| 193 |
for(size_t i = 0; i < options.GetCount(); ++i) { |
| 194 |
cppCode << arrIntName << ".Add(" << options.Item(i) << ");\n"; |
| 195 |
} |
| 196 |
|
| 197 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new " << proptype << "( " |
| 198 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ", wxPG_LABEL, " << arrName << ", " |
| 199 |
<< arrIntName << ", " << strvalue << ") );\n"; |
| 200 |
|
| 201 |
} else if(proptype == "wxFlagsProperty") { |
| 202 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_PG_CHOICES), ";"); |
| 203 |
cppCode << arrName << ".Clear();\n"; |
| 204 |
cppCode << arrIntName << ".Clear();\n"; |
| 205 |
for(size_t i = 0; i < options.GetCount(); ++i) { |
| 206 |
cppCode << arrName << ".Add(" << wxCrafter::UNDERSCORE(options.Item(i)) << ");\n"; |
| 207 |
} |
| 208 |
|
| 209 |
options = wxCrafter::Split(PropertyString(PROP_PG_CHOICES_VALUES), ";"); |
| 210 |
for(size_t i = 0; i < options.GetCount(); ++i) { |
| 211 |
cppCode << arrIntName << ".Add(" << options.Item(i) << ");\n"; |
| 212 |
} |
| 213 |
|
| 214 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new " << proptype << "( " |
| 215 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ", wxPG_LABEL, " << arrName << ", " |
| 216 |
<< arrIntName << ", " << strvalue << ") );\n"; |
| 217 |
|
| 218 |
} else if(proptype == "wxDateProperty") { |
| 219 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new wxDateProperty( " |
| 220 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ", wxPG_LABEL, wxDateTime::Now()) );\n"; |
| 221 |
|
| 222 |
} else if(proptype == "wxImageFileProperty") { |
| 223 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new wxImageFileProperty( " |
| 224 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ") );\n"; |
| 225 |
|
| 226 |
} else if(proptype == "wxFontProperty") { |
| 227 |
wxString fontMemberName = propName + "Font"; |
| 228 |
wxString font = wxCrafter::FontToCpp(PropertyString(PROP_FONT), fontMemberName); |
| 229 |
if(!font.IsEmpty() && font != "wxNullFont") { |
| 230 |
cppCode << font; |
| 231 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new wxFontProperty( " |
| 232 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ", wxPG_LABEL, " << fontMemberName |
| 233 |
<< ") );\n"; |
| 234 |
|
| 235 |
} else { |
| 236 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new wxFontProperty( " |
| 237 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ") );\n"; |
| 238 |
cppCode << propName << "->SetValueToUnspecified();\n"; |
| 239 |
} |
| 240 |
} else if(proptype == "wxSystemColourProperty") { |
| 241 |
wxString colorname = wxCrafter::ColourToCpp(PropertyString(PROP_PG_COLOUR_DEFAULT)); |
| 242 |
if(!colorname.IsEmpty()) { |
| 243 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new wxSystemColourProperty( " |
| 244 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ", wxPG_LABEL, " << colorname << ") );\n"; |
| 245 |
} else { |
| 246 |
cppCode << propName << " = " << grid << "->" << appendFunc << " new wxSystemColourProperty( " |
| 247 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << ") );\n"; |
| 248 |
cppCode << propName << "->SetValueToUnspecified();\n"; |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
if(!cppCode.IsEmpty()) { |
| 253 |
// set common properties |
| 254 |
cppCode << propName << "->SetHelpString(" << wxCrafter::UNDERSCORE(PropertyString(PROP_TOOLTIP)) << ");\n"; |
| 255 |
} |
| 256 |
|
| 257 |
wxString propEditor = PropertyString(PROP_CUSTOM_EDITOR); |
| 258 |
if(!propEditor.IsEmpty()) { |
| 259 |
cppCode << propName << "->SetEditor( " << wxCrafter::WXT(propEditor) << " );\n"; |
| 260 |
} |
| 261 |
return cppCode; |
| 262 |
} |
| 263 |
|
| 264 |
void PropertyGridWrapper::GetIncludeFile(wxArrayString& headers) const |
| 265 |
{ |
| 266 |
headers.Add("#include <wx/propgrid/property.h>"); |
| 267 |
headers.Add("#include <wx/propgrid/advprops.h>"); |
| 268 |
} |
| 269 |
|
| 270 |
wxString PropertyGridWrapper::GetWxClassName() const { return "wxPGProperty"; } |
| 271 |
|
| 272 |
void PropertyGridWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 273 |
{ |
| 274 |
if(type == XRC_LIVE) { |
| 275 |
return; |
| 276 |
|
| 277 |
} else { |
| 278 |
wxString value = wxCrafter::CDATA(PropertyString(PROP_PG_STRING_VALUE)); |
| 279 |
if(PropertyString(PROP_KIND) == "wxBoolProperty") { |
| 280 |
value = PropertyString(PROP_PG_BOOL_VALUE); |
| 281 |
} |
| 282 |
|
| 283 |
text << "<object class=\"wxPGProperty\">" |
| 284 |
<< "<proptype>" << PropertyString(PROP_KIND) << "</proptype>" |
| 285 |
<< "<label>" << wxCrafter::CDATA(PropertyString(PROP_LABEL)) << "</label>" |
| 286 |
<< "<value>" << value << "</value>" |
| 287 |
<< "<wildcard>" << wxCrafter::CDATA(PropertyString(PROP_PG_WILDCARD)) << "</wildcard>" |
| 288 |
<< "<editor>" << wxCrafter::CDATA(PropertyString(PROP_CUSTOM_EDITOR)) << "</editor>" |
| 289 |
<< XRCCommonAttributes() << XRCContentItems(); |
| 290 |
ChildrenXRC(text, type); |
| 291 |
text << XRCSuffix(); |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
bool PropertyGridWrapper::IsValidParent() const { return false; } |
| 296 |
|
| 297 |
bool PropertyGridWrapper::IsWxWindow() const { return false; } |
| 298 |
|
| 299 |
wxString PropertyGridWrapper::DoGenerateCppCtorCode_End() const |
| 300 |
{ |
| 301 |
// We set the colour attribute here since it needs to be placed after |
| 302 |
// all children have been added |
| 303 |
wxString cppCode; |
| 304 |
wxString colorname = wxCrafter::ColourToCpp(PropertyString(PROP_BG)); |
| 305 |
if(!colorname.IsEmpty()) { |
| 306 |
cppCode << GetName() << "->SetBackgroundColour(" << colorname << ");\n"; |
| 307 |
} |
| 308 |
return cppCode; |
| 309 |
} |