]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/bitmap.h
corrected wxCHECK messages
[wxWidgets.git] / include / wx / mac / carbon / bitmap.h
CommitLineData
8cf73271
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: bitmap.h
3// Purpose: wxBitmap class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
8cf73271
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_BITMAP_H_
13#define _WX_BITMAP_H_
14
8cf73271
SC
15#include "wx/palette.h"
16
17// Bitmap
18class WXDLLEXPORT wxBitmap;
20b69855 19class wxBitmapRefData ;
8cf73271
SC
20class WXDLLEXPORT wxBitmapHandler;
21class WXDLLEXPORT wxControl;
22class WXDLLEXPORT wxCursor;
23class WXDLLEXPORT wxDC;
24class WXDLLEXPORT wxIcon;
25class WXDLLEXPORT wxImage;
26class WXDLLEXPORT wxPixelDataBase;
27
28// A mask is a bitmap used for drawing bitmaps
20b69855
SC
29// Internally it is stored as a 8 bit deep memory chunk, 0 = black means the source will be drawn
30// 255 = white means the source will not be drawn, no other values will be present
31// 8 bit is chosen only for performance reasons, note also that this is the inverse value range
32// from alpha, where 0 = invisible , 255 = fully drawn
33
8cf73271
SC
34class WXDLLEXPORT wxMask: public wxObject
35{
36 DECLARE_DYNAMIC_CLASS(wxMask)
37 DECLARE_NO_COPY_CLASS(wxMask)
38
39public:
20b69855 40 wxMask();
8cf73271 41
20b69855
SC
42 // Construct a mask from a bitmap and a colour indicating
43 // the transparent area
44 wxMask(const wxBitmap& bitmap, const wxColour& colour);
8cf73271 45
20b69855
SC
46 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
47 wxMask(const wxBitmap& bitmap);
48
49 // implementation helper only : construct a mask from a 8 bit memory buffer
50 wxMask(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ;
8cf73271 51
20b69855
SC
52 ~wxMask();
53
54 bool Create(const wxBitmap& bitmap, const wxColour& colour);
55 bool Create(const wxBitmap& bitmap);
56 bool Create(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ;
8cf73271 57
20b69855
SC
58 // Implementation below
59
60 void Init() ;
61
62 // a 8 bit depth mask
63 void* GetRawAccess() const;
64 int GetBytesPerRow() const { return m_bytesPerRow ; }
65 // renders/updates native representation when necessary
66 void RealizeNative() ;
71cc158e 67
20b69855 68 WXHBITMAP GetHBITMAP() const ;
71cc158e 69
20b69855
SC
70
71private:
72 wxMemoryBuffer m_memBuf ;
73 int m_bytesPerRow ;
74 int m_width ;
75 int m_height ;
71cc158e 76
20b69855 77 WXHBITMAP m_maskBitmap ;
71cc158e 78
20b69855 79};
8cf73271
SC
80
81class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
82{
8cf73271 83public:
4b61c88d
RR
84 wxBitmapHandler() { }
85 virtual ~wxBitmapHandler();
8cf73271 86
4b61c88d
RR
87 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
88 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
89 int desiredWidth, int desiredHeight);
90 virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
8cf73271 91
4b61c88d
RR
92private:
93 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
8cf73271
SC
94};
95
96#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
97
98class WXDLLEXPORT wxBitmap: public wxBitmapBase
99{
20b69855 100 DECLARE_DYNAMIC_CLASS(wxBitmap)
8cf73271 101
20b69855 102 friend class WXDLLEXPORT wxBitmapHandler;
8cf73271
SC
103
104public:
20b69855
SC
105 wxBitmap(); // Platform-specific
106
107 // Copy constructors
108 wxBitmap(const wxBitmap& bitmap)
f0794a4c
VZ
109 : wxBitmapBase()
110 {
111 Ref(bitmap);
112 }
20b69855
SC
113
114 // Initialize with raw data.
115 wxBitmap(const char bits[], int width, int height, int depth = 1);
116
117 // Initialize with XPM data
118 bool CreateFromXpm(const char **bits);
119 wxBitmap(const char **bits);
120 wxBitmap(char **bits);
121
122 // Load a file or resource
123 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE);
124
125 // Constructor for generalised creation from data
126 wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
127
128 // If depth is omitted, will create a bitmap compatible with the display
129 wxBitmap(int width, int height, int depth = -1);
130
131 // Convert from wxImage:
132 wxBitmap(const wxImage& image, int depth = -1);
133
134 // Convert from wxIcon
135 wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); }
136
137 ~wxBitmap();
138
139 wxImage ConvertToImage() const;
140
141 // get the given part of bitmap
142 wxBitmap GetSubBitmap( const wxRect& rect ) const;
143
144 virtual bool Create(int width, int height, int depth = -1);
145 virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1);
146 // virtual bool Create( WXHICON icon) ;
147 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
148 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
149
150 wxBitmapRefData *GetBitmapData() const
151 { return (wxBitmapRefData *)m_refData; }
152
153 // copies the contents and mask of the given (colour) icon to the bitmap
154 virtual bool CopyFromIcon(const wxIcon& icon);
155
156 bool Ok() const;
157 int GetWidth() const;
158 int GetHeight() const;
159 int GetDepth() const;
160 void SetWidth(int w);
161 void SetHeight(int h);
162 void SetDepth(int d);
163 void SetOk(bool isOk);
164
165#if WXWIN_COMPATIBILITY_2_4
166 // these functions do nothing and are only there for backwards
167 // compatibility
168 wxDEPRECATED( int GetQuality() const );
169 wxDEPRECATED( void SetQuality(int quality) );
170#endif // WXWIN_COMPATIBILITY_2_4
8cf73271
SC
171
172#if wxUSE_PALETTE
20b69855
SC
173 wxPalette* GetPalette() const;
174 void SetPalette(const wxPalette& palette);
8cf73271
SC
175#endif // wxUSE_PALETTE
176
20b69855
SC
177 wxMask *GetMask() const;
178 void SetMask(wxMask *mask) ;
8cf73271 179
20b69855
SC
180 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
181 inline bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
182 inline bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
8cf73271 183
20b69855 184 static void InitStandardHandlers();
8cf73271
SC
185
186 // raw bitmap access support functions, for internal use only
187 void *GetRawData(wxPixelDataBase& data, int bpp);
188 void UngetRawData(wxPixelDataBase& data);
189
20b69855
SC
190 // these functions are internal and shouldn't be used, they risk to
191 // disappear in the future
192 bool HasAlpha() const;
8cf73271
SC
193 void UseAlpha();
194
20b69855
SC
195 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
196 WXHBITMAP GetHBITMAP( WXHBITMAP * mask = NULL ) const;
8cf73271 197
30e77b5c 198#ifdef __WXMAC_OSX__
20b69855
SC
199 // returns a CGImageRef which must released after usage with CGImageRelease
200 WXCGIMAGEREF CGImageCreate() const ;
201#endif
202 // get read only access to the underlying buffer
203 void *GetRawAccess() const ;
204 // brackets to the underlying OS structure for read/write access
205 // makes sure that no cached images will be constructed until terminated
206 void *BeginRawAccess() ;
207 void EndRawAccess() ;
8cf73271
SC
208};
209#endif
210 // _WX_BITMAP_H_