| 1 |
#include "bitmap_button_wrapper.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "bitmap_picker_property.h" |
| 4 |
#include "bool_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 "xmlutils.h" |
| 11 |
#include <wx/bmpbuttn.h> |
| 12 |
|
| 13 |
BitmapButtonWrapper::BitmapButtonWrapper() |
| 14 |
: wxcWidget(ID_WXBITMAPBUTTON) |
| 15 |
{ |
| 16 |
PREPEND_STYLE(wxBU_AUTODRAW, true); |
| 17 |
PREPEND_STYLE(wxBU_LEFT, false); |
| 18 |
PREPEND_STYLE(wxBU_RIGHT, false); |
| 19 |
PREPEND_STYLE(wxBU_TOP, false); |
| 20 |
|
| 21 |
RegisterEvent(wxT("wxEVT_COMMAND_BUTTON_CLICKED"), wxT("wxCommandEvent"), |
| 22 |
_("Process a wxEVT_COMMAND_BUTTON_CLICKED event, when the button is clicked."), |
| 23 |
wxT("wxCommandEventHandler")); |
| 24 |
|
| 25 |
m_namePattern = wxT("m_bmpButton"); |
| 26 |
SetPropertyString(_("Common Settings"), "wxBitmapButton"); |
| 27 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH, wxT(""), _("Select the bitmap file"))); |
| 28 |
AddProperty(new BoolProperty(PROP_DEFAULT_BUTTON, false, _("Make this button the default button"))); |
| 29 |
|
| 30 |
wxCrafter::ResourceLoader bl; |
| 31 |
m_properties.Item(PROP_BITMAP_PATH)->SetValue(bl.GetPlaceHolder16ImagePath().GetFullPath()); |
| 32 |
|
| 33 |
SetName(GenerateName()); |
| 34 |
} |
| 35 |
|
| 36 |
BitmapButtonWrapper::~BitmapButtonWrapper() {} |
| 37 |
|
| 38 |
wxString BitmapButtonWrapper::GetWxClassName() const { return wxT("wxBitmapButton"); } |
| 39 |
|
| 40 |
wxString BitmapButtonWrapper::CppCtorCode() const |
| 41 |
{ |
| 42 |
wxcCodeGeneratorHelper::Get().AddBitmap(PropertyFile(PROP_BITMAP_PATH)); |
| 43 |
|
| 44 |
wxString code; |
| 45 |
code << GetName() << wxT(" = new ") << GetRealClassName() << "(" << GetWindowParent() << wxT(", ") << WindowID() |
| 46 |
<< wxT(", ") << wxcCodeGeneratorHelper::Get().BitmapCode(PropertyFile(PROP_BITMAP_PATH)) |
| 47 |
<< wxT(", wxDefaultPosition, ") << SizeAsString() << wxT(", ") << StyleFlags(wxT("0")) << wxT(");\n"); |
| 48 |
|
| 49 |
if(PropertyString(PROP_DEFAULT_BUTTON) == wxT("1")) { code << GetName() << wxT("->SetDefault();"); } |
| 50 |
code << CPPCommonAttributes(); |
| 51 |
return code; |
| 52 |
} |
| 53 |
|
| 54 |
void BitmapButtonWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 55 |
{ |
| 56 |
text << XRCPrefix() << XRCBitmap() << XRCSize() << XRCStyle() << XRCCommonAttributes() << wxT("<default>") |
| 57 |
<< PropertyString(PROP_DEFAULT_BUTTON) << wxT("</default>") << wxT("</object>"); |
| 58 |
} |
| 59 |
|
| 60 |
void BitmapButtonWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/bmpbuttn.h>")); } |
| 61 |
|
| 62 |
void BitmapButtonWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 63 |
{ |
| 64 |
// First call the base-class for the standard things |
| 65 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 66 |
|
| 67 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("bitmap")); |
| 68 |
if(propertynode) { ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_BITMAP_PATH, "wxART_BUTTON"); } |
| 69 |
|
| 70 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("default")); |
| 71 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_BUTTON, propertynode->GetNodeContent()); } |
| 72 |
} |
| 73 |
|
| 74 |
void BitmapButtonWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 75 |
{ |
| 76 |
// First call the base-class for the standard things |
| 77 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 78 |
|
| 79 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("bitmap")); |
| 80 |
if(propertynode) { ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_BITMAP_PATH, "wxART_BUTTON"); } |
| 81 |
|
| 82 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("default")); |
| 83 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_BUTTON, propertynode->GetNodeContent()); } |
| 84 |
} |
| 85 |
|
| 86 |
void BitmapButtonWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 87 |
{ |
| 88 |
// First call the base-class for the standard things |
| 89 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 90 |
|
| 91 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "bitmap"); |
| 92 |
if(propertynode) { |
| 93 |
ImportFromwxFB::ProcessBitmapProperty(propertynode->GetNodeContent(), this, PROP_BITMAP_PATH, "wxART_BUTTON"); |
| 94 |
} |
| 95 |
|
| 96 |
propertynode = XmlUtils::FindNodeByName(node, "property", "default"); |
| 97 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_BUTTON, propertynode->GetNodeContent()); } |
| 98 |
} |