]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/bitmap.h
1. fixed wxStaticBox background erasing (or, rather, restored the old bug)
[wxWidgets.git] / include / wx / msw / bitmap.h
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: bitmap.h
3// Purpose: wxBitmap class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
bbcdf8bc 8// Copyright: (c) Julian Smart
4fe5383d 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_BITMAP_H_
13#define _WX_BITMAP_H_
2bda0e17
KB
14
15#ifdef __GNUG__
4fe5383d 16 #pragma interface "bitmap.h"
2bda0e17
KB
17#endif
18
19#include "wx/gdiobj.h"
20#include "wx/gdicmn.h"
21#include "wx/palette.h"
22
23// Bitmap
24class WXDLLEXPORT wxDC;
25class WXDLLEXPORT wxControl;
26class WXDLLEXPORT wxBitmap;
27class WXDLLEXPORT wxBitmapHandler;
28class WXDLLEXPORT wxIcon;
29class WXDLLEXPORT wxCursor;
03ab016d 30class WXDLLEXPORT wxControl;
2bda0e17
KB
31
32// A mask is a mono bitmap used for drawing bitmaps
33// transparently.
34class WXDLLEXPORT wxMask: public wxObject
35{
36 DECLARE_DYNAMIC_CLASS(wxMask)
37
38public:
10fcf31a 39 wxMask();
2bda0e17
KB
40
41 // Construct a mask from a bitmap and a colour indicating
42 // the transparent area
43 wxMask(const wxBitmap& bitmap, const wxColour& colour);
44
45 // Construct a mask from a bitmap and a palette index indicating
46 // the transparent area
debe6624 47 wxMask(const wxBitmap& bitmap, int paletteIndex);
2bda0e17
KB
48
49 // Construct a mask from a mono bitmap (copies the bitmap).
50 wxMask(const wxBitmap& bitmap);
51
10fcf31a 52 ~wxMask();
2bda0e17
KB
53
54 bool Create(const wxBitmap& bitmap, const wxColour& colour);
debe6624 55 bool Create(const wxBitmap& bitmap, int paletteIndex);
2bda0e17
KB
56 bool Create(const wxBitmap& bitmap);
57
58 // Implementation
4fe5383d
VZ
59 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
60 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
61
2bda0e17
KB
62protected:
63 WXHBITMAP m_maskBitmap;
64};
65
66class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
67{
68 friend class WXDLLEXPORT wxBitmap;
69 friend class WXDLLEXPORT wxIcon;
70 friend class WXDLLEXPORT wxCursor;
71public:
10fcf31a
VZ
72 wxBitmapRefData();
73 ~wxBitmapRefData();
2bda0e17
KB
74
75public:
76 int m_width;
77 int m_height;
78 int m_depth;
79 bool m_ok;
80 int m_numColors;
81 wxPalette m_bitmapPalette;
82 int m_quality;
83
2049ba38 84#ifdef __WXMSW__
2bda0e17
KB
85 WXHBITMAP m_hBitmap;
86 wxDC * m_selectedInto; // So bitmap knows whether it's been selected into
87 // a device context (for error checking)
88 wxMask * m_bitmapMask; // Option mask
89#endif
90};
91
92#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
93
94class WXDLLEXPORT wxBitmapHandler: public wxObject
95{
96 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
97public:
4fe5383d 98 wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; };
2bda0e17 99
debe6624
JS
100 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
101 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
2bda0e17 102 int desiredWidth, int desiredHeight);
debe6624 103 virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
2bda0e17 104
4fe5383d
VZ
105 void SetName(const wxString& name) { m_name = name; }
106 void SetExtension(const wxString& ext) { m_extension = ext; }
107 void SetType(long type) { m_type = type; }
108 wxString GetName() const { return m_name; }
109 wxString GetExtension() const { return m_extension; }
110 long GetType() const { return m_type; }
2bda0e17
KB
111protected:
112 wxString m_name;
113 wxString m_extension;
114 long m_type;
115};
116#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
117
118class WXDLLEXPORT wxBitmap: public wxGDIObject
119{
4fe5383d 120friend class WXDLLEXPORT wxBitmapHandler;
2bda0e17
KB
121
122public:
4fe5383d
VZ
123 // default ctor creates an invalid bitmap, you must Create() it later
124 wxBitmap() { Init(); }
125
126 // Copy constructors
127 wxBitmap(const wxBitmap& bitmap) { Init(); Ref(bitmap); }
128
129 // Initialize with raw data
130 wxBitmap(const char bits[], int width, int height, int depth = 1);
131
132 // Initialize with XPM data
133 wxBitmap(char **data, wxControl *anItem = NULL);
2bda0e17 134
4fe5383d
VZ
135 // Load a file or resource
136 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
2bda0e17 137
4fe5383d
VZ
138 // New constructor for generalised creation from data
139 wxBitmap(void *data, long type, int width, int height, int depth = 1);
2bda0e17 140
4fe5383d
VZ
141 // If depth is omitted, will create a bitmap compatible with the display
142 wxBitmap(int width, int height, int depth = -1);
2bda0e17 143
4fe5383d
VZ
144 // we must have this, otherwise icons are silently copied into bitmaps using
145 // the copy ctor but the resulting bitmap is invalid!
146 wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
2bda0e17 147
4fe5383d
VZ
148 wxBitmap& operator=(const wxBitmap& bitmap)
149 {
150 if ( m_refData != bitmap.m_refData )
151 Ref(bitmap);
152 return *this;
153 }
2bda0e17 154
4fe5383d
VZ
155 wxBitmap& operator=(const wxIcon& icon)
156 {
157 (void)CopyFromIcon(icon);
07cf98cb 158
4fe5383d
VZ
159 return *this;
160 }
07cf98cb 161
4fe5383d 162 virtual ~wxBitmap();
2bda0e17 163
4fe5383d
VZ
164 // copies the contents and mask of the given (colour) icon to the bitmap
165 bool CopyFromIcon(const wxIcon& icon);
2bda0e17 166
4fe5383d
VZ
167 virtual bool Create(int width, int height, int depth = -1);
168 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
169 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
170 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
171
172 bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); }
173 int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); }
174 int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); }
175 int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); }
176 int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); }
177 void SetWidth(int w);
178 void SetHeight(int h);
179 void SetDepth(int d);
180 void SetQuality(int q);
181 void SetOk(bool isOk);
2bda0e17 182#if WXWIN_COMPATIBILITY
4fe5383d
VZ
183 wxPalette *GetColourMap() const { return GetPalette(); }
184 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
2bda0e17 185#endif
4fe5383d
VZ
186 wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); }
187 void SetPalette(const wxPalette& palette);
2bda0e17 188
4fe5383d
VZ
189 wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); }
190 void SetMask(wxMask *mask) ;
2bda0e17 191
4fe5383d
VZ
192 bool operator==(const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
193 bool operator!=(const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
ce3ed50d 194
4fe5383d
VZ
195 // Format handling
196 static wxList& GetHandlers() { return sm_handlers; }
197 static void AddHandler(wxBitmapHandler *handler);
198 static void InsertHandler(wxBitmapHandler *handler);
199 static bool RemoveHandler(const wxString& name);
200 static wxBitmapHandler *FindHandler(const wxString& name);
201 static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType);
202 static wxBitmapHandler *FindHandler(long bitmapType);
2bda0e17 203
4fe5383d
VZ
204 static void InitStandardHandlers();
205 static void CleanUpHandlers();
2bda0e17 206
2bda0e17 207protected:
4fe5383d 208 static wxList sm_handlers;
2bda0e17 209
4fe5383d 210 // Implementation
2bda0e17 211public:
4fe5383d
VZ
212 void SetHBITMAP(WXHBITMAP bmp);
213 WXHBITMAP GetHBITMAP() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); }
214 void SetSelectedInto(wxDC *dc) { if (M_BITMAPDATA) M_BITMAPDATA->m_selectedInto = dc; }
215 wxDC *GetSelectedInto() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_selectedInto : (wxDC*) NULL); }
216 bool FreeResource(bool force = FALSE);
217
218 // Creates a bitmap that matches the device context's depth, from
219 // an arbitray bitmap. At present, the original bitmap must have an
220 // associated palette. (TODO: use a default palette if no palette exists.)
221 // This function is necessary for you to Blit an arbitrary bitmap (which may have
222 // the wrong depth). wxDC::SelectObject will compare the depth of the bitmap
223 // with the DC's depth, and create a new bitmap if the depths differ.
224 // Eventually we should perhaps make this a public API function so that
225 // an app can efficiently produce bitmaps of the correct depth.
226 // The Windows solution is to use SetDibBits to blit an arbotrary DIB directly to a DC, but
227 // this is too Windows-specific, hence this solution of quietly converting the wxBitmap.
228 // Contributed by Frederic Villeneuve <frederic.villeneuve@natinst.com>
229 wxBitmap GetBitmapForDC(wxDC& dc) const;
230
231protected:
232 // common part of all ctors
233 void Init();
7b46ecac 234
4fe5383d
VZ
235private:
236 DECLARE_DYNAMIC_CLASS(wxBitmap)
2bda0e17 237};
ce3ed50d 238
2bda0e17 239#endif
bbcdf8bc 240 // _WX_BITMAP_H_