]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/bitmap.h
ignore hidden windows when deciding if the MDI parent frame should be visible
[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 : wxBitmapBase()
114 {
115 Ref(bitmap);
116 }
117
118 // Initialize with raw data.
119 wxBitmap(const char bits[], int width, int height, int depth = 1);
120
121 // Initialize with XPM data
122 bool CreateFromXpm(const char **bits);
123 wxBitmap(const char **bits);
124 wxBitmap(char **bits);
125
126 // Load a file or resource
127 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE);
128
129 // Constructor for generalised creation from data
130 wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
131
132 // If depth is omitted, will create a bitmap compatible with the display
133 wxBitmap(int width, int height, int depth = -1);
134
135 // Convert from wxImage:
136 wxBitmap(const wxImage& image, int depth = -1);
137
138 // Convert from wxIcon
139 wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); }
140
141 ~wxBitmap();
142
143 wxImage ConvertToImage() const;
144
145 // get the given part of bitmap
146 wxBitmap GetSubBitmap( const wxRect& rect ) const;
147
148 virtual bool Create(int width, int height, int depth = -1);
149 virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1);
150 // virtual bool Create( WXHICON icon) ;
151 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
152 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
153
154 wxBitmapRefData *GetBitmapData() const
155 { return (wxBitmapRefData *)m_refData; }
156
157 // copies the contents and mask of the given (colour) icon to the bitmap
158 virtual bool CopyFromIcon(const wxIcon& icon);
159
160 bool Ok() const;
161 int GetWidth() const;
162 int GetHeight() const;
163 int GetDepth() const;
164 void SetWidth(int w);
165 void SetHeight(int h);
166 void SetDepth(int d);
167 void SetOk(bool isOk);
168
169 #if WXWIN_COMPATIBILITY_2_4
170 // these functions do nothing and are only there for backwards
171 // compatibility
172 wxDEPRECATED( int GetQuality() const );
173 wxDEPRECATED( void SetQuality(int quality) );
174 #endif // WXWIN_COMPATIBILITY_2_4
175
176 #if wxUSE_PALETTE
177 wxPalette* GetPalette() const;
178 void SetPalette(const wxPalette& palette);
179 #endif // wxUSE_PALETTE
180
181 wxMask *GetMask() const;
182 void SetMask(wxMask *mask) ;
183
184 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
185 inline bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
186 inline bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
187
188 static void InitStandardHandlers();
189
190 // raw bitmap access support functions, for internal use only
191 void *GetRawData(wxPixelDataBase& data, int bpp);
192 void UngetRawData(wxPixelDataBase& data);
193
194 // these functions are internal and shouldn't be used, they risk to
195 // disappear in the future
196 bool HasAlpha() const;
197 void UseAlpha();
198
199 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
200 WXHBITMAP GetHBITMAP( WXHBITMAP * mask = NULL ) const;
201
202 #ifdef __WXMAC_OSX__
203 // returns a CGImageRef which must released after usage with CGImageRelease
204 WXCGIMAGEREF CGImageCreate() const ;
205 #endif
206 // get read only access to the underlying buffer
207 void *GetRawAccess() const ;
208 // brackets to the underlying OS structure for read/write access
209 // makes sure that no cached images will be constructed until terminated
210 void *BeginRawAccess() ;
211 void EndRawAccess() ;
212 };
213 #endif
214 // _WX_BITMAP_H_