]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / os2 / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Webster
5 // Modified by:
6 // Created: 11/28/99
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_BITMAP_H_
12 #define _WX_BITMAP_H_
13
14 #include "wx/os2/private.h"
15 #include "wx/os2/gdiimage.h"
16 #include "wx/gdicmn.h"
17 #include "wx/palette.h"
18
19 class WXDLLIMPEXP_FWD_CORE wxDC;
20 class WXDLLIMPEXP_FWD_CORE wxControl;
21 class WXDLLIMPEXP_FWD_CORE wxBitmap;
22 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
23 class WXDLLIMPEXP_FWD_CORE wxIcon;
24 class WXDLLIMPEXP_FWD_CORE wxMask;
25 class WXDLLIMPEXP_FWD_CORE wxCursor;
26 class WXDLLIMPEXP_FWD_CORE wxControl;
27 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
28
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 // ----------------------------------------------------------------------------
35
36 class WXDLLIMPEXP_CORE wxBitmapRefData : public wxGDIImageRefData
37 {
38 public:
39 wxBitmapRefData();
40 wxBitmapRefData(const wxBitmapRefData &tocopy);
41 virtual ~wxBitmapRefData() { Free(); }
42
43 virtual void Free();
44
45 public:
46 int m_nNumColors;
47 wxPalette m_vBitmapPalette;
48 int m_nQuality;
49
50 // OS2-specific
51 // ------------
52
53 wxDC* m_pSelectedInto;
54
55 //
56 // Optional mask for transparent drawing
57 //
58 wxMask* m_pBitmapMask;
59 }; // end of CLASS wxBitmapRefData
60
61 // ----------------------------------------------------------------------------
62 // wxBitmap: a mono or colour bitmap
63 // ----------------------------------------------------------------------------
64
65 class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage,
66 public wxBitmapHelpers
67 {
68 public:
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)
74 : wxGDIImage(rBitmap)
75 {
76 Init();
77 SetHandle(rBitmap.GetHandle());
78 }
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
88 wxBitmap(const char* const* bits);
89 #ifdef wxNEEDS_CHARPP
90 // needed for old GCC
91 wxBitmap(char** data)
92 {
93 *this = wxBitmap(const_cast<const char* const*>(data));
94 }
95 #endif
96
97 // Load a resource
98 wxBitmap( int nId
99 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
100 );
101
102 // For compatiability with other ports, under OS/2 does same as default ctor
103 inline wxBitmap( const wxString& WXUNUSED(rFilename)
104 ,wxBitmapType WXUNUSED(lType)
105 )
106 { Init(); }
107 // New constructor for generalised creation from data
108 wxBitmap( const void* pData
109 ,wxBitmapType lType
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
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 }
126
127 wxBitmap( const wxImage& image, int depth = -1 )
128 { (void)CreateFromImage(image, depth); }
129
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
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
150 wxImage ConvertToImage() const;
151 wxBitmap ConvertToDisabled(unsigned char brightness = 255) const;
152
153 // get the given part of bitmap
154 wxBitmap GetSubBitmap(const wxRect& rRect) const;
155
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
164 ,int nDepth = wxBITMAP_SCREEN_DEPTH
165 );
166 virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
167 { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
168 virtual bool Create(int width, int height, const wxDC& WXUNUSED(dc))
169 { return Create(width,height); }
170
171 virtual bool Create( const void* pData
172 ,wxBitmapType lType
173 ,int nWidth
174 ,int nHeight
175 ,int nDepth = 1
176 );
177 virtual bool LoadFile( int nId
178 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
179 );
180 virtual bool LoadFile( const wxString& rName
181 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
182 );
183 virtual bool SaveFile( const wxString& rName
184 ,wxBitmapType lType
185 ,const wxPalette* pCmap = NULL
186 );
187
188 inline wxBitmapRefData* GetBitmapData() const
189 { return (wxBitmapRefData *)m_refData; }
190
191 // raw bitmap access support functions
192 void *GetRawData(wxPixelDataBase& data, int bpp);
193 void UngetRawData(wxPixelDataBase& data);
194
195 inline int GetQuality() const
196 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
197
198 void SetQuality(int nQ);
199
200 wxPalette* GetPalette() const
201 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : NULL); }
202
203 void SetPalette(const wxPalette& rPalette);
204
205 inline wxMask* GetMask() const
206 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : NULL); }
207
208 void SetMask(wxMask* pMask) ;
209
210 // Implementation
211 public:
212 inline void SetHBITMAP(WXHBITMAP hBmp)
213 { SetHandle((WXHANDLE)hBmp); }
214
215 inline WXHBITMAP GetHBITMAP() const
216 { return (WXHBITMAP)GetHandle(); }
217
218 inline void SetSelectedInto(wxDC* pDc)
219 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
220
221 inline wxDC* GetSelectedInto() const
222 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : NULL); }
223
224 inline bool IsMono(void) const { return m_bIsMono; }
225
226 // An OS/2 version that probably doesn't do anything like the msw version
227 wxBitmap GetBitmapForDC(wxDC& rDc) const;
228
229 protected:
230 // common part of all ctors
231 void Init();
232
233 inline virtual wxGDIImageRefData* CreateData() const
234 { return new wxBitmapRefData; }
235
236 bool CreateFromImage(const wxImage& image, int depth);
237
238 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
239
240 private:
241 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
242
243 bool m_bIsMono;
244 DECLARE_DYNAMIC_CLASS(wxBitmap)
245 }; // end of CLASS wxBitmap
246
247 // ----------------------------------------------------------------------------
248 // wxMask: a mono bitmap used for drawing bitmaps transparently.
249 // ----------------------------------------------------------------------------
250
251 class WXDLLIMPEXP_CORE wxMask : public wxObject
252 {
253 public:
254 wxMask();
255 wxMask( const wxMask& tocopy);
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; }
291
292 protected:
293 WXHBITMAP m_hMaskBitmap;
294 DECLARE_DYNAMIC_CLASS(wxMask)
295 }; // end of CLASS wxMask
296
297 // ----------------------------------------------------------------------------
298 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
299 // ----------------------------------------------------------------------------
300
301 class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler
302 {
303 public:
304 inline wxBitmapHandler()
305 { m_lType = wxBITMAP_TYPE_INVALID; }
306
307 inline wxBitmapHandler( const wxString& rName
308 ,const wxString& rExt
309 ,wxBitmapType lType
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
320 ,const void* pData
321 ,wxBitmapType lType
322 ,int nWidth
323 ,int nHeight
324 ,int nDepth = 1
325 );
326 virtual bool LoadFile( wxBitmap* pBitmap
327 ,int nId
328 ,wxBitmapType lType
329 ,int nDesiredWidth
330 ,int nDesiredHeight
331 );
332 virtual bool LoadFile( wxBitmap* pBitmap
333 ,const wxString& rName
334 ,wxBitmapType lType
335 ,int nDesiredWidth
336 ,int nDesiredHeight
337 );
338 virtual bool SaveFile( wxBitmap* pBitmap
339 ,const wxString& rName
340 ,wxBitmapType lType
341 ,const wxPalette* pPalette = NULL
342 ) const;
343
344 virtual bool Create( wxGDIImage* pImage
345 ,const void* pData
346 ,wxBitmapType lFlags
347 ,int nWidth
348 ,int nHeight
349 ,int nDepth = 1
350 );
351 virtual bool Load( wxGDIImage* pImage
352 ,int nId
353 ,wxBitmapType lFlags
354 ,int nDesiredWidth
355 ,int nDesiredHeight
356 );
357 virtual bool Save( const wxGDIImage* pImage
358 ,const wxString& rName
359 ,wxBitmapType lType
360 ) const;
361 private:
362 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
363 ,const wxString& WXUNUSED(rName)
364 ,WXHANDLE WXUNUSED(hPs)
365 ,wxBitmapType WXUNUSED(lFlags)
366 ,int WXUNUSED(nDesiredWidth)
367 ,int WXUNUSED(nDesiredHeight)
368 )
369 { return false; }
370 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
371 }; // end of CLASS wxBitmapHandler
372
373 #endif
374 // _WX_BITMAP_H_