]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/bitmap.h
First hack at wxBrush for wxCocoa
[wxWidgets.git] / include / wx / mac / 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(__APPLE__)
16 #pragma interface "bitmap.h"
17 #endif
18
19 #include "wx/palette.h"
20
21 // Bitmap
22 class WXDLLEXPORT wxBitmap;
23 class WXDLLEXPORT wxBitmapHandler;
24 class WXDLLEXPORT wxControl;
25 class WXDLLEXPORT wxCursor;
26 class WXDLLEXPORT wxDC;
27 class WXDLLEXPORT wxIcon;
28 class WXDLLEXPORT wxImage;
29 class WXDLLEXPORT wxPixelDataBase;
30
31 // A mask is a bitmap used for drawing bitmaps
32 // it can be a monochrome bitmap or a multi-bit bitmap which transfers to alpha channels
33 // transparently.
34 class WXDLLEXPORT wxMask: public wxObject
35 {
36 DECLARE_DYNAMIC_CLASS(wxMask)
37 DECLARE_NO_COPY_CLASS(wxMask)
38
39 public:
40 wxMask();
41
42 // Construct a mask from a bitmap and a colour indicating
43 // the transparent area
44 wxMask(const wxBitmap& bitmap, const wxColour& colour);
45
46 // Construct a mask from a bitmap and a palette index indicating
47 // the transparent area
48 wxMask(const wxBitmap& bitmap, int paletteIndex);
49
50 // Construct a mask from a mono bitmap (copies the bitmap).
51 wxMask(const wxBitmap& bitmap);
52
53 ~wxMask();
54
55 bool Create(const wxBitmap& bitmap, const wxColour& colour);
56 bool Create(const wxBitmap& bitmap, int paletteIndex);
57 bool Create(const wxBitmap& bitmap);
58
59 // Implementation
60 bool PointMasked(int x, int y);
61 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
62 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
63 int GetDepth() const { return m_depth ; }
64 void SetDepth( int depth ) { m_depth = depth ; }
65 protected:
66 WXHBITMAP m_maskBitmap;
67 int m_depth ;
68 };
69
70 enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict , kMacBitmapTypeIcon } ;
71
72 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
73 {
74 DECLARE_NO_COPY_CLASS(wxBitmapRefData)
75
76 friend class WXDLLEXPORT wxBitmap;
77 friend class WXDLLEXPORT wxIcon;
78 friend class WXDLLEXPORT wxCursor;
79 public:
80 wxBitmapRefData();
81 ~wxBitmapRefData();
82
83 public:
84 int m_width;
85 int m_height;
86 int m_depth;
87 bool m_ok;
88 int m_numColors;
89 wxPalette m_bitmapPalette;
90 int m_quality;
91
92 int m_bitmapType ;
93 WXHMETAFILE m_hPict ;
94 WXHBITMAP m_hBitmap;
95 WXHICON m_hIcon ;
96 wxMask * m_bitmapMask; // Optional mask
97 bool m_hasAlpha;
98 };
99
100 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
101
102 class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
103 {
104 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
105 public:
106 wxBitmapHandler() : m_name(), m_extension(), m_type(0) { }
107 virtual ~wxBitmapHandler();
108
109 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
110 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
111 int desiredWidth, int desiredHeight);
112 virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
113
114 void SetName(const wxString& name) { m_name = name; }
115 void SetExtension(const wxString& ext) { m_extension = ext; }
116 void SetType(long type) { m_type = type; }
117 wxString GetName() const { return m_name; }
118 wxString GetExtension() const { return m_extension; }
119 long GetType() const { return m_type; }
120
121 protected:
122 wxString m_name;
123 wxString m_extension;
124 long m_type;
125 };
126
127 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
128
129 class WXDLLEXPORT wxBitmap: public wxBitmapBase
130 {
131 DECLARE_DYNAMIC_CLASS(wxBitmap)
132
133 friend class WXDLLEXPORT wxBitmapHandler;
134
135 public:
136 wxBitmap(); // Platform-specific
137
138 // Copy constructors
139 wxBitmap(const wxBitmap& bitmap)
140 : wxBitmapBase()
141 { Ref(bitmap); }
142
143 // Initialize with raw data.
144 wxBitmap(const char bits[], int width, int height, int depth = 1);
145
146 // Initialize with XPM data
147 bool CreateFromXpm(const char **bits);
148 wxBitmap(const char **bits);
149 wxBitmap(char **bits);
150
151 // Load a file or resource
152 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE);
153
154 // Constructor for generalised creation from data
155 wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
156
157 // If depth is omitted, will create a bitmap compatible with the display
158 wxBitmap(int width, int height, int depth = -1);
159
160 // Convert from wxImage:
161 wxBitmap(const wxImage& image, int depth = -1);
162
163 ~wxBitmap();
164
165 wxImage ConvertToImage() const;
166
167 // get the given part of bitmap
168 wxBitmap GetSubBitmap( const wxRect& rect ) const;
169
170 virtual bool Create(int width, int height, int depth = -1);
171 virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1);
172 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
173 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
174
175 // copies the contents and mask of the given (colour) icon to the bitmap
176 virtual bool CopyFromIcon(const wxIcon& icon);
177
178 bool Ok() const;
179 int GetWidth() const;
180 int GetHeight() const;
181 int GetDepth() const;
182 int GetQuality() const;
183 void SetWidth(int w);
184 void SetHeight(int h);
185 void SetDepth(int d);
186 void SetQuality(int q);
187 void SetOk(bool isOk);
188
189 wxPalette* GetPalette() const;
190 void SetPalette(const wxPalette& palette);
191
192 wxMask *GetMask() const;
193 void SetMask(wxMask *mask) ;
194
195 int GetBitmapType() const;
196
197 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
198 inline bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
199 inline bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
200
201 static void InitStandardHandlers();
202
203 // raw bitmap access support functions, for internal use only
204 void *GetRawData(wxPixelDataBase& data, int bpp);
205 void UngetRawData(wxPixelDataBase& data);
206
207 void UseAlpha();
208
209 public:
210 WXHBITMAP GetHBITMAP() const;
211 inline WXHICON GetHICON() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hIcon : 0); }
212 WXHMETAFILE GetPict(bool *created = NULL ) const;
213
214 void SetHBITMAP(WXHBITMAP bmp);
215 void SetHICON(WXHICON ico);
216 void SetPict( WXHMETAFILE pict ) ;
217
218 bool FreeResource(bool force = FALSE);
219 };
220 #endif
221 // _WX_BITMAP_H_