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