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