]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/bitmap.h
no changes, just resolving conflict with Julian's change which was almost exactly...
[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)
f8855e47
VZ
73 : wxGDIImage(rBitmap)
74 {
75 Init();
76 SetHandle(rBitmap.GetHandle());
77 }
3b9e3455
DW
78
79 // Initialize with raw data
80 wxBitmap( const char bits[]
81 ,int nWidth
82 ,int nHeight
83 ,int nDepth = 1
84 );
85
86 // Initialize with XPM data
452418c4 87 wxBitmap(const char* const* bits);
4a4bf7ee
SN
88#if defined (__GNUC__) && __GNUC__ < 3
89 // needed for old GCC
90 wxBitmap(char** data)
91 {
92 *this = wxBitmap(wx_const_cast(const char* const*, data));
93 }
94#endif
3b9e3455 95
b6f4144e
DW
96 // Load a resource
97 wxBitmap( int nId
3b9e3455
DW
98 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
99 );
100
b6f4144e
DW
101 // For compatiability with other ports, under OS/2 does same as default ctor
102 inline wxBitmap( const wxString& WXUNUSED(rFilename)
103 ,long WXUNUSED(lType)
104 )
105 { Init(); }
3b9e3455 106 // New constructor for generalised creation from data
452418c4 107 wxBitmap( const void* pData
3b9e3455
DW
108 ,long lType
109 ,int nWidth
110 ,int nHeight
111 ,int nDepth = 1
112 );
113
114 // If depth is omitted, will create a bitmap compatible with the display
7e1e6965 115 wxBitmap( int nWidth, int nHeight, int nDepth = -1 );
3b9e3455 116
98edf626 117 wxBitmap( const wxImage& image, int depth = -1 )
fd859211
VS
118 { (void)CreateFromImage(image, depth); }
119
3b9e3455
DW
120 // we must have this, otherwise icons are silently copied into bitmaps using
121 // the copy ctor but the resulting bitmap is invalid!
122 inline wxBitmap(const wxIcon& rIcon)
123 { Init(); CopyFromIcon(rIcon); }
124
3b9e3455
DW
125 wxBitmap& operator=(const wxIcon& rIcon)
126 {
127 (void)CopyFromIcon(rIcon);
128
129 return(*this);
130 }
131
132 wxBitmap& operator=(const wxCursor& rCursor)
133 {
134 (void)CopyFromCursor(rCursor);
135 return (*this);
136 }
137
138 virtual ~wxBitmap();
139
98edf626 140 wxImage ConvertToImage() const;
fd859211 141
341366c6
DW
142 // get the given part of bitmap
143 wxBitmap GetSubBitmap(const wxRect& rRect) const;
144
3b9e3455
DW
145 // copies the contents and mask of the given (colour) icon to the bitmap
146 bool CopyFromIcon(const wxIcon& rIcon);
147
148 // copies the contents and mask of the given cursor to the bitmap
149 bool CopyFromCursor(const wxCursor& rCursor);
150
151 virtual bool Create( int nWidth
152 ,int nHeight
153 ,int nDepth = -1
154 );
452418c4 155 virtual bool Create( const void* pData
3b9e3455
DW
156 ,long lType
157 ,int nWidth
158 ,int nHeight
159 ,int nDepth = 1
160 );
b6f4144e 161 virtual bool LoadFile( int nId
3b9e3455
DW
162 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
163 );
c90c3400
SN
164 virtual bool LoadFile( const wxString& rName
165 ,long lType = wxBITMAP_TYPE_XPM
166 );
3b9e3455
DW
167 virtual bool SaveFile( const wxString& rName
168 ,int lType
169 ,const wxPalette* pCmap = NULL
170 );
171
172 inline wxBitmapRefData* GetBitmapData() const
173 { return (wxBitmapRefData *)m_refData; }
174
175 inline int GetQuality() const
58b16424 176 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
3b9e3455
DW
177
178 void SetQuality(int nQ);
179
180 wxPalette* GetPalette() const
58b16424 181 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
3b9e3455
DW
182
183 void SetPalette(const wxPalette& rPalette);
184
185 inline wxMask* GetMask() const
58b16424 186 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
3b9e3455
DW
187
188 void SetMask(wxMask* pMask) ;
189
3b9e3455
DW
190 // Implementation
191public:
58b16424
DW
192 inline void SetHBITMAP(WXHBITMAP hBmp)
193 { SetHandle((WXHANDLE)hBmp); }
3b9e3455
DW
194
195 inline WXHBITMAP GetHBITMAP() const
196 { return (WXHBITMAP)GetHandle(); }
197
198 inline void SetSelectedInto(wxDC* pDc)
58b16424 199 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
3b9e3455
DW
200
201 inline wxDC* GetSelectedInto() const
58b16424 202 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
3b9e3455 203
79c09341 204 inline bool IsMono(void) const { return m_bIsMono; }
1759c491 205
4f72fe4f 206 // An OS/2 version that probably doesn't do anything like the msw version
3b9e3455 207 wxBitmap GetBitmapForDC(wxDC& rDc) const;
0e320a79 208
3b9e3455
DW
209protected:
210 // common part of all ctors
211 void Init();
0e320a79 212
3b9e3455
DW
213 inline virtual wxGDIImageRefData* CreateData() const
214 { return new wxBitmapRefData; }
0e320a79 215
fd859211 216 bool CreateFromImage(const wxImage& image, int depth);
341366c6 217
3b9e3455
DW
218private:
219 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
0e320a79 220
79c09341 221 bool m_bIsMono;
3b9e3455 222 DECLARE_DYNAMIC_CLASS(wxBitmap)
341366c6 223}; // end of CLASS wxBitmap
d88de032 224
3b9e3455
DW
225// ----------------------------------------------------------------------------
226// wxMask: a mono bitmap used for drawing bitmaps transparently.
227// ----------------------------------------------------------------------------
0e320a79 228
3b9e3455
DW
229class WXDLLEXPORT wxMask : public wxObject
230{
231public:
232 wxMask();
233
234 // Construct a mask from a bitmap and a colour indicating the transparent
235 // area
236 wxMask( const wxBitmap& rBitmap
237 ,const wxColour& rColour
238 );
239
240 // Construct a mask from a bitmap and a palette index indicating the
241 // transparent area
242 wxMask( const wxBitmap& rBitmap
243 ,int nPaletteIndex
244 );
245
246 // Construct a mask from a mono bitmap (copies the bitmap).
247 wxMask(const wxBitmap& rBitmap);
248
249 // construct a mask from the givne bitmap handle
250 wxMask(WXHBITMAP hBmp)
251 { m_hMaskBitmap = hBmp; }
252
253 virtual ~wxMask();
254
255 bool Create( const wxBitmap& bitmap
256 ,const wxColour& rColour
257 );
258 bool Create( const wxBitmap& rBitmap
259 ,int nPaletteIndex
260 );
261 bool Create(const wxBitmap& rBitmap);
262
263 // Implementation
264 WXHBITMAP GetMaskBitmap() const
265 { return m_hMaskBitmap; }
266 void SetMaskBitmap(WXHBITMAP hBmp)
267 { m_hMaskBitmap = hBmp; }
0e320a79 268
0e320a79 269protected:
3b9e3455
DW
270 WXHBITMAP m_hMaskBitmap;
271 DECLARE_DYNAMIC_CLASS(wxMask)
8bb6da4a 272}; // end of CLASS wxMask
3b9e3455
DW
273
274// ----------------------------------------------------------------------------
275// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
276// ----------------------------------------------------------------------------
0e320a79 277
3b9e3455
DW
278class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
279{
0e320a79 280public:
3b9e3455
DW
281 inline wxBitmapHandler()
282 { m_lType = wxBITMAP_TYPE_INVALID; }
283
284 inline wxBitmapHandler( const wxString& rName
285 ,const wxString& rExt
286 ,long lType
287 )
288 : wxGDIImageHandler( rName
289 ,rExt
290 ,lType)
291 {
292 }
293
294 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
295 // old class which worked only with bitmaps
296 virtual bool Create( wxBitmap* pBitmap
452418c4 297 ,const void* pData
3b9e3455
DW
298 ,long lFlags
299 ,int nWidth
300 ,int nHeight
301 ,int nDepth = 1
302 );
303 virtual bool LoadFile( wxBitmap* pBitmap
b6f4144e 304 ,int nId
3b9e3455
DW
305 ,long lFlags
306 ,int nDesiredWidth
307 ,int nDesiredHeight
308 );
c90c3400
SN
309 virtual bool LoadFile( wxBitmap* pBitmap
310 ,const wxString& rName
311 ,long lFlags
312 ,int nDesiredWidth
313 ,int nDesiredHeight
314 );
3b9e3455
DW
315 virtual bool SaveFile( wxBitmap* pBitmap
316 ,const wxString& rName
317 ,int lType
318 ,const wxPalette* pPalette = NULL
319 );
320
321 virtual bool Create( wxGDIImage* pImage
452418c4 322 ,const void* pData
3b9e3455
DW
323 ,long lFlags
324 ,int nWidth
325 ,int nHeight
326 ,int nDepth = 1
327 );
328 virtual bool Load( wxGDIImage* pImage
b6f4144e 329 ,int nId
3b9e3455
DW
330 ,long lFlags
331 ,int nDesiredWidth
332 ,int nDesiredHeight
333 );
58b16424
DW
334 virtual bool Save( wxGDIImage* pImage
335 ,const wxString& rName
336 ,int lType
3b9e3455
DW
337 );
338private:
7e1e6965
WS
339 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
340 ,const wxString& WXUNUSED(rName)
341 ,HPS WXUNUSED(hPs)
342 ,long WXUNUSED(lFlags)
343 ,int WXUNUSED(nDesiredWidth)
344 ,int WXUNUSED(nDesiredHeight)
b6f4144e 345 )
7e1e6965 346 { return false; }
3b9e3455 347 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
8bb6da4a 348}; // end of CLASS wxBitmapHandler
3b9e3455 349
0e320a79
DW
350#endif
351 // _WX_BITMAP_H_