]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/bitmap.h
support for wxUSE_PALETTE = 0
[wxWidgets.git] / include / wx / mac / bitmap.h
CommitLineData
0dbd6262
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: bitmap.h
3// Purpose: wxBitmap class
a31a5f85 4// Author: Stefan Csomor
0dbd6262 5// Modified by:
a31a5f85 6// Created: 1998-01-01
0dbd6262 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
d921af51 9// Licence: wxWindows licence
0dbd6262
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_BITMAP_H_
13#define _WX_BITMAP_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
b698c8e9 16 #pragma interface "bitmap.h"
0dbd6262
SC
17#endif
18
0dbd6262
SC
19#include "wx/palette.h"
20
21// Bitmap
0dbd6262
SC
22class WXDLLEXPORT wxBitmap;
23class WXDLLEXPORT wxBitmapHandler;
55e18dbe 24class WXDLLEXPORT wxControl;
0dbd6262 25class WXDLLEXPORT wxCursor;
55e18dbe
VZ
26class WXDLLEXPORT wxDC;
27class WXDLLEXPORT wxIcon;
fd859211 28class WXDLLEXPORT wxImage;
55e18dbe 29class WXDLLEXPORT wxPixelDataBase;
0dbd6262 30
e9d804eb
SC
31// A mask is a bitmap used for drawing bitmaps
32// it can be a monochrome bitmap or a multi-bit bitmap which transfers to alpha channels
0dbd6262
SC
33// transparently.
34class WXDLLEXPORT wxMask: public wxObject
35{
be52b341
GD
36 DECLARE_DYNAMIC_CLASS(wxMask)
37 DECLARE_NO_COPY_CLASS(wxMask)
0dbd6262
SC
38
39public:
40 wxMask();
41
42 // Construct a mask from a bitmap and a colour indicating
43 // the transparent area
44 wxMask(const wxBitmap& bitmap, const wxColour& colour);
45
46 // Construct a mask from a bitmap and a palette index indicating
47 // the transparent area
48 wxMask(const wxBitmap& bitmap, int paletteIndex);
49
50 // Construct a mask from a mono bitmap (copies the bitmap).
51 wxMask(const wxBitmap& bitmap);
52
53 ~wxMask();
54
55 bool Create(const wxBitmap& bitmap, const wxColour& colour);
56 bool Create(const wxBitmap& bitmap, int paletteIndex);
57 bool Create(const wxBitmap& bitmap);
58
0dbd6262 59 // Implementation
5fde6fcc 60 bool PointMasked(int x, int y);
0dbd6262
SC
61 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
62 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
e9d804eb
SC
63 int GetDepth() const { return m_depth ; }
64 void SetDepth( int depth ) { m_depth = depth ; }
0dbd6262
SC
65protected:
66 WXHBITMAP m_maskBitmap;
e9d804eb 67 int m_depth ;
0dbd6262
SC
68};
69
3dec57ad 70enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict , kMacBitmapTypeIcon } ;
519cb848 71
0dbd6262
SC
72class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
73{
be52b341
GD
74 DECLARE_NO_COPY_CLASS(wxBitmapRefData)
75
0dbd6262
SC
76 friend class WXDLLEXPORT wxBitmap;
77 friend class WXDLLEXPORT wxIcon;
78 friend class WXDLLEXPORT wxCursor;
79public:
80 wxBitmapRefData();
81 ~wxBitmapRefData();
82
83public:
84 int m_width;
85 int m_height;
86 int m_depth;
87 bool m_ok;
88 int m_numColors;
a6de86fa 89#if wxUSE_PALETTE
0dbd6262 90 wxPalette m_bitmapPalette;
a6de86fa 91#endif // wxUSE_PALETTE
0dbd6262
SC
92 int m_quality;
93
d921af51
JS
94 int m_bitmapType ;
95 WXHMETAFILE m_hPict ;
be52b341
GD
96 WXHBITMAP m_hBitmap;
97 WXHICON m_hIcon ;
0dbd6262 98 wxMask * m_bitmapMask; // Optional mask
1e74d03b 99 bool m_hasAlpha;
0dbd6262
SC
100};
101
102#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
103
584bede0 104class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
0dbd6262
SC
105{
106 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
107public:
be52b341
GD
108 wxBitmapHandler() : m_name(), m_extension(), m_type(0) { }
109 virtual ~wxBitmapHandler();
0dbd6262
SC
110
111 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
112 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
113 int desiredWidth, int desiredHeight);
584bede0 114 virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
0dbd6262 115
be52b341
GD
116 void SetName(const wxString& name) { m_name = name; }
117 void SetExtension(const wxString& ext) { m_extension = ext; }
118 void SetType(long type) { m_type = type; }
119 wxString GetName() const { return m_name; }
120 wxString GetExtension() const { return m_extension; }
121 long GetType() const { return m_type; }
122
0dbd6262
SC
123protected:
124 wxString m_name;
125 wxString m_extension;
126 long m_type;
127};
128
129#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
130
584bede0 131class WXDLLEXPORT wxBitmap: public wxBitmapBase
0dbd6262
SC
132{
133 DECLARE_DYNAMIC_CLASS(wxBitmap)
134
135 friend class WXDLLEXPORT wxBitmapHandler;
136
137public:
138 wxBitmap(); // Platform-specific
139
140 // Copy constructors
be52b341
GD
141 wxBitmap(const wxBitmap& bitmap)
142 : wxBitmapBase()
d71c423e 143 { Ref(bitmap); }
0dbd6262
SC
144
145 // Initialize with raw data.
146 wxBitmap(const char bits[], int width, int height, int depth = 1);
147
0dbd6262 148 // Initialize with XPM data
b7d667c5
GD
149 bool CreateFromXpm(const char **bits);
150 wxBitmap(const char **bits);
151 wxBitmap(char **bits);
0dbd6262
SC
152
153 // Load a file or resource
584bede0 154 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE);
0dbd6262
SC
155
156 // Constructor for generalised creation from data
584bede0 157 wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
0dbd6262
SC
158
159 // If depth is omitted, will create a bitmap compatible with the display
160 wxBitmap(int width, int height, int depth = -1);
fd859211
VS
161
162 // Convert from wxImage:
163 wxBitmap(const wxImage& image, int depth = -1);
164
0dbd6262 165 ~wxBitmap();
fd859211
VS
166
167 wxImage ConvertToImage() const;
0dbd6262 168
5fde6fcc
GD
169 // get the given part of bitmap
170 wxBitmap GetSubBitmap( const wxRect& rect ) const;
171
0dbd6262 172 virtual bool Create(int width, int height, int depth = -1);
584bede0
GD
173 virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1);
174 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
175 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
176
177 // copies the contents and mask of the given (colour) icon to the bitmap
178 virtual bool CopyFromIcon(const wxIcon& icon);
0dbd6262 179
5fde6fcc
GD
180 bool Ok() const;
181 int GetWidth() const;
182 int GetHeight() const;
183 int GetDepth() const;
184 int GetQuality() const;
0dbd6262
SC
185 void SetWidth(int w);
186 void SetHeight(int h);
187 void SetDepth(int d);
188 void SetQuality(int q);
189 void SetOk(bool isOk);
190
a6de86fa
SC
191#if wxUSE_PALETTE
192 wxPalette* GetPalette() const;
193 void SetPalette(const wxPalette& palette);
194#endif // wxUSE_PALETTE
0dbd6262 195
5fde6fcc 196 wxMask *GetMask() const;
0dbd6262
SC
197 void SetMask(wxMask *mask) ;
198
5fde6fcc
GD
199 int GetBitmapType() const;
200
0dbd6262 201 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
15e758d1
GD
202 inline bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
203 inline bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
0dbd6262 204
0dbd6262 205 static void InitStandardHandlers();
55e18dbe 206
1e74d03b 207 // raw bitmap access support functions, for internal use only
55e18dbe
VZ
208 void *GetRawData(wxPixelDataBase& data, int bpp);
209 void UngetRawData(wxPixelDataBase& data);
210
211 void UseAlpha();
212
0dbd6262 213public:
5fde6fcc 214 WXHBITMAP GetHBITMAP() const;
3dec57ad 215 inline WXHICON GetHICON() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hIcon : 0); }
1c522100
SC
216 WXHMETAFILE GetPict(bool *created = NULL ) const;
217
218 void SetHBITMAP(WXHBITMAP bmp);
219 void SetHICON(WXHICON ico);
220 void SetPict( WXHMETAFILE pict ) ;
5fde6fcc 221
0dbd6262 222 bool FreeResource(bool force = FALSE);
0dbd6262
SC
223};
224#endif
225 // _WX_BITMAP_H_