Derive wxBitmap from wxBitmapBase.
Move code from LoadFile/SaveFile/Create* to bitmap handlers. Implemented wxBitmap::GetSubBitmap. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19987 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -32,7 +32,7 @@ class WXDLLEXPORT wxImage;
|
|||||||
class WXDLLEXPORT wxMask;
|
class WXDLLEXPORT wxMask;
|
||||||
class WXDLLEXPORT wxPalette;
|
class WXDLLEXPORT wxPalette;
|
||||||
|
|
||||||
#if defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) || defined(__WXMOTIF__)
|
#if defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) || defined(__WXMOTIF__) || defined(__WXX11__)
|
||||||
// Only used by some ports
|
// Only used by some ports
|
||||||
// FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
|
// FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
|
||||||
|
|
||||||
|
@@ -66,7 +66,15 @@ private:
|
|||||||
// wxBitmap
|
// wxBitmap
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxBitmap: public wxGDIObject
|
class WXDLLEXPORT wxBitmapHandler : public wxBitmapHandlerBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxBitmapHandler() : wxBitmapHandlerBase() {}
|
||||||
|
private:
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
|
||||||
|
};
|
||||||
|
|
||||||
|
class wxBitmap: public wxBitmapBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxBitmap();
|
wxBitmap();
|
||||||
@@ -75,7 +83,7 @@ public:
|
|||||||
wxBitmap( const char **bits ) { (void)CreateFromXpm(bits); }
|
wxBitmap( const char **bits ) { (void)CreateFromXpm(bits); }
|
||||||
wxBitmap( char **bits ) { (void)CreateFromXpm((const char **)bits); }
|
wxBitmap( char **bits ) { (void)CreateFromXpm((const char **)bits); }
|
||||||
wxBitmap( const wxBitmap& bmp );
|
wxBitmap( const wxBitmap& bmp );
|
||||||
wxBitmap( const wxString &filename, int type = wxBITMAP_TYPE_XPM );
|
wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM );
|
||||||
wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); }
|
wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); }
|
||||||
~wxBitmap();
|
~wxBitmap();
|
||||||
wxBitmap& operator = ( const wxBitmap& bmp );
|
wxBitmap& operator = ( const wxBitmap& bmp );
|
||||||
@@ -83,8 +91,12 @@ public:
|
|||||||
bool operator != ( const wxBitmap& bmp ) const;
|
bool operator != ( const wxBitmap& bmp ) const;
|
||||||
bool Ok() const;
|
bool Ok() const;
|
||||||
|
|
||||||
|
static void InitStandardHandlers();
|
||||||
|
|
||||||
bool Create(int width, int height, int depth = -1);
|
bool Create(int width, int height, int depth = -1);
|
||||||
|
bool Create(void* data, wxBitmapType type,
|
||||||
|
int width, int height, int depth = -1);
|
||||||
|
|
||||||
int GetHeight() const;
|
int GetHeight() const;
|
||||||
int GetWidth() const;
|
int GetWidth() const;
|
||||||
int GetDepth() const;
|
int GetDepth() const;
|
||||||
@@ -99,12 +111,13 @@ public:
|
|||||||
|
|
||||||
wxBitmap GetSubBitmap( const wxRect& rect ) const;
|
wxBitmap GetSubBitmap( const wxRect& rect ) const;
|
||||||
|
|
||||||
bool SaveFile( const wxString &name, int type, wxPalette *palette = (wxPalette *) NULL );
|
bool SaveFile( const wxString &name, wxBitmapType type, const wxPalette *palette = (wxPalette *) NULL ) const;
|
||||||
bool LoadFile( const wxString &name, int type = wxBITMAP_TYPE_XPM );
|
bool LoadFile( const wxString &name, wxBitmapType type = wxBITMAP_TYPE_XPM );
|
||||||
|
|
||||||
wxPalette *GetPalette() const;
|
wxPalette *GetPalette() const;
|
||||||
wxPalette *GetColourMap() const
|
wxPalette *GetColourMap() const
|
||||||
{ return GetPalette(); };
|
{ return GetPalette(); };
|
||||||
|
virtual void SetPalette(const wxPalette& palette);
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
// --------------
|
// --------------
|
||||||
|
@@ -31,7 +31,7 @@ public:
|
|||||||
|
|
||||||
// For compatibility with wxMSW where desired size is sometimes required to
|
// For compatibility with wxMSW where desired size is sometimes required to
|
||||||
// distinguish between multiple icons in a resource.
|
// distinguish between multiple icons in a resource.
|
||||||
wxIcon( const wxString& filename, int type = wxBITMAP_TYPE_XPM,
|
wxIcon( const wxString& filename, wxBitmapType type = wxBITMAP_TYPE_XPM,
|
||||||
int WXUNUSED(desiredWidth)=-1, int WXUNUSED(desiredHeight)=-1 ) :
|
int WXUNUSED(desiredWidth)=-1, int WXUNUSED(desiredHeight)=-1 ) :
|
||||||
wxBitmap(filename, type)
|
wxBitmap(filename, type)
|
||||||
{
|
{
|
||||||
|
@@ -19,7 +19,8 @@
|
|||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) || defined(__WXMOTIF__)
|
#if defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) \
|
||||||
|
|| defined(__WXMOTIF__) || defined(__WXX11__)
|
||||||
|
|
||||||
#include "wx/setup.h"
|
#include "wx/setup.h"
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
@@ -121,5 +122,5 @@ public:
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
|
IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
|
||||||
|
|
||||||
#endif // defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) || defined(__WXMOTIF__)
|
#endif // defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) || defined(__WXMOTIF__) || defined(__WXX11__)
|
||||||
|
|
||||||
|
@@ -265,6 +265,35 @@ wxBitmapRefData::~wxBitmapRefData()
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// helper function
|
||||||
|
|
||||||
|
static WXPixmap wxGetSubPixmap( WXDisplay* xdisplay, WXPixmap xpixmap,
|
||||||
|
int x, int y, int width, int height,
|
||||||
|
int depth )
|
||||||
|
{
|
||||||
|
int xscreen = DefaultScreen( (Display*)xdisplay );
|
||||||
|
Window xroot = RootWindow( (Display*)xdisplay, xscreen );
|
||||||
|
Visual* xvisual = DefaultVisual( xdisplay, xscreen );
|
||||||
|
|
||||||
|
XImage* ximage = XCreateImage( (Display*)xdisplay, xvisual, depth,
|
||||||
|
ZPixmap, 0, 0, width, height, 32, 0 );
|
||||||
|
ximage->data = (char*)malloc( ximage->bytes_per_line * ximage->height );
|
||||||
|
ximage = XGetSubImage( (Display*)xdisplay, (Pixmap)xpixmap,
|
||||||
|
x, y, width, height,
|
||||||
|
AllPlanes, ZPixmap, ximage, 0, 0 );
|
||||||
|
|
||||||
|
GC gc = XCreateGC( (Display*)xdisplay, (Pixmap)xpixmap, 0, NULL );
|
||||||
|
Pixmap ret = XCreatePixmap( (Display*)xdisplay, xroot,
|
||||||
|
width, height, depth );
|
||||||
|
|
||||||
|
XPutImage( (Display*)xdisplay, ret, gc, ximage,
|
||||||
|
0, 0, 0, 0, width, height );
|
||||||
|
XDestroyImage( ximage );
|
||||||
|
XFreeGC( (Display*)xdisplay, gc );
|
||||||
|
|
||||||
|
return (WXPixmap)ret;
|
||||||
|
}
|
||||||
|
|
||||||
#define M_BMPDATA ((wxBitmapRefData *)m_refData)
|
#define M_BMPDATA ((wxBitmapRefData *)m_refData)
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject)
|
IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject)
|
||||||
@@ -329,78 +358,28 @@ bool wxBitmap::Create( int width, int height, int depth )
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmap::CreateFromXpm( const char **bits )
|
bool wxBitmap::Create(void *data, wxBitmapType type,
|
||||||
|
int width, int height, int depth)
|
||||||
{
|
{
|
||||||
#if wxUSE_XPM
|
|
||||||
#if wxHAVE_LIB_XPM
|
|
||||||
UnRef();
|
UnRef();
|
||||||
|
|
||||||
wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
|
wxBitmapHandler *handler = FindHandler(type);
|
||||||
|
|
||||||
m_refData = new wxBitmapRefData();
|
if ( handler == NULL ) {
|
||||||
|
wxLogWarning("no data bitmap handler for type %ld defined.",
|
||||||
|
(long)type);
|
||||||
|
|
||||||
M_BMPDATA->m_display = wxGlobalDisplay();
|
|
||||||
|
|
||||||
Display *xdisplay = (Display*) M_BMPDATA->m_display;
|
|
||||||
|
|
||||||
int xscreen = DefaultScreen( xdisplay );
|
|
||||||
Window xroot = RootWindow( xdisplay, xscreen );
|
|
||||||
|
|
||||||
int bpp = DefaultDepth( xdisplay, xscreen );
|
|
||||||
|
|
||||||
XpmAttributes xpmAttr;
|
|
||||||
xpmAttr.valuemask = XpmReturnInfos; // nothing yet, but get infos back
|
|
||||||
|
|
||||||
Pixmap pixmap;
|
|
||||||
Pixmap mask = 0;
|
|
||||||
|
|
||||||
int ErrorStatus = XpmCreatePixmapFromData( xdisplay, xroot, (char**) bits, &pixmap, &mask, &xpmAttr );
|
|
||||||
|
|
||||||
if (ErrorStatus == XpmSuccess)
|
|
||||||
{
|
|
||||||
M_BMPDATA->m_width = xpmAttr.width;
|
|
||||||
M_BMPDATA->m_height = xpmAttr.height;
|
|
||||||
|
|
||||||
M_BMPDATA->m_bpp = bpp; // mono as well?
|
|
||||||
|
|
||||||
#if __WXDEBUG__
|
|
||||||
unsigned int depthRet;
|
|
||||||
int xRet, yRet;
|
|
||||||
unsigned int widthRet, heightRet, borderWidthRet;
|
|
||||||
XGetGeometry( xdisplay, pixmap, &xroot, &xRet, &yRet,
|
|
||||||
&widthRet, &heightRet, &borderWidthRet, &depthRet);
|
|
||||||
|
|
||||||
wxASSERT_MSG( bpp == (int)depthRet, wxT("colour depth mismatch") );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
XpmFreeAttributes(&xpmAttr);
|
|
||||||
|
|
||||||
M_BMPDATA->m_pixmap = (WXPixmap) pixmap;
|
|
||||||
|
|
||||||
if (mask)
|
|
||||||
{
|
|
||||||
M_BMPDATA->m_mask = new wxMask;
|
|
||||||
M_BMPDATA->m_mask->SetBitmap( (WXPixmap) mask );
|
|
||||||
M_BMPDATA->m_mask->SetDisplay( xdisplay );
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UnRef();
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
wxXPMDecoder decoder;
|
return handler->Create(this, data, type, width, height, depth);
|
||||||
wxImage image(decoder.ReadData(bits));
|
}
|
||||||
if (image.Ok())
|
|
||||||
return CreateFromImage(image);
|
bool wxBitmap::CreateFromXpm( const char **bits )
|
||||||
else
|
{
|
||||||
return FALSE;
|
wxCHECK_MSG( bits, FALSE, _T("NULL pointer in wxBitmap::CreateFromXpm") );
|
||||||
#endif
|
|
||||||
#endif
|
return Create(bits, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
||||||
@@ -877,30 +856,16 @@ wxBitmap::wxBitmap( const wxBitmap& bmp )
|
|||||||
Ref( bmp );
|
Ref( bmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap( const wxString &filename, int type )
|
wxBitmap::wxBitmap( const wxString &filename, wxBitmapType type )
|
||||||
{
|
{
|
||||||
LoadFile( filename, type );
|
LoadFile( filename, type );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth) )
|
wxBitmap::wxBitmap( const char bits[], int width, int height, int depth )
|
||||||
{
|
{
|
||||||
#if !wxUSE_NANOX
|
m_refData = new wxBitmapRefData;
|
||||||
m_refData = new wxBitmapRefData();
|
|
||||||
|
|
||||||
M_BMPDATA->m_display = wxGlobalDisplay();
|
(void) Create((void*) bits, wxBITMAP_TYPE_XBM_DATA, width, height, depth);
|
||||||
|
|
||||||
Display *xdisplay = (Display*) M_BMPDATA->m_display;
|
|
||||||
|
|
||||||
int xscreen = DefaultScreen( xdisplay );
|
|
||||||
Window xroot = RootWindow( xdisplay, xscreen );
|
|
||||||
|
|
||||||
M_BMPDATA->m_mask = (wxMask *) NULL;
|
|
||||||
M_BMPDATA->m_bitmap = (WXPixmap) XCreateBitmapFromData( xdisplay, xroot, (char *) bits, width, height );
|
|
||||||
M_BMPDATA->m_width = width;
|
|
||||||
M_BMPDATA->m_height = height;
|
|
||||||
M_BMPDATA->m_bpp = 1;
|
|
||||||
#endif
|
|
||||||
wxCHECK_RET( M_BMPDATA->m_bitmap, wxT("couldn't create bitmap") );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::~wxBitmap()
|
wxBitmap::~wxBitmap()
|
||||||
@@ -977,145 +942,103 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
|
|||||||
{
|
{
|
||||||
wxCHECK_MSG( Ok() &&
|
wxCHECK_MSG( Ok() &&
|
||||||
(rect.x >= 0) && (rect.y >= 0) &&
|
(rect.x >= 0) && (rect.y >= 0) &&
|
||||||
(rect.x+rect.width <= M_BMPDATA->m_width) && (rect.y+rect.height <= M_BMPDATA->m_height),
|
(rect.x+rect.width <= M_BMPDATA->m_width ) &&
|
||||||
|
(rect.y+rect.height <= M_BMPDATA->m_height),
|
||||||
wxNullBitmap, wxT("invalid bitmap or bitmap region") );
|
wxNullBitmap, wxT("invalid bitmap or bitmap region") );
|
||||||
|
|
||||||
wxBitmap ret( rect.width, rect.height, M_BMPDATA->m_bpp );
|
wxBitmap ret( rect.width, rect.height, M_BMPDATA->m_bpp );
|
||||||
wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
|
wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
|
||||||
|
|
||||||
|
if( GetMask() )
|
||||||
wxFAIL_MSG( "wxBitmap::GetSubBitmap not yet implemented" );
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (ret.GetPixmap())
|
|
||||||
{
|
{
|
||||||
GdkGC *gc = gdk_gc_new( ret.GetPixmap() );
|
wxMask* mask = new wxMask();
|
||||||
gdk_draw_pixmap( ret.GetPixmap(), gc, GetPixmap(), rect.x, rect.y, 0, 0, rect.width, rect.height );
|
mask->SetDisplay( GetMask()->GetDisplay() );
|
||||||
gdk_gc_destroy( gc );
|
mask->SetBitmap( wxGetSubPixmap( GetMask()->GetDisplay(),
|
||||||
}
|
GetMask()->GetBitmap(),
|
||||||
else
|
rect.x, rect.y,
|
||||||
{
|
rect.width, rect.height,
|
||||||
GdkGC *gc = gdk_gc_new( ret.GetBitmap() );
|
1 ) );
|
||||||
gdk_wx_draw_bitmap( ret.GetBitmap(), gc, GetBitmap(), rect.x, rect.y, 0, 0, rect.width, rect.height );
|
|
||||||
gdk_gc_destroy( gc );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetMask())
|
|
||||||
{
|
|
||||||
wxMask *mask = new wxMask;
|
|
||||||
mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, rect.width, rect.height, 1 );
|
|
||||||
|
|
||||||
GdkGC *gc = gdk_gc_new( mask->m_bitmap );
|
|
||||||
gdk_wx_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height );
|
|
||||||
gdk_gc_destroy( gc );
|
|
||||||
|
|
||||||
ret.SetMask( mask );
|
ret.SetMask( mask );
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
if( GetPixmap() )
|
||||||
|
{
|
||||||
|
ret.SetPixmap( wxGetSubPixmap( GetDisplay(),
|
||||||
|
GetPixmap(),
|
||||||
|
rect.x, rect.y,
|
||||||
|
rect.width, rect.height,
|
||||||
|
M_BMPDATA->m_bpp ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( GetBitmap() )
|
||||||
|
{
|
||||||
|
ret.SetBitmap( wxGetSubPixmap( GetDisplay(),
|
||||||
|
GetBitmap(),
|
||||||
|
rect.x, rect.y,
|
||||||
|
rect.width, rect.height,
|
||||||
|
1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(palette) )
|
bool wxBitmap::SaveFile( const wxString &name, wxBitmapType type,
|
||||||
|
const wxPalette *palette ) const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( Ok(), FALSE, wxT("invalid bitmap") );
|
wxCHECK_MSG( Ok(), FALSE, wxT("invalid bitmap") );
|
||||||
|
|
||||||
|
wxBitmapHandler *handler = FindHandler(type);
|
||||||
|
|
||||||
// Try to save the bitmap via wxImage handlers:
|
// Try to save the bitmap via wxImage handlers:
|
||||||
{
|
if (handler == NULL)
|
||||||
wxImage image(this->ConvertToImage()) ;
|
{
|
||||||
|
wxImage image(this->ConvertToImage());
|
||||||
if (image.Ok()) return image.SaveFile( name, type );
|
if (image.Ok()) return image.SaveFile( name, type );
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return handler->SaveFile(this, name, type, palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmap::LoadFile( const wxString &name, int type )
|
bool wxBitmap::LoadFile( const wxString &name, wxBitmapType type )
|
||||||
{
|
{
|
||||||
UnRef();
|
UnRef();
|
||||||
|
|
||||||
if (!wxFileExists(name)) return FALSE;
|
if (!wxFileExists(name)) return FALSE;
|
||||||
|
|
||||||
|
wxBitmapHandler *handler = FindHandler(type);
|
||||||
|
|
||||||
if (type == wxBITMAP_TYPE_XPM)
|
if (handler == NULL)
|
||||||
{
|
|
||||||
#if wxUSE_XPM
|
|
||||||
#if wxHAVE_LIB_XPM
|
|
||||||
m_refData = new wxBitmapRefData();
|
|
||||||
|
|
||||||
M_BMPDATA->m_display = wxGlobalDisplay();
|
|
||||||
|
|
||||||
Display *xdisplay = (Display*) M_BMPDATA->m_display;
|
|
||||||
|
|
||||||
int xscreen = DefaultScreen( xdisplay );
|
|
||||||
Window xroot = RootWindow( xdisplay, xscreen );
|
|
||||||
|
|
||||||
int bpp = DefaultDepth( xdisplay, xscreen );
|
|
||||||
|
|
||||||
XpmAttributes xpmAttr;
|
|
||||||
xpmAttr.valuemask = XpmReturnInfos; // nothing yet, but get infos back
|
|
||||||
|
|
||||||
Pixmap pixmap;
|
|
||||||
Pixmap mask = 0;
|
|
||||||
|
|
||||||
int ErrorStatus = XpmReadFileToPixmap( xdisplay, xroot, (char*) name.c_str(), &pixmap, &mask, &xpmAttr);
|
|
||||||
|
|
||||||
if (ErrorStatus == XpmSuccess)
|
|
||||||
{
|
|
||||||
M_BMPDATA->m_width = xpmAttr.width;
|
|
||||||
M_BMPDATA->m_height = xpmAttr.height;
|
|
||||||
|
|
||||||
M_BMPDATA->m_bpp = bpp; // mono as well?
|
|
||||||
|
|
||||||
XpmFreeAttributes(&xpmAttr);
|
|
||||||
|
|
||||||
M_BMPDATA->m_bitmap = (WXPixmap) pixmap;
|
|
||||||
|
|
||||||
if (mask)
|
|
||||||
{
|
|
||||||
M_BMPDATA->m_mask = new wxMask;
|
|
||||||
M_BMPDATA->m_mask->SetBitmap( (WXPixmap) mask );
|
|
||||||
M_BMPDATA->m_mask->SetDisplay( xdisplay );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UnRef();
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#if wxUSE_STREAMS
|
|
||||||
wxXPMDecoder decoder;
|
|
||||||
wxFileInputStream stream(name);
|
|
||||||
if (stream.Ok())
|
|
||||||
{
|
|
||||||
wxImage image(decoder.ReadFile(stream));
|
|
||||||
if (image.Ok())
|
|
||||||
return CreateFromImage(image);
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
#else
|
|
||||||
return FALSE;
|
|
||||||
#endif
|
|
||||||
// wxUSE_STREAMS
|
|
||||||
#endif
|
|
||||||
// wxHAVE_LIB_XPM
|
|
||||||
#endif
|
|
||||||
// wxUSE_XPM
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else // try if wxImage can load it
|
|
||||||
{
|
{
|
||||||
wxImage image;
|
wxImage image;
|
||||||
if (!image.LoadFile( name, type )) return FALSE;
|
if (!image.LoadFile( name, type ))
|
||||||
if (image.Ok()) *this = wxBitmap(image);
|
return FALSE;
|
||||||
|
|
||||||
|
if (image.Ok())
|
||||||
|
{
|
||||||
|
*this = wxBitmap(image);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
else return FALSE;
|
else return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return handler->LoadFile(this, name, type, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmap::SetPalette(const wxPalette& palette)
|
||||||
|
{
|
||||||
|
wxCHECK_RET(Ok(), wxT("invalid bitmap"));
|
||||||
|
wxCHECK_RET(GetDepth() > 1 && GetDepth() <= 8,
|
||||||
|
wxT("cannot set palette for bitmap of this depth"));
|
||||||
|
|
||||||
|
delete M_BMPDATA->m_palette;
|
||||||
|
M_BMPDATA->m_palette = NULL;
|
||||||
|
|
||||||
|
if (!palette.Ok()) return;
|
||||||
|
|
||||||
|
M_BMPDATA->m_palette = new wxPalette(palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxPalette *wxBitmap::GetPalette() const
|
wxPalette *wxBitmap::GetPalette() const
|
||||||
@@ -1318,3 +1241,296 @@ int GrGetPixelColor(GR_SCREEN_INFO* sinfo, GR_PALETTE* palette, GR_PIXELVAL pixe
|
|||||||
#endif
|
#endif
|
||||||
// wxUSE_NANOX
|
// wxUSE_NANOX
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// Bitmap handlers
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxBitmapHandlerBase);
|
||||||
|
|
||||||
|
#define M_BMPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
|
||||||
|
|
||||||
|
#if wxUSE_XPM
|
||||||
|
|
||||||
|
#if wxHAVE_LIB_XPM || wxUSE_STREAMS
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxXPMFileHandler
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxXPMFileHandler : public wxBitmapHandler
|
||||||
|
{
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxXPMFileHandler);
|
||||||
|
public:
|
||||||
|
wxXPMFileHandler()
|
||||||
|
{
|
||||||
|
m_name = "XPM file";
|
||||||
|
m_extension = "xpm";
|
||||||
|
m_type = wxBITMAP_TYPE_XPM;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
|
||||||
|
int desiredWidth, int desiredHeight);
|
||||||
|
|
||||||
|
virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name,
|
||||||
|
int type, const wxPalette *palette = NULL);
|
||||||
|
|
||||||
|
virtual bool Create(wxBitmap *bitmap, void *data, long flags,
|
||||||
|
int width, int height, int depth = 1)
|
||||||
|
{ return FALSE; }
|
||||||
|
};
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler, wxBitmapHandler);
|
||||||
|
|
||||||
|
bool wxXPMFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
|
||||||
|
long flags, int desiredWidth,
|
||||||
|
int desiredHeight)
|
||||||
|
{
|
||||||
|
#if wxHAVE_LIB_XPM
|
||||||
|
if (!bitmap->GetRefData())
|
||||||
|
bitmap->SetRefData( new wxBitmapRefData() );
|
||||||
|
|
||||||
|
M_BMPHANDLERDATA->m_display = wxGlobalDisplay();
|
||||||
|
|
||||||
|
Display *xdisplay = (Display*) M_BMPHANDLERDATA->m_display;
|
||||||
|
|
||||||
|
int xscreen = DefaultScreen( xdisplay );
|
||||||
|
Window xroot = RootWindow( xdisplay, xscreen );
|
||||||
|
|
||||||
|
int bpp = DefaultDepth( xdisplay, xscreen );
|
||||||
|
|
||||||
|
XpmAttributes xpmAttr;
|
||||||
|
xpmAttr.valuemask = XpmReturnInfos; // nothing yet, but get infos back
|
||||||
|
|
||||||
|
Pixmap pixmap;
|
||||||
|
Pixmap mask = 0;
|
||||||
|
|
||||||
|
int ErrorStatus = XpmReadFileToPixmap( xdisplay, xroot,
|
||||||
|
(char*) name.c_str(),
|
||||||
|
&pixmap, &mask, &xpmAttr);
|
||||||
|
|
||||||
|
if (ErrorStatus == XpmSuccess)
|
||||||
|
{
|
||||||
|
M_BMPHANDLERDATA->m_width = xpmAttr.width;
|
||||||
|
M_BMPHANDLERDATA->m_height = xpmAttr.height;
|
||||||
|
|
||||||
|
M_BMPHANDLERDATA->m_bpp = bpp; // mono as well?
|
||||||
|
|
||||||
|
XpmFreeAttributes(&xpmAttr);
|
||||||
|
|
||||||
|
M_BMPHANDLERDATA->m_bitmap = (WXPixmap) pixmap;
|
||||||
|
|
||||||
|
if (mask)
|
||||||
|
{
|
||||||
|
M_BMPHANDLERDATA->m_mask = new wxMask;
|
||||||
|
M_BMPHANDLERDATA->m_mask->SetBitmap( (WXPixmap) mask );
|
||||||
|
M_BMPHANDLERDATA->m_mask->SetDisplay( xdisplay );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
#elif wxUSE_STREAMS
|
||||||
|
wxXPMDecoder decoder;
|
||||||
|
wxFileInputStream stream(name);
|
||||||
|
if (stream.Ok())
|
||||||
|
{
|
||||||
|
wxImage image(decoder.ReadFile(stream));
|
||||||
|
if (image.Ok())
|
||||||
|
return CreateFromImage(image);
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
#endif // wxHAVE_LIB_XPM / wxUSE_STREAMS
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxXPMFileHandler::SaveFile(const wxBitmap *bitmap, const wxString& name,
|
||||||
|
int type,
|
||||||
|
const wxPalette *WXUNUSED(palette))
|
||||||
|
{
|
||||||
|
wxImage image(bitmap->ConvertToImage());
|
||||||
|
if (image.Ok()) return image.SaveFile( name, (wxBitmapType)type );
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxHAVE_LIB_XPM || wxUSE_STREAMS
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxXPMDataHandler
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxXPMDataHandler : public wxBitmapHandler
|
||||||
|
{
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxXPMDataHandler);
|
||||||
|
public:
|
||||||
|
wxXPMDataHandler()
|
||||||
|
{
|
||||||
|
m_name = "XPM data";
|
||||||
|
m_extension = "xpm";
|
||||||
|
m_type = wxBITMAP_TYPE_XPM_DATA;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
|
||||||
|
int desiredWidth, int desiredHeight)
|
||||||
|
{ return FALSE; }
|
||||||
|
|
||||||
|
virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name,
|
||||||
|
int type, const wxPalette *palette = NULL)
|
||||||
|
{ return FALSE; }
|
||||||
|
|
||||||
|
virtual bool Create(wxBitmap *bitmap, void *data, long flags,
|
||||||
|
int width, int height, int depth = 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler, wxBitmapHandler);
|
||||||
|
|
||||||
|
bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *bits,
|
||||||
|
long WXUNUSED(flags),
|
||||||
|
int width, int height, int WXUNUSED(depth))
|
||||||
|
{
|
||||||
|
#if wxHAVE_LIB_XPM
|
||||||
|
wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
|
||||||
|
|
||||||
|
if (!bitmap->GetRefData())
|
||||||
|
bitmap->SetRefData( new wxBitmapRefData() );
|
||||||
|
|
||||||
|
M_BMPHANDLERDATA->m_display = wxGlobalDisplay();
|
||||||
|
|
||||||
|
Display *xdisplay = (Display*) M_BMPHANDLERDATA->m_display;
|
||||||
|
|
||||||
|
int xscreen = DefaultScreen( xdisplay );
|
||||||
|
Window xroot = RootWindow( xdisplay, xscreen );
|
||||||
|
|
||||||
|
int bpp = DefaultDepth( xdisplay, xscreen );
|
||||||
|
|
||||||
|
XpmAttributes xpmAttr;
|
||||||
|
xpmAttr.valuemask = XpmReturnInfos; // nothing yet, but get infos back
|
||||||
|
|
||||||
|
Pixmap pixmap = 0;
|
||||||
|
Pixmap mask = 0;
|
||||||
|
|
||||||
|
int ErrorStatus = XpmCreatePixmapFromData( xdisplay, xroot, (char**) bits,
|
||||||
|
&pixmap, &mask, &xpmAttr );
|
||||||
|
|
||||||
|
if (ErrorStatus == XpmSuccess)
|
||||||
|
{
|
||||||
|
M_BMPHANDLERDATA->m_width = xpmAttr.width;
|
||||||
|
M_BMPHANDLERDATA->m_height = xpmAttr.height;
|
||||||
|
|
||||||
|
M_BMPHANDLERDATA->m_bpp = bpp; // mono as well?
|
||||||
|
|
||||||
|
#if __WXDEBUG__
|
||||||
|
unsigned int depthRet;
|
||||||
|
int xRet, yRet;
|
||||||
|
unsigned int widthRet, heightRet, borderWidthRet;
|
||||||
|
XGetGeometry( xdisplay, pixmap, &xroot, &xRet, &yRet,
|
||||||
|
&widthRet, &heightRet, &borderWidthRet, &depthRet);
|
||||||
|
|
||||||
|
wxASSERT_MSG( bpp == (int)depthRet, wxT("colour depth mismatch") );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
XpmFreeAttributes(&xpmAttr);
|
||||||
|
|
||||||
|
M_BMPHANDLERDATA->m_pixmap = (WXPixmap) pixmap;
|
||||||
|
|
||||||
|
if (mask)
|
||||||
|
{
|
||||||
|
M_BMPHANDLERDATA->m_mask = new wxMask;
|
||||||
|
M_BMPHANDLERDATA->m_mask->SetBitmap( (WXPixmap) mask );
|
||||||
|
M_BMPHANDLERDATA->m_mask->SetDisplay( xdisplay );
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bitmap->UnRef();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
wxXPMDecoder decoder;
|
||||||
|
wxImage image(decoder.ReadData(bits));
|
||||||
|
if (image.Ok())
|
||||||
|
return bitmap->CreateFromImage(image);
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_XPM
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxXBMDataHandler
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxXBMDataHandler: public wxBitmapHandler
|
||||||
|
{
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxXBMDataHandler)
|
||||||
|
public:
|
||||||
|
inline wxXBMDataHandler()
|
||||||
|
{
|
||||||
|
m_name = "XBM data";
|
||||||
|
m_extension = "xbm";
|
||||||
|
m_type = wxBITMAP_TYPE_XBM_DATA;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
|
||||||
|
int desiredWidth, int desiredHeight)
|
||||||
|
{ return FALSE; }
|
||||||
|
|
||||||
|
virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name,
|
||||||
|
int type, const wxPalette *palette = NULL)
|
||||||
|
{ return FALSE; }
|
||||||
|
|
||||||
|
virtual bool Create(wxBitmap *bitmap, void *data, long flags,
|
||||||
|
int width, int height, int depth = 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxXBMDataHandler, wxBitmapHandler);
|
||||||
|
|
||||||
|
bool wxXBMDataHandler::Create( wxBitmap *bitmap, void *bits,
|
||||||
|
long WXUNUSED(flags),
|
||||||
|
int width, int height, int depth)
|
||||||
|
{
|
||||||
|
#if !wxUSE_NANOX
|
||||||
|
if (!bitmap->GetRefData())
|
||||||
|
bitmap->SetRefData( new wxBitmapRefData() );
|
||||||
|
|
||||||
|
M_BMPHANDLERDATA->m_display = wxGlobalDisplay();
|
||||||
|
|
||||||
|
Display *xdisplay = (Display*) M_BMPHANDLERDATA->m_display;
|
||||||
|
|
||||||
|
int xscreen = DefaultScreen( xdisplay );
|
||||||
|
Window xroot = RootWindow( xdisplay, xscreen );
|
||||||
|
|
||||||
|
M_BMPHANDLERDATA->m_mask = (wxMask *) NULL;
|
||||||
|
M_BMPHANDLERDATA->m_bitmap =
|
||||||
|
(WXPixmap) XCreateBitmapFromData( xdisplay, xroot,
|
||||||
|
(char *) bits, width, height );
|
||||||
|
M_BMPHANDLERDATA->m_width = width;
|
||||||
|
M_BMPHANDLERDATA->m_height = height;
|
||||||
|
M_BMPHANDLERDATA->m_bpp = 1;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
#endif
|
||||||
|
wxCHECK_MSG( M_BMPHANDLERDATA->m_bitmap, FALSE,
|
||||||
|
wxT("couldn't create bitmap") );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmap::InitStandardHandlers()
|
||||||
|
{
|
||||||
|
AddHandler(new wxXBMDataHandler);
|
||||||
|
#if wxUSE_XPM
|
||||||
|
#if wxHAVE_LIB_XPM || wxUSE_STREAMS
|
||||||
|
AddHandler(new wxXPMFileHandler);
|
||||||
|
#endif
|
||||||
|
AddHandler(new wxXPMDataHandler);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user