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