]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
Remove unnecessary Mac-specific TOOLKIT_LOWERCASE setting.
[wxWidgets.git] / include / wx / os2 / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Webster
5 // Modified by:
6 // Created: 11/28/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BITMAP_H_
13 #define _WX_BITMAP_H_
14
15 #include "wx/os2/private.h"
16 #include "wx/os2/gdiimage.h"
17 #include "wx/gdicmn.h"
18 #include "wx/palette.h"
19
20 class WXDLLIMPEXP_FWD_CORE wxDC;
21 class WXDLLIMPEXP_FWD_CORE wxControl;
22 class WXDLLIMPEXP_FWD_CORE wxBitmap;
23 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
24 class WXDLLIMPEXP_FWD_CORE wxIcon;
25 class WXDLLIMPEXP_FWD_CORE wxMask;
26 class WXDLLIMPEXP_FWD_CORE wxCursor;
27 class WXDLLIMPEXP_FWD_CORE wxControl;
28 class WXDLLIMPEXP_FWD_CORE wxImage;
29 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
30
31 // ----------------------------------------------------------------------------
32 // Bitmap data
33 //
34 // NB: this class is private, but declared here to make it possible inline
35 // wxBitmap functions accessing it
36 // ----------------------------------------------------------------------------
37
38 class WXDLLIMPEXP_CORE wxBitmapRefData : public wxGDIImageRefData
39 {
40 public:
41 wxBitmapRefData();
42 wxBitmapRefData(const wxBitmapRefData &tocopy);
43 virtual ~wxBitmapRefData() { Free(); }
44
45 virtual void Free();
46
47 public:
48 int m_nNumColors;
49 wxPalette m_vBitmapPalette;
50 int m_nQuality;
51
52 // OS2-specific
53 // ------------
54
55 wxDC* m_pSelectedInto;
56
57 //
58 // Optional mask for transparent drawing
59 //
60 wxMask* m_pBitmapMask;
61 }; // end of CLASS wxBitmapRefData
62
63 // ----------------------------------------------------------------------------
64 // wxBitmap: a mono or colour bitmap
65 // ----------------------------------------------------------------------------
66
67 class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage
68 {
69 public:
70 // default ctor creates an invalid bitmap, you must Create() it later
71 wxBitmap() { Init(); }
72
73 // Copy constructors
74 inline wxBitmap(const wxBitmap& rBitmap)
75 : wxGDIImage(rBitmap)
76 {
77 Init();
78 SetHandle(rBitmap.GetHandle());
79 }
80
81 // Initialize with raw data
82 wxBitmap( const char bits[]
83 ,int nWidth
84 ,int nHeight
85 ,int nDepth = 1
86 );
87
88 // Initialize with XPM data
89 wxBitmap(const char* const* bits);
90 #ifdef wxNEEDS_CHARPP
91 // needed for old GCC
92 wxBitmap(char** data)
93 {
94 *this = wxBitmap(const_cast<const char* const*>(data));
95 }
96 #endif
97
98 // Load a resource
99 wxBitmap( int nId
100 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
101 );
102
103 // For compatiability with other ports, under OS/2 does same as default ctor
104 inline wxBitmap( const wxString& WXUNUSED(rFilename)
105 ,wxBitmapType WXUNUSED(lType)
106 )
107 { Init(); }
108 // New constructor for generalised creation from data
109 wxBitmap( const void* pData
110 ,wxBitmapType lType
111 ,int nWidth
112 ,int nHeight
113 ,int nDepth = 1
114 );
115
116 // If depth is omitted, will create a bitmap compatible with the display
117 wxBitmap( int nWidth, int nHeight, int nDepth = -1 )
118 {
119 Init();
120 (void)Create(nWidth, nHeight, nDepth);
121 }
122 wxBitmap( const wxSize& sz, int nDepth = -1 )
123 {
124 Init();
125 (void)Create(sz, nDepth);
126 }
127
128 wxBitmap( const wxImage& image, int depth = -1 )
129 { (void)CreateFromImage(image, depth); }
130
131 // we must have this, otherwise icons are silently copied into bitmaps using
132 // the copy ctor but the resulting bitmap is invalid!
133 inline wxBitmap(const wxIcon& rIcon)
134 { Init(); CopyFromIcon(rIcon); }
135
136 wxBitmap& operator=(const wxIcon& rIcon)
137 {
138 (void)CopyFromIcon(rIcon);
139
140 return(*this);
141 }
142
143 wxBitmap& operator=(const wxCursor& rCursor)
144 {
145 (void)CopyFromCursor(rCursor);
146 return (*this);
147 }
148
149 virtual ~wxBitmap();
150
151 wxImage ConvertToImage() const;
152
153 // get the given part of bitmap
154 wxBitmap GetSubBitmap(const wxRect& rRect) const;
155
156 // copies the contents and mask of the given (colour) icon to the bitmap
157 bool CopyFromIcon(const wxIcon& rIcon);
158
159 // copies the contents and mask of the given cursor to the bitmap
160 bool CopyFromCursor(const wxCursor& rCursor);
161
162 virtual bool Create( int nWidth
163 ,int nHeight
164 ,int nDepth = wxBITMAP_SCREEN_DEPTH
165 );
166 virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
167 { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
168
169 virtual bool Create( const void* pData
170 ,wxBitmapType lType
171 ,int nWidth
172 ,int nHeight
173 ,int nDepth = 1
174 );
175 virtual bool LoadFile( int nId
176 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
177 );
178 virtual bool LoadFile( const wxString& rName
179 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
180 );
181 virtual bool SaveFile( const wxString& rName
182 ,wxBitmapType lType
183 ,const wxPalette* pCmap = NULL
184 );
185
186 inline wxBitmapRefData* GetBitmapData() const
187 { return (wxBitmapRefData *)m_refData; }
188
189 // raw bitmap access support functions
190 void *GetRawData(wxPixelDataBase& data, int bpp);
191 void UngetRawData(wxPixelDataBase& data);
192
193 inline int GetQuality() const
194 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
195
196 void SetQuality(int nQ);
197
198 wxPalette* GetPalette() const
199 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : NULL); }
200
201 void SetPalette(const wxPalette& rPalette);
202
203 inline wxMask* GetMask() const
204 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : NULL); }
205
206 void SetMask(wxMask* pMask) ;
207
208 // Implementation
209 public:
210 inline void SetHBITMAP(WXHBITMAP hBmp)
211 { SetHandle((WXHANDLE)hBmp); }
212
213 inline WXHBITMAP GetHBITMAP() const
214 { return (WXHBITMAP)GetHandle(); }
215
216 inline void SetSelectedInto(wxDC* pDc)
217 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
218
219 inline wxDC* GetSelectedInto() const
220 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : NULL); }
221
222 inline bool IsMono(void) const { return m_bIsMono; }
223
224 // An OS/2 version that probably doesn't do anything like the msw version
225 wxBitmap GetBitmapForDC(wxDC& rDc) const;
226
227 protected:
228 // common part of all ctors
229 void Init();
230
231 inline virtual wxGDIImageRefData* CreateData() const
232 { return new wxBitmapRefData; }
233
234 bool CreateFromImage(const wxImage& image, int depth);
235
236 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
237
238 private:
239 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
240
241 bool m_bIsMono;
242 DECLARE_DYNAMIC_CLASS(wxBitmap)
243 }; // end of CLASS wxBitmap
244
245 // ----------------------------------------------------------------------------
246 // wxMask: a mono bitmap used for drawing bitmaps transparently.
247 // ----------------------------------------------------------------------------
248
249 class WXDLLIMPEXP_CORE wxMask : public wxObject
250 {
251 public:
252 wxMask();
253 wxMask( const wxMask& tocopy);
254
255 // Construct a mask from a bitmap and a colour indicating the transparent
256 // area
257 wxMask( const wxBitmap& rBitmap
258 ,const wxColour& rColour
259 );
260
261 // Construct a mask from a bitmap and a palette index indicating the
262 // transparent area
263 wxMask( const wxBitmap& rBitmap
264 ,int nPaletteIndex
265 );
266
267 // Construct a mask from a mono bitmap (copies the bitmap).
268 wxMask(const wxBitmap& rBitmap);
269
270 // construct a mask from the givne bitmap handle
271 wxMask(WXHBITMAP hBmp)
272 { m_hMaskBitmap = hBmp; }
273
274 virtual ~wxMask();
275
276 bool Create( const wxBitmap& bitmap
277 ,const wxColour& rColour
278 );
279 bool Create( const wxBitmap& rBitmap
280 ,int nPaletteIndex
281 );
282 bool Create(const wxBitmap& rBitmap);
283
284 // Implementation
285 WXHBITMAP GetMaskBitmap() const
286 { return m_hMaskBitmap; }
287 void SetMaskBitmap(WXHBITMAP hBmp)
288 { m_hMaskBitmap = hBmp; }
289
290 protected:
291 WXHBITMAP m_hMaskBitmap;
292 DECLARE_DYNAMIC_CLASS(wxMask)
293 }; // end of CLASS wxMask
294
295 // ----------------------------------------------------------------------------
296 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
297 // ----------------------------------------------------------------------------
298
299 class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler
300 {
301 public:
302 inline wxBitmapHandler()
303 { m_lType = wxBITMAP_TYPE_INVALID; }
304
305 inline wxBitmapHandler( const wxString& rName
306 ,const wxString& rExt
307 ,wxBitmapType lType
308 )
309 : wxGDIImageHandler( rName
310 ,rExt
311 ,lType)
312 {
313 }
314
315 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
316 // old class which worked only with bitmaps
317 virtual bool Create( wxBitmap* pBitmap
318 ,const void* pData
319 ,wxBitmapType lType
320 ,int nWidth
321 ,int nHeight
322 ,int nDepth = 1
323 );
324 virtual bool LoadFile( wxBitmap* pBitmap
325 ,int nId
326 ,wxBitmapType lType
327 ,int nDesiredWidth
328 ,int nDesiredHeight
329 );
330 virtual bool LoadFile( wxBitmap* pBitmap
331 ,const wxString& rName
332 ,wxBitmapType lType
333 ,int nDesiredWidth
334 ,int nDesiredHeight
335 );
336 virtual bool SaveFile( wxBitmap* pBitmap
337 ,const wxString& rName
338 ,wxBitmapType lType
339 ,const wxPalette* pPalette = NULL
340 ) const;
341
342 virtual bool Create( wxGDIImage* pImage
343 ,const void* pData
344 ,wxBitmapType lFlags
345 ,int nWidth
346 ,int nHeight
347 ,int nDepth = 1
348 );
349 virtual bool Load( wxGDIImage* pImage
350 ,int nId
351 ,wxBitmapType lFlags
352 ,int nDesiredWidth
353 ,int nDesiredHeight
354 );
355 virtual bool Save( const wxGDIImage* pImage
356 ,const wxString& rName
357 ,wxBitmapType lType
358 ) const;
359 private:
360 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
361 ,const wxString& WXUNUSED(rName)
362 ,WXHANDLE WXUNUSED(hPs)
363 ,wxBitmapType WXUNUSED(lFlags)
364 ,int WXUNUSED(nDesiredWidth)
365 ,int WXUNUSED(nDesiredHeight)
366 )
367 { return false; }
368 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
369 }; // end of CLASS wxBitmapHandler
370
371 #endif
372 // _WX_BITMAP_H_