]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/bitmap.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[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
d88de032 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
0e320a79
DW
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_BITMAP_H_
12#define _WX_BITMAP_H_
13
58b16424 14#include "wx/os2/private.h"
3b9e3455 15#include "wx/os2/gdiimage.h"
0e320a79
DW
16#include "wx/gdicmn.h"
17#include "wx/palette.h"
18
b5dbe15d
VS
19class WXDLLIMPEXP_FWD_CORE wxDC;
20class WXDLLIMPEXP_FWD_CORE wxControl;
21class WXDLLIMPEXP_FWD_CORE wxBitmap;
22class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
23class WXDLLIMPEXP_FWD_CORE wxIcon;
24class WXDLLIMPEXP_FWD_CORE wxMask;
25class WXDLLIMPEXP_FWD_CORE wxCursor;
26class WXDLLIMPEXP_FWD_CORE wxControl;
6b5c2d52 27class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
0e320a79 28
3b9e3455
DW
29// ----------------------------------------------------------------------------
30// Bitmap data
31//
32// NB: this class is private, but declared here to make it possible inline
33// wxBitmap functions accessing it
34// ----------------------------------------------------------------------------
0e320a79 35
53a2db12 36class WXDLLIMPEXP_CORE wxBitmapRefData : public wxGDIImageRefData
0e320a79 37{
0e320a79
DW
38public:
39 wxBitmapRefData();
cd7ff808 40 wxBitmapRefData(const wxBitmapRefData &tocopy);
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
20e6714a
VZ
65class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage,
66 public wxBitmapHelpers
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); }
7f74897f
SC
168 virtual bool Create(int width, int height, const wxDC& WXUNUSED(dc))
169 { return Create(width,height); }
03647350 170
452418c4 171 virtual bool Create( const void* pData
6b5c2d52 172 ,wxBitmapType lType
3b9e3455
DW
173 ,int nWidth
174 ,int nHeight
175 ,int nDepth = 1
176 );
b6f4144e 177 virtual bool LoadFile( int nId
cbea3ec6 178 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
3b9e3455 179 );
c90c3400 180 virtual bool LoadFile( const wxString& rName
cbea3ec6 181 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
c90c3400 182 );
3b9e3455 183 virtual bool SaveFile( const wxString& rName
6b5c2d52 184 ,wxBitmapType lType
3b9e3455
DW
185 ,const wxPalette* pCmap = NULL
186 );
187
188 inline wxBitmapRefData* GetBitmapData() const
189 { return (wxBitmapRefData *)m_refData; }
190
6b5c2d52
SN
191 // raw bitmap access support functions
192 void *GetRawData(wxPixelDataBase& data, int bpp);
193 void UngetRawData(wxPixelDataBase& data);
194
3b9e3455 195 inline int GetQuality() const
58b16424 196 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
3b9e3455
DW
197
198 void SetQuality(int nQ);
199
200 wxPalette* GetPalette() const
d3b9f782 201 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : NULL); }
3b9e3455
DW
202
203 void SetPalette(const wxPalette& rPalette);
204
205 inline wxMask* GetMask() const
d3b9f782 206 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : NULL); }
3b9e3455
DW
207
208 void SetMask(wxMask* pMask) ;
209
3b9e3455
DW
210 // Implementation
211public:
58b16424
DW
212 inline void SetHBITMAP(WXHBITMAP hBmp)
213 { SetHandle((WXHANDLE)hBmp); }
3b9e3455
DW
214
215 inline WXHBITMAP GetHBITMAP() const
216 { return (WXHBITMAP)GetHandle(); }
217
218 inline void SetSelectedInto(wxDC* pDc)
58b16424 219 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
3b9e3455
DW
220
221 inline wxDC* GetSelectedInto() const
d3b9f782 222 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : NULL); }
3b9e3455 223
79c09341 224 inline bool IsMono(void) const { return m_bIsMono; }
1759c491 225
4f72fe4f 226 // An OS/2 version that probably doesn't do anything like the msw version
3b9e3455 227 wxBitmap GetBitmapForDC(wxDC& rDc) const;
0e320a79 228
3b9e3455
DW
229protected:
230 // common part of all ctors
231 void Init();
0e320a79 232
3b9e3455
DW
233 inline virtual wxGDIImageRefData* CreateData() const
234 { return new wxBitmapRefData; }
0e320a79 235
fd859211 236 bool CreateFromImage(const wxImage& image, int depth);
341366c6 237
8f884a0d 238 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
cd7ff808 239
3b9e3455
DW
240private:
241 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
0e320a79 242
79c09341 243 bool m_bIsMono;
3b9e3455 244 DECLARE_DYNAMIC_CLASS(wxBitmap)
341366c6 245}; // end of CLASS wxBitmap
d88de032 246
3b9e3455
DW
247// ----------------------------------------------------------------------------
248// wxMask: a mono bitmap used for drawing bitmaps transparently.
249// ----------------------------------------------------------------------------
0e320a79 250
53a2db12 251class WXDLLIMPEXP_CORE wxMask : public wxObject
3b9e3455
DW
252{
253public:
254 wxMask();
cd7ff808 255 wxMask( const wxMask& tocopy);
3b9e3455
DW
256
257 // Construct a mask from a bitmap and a colour indicating the transparent
258 // area
259 wxMask( const wxBitmap& rBitmap
260 ,const wxColour& rColour
261 );
262
263 // Construct a mask from a bitmap and a palette index indicating the
264 // transparent area
265 wxMask( const wxBitmap& rBitmap
266 ,int nPaletteIndex
267 );
268
269 // Construct a mask from a mono bitmap (copies the bitmap).
270 wxMask(const wxBitmap& rBitmap);
271
272 // construct a mask from the givne bitmap handle
273 wxMask(WXHBITMAP hBmp)
274 { m_hMaskBitmap = hBmp; }
275
276 virtual ~wxMask();
277
278 bool Create( const wxBitmap& bitmap
279 ,const wxColour& rColour
280 );
281 bool Create( const wxBitmap& rBitmap
282 ,int nPaletteIndex
283 );
284 bool Create(const wxBitmap& rBitmap);
285
286 // Implementation
287 WXHBITMAP GetMaskBitmap() const
288 { return m_hMaskBitmap; }
289 void SetMaskBitmap(WXHBITMAP hBmp)
290 { m_hMaskBitmap = hBmp; }
0e320a79 291
0e320a79 292protected:
3b9e3455
DW
293 WXHBITMAP m_hMaskBitmap;
294 DECLARE_DYNAMIC_CLASS(wxMask)
8bb6da4a 295}; // end of CLASS wxMask
3b9e3455
DW
296
297// ----------------------------------------------------------------------------
298// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
299// ----------------------------------------------------------------------------
0e320a79 300
53a2db12 301class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler
3b9e3455 302{
0e320a79 303public:
3b9e3455
DW
304 inline wxBitmapHandler()
305 { m_lType = wxBITMAP_TYPE_INVALID; }
306
307 inline wxBitmapHandler( const wxString& rName
308 ,const wxString& rExt
e86f2cc8 309 ,wxBitmapType lType
3b9e3455
DW
310 )
311 : wxGDIImageHandler( rName
312 ,rExt
313 ,lType)
314 {
315 }
316
317 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
318 // old class which worked only with bitmaps
319 virtual bool Create( wxBitmap* pBitmap
452418c4 320 ,const void* pData
e86f2cc8 321 ,wxBitmapType lType
3b9e3455
DW
322 ,int nWidth
323 ,int nHeight
324 ,int nDepth = 1
325 );
326 virtual bool LoadFile( wxBitmap* pBitmap
b6f4144e 327 ,int nId
e86f2cc8 328 ,wxBitmapType lType
3b9e3455
DW
329 ,int nDesiredWidth
330 ,int nDesiredHeight
331 );
c90c3400
SN
332 virtual bool LoadFile( wxBitmap* pBitmap
333 ,const wxString& rName
e86f2cc8 334 ,wxBitmapType lType
c90c3400
SN
335 ,int nDesiredWidth
336 ,int nDesiredHeight
337 );
3b9e3455
DW
338 virtual bool SaveFile( wxBitmap* pBitmap
339 ,const wxString& rName
e86f2cc8 340 ,wxBitmapType lType
3b9e3455 341 ,const wxPalette* pPalette = NULL
e86f2cc8 342 ) const;
3b9e3455
DW
343
344 virtual bool Create( wxGDIImage* pImage
452418c4 345 ,const void* pData
6b5c2d52 346 ,wxBitmapType lFlags
3b9e3455
DW
347 ,int nWidth
348 ,int nHeight
349 ,int nDepth = 1
350 );
351 virtual bool Load( wxGDIImage* pImage
b6f4144e 352 ,int nId
6b5c2d52 353 ,wxBitmapType lFlags
3b9e3455
DW
354 ,int nDesiredWidth
355 ,int nDesiredHeight
356 );
6b5c2d52
SN
357 virtual bool Save( const wxGDIImage* pImage
358 ,const wxString& rName
359 ,wxBitmapType lType
e86f2cc8 360 ) const;
3b9e3455 361private:
7e1e6965
WS
362 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
363 ,const wxString& WXUNUSED(rName)
4b3f61d1 364 ,WXHANDLE WXUNUSED(hPs)
6b5c2d52 365 ,wxBitmapType WXUNUSED(lFlags)
7e1e6965
WS
366 ,int WXUNUSED(nDesiredWidth)
367 ,int WXUNUSED(nDesiredHeight)
b6f4144e 368 )
7e1e6965 369 { return false; }
3b9e3455 370 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
8bb6da4a 371}; // end of CLASS wxBitmapHandler
3b9e3455 372
0e320a79
DW
373#endif
374 // _WX_BITMAP_H_