#include <wx/wxprec.h>
#include <wx/wx.h>
#include "../include/wxdragon.h"
#if wxdUSE_XRC
#include <wx/xrc/xmlres.h>
#include <wx/xrc/xh_stbmp.h>
#include <wx/xml/xml.h>
#include <wx/statbmp.h>
#if defined(__WXMSW__) || defined(WXD_TARGET_WINDOWS)
#include <wx/generic/statbmpg.h>
#pragma message( \
"wxDragon: Compiling with Windows StaticBitmap support (will use wxGenericStaticBitmap)")
#ifdef __WXMSW__
#pragma message("wxDragon: __WXMSW__ is defined (native Windows build)")
#endif
#ifdef WXD_TARGET_WINDOWS
#pragma message("wxDragon: WXD_TARGET_WINDOWS is defined (cross-compilation target)")
#endif
#else
#pragma message("wxDragon: Compiling for non-Windows platform (will use native wxStaticBitmap)")
#endif
class WxdPlatformAwareStaticBitmapHandler : public wxXmlResourceHandler {
public:
WxdPlatformAwareStaticBitmapHandler()
{
AddWindowStyles();
}
virtual wxObject*
DoCreateResource()
{
wxBitmap bitmap = GetBitmap(wxT("bitmap"), wxART_OTHER);
#if defined(__WXMSW__) || defined(WXD_TARGET_WINDOWS)
wxGenericStaticBitmap* control = new wxGenericStaticBitmap(m_parentAsWindow, GetID(),
bitmap, GetPosition(), GetSize(),
GetStyle(), GetName());
wxString scaleMode = GetParamValue(wxT("scalemode"));
if (!scaleMode.IsEmpty()) {
if (scaleMode == wxT("None") || scaleMode == wxT("0")) {
control->SetScaleMode(wxStaticBitmap::Scale_None);
}
else if (scaleMode == wxT("Fill") || scaleMode == wxT("1")) {
control->SetScaleMode(wxStaticBitmap::Scale_Fill);
}
else if (scaleMode == wxT("AspectFit") || scaleMode == wxT("2")) {
control->SetScaleMode(wxStaticBitmap::Scale_AspectFit);
}
else if (scaleMode == wxT("AspectFill") || scaleMode == wxT("3")) {
control->SetScaleMode(wxStaticBitmap::Scale_AspectFill);
}
}
SetupWindow(control);
return control;
#else
wxStaticBitmap* control = new wxStaticBitmap(m_parentAsWindow, GetID(), bitmap,
GetPosition(), GetSize(), GetStyle(),
GetName());
wxString scaleMode = GetParamValue(wxT("scalemode"));
if (!scaleMode.IsEmpty()) {
if (scaleMode == wxT("None") || scaleMode == wxT("0")) {
control->SetScaleMode(wxStaticBitmap::Scale_None);
}
else if (scaleMode == wxT("Fill") || scaleMode == wxT("1")) {
control->SetScaleMode(wxStaticBitmap::Scale_Fill);
}
else if (scaleMode == wxT("AspectFit") || scaleMode == wxT("2")) {
control->SetScaleMode(wxStaticBitmap::Scale_AspectFit);
}
else if (scaleMode == wxT("AspectFill") || scaleMode == wxT("3")) {
control->SetScaleMode(wxStaticBitmap::Scale_AspectFill);
}
}
SetupWindow(control);
return control;
#endif
}
virtual bool
CanHandle(wxXmlNode* node)
{
return IsOfClass(node, wxT("wxStaticBitmap"));
}
};
WXD_EXPORTED void
wxd_XmlResource_InitPlatformAwareStaticBitmapHandler(wxd_XmlResource_t* resource)
{
wxXmlResource* res = reinterpret_cast<wxXmlResource*>(resource);
if (!res)
return;
res->AddHandler(new WxdPlatformAwareStaticBitmapHandler());
}
#else
WXD_EXPORTED void
wxd_XmlResource_InitPlatformAwareStaticBitmapHandler(wxd_XmlResource_t* resource)
{
(void)resource; }
#endif