| 1 |
#include "wxc_widget.h" |
| 2 |
|
| 3 |
#include "allocator_mgr.h" |
| 4 |
#include "bool_property.h" |
| 5 |
#include "category_property.h" |
| 6 |
#include "color_property.h" |
| 7 |
#include "custom_control_wrapper.h" |
| 8 |
#include "data_view_tree_list_ctrl_wrapper.h" |
| 9 |
#include "file_ficker_property.h" |
| 10 |
#include "file_logger.h" |
| 11 |
#include "font_property.h" |
| 12 |
#include "import_from_wxFB.h" |
| 13 |
#include "multi_strings_property.h" |
| 14 |
#include "notebook_base_wrapper.h" |
| 15 |
#include "notebook_page_wrapper.h" |
| 16 |
#include "top_level_win_wrapper.h" |
| 17 |
#include "winid_property.h" |
| 18 |
#include "wx_collapsible_pane_pane_wrapper.h" |
| 19 |
#include "wxc_bitmap_code_generator.h" |
| 20 |
#include "wxc_settings.h" |
| 21 |
#include "wxgui_defs.h" |
| 22 |
#include "wxgui_helpers.h" |
| 23 |
#include "xmlutils.h" |
| 24 |
|
| 25 |
#include <wx/app.h> |
| 26 |
#include <wx/regex.h> |
| 27 |
|
| 28 |
size_t wxcWidget::s_objCounter = 0; |
| 29 |
wxcWidget::AntiGroupMap_t wxcWidget::s_antiGroup; |
| 30 |
wxcWidget::SizerFlagsValueSet_t wxcWidget::s_sizerFlagsValue; |
| 31 |
CustomControlTemplateMap_t wxcWidget::ms_customControlsUsed; |
| 32 |
int wxcWidget::m_copyCounter = 0; |
| 33 |
|
| 34 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 35 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 |
|
| 37 |
wxcWidget::wxcWidget(int type) |
| 38 |
: m_parent(NULL) |
| 39 |
, m_type(type) |
| 40 |
, m_eventsMenu(NULL) |
| 41 |
, m_copyReason(CR_Copy) |
| 42 |
{ |
| 43 |
if(s_antiGroup.empty()) { |
| 44 |
s_antiGroup.insert(std::make_pair("wxALIGN_LEFT", wxArrayString())); |
| 45 |
s_antiGroup["wxALIGN_LEFT"].Add("wxALIGN_CENTER_HORIZONTAL"); |
| 46 |
s_antiGroup["wxALIGN_LEFT"].Add("wxALIGN_RIGHT"); |
| 47 |
|
| 48 |
s_antiGroup.insert(std::make_pair("wxALIGN_CENTER_HORIZONTAL", wxArrayString())); |
| 49 |
s_antiGroup["wxALIGN_CENTER_HORIZONTAL"].Add("wxALIGN_LEFT"); |
| 50 |
s_antiGroup["wxALIGN_CENTER_HORIZONTAL"].Add("wxALIGN_RIGHT"); |
| 51 |
|
| 52 |
s_antiGroup.insert(std::make_pair("wxALIGN_RIGHT", wxArrayString())); |
| 53 |
s_antiGroup["wxALIGN_RIGHT"].Add("wxALIGN_LEFT"); |
| 54 |
s_antiGroup["wxALIGN_RIGHT"].Add("wxALIGN_CENTER_HORIZONTAL"); |
| 55 |
|
| 56 |
s_antiGroup.insert(std::make_pair("wxALIGN_TOP", wxArrayString())); |
| 57 |
s_antiGroup["wxALIGN_TOP"].Add("wxALIGN_CENTER_VERTICAL"); |
| 58 |
s_antiGroup["wxALIGN_TOP"].Add("wxALIGN_BOTTOM"); |
| 59 |
|
| 60 |
s_antiGroup.insert(std::make_pair("wxALIGN_CENTER_VERTICAL", wxArrayString())); |
| 61 |
s_antiGroup["wxALIGN_CENTER_VERTICAL"].Add("wxALIGN_TOP"); |
| 62 |
s_antiGroup["wxALIGN_CENTER_VERTICAL"].Add("wxALIGN_BOTTOM"); |
| 63 |
|
| 64 |
s_antiGroup.insert(std::make_pair("wxALIGN_BOTTOM", wxArrayString())); |
| 65 |
s_antiGroup["wxALIGN_BOTTOM"].Add("wxALIGN_TOP"); |
| 66 |
s_antiGroup["wxALIGN_BOTTOM"].Add("wxALIGN_CENTER_VERTICAL"); |
| 67 |
} |
| 68 |
|
| 69 |
if(s_sizerFlagsValue.empty()) { |
| 70 |
s_sizerFlagsValue.insert(std::make_pair(wxALL, SZ_ALL)); |
| 71 |
s_sizerFlagsValue.insert(std::make_pair(wxLEFT, SZ_LEFT)); |
| 72 |
s_sizerFlagsValue.insert(std::make_pair(wxRIGHT, SZ_RIGHT)); |
| 73 |
s_sizerFlagsValue.insert(std::make_pair(wxTOP, SZ_TOP)); |
| 74 |
s_sizerFlagsValue.insert(std::make_pair(wxBOTTOM, SZ_BOTTOM)); |
| 75 |
s_sizerFlagsValue.insert(std::make_pair(wxEXPAND, SZ_EXPAND)); |
| 76 |
s_sizerFlagsValue.insert(std::make_pair(wxALIGN_CENTER, SZ_ALIGN_CENTER)); |
| 77 |
s_sizerFlagsValue.insert(std::make_pair(wxALIGN_LEFT, SZ_ALIGN_LEFT)); |
| 78 |
s_sizerFlagsValue.insert(std::make_pair(wxALIGN_CENTER_HORIZONTAL, SZ_ALIGN_CENTER_HORIZONTAL)); |
| 79 |
s_sizerFlagsValue.insert(std::make_pair(wxALIGN_RIGHT, SZ_ALIGN_RIGHT)); |
| 80 |
s_sizerFlagsValue.insert( |
| 81 |
std::make_pair(crafterALIGN_TOP, SZ_ALIGN_TOP)); // See the explanation inside enum SIZER_FLAG_VALUE |
| 82 |
s_sizerFlagsValue.insert(std::make_pair(wxALIGN_CENTER_VERTICAL, SZ_ALIGN_CENTER_VERTICAL)); |
| 83 |
s_sizerFlagsValue.insert(std::make_pair(wxALIGN_BOTTOM, SZ_ALIGN_BOTTOM)); |
| 84 |
s_sizerFlagsValue.insert(std::make_pair(wxRESERVE_SPACE_EVEN_IF_HIDDEN, SZ_RESERVE_SPACE_EVEN_IF_HIDDEN)); |
| 85 |
} |
| 86 |
|
| 87 |
m_sizerItem.SetBorder(DEFAULT_SIZER_BORDER); |
| 88 |
m_sizerItem.SetProportion(DEFAULT_SIZER_PROPORTION); |
| 89 |
|
| 90 |
m_gbSpan = "1,1"; |
| 91 |
m_gbPos = "0,0"; |
| 92 |
|
| 93 |
// This will act as the separator between the basic styles and the control scpecific ones |
| 94 |
ADD_STYLE(0, false); |
| 95 |
ADD_STYLE(wxFULL_REPAINT_ON_RESIZE, false); |
| 96 |
ADD_STYLE(wxWANTS_CHARS, false); |
| 97 |
ADD_STYLE(wxTAB_TRAVERSAL, false); |
| 98 |
ADD_STYLE(wxBORDER_NONE, false); |
| 99 |
ADD_STYLE(wxCLIP_CHILDREN, false); |
| 100 |
ADD_STYLE(wxALWAYS_SHOW_SB, false); |
| 101 |
ADD_STYLE(wxBORDER_STATIC, false); |
| 102 |
ADD_STYLE(wxBORDER_SIMPLE, false); |
| 103 |
ADD_STYLE(wxBORDER_SUNKEN, false); |
| 104 |
ADD_STYLE(wxBORDER_THEME, false); |
| 105 |
ADD_STYLE(wxBORDER_RAISED, false); |
| 106 |
ADD_STYLE(wxHSCROLL, false); |
| 107 |
ADD_STYLE(wxVSCROLL, false); |
| 108 |
|
| 109 |
ADD_SIZER_FLAG(wxALL, true); |
| 110 |
ADD_SIZER_FLAG(wxLEFT, true); |
| 111 |
ADD_SIZER_FLAG(wxRIGHT, true); |
| 112 |
ADD_SIZER_FLAG(wxTOP, true); |
| 113 |
ADD_SIZER_FLAG(wxBOTTOM, true); |
| 114 |
ADD_SIZER_FLAG(wxEXPAND, false); |
| 115 |
ADD_SIZER_FLAG(wxALIGN_CENTER, false); |
| 116 |
ADD_SIZER_FLAG(wxALIGN_LEFT, false); |
| 117 |
ADD_SIZER_FLAG(wxALIGN_CENTER_HORIZONTAL, false); |
| 118 |
ADD_SIZER_FLAG(wxALIGN_RIGHT, false); |
| 119 |
ADD_SIZER_FLAG(wxALIGN_TOP, false); |
| 120 |
ADD_SIZER_FLAG(wxALIGN_CENTER_VERTICAL, false); |
| 121 |
ADD_SIZER_FLAG(wxALIGN_BOTTOM, false); |
| 122 |
|
| 123 |
if(GetType() == ID_WXSTATICBOXSIZER) { |
| 124 |
ADD_SIZER_FLAG(wxRESERVE_SPACE_EVEN_IF_HIDDEN, true); |
| 125 |
|
| 126 |
} else { |
| 127 |
ADD_SIZER_FLAG(wxRESERVE_SPACE_EVEN_IF_HIDDEN, false); |
| 128 |
} |
| 129 |
|
| 130 |
AddProperty(new CategoryProperty(_("Common Settings"))); |
| 131 |
AddProperty(new WinIdProperty()); |
| 132 |
AddProperty(new StringProperty(PROP_SIZE, "-1,-1", |
| 133 |
_("The control's size. It is recommended to leave it as -1,-1 and " |
| 134 |
"let\nthe sizers calculate the best size for the window"))); |
| 135 |
AddProperty(new StringProperty(PROP_MINSIZE, "-1,-1", |
| 136 |
_("The control's minimum size, to indicate to the sizer layout " |
| 137 |
"mechanism that this is the minimum required size"))); |
| 138 |
AddProperty(new StringProperty(PROP_NAME, "", _("C++ member name"))); |
| 139 |
AddProperty(new MultiStringsProperty(PROP_TOOLTIP, _("Tooltip"), "\\n", _("Tooltip text:"))); |
| 140 |
AddProperty(new ColorProperty(PROP_BG, "<Default>", _("Set the control's background colour"))); |
| 141 |
AddProperty(new ColorProperty(PROP_FG, "<Default>", _("Set the control's foreground colour"))); |
| 142 |
AddProperty(new FontProperty(PROP_FONT, "", _("Set the control's font"))); |
| 143 |
|
| 144 |
AddProperty(new CategoryProperty(_("Initial State"))); |
| 145 |
AddProperty(new BoolProperty(PROP_STATE_HIDDEN, false, _("Sets the control initial state to 'Hidden'"))); |
| 146 |
AddProperty(new BoolProperty(PROP_STATE_DISABLED, false, _("Sets the control initial state to 'Disabled'"))); |
| 147 |
AddProperty(new BoolProperty(PROP_HAS_FOCUS, false, _("This control should have keyboard focus"))); |
| 148 |
|
| 149 |
AddProperty(new CategoryProperty(_("Subclass"))); |
| 150 |
AddProperty(new StringProperty(PROP_SUBCLASS_NAME, "", |
| 151 |
_("The name of the derived class. Used both for C++ and XRC generated code."))); |
| 152 |
AddProperty( |
| 153 |
new StringProperty(PROP_SUBCLASS_INCLUDE, "", |
| 154 |
_("(C++ only) The name of any extra header file to be #included e.g. mydialog.hpp"))); |
| 155 |
AddText(PROP_SUBCLASS_STYLE, |
| 156 |
_("Override the default class style with the content of this field.\nThe style should be | separated")); |
| 157 |
AddProperty(new CategoryProperty(_("Control Specific Settings"))); |
| 158 |
} |
| 159 |
|
| 160 |
wxcWidget::~wxcWidget() |
| 161 |
{ |
| 162 |
if(GetParent()) { |
| 163 |
GetParent()->RemoveChild(this); |
| 164 |
} |
| 165 |
DeleteAllChildren(); |
| 166 |
wxDELETE(m_eventsMenu); |
| 167 |
m_properties.DeleteValues(); |
| 168 |
m_controlEvents.Clear(); |
| 169 |
} |
| 170 |
|
| 171 |
void wxcWidget::DeleteAllChildren() |
| 172 |
{ |
| 173 |
// deleting a child will also remove it from the parent's m_children |
| 174 |
// this is why we use a temporary list here |
| 175 |
List_t tmpChildren; |
| 176 |
tmpChildren.insert(tmpChildren.end(), m_children.begin(), m_children.end()); |
| 177 |
wxcWidget::List_t::iterator iter = tmpChildren.begin(); |
| 178 |
for(; iter != tmpChildren.end(); ++iter) { |
| 179 |
delete(*iter); |
| 180 |
} |
| 181 |
m_children.clear(); |
| 182 |
} |
| 183 |
|
| 184 |
wxString wxcWidget::GetWindowParent() const |
| 185 |
{ |
| 186 |
wxString parentName = "NULL"; |
| 187 |
const NotebookPageWrapper* nbPage = dynamic_cast<const NotebookPageWrapper*>(this); |
| 188 |
|
| 189 |
wxcWidget* pParent = m_parent; |
| 190 |
if(nbPage && nbPage->GetNotebook()) { |
| 191 |
return nbPage->GetNotebook()->GetName(); |
| 192 |
|
| 193 |
} else { |
| 194 |
while(pParent) { |
| 195 |
|
| 196 |
if(pParent->IsValidParent()) { |
| 197 |
if(pParent->IsTopWindow()) { |
| 198 |
parentName = "this"; |
| 199 |
|
| 200 |
} else { |
| 201 |
parentName = pParent->GetName(); |
| 202 |
} |
| 203 |
break; |
| 204 |
|
| 205 |
} else { |
| 206 |
pParent = pParent->GetParent(); |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
if(pParent && pParent->GetType() == ID_WXCOLLAPSIBLEPANE_PANE) { |
| 212 |
const wxCollapsiblePanePaneWrapper* paneWin = dynamic_cast<const wxCollapsiblePanePaneWrapper*>(pParent); |
| 213 |
if(paneWin && paneWin->GetParent()) { |
| 214 |
parentName.Clear(); |
| 215 |
parentName << paneWin->GetParent()->GetName() << "->GetPane()"; |
| 216 |
return parentName; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
return parentName; |
| 221 |
} |
| 222 |
|
| 223 |
void wxcWidget::ChildrenXRC(wxString& text, XRC_TYPE type) const |
| 224 |
{ |
| 225 |
wxcWidget::List_t::const_iterator iter = m_children.begin(); |
| 226 |
for(; iter != m_children.end(); iter++) { |
| 227 |
wxString xrc; |
| 228 |
(*iter)->ToXRC(xrc, type); |
| 229 |
|
| 230 |
if((*iter)->IsAuiPane()) { |
| 231 |
xrc = (*iter)->WrapInAuiPaneXRC(xrc); |
| 232 |
|
| 233 |
} else if((*iter)->IsSizerItem()) { |
| 234 |
xrc = (*iter)->WrapInSizerXRC(xrc); |
| 235 |
} |
| 236 |
text << xrc; |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
wxString wxcWidget::SizerFlags(const wxString& defaultFlags) const |
| 241 |
{ |
| 242 |
wxString s; |
| 243 |
MapStyles_t::ConstIterator iter = m_sizerFlags.Begin(); |
| 244 |
for(; iter != m_sizerFlags.End(); iter++) { |
| 245 |
if(iter->second.is_set) { |
| 246 |
s << iter->second.style_name << "|"; |
| 247 |
} |
| 248 |
} |
| 249 |
// For aesthetic reasons, remove the individual border flags if wxALL is present |
| 250 |
// First check it's there if it should be (it won't always be in legacy files) |
| 251 |
if(s.Contains("wxLEFT") && s.Contains("wxRIGHT") && s.Contains("wxTOP") && s.Contains("wxBOTTOM") && |
| 252 |
!s.Contains("wxALL")) { |
| 253 |
s << "wxALL|"; |
| 254 |
} |
| 255 |
if(s.Contains("wxALL")) { |
| 256 |
s.Replace("wxLEFT", ""); |
| 257 |
s.Replace("wxRIGHT", ""); |
| 258 |
s.Replace("wxTOP", ""); |
| 259 |
s.Replace("wxBOTTOM", ""); |
| 260 |
} |
| 261 |
// Cope with multiple or trailing separators |
| 262 |
s = wxCrafter::Join(wxCrafter::Split(s, "|"), "|"); |
| 263 |
|
| 264 |
s.Trim().Trim(false); |
| 265 |
if(s.IsEmpty()) { |
| 266 |
s = defaultFlags; |
| 267 |
} |
| 268 |
return s; |
| 269 |
} |
| 270 |
|
| 271 |
wxString wxcWidget::WrapInSizerXRC(const wxString& objXRC) const |
| 272 |
{ |
| 273 |
bool isGBSizerItem = IsGridBagSizerItem(); |
| 274 |
bool isSizer = (GetWidgetType() == TYPE_SIZER); |
| 275 |
bool isSpacer = (GetType() == ID_WXSPACER); |
| 276 |
|
| 277 |
// Minimum size is an object property, but XRC plonks it in sizeritem :/ |
| 278 |
wxString minsize; |
| 279 |
wxSize minSize = wxCrafter::DecodeSize(PropertyString(PROP_MINSIZE)); |
| 280 |
if(minSize != wxDefaultSize) { |
| 281 |
minsize = "<minsize>" + wxCrafter::EncodeSize(minSize) + "</minsize>"; |
| 282 |
} |
| 283 |
|
| 284 |
// There's a backdoor way if IDing sizers/spacers: putting their 'name' in the sizeritem |
| 285 |
// See http://trac.wxwidgets.org/changeset/48718 and wxSizerItem::GetId and wxSizer::GetItemById |
| 286 |
wxString name; |
| 287 |
if((isSizer || isSpacer) && !GetName().empty()) { |
| 288 |
name << " name=\"" << wxCrafter::XMLEncode(GetName()) << "\""; |
| 289 |
} |
| 290 |
|
| 291 |
wxString strXRC; |
| 292 |
if(!isSpacer) { |
| 293 |
strXRC << "<object class=\"sizeritem\"" << name << " >"; |
| 294 |
|
| 295 |
} else { |
| 296 |
strXRC << "<object class=\"spacer\"" << name << " >"; |
| 297 |
|
| 298 |
if(GetSize() != wxSize(0, 0)) { |
| 299 |
strXRC << XRCSize(); |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
strXRC << " <flag>" << SizerFlags("") << "</flag>"; |
| 304 |
|
| 305 |
// Don't pointlessly output <border>0</border> |
| 306 |
if(m_sizerItem.GetBorder() > 0) { |
| 307 |
strXRC << " <border>" << m_sizerItem.GetBorder() << "</border>"; |
| 308 |
} |
| 309 |
|
| 310 |
strXRC << minsize; |
| 311 |
if(m_sizerItem.GetProportion() > 0) { |
| 312 |
strXRC << " <option>" << m_sizerItem.GetProportion() << "</option>"; |
| 313 |
} |
| 314 |
|
| 315 |
if(isGBSizerItem) { |
| 316 |
strXRC << "<cellpos>" << m_gbPos << "</cellpos>"; |
| 317 |
strXRC << "<cellspan>" << m_gbSpan << "</cellspan>"; |
| 318 |
} |
| 319 |
|
| 320 |
if(!isSpacer) { |
| 321 |
strXRC << objXRC; |
| 322 |
} |
| 323 |
|
| 324 |
strXRC << "</object>"; |
| 325 |
return strXRC; |
| 326 |
} |
| 327 |
|
| 328 |
bool wxcWidget::HasMainSizer() const |
| 329 |
{ |
| 330 |
if(IsSizer()) { |
| 331 |
return false; |
| 332 |
} |
| 333 |
|
| 334 |
wxcWidget::List_t::const_iterator iter = m_children.begin(); |
| 335 |
for(; iter != m_children.end(); iter++) { |
| 336 |
if((*iter)->IsSizer()) { |
| 337 |
return true; |
| 338 |
} |
| 339 |
} |
| 340 |
return false; |
| 341 |
} |
| 342 |
|
| 343 |
void wxcWidget::DoClearFlags(MapStyles_t& mp) |
| 344 |
{ |
| 345 |
MapStyles_t::Iterator iter = mp.Begin(); |
| 346 |
for(; iter != mp.End(); iter++) { |
| 347 |
iter->second.is_set = false; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
void wxcWidget::AddProperty(PropertyBase* prop) |
| 352 |
{ |
| 353 |
if(prop) { |
| 354 |
m_properties.PushBack(prop->GetLabel(), prop); |
| 355 |
|
| 356 |
} else { |
| 357 |
m_properties.PushBack("", NULL); |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
wxString wxcWidget::StyleFlags(const wxString& deafultStyle) const |
| 362 |
{ |
| 363 |
wxString s; |
| 364 |
|
| 365 |
wxString subclassStyle = PropertyString(PROP_SUBCLASS_STYLE); |
| 366 |
if(!subclassStyle.IsEmpty()) { |
| 367 |
return subclassStyle; |
| 368 |
|
| 369 |
} else { |
| 370 |
for(auto style : m_styles) { |
| 371 |
wxString style_name = style.second.style_name; |
| 372 |
if(style.second.is_set) { |
| 373 |
if(style_name == "wxBORDER_SIMPLE") { |
| 374 |
s << "get_border_simple_theme_aware_bit()|"; |
| 375 |
} else { |
| 376 |
s << style_name << "|"; |
| 377 |
} |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
if(s.EndsWith("|")) { |
| 382 |
s.RemoveLast(); |
| 383 |
} |
| 384 |
|
| 385 |
if(s.IsEmpty()) { |
| 386 |
s = deafultStyle; |
| 387 |
} |
| 388 |
|
| 389 |
return s; |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
void wxcWidget::DoAddSizerFlag(const wxString& name, WxStyleInfo info) |
| 394 |
{ |
| 395 |
if(!m_sizerFlags.Contains(name)) { |
| 396 |
m_sizerFlags.PushBack(name, info); |
| 397 |
} else { |
| 398 |
m_sizerFlags.Item(name) = info; |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
bool wxcWidget::IsSizerItem() const { return GetParent() && GetParent()->IsSizer(); } |
| 403 |
|
| 404 |
bool wxcWidget::IsGridBagSizerItem() const { return GetParent() && GetParent()->GetType() == ID_WXGRIDBAGSIZER; } |
| 405 |
|
| 406 |
wxString wxcWidget::PropertyBool(const wxString& propname) const |
| 407 |
{ |
| 408 |
if(m_properties.Contains(propname)) { |
| 409 |
wxString value = m_properties.Item(propname)->GetValue(); |
| 410 |
|
| 411 |
if(value == "1") { |
| 412 |
return "true"; |
| 413 |
|
| 414 |
} else { |
| 415 |
return "false"; |
| 416 |
} |
| 417 |
|
| 418 |
} else { |
| 419 |
return "false"; |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
wxString wxcWidget::PropertyFile(const wxString& propname) const |
| 424 |
{ |
| 425 |
if(m_properties.Contains(propname)) { |
| 426 |
wxString value = m_properties.Item(propname)->GetValue(); |
| 427 |
|
| 428 |
// FIXME:: Expand codelite's macros here |
| 429 |
value.Replace("\\", "/"); |
| 430 |
value = wxCrafter::XMLEncode(value); |
| 431 |
return value; |
| 432 |
|
| 433 |
} else { |
| 434 |
return ""; |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
wxString wxcWidget::PropertyString(const wxString& propname, const wxString& defaultValue) const |
| 439 |
{ |
| 440 |
if(m_properties.Contains(propname)) { |
| 441 |
wxString v = m_properties.Item(propname)->GetValue(); |
| 442 |
v.Trim(); |
| 443 |
if(v.IsEmpty()) { |
| 444 |
return defaultValue; |
| 445 |
} |
| 446 |
return v; |
| 447 |
|
| 448 |
} else { |
| 449 |
return defaultValue; |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
void wxcWidget::DoSetPropertyStringValue(const wxString& propname, const wxString& value) |
| 454 |
{ |
| 455 |
if(m_properties.Contains(propname)) { |
| 456 |
// Delete the old one and replace it with a new property |
| 457 |
m_properties.Item(propname)->SetValue(value); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
void wxcWidget::DoTraverseAndGenCode(wxArrayString& headers, wxString& ctorCode, wxString& members, |
| 462 |
wxString& eventFunctions, wxString& eventConnectCode, |
| 463 |
wxStringMap_t& additionalFiles, wxString& dtorCode, wxString& extraFunctionsImpl, |
| 464 |
wxString& extraFunctionsDecl) const |
| 465 |
{ |
| 466 |
// Start by checking if this control is subclassed; if so, use its data, not the superclass's |
| 467 |
wxString subclass = PropertyString(PROP_SUBCLASS_NAME); |
| 468 |
wxString subinclude = PropertyString(PROP_SUBCLASS_INCLUDE); |
| 469 |
|
| 470 |
GetIncludeFile(headers); |
| 471 |
if(!subinclude.empty()) { |
| 472 |
// 'subinclude' will probably be just "myfoo.hpp", but check: |
| 473 |
if(!subinclude.Contains("#include")) { |
| 474 |
subinclude = "#include \"" + subinclude + "\""; |
| 475 |
} |
| 476 |
headers.Add(subinclude); |
| 477 |
} |
| 478 |
|
| 479 |
// Additional files generated by the controls (if any) |
| 480 |
GenerateAdditionalFiles(additionalFiles); |
| 481 |
|
| 482 |
// ctor |
| 483 |
ctorCode << DoGenerateCppCtorCode() << "\n"; |
| 484 |
|
| 485 |
// dtor |
| 486 |
wxString dtor = DoGenerateCppDtorCode(); |
| 487 |
if(dtor.IsEmpty() == false) { |
| 488 |
dtorCode << dtor << "\n"; |
| 489 |
} |
| 490 |
|
| 491 |
wxArrayString existsFunctionsArr = wxCrafter::Split(eventFunctions, "\r\n"); |
| 492 |
wxArrayString newEventFuncArr = wxCrafter::Split(DoGenerateEventStubs(), "\r\n"); |
| 493 |
|
| 494 |
// Append the array |
| 495 |
existsFunctionsArr.insert(existsFunctionsArr.end(), newEventFuncArr.begin(), newEventFuncArr.end()); |
| 496 |
|
| 497 |
// Remove duplicate entries |
| 498 |
existsFunctionsArr = wxCrafter::MakeUnique(existsFunctionsArr); |
| 499 |
|
| 500 |
// And finally convert the wxArrayString to wxString |
| 501 |
eventFunctions.Clear(); |
| 502 |
eventFunctions << wxCrafter::Join(existsFunctionsArr, "\n"); |
| 503 |
|
| 504 |
eventConnectCode << DoGenerateConnectCode(); |
| 505 |
|
| 506 |
wxString memberCode = DoGenerateClassMember(); |
| 507 |
if(memberCode.IsEmpty() == false) { |
| 508 |
members << memberCode << "\n"; |
| 509 |
} |
| 510 |
|
| 511 |
List_t::const_iterator iter = m_children.begin(); |
| 512 |
for(; iter != m_children.end(); iter++) { |
| 513 |
(*iter)->DoTraverseAndGenCode(headers, ctorCode, members, eventFunctions, eventConnectCode, additionalFiles, |
| 514 |
dtorCode, extraFunctionsImpl, extraFunctionsDecl); |
| 515 |
if((*iter)->IsSizerItem()) { |
| 516 |
wxSize minSize = wxCrafter::DecodeSize((*iter)->PropertyString(PROP_MINSIZE)); |
| 517 |
if(minSize != wxDefaultSize) { |
| 518 |
if(ctorCode.Right(2) == "\n\n") { |
| 519 |
ctorCode.RemoveLast(); // Otherwise the SetMinSize() feels lonely |
| 520 |
} |
| 521 |
ctorCode << (*iter)->GetName() << "->SetMinSize(wxSize(" << wxCrafter::EncodeSize(minSize) << "));\n\n"; |
| 522 |
; |
| 523 |
} |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
// Allow the parent item to "close" the ctor (useful when we want to add calls like "p->Realize()" etc) |
| 528 |
wxString cppCtorEndCode = DoGenerateCppCtorCode_End(); |
| 529 |
if(!cppCtorEndCode.IsEmpty()) { |
| 530 |
ctorCode.Trim(); |
| 531 |
ctorCode << "\n" << cppCtorEndCode; |
| 532 |
} |
| 533 |
|
| 534 |
// Add any extra functions. atm the only example is an eventhandler for wxAuiToolBar dropdowns |
| 535 |
wxString extraCodeImpl, extraCodeDecl; |
| 536 |
DoGenerateExtraFunctions(extraCodeDecl, // Implementation |
| 537 |
extraCodeImpl); // Declarations |
| 538 |
if(!extraCodeImpl.IsEmpty()) { |
| 539 |
extraCodeImpl.Trim(); |
| 540 |
extraFunctionsImpl << "\n" << extraCodeImpl; |
| 541 |
extraFunctionsDecl << "\n" << extraCodeDecl; |
| 542 |
} |
| 543 |
|
| 544 |
DoGenerateGetters(extraFunctionsDecl); |
| 545 |
} |
| 546 |
|
| 547 |
wxString wxcWidget::DoGenerateCppDtorCode() const |
| 548 |
{ |
| 549 |
wxString code = CppDtorCode(); |
| 550 |
return code; |
| 551 |
} |
| 552 |
|
| 553 |
wxString wxcWidget::DoGenerateCppCtorCode() const |
| 554 |
{ |
| 555 |
wxString code = CppCtorCode(); |
| 556 |
|
| 557 |
//////////////////////////////////////////////////////////////////////////// |
| 558 |
// Add extra code here (required in some unique cases, like wxToolbar, etc) |
| 559 |
//////////////////////////////////////////////////////////////////////////// |
| 560 |
|
| 561 |
if(GetType() == ID_WXSTDBUTTON) { |
| 562 |
// standard button |
| 563 |
wxString extraCode; |
| 564 |
extraCode << GetParent()->GetName() << "->AddButton(" << GetName() << ");\n"; |
| 565 |
if(IsLastChild()) { |
| 566 |
extraCode << GetParent()->GetName() << "->Realize();\n"; |
| 567 |
} |
| 568 |
code << extraCode; |
| 569 |
|
| 570 |
} else if(GetType() == ID_WXSPACER) { |
| 571 |
// Do nothing |
| 572 |
|
| 573 |
} else if(IsParentToolbar() && !IsToolBarTool()) { |
| 574 |
// Control is being added to the toolbar |
| 575 |
wxString tbCode; |
| 576 |
|
| 577 |
tbCode << GetWindowParent() << "->AddControl(" << GetName() << ");"; |
| 578 |
code << tbCode << "\n"; |
| 579 |
|
| 580 |
if(IsLastChild()) { |
| 581 |
code << GetWindowParent() << "->Realize();\n"; |
| 582 |
} |
| 583 |
|
| 584 |
} else if(IsParentToolbar() && IsToolBarTool()) { |
| 585 |
if(IsLastChild()) { |
| 586 |
code << GetWindowParent() << "->Realize();\n"; |
| 587 |
} |
| 588 |
|
| 589 |
} else if(IsGridBagSizerItem()) { |
| 590 |
|
| 591 |
wxString sizerCode; |
| 592 |
sizerCode << GetParent()->GetName() << "->Add(" << GetName() << ", " |
| 593 |
<< "wxGBPosition(" << m_gbPos << "), " |
| 594 |
<< "wxGBSpan(" << m_gbSpan << "), " << SizerFlags("0") << ", " << m_sizerItem.GetBorderScaled() |
| 595 |
<< ");"; |
| 596 |
code << "\n" << sizerCode << "\n"; |
| 597 |
|
| 598 |
} else if(IsAuiPane()) { |
| 599 |
wxString auiPaneCode; |
| 600 |
auiPaneCode << GetParent()->GetName() << "->AddPane(" << GetName() << ", " << m_auiPaneInfo.ToCppCode() << ");"; |
| 601 |
code << "\n" << auiPaneCode << "\n"; |
| 602 |
|
| 603 |
if(IsLastChild()) { |
| 604 |
code << GetParent()->GetName() << "->Update();\n"; |
| 605 |
} |
| 606 |
|
| 607 |
} else if(IsSizerItem()) { |
| 608 |
wxString sizerCode; |
| 609 |
sizerCode << GetParent()->GetName() << "->Add(" << GetName() << ", " << m_sizerItem.GetProportion() << ", " |
| 610 |
<< SizerFlags("0") << ", " << m_sizerItem.GetBorderScaled() << ");"; |
| 611 |
code << "\n" << sizerCode << "\n"; |
| 612 |
} |
| 613 |
WrapInIfBlockIfNeeded(code); |
| 614 |
return code; |
| 615 |
} |
| 616 |
|
| 617 |
wxString wxcWidget::DoGenerateClassMember() const { return BaseDoGenerateClassMember(); } |
| 618 |
|
| 619 |
bool wxcWidget::IsSizerFlagChecked(const wxString& style) const |
| 620 |
{ |
| 621 |
if(!m_sizerFlags.Contains(style)) { |
| 622 |
return false; |
| 623 |
} |
| 624 |
|
| 625 |
return m_sizerFlags.Item(style).is_set; |
| 626 |
} |
| 627 |
|
| 628 |
void wxcWidget::DoEnableStyle(wxcWidget::MapStyles_t& mp, const wxString& style, bool enable) |
| 629 |
{ |
| 630 |
if(mp.Contains(style)) { |
| 631 |
mp.Item(style).is_set = enable; |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
void wxcWidget::Serialize(JSONElement& json) const |
| 636 |
{ |
| 637 |
json.addProperty("m_type", m_type); |
| 638 |
json.addProperty("proportion", m_sizerItem.GetProportion()); |
| 639 |
json.addProperty("border", m_sizerItem.GetBorder()); |
| 640 |
json.addProperty("gbSpan", m_gbSpan); |
| 641 |
json.addProperty("gbPosition", m_gbPos); |
| 642 |
|
| 643 |
JSONElement styles = JSONElement::createArray("m_styles"); |
| 644 |
MapStyles_t::const_iterator iter = m_styles.begin(); |
| 645 |
for(; iter != m_styles.end(); iter++) { |
| 646 |
if(iter->second.is_set) { |
| 647 |
styles.arrayAppend(iter->second.style_name); |
| 648 |
} |
| 649 |
} |
| 650 |
json.append(styles); |
| 651 |
|
| 652 |
if(IsAuiPane()) { |
| 653 |
json.append(m_auiPaneInfo.ToJSON()); |
| 654 |
} |
| 655 |
|
| 656 |
JSONElement sizerFlags = JSONElement::createArray("m_sizerFlags"); |
| 657 |
iter = m_sizerFlags.begin(); |
| 658 |
for(; iter != m_sizerFlags.end(); iter++) { |
| 659 |
if(iter->second.is_set) { |
| 660 |
sizerFlags.arrayAppend(iter->second.style_name); |
| 661 |
} |
| 662 |
} |
| 663 |
json.append(sizerFlags); |
| 664 |
|
| 665 |
JSONElement properties = JSONElement::createArray("m_properties"); |
| 666 |
MapProperties_t::const_iterator prop_iter = m_properties.begin(); |
| 667 |
for(; prop_iter != m_properties.end(); prop_iter++) { |
| 668 |
if(prop_iter->second) { |
| 669 |
properties.arrayAppend(prop_iter->second->Serialize()); |
| 670 |
} |
| 671 |
} |
| 672 |
json.append(properties); |
| 673 |
|
| 674 |
JSONElement events = JSONElement::createArray("m_events"); |
| 675 |
MapEvents_t::const_iterator events_iter = m_connectedEvents.begin(); |
| 676 |
for(; events_iter != m_connectedEvents.end(); events_iter++) { |
| 677 |
events.arrayAppend(events_iter->second.ToJSON()); |
| 678 |
} |
| 679 |
json.append(events); |
| 680 |
|
| 681 |
JSONElement children = JSONElement::createArray("m_children"); |
| 682 |
List_t::const_iterator child_iter = m_children.begin(); |
| 683 |
for(; child_iter != m_children.end(); child_iter++) { |
| 684 |
JSONElement child = JSONElement::createObject(); |
| 685 |
(*child_iter)->Serialize(child); |
| 686 |
children.arrayAppend(child); |
| 687 |
} |
| 688 |
|
| 689 |
json.append(children); |
| 690 |
} |
| 691 |
|
| 692 |
void wxcWidget::UnSerialize(const JSONElement& json) |
| 693 |
{ |
| 694 |
m_sizerItem.SetBorder(json.namedObject("border").toInt(5)); |
| 695 |
m_sizerItem.SetProportion(json.namedObject("proportion").toInt(0)); |
| 696 |
m_gbSpan = json.namedObject("gbSpan").toString(); |
| 697 |
m_gbPos = json.namedObject("gbPosition").toString(); |
| 698 |
|
| 699 |
m_auiPaneInfo.FromJSON(json.namedObject("wxAuiPaneInfo")); |
| 700 |
|
| 701 |
// Unserialize the styles |
| 702 |
DoClearFlags(m_styles); |
| 703 |
DoClearFlags(m_sizerFlags); |
| 704 |
|
| 705 |
m_connectedEvents.Clear(); |
| 706 |
|
| 707 |
JSONElement styles = json.namedObject("m_styles"); |
| 708 |
int nCount = styles.arraySize(); |
| 709 |
for(int i = 0; i < nCount; i++) { |
| 710 |
wxString styleName = styles.arrayItem(i).toString(); |
| 711 |
EnableStyle(styleName, true); |
| 712 |
} |
| 713 |
|
| 714 |
JSONElement sizerFlags = json.namedObject("m_sizerFlags"); |
| 715 |
nCount = sizerFlags.arraySize(); |
| 716 |
for(int i = 0; i < nCount; i++) { |
| 717 |
wxString styleName = sizerFlags.arrayItem(i).toString(); |
| 718 |
EnableSizerFlag(styleName, true); |
| 719 |
} |
| 720 |
|
| 721 |
// Unserialize the properties |
| 722 |
JSONElement properties = json.namedObject("m_properties"); |
| 723 |
nCount = properties.arraySize(); |
| 724 |
for(int i = 0; i < nCount; i++) { |
| 725 |
JSONElement jsonProp = properties.arrayItem(i); |
| 726 |
wxString propLabel = jsonProp.namedObject("m_label").toString(); |
| 727 |
if(m_properties.Contains(propLabel)) { |
| 728 |
m_properties.Item(propLabel)->UnSerialize(jsonProp); |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
// Unserialize the events |
| 733 |
JSONElement events = json.namedObject("m_events"); |
| 734 |
nCount = events.arraySize(); |
| 735 |
for(int i = 0; i < nCount; i++) { |
| 736 |
JSONElement jsonEvent = events.arrayItem(i); |
| 737 |
ConnectDetails details; |
| 738 |
details.FromJSON(jsonEvent); |
| 739 |
|
| 740 |
// Since wx295, the WebView event names were modified from *_WEB_VIEW_* to *_WEBVIEW_* |
| 741 |
// perfrom the name changes here |
| 742 |
if(details.GetEventName().Contains("_WEB_VIEW_")) { |
| 743 |
wxString new_name = details.GetEventName(); |
| 744 |
new_name.Replace("_WEB_VIEW_", "_WEBVIEW_"); |
| 745 |
details.SetEventName(new_name); |
| 746 |
} |
| 747 |
m_connectedEvents.PushBack(details.GetEventName(), details); |
| 748 |
} |
| 749 |
|
| 750 |
JSONElement children = json.namedObject("m_children"); |
| 751 |
int nChildren = children.arraySize(); |
| 752 |
for(int i = 0; i < nChildren; i++) { |
| 753 |
JSONElement child = children.arrayItem(i); |
| 754 |
wxcWidget* wrapper = Allocator::Instance()->CreateWrapperFromJSON(child); |
| 755 |
if(wrapper) { |
| 756 |
AddChild(wrapper); |
| 757 |
} |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
void wxcWidget::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 762 |
{ |
| 763 |
wxString value; |
| 764 |
|
| 765 |
// Start with 2 possible strings in node itself |
| 766 |
value = XmlUtils::ReadString(node, "name"); |
| 767 |
if(!value.empty()) { |
| 768 |
SetName(value); |
| 769 |
} |
| 770 |
|
| 771 |
wxString subclass = XmlUtils::ReadString(node, "subclass"); |
| 772 |
if(!subclass.empty()) { |
| 773 |
SetPropertyString(PROP_SUBCLASS_NAME, subclass); |
| 774 |
} |
| 775 |
|
| 776 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, "size"); |
| 777 |
if(propertynode) { |
| 778 |
SetPropertyString(PROP_SIZE, propertynode->GetNodeContent()); |
| 779 |
} |
| 780 |
|
| 781 |
/* propertynode = XmlUtils::FindFirstByTagName(node, "pos"); |
| 782 |
if (propertynode) { |
| 783 |
// wxC doesn't do positions |
| 784 |
}*/ |
| 785 |
|
| 786 |
propertynode = XmlUtils::FindFirstByTagName(node, "tooltip"); |
| 787 |
if(propertynode) { |
| 788 |
SetPropertyString(PROP_TOOLTIP, propertynode->GetNodeContent()); |
| 789 |
} |
| 790 |
|
| 791 |
propertynode = XmlUtils::FindFirstByTagName(node, "font"); |
| 792 |
if(propertynode) { |
| 793 |
SetPropertyString(PROP_FONT, wxCrafter::XRCToFontstring(propertynode)); |
| 794 |
} |
| 795 |
|
| 796 |
propertynode = XmlUtils::FindFirstByTagName(node, "fg"); |
| 797 |
if(propertynode) { |
| 798 |
SetPropertyString(PROP_FG, wxCrafter::ValueToColourString(propertynode->GetNodeContent())); |
| 799 |
} |
| 800 |
|
| 801 |
propertynode = XmlUtils::FindFirstByTagName(node, "bg"); |
| 802 |
if(propertynode) { |
| 803 |
SetPropertyString(PROP_BG, wxCrafter::ValueToColourString(propertynode->GetNodeContent())); |
| 804 |
} |
| 805 |
|
| 806 |
propertynode = XmlUtils::FindFirstByTagName(node, "hidden"); |
| 807 |
if(propertynode && propertynode->GetNodeContent() == "1") { |
| 808 |
SetPropertyString(PROP_STATE_HIDDEN, "1"); |
| 809 |
} |
| 810 |
|
| 811 |
propertynode = XmlUtils::FindFirstByTagName(node, "enabled"); |
| 812 |
if(propertynode && propertynode->GetNodeContent() == "0") { |
| 813 |
SetPropertyString(PROP_STATE_DISABLED, "1"); |
| 814 |
} |
| 815 |
|
| 816 |
propertynode = XmlUtils::FindFirstByTagName(node, "focused"); |
| 817 |
if(propertynode && propertynode->GetNodeContent() == "1") { |
| 818 |
SetPropertyString(PROP_HAS_FOCUS, "1"); |
| 819 |
} |
| 820 |
|
| 821 |
// The Label property has a default, so we must clear it even if the node is absent |
| 822 |
PropertyBase* labelprop = GetProperty(PROP_LABEL); |
| 823 |
if(labelprop) { |
| 824 |
wxString labelvalue; |
| 825 |
propertynode = XmlUtils::FindFirstByTagName(node, "label"); |
| 826 |
if(propertynode) { |
| 827 |
labelvalue = propertynode->GetNodeContent(); |
| 828 |
} |
| 829 |
labelprop->SetValue(labelvalue); |
| 830 |
} |
| 831 |
|
| 832 |
propertynode = XmlUtils::FindFirstByTagName(node, "title"); |
| 833 |
if(propertynode) { |
| 834 |
SetTitle(propertynode->GetNodeContent()); |
| 835 |
} |
| 836 |
|
| 837 |
propertynode = XmlUtils::FindFirstByTagName(node, "style"); |
| 838 |
if(propertynode) { |
| 839 |
wxString styles = propertynode->GetNodeContent(); |
| 840 |
styles.Replace("wxRESIZE_BOX", "wxMAXIMIZE_BOX"); // Deprecated (removed?) in wx2.9 but still likely to be seen |
| 841 |
styles.Replace("wxSTATIC_BORDER", "wxBORDER_STATIC"); |
| 842 |
styles.Replace("wxSIMPLE_BORDER", "wxBORDER_SIMPLE"); |
| 843 |
styles.Replace("wxSUNKEN_BORDER", "wxBORDER_SUNKEN"); |
| 844 |
styles.Replace("wxRAISED_BORDER", "wxBORDER_RAISED"); |
| 845 |
styles.Replace("wxNO_BORDER", "wxBORDER_NONE"); |
| 846 |
|
| 847 |
wxArrayString stylearray = wxCrafter::Split(styles, "|"); |
| 848 |
|
| 849 |
DoClearFlags(m_styles); // otherwise the default ones will remain |
| 850 |
for(size_t n = 0; n < stylearray.GetCount(); ++n) { |
| 851 |
DoEnableStyle(m_styles, stylearray.Item(n), true); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
// Now get any events. wxFB's XRC output produces nothing. XRCed just produces: |
| 856 |
// <XRCED> <events>EVT_LEFT_DOWN|EVT_CHAR</events> </XRCED> |
| 857 |
propertynode = XmlUtils::FindFirstByTagName(node, "XRCED"); |
| 858 |
if(propertynode) { |
| 859 |
wxXmlNode* eventsnode = XmlUtils::FindFirstByTagName(propertynode, "events"); |
| 860 |
if(eventsnode) { |
| 861 |
ImportEventsFromXRC(eventsnode->GetNodeContent()); |
| 862 |
} |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
void wxcWidget::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 867 |
{ |
| 868 |
wxString value; |
| 869 |
|
| 870 |
// Start with 2 possible strings in node itself |
| 871 |
value = XmlUtils::ReadString(node, "name"); |
| 872 |
if(!value.empty()) { |
| 873 |
SetName(value); |
| 874 |
} |
| 875 |
|
| 876 |
wxString subclass = XmlUtils::ReadString(node, "subclass"); |
| 877 |
if(!subclass.empty()) { |
| 878 |
SetPropertyString(PROP_SUBCLASS_NAME, subclass); |
| 879 |
} |
| 880 |
|
| 881 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, "size"); |
| 882 |
if(propertynode) { |
| 883 |
SetPropertyString(PROP_SIZE, propertynode->GetNodeContent()); |
| 884 |
} |
| 885 |
|
| 886 |
/* propertynode = XmlUtils::FindFirstByTagName(node, "pos"); |
| 887 |
if (propertynode) { |
| 888 |
// wxC doesn't do positions |
| 889 |
}*/ |
| 890 |
|
| 891 |
propertynode = XmlUtils::FindFirstByTagName(node, "tooltip"); |
| 892 |
if(propertynode) { |
| 893 |
SetPropertyString(PROP_TOOLTIP, wxCrafter::ESCAPE(propertynode->GetNodeContent())); |
| 894 |
} |
| 895 |
|
| 896 |
propertynode = XmlUtils::FindFirstByTagName(node, "font"); |
| 897 |
if(propertynode) { |
| 898 |
SetPropertyString(PROP_FONT, wxCrafter::XRCToFontstring(propertynode)); // wxS behaves like XRC here |
| 899 |
} |
| 900 |
|
| 901 |
propertynode = XmlUtils::FindFirstByTagName(node, "fg"); |
| 902 |
if(propertynode) { |
| 903 |
SetPropertyString(PROP_FG, wxCrafter::ValueToColourString(propertynode->GetNodeContent())); // and here |
| 904 |
} |
| 905 |
|
| 906 |
propertynode = XmlUtils::FindFirstByTagName(node, "bg"); |
| 907 |
if(propertynode) { |
| 908 |
SetPropertyString(PROP_BG, wxCrafter::ValueToColourString(propertynode->GetNodeContent())); |
| 909 |
} |
| 910 |
|
| 911 |
propertynode = XmlUtils::FindFirstByTagName(node, "hidden"); |
| 912 |
if(propertynode && propertynode->GetNodeContent() == "1") { |
| 913 |
SetPropertyString(PROP_STATE_HIDDEN, "1"); |
| 914 |
} |
| 915 |
|
| 916 |
propertynode = XmlUtils::FindFirstByTagName(node, "enabled"); |
| 917 |
if(propertynode && propertynode->GetNodeContent() == "0") { |
| 918 |
SetPropertyString(PROP_STATE_DISABLED, "1"); |
| 919 |
} |
| 920 |
|
| 921 |
propertynode = XmlUtils::FindFirstByTagName(node, "focused"); |
| 922 |
if(propertynode && propertynode->GetNodeContent() == "1") { |
| 923 |
SetPropertyString(PROP_HAS_FOCUS, "1"); |
| 924 |
} |
| 925 |
|
| 926 |
// The Label property has a default, so we must clear it even if the node is absent |
| 927 |
PropertyBase* labelprop = GetProperty(PROP_LABEL); |
| 928 |
if(labelprop) { |
| 929 |
wxString labelvalue; |
| 930 |
propertynode = XmlUtils::FindFirstByTagName(node, "label"); |
| 931 |
if(propertynode) { |
| 932 |
labelvalue = wxCrafter::ESCAPE(propertynode->GetNodeContent()); |
| 933 |
} |
| 934 |
labelprop->SetValue(labelvalue); |
| 935 |
} |
| 936 |
|
| 937 |
propertynode = XmlUtils::FindFirstByTagName(node, "title"); |
| 938 |
if(propertynode) { |
| 939 |
SetTitle(wxCrafter::ESCAPE(propertynode->GetNodeContent())); |
| 940 |
} |
| 941 |
|
| 942 |
propertynode = XmlUtils::FindFirstByTagName(node, "style"); |
| 943 |
if(propertynode) { |
| 944 |
wxString styles = propertynode->GetNodeContent(); |
| 945 |
styles.Replace("wxRESIZE_BOX", "wxMAXIMIZE_BOX"); // Deprecated (removed?) in wx2.9 but still likely to be seen |
| 946 |
styles.Replace("wxSTATIC_BORDER", "wxBORDER_STATIC"); |
| 947 |
styles.Replace("wxSIMPLE_BORDER", "wxBORDER_SIMPLE"); |
| 948 |
styles.Replace("wxSUNKEN_BORDER", "wxBORDER_SUNKEN"); |
| 949 |
styles.Replace("wxRAISED_BORDER", "wxBORDER_RAISED"); |
| 950 |
styles.Replace("wxNO_BORDER", "wxBORDER_NONE"); |
| 951 |
|
| 952 |
wxArrayString stylearray = wxCrafter::Split(styles, "|"); |
| 953 |
|
| 954 |
DoClearFlags(m_styles); // otherwise the default ones will remain |
| 955 |
for(size_t n = 0; n < stylearray.GetCount(); ++n) { |
| 956 |
DoEnableStyle(m_styles, stylearray.Item(n), true); |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
// Now get any events. wxSmith does: |
| 961 |
// <handler function="OnTextCtrl1Text" entry="EVT_TEXT" /> |
| 962 |
// <handler function="OnTextCtrl1TextEnter" entry="EVT_TEXT_ENTER" /> |
| 963 |
// i.e. possible multiple child nodes, so we can't use FindFirstByTagName() |
| 964 |
wxXmlNode* child = node->GetChildren(); |
| 965 |
while(child) { |
| 966 |
if(child->GetName() == "handler") { |
| 967 |
ImportEventFromwxSmith(XmlUtils::ReadString(child, "entry"), XmlUtils::ReadString(child, "function")); |
| 968 |
} |
| 969 |
child = child->GetNext(); |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
void wxcWidget::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 974 |
{ |
| 975 |
wxString value; |
| 976 |
DoClearFlags(m_styles); // otherwise the default ones will remain. NB unlike fromXRC, do it here as we have 2 style |
| 977 |
// attributes below |
| 978 |
|
| 979 |
// Unlike XRC, wxFB stores everything in <property name=foo>value</property> nodes |
| 980 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "name"); |
| 981 |
if(propertynode) { |
| 982 |
value = propertynode->GetNodeContent(); |
| 983 |
if(!value.empty()) { |
| 984 |
SetName(value); |
| 985 |
|
| 986 |
// use the name as the file name by default |
| 987 |
// ERAN: Do not set filename when importing from wxFB |
| 988 |
// if ( IsTopWindow() ) { |
| 989 |
// SetFilename(value); |
| 990 |
// } |
| 991 |
|
| 992 |
// ERAN |
| 993 |
// When importing from wxFB, leave the 'Base Class Suffix' property empty |
| 994 |
if(IsTopWindow()) { |
| 995 |
if(m_properties.Contains(PROP_BASE_CLASS_SUFFIX)) { |
| 996 |
m_properties.Item(PROP_BASE_CLASS_SUFFIX)->SetValue(""); |
| 997 |
} |
| 998 |
} |
| 999 |
} |
| 1000 |
} |
| 1001 |
|
| 1002 |
propertynode = XmlUtils::FindNodeByName(node, "property", "subclass"); |
| 1003 |
if(propertynode) { |
| 1004 |
// Any contents will come as a pair: "classname; headername" |
| 1005 |
wxString props = propertynode->GetNodeContent(); |
| 1006 |
if(!props.empty()) { |
| 1007 |
wxArrayString arr = wxCrafter::Split(props, ";"); |
| 1008 |
wxString classname = arr.Item(0).Trim().Trim(false); |
| 1009 |
if(!classname.empty()) { |
| 1010 |
SetPropertyString(PROP_SUBCLASS_NAME, classname); |
| 1011 |
if(arr.GetCount() > 1) { |
| 1012 |
SetPropertyString(PROP_SUBCLASS_INCLUDE, arr.Item(1).Trim().Trim(false)); |
| 1013 |
} |
| 1014 |
} |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
propertynode = XmlUtils::FindNodeByName(node, "property", "id"); |
| 1019 |
if(propertynode) { |
| 1020 |
SetPropertyString(PROP_WINDOW_ID, propertynode->GetNodeContent()); |
| 1021 |
} |
| 1022 |
|
| 1023 |
propertynode = XmlUtils::FindNodeByName(node, "property", "size"); |
| 1024 |
if(propertynode) { |
| 1025 |
SetPropertyString(PROP_SIZE, propertynode->GetNodeContent()); |
| 1026 |
} |
| 1027 |
|
| 1028 |
propertynode = XmlUtils::FindNodeByName(node, "property", "tooltip"); |
| 1029 |
if(propertynode) { |
| 1030 |
SetPropertyString(PROP_TOOLTIP, wxCrafter::ESCAPE(propertynode->GetNodeContent())); |
| 1031 |
} |
| 1032 |
|
| 1033 |
propertynode = XmlUtils::FindNodeByName(node, "property", "font"); |
| 1034 |
if(propertynode) { |
| 1035 |
wxString fontasstring = wxCrafter::FBToFontstring(propertynode->GetNodeContent()); |
| 1036 |
if(!fontasstring.empty()) { |
| 1037 |
SetPropertyString(PROP_FONT, fontasstring); |
| 1038 |
} |
| 1039 |
} |
| 1040 |
|
| 1041 |
propertynode = XmlUtils::FindNodeByName(node, "property", "fg"); |
| 1042 |
if(propertynode) { |
| 1043 |
wxString value = propertynode->GetNodeContent(); |
| 1044 |
if(!value.empty()) { |
| 1045 |
wxString col = wxCrafter::ValueToColourString(value); |
| 1046 |
if(!col.empty()) { |
| 1047 |
SetPropertyString(PROP_FG, col); |
| 1048 |
} |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
propertynode = XmlUtils::FindNodeByName(node, "property", "bg"); |
| 1053 |
if(propertynode) { |
| 1054 |
wxString value = propertynode->GetNodeContent(); |
| 1055 |
if(!value.empty()) { |
| 1056 |
wxString col = wxCrafter::ValueToColourString(propertynode->GetNodeContent()); |
| 1057 |
if(!col.empty()) { |
| 1058 |
SetPropertyString(PROP_BG, col); |
| 1059 |
} |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
propertynode = XmlUtils::FindNodeByName(node, "property", "hidden"); |
| 1064 |
if(propertynode) { |
| 1065 |
wxString value = propertynode->GetNodeContent(); |
| 1066 |
if(value == "1") { |
| 1067 |
SetPropertyString(PROP_STATE_HIDDEN, "1"); |
| 1068 |
} |
| 1069 |
} |
| 1070 |
|
| 1071 |
propertynode = XmlUtils::FindNodeByName(node, "property", "enabled"); |
| 1072 |
if(propertynode) { |
| 1073 |
wxString value = propertynode->GetNodeContent(); |
| 1074 |
if(value == "0") { |
| 1075 |
SetPropertyString(PROP_STATE_DISABLED, "1"); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
// wxFB doesn't do Focused |
| 1080 |
|
| 1081 |
propertynode = XmlUtils::FindNodeByName(node, "property", "label"); |
| 1082 |
if(propertynode) { |
| 1083 |
SetPropertyString(PROP_LABEL, wxCrafter::ESCAPE(propertynode->GetNodeContent())); |
| 1084 |
} |
| 1085 |
|
| 1086 |
propertynode = XmlUtils::FindNodeByName(node, "property", "title"); |
| 1087 |
if(propertynode) { |
| 1088 |
SetTitle(wxCrafter::ESCAPE(propertynode->GetNodeContent())); |
| 1089 |
} |
| 1090 |
|
| 1091 |
propertynode = XmlUtils::FindNodeByName(node, "property", "minimum_size"); |
| 1092 |
if(propertynode) { |
| 1093 |
SetPropertyString(PROP_MINSIZE, propertynode->GetNodeContent()); |
| 1094 |
} |
| 1095 |
|
| 1096 |
// Special 'two for the price of one' offer :) |
| 1097 |
propertynode = XmlUtils::FindNodeByName(node, "property", "style"); // the derived-class styles |
| 1098 |
if(propertynode) { |
| 1099 |
value = propertynode->GetNodeContent(); |
| 1100 |
} |
| 1101 |
propertynode = XmlUtils::FindNodeByName(node, "property", "window_style"); // the standard ones |
| 1102 |
if(propertynode) { |
| 1103 |
if(!value.empty()) { |
| 1104 |
value << '|'; |
| 1105 |
} |
| 1106 |
value << propertynode->GetNodeContent(); |
| 1107 |
} |
| 1108 |
if(!value.empty()) { |
| 1109 |
value.Replace("wxRESIZE_BOX", "wxMAXIMIZE_BOX"); // Deprecated (removed?) in wx2.9 but still likely to be seen |
| 1110 |
value.Replace("wxSTATIC_BORDER", "wxBORDER_STATIC"); |
| 1111 |
value.Replace("wxSIMPLE_BORDER", "wxBORDER_SIMPLE"); |
| 1112 |
value.Replace("wxSUNKEN_BORDER", "wxBORDER_SUNKEN"); |
| 1113 |
value.Replace("wxRAISED_BORDER", "wxBORDER_RAISED"); |
| 1114 |
value.Replace("wxNO_BORDER", "wxBORDER_NONE"); |
| 1115 |
wxArrayString stylearray = wxCrafter::Split(value, "|"); |
| 1116 |
|
| 1117 |
for(size_t n = 0; n < stylearray.GetCount(); ++n) { |
| 1118 |
DoEnableStyle(m_styles, stylearray.Item(n), true); |
| 1119 |
} |
| 1120 |
} |
| 1121 |
|
| 1122 |
// Now get any events. wxFB lists all the control's events, whether set or not, so we must iterate |
| 1123 |
// <event name="OnChar"></event> |
| 1124 |
// <event name="OnButtonClick">whatever-the-user-typed</event> |
| 1125 |
wxXmlNode* child = node->GetChildren(); |
| 1126 |
while(child) { |
| 1127 |
if(child->GetName() == "event") { |
| 1128 |
wxString value = child->GetNodeContent(); |
| 1129 |
if(!value.empty()) { |
| 1130 |
ImportEventFromFB(XmlUtils::ReadString(child, "name"), value); |
| 1131 |
} |
| 1132 |
} |
| 1133 |
child = child->GetNext(); |
| 1134 |
} |
| 1135 |
} |
| 1136 |
|
| 1137 |
void wxcWidget::ImportEventsFromXRC(const wxString& events) |
| 1138 |
{ |
| 1139 |
// XRCed supplies any events as e.g. "EVT_LEFT_DOWN|EVT_CHAR" |
| 1140 |
wxArrayString arr = wxCrafter::Split(events, "|"); |
| 1141 |
for(size_t n = 0; n < arr.GetCount(); ++n) { |
| 1142 |
wxString eventname = arr.Item(n); |
| 1143 |
wxString eventtype = ImportFromwxFB::GetEventtypeFromHandlerstub( |
| 1144 |
eventname); // The 'FB' isn't a mistake; it's stored there for convenience |
| 1145 |
if(!eventtype.empty()) { |
| 1146 |
EventsDatabase& edb = Allocator::GetCommonEvents(); |
| 1147 |
if(edb.Exists(wxXmlResource::GetXRCID(eventtype))) { |
| 1148 |
ConnectDetails eventDetails = edb.Item(wxXmlResource::GetXRCID(eventtype)); |
| 1149 |
eventDetails.SetFunctionNameAndSignature(eventDetails.GetEventClass() + "Handler"); |
| 1150 |
AddEvent(eventDetails); |
| 1151 |
} else { |
| 1152 |
EventsDatabase& edb = GetControlEvents(); |
| 1153 |
if(edb.Exists(wxXmlResource::GetXRCID(eventtype))) { |
| 1154 |
ConnectDetails eventDetails = edb.Item(wxXmlResource::GetXRCID(eventtype)); |
| 1155 |
eventDetails.SetFunctionNameAndSignature(eventDetails.GetEventClass() + "Handler"); |
| 1156 |
AddEvent(eventDetails); |
| 1157 |
} |
| 1158 |
} |
| 1159 |
} |
| 1160 |
} |
| 1161 |
} |
| 1162 |
|
| 1163 |
void wxcWidget::ImportEventFromwxSmith(const wxString& eventname, const wxString& handlerstub) |
| 1164 |
{ |
| 1165 |
if(!eventname.empty()) { |
| 1166 |
wxString eventtype = ImportFromwxFB::GetEventtypeFromHandlerstub(eventname); |
| 1167 |
EventsDatabase& edb = Allocator::GetCommonEvents(); |
| 1168 |
if(edb.Exists(wxXmlResource::GetXRCID(eventtype))) { |
| 1169 |
ConnectDetails eventDetails = edb.Item(wxXmlResource::GetXRCID(eventtype)); |
| 1170 |
eventDetails.SetFunctionNameAndSignature(handlerstub); |
| 1171 |
AddEvent(eventDetails); |
| 1172 |
} else { |
| 1173 |
EventsDatabase& edb = GetControlEvents(); |
| 1174 |
if(edb.Exists(wxXmlResource::GetXRCID(eventtype))) { |
| 1175 |
ConnectDetails eventDetails = edb.Item(wxXmlResource::GetXRCID(eventtype)); |
| 1176 |
eventDetails.SetFunctionNameAndSignature(handlerstub); |
| 1177 |
AddEvent(eventDetails); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
void wxcWidget::ImportEventFromFB(const wxString& eventname, const wxString& handlerstub) |
| 1184 |
{ |
| 1185 |
if(!eventname.empty()) { |
| 1186 |
wxString eventtype = ImportFromwxFB::GetEventtypeFromHandlerstub(eventname); |
| 1187 |
EventsDatabase& edb = Allocator::GetCommonEvents(); |
| 1188 |
if(edb.Exists(wxXmlResource::GetXRCID(eventtype))) { |
| 1189 |
ConnectDetails eventDetails = edb.Item(wxXmlResource::GetXRCID(eventtype)); |
| 1190 |
eventDetails.SetFunctionNameAndSignature(handlerstub); |
| 1191 |
AddEvent(eventDetails); |
| 1192 |
} else { |
| 1193 |
EventsDatabase& edb = GetControlEvents(); |
| 1194 |
if(edb.Exists(wxXmlResource::GetXRCID(eventtype))) { |
| 1195 |
ConnectDetails eventDetails = edb.Item(wxXmlResource::GetXRCID(eventtype)); |
| 1196 |
eventDetails.SetFunctionNameAndSignature(handlerstub); |
| 1197 |
AddEvent(eventDetails); |
| 1198 |
} |
| 1199 |
} |
| 1200 |
} |
| 1201 |
} |
| 1202 |
|
| 1203 |
void wxcWidget::RemoveChild(wxcWidget* child) |
| 1204 |
{ |
| 1205 |
List_t::iterator iter = m_children.begin(); |
| 1206 |
for(; iter != m_children.end(); iter++) { |
| 1207 |
if((*iter) == child) { |
| 1208 |
m_children.erase(iter); |
| 1209 |
break; |
| 1210 |
} |
| 1211 |
} |
| 1212 |
} |
| 1213 |
|
| 1214 |
void wxcWidget::RemoveFromParent() |
| 1215 |
{ |
| 1216 |
if(m_parent) { |
| 1217 |
m_parent->RemoveChild(this); |
| 1218 |
} |
| 1219 |
m_parent = NULL; |
| 1220 |
} |
| 1221 |
|
| 1222 |
void wxcWidget::MoveDown() |
| 1223 |
{ |
| 1224 |
if(!m_parent) { |
| 1225 |
return; |
| 1226 |
} |
| 1227 |
|
| 1228 |
// Locate our pointer in the parent children list |
| 1229 |
List_t& list = m_parent->m_children; |
| 1230 |
List_t::iterator iter = list.begin(); |
| 1231 |
for(; iter != list.end(); iter++) { |
| 1232 |
if((*iter) == this) { |
| 1233 |
break; |
| 1234 |
} |
| 1235 |
} |
| 1236 |
|
| 1237 |
// Now move your element two positions forward |
| 1238 |
int i = 0; |
| 1239 |
List_t::iterator new_position = iter; |
| 1240 |
for(; (new_position != list.end() && i < 2); new_position++) { |
| 1241 |
i++; |
| 1242 |
} |
| 1243 |
|
| 1244 |
list.insert(new_position, this); |
| 1245 |
list.erase(iter); |
| 1246 |
} |
| 1247 |
|
| 1248 |
void wxcWidget::MoveUp() |
| 1249 |
{ |
| 1250 |
if(!m_parent) { |
| 1251 |
return; |
| 1252 |
} |
| 1253 |
|
| 1254 |
// Locate our pointer in the parent children list |
| 1255 |
List_t& list = m_parent->m_children; |
| 1256 |
List_t::iterator iter = list.begin(); |
| 1257 |
for(; iter != list.end(); iter++) { |
| 1258 |
if((*iter) == this) { |
| 1259 |
break; |
| 1260 |
} |
| 1261 |
} |
| 1262 |
|
| 1263 |
// Now move your element two positions back (let's assume you have the elements in |
| 1264 |
// the list to-do that amount of movement, but nevertheless, |
| 1265 |
// we still check the list bounds and exit the loop if we hit the front of the list) |
| 1266 |
int i = 0; |
| 1267 |
List_t::iterator new_position = iter; |
| 1268 |
for(; (new_position != list.begin() && i < 1); new_position--) { |
| 1269 |
i++; |
| 1270 |
} |
| 1271 |
|
| 1272 |
list.insert(new_position, this); |
| 1273 |
list.erase(iter); |
| 1274 |
} |
| 1275 |
|
| 1276 |
void wxcWidget::CopySizerAndAuiInfo(const wxcWidget* source, wxcWidget* target) |
| 1277 |
{ |
| 1278 |
MapStyles_t::const_iterator sizerIter = source->m_sizerFlags.begin(); |
| 1279 |
for(; sizerIter != source->m_sizerFlags.end(); ++sizerIter) { |
| 1280 |
if(target->m_sizerFlags.Contains(sizerIter->first)) { |
| 1281 |
target->m_sizerFlags.Item(sizerIter->first) = sizerIter->second; |
| 1282 |
} |
| 1283 |
} |
| 1284 |
target->m_auiPaneInfo = source->m_auiPaneInfo; |
| 1285 |
target->m_sizerItem.SetProportion(source->m_sizerItem.GetProportion()); |
| 1286 |
target->m_sizerItem.SetBorder(source->m_sizerItem.GetBorder()); |
| 1287 |
target->m_gbPos = source->m_gbPos; |
| 1288 |
target->m_gbSpan = source->m_gbSpan; |
| 1289 |
} |
| 1290 |
|
| 1291 |
void wxcWidget::ReplaceWidget(wxcWidget* oldWidget, wxcWidget* newWidget) |
| 1292 |
{ |
| 1293 |
List_t tmp_children = oldWidget->m_children; // Naive copy |
| 1294 |
|
| 1295 |
// Use a tmp_children because 'Reparent' will cause the m_children |
| 1296 |
// size to change so its not reliable to count on it |
| 1297 |
List_t::iterator iter = tmp_children.begin(); |
| 1298 |
for(; iter != tmp_children.end(); ++iter) { |
| 1299 |
(*iter)->Reparent(newWidget); |
| 1300 |
} |
| 1301 |
|
| 1302 |
// at this point oldWidget->m_children should be empty |
| 1303 |
// Now whats left to be done is: |
| 1304 |
// - disconnect oldWidget from its parent |
| 1305 |
// - connect newWidget to the parent in the same position where oldWidget was |
| 1306 |
if(oldWidget->GetParent()) { |
| 1307 |
oldWidget->GetParent()->InsertBefore(newWidget, oldWidget); |
| 1308 |
oldWidget->GetParent()->RemoveChild(oldWidget); |
| 1309 |
} |
| 1310 |
|
| 1311 |
// ------------------------------------------ |
| 1312 |
// Copy the item's sizer flags |
| 1313 |
// ------------------------------------------ |
| 1314 |
CopySizerAndAuiInfo(oldWidget, newWidget); |
| 1315 |
} |
| 1316 |
|
| 1317 |
void wxcWidget::InsertWidgetInto(wxcWidget* oldWidget, wxcWidget* newWidget) // Used for Insert into new Sizer |
| 1318 |
{ |
| 1319 |
wxcWidget* parent = oldWidget->GetParent(); |
| 1320 |
wxCHECK_RET(parent, "An orphaned widget"); |
| 1321 |
|
| 1322 |
parent->InsertBefore(newWidget, oldWidget); |
| 1323 |
oldWidget->Reparent(newWidget); |
| 1324 |
|
| 1325 |
// ------------------------------------------ |
| 1326 |
// Copy the item's sizer flags |
| 1327 |
// ------------------------------------------ |
| 1328 |
CopySizerAndAuiInfo(oldWidget, newWidget); |
| 1329 |
} |
| 1330 |
|
| 1331 |
bool wxcWidget::CanMoveDown() const |
| 1332 |
{ |
| 1333 |
if(!m_parent) { |
| 1334 |
return false; |
| 1335 |
} |
| 1336 |
|
| 1337 |
// Locate our pointer in the parent children list |
| 1338 |
List_t& list = m_parent->m_children; |
| 1339 |
List_t::iterator iter = list.begin(); |
| 1340 |
for(; iter != list.end(); iter++) { |
| 1341 |
if((*iter) == this) { |
| 1342 |
break; |
| 1343 |
} |
| 1344 |
} |
| 1345 |
|
| 1346 |
if(iter == list.end()) { |
| 1347 |
return false; |
| 1348 |
} |
| 1349 |
|
| 1350 |
// Return true of this iterator is not the last one |
| 1351 |
return (++iter) != list.end(); |
| 1352 |
} |
| 1353 |
|
| 1354 |
bool wxcWidget::CanMoveUp() const |
| 1355 |
{ |
| 1356 |
if(!m_parent) { |
| 1357 |
return false; |
| 1358 |
} |
| 1359 |
|
| 1360 |
// Locate our pointer in the parent children list |
| 1361 |
List_t& list = m_parent->m_children; |
| 1362 |
List_t::iterator iter = list.begin(); |
| 1363 |
for(; iter != list.end(); iter++) { |
| 1364 |
if((*iter) == this) { |
| 1365 |
break; |
| 1366 |
} |
| 1367 |
} |
| 1368 |
|
| 1369 |
if(iter == list.end()) { |
| 1370 |
return false; |
| 1371 |
} |
| 1372 |
|
| 1373 |
return (*iter) != *(list.begin()); |
| 1374 |
} |
| 1375 |
|
| 1376 |
wxcWidget* |
| 1377 |
wxcWidget::GetAdjacentSiblingSizer(bool* isAbove /*=NULL*/) const // Return an adjacent sibling that's a sizer, or NULL |
| 1378 |
{ |
| 1379 |
wxcWidget* adjacent = GetAdjacentSibling(true); |
| 1380 |
if(adjacent && adjacent->IsSizer()) { |
| 1381 |
if(isAbove) { |
| 1382 |
*isAbove = true; |
| 1383 |
} |
| 1384 |
return adjacent; |
| 1385 |
} |
| 1386 |
adjacent = GetAdjacentSibling(false); |
| 1387 |
if(adjacent && adjacent->IsSizer()) { |
| 1388 |
if(isAbove) { |
| 1389 |
*isAbove = false; |
| 1390 |
} |
| 1391 |
return adjacent; |
| 1392 |
} |
| 1393 |
return NULL; |
| 1394 |
} |
| 1395 |
|
| 1396 |
wxcWidget* |
| 1397 |
wxcWidget::GetAdjacentSibling(bool previous) const // i.e. the previous (or next) control with the same parent |
| 1398 |
{ |
| 1399 |
if(!m_parent) { |
| 1400 |
return NULL; |
| 1401 |
} |
| 1402 |
|
| 1403 |
// Locate our pointer in the parent children list |
| 1404 |
List_t& list = m_parent->m_children; |
| 1405 |
List_t::iterator iter = list.begin(); |
| 1406 |
for(; iter != list.end(); ++iter) { |
| 1407 |
if((*iter) == this) { |
| 1408 |
break; |
| 1409 |
} |
| 1410 |
} |
| 1411 |
|
| 1412 |
if(iter == list.end()) { |
| 1413 |
return NULL; |
| 1414 |
} |
| 1415 |
|
| 1416 |
if(previous) { |
| 1417 |
if(iter == list.begin()) { |
| 1418 |
return NULL; |
| 1419 |
} |
| 1420 |
--iter; |
| 1421 |
} else { |
| 1422 |
if(++iter == list.end()) { |
| 1423 |
return NULL; |
| 1424 |
} |
| 1425 |
} |
| 1426 |
|
| 1427 |
return *iter; |
| 1428 |
} |
| 1429 |
|
| 1430 |
wxString wxcWidget::SizeAsString() const |
| 1431 |
{ |
| 1432 |
wxString parentStr = GetWindowParent(); |
| 1433 |
wxString size = PropertyString(PROP_SIZE); |
| 1434 |
size.Trim().Trim(false); |
| 1435 |
|
| 1436 |
if(size.IsEmpty()) { |
| 1437 |
size = "-1, -1"; |
| 1438 |
} |
| 1439 |
size.Prepend("wxSize(").Append(")"); |
| 1440 |
if(!parentStr.IsEmpty() && (parentStr != "NULL")) { |
| 1441 |
wxString dlgUnits; |
| 1442 |
dlgUnits << "wxDLG_UNIT(" << parentStr << ", " << size << ")"; |
| 1443 |
size.swap(dlgUnits); |
| 1444 |
} |
| 1445 |
return size; |
| 1446 |
} |
| 1447 |
|
| 1448 |
wxString wxcWidget::ValueAsString() const |
| 1449 |
{ |
| 1450 |
wxString value = PropertyString(PROP_VALUE); |
| 1451 |
value.Prepend("wxT(\"").Append("\")"); |
| 1452 |
return value; |
| 1453 |
} |
| 1454 |
|
| 1455 |
wxString wxcWidget::WindowID() const { return GetId(); } |
| 1456 |
|
| 1457 |
wxString wxcWidget::CPPLabel() const { return wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)); } |
| 1458 |
|
| 1459 |
wxString wxcWidget::Label() const |
| 1460 |
{ |
| 1461 |
wxString label = PropertyString(PROP_LABEL); |
| 1462 |
label.Replace("&", "&"); |
| 1463 |
return wxCrafter::UNDERSCORE(label); |
| 1464 |
} |
| 1465 |
|
| 1466 |
wxString wxcWidget::Size() const |
| 1467 |
{ |
| 1468 |
wxString size = PropertyString(PROP_SIZE); |
| 1469 |
size.Trim().Trim(false); |
| 1470 |
|
| 1471 |
if(size.IsEmpty()) { |
| 1472 |
size = "-1, -1"; |
| 1473 |
} |
| 1474 |
return size; |
| 1475 |
} |
| 1476 |
|
| 1477 |
void wxcWidget::AddEvent(const ConnectDetails& eventDetails) |
| 1478 |
{ |
| 1479 |
if(m_connectedEvents.Contains(eventDetails.GetEventName())) { |
| 1480 |
// Replace it |
| 1481 |
m_connectedEvents.Item(eventDetails.GetEventName()) = eventDetails; |
| 1482 |
|
| 1483 |
} else { |
| 1484 |
// Add it |
| 1485 |
m_connectedEvents.PushBack(eventDetails.GetEventName(), eventDetails); |
| 1486 |
} |
| 1487 |
} |
| 1488 |
|
| 1489 |
void wxcWidget::RemoveEvent(const wxString& eventName) { m_connectedEvents.Remove(eventName); } |
| 1490 |
|
| 1491 |
bool wxcWidget::HasEvent(const wxString& eventName) const { return m_connectedEvents.Contains(eventName); } |
| 1492 |
|
| 1493 |
wxString wxcWidget::GetCppName() const |
| 1494 |
{ |
| 1495 |
if(IsTopWindow()) { |
| 1496 |
return "this"; |
| 1497 |
} else { |
| 1498 |
return GetName(); |
| 1499 |
} |
| 1500 |
} |
| 1501 |
|
| 1502 |
wxString wxcWidget::CreateBaseclassName() const |
| 1503 |
{ |
| 1504 |
// Avoid creating MyFooBaseBaseClass |
| 1505 |
wxString name = GetName().Trim().Trim(false); |
| 1506 |
return name; |
| 1507 |
} |
| 1508 |
|
| 1509 |
wxString wxcWidget::DoGenerateEventStubs() const |
| 1510 |
{ |
| 1511 |
wxString stubsCode; |
| 1512 |
MapEvents_t::const_iterator iter = m_connectedEvents.begin(); |
| 1513 |
for(; iter != m_connectedEvents.end(); iter++) { |
| 1514 |
ConnectDetails eventDetails = iter->second; |
| 1515 |
if(eventDetails.GetFunctionNameAndSignature().IsEmpty()) { |
| 1516 |
eventDetails.GenerateFunctionName(GetName()); |
| 1517 |
} |
| 1518 |
|
| 1519 |
if(eventDetails.GetNoBody()) { |
| 1520 |
stubsCode << "virtual void " << eventDetails.GetFunctionNameAndSignature() << ";\n"; |
| 1521 |
} else { |
| 1522 |
stubsCode << "virtual void " << eventDetails.GetFunctionNameAndSignature() << " { event.Skip(); }\n"; |
| 1523 |
} |
| 1524 |
} |
| 1525 |
WrapInIfBlockIfNeeded(stubsCode); |
| 1526 |
return stubsCode; |
| 1527 |
} |
| 1528 |
|
| 1529 |
wxString wxcWidget::DoGenerateConnectCode() const |
| 1530 |
{ |
| 1531 |
wxString bind_code; |
| 1532 |
wxString scopeName = DoGetScopeName(); |
| 1533 |
|
| 1534 |
MapEvents_t::const_iterator iter = m_connectedEvents.begin(); |
| 1535 |
for(; iter != m_connectedEvents.end(); iter++) { |
| 1536 |
ConnectDetails eventDetails = iter->second; |
| 1537 |
|
| 1538 |
if(eventDetails.GetFunctionNameAndSignature().IsEmpty()) { |
| 1539 |
eventDetails.GenerateFunctionName(GetName()); |
| 1540 |
} |
| 1541 |
|
| 1542 |
wxString funcNameOnly = eventDetails.GetFunctionNameAndSignature().BeforeFirst(wxT('(')); |
| 1543 |
bool isMenuItem = (GetType() == ID_WXMENUITEM); |
| 1544 |
bool isToolbarItem = (GetType() == ID_WXTOOLBARITEM); |
| 1545 |
bool isInfoBarButton = (GetType() == ID_WXINFOBARBUTTON); |
| 1546 |
if(isMenuItem) { |
| 1547 |
// This item is a menu item |
| 1548 |
// dont generate code for separator item |
| 1549 |
if(this->PropertyString(PROP_WINDOW_ID) != "wxID_SEPARATOR" && |
| 1550 |
wxCrafter::GetToolType(PropertyString(PROP_KIND)) != wxCrafter::TOOL_TYPE_SEPARATOR) { |
| 1551 |
wxString menu_id = GetName() + "->GetId()"; |
| 1552 |
bind_code << "this->Bind(" << eventDetails.GetEventName() << ", " |
| 1553 |
<< "&" << scopeName << "::" << funcNameOnly << ", " |
| 1554 |
<< "this," << menu_id << ");\n"; |
| 1555 |
} |
| 1556 |
|
| 1557 |
} else if(isInfoBarButton) { |
| 1558 |
// Toolbar item connect |
| 1559 |
wxString menu_id = WindowID(); |
| 1560 |
bind_code << GetParent()->GetName() << "->Bind(" << eventDetails.GetEventName() << ", &" << scopeName |
| 1561 |
<< "::" << funcNameOnly << ", " |
| 1562 |
<< "this, " << menu_id << ");\n"; |
| 1563 |
|
| 1564 |
} else if(isToolbarItem) { |
| 1565 |
// Toolbar item connect |
| 1566 |
bind_code << "this->Bind(" << eventDetails.GetEventName() << ", " |
| 1567 |
<< "&" << scopeName << "::" << funcNameOnly << ", " |
| 1568 |
<< "this, " << WindowID() << ");\n"; |
| 1569 |
|
| 1570 |
} else { |
| 1571 |
bind_code << GetCppName() << "->Bind("; |
| 1572 |
if(!UseIdInConnect()) { |
| 1573 |
bind_code << eventDetails.GetEventName() << ", " |
| 1574 |
<< "&" << scopeName << "::" << funcNameOnly << ", " |
| 1575 |
<< "this);\n"; |
| 1576 |
} else { |
| 1577 |
bind_code << eventDetails.GetEventName() << ", " |
| 1578 |
<< "&" << scopeName << "::" << funcNameOnly << ", " |
| 1579 |
<< "this, " << GetId() << ");\n"; |
| 1580 |
} |
| 1581 |
} |
| 1582 |
} |
| 1583 |
|
| 1584 |
WrapInIfBlockIfNeeded(bind_code); |
| 1585 |
return bind_code; |
| 1586 |
} |
| 1587 |
|
| 1588 |
wxString wxcWidget::DoGetScopeName() const |
| 1589 |
{ |
| 1590 |
const wxcWidget* wrapper = this; |
| 1591 |
do { |
| 1592 |
if(wrapper->IsTopWindow()) { |
| 1593 |
return wrapper->CreateBaseclassName(); |
| 1594 |
} |
| 1595 |
wrapper = wrapper->GetParent(); |
| 1596 |
} while(wrapper); |
| 1597 |
|
| 1598 |
return ""; |
| 1599 |
} |
| 1600 |
|
| 1601 |
void wxcWidget::RegisterEvent(const wxString& eventName, const wxString& className, const wxString& description, |
| 1602 |
const wxString& handlerName /*=""*/, const wxString& functionNameAndSig /*=""*/, |
| 1603 |
bool noBody /*=false*/) |
| 1604 |
{ |
| 1605 |
m_controlEvents.Add(eventName, className, description, functionNameAndSig, noBody); |
| 1606 |
} |
| 1607 |
|
| 1608 |
wxString wxcWidget::XRCPrefix(const wxString& class_name) const |
| 1609 |
{ |
| 1610 |
wxString text; |
| 1611 |
wxString className = class_name.IsEmpty() ? GetWxClassName() : class_name; |
| 1612 |
text << "<object class=\"" << className << "\" name=\"" << wxCrafter::XMLEncode(GetName()) << "\""; |
| 1613 |
if(!PropertyString(PROP_SUBCLASS_NAME).empty()) { |
| 1614 |
text << " subclass=\"" << wxCrafter::XMLEncode(PropertyString(PROP_SUBCLASS_NAME)) << "\""; |
| 1615 |
} |
| 1616 |
text << ">"; |
| 1617 |
return text; |
| 1618 |
} |
| 1619 |
|
| 1620 |
wxString wxcWidget::XRCSuffix() const { return "</object>"; } |
| 1621 |
|
| 1622 |
wxString wxcWidget::XRCStyle(bool forPreview) const |
| 1623 |
{ |
| 1624 |
wxString text; |
| 1625 |
wxString style = StyleFlags(); |
| 1626 |
|
| 1627 |
if(forPreview && style.IsEmpty()) { |
| 1628 |
style << "wxSTAY_ON_TOP"; |
| 1629 |
|
| 1630 |
} else if(forPreview) { |
| 1631 |
style << "|wxSTAY_ON_TOP"; |
| 1632 |
} |
| 1633 |
|
| 1634 |
text << "<style>" << wxCrafter::XMLEncode(style) << "</style>"; |
| 1635 |
return text; |
| 1636 |
} |
| 1637 |
|
| 1638 |
wxString wxcWidget::XRCSize(bool dontEmitDefault /*=true*/) const |
| 1639 |
{ |
| 1640 |
wxString text; |
| 1641 |
if(!dontEmitDefault || GetSize() != wxSize(-1, -1)) { |
| 1642 |
text << "<size>" << wxCrafter::XMLEncode(Size()) << "</size>"; |
| 1643 |
} |
| 1644 |
return text; |
| 1645 |
} |
| 1646 |
|
| 1647 |
wxString wxcWidget::XRCValue() const |
| 1648 |
{ |
| 1649 |
wxString text; |
| 1650 |
wxString value = PropertyString(PROP_VALUE); |
| 1651 |
if(!value.empty()) { |
| 1652 |
// Don't use wxCrafter::CDATA here because of http://trac.wxwidgets.org/ticket/10552 |
| 1653 |
// which in < wx3 results in "foo" -> "\nfoo" and very strange-looking buttons! |
| 1654 |
text << "<value>" << wxCrafter::XMLEncode(value) << "</value>"; |
| 1655 |
} |
| 1656 |
return text; |
| 1657 |
} |
| 1658 |
|
| 1659 |
wxString wxcWidget::XRCLabel() const |
| 1660 |
{ |
| 1661 |
wxString text; |
| 1662 |
// Don't use wxCrafter::CDATA here because of http://trac.wxwidgets.org/ticket/10552 |
| 1663 |
// which in < wx3 results in "foo" -> "\nfoo" and very strange-looking buttons! |
| 1664 |
text << "<label>" << wxCrafter::XMLEncode(PropertyString(PROP_LABEL)) << "</label>"; |
| 1665 |
return text; |
| 1666 |
} |
| 1667 |
|
| 1668 |
wxString wxcWidget::XRCContentItems(bool ensureAtLeastOneEntry) const |
| 1669 |
{ |
| 1670 |
wxArrayString options = wxCrafter::Split(PropertyString(PROP_OPTIONS), ";"); |
| 1671 |
if(options.IsEmpty() && ensureAtLeastOneEntry) { |
| 1672 |
options.Add("Dummy Option"); |
| 1673 |
} |
| 1674 |
|
| 1675 |
wxString text; |
| 1676 |
text << "<content>"; |
| 1677 |
for(size_t i = 0; i < options.GetCount(); i++) { |
| 1678 |
// Don't use wxCrafter::CDATA here because of http://trac.wxwidgets.org/ticket/10552 |
| 1679 |
// which in < wx3 results in "foo" -> "\nfoo" and very strange-looking buttons! |
| 1680 |
text << "<item>" << wxCrafter::XMLEncode(options.Item(i)) << "</item>"; |
| 1681 |
} |
| 1682 |
text << "</content>"; |
| 1683 |
return text; |
| 1684 |
} |
| 1685 |
|
| 1686 |
wxString wxcWidget::XRCSelection() const |
| 1687 |
{ |
| 1688 |
wxString text; |
| 1689 |
// Don't use wxCrafter::CDATA here because of http://trac.wxwidgets.org/ticket/10552 |
| 1690 |
// which in < wx3 results in "foo" -> "\nfoo" and very strange-looking buttons! |
| 1691 |
text << "<selection>" << wxCrafter::XMLEncode(PropertyString(PROP_SELECTION)) << "</selection>"; |
| 1692 |
return text; |
| 1693 |
} |
| 1694 |
|
| 1695 |
ConnectDetails wxcWidget::GetEventMetaData(const wxString& eventName) const |
| 1696 |
{ |
| 1697 |
if(!m_controlEvents.GetEvents().Contains(eventName)) { |
| 1698 |
return ConnectDetails(); |
| 1699 |
} |
| 1700 |
|
| 1701 |
return m_controlEvents.GetEvents().Item(eventName); |
| 1702 |
} |
| 1703 |
|
| 1704 |
ConnectDetails wxcWidget::GetEvent(const wxString& eventName) const |
| 1705 |
{ |
| 1706 |
if(m_connectedEvents.Contains(eventName)) { |
| 1707 |
return m_connectedEvents.Item(eventName); |
| 1708 |
} |
| 1709 |
return ConnectDetails(); |
| 1710 |
} |
| 1711 |
|
| 1712 |
wxString wxcWidget::CPPStandardWxCtor(const wxString& defaultStyle) const |
| 1713 |
{ |
| 1714 |
// For subclassed controls we must use the subclass name |
| 1715 |
wxString cpp; |
| 1716 |
cpp << GetName() << " = new " << GetRealClassName() << "(" << GetWindowParent() << ", " << WindowID() << ", " |
| 1717 |
<< "wxDefaultPosition, " << SizeAsString() << ", " << StyleFlags(defaultStyle) << ");\n"; |
| 1718 |
cpp << CPPCommonAttributes(); |
| 1719 |
return cpp; |
| 1720 |
} |
| 1721 |
|
| 1722 |
wxString wxcWidget::CPPStandardWxCtorWithValue(const wxString& defaultStyle) const |
| 1723 |
{ |
| 1724 |
// For subclassed controls we must use the subclass name |
| 1725 |
wxString cpp; |
| 1726 |
cpp << GetName() << " = new " << GetRealClassName() << "(" << GetWindowParent() << ", " << WindowID() << ", " |
| 1727 |
<< ValueAsString() << ", " |
| 1728 |
<< "wxDefaultPosition, " << SizeAsString() << ", " << StyleFlags(defaultStyle) << ");\n"; |
| 1729 |
|
| 1730 |
cpp << CPPCommonAttributes(); |
| 1731 |
return cpp; |
| 1732 |
} |
| 1733 |
|
| 1734 |
wxString wxcWidget::CPPStandardWxCtorWithLabel(const wxString& defaultStyle) const |
| 1735 |
{ |
| 1736 |
wxString cpp; |
| 1737 |
cpp << GetName() << " = new " << GetRealClassName() << "(" << GetWindowParent() << ", " << WindowID() << ", " |
| 1738 |
<< Label() << ", " |
| 1739 |
<< "wxDefaultPosition, " << SizeAsString() << ", " << StyleFlags(defaultStyle) << ");\n"; |
| 1740 |
cpp << CPPCommonAttributes(); |
| 1741 |
return cpp; |
| 1742 |
} |
| 1743 |
|
| 1744 |
wxString wxcWidget::XRCUnknown() const |
| 1745 |
{ |
| 1746 |
wxString xrc; |
| 1747 |
xrc << "<object class=\"unknown\" name=\"" << GetName() << "\">"; |
| 1748 |
xrc << XRCSize() << XRCCommonAttributes() << XRCSuffix(); |
| 1749 |
return xrc; |
| 1750 |
} |
| 1751 |
|
| 1752 |
wxString wxcWidget::XRCCommonAttributes() const |
| 1753 |
{ |
| 1754 |
wxString xrc; |
| 1755 |
wxString colorname = PropertyString(PROP_BG); |
| 1756 |
if(colorname != "<Default>") { |
| 1757 |
xrc << "<bg>" << wxCrafter::GetColourForXRC(colorname) << "</bg>"; |
| 1758 |
} |
| 1759 |
|
| 1760 |
colorname = PropertyString(PROP_FG); |
| 1761 |
if(colorname != "<Default>") { |
| 1762 |
xrc << "<fg>" << wxCrafter::GetColourForXRC(colorname) << "</fg>"; |
| 1763 |
} |
| 1764 |
|
| 1765 |
wxString font = wxCrafter::FontToXRC(PropertyString(PROP_FONT)); |
| 1766 |
if(!font.IsEmpty()) { |
| 1767 |
xrc << "<font>" << font << "</font>"; |
| 1768 |
} |
| 1769 |
|
| 1770 |
wxString tip = PropertyString(PROP_TOOLTIP); |
| 1771 |
tip.Trim().Trim(false); |
| 1772 |
|
| 1773 |
if(!tip.IsEmpty()) { |
| 1774 |
xrc << "<tooltip>" << wxCrafter::CDATA(tip) << "</tooltip>"; |
| 1775 |
} |
| 1776 |
|
| 1777 |
// Enable / Disable + Hidden support |
| 1778 |
bool bHide = (PropertyBool(PROP_STATE_HIDDEN) == "true"); |
| 1779 |
bool bDisable = (PropertyBool(PROP_STATE_DISABLED) == "true"); |
| 1780 |
if(bHide) { |
| 1781 |
xrc << "<hidden>1</hidden>"; |
| 1782 |
} |
| 1783 |
|
| 1784 |
if(bDisable) { |
| 1785 |
xrc << "<enabled>0</enabled>"; |
| 1786 |
} |
| 1787 |
|
| 1788 |
bool bFocused = (PropertyBool(PROP_HAS_FOCUS) == "true"); |
| 1789 |
if(bFocused) { |
| 1790 |
xrc << "<focused>1</focused>"; |
| 1791 |
} |
| 1792 |
|
| 1793 |
return xrc; |
| 1794 |
} |
| 1795 |
|
| 1796 |
wxString wxcWidget::CPPCommonAttributes() const |
| 1797 |
{ |
| 1798 |
wxString cpp; |
| 1799 |
wxString instanceName; |
| 1800 |
if(IsTopWindow()) { |
| 1801 |
instanceName = "this"; |
| 1802 |
} else { |
| 1803 |
instanceName = GetName(); |
| 1804 |
} |
| 1805 |
|
| 1806 |
wxString colorname = wxCrafter::ColourToCpp(PropertyString(PROP_BG)); |
| 1807 |
if(colorname.IsEmpty() == false) { |
| 1808 |
cpp << instanceName << "->SetBackgroundColour(" << colorname << ");\n"; |
| 1809 |
} |
| 1810 |
|
| 1811 |
colorname = wxCrafter::ColourToCpp(PropertyString(PROP_FG)); |
| 1812 |
if(colorname.IsEmpty() == false) { |
| 1813 |
cpp << instanceName << "->SetForegroundColour(" << colorname << ");\n"; |
| 1814 |
} |
| 1815 |
|
| 1816 |
wxString fontMemberName = instanceName + "Font"; |
| 1817 |
wxString font = wxCrafter::FontToCpp(PropertyString(PROP_FONT), fontMemberName); |
| 1818 |
if(font.IsEmpty() == false && font != "wxNullFont") { |
| 1819 |
cpp << font; |
| 1820 |
cpp << instanceName << "->SetFont(" << fontMemberName << ");\n"; |
| 1821 |
} |
| 1822 |
|
| 1823 |
wxString tip = PropertyString(PROP_TOOLTIP); |
| 1824 |
tip.Trim().Trim(false); |
| 1825 |
if(tip.IsEmpty() == false) { |
| 1826 |
cpp << instanceName << "->SetToolTip(" << wxCrafter::UNDERSCORE(tip) << ");\n"; |
| 1827 |
} |
| 1828 |
|
| 1829 |
bool bHide = (PropertyBool(PROP_STATE_HIDDEN) == "true"); |
| 1830 |
if(bHide) { |
| 1831 |
cpp << instanceName << "->Hide();\n"; |
| 1832 |
} |
| 1833 |
|
| 1834 |
bool bDisable = (PropertyBool(PROP_STATE_DISABLED) == "true"); |
| 1835 |
if(bDisable) { |
| 1836 |
cpp << instanceName << "->Enable(false);\n"; |
| 1837 |
} |
| 1838 |
|
| 1839 |
bool bFocused = (PropertyBool(PROP_HAS_FOCUS) == "true"); |
| 1840 |
if(bFocused) { |
| 1841 |
cpp << instanceName << "->SetFocus();\n"; |
| 1842 |
} |
| 1843 |
|
| 1844 |
return cpp; |
| 1845 |
} |
| 1846 |
|
| 1847 |
void wxcWidget::SetParent(wxcWidget* parent) { this->m_parent = parent; } |
| 1848 |
|
| 1849 |
CONTROL_TYPE wxcWidget::GetWidgetType(int type) |
| 1850 |
{ |
| 1851 |
// ADD_NEW_CONTROL |
| 1852 |
switch(type) { |
| 1853 |
case ID_WXREARRANGELIST: |
| 1854 |
case ID_WXANIMATIONCTRL: |
| 1855 |
case ID_WXBANNERWINDOW: |
| 1856 |
case ID_WXBUTTON: |
| 1857 |
case ID_WXBITMAPBUTTON: |
| 1858 |
case ID_WXSTATICTEXT: |
| 1859 |
case ID_WXTEXTCTRL: |
| 1860 |
case ID_WXSTATICBITMAP: |
| 1861 |
case ID_WXCOMBOBOX: |
| 1862 |
case ID_WXCHOICE: |
| 1863 |
case ID_WXLISTBOX: |
| 1864 |
case ID_WXCHECKBOX: |
| 1865 |
case ID_WXRADIOBOX: |
| 1866 |
case ID_WXRADIOBUTTON: |
| 1867 |
case ID_WXSTATICLINE: |
| 1868 |
case ID_WXSLIDER: |
| 1869 |
case ID_WXGAUGE: |
| 1870 |
case ID_WXTREECTRL: |
| 1871 |
case ID_WXHTMLWIN: |
| 1872 |
case ID_WXRICHTEXT: |
| 1873 |
case ID_WXCHECKLISTBOX: |
| 1874 |
case ID_WXTOGGLEBUTTON: |
| 1875 |
case ID_WXSEARCHCTRL: |
| 1876 |
case ID_WXCOLORPICKER: |
| 1877 |
case ID_WXFONTPICKER: |
| 1878 |
case ID_WXFILEPICKER: |
| 1879 |
case ID_WXDIRPICKER: |
| 1880 |
case ID_WXDATEPICKER: |
| 1881 |
case ID_WXCALEDARCTRL: |
| 1882 |
case ID_WXSCROLLBAR: |
| 1883 |
case ID_WXSPINCTRL: |
| 1884 |
case ID_WXSPINBUTTON: |
| 1885 |
case ID_WXHYPERLINK: |
| 1886 |
case ID_WXGENERICDIRCTRL: |
| 1887 |
case ID_WXCUSTOMCONTROL: |
| 1888 |
case ID_WXSTC: |
| 1889 |
case ID_WXDATAVIEWTREECTRL: |
| 1890 |
case ID_WXCOMMANDLINKBUTTON: |
| 1891 |
case ID_WXWEBVIEW: |
| 1892 |
case ID_WXGLCANVAS: |
| 1893 |
case ID_WXMEDIACTRL: |
| 1894 |
case ID_WXBITMAPTOGGLEBUTTON: |
| 1895 |
case ID_WXBITMAPCOMBOBOX: |
| 1896 |
case ID_WXSIMPLEHTMLLISTBOX: |
| 1897 |
case ID_WXACTIVITYINDICATOR: |
| 1898 |
case ID_WXTIMEPICKERCTRL: |
| 1899 |
return TYPE_CONTROL; |
| 1900 |
|
| 1901 |
case ID_WXGRID: |
| 1902 |
return TYPE_GRID; |
| 1903 |
|
| 1904 |
case ID_WXGRIDCOL: |
| 1905 |
case ID_WXGRIDROW: |
| 1906 |
return TYPE_GRID_CHILD; |
| 1907 |
|
| 1908 |
case ID_WXRIBBONGALLERY: |
| 1909 |
return TYPE_RIBBON_GALLERY; |
| 1910 |
|
| 1911 |
case ID_WXRIBBONGALLERYITME: |
| 1912 |
return TYPE_RIBBON_GALLERY_ITEM; |
| 1913 |
|
| 1914 |
case ID_WXRIBBONTOOLBAR: |
| 1915 |
return TYPE_RIBBON_TOOLBAR; |
| 1916 |
|
| 1917 |
case ID_WXRIBBONBUTTONBAR: |
| 1918 |
return TYPE_RIBBON_BUTTONBAR; |
| 1919 |
|
| 1920 |
case ID_WXRIBBONBUTTON: |
| 1921 |
case ID_WXRIBBONHYBRIDBUTTON: |
| 1922 |
case ID_WXRIBBONTOGGLEBUTTON: |
| 1923 |
case ID_WXRIBBONDROPDOWNBUTTON: |
| 1924 |
return TYPE_RIBBON_BUTTON; |
| 1925 |
|
| 1926 |
case ID_WXRIBBONTOOL: |
| 1927 |
case ID_WXRIBBONHYBRIDTOOL: |
| 1928 |
case ID_WXRIBBONTOGGLETOOL: |
| 1929 |
case ID_WXRIBBONDROPDOWNTOOL: |
| 1930 |
case ID_WXRIBBONTOOLSEPARATOR: |
| 1931 |
return TYPE_RIBBON_TOOL; |
| 1932 |
|
| 1933 |
case ID_WXRIBBONPANEL: |
| 1934 |
return TYPE_RIBBON_PANEL; |
| 1935 |
|
| 1936 |
case ID_WXRIBBONPAGE: |
| 1937 |
return TYPE_RIBBON_PAGE; |
| 1938 |
|
| 1939 |
case ID_WXRIBBONBAR: |
| 1940 |
return TYPE_RIBBON_BAR; |
| 1941 |
|
| 1942 |
case ID_WXPROPERTYGRIDMANAGER: |
| 1943 |
return TYPE_PG_MGR; |
| 1944 |
|
| 1945 |
case ID_WXPGPROPERTY: |
| 1946 |
return TYPE_PG_PROPERTY; |
| 1947 |
|
| 1948 |
case ID_WXBITMAP: |
| 1949 |
return TYPE_BITMAP; |
| 1950 |
case ID_WXIMAGELIST: |
| 1951 |
return TYPE_IMGLIST; |
| 1952 |
|
| 1953 |
case ID_WXAUIMANAGER: |
| 1954 |
return TYPE_AUI_MGR; |
| 1955 |
|
| 1956 |
case ID_WXINFOBAR: |
| 1957 |
return TYPE_INFO_BAR; |
| 1958 |
|
| 1959 |
case ID_WXINFOBARBUTTON: |
| 1960 |
return TYPE_INFO_BAR_BUTTON; |
| 1961 |
|
| 1962 |
case ID_WXSTDDLGBUTTONSIZER: |
| 1963 |
return TYPE_STD_BUTTON_SIZER; |
| 1964 |
|
| 1965 |
case ID_WXSTDBUTTON: |
| 1966 |
return TYPE_STD_BUTTON; |
| 1967 |
|
| 1968 |
case ID_WXSTATUSBAR: |
| 1969 |
return TYPE_STATUSABR; |
| 1970 |
|
| 1971 |
case ID_WXTOOLBAR: |
| 1972 |
return TYPE_TOOLBAR; |
| 1973 |
|
| 1974 |
case ID_WXAUITOOLBAR: |
| 1975 |
case ID_WXAUITOOLBARTOPLEVEL: |
| 1976 |
return TYPE_AUITOOLBAR; |
| 1977 |
|
| 1978 |
case ID_WXTOOLBARITEM: |
| 1979 |
case ID_WXTOOLBARITEM_SEPARATOR: |
| 1980 |
case ID_WXTOOLBARITEM_STRETCHSPACE: |
| 1981 |
case ID_WXAUITOOLBARLABEL: |
| 1982 |
case ID_WXAUITOOLBARITEM_SPACE: |
| 1983 |
case ID_WXAUITOOLBARITEM_STRETCHSPACE: |
| 1984 |
return TYPE_TOOLITEM; |
| 1985 |
|
| 1986 |
case ID_WXMENUITEM: |
| 1987 |
return TYPE_MENUITEM; |
| 1988 |
|
| 1989 |
case ID_WXMENUBAR: |
| 1990 |
return TYPE_MENUBAR; |
| 1991 |
|
| 1992 |
case ID_WXMENU: |
| 1993 |
return TYPE_MENU; |
| 1994 |
|
| 1995 |
case ID_WXSUBMENU: |
| 1996 |
return TYPE_SUBMENU; |
| 1997 |
|
| 1998 |
case ID_WXSPACER: |
| 1999 |
return TYPE_SPACER; |
| 2000 |
|
| 2001 |
case ID_WXLISTCTRL_COL: |
| 2002 |
return TYPE_LIST_CTRL_COL; |
| 2003 |
|
| 2004 |
case ID_WXSPLITTERWINDOW: |
| 2005 |
return TYPE_SPLITTER_WINDOW; |
| 2006 |
|
| 2007 |
case ID_WXLISTCTRL: |
| 2008 |
return TYPE_LIST_CTRL; |
| 2009 |
|
| 2010 |
case ID_WXTREELISTCTRL: |
| 2011 |
return TYPE_TREE_LIST_CTRL; |
| 2012 |
|
| 2013 |
case ID_WXTREELISTCTRLCOL: |
| 2014 |
return TYPE_TREE_LIST_CTRL_COL; |
| 2015 |
|
| 2016 |
case ID_WXTIMER: |
| 2017 |
return TYPE_TIMER; |
| 2018 |
case ID_WXTASKBARICON: |
| 2019 |
return TYPE_TASKBARICON; |
| 2020 |
|
| 2021 |
case ID_WXDATAVIEWLISTCTRL: |
| 2022 |
case ID_WXDATAVIEWTREELISTCTRL: |
| 2023 |
return TYPE_DV_WITH_COLUMNS; |
| 2024 |
|
| 2025 |
case ID_WXDATAVIEWCOL: |
| 2026 |
return TYPE_DV_LISTCTRLCOL; |
| 2027 |
|
| 2028 |
case ID_WXPANEL_TOPLEVEL: |
| 2029 |
case ID_WXDIALOG: |
| 2030 |
case ID_WXPOPUPWINDOW: |
| 2031 |
return TYPE_FORM; |
| 2032 |
|
| 2033 |
case ID_WXFRAME: |
| 2034 |
return TYPE_FORM_FRAME; |
| 2035 |
|
| 2036 |
case ID_WXWIZARD: |
| 2037 |
return TYPE_WIZARD; |
| 2038 |
|
| 2039 |
case ID_WXWIZARDPAGE: |
| 2040 |
return TYPE_WIZARD_PAGE; |
| 2041 |
|
| 2042 |
case ID_WXBOXSIZER: |
| 2043 |
case ID_WXFLEXGRIDSIZER: |
| 2044 |
case ID_WXSTATICBOXSIZER: |
| 2045 |
case ID_WXGRIDSIZER: |
| 2046 |
case ID_WXGRIDBAGSIZER: |
| 2047 |
return TYPE_SIZER; |
| 2048 |
|
| 2049 |
case ID_WXPANEL: |
| 2050 |
case ID_WXSCROLLEDWIN: |
| 2051 |
return TYPE_CONTAINER; |
| 2052 |
|
| 2053 |
case ID_WXCOLLAPSIBLEPANE: |
| 2054 |
return TYPE_COLOLAPSIBLEPANE; |
| 2055 |
|
| 2056 |
case ID_WXCOLLAPSIBLEPANE_PANE: |
| 2057 |
return TYPE_COLOLAPSIBLEPANE_PANE; |
| 2058 |
|
| 2059 |
case ID_WXNOTEBOOK: |
| 2060 |
case ID_WXLISTBOOK: |
| 2061 |
case ID_WXCHOICEBOOK: |
| 2062 |
case ID_WXTREEBOOK: |
| 2063 |
case ID_WXTOOLBOOK: |
| 2064 |
case ID_WXAUINOTEBOOK: |
| 2065 |
case ID_WXSIMPLEBOOK: |
| 2066 |
return TYPE_BOOK; |
| 2067 |
|
| 2068 |
case ID_WXSPLITTERWINDOW_PAGE: |
| 2069 |
return TYPE_SPLITTERWIN_PAGE; |
| 2070 |
|
| 2071 |
case ID_WXPANEL_NOTEBOOK_PAGE: |
| 2072 |
return TYPE_NOTEBOOK_PAGE; |
| 2073 |
|
| 2074 |
default: |
| 2075 |
return TYPE_UNKNOWN; |
| 2076 |
} |
| 2077 |
} |
| 2078 |
|
| 2079 |
CONTROL_TYPE wxcWidget::GetWidgetType() const { return GetWidgetType(this->m_type); } |
| 2080 |
|
| 2081 |
bool wxcWidget::IsDirectOrIndirectChildOf(wxcWidget* p) const |
| 2082 |
{ |
| 2083 |
wxcWidget* parent = this->GetParent(); |
| 2084 |
while(parent) { |
| 2085 |
if(parent == p) { |
| 2086 |
return true; |
| 2087 |
} |
| 2088 |
parent = parent->GetParent(); |
| 2089 |
} |
| 2090 |
return false; |
| 2091 |
} |
| 2092 |
|
| 2093 |
void wxcWidget::InsertBefore(wxcWidget* item, wxcWidget* insertBefore) |
| 2094 |
{ |
| 2095 |
item->SetParent(this); |
| 2096 |
List_t::iterator iter = m_children.begin(); |
| 2097 |
for(; iter != m_children.end(); iter++) { |
| 2098 |
if((*iter) == insertBefore) { |
| 2099 |
m_children.insert(iter, item); |
| 2100 |
break; |
| 2101 |
} |
| 2102 |
} |
| 2103 |
} |
| 2104 |
|
| 2105 |
void wxcWidget::InsertAfter(wxcWidget* item, wxcWidget* insertAfter) |
| 2106 |
{ |
| 2107 |
item->SetParent(this); |
| 2108 |
bool inserted = false; |
| 2109 |
bool insert_next = false; |
| 2110 |
|
| 2111 |
List_t::iterator iter = m_children.begin(); |
| 2112 |
for(; iter != m_children.end(); iter++) { |
| 2113 |
|
| 2114 |
if(insert_next) { |
| 2115 |
m_children.insert(iter, item); |
| 2116 |
inserted = true; |
| 2117 |
break; |
| 2118 |
|
| 2119 |
} else if((*iter) == insertAfter) { |
| 2120 |
insert_next = true; |
| 2121 |
} |
| 2122 |
} |
| 2123 |
|
| 2124 |
if(insert_next && !inserted) { |
| 2125 |
m_children.push_back(item); |
| 2126 |
} |
| 2127 |
} |
| 2128 |
void wxcWidget::FixPaths(const wxString& cwd) |
| 2129 |
{ |
| 2130 |
MapProperties_t::iterator prop_iter = m_properties.begin(); |
| 2131 |
for(; prop_iter != m_properties.end(); prop_iter++) { |
| 2132 |
if(prop_iter->second) { |
| 2133 |
FilePickerProperty* pb = dynamic_cast<FilePickerProperty*>(prop_iter->second); |
| 2134 |
if(pb) { |
| 2135 |
pb->FixPaths(cwd); |
| 2136 |
} |
| 2137 |
} |
| 2138 |
} |
| 2139 |
|
| 2140 |
// Fix the children properties as well |
| 2141 |
List_t::iterator child_iter = m_children.begin(); |
| 2142 |
for(; child_iter != m_children.end(); child_iter++) { |
| 2143 |
(*child_iter)->FixPaths(cwd); |
| 2144 |
} |
| 2145 |
} |
| 2146 |
|
| 2147 |
bool wxcWidget::IsParentToolbar() const |
| 2148 |
{ |
| 2149 |
return GetParent() && (GetParent()->GetType() == ID_WXTOOLBAR || GetParent()->GetType() == ID_WXAUITOOLBAR || |
| 2150 |
GetParent()->GetType() == ID_WXAUITOOLBARTOPLEVEL); |
| 2151 |
} |
| 2152 |
|
| 2153 |
bool wxcWidget::IsLastChild() const |
| 2154 |
{ |
| 2155 |
wxcWidget* parent = GetParent(); |
| 2156 |
if(!parent) { |
| 2157 |
return false; |
| 2158 |
} |
| 2159 |
|
| 2160 |
const List_t& siblings = parent->GetChildren(); |
| 2161 |
const wxcWidget* lastChild = siblings.back(); |
| 2162 |
return lastChild == this; |
| 2163 |
} |
| 2164 |
|
| 2165 |
wxcWidget* wxcWidget::GetTopLevel() const |
| 2166 |
{ |
| 2167 |
const wxcWidget* parent = this; |
| 2168 |
|
| 2169 |
while(parent->GetParent()) { |
| 2170 |
parent = parent->GetParent(); |
| 2171 |
} |
| 2172 |
|
| 2173 |
return const_cast<wxcWidget*>(parent); |
| 2174 |
} |
| 2175 |
|
| 2176 |
bool wxcWidget::HasMenuBar() const |
| 2177 |
{ |
| 2178 |
const List_t& children = GetChildren(); |
| 2179 |
List_t::const_iterator iter = children.begin(); |
| 2180 |
for(; iter != children.end(); ++iter) { |
| 2181 |
if((*iter)->GetType() == ID_WXMENUBAR) { |
| 2182 |
return true; |
| 2183 |
} |
| 2184 |
} |
| 2185 |
return false; |
| 2186 |
} |
| 2187 |
|
| 2188 |
bool wxcWidget::HasStatusBar() const |
| 2189 |
{ |
| 2190 |
const List_t& children = GetChildren(); |
| 2191 |
List_t::const_iterator iter = children.begin(); |
| 2192 |
for(; iter != children.end(); ++iter) { |
| 2193 |
if((*iter)->GetType() == ID_WXSTATUSBAR) { |
| 2194 |
return true; |
| 2195 |
} |
| 2196 |
} |
| 2197 |
return false; |
| 2198 |
} |
| 2199 |
|
| 2200 |
bool wxcWidget::HasToolBar() const |
| 2201 |
{ |
| 2202 |
const List_t& children = GetChildren(); |
| 2203 |
List_t::const_iterator iter = children.begin(); |
| 2204 |
for(; iter != children.end(); ++iter) { |
| 2205 |
if((*iter)->GetType() == ID_WXTOOLBAR) { |
| 2206 |
return true; |
| 2207 |
} |
| 2208 |
} |
| 2209 |
return false; |
| 2210 |
} |
| 2211 |
|
| 2212 |
wxString wxcWidget::XRCBitmap(const wxString& label, const wxString& bitmap) const |
| 2213 |
{ |
| 2214 |
wxString file = bitmap; |
| 2215 |
file.Trim().Trim(false); |
| 2216 |
|
| 2217 |
if(file.IsEmpty()) { |
| 2218 |
return ""; |
| 2219 |
} |
| 2220 |
|
| 2221 |
wxString artId, clientId, sizeHint; |
| 2222 |
wxString xrc; |
| 2223 |
if(wxCrafter::IsArtProviderBitmap(file, artId, clientId, sizeHint)) { |
| 2224 |
wxString artstring; |
| 2225 |
artstring << " stock_id=\"" << artId << "\""; |
| 2226 |
if(!clientId.empty()) { |
| 2227 |
artstring << " stock_client=\"" << clientId << "\""; |
| 2228 |
xrc << "<" << label << artstring << " />"; |
| 2229 |
} |
| 2230 |
} else { |
| 2231 |
xrc << "<" << label << ">" << file << "</" << label << ">"; |
| 2232 |
} |
| 2233 |
return xrc; |
| 2234 |
} |
| 2235 |
|
| 2236 |
wxString wxcWidget::XRCBitmap(const wxString& labelname) const |
| 2237 |
{ |
| 2238 |
wxString file = PropertyFile(PROP_BITMAP_PATH); |
| 2239 |
file.Trim().Trim(false); |
| 2240 |
|
| 2241 |
if(file.IsEmpty()) { |
| 2242 |
return ""; |
| 2243 |
} |
| 2244 |
|
| 2245 |
wxString artId, clientId, sizeHint; |
| 2246 |
wxString xrc; |
| 2247 |
if(wxCrafter::IsArtProviderBitmap(file, artId, clientId, sizeHint)) { |
| 2248 |
wxString artstring; |
| 2249 |
artstring << " stock_id=\"" << artId << "\""; |
| 2250 |
if(!clientId.empty()) { |
| 2251 |
artstring << " stock_client=\"" << clientId << "\""; |
| 2252 |
xrc << "<" << labelname << artstring << " />"; |
| 2253 |
} |
| 2254 |
} else { |
| 2255 |
xrc << "<" << labelname << ">" << file << "</" << labelname << ">"; |
| 2256 |
} |
| 2257 |
return xrc; |
| 2258 |
} |
| 2259 |
|
| 2260 |
const wxcWidget* wxcWidget::FindChildByName(const wxString& name) const { return DoFindByName(this, name); } |
| 2261 |
|
| 2262 |
const wxcWidget* wxcWidget::DoFindByName(const wxcWidget* parent, const wxString& name) const |
| 2263 |
{ |
| 2264 |
if(parent->GetName() == name) { |
| 2265 |
return parent; |
| 2266 |
} |
| 2267 |
|
| 2268 |
List_t::const_iterator iter = parent->GetChildren().begin(); |
| 2269 |
for(; iter != parent->GetChildren().end(); ++iter) { |
| 2270 |
const wxcWidget* match = DoFindByName(*iter, name); |
| 2271 |
if(match) { |
| 2272 |
return match; |
| 2273 |
} |
| 2274 |
} |
| 2275 |
return NULL; |
| 2276 |
} |
| 2277 |
|
| 2278 |
const wxcWidget* wxcWidget::FindFirstDirectChildOfType(int type) const |
| 2279 |
{ |
| 2280 |
List_t::const_iterator iter = GetChildren().begin(); |
| 2281 |
for(; iter != GetChildren().end(); ++iter) { |
| 2282 |
if((*iter)->GetType() == type) { |
| 2283 |
return (*iter); |
| 2284 |
} |
| 2285 |
} |
| 2286 |
return NULL; |
| 2287 |
} |
| 2288 |
|
| 2289 |
wxSize wxcWidget::GetSize() const |
| 2290 |
{ |
| 2291 |
wxString sizeString = PropertyString(PROP_SIZE); |
| 2292 |
wxSize sz = wxCrafter::DecodeSize(sizeString); |
| 2293 |
return sz; |
| 2294 |
} |
| 2295 |
|
| 2296 |
void wxcWidget::DoGetConnectedEventsRecrusively(wxcWidget::Map_t& events, const wxcWidget* wb) const |
| 2297 |
{ |
| 2298 |
wxcWidget::MapEvents_t::const_iterator iter = wb->m_connectedEvents.begin(); |
| 2299 |
for(; iter != wb->m_connectedEvents.end(); ++iter) { |
| 2300 |
wxString fooname = iter->second.GetFunctionNameAndSignature().BeforeFirst(wxT('(')); |
| 2301 |
if(events.count(fooname) == 0) { |
| 2302 |
events.insert(std::make_pair(fooname, iter->second)); |
| 2303 |
} |
| 2304 |
} |
| 2305 |
|
| 2306 |
wxcWidget::List_t::const_iterator childIter = wb->m_children.begin(); |
| 2307 |
for(; childIter != wb->m_children.end(); ++childIter) { |
| 2308 |
DoGetConnectedEventsRecrusively(events, *childIter); |
| 2309 |
} |
| 2310 |
} |
| 2311 |
|
| 2312 |
wxcWidget::Map_t wxcWidget::GetConnectedEventsRecrusively() const |
| 2313 |
{ |
| 2314 |
wxcWidget::Map_t events; |
| 2315 |
DoGetConnectedEventsRecrusively(events, this); |
| 2316 |
return events; |
| 2317 |
} |
| 2318 |
|
| 2319 |
PropertyBase* wxcWidget::GetProperty(const wxString& name) |
| 2320 |
{ |
| 2321 |
if(m_properties.Contains(name)) { |
| 2322 |
return m_properties.Item(name); |
| 2323 |
} |
| 2324 |
return NULL; |
| 2325 |
} |
| 2326 |
|
| 2327 |
void wxcWidget::DelProperty(const wxString& name) |
| 2328 |
{ |
| 2329 |
if(m_properties.Contains(name)) { |
| 2330 |
delete m_properties.Item(name); |
| 2331 |
m_properties.Remove(name); |
| 2332 |
} |
| 2333 |
} |
| 2334 |
|
| 2335 |
size_t wxcWidget::SizerFlagsAsInteger() const |
| 2336 |
{ |
| 2337 |
size_t flags = 0; |
| 2338 |
MapStyles_t::const_iterator iter = m_sizerFlags.begin(); |
| 2339 |
for(; iter != m_sizerFlags.end(); ++iter) { |
| 2340 |
if(iter->second.is_set) { |
| 2341 |
flags |= iter->second.style_bit; |
| 2342 |
} |
| 2343 |
} |
| 2344 |
return flags; |
| 2345 |
} |
| 2346 |
|
| 2347 |
void wxcWidget::SetStyles(size_t value) |
| 2348 |
{ |
| 2349 |
MapStyles_t::iterator iter = m_styles.begin(); |
| 2350 |
for(; iter != m_styles.end(); ++iter) { |
| 2351 |
EnableStyle(iter->second.style_name, value & iter->second.style_bit); |
| 2352 |
} |
| 2353 |
} |
| 2354 |
|
| 2355 |
void wxcWidget::EnableSizerFlag(const wxString& flag, bool enable) |
| 2356 |
{ |
| 2357 |
if(m_sizerFlags.Contains(flag)) { |
| 2358 |
m_sizerFlags.Item(flag).is_set = enable; |
| 2359 |
|
| 2360 |
if(enable) { |
| 2361 |
// Uncheck all "grouped" flags |
| 2362 |
AntiGroupMap_t::const_iterator iter = s_antiGroup.find(flag); |
| 2363 |
if(iter != s_antiGroup.end()) { |
| 2364 |
const wxArrayString& arr = iter->second; |
| 2365 |
for(size_t i = 0; i < arr.GetCount(); ++i) { |
| 2366 |
EnableSizerFlag(arr.Item(i), false); // since it false, the recursion can not occur more than once |
| 2367 |
} |
| 2368 |
} |
| 2369 |
} |
| 2370 |
} |
| 2371 |
} |
| 2372 |
|
| 2373 |
int wxcWidget::SizerFakeValue(int realValue) |
| 2374 |
{ |
| 2375 |
if(s_sizerFlagsValue.count(realValue) == 0) { |
| 2376 |
return 0; |
| 2377 |
} |
| 2378 |
return s_sizerFlagsValue[realValue]; |
| 2379 |
} |
| 2380 |
|
| 2381 |
void wxcWidget::GenerateAdditionalFiles(wxStringMap_t& additionalFiles) const { wxUnusedVar(additionalFiles); } |
| 2382 |
|
| 2383 |
bool wxcWidget::IsAuiPane() const { return GetParent() && GetParent()->GetType() == ID_WXAUIMANAGER; } |
| 2384 |
|
| 2385 |
wxString wxcWidget::WrapInAuiPaneXRC(const wxString& objXRC) const { return m_auiPaneInfo.ToXRC(objXRC); } |
| 2386 |
|
| 2387 |
size_t wxcWidget::StyleFlagsAsInteger() const |
| 2388 |
{ |
| 2389 |
size_t flags = 0; |
| 2390 |
MapStyles_t::const_iterator iter = m_styles.begin(); |
| 2391 |
for(; iter != m_styles.end(); ++iter) { |
| 2392 |
if(iter->second.is_set) { |
| 2393 |
flags |= iter->second.style_bit; |
| 2394 |
} |
| 2395 |
} |
| 2396 |
return flags; |
| 2397 |
} |
| 2398 |
|
| 2399 |
int wxcWidget::PropertyInt(const wxString& propname, int defval) const |
| 2400 |
{ |
| 2401 |
if(m_properties.Contains(propname)) { |
| 2402 |
wxString value = m_properties.Item(propname)->GetValue(); |
| 2403 |
return wxCrafter::ToNumber(value, defval); |
| 2404 |
|
| 2405 |
} else { |
| 2406 |
return defval; |
| 2407 |
} |
| 2408 |
} |
| 2409 |
|
| 2410 |
bool wxcWidget::IsAuiManaged() const |
| 2411 |
{ |
| 2412 |
wxcWidget::List_t::const_iterator iter = m_children.begin(); |
| 2413 |
for(; iter != m_children.end(); ++iter) { |
| 2414 |
if((*iter)->GetType() == ID_WXAUIMANAGER) { |
| 2415 |
return true; |
| 2416 |
} |
| 2417 |
} |
| 2418 |
return false; |
| 2419 |
} |
| 2420 |
|
| 2421 |
void wxcWidget::DoGetCustomControlsName(const wxcWidget* widget, wxArrayString& controls) const |
| 2422 |
{ |
| 2423 |
if(widget->GetType() == ID_WXCUSTOMCONTROL) { |
| 2424 |
const CustomControlWrapper* cs = dynamic_cast<const CustomControlWrapper*>(widget); |
| 2425 |
if(cs) { |
| 2426 |
if(controls.Index(cs->GetTemplInfoName()) == wxNOT_FOUND) { |
| 2427 |
controls.Add(cs->GetTemplInfoName()); |
| 2428 |
} |
| 2429 |
} |
| 2430 |
} |
| 2431 |
|
| 2432 |
wxcWidget::List_t::const_iterator iter = widget->GetChildren().begin(); |
| 2433 |
for(; iter != widget->GetChildren().end(); ++iter) { |
| 2434 |
DoGetCustomControlsName(*iter, controls); |
| 2435 |
} |
| 2436 |
} |
| 2437 |
|
| 2438 |
void wxcWidget::GetCustomControlsName(wxArrayString& controls) const { DoGetCustomControlsName(this, controls); } |
| 2439 |
|
| 2440 |
wxString wxcWidget::GetRealClassName() const |
| 2441 |
{ |
| 2442 |
wxString subclass = PropertyString(PROP_SUBCLASS_NAME); |
| 2443 |
subclass.Trim().Trim(false); |
| 2444 |
|
| 2445 |
if(!subclass.IsEmpty()) { |
| 2446 |
return subclass; |
| 2447 |
} else { |
| 2448 |
return GetWxClassName(); |
| 2449 |
} |
| 2450 |
} |
| 2451 |
|
| 2452 |
bool wxcWidget::DoCheckNameUniqueness(const wxString& name, const wxcWidget* widget) const |
| 2453 |
{ |
| 2454 |
if(widget->GetRealName() == name) { |
| 2455 |
return false; |
| 2456 |
} |
| 2457 |
|
| 2458 |
const wxcWidget::List_t& children = widget->GetChildren(); |
| 2459 |
wxcWidget::List_t::const_iterator iter = children.begin(); |
| 2460 |
for(; iter != children.end(); ++iter) { |
| 2461 |
if(!DoCheckNameUniqueness(name, *iter)) { |
| 2462 |
return false; |
| 2463 |
} |
| 2464 |
} |
| 2465 |
return true; |
| 2466 |
} |
| 2467 |
|
| 2468 |
bool wxcWidget::IsNameUnique(const wxString& name) const { return DoCheckNameUniqueness(name, this); } |
| 2469 |
|
| 2470 |
wxcWidget* wxcWidget::Copy(enum DuplicatingOptions nametypesToChange, const std::set<wxString>& existingNames, |
| 2471 |
const wxString& chosenName, const wxString& chosenInheritedName, |
| 2472 |
const wxString& chosenFilename) const |
| 2473 |
{ |
| 2474 |
wxcWidget* widget = Clone(); |
| 2475 |
widget->DoDeepCopy(*this, nametypesToChange, existingNames, chosenName, chosenInheritedName, chosenFilename); |
| 2476 |
DoCopyChildren(widget, nametypesToChange, existingNames); |
| 2477 |
return widget; |
| 2478 |
} |
| 2479 |
|
| 2480 |
void wxcWidget::DoCopyChildren(wxcWidget* widget, enum DuplicatingOptions nametypesToChange, |
| 2481 |
const std::set<wxString>& existingNames) const |
| 2482 |
{ |
| 2483 |
List_t::const_iterator iter = m_children.begin(); |
| 2484 |
for(; iter != m_children.end(); ++iter) { |
| 2485 |
wxcWidget* child = (*iter)->Clone(); |
| 2486 |
child->DoDeepCopy(*(*iter), nametypesToChange, existingNames); |
| 2487 |
widget->AddChild(child); |
| 2488 |
if(!(*iter)->GetChildren().empty()) { |
| 2489 |
(*iter)->DoCopyChildren(child, nametypesToChange, existingNames); |
| 2490 |
} |
| 2491 |
} |
| 2492 |
} |
| 2493 |
|
| 2494 |
void wxcWidget::DoDeepCopy(const wxcWidget& rhs, enum DuplicatingOptions nametypesToChange, |
| 2495 |
const std::set<wxString>& existingNames, const wxString& chosenName, |
| 2496 |
const wxString& chosenInheritedName, const wxString& chosenFilename) |
| 2497 |
{ |
| 2498 |
MapProperties_t::const_iterator propIter = rhs.m_properties.begin(); |
| 2499 |
for(; propIter != rhs.m_properties.end(); ++propIter) { |
| 2500 |
if(this->m_properties.Contains(propIter->first)) { |
| 2501 |
|
| 2502 |
if(propIter->first == PROP_NAME) { |
| 2503 |
// The name should be different, unless we're just copying to the clipboard |
| 2504 |
// or (optionally) unless we're duplicating a TLW or pasting into a different TLW |
| 2505 |
wxString newname; |
| 2506 |
if(!chosenName.empty()) { // Always use any supplied name |
| 2507 |
newname = chosenName; |
| 2508 |
|
| 2509 |
} else { |
| 2510 |
newname << propIter->second->GetValue(); |
| 2511 |
if(IsTopWindow() || existingNames.count(newname) || |
| 2512 |
((nametypesToChange & DO_renameAllChildren) || |
| 2513 |
(nametypesToChange & DO_renameAllChildrenExceptUsernamed && wxIsdigit(newname.Last())))) { |
| 2514 |
newname << ++m_copyCounter; // Append a 'unique'ing number to the name e.g. foo12 -> foo1234 |
| 2515 |
} |
| 2516 |
} |
| 2517 |
|
| 2518 |
this->m_properties.Item(propIter->first)->SetValue(newname); |
| 2519 |
|
| 2520 |
} else if(propIter->first == PROP_FILE) { |
| 2521 |
|
| 2522 |
wxString filename; |
| 2523 |
if(!chosenFilename.empty()) { // Always use any supplied name |
| 2524 |
filename = chosenFilename; |
| 2525 |
} else { |
| 2526 |
filename << propIter->second->GetValue(); |
| 2527 |
|
| 2528 |
if(!filename.empty() && (nametypesToChange != DO_renameNone)) { |
| 2529 |
filename << ++m_copyCounter; |
| 2530 |
} |
| 2531 |
} |
| 2532 |
|
| 2533 |
// update the file name property |
| 2534 |
this->m_properties.Item(propIter->first)->SetValue(filename); |
| 2535 |
|
| 2536 |
} else if(propIter->first == PROP_INHERITED_CLASS) { |
| 2537 |
|
| 2538 |
wxString classname; |
| 2539 |
if(!chosenInheritedName.empty()) { // Always use any supplied name |
| 2540 |
classname = chosenInheritedName; |
| 2541 |
} else { |
| 2542 |
classname << propIter->second->GetValue(); |
| 2543 |
|
| 2544 |
if(!classname.empty() && (nametypesToChange != DO_renameNone)) { |
| 2545 |
// Don't increment here: it's sensible for classname to use the same suffix as filename |
| 2546 |
classname << m_copyCounter; |
| 2547 |
} |
| 2548 |
} |
| 2549 |
|
| 2550 |
this->m_properties.Item(propIter->first)->SetValue(classname); |
| 2551 |
|
| 2552 |
} else { |
| 2553 |
this->m_properties.Item(propIter->first)->SetValue(propIter->second->GetValue()); |
| 2554 |
} |
| 2555 |
} |
| 2556 |
} |
| 2557 |
|
| 2558 |
if(nametypesToChange & DO_copyEventsToo) { |
| 2559 |
// Doing a simple m_connectedEvents = rhs.m_connectedEvents (even using wxString::Clone) failed here as, |
| 2560 |
// strangely, if ConnectDetails::m_functionNameAndSignature |
| 2561 |
// of either duplicate was later changed, that change was shown in *both* controls in their EventsTableListView. |
| 2562 |
// The generated code was still correct, though :/ |
| 2563 |
MapEvents_t::const_iterator events_iter = rhs.m_connectedEvents.begin(); |
| 2564 |
for(; events_iter != rhs.m_connectedEvents.end(); ++events_iter) { |
| 2565 |
AddEvent(events_iter->second); |
| 2566 |
} |
| 2567 |
} |
| 2568 |
|
| 2569 |
MapStyles_t::const_iterator styleIter = rhs.m_styles.begin(); |
| 2570 |
for(; styleIter != rhs.m_styles.end(); ++styleIter) { |
| 2571 |
if(this->m_styles.Contains(styleIter->first)) { |
| 2572 |
this->m_styles.Item(styleIter->first) = styleIter->second; |
| 2573 |
} |
| 2574 |
} |
| 2575 |
|
| 2576 |
MapStyles_t::const_iterator sizerIter = rhs.m_sizerFlags.begin(); |
| 2577 |
for(; sizerIter != rhs.m_sizerFlags.end(); ++sizerIter) { |
| 2578 |
if(this->m_sizerFlags.Contains(sizerIter->first)) { |
| 2579 |
this->m_sizerFlags.Item(sizerIter->first) = sizerIter->second; |
| 2580 |
} |
| 2581 |
} |
| 2582 |
this->m_auiPaneInfo = rhs.m_auiPaneInfo; |
| 2583 |
this->m_sizerItem.SetProportion(rhs.m_sizerItem.GetProportion()); |
| 2584 |
this->m_sizerItem.SetBorder(rhs.m_sizerItem.GetBorder()); |
| 2585 |
this->m_gbPos = rhs.m_gbPos; |
| 2586 |
this->m_gbSpan = rhs.m_gbSpan; |
| 2587 |
} |
| 2588 |
|
| 2589 |
wxString wxcWidget::DoGenerateCppCtorCode_End() const { return ""; } |
| 2590 |
|
| 2591 |
wxString wxcWidget::GetId() const |
| 2592 |
{ |
| 2593 |
wxString winId = PropertyString(PROP_WINDOW_ID).Trim().Trim(false); |
| 2594 |
static wxRegEx reXrcId("XRCID *\\(\"[^\"]*\"\\)"); |
| 2595 |
|
| 2596 |
if(reXrcId.IsValid() && reXrcId.Matches(winId)) { |
| 2597 |
/// this window id already contains XRCID("..") wrapper |
| 2598 |
/// return it as it is |
| 2599 |
return winId; |
| 2600 |
} |
| 2601 |
|
| 2602 |
/// Not an XRCID string, check if it is one of the stock Id |
| 2603 |
if(WinIdProperty::m_winIdSet.count(winId)) { |
| 2604 |
return winId; |
| 2605 |
} |
| 2606 |
|
| 2607 |
/// Is it a number? |
| 2608 |
long nWinID = -1; |
| 2609 |
if(winId.ToCLong(&nWinID)) { |
| 2610 |
// a number |
| 2611 |
return winId; |
| 2612 |
} |
| 2613 |
|
| 2614 |
// A random string |
| 2615 |
wxcCodeGeneratorHelper::Get().AddWindowId(winId); |
| 2616 |
return winId; |
| 2617 |
} |
| 2618 |
|
| 2619 |
void wxcWidget::Reparent(wxcWidget* parent) |
| 2620 |
{ |
| 2621 |
// detach us from the old parent |
| 2622 |
if(GetParent()) { |
| 2623 |
GetParent()->RemoveChild(this); |
| 2624 |
} |
| 2625 |
|
| 2626 |
parent->AddChild(this); |
| 2627 |
} |
| 2628 |
|
| 2629 |
void wxcWidget::StoreNames(std::set<wxString>& store) |
| 2630 |
{ |
| 2631 |
store.insert(GetName()); |
| 2632 |
|
| 2633 |
List_t::iterator child_iter = m_children.begin(); |
| 2634 |
for(; child_iter != m_children.end(); child_iter++) { |
| 2635 |
(*child_iter)->StoreNames(store); |
| 2636 |
} |
| 2637 |
} |
| 2638 |
|
| 2639 |
bool wxcWidget::HasStyle(int styleBit) const |
| 2640 |
{ |
| 2641 |
MapStyles_t::ConstIterator iter = m_styles.Begin(); |
| 2642 |
for(; iter != m_styles.End(); ++iter) { |
| 2643 |
if(iter->second.style_bit == styleBit && iter->second.is_set) { |
| 2644 |
return true; |
| 2645 |
} |
| 2646 |
} |
| 2647 |
return false; |
| 2648 |
} |
| 2649 |
|
| 2650 |
void wxcWidget::WrapInIfBlockIfNeeded(wxString& code) const |
| 2651 |
{ |
| 2652 |
if(!GetCondname().IsEmpty()) { |
| 2653 |
wxCrafter::WrapInIfBlock(GetCondname(), code); |
| 2654 |
} |
| 2655 |
} |
| 2656 |
|
| 2657 |
void wxcWidget::SetIfBlockCond(const wxString& condname) |
| 2658 |
{ |
| 2659 |
m_condname = condname; |
| 2660 |
|
| 2661 |
// Set this condition to all this control events |
| 2662 |
EventsDatabase::MapEvents_t& events = m_controlEvents.GetEvents(); |
| 2663 |
EventsDatabase::MapEvents_t::Iterator iter = events.Begin(); |
| 2664 |
for(; iter != events.End(); ++iter) { |
| 2665 |
iter->second.SetIfBlock(m_condname); |
| 2666 |
} |
| 2667 |
} |
| 2668 |
|
| 2669 |
wxString wxcWidget::BaseDoGenerateClassMember() const |
| 2670 |
{ |
| 2671 |
wxString memberCode; |
| 2672 |
|
| 2673 |
if(KeepAsClassMember()) { |
| 2674 |
|
| 2675 |
// For subclasses controls we must use the subclass name |
| 2676 |
wxString classname = GetRealClassName(); |
| 2677 |
if(!IsTopWindow() && !classname.IsEmpty()) { |
| 2678 |
|
| 2679 |
memberCode << " " << classname << "* " << GetName() << ";"; |
| 2680 |
WrapInIfBlockIfNeeded(memberCode); |
| 2681 |
} |
| 2682 |
} |
| 2683 |
return memberCode; |
| 2684 |
} |
| 2685 |
|
| 2686 |
bool wxcWidget::IsParentAuiToolbar() const |
| 2687 |
{ |
| 2688 |
return GetParent() && |
| 2689 |
(GetParent()->GetType() == ID_WXAUITOOLBAR || GetParent()->GetType() == ID_WXAUITOOLBARTOPLEVEL); |
| 2690 |
} |
| 2691 |
|
| 2692 |
void wxcWidget::DoGenerateGetters(wxString& decl) const |
| 2693 |
{ |
| 2694 |
if(KeepAsClassMember()) { |
| 2695 |
switch(GetWidgetType()) { |
| 2696 |
case TYPE_CONTROL: |
| 2697 |
case TYPE_LIST_CTRL: |
| 2698 |
case TYPE_CONTAINER: |
| 2699 |
case TYPE_BOOK: |
| 2700 |
case TYPE_WIZARD_PAGE: |
| 2701 |
case TYPE_NOTEBOOK_PAGE: |
| 2702 |
case TYPE_SPLITTERWIN_PAGE: |
| 2703 |
case TYPE_SPLITTER_WINDOW: |
| 2704 |
case TYPE_MENUBAR: |
| 2705 |
case TYPE_TOOLBAR: |
| 2706 |
case TYPE_STATUSABR: |
| 2707 |
case TYPE_AUITOOLBAR: |
| 2708 |
case TYPE_DV_WITH_COLUMNS: |
| 2709 |
case TYPE_COLOLAPSIBLEPANE: |
| 2710 |
case TYPE_INFO_BAR: |
| 2711 |
case TYPE_AUI_MGR: |
| 2712 |
case TYPE_TIMER: |
| 2713 |
case TYPE_PG_MGR: |
| 2714 |
case TYPE_RIBBON_BAR: |
| 2715 |
case TYPE_GRID: |
| 2716 |
case TYPE_TREE_LIST_CTRL: |
| 2717 |
case TYPE_TASKBARICON: { |
| 2718 |
if(!IsTopWindow()) { |
| 2719 |
wxString code; |
| 2720 |
wxString memberName(GetName()); |
| 2721 |
|
| 2722 |
if(memberName.StartsWith("m_")) { |
| 2723 |
memberName.Remove(0, 2); |
| 2724 |
|
| 2725 |
} else if(memberName.StartsWith("_")) { |
| 2726 |
memberName.Remove(0, 1); |
| 2727 |
} |
| 2728 |
|
| 2729 |
wxString firstChar = memberName.Mid(0, 1); |
| 2730 |
firstChar.MakeUpper(); |
| 2731 |
memberName.replace(0, 1, firstChar); |
| 2732 |
|
| 2733 |
code << " " << GetRealClassName() << "* Get" << memberName << "() { return " << GetName() << "; }\n"; |
| 2734 |
decl << code; |
| 2735 |
} |
| 2736 |
} break; |
| 2737 |
default: |
| 2738 |
break; |
| 2739 |
} |
| 2740 |
} |
| 2741 |
} |
| 2742 |
|
| 2743 |
wxString wxcSizerItem::GetBorderScaled() const { return wxString() << "WXC_FROM_DIP(" << GetBorder() << ")"; } |