| 1 |
#include "myxh_propgrid.h" |
| 2 |
|
| 3 |
#include <wx/datetime.h> |
| 4 |
#include <wx/log.h> |
| 5 |
#include <wx/propgrid/advprops.h> |
| 6 |
#include <wx/propgrid/manager.h> |
| 7 |
#include <wx/propgrid/propgrid.h> |
| 8 |
#include <wx/sizer.h> |
| 9 |
#include <wx/xml/xml.h> |
| 10 |
|
| 11 |
MyWxPropGridXmlHandler::MyWxPropGridXmlHandler() |
| 12 |
: wxXmlResourceHandler() |
| 13 |
, m_isInside(false) |
| 14 |
, m_pgmgr(NULL) |
| 15 |
, m_propertyParent(NULL) |
| 16 |
{ |
| 17 |
XRC_ADD_STYLE(wxPG_AUTO_SORT); |
| 18 |
XRC_ADD_STYLE(wxPG_HIDE_CATEGORIES); |
| 19 |
XRC_ADD_STYLE(wxPG_ALPHABETIC_MODE); |
| 20 |
XRC_ADD_STYLE(wxPG_BOLD_MODIFIED); |
| 21 |
XRC_ADD_STYLE(wxPG_SPLITTER_AUTO_CENTER); |
| 22 |
XRC_ADD_STYLE(wxPG_TOOLTIPS); |
| 23 |
XRC_ADD_STYLE(wxPG_HIDE_MARGIN); |
| 24 |
XRC_ADD_STYLE(wxPG_STATIC_SPLITTER); |
| 25 |
XRC_ADD_STYLE(wxPG_STATIC_LAYOUT); |
| 26 |
XRC_ADD_STYLE(wxPG_LIMITED_EDITING); |
| 27 |
XRC_ADD_STYLE(wxPG_TOOLBAR); |
| 28 |
XRC_ADD_STYLE(wxPG_DESCRIPTION); |
| 29 |
XRC_ADD_STYLE(wxPG_NO_INTERNAL_BORDER); |
| 30 |
AddWindowStyles(); |
| 31 |
} |
| 32 |
|
| 33 |
wxObject* MyWxPropGridXmlHandler::DoCreateResource() |
| 34 |
{ |
| 35 |
if(m_class == wxT("wxPGProperty")) { |
| 36 |
HandlePgProperty(m_propertyParent); |
| 37 |
|
| 38 |
} else { |
| 39 |
// wxPropertyGridManager |
| 40 |
XRC_MAKE_INSTANCE(pg, wxPropertyGridManager); |
| 41 |
pg->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), GetStyle(), GetName()); |
| 42 |
SetupWindow(pg); |
| 43 |
|
| 44 |
m_pgmgr = pg; |
| 45 |
m_pgmgr->AddPage("Settings"); |
| 46 |
m_propertyParent = NULL; |
| 47 |
m_isInside = true; |
| 48 |
CreateChildren(m_pgmgr, true /*only this handler*/); |
| 49 |
|
| 50 |
// add the splitter property after the children were added |
| 51 |
int splitterLeft = GetBool("splitterleft"); |
| 52 |
if(splitterLeft) { |
| 53 |
m_pgmgr->SetSplitterLeft(); |
| 54 |
} |
| 55 |
|
| 56 |
int splitterPos = GetLong("splitterpos", wxNOT_FOUND); |
| 57 |
if(splitterPos != wxNOT_FOUND) { |
| 58 |
m_pgmgr->GetPage(0)->SetSplitterPosition(splitterPos); |
| 59 |
} |
| 60 |
|
| 61 |
m_isInside = false; |
| 62 |
return m_pgmgr; |
| 63 |
} |
| 64 |
return m_parentAsWindow; |
| 65 |
} |
| 66 |
|
| 67 |
bool MyWxPropGridXmlHandler::CanHandle(wxXmlNode* node) |
| 68 |
{ |
| 69 |
return ((!m_isInside && IsOfClass(node, wxT("wxPropertyGridManager"))) || |
| 70 |
(m_isInside && IsOfClass(node, wxT("wxPGProperty")))); |
| 71 |
} |
| 72 |
|
| 73 |
void MyWxPropGridXmlHandler::HandlePgProperty(wxPGProperty* parent) |
| 74 |
{ |
| 75 |
if(!HasParam(wxT("proptype"))) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
// Property |
| 80 |
wxString proptype = GetText("proptype"); |
| 81 |
wxString label = GetText("label"); |
| 82 |
wxString value = GetText("value"); |
| 83 |
wxString wildcard = GetText("wildcard", false); |
| 84 |
wxString tip = GetText("tooltip"); |
| 85 |
wxColour bgcol = GetColour("bg"); |
| 86 |
bool bgcolRecurse = GetBool("bg-recurse"); |
| 87 |
wxString propEditor = GetText("editor", false); |
| 88 |
|
| 89 |
wxArrayString items = GetArray(GetParamNode("content")); |
| 90 |
|
| 91 |
wxPGProperty* prop = NULL; |
| 92 |
if(proptype == "wxIntProperty") { |
| 93 |
long v; |
| 94 |
value.ToLong(&v); |
| 95 |
prop = DoAppendProperty(parent, new wxIntProperty(label, wxPG_LABEL, v)); |
| 96 |
|
| 97 |
} else if(proptype == "wxFloatProperty") { |
| 98 |
double v; |
| 99 |
value.ToDouble(&v); |
| 100 |
prop = DoAppendProperty(parent, new wxFloatProperty(label, wxPG_LABEL, v)); |
| 101 |
|
| 102 |
} else if(proptype == "wxBoolProperty") { |
| 103 |
prop = DoAppendProperty(parent, new wxBoolProperty(label, wxPG_LABEL, value == "1")); |
| 104 |
|
| 105 |
} else if(proptype == "wxStringProperty") { |
| 106 |
prop = DoAppendProperty(parent, new wxStringProperty(label, wxPG_LABEL, value)); |
| 107 |
|
| 108 |
} else if(proptype == "wxLongStringProperty") { |
| 109 |
prop = DoAppendProperty(parent, new wxLongStringProperty(label, wxPG_LABEL, value)); |
| 110 |
|
| 111 |
} else if(proptype == "wxDirProperty") { |
| 112 |
prop = DoAppendProperty(parent, new wxDirProperty(label, wxPG_LABEL, value)); |
| 113 |
|
| 114 |
} else if(proptype == "wxArrayStringProperty") { |
| 115 |
prop = DoAppendProperty(parent, new wxArrayStringProperty(label, wxPG_LABEL, items)); |
| 116 |
|
| 117 |
} else if(proptype == "wxFileProperty") { |
| 118 |
prop = DoAppendProperty(parent, new wxFileProperty(label, wxPG_LABEL, value)); |
| 119 |
m_pgmgr->SetPropertyAttribute(prop, wxPG_FILE_WILDCARD, wildcard); |
| 120 |
|
| 121 |
} else if(proptype == "wxPropertyCategory") { |
| 122 |
prop = DoAppendProperty(parent, new wxPropertyCategory(label)); |
| 123 |
|
| 124 |
} else if(proptype == "wxEnumProperty") { |
| 125 |
int sel = items.Index(value); |
| 126 |
if(sel == wxNOT_FOUND) { |
| 127 |
sel = 0; |
| 128 |
} |
| 129 |
|
| 130 |
prop = DoAppendProperty(parent, new wxEnumProperty(label, wxPG_LABEL, items, wxArrayInt(), sel)); |
| 131 |
|
| 132 |
} else if(proptype == "wxEditEnumProperty") { |
| 133 |
prop = DoAppendProperty(parent, new wxEditEnumProperty(label, wxPG_LABEL, items, wxArrayInt(), value)); |
| 134 |
|
| 135 |
} else if(proptype == "wxFlagsProperty") { |
| 136 |
prop = DoAppendProperty(parent, new wxFlagsProperty(label, wxPG_LABEL, items, wxArrayInt(), 0)); |
| 137 |
|
| 138 |
} else if(proptype == "wxDateProperty") { |
| 139 |
prop = DoAppendProperty(parent, new wxDateProperty(label, wxPG_LABEL, wxDateTime::Now())); |
| 140 |
|
| 141 |
} else if(proptype == "wxImageFileProperty") { |
| 142 |
prop = DoAppendProperty(parent, new wxImageFileProperty(label)); |
| 143 |
|
| 144 |
} else if(proptype == "wxFontProperty") { |
| 145 |
prop = DoAppendProperty(parent, new wxFontProperty(label)); |
| 146 |
prop->SetValueToUnspecified(); |
| 147 |
|
| 148 |
} else if(proptype == "wxSystemColourProperty") { |
| 149 |
prop = DoAppendProperty(parent, new wxSystemColourProperty(label)); |
| 150 |
prop->SetValueToUnspecified(); |
| 151 |
} |
| 152 |
|
| 153 |
// Handle nested children |
| 154 |
if(prop) { |
| 155 |
if(bgcol.IsOk()) { |
| 156 |
prop->SetBackgroundColour(bgcol, bgcolRecurse); |
| 157 |
} |
| 158 |
if(!propEditor.IsEmpty()) { |
| 159 |
prop->SetEditor(propEditor); |
| 160 |
} |
| 161 |
prop->SetHelpString(tip); |
| 162 |
|
| 163 |
// Check to see if this property has children |
| 164 |
// But keep the current parent (incase the current parent has more children...) |
| 165 |
wxPGProperty* oldParent = m_propertyParent; |
| 166 |
m_propertyParent = prop; |
| 167 |
CreateChildren(prop, true); |
| 168 |
|
| 169 |
// Restore the old parent |
| 170 |
m_propertyParent = oldParent; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
wxArrayString MyWxPropGridXmlHandler::GetArray(const wxXmlNode* node) const |
| 175 |
{ |
| 176 |
if(!node) |
| 177 |
return wxArrayString(); |
| 178 |
|
| 179 |
wxArrayString items; |
| 180 |
wxXmlNode* child = node->GetChildren(); |
| 181 |
while(child) { |
| 182 |
if(child->GetName() == "item") { |
| 183 |
items.Add(child->GetNodeContent()); |
| 184 |
} |
| 185 |
child = child->GetNext(); |
| 186 |
} |
| 187 |
return items; |
| 188 |
} |
| 189 |
|
| 190 |
wxPGProperty* MyWxPropGridXmlHandler::DoAppendProperty(wxPGProperty* parent, wxPGProperty* prop) |
| 191 |
{ |
| 192 |
if(parent) { |
| 193 |
return m_pgmgr->GetPage(0)->AppendIn(parent, prop); |
| 194 |
} else { |
| 195 |
return m_pgmgr->GetPage(0)->Append(prop); |
| 196 |
} |
| 197 |
} |