]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
temporary fix the linking problem due to making GSocket::Detected_Read/Write() non...
[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 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BITMAP_H_
13 #define _WX_BITMAP_H_
14
15 #include "wx/os2/private.h"
16 #include "wx/os2/gdiimage.h"
17 #include "wx/gdicmn.h"
18 #include "wx/palette.h"
19
20 class WXDLLIMPEXP_FWD_CORE wxDC;
21 class WXDLLIMPEXP_FWD_CORE wxControl;
22 class WXDLLIMPEXP_FWD_CORE wxBitmap;
23 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
24 class WXDLLIMPEXP_FWD_CORE wxIcon;
25 class WXDLLIMPEXP_FWD_CORE wxMask;
26 class WXDLLIMPEXP_FWD_CORE wxCursor;
27 class WXDLLIMPEXP_FWD_CORE wxControl;
28 class WXDLLIMPEXP_FWD_CORE wxImage;
29 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
30
31 // ----------------------------------------------------------------------------
32 // Bitmap data
33 //
34 // NB: this class is private, but declared here to make it possible inline
35 // wxBitmap functions accessing it
36 // ----------------------------------------------------------------------------
37
38 class WXDLLIMPEXP_CORE wxBitmapRefData : public wxGDIImageRefData
39 {
40 public:
41 wxBitmapRefData();
42 wxBitmapRefData(const wxBitmapRefData &tocopy);
43 virtual ~wxBitmapRefData() { Free(); }
44
45 virtual void Free();
46
47 public:
48 int m_nNumColors;
49 wxPalette m_vBitmapPalette;
50 int m_nQuality;
51
52 // OS2-specific
53 // ------------
54
55 wxDC* m_pSelectedInto;
56
57 //
58 // Optional mask for transparent drawing
59 //
60 wxMask* m_pBitmapMask;
61 }; // end of CLASS wxBitmapRefData
62
63 // ----------------------------------------------------------------------------
64 // wxBitmap: a mono or colour bitmap
65 // ----------------------------------------------------------------------------
66
67 class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage
68 {
69 public:
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)
75 : wxGDIImage(rBitmap)
76 {
77 Init();
78 SetHandle(rBitmap.GetHandle());
79 }
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
89 wxBitmap(const char* const* bits);
90 #ifdef wxNEEDS_CHARPP
91 // needed for old GCC
92 wxBitmap(char** data)
93 {
94 *this = wxBitmap(const_cast<const char* const*>(data));
95 }
96 #endif
97
98 // Load a resource
99 wxBitmap( int nId
100 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
101 );
102
103 // For compatiability with other ports, under OS/2 does same as default ctor
104 inline wxBitmap( const wxString& WXUNUSED(rFilename)
105 ,wxBitmapType WXUNUSED(lType)
106 )
107 { Init(); }
108 // New constructor for generalised creation from data
109 wxBitmap( const void* pData
110 ,wxBitmapType lType
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
117 wxBitmap( int nWidth, int nHeight, int nDepth = -1 );
118
119 wxBitmap( const wxImage& image, int depth = -1 )
120 { (void)CreateFromImage(image, depth); }
121
122 // we must have this, otherwise icons are silently copied into bitmaps using
123 // the copy ctor but the resulting bitmap is invalid!
124 inline wxBitmap(const wxIcon& rIcon)
125 { Init(); CopyFromIcon(rIcon); }
126
127 wxBitmap& operator=(const wxIcon& rIcon)
128 {
129 (void)CopyFromIcon(rIcon);
130
131 return(*this);
132 }
133
134 wxBitmap& operator=(const wxCursor& rCursor)
135 {
136 (void)CopyFromCursor(rCursor);
137 return (*this);
138 }
139
140 virtual ~wxBitmap();
141
142 wxImage ConvertToImage() const;
143
144 // get the given part of bitmap
145 wxBitmap GetSubBitmap(const wxRect& rRect) const;
146
147 // copies the contents and mask of the given (colour) icon to the bitmap
148 bool CopyFromIcon(const wxIcon& rIcon);
149
150 // copies the contents and mask of the given cursor to the bitmap
151 bool CopyFromCursor(const wxCursor& rCursor);
152
153 virtual bool Create( int nWidth
154 ,int nHeight
155 ,int nDepth = -1
156 );
157 virtual bool Create( const void* pData
158 ,wxBitmapType lType
159 ,int nWidth
160 ,int nHeight
161 ,int nDepth = 1
162 );
163 virtual bool LoadFile( int nId
164 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
165 );
166 virtual bool LoadFile( const wxString& rName
167 ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE
168 );
169 virtual bool SaveFile( const wxString& rName
170 ,wxBitmapType lType
171 ,const wxPalette* pCmap = NULL
172 );
173
174 inline wxBitmapRefData* GetBitmapData() const
175 { return (wxBitmapRefData *)m_refData; }
176
177 // raw bitmap access support functions
178 void *GetRawData(wxPixelDataBase& data, int bpp);
179 void UngetRawData(wxPixelDataBase& data);
180
181 inline int GetQuality() const
182 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
183
184 void SetQuality(int nQ);
185
186 wxPalette* GetPalette() const
187 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
188
189 void SetPalette(const wxPalette& rPalette);
190
191 inline wxMask* GetMask() const
192 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
193
194 void SetMask(wxMask* pMask) ;
195
196 // Implementation
197 public:
198 inline void SetHBITMAP(WXHBITMAP hBmp)
199 { SetHandle((WXHANDLE)hBmp); }
200
201 inline WXHBITMAP GetHBITMAP() const
202 { return (WXHBITMAP)GetHandle(); }
203
204 inline void SetSelectedInto(wxDC* pDc)
205 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
206
207 inline wxDC* GetSelectedInto() const
208 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
209
210 inline bool IsMono(void) const { return m_bIsMono; }
211
212 // An OS/2 version that probably doesn't do anything like the msw version
213 wxBitmap GetBitmapForDC(wxDC& rDc) const;
214
215 protected:
216 // common part of all ctors
217 void Init();
218
219 inline virtual wxGDIImageRefData* CreateData() const
220 { return new wxBitmapRefData; }
221
222 bool CreateFromImage(const wxImage& image, int depth);
223
224 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
225
226 private:
227 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
228
229 bool m_bIsMono;
230 DECLARE_DYNAMIC_CLASS(wxBitmap)
231 }; // end of CLASS wxBitmap
232
233 // ----------------------------------------------------------------------------
234 // wxMask: a mono bitmap used for drawing bitmaps transparently.
235 // ----------------------------------------------------------------------------
236
237 class WXDLLIMPEXP_CORE wxMask : public wxObject
238 {
239 public:
240 wxMask();
241 wxMask( const wxMask& tocopy);
242
243 // Construct a mask from a bitmap and a colour indicating the transparent
244 // area
245 wxMask( const wxBitmap& rBitmap
246 ,const wxColour& rColour
247 );
248
249 // Construct a mask from a bitmap and a palette index indicating the
250 // transparent area
251 wxMask( const wxBitmap& rBitmap
252 ,int nPaletteIndex
253 );
254
255 // Construct a mask from a mono bitmap (copies the bitmap).
256 wxMask(const wxBitmap& rBitmap);
257
258 // construct a mask from the givne bitmap handle
259 wxMask(WXHBITMAP hBmp)
260 { m_hMaskBitmap = hBmp; }
261
262 virtual ~wxMask();
263
264 bool Create( const wxBitmap& bitmap
265 ,const wxColour& rColour
266 );
267 bool Create( const wxBitmap& rBitmap
268 ,int nPaletteIndex
269 );
270 bool Create(const wxBitmap& rBitmap);
271
272 // Implementation
273 WXHBITMAP GetMaskBitmap() const
274 { return m_hMaskBitmap; }
275 void SetMaskBitmap(WXHBITMAP hBmp)
276 { m_hMaskBitmap = hBmp; }
277
278 protected:
279 WXHBITMAP m_hMaskBitmap;
280 DECLARE_DYNAMIC_CLASS(wxMask)
281 }; // end of CLASS wxMask
282
283 // ----------------------------------------------------------------------------
284 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
285 // ----------------------------------------------------------------------------
286
287 class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler
288 {
289 public:
290 inline wxBitmapHandler()
291 { m_lType = wxBITMAP_TYPE_INVALID; }
292
293 inline wxBitmapHandler( const wxString& rName
294 ,const wxString& rExt
295 ,wxBitmapType lType
296 )
297 : wxGDIImageHandler( rName
298 ,rExt
299 ,lType)
300 {
301 }
302
303 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
304 // old class which worked only with bitmaps
305 virtual bool Create( wxBitmap* pBitmap
306 ,const void* pData
307 ,wxBitmapType lType
308 ,int nWidth
309 ,int nHeight
310 ,int nDepth = 1
311 );
312 virtual bool LoadFile( wxBitmap* pBitmap
313 ,int nId
314 ,wxBitmapType lType
315 ,int nDesiredWidth
316 ,int nDesiredHeight
317 );
318 virtual bool LoadFile( wxBitmap* pBitmap
319 ,const wxString& rName
320 ,wxBitmapType lType
321 ,int nDesiredWidth
322 ,int nDesiredHeight
323 );
324 virtual bool SaveFile( wxBitmap* pBitmap
325 ,const wxString& rName
326 ,wxBitmapType lType
327 ,const wxPalette* pPalette = NULL
328 ) const;
329
330 virtual bool Create( wxGDIImage* pImage
331 ,const void* pData
332 ,wxBitmapType lFlags
333 ,int nWidth
334 ,int nHeight
335 ,int nDepth = 1
336 );
337 virtual bool Load( wxGDIImage* pImage
338 ,int nId
339 ,wxBitmapType lFlags
340 ,int nDesiredWidth
341 ,int nDesiredHeight
342 );
343 virtual bool Save( const wxGDIImage* pImage
344 ,const wxString& rName
345 ,wxBitmapType lType
346 ) const;
347 private:
348 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
349 ,const wxString& WXUNUSED(rName)
350 ,WXHANDLE WXUNUSED(hPs)
351 ,wxBitmapType WXUNUSED(lFlags)
352 ,int WXUNUSED(nDesiredWidth)
353 ,int WXUNUSED(nDesiredHeight)
354 )
355 { return false; }
356 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
357 }; // end of CLASS wxBitmapHandler
358
359 #endif
360 // _WX_BITMAP_H_