reorganized wxBitmap/wxBitmapHandler classes to use wxBitmapType instead of "long" where possible; made them const-correct; introduce wxBITMAP_SCREEN_DEPTH instead of -1 for clearness (specially in the docs); remove wxBitmapHandler empty stubs and rename wxBitmapHandlerBase as wxBitmapHandler

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52820 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2008-03-25 20:31:48 +00:00
parent 0685aa9eb6
commit e86f2cc84a
22 changed files with 184 additions and 236 deletions

View File

@@ -40,6 +40,8 @@ DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLEXPORT)
// wxMask represents the transparent area of the bitmap
// ----------------------------------------------------------------------------
// TODO: all implementation of wxMask, except the generic one,
// do not derive from wxMaskBase,,, they should
class WXDLLEXPORT wxMaskBase : public wxObject
{
public:
@@ -78,8 +80,13 @@ protected:
#define wxUSE_BITMAP_BASE 0
#endif
// Only used by some ports
// FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
// a more readable way to tell
#define wxBITMAP_SCREEN_DEPTH (-1)
// All ports except wxMSW,wxOS2,wxPalmOS use wxBitmapHandler and wxBitmapBase as base class
// for wxBitmapHandler; wxMSW,wxOS2,wxPalmOS use wxGDIImageHandler as base class
// since it allows some code reuse there.
#if wxUSE_BITMAP_BASE
// ----------------------------------------------------------------------------
@@ -87,18 +94,29 @@ protected:
// different formats
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmapHandlerBase : public wxObject
class WXDLLEXPORT wxBitmapHandler : public wxObject
{
public:
wxBitmapHandlerBase() { m_type = wxBITMAP_TYPE_INVALID; }
virtual ~wxBitmapHandlerBase() { }
wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
virtual ~wxBitmapHandler() { }
virtual bool Create(wxBitmap *bitmap, const void* data, long flags,
int width, int height, int depth = 1);
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);
// NOTE: the following functions should be pure virtuals, but they aren't
// because otherwise almost all ports would have to implement
// them as "return false"...
virtual bool Create(wxBitmap *WXUNUSED(bitmap), const void* WXUNUSED(data),
wxBitmapType WXUNUSED(type), int WXUNUSED(width), int WXUNUSED(height),
int WXUNUSED(depth) = 1)
{ return false; }
virtual bool LoadFile(wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
wxBitmapType WXUNUSED(type), int WXUNUSED(desiredWidth),
int WXUNUSED(desiredHeight))
{ return false; }
virtual bool SaveFile(const wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
wxBitmapType WXUNUSED(type), const wxPalette *WXUNUSED(palette) = NULL) const
{ return false; }
void SetName(const wxString& name) { m_name = name; }
void SetExtension(const wxString& ext) { m_extension = ext; }
@@ -112,9 +130,14 @@ private:
wxString m_extension;
wxBitmapType m_type;
DECLARE_ABSTRACT_CLASS(wxBitmapHandlerBase)
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
};
// ----------------------------------------------------------------------------
// wxBitmap: class which represents platform-dependent bitmap (unlike wxImage)
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmapBase : public wxGDIObject
{
public:
@@ -122,17 +145,18 @@ public:
Derived class must implement these:
wxBitmap();
wxBitmap(int width, int height, int depth = -1);
wxBitmap(const wxBitmap& bmp);
wxBitmap(const char bits[], int width, int height, int depth = 1);
wxBitmap(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
wxBitmap(const char* const* bits);
wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
wxBitmap(const wxImage& image, int depth = -1);
bool Create(int width, int height, int depth = -1);
wxBitmap(const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH);
static void InitStandardHandlers();
*/
virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
virtual int GetHeight() const = 0;
virtual int GetWidth() const = 0;
virtual int GetDepth() const = 0;
@@ -173,8 +197,8 @@ public:
// Format handling
static inline wxList& GetHandlers() { return sm_handlers; }
static void AddHandler(wxBitmapHandlerBase *handler);
static void InsertHandler(wxBitmapHandlerBase *handler);
static void AddHandler(wxBitmapHandler *handler);
static void InsertHandler(wxBitmapHandler *handler);
static bool RemoveHandler(const wxString& name);
static wxBitmapHandler *FindHandler(const wxString& name);
static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType bitmapType);

View File

@@ -135,7 +135,7 @@ public:
wxMask *GetMask() const;
void SetMask(wxMask *mask) ;
int GetBitmapType() const;
wxBitmapType GetBitmapType() const;
// wxCocoa
WX_NSBitmapImageRep GetNSBitmapImageRep();
@@ -152,9 +152,5 @@ protected:
DECLARE_DYNAMIC_CLASS(wxBitmap)
};
class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
{
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
};
#endif // __WX_COCOA_BITMAP_H__

View File

@@ -21,11 +21,6 @@ wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
// wxBitmap
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxBitmapHandler : public wxBitmapHandlerBase
{
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
};
class WXDLLIMPEXP_CORE wxBitmap : public wxBitmapBase
{
public:
@@ -55,7 +50,8 @@ public:
virtual wxBitmap GetSubBitmap(const wxRect& rect) const;
virtual bool SaveFile(const wxString &name, wxBitmapType type, const wxPalette *palette = (wxPalette *) NULL) const;
virtual bool SaveFile(const wxString &name, wxBitmapType type,
const wxPalette *palette = (wxPalette *) NULL) const;
virtual bool LoadFile(const wxString &name, wxBitmapType type = wxBITMAP_TYPE_RESOURCE);
#if wxUSE_PALETTE

View File

@@ -51,23 +51,22 @@ class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase
{
public:
wxBitmap() { }
wxBitmap( int width, int height, int depth = -1 );
wxBitmap( int width, int height, int depth = wxBITMAP_SCREEN_DEPTH );
wxBitmap( const char bits[], int width, int height, int depth = 1 );
wxBitmap( const char* const* bits );
#ifdef wxNEEDS_CHARPP
// needed for old GCC
wxBitmap(char** data)
{
*this = wxBitmap(wx_const_cast(const char* const*, data));
}
{ *this = wxBitmap(wx_const_cast(const char* const*, data)); }
#endif
wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM );
#if wxUSE_IMAGE
wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); }
wxBitmap( const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH )
{ (void)CreateFromImage(image, depth); }
#endif // wxUSE_IMAGE
virtual ~wxBitmap();
bool Create(int width, int height, int depth = -1);
bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
virtual int GetHeight() const;
virtual int GetWidth() const;
@@ -112,7 +111,8 @@ public:
GdkPixbuf *GetPixbuf() const;
// Basically, this corresponds to Win32 StretchBlt()
wxBitmap Rescale(int clipx, int clipy, int clipwidth, int clipheight, int width, int height) const;
wxBitmap Rescale(int clipx, int clipy, int clipwidth, int clipheight,
int width, int height) const;
// raw bitmap access support functions
void *GetRawData(wxPixelDataBase& data, int bpp);
@@ -150,13 +150,4 @@ private:
DECLARE_DYNAMIC_CLASS(wxBitmap)
};
//-----------------------------------------------------------------------------
// wxBitmapHandler
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
{
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
};
#endif // _WX_GTK_BITMAP_H_

View File

@@ -146,13 +146,5 @@ private:
DECLARE_DYNAMIC_CLASS(wxBitmap)
};
//-----------------------------------------------------------------------------
// wxBitmapHandler
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
{
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
};
#endif // __GTKBITMAPH__

View File

@@ -80,11 +80,6 @@ private:
};
class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
{
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
};
class WXDLLEXPORT wxBitmap: public wxBitmapBase
{
DECLARE_DYNAMIC_CLASS(wxBitmap)

View File

@@ -23,11 +23,6 @@ struct bitmap_t;
// wxBitmap
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
{
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
};
class WXDLLEXPORT wxBitmap: public wxBitmapBase
{
public:

View File

@@ -41,6 +41,7 @@ enum wxBitmapTransparency
// ----------------------------------------------------------------------------
// wxBitmap: a mono or colour bitmap
// NOTE: for wxMSW we don't use the wxBitmapBase base class declared in bitmap.h!
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmap : public wxGDIImage
@@ -65,7 +66,7 @@ public:
wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
// New constructor for generalised creation from data
wxBitmap(const void* data, long type, int width, int height, int depth = 1);
wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1);
// Create a new, uninitialized bitmap of the given size and depth (if it
// is omitted, will create a bitmap compatible with the display)
@@ -135,11 +136,11 @@ public:
bool CopyFromDIB(const wxDIB& dib);
#endif
virtual bool Create(int width, int height, int depth = -1);
virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
virtual bool Create(int width, int height, const wxDC& dc);
virtual bool Create(const void* data, long type, int width, int height, int depth = 1);
virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
wxBitmapRefData *GetBitmapData() const
{ return (wxBitmapRefData *)m_refData; }
@@ -244,45 +245,49 @@ protected:
DECLARE_DYNAMIC_CLASS(wxMask)
};
// ----------------------------------------------------------------------------
// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
// NOTE: for wxMSW we don't use the wxBitmapHandler class declared in bitmap.h!
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
{
public:
wxBitmapHandler() { }
wxBitmapHandler(const wxString& name, const wxString& ext, long type)
: wxGDIImageHandler(name, ext, type)
{
}
wxBitmapHandler(const wxString& name, const wxString& ext, wxBitmapType type)
: wxGDIImageHandler(name, ext, type) { }
// keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
// old class which worked only with bitmaps
virtual bool Create(wxBitmap *bitmap,
const void* data,
long flags,
int width, int height, int depth = 1);
virtual bool LoadFile(wxBitmap *bitmap,
const wxString& name,
long flags,
int desiredWidth, int desiredHeight);
virtual bool SaveFile(wxBitmap *bitmap,
const wxString& name,
int type,
const wxPalette *palette = NULL);
// implement wxGDIImageHandler's pure virtuals:
virtual bool Create(wxGDIImage *image,
const void* data,
long flags,
wxBitmapType type,
int width, int height, int depth = 1);
virtual bool Load(wxGDIImage *image,
const wxString& name,
long flags,
wxBitmapType type,
int desiredWidth, int desiredHeight);
virtual bool Save(wxGDIImage *image,
virtual bool Save(const wxGDIImage *image,
const wxString& name,
int type);
wxBitmapType type) const;
// make wxBitmapHandler compatible with the wxBitmapHandler interface
// declared in bitmap.h, even if it's derived from wxGDIImageHandler:
virtual bool Create(wxBitmap *bitmap,
const void* data,
wxBitmapType type,
int width, int height, int depth = 1);
virtual bool LoadFile(wxBitmap *bitmap,
const wxString& name,
wxBitmapType type,
int desiredWidth, int desiredHeight);
virtual bool SaveFile(const wxBitmap *bitmap,
const wxString& name,
wxBitmapType type,
const wxPalette *palette = NULL) const;
private:
DECLARE_DYNAMIC_CLASS(wxBitmapHandler)

View File

@@ -76,51 +76,6 @@ public:
};
};
// ----------------------------------------------------------------------------
// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGDIImageHandler : public wxObject
{
public:
// ctor
wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; }
wxGDIImageHandler(const wxString& name,
const wxString& ext,
long type)
: m_name(name), m_extension(ext)
{
m_type = type;
}
// accessors
void SetName(const wxString& name) { m_name = name; }
void SetExtension(const wxString& ext) { m_extension = ext; }
void SetType(long type) { m_type = type; }
const wxString& GetName() const { return m_name; }
const wxString& GetExtension() const { return m_extension; }
long GetType() const { return m_type; }
// real handler operations: to implement in derived classes
virtual bool Create(wxGDIImage *image,
const void* data,
long flags,
int width, int height, int depth = 1) = 0;
virtual bool Load(wxGDIImage *image,
const wxString& name,
long flags,
int desiredWidth, int desiredHeight) = 0;
virtual bool Save(wxGDIImage *image,
const wxString& name,
int type) = 0;
protected:
wxString m_name;
wxString m_extension;
long m_type;
};
// ----------------------------------------------------------------------------
// wxGDIImage: this class supports GDI image handlers which may be registered
// dynamically and will be used for loading/saving the images in the specified
@@ -192,4 +147,46 @@ protected:
static wxGDIImageHandlerList ms_handlers;
};
// ----------------------------------------------------------------------------
// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGDIImageHandler : public wxObject
{
public:
// ctor
wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; }
wxGDIImageHandler(const wxString& name,
const wxString& ext,
wxBitmapType type)
: m_name(name), m_extension(ext), m_type(type) { }
// accessors
void SetName(const wxString& name) { m_name = name; }
void SetExtension(const wxString& ext) { m_extension = ext; }
void SetType(wxBitmapType type) { m_type = type; }
const wxString& GetName() const { return m_name; }
const wxString& GetExtension() const { return m_extension; }
wxBitmapType GetType() const { return m_type; }
// real handler operations: to implement in derived classes
virtual bool Create(wxGDIImage *image,
const void* data,
wxBitmapType flags,
int width, int height, int depth = 1) = 0;
virtual bool Load(wxGDIImage *image,
const wxString& name,
wxBitmapType flags,
int desiredWidth, int desiredHeight) = 0;
virtual bool Save(const wxGDIImage *image,
const wxString& name,
wxBitmapType type) const = 0;
protected:
wxString m_name;
wxString m_extension;
wxBitmapType m_type;
};
#endif // _WX_MSW_GDIIMAGE_H_

View File

@@ -54,7 +54,7 @@ public:
#endif
// from resource/file
wxIcon(const wxString& name,
long type = wxBITMAP_TYPE_ICO_RESOURCE,
wxBitmapType type = wxBITMAP_TYPE_ICO_RESOURCE,
int desiredWidth = -1, int desiredHeight = -1);
wxIcon(const wxIconLocation& loc);
@@ -62,7 +62,7 @@ public:
virtual ~wxIcon();
virtual bool LoadFile(const wxString& name,
long type = wxBITMAP_TYPE_ICO_RESOURCE,
wxBitmapType type = wxBITMAP_TYPE_ICO_RESOURCE,
int desiredWidth = -1, int desiredHeight = -1);
// implementation only from now on

View File

@@ -287,7 +287,7 @@ public:
inline wxBitmapHandler( const wxString& rName
,const wxString& rExt
,long lType
,wxBitmapType lType
)
: wxGDIImageHandler( rName
,rExt
@@ -299,28 +299,28 @@ public:
// old class which worked only with bitmaps
virtual bool Create( wxBitmap* pBitmap
,const void* pData
,long lFlags
,wxBitmapType lType
,int nWidth
,int nHeight
,int nDepth = 1
);
virtual bool LoadFile( wxBitmap* pBitmap
,int nId
,long lFlags
,wxBitmapType lType
,int nDesiredWidth
,int nDesiredHeight
);
virtual bool LoadFile( wxBitmap* pBitmap
,const wxString& rName
,long lFlags
,wxBitmapType lType
,int nDesiredWidth
,int nDesiredHeight
);
virtual bool SaveFile( wxBitmap* pBitmap
,const wxString& rName
,int lType
,wxBitmapType lType
,const wxPalette* pPalette = NULL
);
) const;
virtual bool Create( wxGDIImage* pImage
,const void* pData
@@ -338,7 +338,7 @@ public:
virtual bool Save( wxGDIImage* pImage
,const wxString& rName
,int lType
);
) const;
private:
inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
,const wxString& WXUNUSED(rName)

View File

@@ -62,11 +62,6 @@ private:
// wxBitmap
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
{
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
};
class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase
{
public: