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