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