]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/bitmap.h
define wxUSE_MFC as 0 if it's not defined (fixes gcc -Wundef warning)
[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
3b9e3455
DW
15#ifdef __GNUG__
16 #pragma interface "bitmap.h"
17#endif
18
58b16424 19#include "wx/os2/private.h"
3b9e3455 20#include "wx/os2/gdiimage.h"
0e320a79
DW
21#include "wx/gdicmn.h"
22#include "wx/palette.h"
23
0e320a79
DW
24class WXDLLEXPORT wxDC;
25class WXDLLEXPORT wxControl;
26class WXDLLEXPORT wxBitmap;
27class WXDLLEXPORT wxBitmapHandler;
28class WXDLLEXPORT wxIcon;
3b9e3455 29class WXDLLEXPORT wxMask;
0e320a79 30class WXDLLEXPORT wxCursor;
d88de032 31class WXDLLEXPORT wxControl;
fd859211 32class WXDLLEXPORT wxImage;
0e320a79 33
3b9e3455
DW
34// ----------------------------------------------------------------------------
35// Bitmap data
36//
37// NB: this class is private, but declared here to make it possible inline
38// wxBitmap functions accessing it
39// ----------------------------------------------------------------------------
0e320a79 40
3b9e3455 41class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
0e320a79 42{
0e320a79
DW
43public:
44 wxBitmapRefData();
3b9e3455
DW
45 virtual ~wxBitmapRefData() { Free(); }
46
47 virtual void Free();
0e320a79
DW
48
49public:
3b9e3455
DW
50 int m_nNumColors;
51 wxPalette m_vBitmapPalette;
52 int m_nQuality;
0e320a79 53
3b9e3455
DW
54 // OS2-specific
55 // ------------
0e320a79 56
3b9e3455 57 wxDC* m_pSelectedInto;
3b9e3455 58
8bb6da4a
DW
59 //
60 // Optional mask for transparent drawing
61 //
3b9e3455 62 wxMask* m_pBitmapMask;
8bb6da4a 63}; // end of CLASS wxBitmapRefData
0e320a79 64
3b9e3455
DW
65// ----------------------------------------------------------------------------
66// wxBitmap: a mono or colour bitmap
67// ----------------------------------------------------------------------------
0e320a79 68
3b9e3455 69class WXDLLEXPORT wxBitmap : public wxGDIImage
0e320a79 70{
0e320a79 71public:
3b9e3455
DW
72 // default ctor creates an invalid bitmap, you must Create() it later
73 wxBitmap() { Init(); }
74
75 // Copy constructors
76 inline wxBitmap(const wxBitmap& rBitmap)
10769d8c 77 { Init(); Ref(rBitmap); SetHandle(rBitmap.GetHandle()); }
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
119 wxBitmap& operator=(const wxBitmap& rBitmap)
120 {
121 if ( m_refData != rBitmap.m_refData )
122 Ref(rBitmap);
123 return(*this);
124 }
125
126 wxBitmap& operator=(const wxIcon& rIcon)
127 {
128 (void)CopyFromIcon(rIcon);
129
130 return(*this);
131 }
132
133 wxBitmap& operator=(const wxCursor& rCursor)
134 {
135 (void)CopyFromCursor(rCursor);
136 return (*this);
137 }
138
139 virtual ~wxBitmap();
140
98edf626 141 wxImage ConvertToImage() const;
fd859211 142
341366c6
DW
143 // get the given part of bitmap
144 wxBitmap GetSubBitmap(const wxRect& rRect) const;
145
3b9e3455
DW
146 // copies the contents and mask of the given (colour) icon to the bitmap
147 bool CopyFromIcon(const wxIcon& rIcon);
148
149 // copies the contents and mask of the given cursor to the bitmap
150 bool CopyFromCursor(const wxCursor& rCursor);
151
152 virtual bool Create( int nWidth
153 ,int nHeight
154 ,int nDepth = -1
155 );
156 virtual bool Create( void* pData
157 ,long lType
158 ,int nWidth
159 ,int nHeight
160 ,int nDepth = 1
161 );
b6f4144e 162 virtual bool LoadFile( int nId
3b9e3455
DW
163 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
164 );
165 virtual bool SaveFile( const wxString& rName
166 ,int lType
167 ,const wxPalette* pCmap = NULL
168 );
169
170 inline wxBitmapRefData* GetBitmapData() const
171 { return (wxBitmapRefData *)m_refData; }
172
173 inline int GetQuality() const
58b16424 174 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
3b9e3455
DW
175
176 void SetQuality(int nQ);
177
178 wxPalette* GetPalette() const
58b16424 179 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
3b9e3455
DW
180
181 void SetPalette(const wxPalette& rPalette);
182
183 inline wxMask* GetMask() const
58b16424 184 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
3b9e3455
DW
185
186 void SetMask(wxMask* pMask) ;
187
ab4fece8 188 inline bool operator==(const wxBitmap& rBitmap) const
3b9e3455
DW
189 { return m_refData == rBitmap.m_refData; }
190
ab4fece8 191 inline bool operator!=(const wxBitmap& rBitmap) const
3b9e3455
DW
192 { return m_refData != rBitmap.m_refData; }
193
3b9e3455
DW
194 // Implementation
195public:
58b16424
DW
196 inline void SetHBITMAP(WXHBITMAP hBmp)
197 { SetHandle((WXHANDLE)hBmp); }
3b9e3455
DW
198
199 inline WXHBITMAP GetHBITMAP() const
200 { return (WXHBITMAP)GetHandle(); }
201
202 inline void SetSelectedInto(wxDC* pDc)
58b16424 203 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
3b9e3455
DW
204
205 inline wxDC* GetSelectedInto() const
58b16424 206 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
3b9e3455 207
79c09341 208 inline bool IsMono(void) const { return m_bIsMono; }
1759c491 209
4f72fe4f 210 // An OS/2 version that probably doesn't do anything like the msw version
3b9e3455 211 wxBitmap GetBitmapForDC(wxDC& rDc) const;
0e320a79 212
3b9e3455
DW
213protected:
214 // common part of all ctors
215 void Init();
0e320a79 216
3b9e3455
DW
217 inline virtual wxGDIImageRefData* CreateData() const
218 { return new wxBitmapRefData; }
0e320a79 219
341366c6 220 // creates the bitmap from XPM data, supposed to be called from ctor
98edf626 221 bool CreateFromXpm(const char** ppData);
fd859211 222 bool CreateFromImage(const wxImage& image, int depth);
341366c6 223
3b9e3455
DW
224private:
225 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
0e320a79 226
79c09341 227 bool m_bIsMono;
3b9e3455 228 DECLARE_DYNAMIC_CLASS(wxBitmap)
341366c6 229}; // end of CLASS wxBitmap
d88de032 230
3b9e3455
DW
231// ----------------------------------------------------------------------------
232// wxMask: a mono bitmap used for drawing bitmaps transparently.
233// ----------------------------------------------------------------------------
0e320a79 234
3b9e3455
DW
235class WXDLLEXPORT wxMask : public wxObject
236{
237public:
238 wxMask();
239
240 // Construct a mask from a bitmap and a colour indicating the transparent
241 // area
242 wxMask( const wxBitmap& rBitmap
243 ,const wxColour& rColour
244 );
245
246 // Construct a mask from a bitmap and a palette index indicating the
247 // transparent area
248 wxMask( const wxBitmap& rBitmap
249 ,int nPaletteIndex
250 );
251
252 // Construct a mask from a mono bitmap (copies the bitmap).
253 wxMask(const wxBitmap& rBitmap);
254
255 // construct a mask from the givne bitmap handle
256 wxMask(WXHBITMAP hBmp)
257 { m_hMaskBitmap = hBmp; }
258
259 virtual ~wxMask();
260
261 bool Create( const wxBitmap& bitmap
262 ,const wxColour& rColour
263 );
264 bool Create( const wxBitmap& rBitmap
265 ,int nPaletteIndex
266 );
267 bool Create(const wxBitmap& rBitmap);
268
269 // Implementation
270 WXHBITMAP GetMaskBitmap() const
271 { return m_hMaskBitmap; }
272 void SetMaskBitmap(WXHBITMAP hBmp)
273 { m_hMaskBitmap = hBmp; }
0e320a79 274
0e320a79 275protected:
3b9e3455
DW
276 WXHBITMAP m_hMaskBitmap;
277 DECLARE_DYNAMIC_CLASS(wxMask)
8bb6da4a 278}; // end of CLASS wxMask
3b9e3455
DW
279
280// ----------------------------------------------------------------------------
281// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
282// ----------------------------------------------------------------------------
0e320a79 283
3b9e3455
DW
284class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
285{
0e320a79 286public:
3b9e3455
DW
287 inline wxBitmapHandler()
288 { m_lType = wxBITMAP_TYPE_INVALID; }
289
290 inline wxBitmapHandler( const wxString& rName
291 ,const wxString& rExt
292 ,long lType
293 )
294 : wxGDIImageHandler( rName
295 ,rExt
296 ,lType)
297 {
298 }
299
300 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
301 // old class which worked only with bitmaps
302 virtual bool Create( wxBitmap* pBitmap
303 ,void* pData
304 ,long lFlags
305 ,int nWidth
306 ,int nHeight
307 ,int nDepth = 1
308 );
309 virtual bool LoadFile( wxBitmap* pBitmap
b6f4144e 310 ,int nId
3b9e3455
DW
311 ,long lFlags
312 ,int nDesiredWidth
313 ,int nDesiredHeight
314 );
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
322 ,void* pData
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_