]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/bitmap.h
Made wxGTK compile and link again. Broke wxMSW a little.
[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
JS
8// Copyright: (c) Julian Smart
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__
16#pragma interface "bitmap.h"
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
59 inline WXHBITMAP GetMaskBitmap(void) const { return m_maskBitmap; }
60 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
61protected:
62 WXHBITMAP m_maskBitmap;
63};
64
65class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
66{
67 friend class WXDLLEXPORT wxBitmap;
68 friend class WXDLLEXPORT wxIcon;
69 friend class WXDLLEXPORT wxCursor;
70public:
10fcf31a
VZ
71 wxBitmapRefData();
72 ~wxBitmapRefData();
2bda0e17
KB
73
74public:
75 int m_width;
76 int m_height;
77 int m_depth;
78 bool m_ok;
79 int m_numColors;
80 wxPalette m_bitmapPalette;
81 int m_quality;
82
2049ba38 83#ifdef __WXMSW__
2bda0e17
KB
84 WXHBITMAP m_hBitmap;
85 wxDC * m_selectedInto; // So bitmap knows whether it's been selected into
86 // a device context (for error checking)
87 wxMask * m_bitmapMask; // Option mask
88#endif
89};
90
91#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
92
93class WXDLLEXPORT wxBitmapHandler: public wxObject
94{
95 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
96public:
97 wxBitmapHandler(void) { m_name = ""; m_extension = ""; m_type = 0; };
98
debe6624
JS
99 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
100 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
2bda0e17 101 int desiredWidth, int desiredHeight);
debe6624 102 virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
2bda0e17
KB
103
104 inline void SetName(const wxString& name) { m_name = name; }
105 inline void SetExtension(const wxString& ext) { m_extension = ext; }
debe6624 106 inline void SetType(long type) { m_type = type; }
2bda0e17
KB
107 inline wxString GetName(void) const { return m_name; }
108 inline wxString GetExtension(void) const { return m_extension; }
109 inline long GetType(void) const { return m_type; }
110protected:
111 wxString m_name;
112 wxString m_extension;
113 long m_type;
114};
115#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
116
117class WXDLLEXPORT wxBitmap: public wxGDIObject
118{
119 DECLARE_DYNAMIC_CLASS(wxBitmap)
120
121 friend class WXDLLEXPORT wxBitmapHandler;
122
123public:
10fcf31a 124 wxBitmap(); // Platform-specific
2bda0e17
KB
125
126 // Copy constructors
10fcf31a 127 wxBitmap(const wxBitmap& bitmap);
2bda0e17
KB
128
129 // Initialize with raw data
debe6624 130 wxBitmap(const char bits[], int width, int height, int depth = 1);
2bda0e17 131
2bda0e17 132 // Initialize with XPM data
03ab016d 133 wxBitmap(char **data, wxControl *anItem = NULL);
2bda0e17
KB
134
135 // Load a file or resource
debe6624 136 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
2bda0e17
KB
137
138 // New constructor for generalised creation from data
debe6624 139 wxBitmap(void *data, long type, int width, int height, int depth = 1);
2bda0e17
KB
140
141 // If depth is omitted, will create a bitmap compatible with the display
debe6624 142 wxBitmap(int width, int height, int depth = -1);
10fcf31a 143 ~wxBitmap();
2bda0e17 144
debe6624
JS
145 virtual bool Create(int width, int height, int depth = -1);
146 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
147 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
148 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
2bda0e17
KB
149
150 inline bool Ok(void) const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); }
151 inline int GetWidth(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); }
152 inline int GetHeight(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); }
153 inline int GetDepth(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); }
154 inline int GetQuality(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); }
155 void SetWidth(int w);
156 void SetHeight(int h);
157 void SetDepth(int d);
158 void SetQuality(int q);
159 void SetOk(bool isOk);
160#if WXWIN_COMPATIBILITY
161 inline wxPalette *GetColourMap(void) const { return GetPalette(); }
162 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
163#endif
57c208c5 164 inline wxPalette* GetPalette(void) const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); }
2bda0e17
KB
165 void SetPalette(const wxPalette& palette);
166
57c208c5 167 inline wxMask *GetMask(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); }
2bda0e17
KB
168 void SetMask(wxMask *mask) ;
169
170 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
ce3ed50d 171
2bda0e17
KB
172 inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
173 inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
174
175 // Format handling
176 static inline wxList& GetHandlers(void) { return sm_handlers; }
177 static void AddHandler(wxBitmapHandler *handler);
178 static void InsertHandler(wxBitmapHandler *handler);
179 static bool RemoveHandler(const wxString& name);
180 static wxBitmapHandler *FindHandler(const wxString& name);
181 static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType);
182 static wxBitmapHandler *FindHandler(long bitmapType);
183
10fcf31a
VZ
184 static void InitStandardHandlers();
185 static void CleanUpHandlers();
2bda0e17
KB
186protected:
187 static wxList sm_handlers;
188
189 // Implementation
190public:
191 void SetHBITMAP(WXHBITMAP bmp);
192 inline WXHBITMAP GetHBITMAP(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); }
193 inline void SetSelectedInto(wxDC *dc) { if (M_BITMAPDATA) M_BITMAPDATA->m_selectedInto = dc; }
57c208c5 194 inline wxDC *GetSelectedInto(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_selectedInto : (wxDC*) NULL); }
2bda0e17
KB
195 bool FreeResource(bool force = FALSE);
196
7b46ecac
JS
197 // Creates a bitmap that matches the device context's depth, from
198 // an arbitray bitmap. At present, the original bitmap must have an
199 // associated palette. (TODO: use a default palette if no palette exists.)
200 // This function is necessary for you to Blit an arbitrary bitmap (which may have
201 // the wrong depth). wxDC::SelectObject will compare the depth of the bitmap
202 // with the DC's depth, and create a new bitmap if the depths differ.
203 // Eventually we should perhaps make this a public API function so that
204 // an app can efficiently produce bitmaps of the correct depth.
205 // The Windows solution is to use SetDibBits to blit an arbotrary DIB directly to a DC, but
206 // this is too Windows-specific, hence this solution of quietly converting the wxBitmap.
207 // Contributed by Frederic Villeneuve <frederic.villeneuve@natinst.com>
208 wxBitmap GetBitmapForDC(wxDC& dc) const;
209
2bda0e17 210};
ce3ed50d 211
2bda0e17 212#endif
bbcdf8bc 213 // _WX_BITMAP_H_