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