| 1 |
#include "ribbon_button.h" |
| 2 |
|
| 3 |
#include "allocator_mgr.h" |
| 4 |
#include "choice_property.h" |
| 5 |
#include "file_ficker_property.h" |
| 6 |
#include "wxc_bitmap_code_generator.h" |
| 7 |
#include "wxgui_bitmaploader.h" |
| 8 |
#include "wxgui_helpers.h" |
| 9 |
|
| 10 |
RibbonButtonBase::RibbonButtonBase(int type) |
| 11 |
: wxcWidget(type) |
| 12 |
{ |
| 13 |
wxArrayString kind; |
| 14 |
kind.Add("wxRIBBON_BUTTON_NORMAL"); |
| 15 |
kind.Add("wxRIBBON_BUTTON_DROPDOWN"); |
| 16 |
kind.Add("wxRIBBON_BUTTON_HYBRID"); |
| 17 |
kind.Add("wxRIBBON_BUTTON_TOGGLE"); |
| 18 |
|
| 19 |
m_isButtonBar = !(type == ID_WXRIBBONTOOL || type == ID_WXRIBBONDROPDOWNTOOL || type == ID_WXRIBBONHYBRIDTOOL || |
| 20 |
type == ID_WXRIBBONTOGGLETOOL); |
| 21 |
|
| 22 |
int selection = 0; |
| 23 |
if(type == ID_WXRIBBONBUTTON || type == ID_WXRIBBONTOOL) { |
| 24 |
selection = 0; |
| 25 |
} else if(type == ID_WXRIBBONDROPDOWNBUTTON || type == ID_WXRIBBONDROPDOWNTOOL) { |
| 26 |
selection = 1; |
| 27 |
} else if(type == ID_WXRIBBONHYBRIDBUTTON || type == ID_WXRIBBONHYBRIDTOOL) { |
| 28 |
selection = 2; |
| 29 |
} else if(type == ID_WXRIBBONTOGGLEBUTTON || type == ID_WXRIBBONTOGGLETOOL) { |
| 30 |
selection = 3; |
| 31 |
} |
| 32 |
|
| 33 |
AddProperty(new StringProperty(PROP_LABEL, _("Button"), _("The button label"))); |
| 34 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH, "", _("Select the bitmap file"))); |
| 35 |
AddProperty(new StringProperty(PROP_HELP, "Help String", _("Help string"))); |
| 36 |
AddProperty(new ChoiceProperty(PROP_KIND, kind, selection, _("The button type"))); |
| 37 |
|
| 38 |
wxCrafter::ResourceLoader bl; |
| 39 |
if(m_isButtonBar) { |
| 40 |
m_properties.Item(PROP_BITMAP_PATH)->SetValue(bl.GetPlaceHolderImagePath().GetFullPath()); |
| 41 |
|
| 42 |
} else { |
| 43 |
m_properties.Item(PROP_BITMAP_PATH)->SetValue(bl.GetPlaceHolder16ImagePath().GetFullPath()); |
| 44 |
} |
| 45 |
|
| 46 |
if(m_isButtonBar) { |
| 47 |
RegisterEvent("wxEVT_COMMAND_RIBBONBUTTON_CLICKED", "wxRibbonButtonBarEvent", |
| 48 |
_("Triggered when the normal (non-dropdown) region of a button on the button bar is clicked.")); |
| 49 |
RegisterEvent("wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED", "wxRibbonButtonBarEvent", |
| 50 |
_("Triggered when the dropdown region of a button on the button bar is clicked. " |
| 51 |
"wxRibbonButtonBarEvent::PopupMenu() should be called by the event handler if it wants to " |
| 52 |
"display a popup menu (which is what most dropdown buttons should be doing).")); |
| 53 |
m_namePattern = "m_ribbonButton"; |
| 54 |
|
| 55 |
} else { |
| 56 |
DelProperty(PROP_LABEL); |
| 57 |
RegisterEvent("wxEVT_COMMAND_RIBBONTOOL_CLICKED", "wxRibbonToolBarEvent", |
| 58 |
_("Triggered when the normal (non-dropdown) region of a tool on the toolbar is clicked.")); |
| 59 |
RegisterEvent("wxEVT_COMMAND_RIBBONTOOL_DROPDOWN_CLICKED", "wxRibbonToolBarEvent", |
| 60 |
_("Triggered when the dropdown region of a tool on the toolbar is clicked. " |
| 61 |
"wxRibbonToolBarEvent::PopupMenu() should be called by the event handler if it wants to " |
| 62 |
"display a popup menu (which is what most dropdown buttons should be doing).")); |
| 63 |
m_namePattern = "m_ribbonTool"; |
| 64 |
} |
| 65 |
SetName(GenerateName()); |
| 66 |
} |
| 67 |
|
| 68 |
RibbonButtonBase::~RibbonButtonBase() {} |
| 69 |
|
| 70 |
wxString RibbonButtonBase::CppCtorCode() const |
| 71 |
{ |
| 72 |
wxcCodeGeneratorHelper::Get().AddBitmap(PropertyFile(PROP_BITMAP_PATH)); |
| 73 |
wxString code; |
| 74 |
|
| 75 |
if(m_isButtonBar) { |
| 76 |
code << GetParent()->GetName() << "->AddButton(" << GetId() << ", " << Label() << ", " |
| 77 |
<< wxcCodeGeneratorHelper::Get().BitmapCode(PropertyFile(PROP_BITMAP_PATH)) << ", " |
| 78 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_HELP)) << ", " << PropertyString(PROP_KIND) << ");\n"; |
| 79 |
|
| 80 |
} else { |
| 81 |
code << GetParent()->GetName() << "->AddTool(" << GetId() << ", " |
| 82 |
<< wxcCodeGeneratorHelper::Get().BitmapCode(PropertyFile(PROP_BITMAP_PATH)) << ", " |
| 83 |
<< "wxNullBitmap, " << wxCrafter::UNDERSCORE(PropertyString(PROP_HELP)) << ", " |
| 84 |
<< PropertyString(PROP_KIND) << ");\n"; |
| 85 |
} |
| 86 |
return code; |
| 87 |
} |
| 88 |
|
| 89 |
void RibbonButtonBase::GetIncludeFile(wxArrayString& headers) const { wxUnusedVar(headers); } |
| 90 |
|
| 91 |
wxString RibbonButtonBase::GetWxClassName() const { return ""; } |
| 92 |
|
| 93 |
void RibbonButtonBase::ToXRC(wxString& text, XRC_TYPE type) const |
| 94 |
{ |
| 95 |
if(m_isButtonBar) { |
| 96 |
text << "<object class=\"button\" name=\"" << wxCrafter::XMLEncode(GetName()) << "\">"; |
| 97 |
|
| 98 |
} else { |
| 99 |
text << "<object class=\"tool\" name=\"" << wxCrafter::XMLEncode(GetName()) << "\">"; |
| 100 |
} |
| 101 |
|
| 102 |
text << XRCBitmap() << XRCLabel(); |
| 103 |
|
| 104 |
wxString kind = PropertyString(PROP_KIND); |
| 105 |
if(kind == "wxRIBBON_BUTTON_DROPDOWN") { |
| 106 |
text << "<dropdown>1</dropdown>"; |
| 107 |
|
| 108 |
} else if(kind == "wxRIBBON_BUTTON_HYBRID") { |
| 109 |
text << "<hybrid>1</hybrid>"; |
| 110 |
} |
| 111 |
|
| 112 |
text << XRCSuffix(); |
| 113 |
} |
| 114 |
|
| 115 |
wxString RibbonButtonBase::GetCppName() const { return GetParent()->GetName(); } |
| 116 |
|
| 117 |
// ---------------------------------------------- |
| 118 |
|
| 119 |
RibbonButton::RibbonButton() |
| 120 |
: RibbonButtonBase(ID_WXRIBBONBUTTON) |
| 121 |
{ |
| 122 |
} |
| 123 |
|
| 124 |
RibbonButton::~RibbonButton() {} |
| 125 |
|
| 126 |
// ---------------------------------------------- |
| 127 |
|
| 128 |
RibbonButtonHybrid::RibbonButtonHybrid() |
| 129 |
: RibbonButtonBase(ID_WXRIBBONHYBRIDBUTTON) |
| 130 |
{ |
| 131 |
} |
| 132 |
|
| 133 |
RibbonButtonHybrid::~RibbonButtonHybrid() {} |
| 134 |
|
| 135 |
// ----------------------------------------------- |
| 136 |
|
| 137 |
RibbonButtonDropdown::RibbonButtonDropdown() |
| 138 |
: RibbonButtonBase(ID_WXRIBBONDROPDOWNBUTTON) |
| 139 |
{ |
| 140 |
} |
| 141 |
|
| 142 |
RibbonButtonDropdown::~RibbonButtonDropdown() {} |
| 143 |
|
| 144 |
// ------------------------------------------- |
| 145 |
|
| 146 |
RibbonButtonToggle::RibbonButtonToggle() |
| 147 |
: RibbonButtonBase(ID_WXRIBBONTOGGLEBUTTON) |
| 148 |
{ |
| 149 |
} |
| 150 |
|
| 151 |
RibbonButtonToggle::~RibbonButtonToggle() {} |
| 152 |
|
| 153 |
// ------------------------------------------- |
| 154 |
RibbonTool::RibbonTool() |
| 155 |
: RibbonButtonBase(ID_WXRIBBONTOOL) |
| 156 |
{ |
| 157 |
} |
| 158 |
|
| 159 |
RibbonTool::~RibbonTool() {} |
| 160 |
|
| 161 |
// ------------------------------------------- |
| 162 |
|
| 163 |
RibbonToolToggle::RibbonToolToggle() |
| 164 |
: RibbonButtonBase(ID_WXRIBBONTOGGLETOOL) |
| 165 |
{ |
| 166 |
} |
| 167 |
|
| 168 |
RibbonToolToggle::~RibbonToolToggle() {} |
| 169 |
|
| 170 |
// ------------------------------------------- |
| 171 |
|
| 172 |
RibbonToolHybrid::RibbonToolHybrid() |
| 173 |
: RibbonButtonBase(ID_WXRIBBONHYBRIDTOOL) |
| 174 |
{ |
| 175 |
} |
| 176 |
|
| 177 |
RibbonToolHybrid::~RibbonToolHybrid() {} |
| 178 |
|
| 179 |
// ------------------------------------------- |
| 180 |
|
| 181 |
RibbonToolDropdown::RibbonToolDropdown() |
| 182 |
: RibbonButtonBase(ID_WXRIBBONDROPDOWNTOOL) |
| 183 |
{ |
| 184 |
} |
| 185 |
|
| 186 |
RibbonToolDropdown::~RibbonToolDropdown() {} |