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