]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/bitmap.h
Harmonize wxDataViewCtrl::GetSelection() behaviour in all ports.
[wxWidgets.git] / include / wx / osx / bitmap.h
CommitLineData
6762286d 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/osx/bitmap.h
6762286d
SC
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#include "wx/palette.h"
16
17// Bitmap
18class WXDLLIMPEXP_FWD_CORE wxBitmap;
19class wxBitmapRefData ;
20class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
21class WXDLLIMPEXP_FWD_CORE wxControl;
22class WXDLLIMPEXP_FWD_CORE wxCursor;
23class WXDLLIMPEXP_FWD_CORE wxDC;
24class WXDLLIMPEXP_FWD_CORE wxIcon;
25class WXDLLIMPEXP_FWD_CORE wxImage;
26class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
27
28// A mask is a bitmap used for drawing bitmaps
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
34class WXDLLIMPEXP_CORE wxMask: public wxObject
35{
36 DECLARE_DYNAMIC_CLASS(wxMask)
37
38public:
39 wxMask();
40
41 // Copy constructor
42 wxMask(const wxMask& mask);
43
44 // Construct a mask from a bitmap and a colour indicating
45 // the transparent area
46 wxMask(const wxBitmap& bitmap, const wxColour& colour);
47
48 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
49 wxMask(const wxBitmap& bitmap);
50
51 // implementation helper only : construct a mask from a 32 bit memory buffer
52 wxMask(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ;
53
54 virtual ~wxMask();
55
56 bool Create(const wxBitmap& bitmap, const wxColour& colour);
57 bool Create(const wxBitmap& bitmap);
58 bool Create(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ;
59
60 // Implementation below
61
62 void Init() ;
63
64 // a 8 bit depth mask
65 void* GetRawAccess() const;
66 int GetBytesPerRow() const { return m_bytesPerRow ; }
67 // renders/updates native representation when necessary
68 void RealizeNative() ;
69
70 WXHBITMAP GetHBITMAP() const ;
71
72
73private:
74 wxMemoryBuffer m_memBuf ;
75 int m_bytesPerRow ;
76 int m_width ;
77 int m_height ;
78
79 WXHBITMAP m_maskBitmap ;
80
81};
82
83class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase
84{
85 DECLARE_DYNAMIC_CLASS(wxBitmap)
86
87 friend class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
88
89public:
732d8c74 90 wxBitmap() {} // Platform-specific
6762286d
SC
91
92 // Initialize with raw data.
93 wxBitmap(const char bits[], int width, int height, int depth = 1);
94
95 // Initialize with XPM data
96 wxBitmap(const char* const* bits);
97
98 // Load a file or resource
99 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
100
101 // Constructor for generalised creation from data
102 wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1);
4cf611db
SC
103
104 // creates an bitmap from the native image format
105 wxBitmap(CGImageRef image);
6762286d
SC
106
107 // If depth is omitted, will create a bitmap compatible with the display
732d8c74
FM
108 wxBitmap(int width, int height, int depth = -1) { (void)Create(width, height, depth); }
109 wxBitmap(const wxSize& sz, int depth = -1) { (void)Create(sz, depth); }
6762286d
SC
110
111 // Convert from wxImage:
112 wxBitmap(const wxImage& image, int depth = -1);
113
114 // Convert from wxIcon
115 wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); }
116
732d8c74 117 virtual ~wxBitmap() {}
6762286d
SC
118
119 wxImage ConvertToImage() const;
120
121 // get the given part of bitmap
122 wxBitmap GetSubBitmap( const wxRect& rect ) const;
123
732d8c74
FM
124 virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
125 virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
126 { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
127
6762286d 128 virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
4cf611db
SC
129 bool Create( CGImageRef image );
130
6762286d
SC
131 // virtual bool Create( WXHICON icon) ;
132 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
133 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
134
135 wxBitmapRefData *GetBitmapData() const
136 { return (wxBitmapRefData *)m_refData; }
137
138 // copies the contents and mask of the given (colour) icon to the bitmap
139 virtual bool CopyFromIcon(const wxIcon& icon);
140
141 int GetWidth() const;
142 int GetHeight() const;
143 int GetDepth() const;
144 void SetWidth(int w);
145 void SetHeight(int h);
146 void SetDepth(int d);
147 void SetOk(bool isOk);
148
149#if wxUSE_PALETTE
150 wxPalette* GetPalette() const;
151 void SetPalette(const wxPalette& palette);
152#endif // wxUSE_PALETTE
153
154 wxMask *GetMask() const;
155 void SetMask(wxMask *mask) ;
156
157 static void InitStandardHandlers();
158
159 // raw bitmap access support functions, for internal use only
160 void *GetRawData(wxPixelDataBase& data, int bpp);
161 void UngetRawData(wxPixelDataBase& data);
162
163 // these functions are internal and shouldn't be used, they risk to
164 // disappear in the future
165 bool HasAlpha() const;
166 void UseAlpha();
167
168 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
169 WXHBITMAP GetHBITMAP( WXHBITMAP * mask = NULL ) const;
170
171 // returns a CGImageRef which must released after usage with CGImageRelease
172 CGImageRef CreateCGImage() const ;
173
4bea628d 174#if wxOSX_USE_COCOA
6762286d
SC
175 // returns an autoreleased version of the image
176 WX_NSImage GetNSImage() const;
4bea628d
SC
177#endif
178#if wxOSX_USE_IPHONE
179 // returns an autoreleased version of the image
180 WX_UIImage GetUIImage() const;
5c6eb3a8 181#endif
6762286d
SC
182 // returns a IconRef which must be retained before and released after usage
183 IconRef GetIconRef() const;
184 // returns a IconRef which must be released after usage
185 IconRef CreateIconRef() const;
186 // get read only access to the underlying buffer
187 void *GetRawAccess() const ;
188 // brackets to the underlying OS structure for read/write access
189 // makes sure that no cached images will be constructed until terminated
190 void *BeginRawAccess() ;
191 void EndRawAccess() ;
192
193protected:
194 virtual wxGDIRefData *CreateGDIRefData() const;
195 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
196};
197
198#endif // _WX_BITMAP_H_