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
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
#include "wx/msw/gdiimage.h"
|
1998-05-20 10:12:05 -04:00
|
|
|
#include "wx/palette.h"
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxBitmap;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxBitmapRefData;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxControl;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxCursor;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxDC;
|
2003-07-11 17:43:57 -04:00
|
|
|
#if wxUSE_WXDIB
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxDIB;
|
2003-07-11 17:43:57 -04:00
|
|
|
#endif
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxIcon;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxImage;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxMask;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxPalette;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2007-07-21 18:56:07 -04:00
|
|
|
// What kind of transparency should a bitmap copied from an icon or cursor
|
|
|
|
// have?
|
|
|
|
enum wxBitmapTransparency
|
|
|
|
{
|
|
|
|
wxBitmapTransparency_Auto, // default: copy alpha if the source has it
|
|
|
|
wxBitmapTransparency_None, // never create alpha
|
|
|
|
wxBitmapTransparency_Always // always use alpha
|
|
|
|
};
|
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxBitmap: a mono or colour bitmap
|
2008-03-25 16:31:48 -04:00
|
|
|
// NOTE: for wxMSW we don't use the wxBitmapBase base class declared in bitmap.h!
|
1999-11-24 07:30:56 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage
|
1999-11-24 07:30:56 -05:00
|
|
|
{
|
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
|
2006-02-08 19:51:23 -05:00
|
|
|
wxBitmap() { }
|
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
|
2006-10-08 04:04:49 -04:00
|
|
|
wxBitmap(const char* const* data);
|
2006-10-31 20:16:01 -05:00
|
|
|
#ifdef wxNEEDS_CHARPP
|
2006-10-29 15:36:43 -05:00
|
|
|
wxBitmap(char** data)
|
|
|
|
{
|
2008-11-01 22:39:52 -04:00
|
|
|
*this = wxBitmap(const_cast<const char* const*>(data));
|
2006-10-29 15:36:43 -05:00
|
|
|
}
|
|
|
|
#endif
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
// Load a file or resource
|
2008-09-21 16:03:14 -04:00
|
|
|
wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
// New constructor for generalised creation from data
|
2008-03-25 16:31:48 -04:00
|
|
|
wxBitmap(const void* data, wxBitmapType 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
|
2009-03-14 09:57:51 -04:00
|
|
|
wxBitmap(int width, int height, int depth = -1) { (void)Create(width, height, depth); }
|
|
|
|
wxBitmap(const wxSize& sz, int depth = -1) { (void)Create(sz, depth); }
|
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);
|
|
|
|
|
2006-03-20 18:23:00 -05:00
|
|
|
#if wxUSE_IMAGE
|
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!
|
2007-07-21 18:56:07 -04:00
|
|
|
wxBitmap(const wxIcon& icon,
|
|
|
|
wxBitmapTransparency transp = wxBitmapTransparency_Auto)
|
|
|
|
{
|
|
|
|
CopyFromIcon(icon, transp);
|
|
|
|
}
|
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
|
|
|
|
2006-03-20 18:23:00 -05:00
|
|
|
#if wxUSE_IMAGE
|
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
|
|
|
|
2007-08-20 19:26:35 -04:00
|
|
|
// NB: This should not be called from user code. It is for wx internal
|
2008-09-21 16:03:14 -04:00
|
|
|
// use only.
|
2007-08-20 19:26:35 -04:00
|
|
|
wxBitmap GetSubBitmapOfHDC( const wxRect& rect, WXHDC hdc ) const;
|
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
// copies the contents and mask of the given (colour) icon to the bitmap
|
2007-07-21 18:56:07 -04:00
|
|
|
bool CopyFromIcon(const wxIcon& icon,
|
|
|
|
wxBitmapTransparency transp = wxBitmapTransparency_Auto);
|
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
|
2007-07-21 18:56:07 -04:00
|
|
|
bool CopyFromCursor(const wxCursor& cursor,
|
|
|
|
wxBitmapTransparency transp = wxBitmapTransparency_Auto);
|
1999-11-24 07:30:56 -05:00
|
|
|
|
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
|
|
|
|
2008-03-25 16:31:48 -04:00
|
|
|
virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
|
2009-03-14 09:57:51 -04:00
|
|
|
virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
|
|
|
|
{ return Create(sz.GetWidth(), sz.GetHeight(), depth); }
|
|
|
|
|
2003-03-22 14:02:05 -05:00
|
|
|
virtual bool Create(int width, int height, const wxDC& dc);
|
2008-03-25 16:31:48 -04:00
|
|
|
virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
|
2008-09-21 16:03:14 -04:00
|
|
|
virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
|
2008-03-25 16:31:48 -04:00
|
|
|
virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
|
1999-11-13 21:22:27 -05:00
|
|
|
|
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;
|
2005-03-27 12:47:39 -05:00
|
|
|
wxBitmap GetMaskBitmap() const;
|
2003-03-03 21:12:28 -05:00
|
|
|
void SetMask(wxMask *mask);
|
1998-05-20 10:12:05 -04: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
|
|
|
|
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-01-22 12:43:02 -05:00
|
|
|
void SetSelectedInto(wxDC *dc);
|
|
|
|
wxDC *GetSelectedInto() const;
|
1999-11-24 07:30:56 -05:00
|
|
|
|
1999-11-13 21:22:27 -05:00
|
|
|
protected:
|
2003-01-22 12:43:02 -05:00
|
|
|
virtual wxGDIImageRefData *CreateData() const;
|
2007-12-15 12:54:20 -05:00
|
|
|
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
|
1999-11-24 07:30:56 -05: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);
|
|
|
|
|
2006-03-20 18:23:00 -05:00
|
|
|
#if wxUSE_IMAGE
|
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
|
|
|
// common part of CopyFromIcon/CopyFromCursor for Win32
|
2007-07-21 18:56:07 -04:00
|
|
|
bool
|
|
|
|
CopyFromIconOrCursor(const wxGDIImage& icon,
|
|
|
|
wxBitmapTransparency transp = wxBitmapTransparency_Auto);
|
2006-03-20 18:23:00 -05:00
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
|
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.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxMask : public wxObject
|
1999-11-24 07:30:56 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxMask();
|
|
|
|
|
2006-10-31 09:43:04 -05:00
|
|
|
// Copy constructor
|
|
|
|
wxMask(const wxMask &mask);
|
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
// 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)
|
|
|
|
};
|
|
|
|
|
2008-03-25 16:31:48 -04:00
|
|
|
|
1999-11-24 07:30:56 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
|
2008-03-25 16:31:48 -04:00
|
|
|
// NOTE: for wxMSW we don't use the wxBitmapHandler class declared in bitmap.h!
|
1999-11-24 07:30:56 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler
|
1999-11-24 07:30:56 -05:00
|
|
|
{
|
|
|
|
public:
|
2006-10-08 11:59:15 -04:00
|
|
|
wxBitmapHandler() { }
|
2008-03-25 16:31:48 -04:00
|
|
|
wxBitmapHandler(const wxString& name, const wxString& ext, wxBitmapType type)
|
|
|
|
: wxGDIImageHandler(name, ext, type) { }
|
1999-11-24 07:30:56 -05:00
|
|
|
|
2008-03-25 16:31:48 -04:00
|
|
|
// implement wxGDIImageHandler's pure virtuals:
|
1999-11-24 07:30:56 -05:00
|
|
|
|
|
|
|
virtual bool Create(wxGDIImage *image,
|
2006-10-08 04:04:49 -04:00
|
|
|
const void* data,
|
2008-03-25 16:31:48 -04:00
|
|
|
wxBitmapType type,
|
1999-11-24 07:30:56 -05:00
|
|
|
int width, int height, int depth = 1);
|
|
|
|
virtual bool Load(wxGDIImage *image,
|
|
|
|
const wxString& name,
|
2008-03-25 16:31:48 -04:00
|
|
|
wxBitmapType type,
|
1999-11-24 07:30:56 -05:00
|
|
|
int desiredWidth, int desiredHeight);
|
2008-03-25 16:31:48 -04:00
|
|
|
virtual bool Save(const wxGDIImage *image,
|
1999-11-24 07:30:56 -05:00
|
|
|
const wxString& name,
|
2008-03-25 16:31:48 -04:00
|
|
|
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;
|
1999-11-24 07:30:56 -05:00
|
|
|
|
|
|
|
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_
|