| 1 |
#include "button_wrapper.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "bool_property.h" |
| 4 |
#include "choice_property.h" |
| 5 |
#include "file_ficker_property.h" |
| 6 |
#include "import_from_wxFB.h" |
| 7 |
#include "import_from_xrc.h" |
| 8 |
#include "wxc_bitmap_code_generator.h" |
| 9 |
#include "wxgui_bitmaploader.h" |
| 10 |
#include "wxgui_defs.h" |
| 11 |
#include "wxgui_helpers.h" |
| 12 |
#include "xmlutils.h" |
| 13 |
#include "xy_pair.h" |
| 14 |
#include <wx/button.h> |
| 15 |
|
| 16 |
ButtonWrapper::ButtonWrapper() |
| 17 |
: wxcWidget(ID_WXBUTTON) |
| 18 |
{ |
| 19 |
PREPEND_STYLE(wxBU_BOTTOM, false); |
| 20 |
PREPEND_STYLE(wxBU_EXACTFIT, false); |
| 21 |
PREPEND_STYLE(wxBU_LEFT, false); |
| 22 |
PREPEND_STYLE(wxBU_RIGHT, false); |
| 23 |
PREPEND_STYLE(wxBU_TOP, false); |
| 24 |
|
| 25 |
wxArrayString directions; |
| 26 |
directions.Add("wxLEFT"); |
| 27 |
directions.Add("wxRIGHT"); |
| 28 |
directions.Add("wxTOP"); |
| 29 |
directions.Add("wxBOTTOM"); |
| 30 |
|
| 31 |
RegisterEvent(wxT("wxEVT_COMMAND_BUTTON_CLICKED"), wxT("wxCommandEvent"), |
| 32 |
_("Process a wxEVT_COMMAND_BUTTON_CLICKED event, when the button is clicked."), |
| 33 |
wxT("wxCommandEventHandler")); |
| 34 |
|
| 35 |
m_namePattern = wxT("m_button"); |
| 36 |
SetPropertyString(_("Common Settings"), "wxButton"); |
| 37 |
AddProperty(new StringProperty(PROP_LABEL, _("My Button"), _("The button label"))); |
| 38 |
AddProperty(new BoolProperty(PROP_DEFAULT_BUTTON, false, _("Make this button the default button"))); |
| 39 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH, wxT(""), _("Select the bitmap file (wx2.9.X and later)"))); |
| 40 |
AddProperty(new ChoiceProperty(PROP_DIRECTION, directions, 0, |
| 41 |
_("The position of the bitmap inside the button. By default it is positioned to " |
| 42 |
"the left of the text, near to the left button border. "))); |
| 43 |
AddProperty(new StringProperty(PROP_MARGINS, "2,2", |
| 44 |
_("Sets x/y margins between the bitmap and the button label (wx2.9.X and later)"))); |
| 45 |
|
| 46 |
// wxCrafter::ResourceLoader bl; |
| 47 |
// m_properties.Item(PROP_BITMAP_PATH)->SetValue( bl.GetPlaceHolder16ImagePath().GetFullPath() ); |
| 48 |
|
| 49 |
SetName(GenerateName()); |
| 50 |
} |
| 51 |
|
| 52 |
ButtonWrapper::~ButtonWrapper() {} |
| 53 |
|
| 54 |
wxString ButtonWrapper::CppCtorCode() const |
| 55 |
{ |
| 56 |
wxcCodeGeneratorHelper::Get().AddBitmap(PropertyFile(PROP_BITMAP_PATH)); |
| 57 |
|
| 58 |
XYPair xy(PropertyString(PROP_MARGINS), 2, 2); |
| 59 |
|
| 60 |
wxString code; |
| 61 |
code << GetName() << wxT(" = new ") << GetRealClassName() << "(" << GetWindowParent() << wxT(", ") << WindowID() |
| 62 |
<< wxT(", ") << Label() << wxT(", wxDefaultPosition, ") << SizeAsString() << wxT(", ") << StyleFlags(wxT("0")) |
| 63 |
<< wxT(");\n"); |
| 64 |
|
| 65 |
if(PropertyString(PROP_DEFAULT_BUTTON) == wxT("1")) { code << GetName() << wxT("->SetDefault();\n"); } |
| 66 |
|
| 67 |
wxString bmpCpp = wxcCodeGeneratorHelper::Get().BitmapCode(PropertyFile(PROP_BITMAP_PATH)); |
| 68 |
if(bmpCpp != "wxNullBitmap") { |
| 69 |
code << wxCrafter::WX294_BLOCK_START(); |
| 70 |
code << GetName() << "->SetBitmap(" << bmpCpp << ", " << PropertyString(PROP_DIRECTION) << ");\n"; |
| 71 |
code << GetName() << "->SetBitmapMargins(" << xy.ToString() << ");\n"; |
| 72 |
code << wxCrafter::WXVER_CHECK_BLOCK_END(); |
| 73 |
} |
| 74 |
code << CPPCommonAttributes(); |
| 75 |
return code; |
| 76 |
} |
| 77 |
|
| 78 |
void ButtonWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 79 |
{ |
| 80 |
text << XRCPrefix() << XRCLabel() << XRCStyle() << XRCSize() << XRCCommonAttributes() << XRCBitmap() |
| 81 |
<< "<bitmapposition>" << PropertyString(PROP_DIRECTION) << "</bitmapposition>" << wxT("<default>") |
| 82 |
<< PropertyString(PROP_DEFAULT_BUTTON) << wxT("</default>") << XRCSuffix(); |
| 83 |
} |
| 84 |
|
| 85 |
wxString ButtonWrapper::GetWxClassName() const { return wxT("wxButton"); } |
| 86 |
|
| 87 |
void ButtonWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/button.h>")); } |
| 88 |
|
| 89 |
void ButtonWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 90 |
{ |
| 91 |
// First call the base-class for the standard things |
| 92 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 93 |
|
| 94 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("bitmap")); |
| 95 |
if(propertynode) { ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_BITMAP_PATH, "wxART_BUTTON"); } |
| 96 |
|
| 97 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("default")); |
| 98 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_BUTTON, propertynode->GetNodeContent()); } |
| 99 |
} |
| 100 |
|
| 101 |
void ButtonWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 102 |
{ |
| 103 |
// First call the base-class for the standard things |
| 104 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 105 |
|
| 106 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("bitmap")); |
| 107 |
if(propertynode) { ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_BITMAP_PATH, "wxART_BUTTON"); } |
| 108 |
|
| 109 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("default")); |
| 110 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_BUTTON, propertynode->GetNodeContent()); } |
| 111 |
} |
| 112 |
|
| 113 |
void ButtonWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 114 |
{ |
| 115 |
// First call the base-class for the standard things |
| 116 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 117 |
|
| 118 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "bitmap"); |
| 119 |
if(propertynode) { |
| 120 |
ImportFromwxFB::ProcessBitmapProperty(propertynode->GetNodeContent(), this, PROP_BITMAP_PATH, "wxART_BUTTON"); |
| 121 |
} |
| 122 |
|
| 123 |
propertynode = XmlUtils::FindNodeByName(node, "property", "default"); |
| 124 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_BUTTON, propertynode->GetNodeContent()); } |
| 125 |
} |