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