| 1 |
#include "tool_bar_item_wrapper.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "choice_property.h" |
| 4 |
#include "event_notifier.h" |
| 5 |
#include "file_ficker_property.h" |
| 6 |
#include "import_from_wxFB.h" |
| 7 |
#include "import_from_xrc.h" |
| 8 |
#include "menu_item_wrapper.h" |
| 9 |
#include "menu_wrapper.h" |
| 10 |
#include "multi_strings_property.h" |
| 11 |
#include "winid_property.h" |
| 12 |
#include "wxc_bitmap_code_generator.h" |
| 13 |
#include "wxgui_bitmaploader.h" |
| 14 |
#include "wxgui_helpers.h" |
| 15 |
#include "xmlutils.h" |
| 16 |
#include <wx/aui/auibar.h> |
| 17 |
|
| 18 |
wxDECLARE_EVENT(wxEVT_EVENTS_PROPERTIES_UPDATED, wxCommandEvent); |
| 19 |
|
| 20 |
ToolBarItemWrapper::ToolBarItemWrapper(int type) |
| 21 |
: wxcWidget(type) |
| 22 |
{ |
| 23 |
// id, label, bitmap, kind, tooltip, help string |
| 24 |
RegisterEventCommand(wxT("wxEVT_COMMAND_TOOL_CLICKED"), |
| 25 |
_("Process a wxEVT_COMMAND_TOOL_CLICKED event (a synonym for wxEVT_COMMAND_MENU_SELECTED). " |
| 26 |
"Pass the id of the tool")); |
| 27 |
RegisterEventCommand(wxT("wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED"), |
| 28 |
_("Process a wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED event")); |
| 29 |
|
| 30 |
m_styles.Clear(); |
| 31 |
m_sizerFlags.Clear(); |
| 32 |
m_properties.DeleteValues(); |
| 33 |
|
| 34 |
wxCrafter::ResourceLoader bmps; |
| 35 |
AddProperty(new CategoryProperty(_("Common Settings"), "wxToolBarItem")); |
| 36 |
AddProperty(new WinIdProperty()); |
| 37 |
AddProperty(new StringProperty(PROP_NAME, "", _("C++ variable name"))); |
| 38 |
|
| 39 |
AddProperty(new CategoryProperty(_("ToolBar Item"))); |
| 40 |
AddProperty(new StringProperty(PROP_LABEL, _("Tool Label"), _("The tool label"))); |
| 41 |
AddProperty(new MultiStringsProperty(PROP_TOOLTIP, _("Tooltip"), wxT("\\n"), |
| 42 |
_("Short help string. This will appear as the tool's tooltip"))); |
| 43 |
AddProperty(new StringProperty(PROP_HELP, "", _("Long help string. This will be displayed in the statusbar"))); |
| 44 |
AddProperty( |
| 45 |
new BitmapPickerProperty(PROP_BITMAP_PATH, bmps.GetPlaceHolder16ImagePath().GetFullPath(), _("Bitmap"))); |
| 46 |
AddProperty(new FilePickerProperty(PROP_DISABLED_BITMAP_PATH, "", _("Disabled bitmap"))); |
| 47 |
AddProperty(new ChoiceProperty(PROP_KIND, wxCrafter::GetToolTypes(true), 0, _("The tool kind"))); |
| 48 |
AddProperty( |
| 49 |
new BoolProperty(PROP_DROPDOWN_MENU, true, _("Use wxCrafter to construct the menu called by the dropdown"))); |
| 50 |
|
| 51 |
m_namePattern = wxT("m_toolbarItem"); |
| 52 |
SetName(GenerateName()); |
| 53 |
} |
| 54 |
|
| 55 |
ToolBarItemWrapper::~ToolBarItemWrapper() {} |
| 56 |
|
| 57 |
wxcWidget* ToolBarItemWrapper::Clone() const { return new ToolBarItemWrapper(); } |
| 58 |
|
| 59 |
static wxString GenerateCppCtorCodeRecursively(wxcWidget* widget) // Helper function for CppCtorCode() dropdown menus |
| 60 |
{ |
| 61 |
wxString code; |
| 62 |
if(wxCrafter::GetToolType(widget->PropertyString(PROP_KIND)) == wxCrafter::TOOL_TYPE_SEPARATOR) { |
| 63 |
code << widget->CppCtorCode(); |
| 64 |
} else { |
| 65 |
wxString childcode = widget->CppCtorCode(); |
| 66 |
code << childcode; |
| 67 |
} |
| 68 |
wxcWidget::List_t::const_iterator iter = widget->GetChildren().begin(); |
| 69 |
for(; iter != widget->GetChildren().end(); ++iter) { |
| 70 |
if(wxCrafter::GetToolType((*iter)->PropertyString(PROP_KIND)) != wxCrafter::TOOL_TYPE_SEPARATOR) { |
| 71 |
wxString childcode = (*iter)->CppCtorCode(); |
| 72 |
code << childcode; |
| 73 |
} |
| 74 |
wxcWidget::List_t::const_iterator childiter = (*iter)->GetChildren().begin(); |
| 75 |
for(; childiter != (*iter)->GetChildren().end(); ++childiter) { |
| 76 |
code << GenerateCppCtorCodeRecursively(*childiter); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
return code; |
| 81 |
} |
| 82 |
|
| 83 |
wxString ToolBarItemWrapper::CppCtorCode() const |
| 84 |
{ |
| 85 |
wxString code; |
| 86 |
wxcCodeGeneratorHelper::Get().AddBitmap(PropertyFile(PROP_BITMAP_PATH)); |
| 87 |
wxcCodeGeneratorHelper::Get().AddBitmap(PropertyFile(PROP_DISABLED_BITMAP_PATH)); |
| 88 |
|
| 89 |
bool isAuiItem = IsParentAuiToolbar(); |
| 90 |
wxCrafter::TOOL_TYPE toolType = wxCrafter::GetToolType(PropertyString(PROP_KIND)); |
| 91 |
wxCrafter::TOOL_TYPE realToolType = toolType; |
| 92 |
|
| 93 |
if(isAuiItem && toolType == wxCrafter::TOOL_TYPE_DROPDOWN) { |
| 94 |
/// wxAuiTooBar does not support wxITEM_DROPDOWN |
| 95 |
/// convert the type to wxITEM_NORMAL |
| 96 |
toolType = wxCrafter::TOOL_TYPE_NORMAL; |
| 97 |
} |
| 98 |
|
| 99 |
wxString functionArgs; |
| 100 |
wxString disabledBmp = wxcCodeGeneratorHelper::Get().BitmapCode(PropertyFile(PROP_DISABLED_BITMAP_PATH)); |
| 101 |
functionArgs << WindowID() << wxT(", ") << CPPLabel() << wxT(", ") |
| 102 |
<< wxcCodeGeneratorHelper::Get().BitmapCode(PropertyFile(PROP_BITMAP_PATH)) << wxT(", ") << disabledBmp |
| 103 |
<< ", " << wxCrafter::ToolTypeToWX(toolType) << ", " |
| 104 |
<< wxString(wxCrafter::UNDERSCORE(PropertyString(PROP_TOOLTIP))) << wxT(", ") |
| 105 |
<< wxString(wxCrafter::UNDERSCORE(PropertyString(PROP_HELP))) << wxT(", ") << "NULL"; |
| 106 |
|
| 107 |
wxString functionName = wxT("AddTool"); |
| 108 |
|
| 109 |
switch(toolType) { |
| 110 |
case wxCrafter::TOOL_TYPE_SEPARATOR: |
| 111 |
functionName = wxT("AddSeparator"); |
| 112 |
functionArgs.Clear(); |
| 113 |
break; |
| 114 |
|
| 115 |
default: |
| 116 |
case wxCrafter::TOOL_TYPE_NORMAL: |
| 117 |
case wxCrafter::TOOL_TYPE_RADIO: |
| 118 |
case wxCrafter::TOOL_TYPE_CHECK: |
| 119 |
case wxCrafter::TOOL_TYPE_DROPDOWN: |
| 120 |
functionName = wxT("AddTool"); |
| 121 |
break; |
| 122 |
} |
| 123 |
|
| 124 |
code << GetWindowParent() << "->" << functionName << wxT("(") << functionArgs << wxT(");\n"); |
| 125 |
if(realToolType == wxCrafter::TOOL_TYPE_DROPDOWN && isAuiItem) { |
| 126 |
// wxAuiToolBarItem* AddTool(...) is >= wx3.0, so we have to locate the new tool ourselves |
| 127 |
code << "wxAuiToolBarItem* " << GetName() << " = " << GetWindowParent() << "->FindToolByIndex(" |
| 128 |
<< GetWindowParent() << "->GetToolCount()-1);\n"; |
| 129 |
code << "if (" << GetName() << ") {\n"; |
| 130 |
code << " " << GetName() << "->SetHasDropDown(true);\n"; |
| 131 |
if(HasDefaultDropdown()) { |
| 132 |
wxcWidget* menu = GetChildren().front(); |
| 133 |
wxASSERT(menu && menu->GetType() == ID_WXMENU); |
| 134 |
if(menu && menu->GetType() == ID_WXMENU) { |
| 135 |
wxString menuname = menu->GetName(); |
| 136 |
code << " " << menuname << " = new wxMenu;\n"; |
| 137 |
if(menu && menu->GetType() == ID_WXMENU) { |
| 138 |
// Add each of the wxcWidget menu's children to the generated menu |
| 139 |
wxcWidget* me = menu->GetParent(); |
| 140 |
menu->SetParent(NULL); // Allow menu code to be emitted here; there's code to prevent this if the |
| 141 |
// parent's a dropdown |
| 142 |
wxString menucode; |
| 143 |
wxcWidget::List_t::const_iterator iter = menu->GetChildren().begin(); |
| 144 |
for(; iter != menu->GetChildren().end(); ++iter) { |
| 145 |
wxString childmenucode = |
| 146 |
GenerateCppCtorCodeRecursively(*iter); // Must be recursive here; submenus can nest |
| 147 |
childmenucode.Replace("\n", "\n "); |
| 148 |
menucode << childmenucode; |
| 149 |
} |
| 150 |
code << " " << menucode; |
| 151 |
menu->SetParent(me); |
| 152 |
} |
| 153 |
code << "\n m_dropdownMenus.insert(std::make_pair( " << GetName() |
| 154 |
<< wxT("->GetId(), " << menuname << ") );\n"); |
| 155 |
} |
| 156 |
} |
| 157 |
code << "}\n"; |
| 158 |
} |
| 159 |
|
| 160 |
return code; |
| 161 |
} |
| 162 |
|
| 163 |
void ToolBarItemWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/toolbar.h>")); } |
| 164 |
|
| 165 |
wxString ToolBarItemWrapper::GetWxClassName() const { return wxT(""); } |
| 166 |
|
| 167 |
void ToolBarItemWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 168 |
{ |
| 169 |
wxCrafter::TOOL_TYPE toolType = wxCrafter::GetToolType(PropertyString(PROP_KIND)); |
| 170 |
wxString tip = PropertyString(PROP_TOOLTIP); |
| 171 |
wxString help = PropertyString(PROP_HELP); |
| 172 |
|
| 173 |
if(toolType == wxCrafter::TOOL_TYPE_SEPARATOR) { |
| 174 |
text << wxT("<object class=\"separator\"/>"); |
| 175 |
|
| 176 |
} else if(toolType == wxCrafter::TOOL_TYPE_SPACE) { |
| 177 |
text << wxT("<object class=\"space\"/>"); |
| 178 |
|
| 179 |
} else { |
| 180 |
text << wxT("<object class=\"tool\" name=\"") << GetName() << wxT("\">"); |
| 181 |
|
| 182 |
if(toolType == wxCrafter::TOOL_TYPE_CHECK) { |
| 183 |
text << wxT("<toggle>1</toggle>"); |
| 184 |
|
| 185 |
} else if(toolType == wxCrafter::TOOL_TYPE_RADIO) { |
| 186 |
text << wxT("<radio>1</radio>"); |
| 187 |
|
| 188 |
} else if(toolType == wxCrafter::TOOL_TYPE_DROPDOWN) { |
| 189 |
text << "<dropdown>"; |
| 190 |
if(IsParentAuiToolbar()) { ChildrenXRC(text, type); } |
| 191 |
text << "</dropdown>"; |
| 192 |
} |
| 193 |
|
| 194 |
text << XRCLabel(); |
| 195 |
if(!tip.empty()) { text << wxT("<tooltip>") << wxCrafter::CDATA(tip) << wxT("</tooltip>"); } |
| 196 |
text << wxT("<longhelp>") << wxCrafter::CDATA(help) << wxT("</longhelp>"); |
| 197 |
text << XRCBitmap(); |
| 198 |
text << wxT("</object>"); |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
void ToolBarItemWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 203 |
{ |
| 204 |
// First call the base-class for the standard things |
| 205 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 206 |
|
| 207 |
// Next cope with separators. This will be a toolbaritem, but we must set its type |
| 208 |
wxString classname = XmlUtils::ReadString(node, wxT("class")); |
| 209 |
if(classname == "separator") { |
| 210 |
SetPropertyString(PROP_KIND, ITEM_SEPARATOR); |
| 211 |
return; // Nothing else needed for a separator |
| 212 |
} |
| 213 |
|
| 214 |
if(classname == "space") { |
| 215 |
SetPropertyString(PROP_KIND, ITEM_SPACE); |
| 216 |
|
| 217 |
// 'space' plus 'width' means an auitoolbar non-stretch spacer |
| 218 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, "width"); |
| 219 |
if(propertynode) { |
| 220 |
SetPropertyString(PROP_WIDTH, propertynode->GetNodeContent()); |
| 221 |
|
| 222 |
} else { |
| 223 |
// 'space' without 'width' must be a stretchspacer. The default proportion is 1, however an auitoolbar might |
| 224 |
// specify a different one |
| 225 |
wxString ppn = "1"; |
| 226 |
propertynode = XmlUtils::FindFirstByTagName(node, "proportion"); |
| 227 |
if(propertynode) { ppn = propertynode->GetNodeContent(); } |
| 228 |
SetPropertyString(PROP_PROPORTION, ppn); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("toggle")); |
| 233 |
if(propertynode && propertynode->GetNodeContent() == "1") { SetPropertyString(PROP_KIND, ITEM_CHECK); } |
| 234 |
|
| 235 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("radio")); |
| 236 |
if(propertynode && propertynode->GetNodeContent() == "1") { SetPropertyString(PROP_KIND, ITEM_RADIO); } |
| 237 |
|
| 238 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("hasdropdown")); // The previous way |
| 239 |
if(propertynode && propertynode->GetNodeContent() == "1") { SetPropertyString(PROP_KIND, ITEM_DROPDOWN); } |
| 240 |
|
| 241 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("dropdown")); |
| 242 |
if(propertynode) { |
| 243 |
SetPropertyString(PROP_KIND, ITEM_DROPDOWN); |
| 244 |
ImportFromXrc imp(NULL); |
| 245 |
imp.ProcessNamedNode(propertynode, this, "wxMenu"); // This should load any contained dropdown menu |
| 246 |
|
| 247 |
UpdateRegisteredEventsIfNeeded(); |
| 248 |
} |
| 249 |
|
| 250 |
propertynode = XmlUtils::FindFirstByTagName(node, "bitmap"); |
| 251 |
if(propertynode) { ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_BITMAP_PATH, "wxART_TOOLBAR"); } |
| 252 |
|
| 253 |
propertynode = XmlUtils::FindFirstByTagName(node, "bitmap2"); |
| 254 |
if(propertynode) { |
| 255 |
ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_DISABLED_BITMAP_PATH, "wxART_TOOLBAR"); |
| 256 |
} |
| 257 |
|
| 258 |
propertynode = XmlUtils::FindFirstByTagName(node, "longhelp"); |
| 259 |
if(propertynode) { SetPropertyString(PROP_HELP, propertynode->GetNodeContent()); } |
| 260 |
} |
| 261 |
|
| 262 |
void ToolBarItemWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 263 |
{ |
| 264 |
// First call the base-class for the standard things |
| 265 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 266 |
|
| 267 |
// Next cope with separators. This will be a toolbaritem, but we must set its type |
| 268 |
wxString classname = XmlUtils::ReadString(node, wxT("class")); |
| 269 |
if(classname == "separator") { |
| 270 |
SetPropertyString(PROP_KIND, ITEM_SEPARATOR); |
| 271 |
return; // Nothing else needed for a separator |
| 272 |
} |
| 273 |
|
| 274 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("check")); // Not 'toggle' |
| 275 |
if(propertynode && propertynode->GetNodeContent() == "1") { SetPropertyString(PROP_KIND, ITEM_CHECK); } |
| 276 |
|
| 277 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("radio")); |
| 278 |
if(propertynode && propertynode->GetNodeContent() == "1") { SetPropertyString(PROP_KIND, ITEM_RADIO); } |
| 279 |
|
| 280 |
propertynode = XmlUtils::FindFirstByTagName(node, "bitmap"); |
| 281 |
if(propertynode) { ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_BITMAP_PATH, "wxART_TOOLBAR"); } |
| 282 |
|
| 283 |
propertynode = XmlUtils::FindFirstByTagName(node, "bitmap2"); |
| 284 |
if(propertynode) { |
| 285 |
ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_DISABLED_BITMAP_PATH, "wxART_TOOLBAR"); |
| 286 |
} |
| 287 |
|
| 288 |
propertynode = XmlUtils::FindFirstByTagName(node, "longhelp"); |
| 289 |
if(propertynode) { SetPropertyString(PROP_HELP, propertynode->GetNodeContent()); } |
| 290 |
} |
| 291 |
|
| 292 |
void ToolBarItemWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 293 |
{ |
| 294 |
// First call the base-class for the standard things |
| 295 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 296 |
|
| 297 |
// Next cope with separators. This will be a toolbaritem, but we must set its type |
| 298 |
wxString classname = XmlUtils::ReadString(node, wxT("class")); |
| 299 |
if(classname == "toolSeparator") { |
| 300 |
SetPropertyString(PROP_KIND, ITEM_SEPARATOR); |
| 301 |
return; // Nothing else needed for a separator |
| 302 |
} |
| 303 |
|
| 304 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "kind"); |
| 305 |
if(propertynode) { SetPropertyString(PROP_KIND, propertynode->GetNodeContent()); } |
| 306 |
|
| 307 |
propertynode = XmlUtils::FindNodeByName(node, "property", "bitmap"); |
| 308 |
if(propertynode) { |
| 309 |
ImportFromwxFB::ProcessBitmapProperty(propertynode->GetNodeContent(), this, PROP_BITMAP_PATH, "wxART_TOOLBAR"); |
| 310 |
} |
| 311 |
|
| 312 |
propertynode = XmlUtils::FindNodeByName(node, "property", "statusbar"); // Yes, 'statusbar' is wxFB's 'help' label |
| 313 |
if(propertynode) { SetPropertyString(PROP_HELP, propertynode->GetNodeContent()); } |
| 314 |
} |
| 315 |
|
| 316 |
void ToolBarItemWrapper::OnPropertiesUpdated() |
| 317 |
{ |
| 318 |
if(IsParentAuiToolbar()) { |
| 319 |
if(wxCrafter::GetToolType(PropertyString(PROP_KIND)) == wxCrafter::TOOL_TYPE_DROPDOWN) { |
| 320 |
// If this was a change of type to a dropdown, we need to delete any stale connected event (which will have |
| 321 |
// the wrong signature) |
| 322 |
if(GetChildren().empty()) { RemoveEvent("wxEVT_COMMAND_TOOL_CLICKED"); } |
| 323 |
} else { |
| 324 |
// If this was a change of type from a dropdown, we again need to delete any stale connected event |
| 325 |
if(!GetChildren().empty()) { RemoveEvent("wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN"); } |
| 326 |
} |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
void ToolBarItemWrapper::UpdateRegisteredEventsIfNeeded() |
| 331 |
{ |
| 332 |
bool isAuiItem = IsParentAuiToolbar(); |
| 333 |
wxCrafter::TOOL_TYPE toolType = wxCrafter::GetToolType(PropertyString(PROP_KIND)); |
| 334 |
|
| 335 |
if(isAuiItem && toolType == wxCrafter::TOOL_TYPE_DROPDOWN) { |
| 336 |
// A wxAuiItem AND a dropdown menu item -> show only wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN |
| 337 |
m_controlEvents.Clear(); |
| 338 |
RegisterEvent(wxT("wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN"), "wxAuiToolBarEvent", |
| 339 |
_("Process a wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN event")); |
| 340 |
|
| 341 |
} else if(isAuiItem) { |
| 342 |
/// Not a dropdown but a wxAuiItem - show only 'Click' event |
| 343 |
m_controlEvents.Clear(); |
| 344 |
RegisterEventCommand(wxT("wxEVT_COMMAND_TOOL_CLICKED"), |
| 345 |
_("Process a wxEVT_COMMAND_TOOL_CLICKED event (a synonym for " |
| 346 |
"wxEVT_COMMAND_MENU_SELECTED). Pass the id of the tool")); |
| 347 |
|
| 348 |
} else if(!isAuiItem && !(toolType == wxCrafter::TOOL_TYPE_DROPDOWN)) { |
| 349 |
/// Not a dropdown nor wxAuiItem - show only 'Click' event |
| 350 |
m_controlEvents.Clear(); |
| 351 |
RegisterEventCommand(wxT("wxEVT_COMMAND_TOOL_CLICKED"), |
| 352 |
_("Process a wxEVT_COMMAND_TOOL_CLICKED event (a synonym for " |
| 353 |
"wxEVT_COMMAND_MENU_SELECTED). Pass the id of the tool")); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
bool ToolBarItemWrapper::HasDefaultDropdown() const |
| 358 |
{ |
| 359 |
wxCrafter::TOOL_TYPE toolType = wxCrafter::GetToolType(PropertyString(PROP_KIND)); |
| 360 |
return (toolType == wxCrafter::TOOL_TYPE_DROPDOWN) && !m_children.empty(); |
| 361 |
} |
| 362 |
|
| 363 |
// ------------------------------------------- |
| 364 |
// Separator item |
| 365 |
// ------------------------------------------- |
| 366 |
|
| 367 |
ToolBarItemSeparatorWrapper::ToolBarItemSeparatorWrapper() |
| 368 |
: ToolBarItemWrapper(ID_WXTOOLBARITEM_SEPARATOR) |
| 369 |
{ |
| 370 |
m_properties.DeleteValues(); |
| 371 |
m_sizerFlags.Clear(); |
| 372 |
|
| 373 |
wxArrayString kinds; |
| 374 |
kinds.Add(ITEM_SEPARATOR); |
| 375 |
|
| 376 |
AddCategory(_("ToolBar Item Separator")); |
| 377 |
AddProperty(new StringProperty(PROP_NAME, "", "Name")); |
| 378 |
AddProperty(new ChoiceProperty(PROP_KIND, kinds, 0, _("The tool kind"))); |
| 379 |
|
| 380 |
m_namePattern = "m_tbSeparator"; |
| 381 |
SetName(GenerateName()); |
| 382 |
} |
| 383 |
|
| 384 |
ToolBarItemSeparatorWrapper::~ToolBarItemSeparatorWrapper() {} |
| 385 |
|
| 386 |
wxString ToolBarItemSeparatorWrapper::CppCtorCode() const |
| 387 |
{ |
| 388 |
return wxString() << GetWindowParent() << "->AddSeparator();\n"; |
| 389 |
} |
| 390 |
|
| 391 |
// ------------------------------------------- |
| 392 |
// StretchSpace item |
| 393 |
// ------------------------------------------- |
| 394 |
|
| 395 |
ToolBarItemSpaceWrapper::ToolBarItemSpaceWrapper() |
| 396 |
: ToolBarItemWrapper(ID_WXTOOLBARITEM_STRETCHSPACE) |
| 397 |
{ |
| 398 |
m_properties.DeleteValues(); |
| 399 |
m_sizerFlags.Clear(); |
| 400 |
|
| 401 |
wxArrayString kinds; |
| 402 |
kinds.Add(ITEM_SPACE); |
| 403 |
|
| 404 |
AddCategory(_("ToolBar Item Space")); |
| 405 |
AddProperty(new StringProperty(PROP_NAME, "", "Name")); |
| 406 |
AddProperty(new ChoiceProperty(PROP_KIND, kinds, 0, _("The tool kind"))); |
| 407 |
|
| 408 |
m_namePattern = "m_toolbarSpacer"; |
| 409 |
SetName(GenerateName()); |
| 410 |
} |
| 411 |
|
| 412 |
wxString ToolBarItemSpaceWrapper::CppCtorCode() const |
| 413 |
{ |
| 414 |
return wxString() << GetWindowParent() << "->AddStretchableSpace();\n"; |
| 415 |
} |
| 416 |
|
| 417 |
// ------------------------------------------- |
| 418 |
// AuiNonStretchSpace item |
| 419 |
// ------------------------------------------- |
| 420 |
|
| 421 |
AuiToolBarItemNonStretchSpaceWrapper::AuiToolBarItemNonStretchSpaceWrapper() |
| 422 |
: ToolBarItemWrapper(ID_WXAUITOOLBARITEM_SPACE) |
| 423 |
{ |
| 424 |
m_properties.DeleteValues(); |
| 425 |
m_sizerFlags.Clear(); |
| 426 |
|
| 427 |
AddCategory(_("AuiToolBar Item Space")); |
| 428 |
AddProperty(new StringProperty(PROP_NAME, "", "Name")); |
| 429 |
AddProperty(new StringProperty(PROP_WIDTH, "0", _("The width of the space in pixels"))); |
| 430 |
|
| 431 |
m_namePattern = "m_auitbarNonstretchSpace"; |
| 432 |
SetName(GenerateName()); |
| 433 |
} |
| 434 |
|
| 435 |
wxString AuiToolBarItemNonStretchSpaceWrapper::CppCtorCode() const |
| 436 |
{ |
| 437 |
return wxString() << GetWindowParent() << "->AddSpacer(" << wxString(PropertyString(PROP_WIDTH)) << ");\n"; |
| 438 |
} |
| 439 |
|
| 440 |
void AuiToolBarItemNonStretchSpaceWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 441 |
{ |
| 442 |
text << wxT("<object class=\"space\" name=\"") << GetName() << wxT("\">") << wxT("<width>") |
| 443 |
<< PropertyString(PROP_WIDTH) << wxT("</width>") << wxT("</object>"); |
| 444 |
} |
| 445 |
|
| 446 |
// ------------------------------------------- |
| 447 |
// AuiStretchSpace item (which has a 'proportion' parameter that's missing in the wxToolBar equivalent) |
| 448 |
// ------------------------------------------- |
| 449 |
|
| 450 |
AuiToolBarItemSpaceWrapper::AuiToolBarItemSpaceWrapper() |
| 451 |
: ToolBarItemWrapper(ID_WXAUITOOLBARITEM_STRETCHSPACE) |
| 452 |
{ |
| 453 |
m_properties.DeleteValues(); |
| 454 |
m_sizerFlags.Clear(); |
| 455 |
|
| 456 |
AddCategory(_("ToolBar Item Space")); |
| 457 |
AddProperty(new StringProperty(PROP_NAME, "", "Name")); |
| 458 |
AddProperty(new StringProperty(PROP_PROPORTION, "1", _("How stretchable the space is. The normal value is 1."))); |
| 459 |
|
| 460 |
m_namePattern = "m_auitbarStretchSpace"; |
| 461 |
SetName(GenerateName()); |
| 462 |
} |
| 463 |
|
| 464 |
wxString AuiToolBarItemSpaceWrapper::CppCtorCode() const |
| 465 |
{ |
| 466 |
return wxString() << GetWindowParent() << "->AddStretchSpacer(" << PropertyString(PROP_PROPORTION) << ");\n"; |
| 467 |
} |
| 468 |
|
| 469 |
void AuiToolBarItemSpaceWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 470 |
{ |
| 471 |
text << wxT("<object class=\"space\" name=\"") << GetName() << wxT("\">") << wxT("<proportion>") |
| 472 |
<< PropertyString(PROP_PROPORTION) << wxT("</proportion>") << wxT("</object>"); |
| 473 |
} |
| 474 |
// ------------------------------------------- |
| 475 |
// AuiLabel item |
| 476 |
// ------------------------------------------- |
| 477 |
|
| 478 |
AuiToolBarLabelWrapper::AuiToolBarLabelWrapper(int type) |
| 479 |
: wxcWidget(type) |
| 480 |
{ |
| 481 |
m_styles.Clear(); |
| 482 |
m_sizerFlags.Clear(); |
| 483 |
m_properties.DeleteValues(); |
| 484 |
|
| 485 |
wxCrafter::ResourceLoader bmps; |
| 486 |
AddProperty(new CategoryProperty(_("wxAuiToolBar Label"))); |
| 487 |
AddProperty(new WinIdProperty()); |
| 488 |
AddProperty(new StringProperty(PROP_NAME, "", _("C++ variable name"))); |
| 489 |
AddProperty(new StringProperty(PROP_LABEL, _("My toolbar label"), _("The label's text"))); |
| 490 |
AddProperty(new StringProperty(PROP_WIDTH, "-1", _("Optionally, specify the label's width"))); |
| 491 |
|
| 492 |
m_namePattern = wxT("m_auitbarLabel"); |
| 493 |
SetName(GenerateName()); |
| 494 |
} |
| 495 |
|
| 496 |
wxcWidget* AuiToolBarLabelWrapper::Clone() const { return new AuiToolBarLabelWrapper(); } |
| 497 |
|
| 498 |
wxString AuiToolBarLabelWrapper::CppCtorCode() const |
| 499 |
{ |
| 500 |
wxString code; |
| 501 |
|
| 502 |
wxString functionArgs; |
| 503 |
functionArgs << WindowID() << wxT(", ") << CPPLabel() << wxT(", ") << wxString(PropertyString(PROP_WIDTH)); |
| 504 |
wxString functionName = "AddLabel"; |
| 505 |
code << GetWindowParent() << "->" << functionName << "(" << functionArgs << ");\n"; |
| 506 |
return code; |
| 507 |
} |
| 508 |
|
| 509 |
void AuiToolBarLabelWrapper::GetIncludeFile(wxArrayString& headers) const |
| 510 |
{ |
| 511 |
headers.Add(wxT("#include <wx/toolbar.h>")); |
| 512 |
} |
| 513 |
|
| 514 |
wxString AuiToolBarLabelWrapper::GetWxClassName() const { return wxT(""); } |
| 515 |
|
| 516 |
void AuiToolBarLabelWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 517 |
{ |
| 518 |
text << wxT("<object class=\"label\" name=\"") << GetName() << wxT("\">") << XRCLabel() << wxT("<width>") |
| 519 |
<< PropertyString(PROP_WIDTH) << wxT("</width>") << wxT("</object>"); |
| 520 |
} |
| 521 |
|
| 522 |
void AuiToolBarLabelWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 523 |
{ |
| 524 |
// First call the base-class for the standard things |
| 525 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 526 |
|
| 527 |
wxString classname = XmlUtils::ReadString(node, wxT("class")); |
| 528 |
if(classname == "label") { |
| 529 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, "width"); |
| 530 |
if(propertynode) { SetPropertyString(PROP_WIDTH, propertynode->GetNodeContent()); } |
| 531 |
} |
| 532 |
} |