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