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