]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/bitmap.h
adding metafile and clipboard support
[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
15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "bitmap.h"
17#endif
18
19#include "wx/palette.h"
20
21// Bitmap
22class WXDLLEXPORT wxBitmap;
20b69855 23class wxBitmapRefData ;
8cf73271
SC
24class WXDLLEXPORT wxBitmapHandler;
25class WXDLLEXPORT wxControl;
26class WXDLLEXPORT wxCursor;
27class WXDLLEXPORT wxDC;
28class WXDLLEXPORT wxIcon;
29class WXDLLEXPORT wxImage;
30class WXDLLEXPORT wxPixelDataBase;
31
32// A mask is a bitmap used for drawing bitmaps
20b69855
SC
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
8cf73271
SC
38class WXDLLEXPORT wxMask: public wxObject
39{
40 DECLARE_DYNAMIC_CLASS(wxMask)
41 DECLARE_NO_COPY_CLASS(wxMask)
42
43public:
20b69855 44 wxMask();
8cf73271 45
20b69855
SC
46 // Construct a mask from a bitmap and a colour indicating
47 // the transparent area
48 wxMask(const wxBitmap& bitmap, const wxColour& colour);
8cf73271 49
20b69855
SC
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 ) ;
8cf73271 55
20b69855
SC
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 ) ;
8cf73271 61
20b69855
SC
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() ;
71cc158e 71
20b69855 72 WXHBITMAP GetHBITMAP() const ;
71cc158e 73
20b69855
SC
74
75private:
76 wxMemoryBuffer m_memBuf ;
77 int m_bytesPerRow ;
78 int m_width ;
79 int m_height ;
71cc158e 80
20b69855 81 WXHBITMAP m_maskBitmap ;
71cc158e 82
20b69855 83};
8cf73271
SC
84
85class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
86{
8cf73271 87public:
4b61c88d
RR
88 wxBitmapHandler() { }
89 virtual ~wxBitmapHandler();
8cf73271 90
4b61c88d
RR
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);
8cf73271 95
4b61c88d
RR
96private:
97 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
8cf73271
SC
98};
99
100#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
101
102class WXDLLEXPORT wxBitmap: public wxBitmapBase
103{
20b69855 104 DECLARE_DYNAMIC_CLASS(wxBitmap)
8cf73271 105
20b69855 106 friend class WXDLLEXPORT wxBitmapHandler;
8cf73271
SC
107
108public:
20b69855
SC
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
8cf73271
SC
172
173#if wxUSE_PALETTE
20b69855
SC
174 wxPalette* GetPalette() const;
175 void SetPalette(const wxPalette& palette);
8cf73271
SC
176#endif // wxUSE_PALETTE
177
20b69855
SC
178 wxMask *GetMask() const;
179 void SetMask(wxMask *mask) ;
8cf73271 180
20b69855
SC
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; }
8cf73271 184
20b69855 185 static void InitStandardHandlers();
8cf73271
SC
186
187 // raw bitmap access support functions, for internal use only
188 void *GetRawData(wxPixelDataBase& data, int bpp);
189 void UngetRawData(wxPixelDataBase& data);
190
20b69855
SC
191 // these functions are internal and shouldn't be used, they risk to
192 // disappear in the future
193 bool HasAlpha() const;
8cf73271
SC
194 void UseAlpha();
195
20b69855
SC
196 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
197 WXHBITMAP GetHBITMAP( WXHBITMAP * mask = NULL ) const;
8cf73271 198
20b69855
SC
199#if wxMAC_USE_CORE_GRAPHICS
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() ;
8cf73271
SC
209};
210#endif
211 // _WX_BITMAP_H_