1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
1999-11-24 07:30:56 -05:00
|
|
|
// Name: wx/msw/bitmap.h
|
1998-05-20 10:12:05 -04:00
|
|
|
// Purpose: wxBitmap class
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 01/02/97
|
|
|
|
// RCS-ID: $Id$
|
1998-08-07 19:52:45 -04:00
|
|
|
// Copyright: (c) Julian Smart
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-07 19:52:45 -04:00
|
|
|
#ifndef _WX_BITMAP_H_
|
|
|
|
#define _WX_BITMAP_H_
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2003-08-09 08:38:21 -04:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
1999-11-13 21:22:27 -05:00
|
|
|
#pragma interface "bitmap.h"
|
1998-05-20 10:12:05 -04:00
|
|
|
#endif
|
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
#include "wx/msw/gdiimage.h"
|
1998-05-20 10:12:05 -04:00
|
|
|
#include "wx/gdicmn.h"
|
|
|
|
#include "wx/palette.h"
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxBitmap;
|
|
|
|
class WXDLLEXPORT wxBitmapHandler;
|
2003-01-22 12:43:02 -05:00
|
|
|
class WXDLLEXPORT wxBitmapRefData;
|
1999-01-31 06:42:58 -05:00
|
|
|
class WXDLLEXPORT wxControl;
|
2003-03-22 20:45:37 -05:00
|
|
|
class WXDLLEXPORT wxCursor;
|
|
|
|
class WXDLLEXPORT wxDC;
|
2003-07-11 17:43:57 -04:00
|
|
|
#if wxUSE_WXDIB
|
2003-03-22 20:45:37 -05:00
|
|
|
class WXDLLEXPORT wxDIB;
|
2003-07-11 17:43:57 -04:00
|
|
|
#endif
|
2003-03-22 20:45:37 -05:00
|
|
|
class WXDLLEXPORT wxIcon;
|
2001-04-04 19:15:36 -04:00
|
|
|
class WXDLLEXPORT wxImage;
|
2003-03-22 20:45:37 -05:00
|
|
|
class WXDLLEXPORT wxMask;
|
2001-09-30 18:06:39 -04:00
|
|
|
class WXDLLEXPORT wxPalette;
|
2003-04-27 21:46:05 -04:00
|
|
|
class WXDLLEXPORT wxPixelDataBase;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxBitmap: a mono or colour bitmap
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
class WXDLLEXPORT wxBitmap : public wxGDIImage
|
|
|
|
{
|
1998-05-20 10:12:05 -04:00
|
|
|
public:
|
1999-11-13 21:22:27 -05:00
|
|
|
// default ctor creates an invalid bitmap, you must Create() it later
|
2004-01-15 08:49:22 -05:00
|
|
|
wxBitmap() { Init(); }
|
1999-11-13 21:22:27 -05:00
|
|
|
|
|
|
|
// Copy constructors
|
2004-09-16 18:36:12 -04:00
|
|
|
wxBitmap(const wxBitmap& bitmap) : wxGDIImage(bitmap) { Init(); Ref(bitmap); }
|
1999-11-13 21:22:27 -05:00
|
|
|
|
|
|
|
// Initialize with raw data
|
|
|
|
wxBitmap(const char bits[], int width, int height, int depth = 1);
|
|
|
|
|
|
|
|
// Initialize with XPM data
|
2004-01-15 08:49:22 -05:00
|
|
|
wxBitmap(const char **data) { CreateFromXpm(data); }
|
|
|
|
wxBitmap(char **data) { CreateFromXpm((const char **)data); }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
// Load a file or resource
|
2001-04-11 14:04:34 -04:00
|
|
|
wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
// New constructor for generalised creation from data
|
|
|
|
wxBitmap(void *data, long type, int width, int height, int depth = 1);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2003-03-22 14:02:05 -05:00
|
|
|
// Create a new, uninitialized bitmap of the given size and depth (if it
|
|
|
|
// is omitted, will create a bitmap compatible with the display)
|
|
|
|
//
|
|
|
|
// NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
|
|
|
|
// taking a DC argument if you want to force using DDB in this case
|
1999-11-13 21:22:27 -05:00
|
|
|
wxBitmap(int width, int height, int depth = -1);
|
2001-04-23 19:31:42 -04:00
|
|
|
|
2003-03-22 14:02:05 -05:00
|
|
|
// Create a bitmap compatible with the given DC
|
|
|
|
wxBitmap(int width, int height, const wxDC& dc);
|
|
|
|
|
2004-04-04 08:57:36 -04:00
|
|
|
#if wxUSE_IMAGE && wxUSE_WXDIB
|
2003-03-22 14:02:05 -05:00
|
|
|
// Convert from wxImage
|
2004-01-15 08:49:22 -05:00
|
|
|
wxBitmap(const wxImage& image, int depth = -1)
|
|
|
|
{ (void)CreateFromImage(image, depth); }
|
2003-03-22 14:02:05 -05:00
|
|
|
|
|
|
|
// Create a DDB compatible with the given DC from wxImage
|
2004-01-15 08:49:22 -05:00
|
|
|
wxBitmap(const wxImage& image, const wxDC& dc)
|
|
|
|
{ (void)CreateFromImage(image, dc); }
|
2001-04-23 19:31:42 -04:00
|
|
|
#endif // wxUSE_IMAGE
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
// we must have this, otherwise icons are silently copied into bitmaps using
|
|
|
|
// the copy ctor but the resulting bitmap is invalid!
|
2004-01-15 08:49:22 -05:00
|
|
|
wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
wxBitmap& operator=(const wxBitmap& bitmap)
|
|
|
|
{
|
|
|
|
if ( m_refData != bitmap.m_refData )
|
|
|
|
Ref(bitmap);
|
|
|
|
return *this;
|
|
|
|
}
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
wxBitmap& operator=(const wxIcon& icon)
|
|
|
|
{
|
|
|
|
(void)CopyFromIcon(icon);
|
1999-11-12 19:30:45 -05:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
return *this;
|
|
|
|
}
|
1999-11-12 19:30:45 -05:00
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
wxBitmap& operator=(const wxCursor& cursor)
|
|
|
|
{
|
|
|
|
(void)CopyFromCursor(cursor);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
virtual ~wxBitmap();
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2004-04-04 08:57:36 -04:00
|
|
|
#if wxUSE_IMAGE && wxUSE_WXDIB
|
2001-04-04 19:15:36 -04:00
|
|
|
wxImage ConvertToImage() const;
|
2001-04-23 19:31:42 -04:00
|
|
|
#endif // wxUSE_IMAGE
|
2001-04-04 19:15:36 -04:00
|
|
|
|
2000-01-21 16:38:51 -05:00
|
|
|
// get the given part of bitmap
|
2000-01-13 06:07:58 -05:00
|
|
|
wxBitmap GetSubBitmap( const wxRect& rect ) const;
|
2001-04-23 19:31:42 -04:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
// copies the contents and mask of the given (colour) icon to the bitmap
|
|
|
|
bool CopyFromIcon(const wxIcon& icon);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
// copies the contents and mask of the given cursor to the bitmap
|
|
|
|
bool CopyFromCursor(const wxCursor& cursor);
|
|
|
|
|
2003-07-11 17:43:57 -04:00
|
|
|
#if wxUSE_WXDIB
|
2003-03-22 20:45:37 -05:00
|
|
|
// copies from a device independent bitmap
|
|
|
|
bool CopyFromDIB(const wxDIB& dib);
|
2003-07-11 17:43:57 -04:00
|
|
|
#endif
|
2003-03-22 20:45:37 -05:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
virtual bool Create(int width, int height, int depth = -1);
|
2003-03-22 14:02:05 -05:00
|
|
|
virtual bool Create(int width, int height, const wxDC& dc);
|
1999-11-13 21:22:27 -05:00
|
|
|
virtual bool Create(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);
|
|
|
|
|
2003-01-22 12:43:02 -05:00
|
|
|
wxBitmapRefData *GetBitmapData() const
|
|
|
|
{ return (wxBitmapRefData *)m_refData; }
|
1999-11-24 07:30:56 -05:00
|
|
|
|
2003-03-22 14:02:05 -05:00
|
|
|
// raw bitmap access support functions
|
2003-04-27 21:46:05 -04:00
|
|
|
void *GetRawData(wxPixelDataBase& data, int bpp);
|
|
|
|
void UngetRawData(wxPixelDataBase& data);
|
2003-03-22 14:02:05 -05:00
|
|
|
|
2001-09-30 18:06:39 -04:00
|
|
|
#if wxUSE_PALETTE
|
2003-01-22 12:43:02 -05:00
|
|
|
wxPalette* GetPalette() const;
|
1999-11-13 21:22:27 -05:00
|
|
|
void SetPalette(const wxPalette& palette);
|
2001-09-30 18:06:39 -04:00
|
|
|
#endif // wxUSE_PALETTE
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2003-01-22 12:43:02 -05:00
|
|
|
wxMask *GetMask() const;
|
2003-03-03 21:12:28 -05:00
|
|
|
void SetMask(wxMask *mask);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
|
|
|
|
bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
|
1999-01-19 06:00:22 -05:00
|
|
|
|
2003-04-13 09:45:20 -04:00
|
|
|
// these functions are internal and shouldn't be used, they risk to
|
|
|
|
// disappear in the future
|
2003-03-03 21:12:28 -05:00
|
|
|
bool HasAlpha() const;
|
2003-04-13 09:45:20 -04:00
|
|
|
void UseAlpha();
|
2003-01-22 12:43:02 -05:00
|
|
|
|
|
|
|
#if WXWIN_COMPATIBILITY_2_4
|
|
|
|
// these functions do nothing and are only there for backwards
|
|
|
|
// compatibility
|
|
|
|
wxDEPRECATED( int GetQuality() const );
|
|
|
|
wxDEPRECATED( void SetQuality(int quality) );
|
|
|
|
#endif // WXWIN_COMPATIBILITY_2_4
|
|
|
|
|
2003-03-22 14:02:05 -05:00
|
|
|
// implementation only from now on
|
|
|
|
// -------------------------------
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
public:
|
1999-11-24 07:30:56 -05:00
|
|
|
void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
|
|
|
|
WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
|
|
|
|
|
2003-03-03 21:12:28 -05:00
|
|
|
#ifdef __WXDEBUG__
|
2003-01-22 12:43:02 -05:00
|
|
|
void SetSelectedInto(wxDC *dc);
|
|
|
|
wxDC *GetSelectedInto() const;
|
2003-03-03 21:12:28 -05:00
|
|
|
#endif // __WXDEBUG__
|
1999-11-24 07:30:56 -05:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
protected:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
1998-09-03 03:34:26 -04:00
|
|
|
|
2003-01-22 12:43:02 -05:00
|
|
|
virtual wxGDIImageRefData *CreateData() const;
|
2004-07-23 14:52:18 -04:00
|
|
|
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
|
1999-11-24 07:30:56 -05:00
|
|
|
|
2000-01-21 16:38:51 -05:00
|
|
|
// creates the bitmap from XPM data, supposed to be called from ctor
|
|
|
|
bool CreateFromXpm(const char **bits);
|
2001-04-23 19:31:42 -04:00
|
|
|
|
2003-03-22 14:02:05 -05:00
|
|
|
// creates an uninitialized bitmap, called from Create()s above
|
|
|
|
bool DoCreate(int w, int h, int depth, WXHDC hdc);
|
|
|
|
|
2004-04-04 08:57:36 -04:00
|
|
|
#if wxUSE_IMAGE && wxUSE_WXDIB
|
2001-04-04 19:15:36 -04:00
|
|
|
// creates the bitmap from wxImage, supposed to be called from ctor
|
|
|
|
bool CreateFromImage(const wxImage& image, int depth);
|
2000-01-21 16:38:51 -05:00
|
|
|
|
2003-03-22 14:02:05 -05:00
|
|
|
// creates a DDB from wxImage, supposed to be called from ctor
|
|
|
|
bool CreateFromImage(const wxImage& image, const wxDC& dc);
|
2003-01-22 12:43:02 -05:00
|
|
|
|
2003-03-22 14:02:05 -05:00
|
|
|
// common part of the 2 methods above (hdc may be 0)
|
|
|
|
bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
|
|
|
|
#endif // wxUSE_IMAGE
|
2003-01-02 18:28:56 -05:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
private:
|
1999-11-24 07:30:56 -05:00
|
|
|
#ifdef __WIN32__
|
|
|
|
// common part of CopyFromIcon/CopyFromCursor for Win32
|
|
|
|
bool CopyFromIconOrCursor(const wxGDIImage& icon);
|
|
|
|
#endif // __WIN32__
|
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxBitmap)
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
1999-01-19 06:00:22 -05:00
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMask: a mono bitmap used for drawing bitmaps transparently.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxMask : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxMask();
|
|
|
|
|
|
|
|
// Construct a mask from a bitmap and a colour indicating the transparent
|
|
|
|
// area
|
|
|
|
wxMask(const wxBitmap& bitmap, const wxColour& colour);
|
|
|
|
|
|
|
|
// Construct a mask from a bitmap and a palette index indicating the
|
|
|
|
// transparent area
|
|
|
|
wxMask(const wxBitmap& bitmap, int paletteIndex);
|
|
|
|
|
|
|
|
// Construct a mask from a mono bitmap (copies the bitmap).
|
|
|
|
wxMask(const wxBitmap& bitmap);
|
|
|
|
|
|
|
|
// construct a mask from the givne bitmap handle
|
|
|
|
wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
|
|
|
|
|
|
|
|
virtual ~wxMask();
|
|
|
|
|
|
|
|
bool Create(const wxBitmap& bitmap, const wxColour& colour);
|
|
|
|
bool Create(const wxBitmap& bitmap, int paletteIndex);
|
|
|
|
bool Create(const wxBitmap& bitmap);
|
|
|
|
|
|
|
|
// Implementation
|
|
|
|
WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
|
|
|
|
void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
WXHBITMAP m_maskBitmap;
|
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxMask)
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
|
|
|
|
wxBitmapHandler(const wxString& name, const wxString& ext, long 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,
|
|
|
|
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);
|
|
|
|
|
|
|
|
virtual bool Create(wxGDIImage *image,
|
|
|
|
void *data,
|
|
|
|
long flags,
|
|
|
|
int width, int height, int depth = 1);
|
|
|
|
virtual bool Load(wxGDIImage *image,
|
|
|
|
const wxString& name,
|
|
|
|
long flags,
|
|
|
|
int desiredWidth, int desiredHeight);
|
|
|
|
virtual bool Save(wxGDIImage *image,
|
|
|
|
const wxString& name,
|
|
|
|
int type);
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
|
|
|
|
};
|
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
#endif
|
1998-08-07 19:52:45 -04:00
|
|
|
// _WX_BITMAP_H_
|