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