]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/bitmap.h
added inactive titlebar text colour
[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
8bb6da4a
DW
87 wxBitmap(const char** ppData);
88 wxBitmap(char** ppData);
3b9e3455
DW
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
fd859211
VS
109 wxBitmap( const wxImage& image, int depth = -1 )
110 { (void)CreateFromImage(image, depth); }
111
3b9e3455
DW
112 // we must have this, otherwise icons are silently copied into bitmaps using
113 // the copy ctor but the resulting bitmap is invalid!
114 inline wxBitmap(const wxIcon& rIcon)
115 { Init(); CopyFromIcon(rIcon); }
116
117 wxBitmap& operator=(const wxBitmap& rBitmap)
118 {
119 if ( m_refData != rBitmap.m_refData )
120 Ref(rBitmap);
121 return(*this);
122 }
123
124 wxBitmap& operator=(const wxIcon& rIcon)
125 {
126 (void)CopyFromIcon(rIcon);
127
128 return(*this);
129 }
130
131 wxBitmap& operator=(const wxCursor& rCursor)
132 {
133 (void)CopyFromCursor(rCursor);
134 return (*this);
135 }
136
137 virtual ~wxBitmap();
138
fd859211
VS
139 wxImage ConvertToImage() const;
140
341366c6
DW
141 // get the given part of bitmap
142 wxBitmap GetSubBitmap(const wxRect& rRect) const;
143
3b9e3455
DW
144 // copies the contents and mask of the given (colour) icon to the bitmap
145 bool CopyFromIcon(const wxIcon& rIcon);
146
147 // copies the contents and mask of the given cursor to the bitmap
148 bool CopyFromCursor(const wxCursor& rCursor);
149
150 virtual bool Create( int nWidth
151 ,int nHeight
152 ,int nDepth = -1
153 );
154 virtual bool Create( void* pData
155 ,long lType
156 ,int nWidth
157 ,int nHeight
158 ,int nDepth = 1
159 );
160 virtual bool LoadFile( const wxString& rName
161 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
162 );
163 virtual bool SaveFile( const wxString& rName
164 ,int lType
165 ,const wxPalette* pCmap = NULL
166 );
167
168 inline wxBitmapRefData* GetBitmapData() const
169 { return (wxBitmapRefData *)m_refData; }
170
171 inline int GetQuality() const
58b16424 172 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
3b9e3455
DW
173
174 void SetQuality(int nQ);
175
176 wxPalette* GetPalette() const
58b16424 177 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
3b9e3455
DW
178
179 void SetPalette(const wxPalette& rPalette);
180
181 inline wxMask* GetMask() const
58b16424 182 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
3b9e3455
DW
183
184 void SetMask(wxMask* pMask) ;
185
186 inline bool operator==(const wxBitmap& rBitmap)
187 { return m_refData == rBitmap.m_refData; }
188
189 inline bool operator!=(const wxBitmap& rBitmap)
190 { return m_refData != rBitmap.m_refData; }
191
192#if WXWIN_COMPATIBILITY_2
193 void SetOk(bool bIsOk);
194#endif // WXWIN_COMPATIBILITY_2
0e320a79 195
3b9e3455
DW
196#if WXWIN_COMPATIBILITY
197 inline wxPalette* GetColourMap() const
198 { return GetPalette(); }
0e320a79 199
3b9e3455
DW
200 inline void SetColourMap(wxPalette* pCmap)
201 { SetPalette(*pCmap); };
0e320a79 202
3b9e3455 203#endif // WXWIN_COMPATIBILITY
0e320a79 204
3b9e3455
DW
205 // Implementation
206public:
58b16424
DW
207 inline void SetHBITMAP(WXHBITMAP hBmp)
208 { SetHandle((WXHANDLE)hBmp); }
3b9e3455
DW
209
210 inline WXHBITMAP GetHBITMAP() const
211 { return (WXHBITMAP)GetHandle(); }
212
213 inline void SetSelectedInto(wxDC* pDc)
58b16424 214 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
3b9e3455
DW
215
216 inline wxDC* GetSelectedInto() const
58b16424 217 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
3b9e3455 218
4f72fe4f 219 // An OS/2 version that probably doesn't do anything like the msw version
3b9e3455 220 wxBitmap GetBitmapForDC(wxDC& rDc) const;
0e320a79 221
8bb6da4a
DW
222// inline LONG GetId() const
223// { return (GetBitmapData() ? GetBitmapData()->m_lId : 0L); }
fd368161
DW
224
225
3b9e3455
DW
226protected:
227 // common part of all ctors
228 void Init();
0e320a79 229
3b9e3455
DW
230 inline virtual wxGDIImageRefData* CreateData() const
231 { return new wxBitmapRefData; }
0e320a79 232
341366c6
DW
233 // creates the bitmap from XPM data, supposed to be called from ctor
234 bool CreateFromXpm(const char **bits);
fd859211 235 bool CreateFromImage(const wxImage& image, int depth);
341366c6 236
3b9e3455
DW
237private:
238 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
0e320a79 239
3b9e3455 240 DECLARE_DYNAMIC_CLASS(wxBitmap)
341366c6 241}; // end of CLASS wxBitmap
d88de032 242
3b9e3455
DW
243// ----------------------------------------------------------------------------
244// wxMask: a mono bitmap used for drawing bitmaps transparently.
245// ----------------------------------------------------------------------------
0e320a79 246
3b9e3455
DW
247class WXDLLEXPORT wxMask : public wxObject
248{
249public:
250 wxMask();
251
252 // Construct a mask from a bitmap and a colour indicating the transparent
253 // area
254 wxMask( const wxBitmap& rBitmap
255 ,const wxColour& rColour
256 );
257
258 // Construct a mask from a bitmap and a palette index indicating the
259 // transparent area
260 wxMask( const wxBitmap& rBitmap
261 ,int nPaletteIndex
262 );
263
264 // Construct a mask from a mono bitmap (copies the bitmap).
265 wxMask(const wxBitmap& rBitmap);
266
267 // construct a mask from the givne bitmap handle
268 wxMask(WXHBITMAP hBmp)
269 { m_hMaskBitmap = hBmp; }
270
271 virtual ~wxMask();
272
273 bool Create( const wxBitmap& bitmap
274 ,const wxColour& rColour
275 );
276 bool Create( const wxBitmap& rBitmap
277 ,int nPaletteIndex
278 );
279 bool Create(const wxBitmap& rBitmap);
280
281 // Implementation
282 WXHBITMAP GetMaskBitmap() const
283 { return m_hMaskBitmap; }
284 void SetMaskBitmap(WXHBITMAP hBmp)
285 { m_hMaskBitmap = hBmp; }
0e320a79 286
0e320a79 287protected:
3b9e3455
DW
288 WXHBITMAP m_hMaskBitmap;
289 DECLARE_DYNAMIC_CLASS(wxMask)
8bb6da4a 290}; // end of CLASS wxMask
3b9e3455
DW
291
292// ----------------------------------------------------------------------------
293// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
294// ----------------------------------------------------------------------------
0e320a79 295
3b9e3455
DW
296class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
297{
0e320a79 298public:
3b9e3455
DW
299 inline wxBitmapHandler()
300 { m_lType = wxBITMAP_TYPE_INVALID; }
301
302 inline wxBitmapHandler( const wxString& rName
303 ,const wxString& rExt
304 ,long lType
305 )
306 : wxGDIImageHandler( rName
307 ,rExt
308 ,lType)
309 {
310 }
311
312 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
313 // old class which worked only with bitmaps
314 virtual bool Create( wxBitmap* pBitmap
315 ,void* pData
316 ,long lFlags
317 ,int nWidth
318 ,int nHeight
319 ,int nDepth = 1
320 );
321 virtual bool LoadFile( wxBitmap* pBitmap
322 ,const wxString& rName
8ea3f821 323 ,HPS hPs
3b9e3455
DW
324 ,long lFlags
325 ,int nDesiredWidth
326 ,int nDesiredHeight
327 );
328 virtual bool SaveFile( wxBitmap* pBitmap
329 ,const wxString& rName
330 ,int lType
331 ,const wxPalette* pPalette = NULL
332 );
333
334 virtual bool Create( wxGDIImage* pImage
335 ,void* pData
336 ,long lFlags
337 ,int nWidth
338 ,int nHeight
339 ,int nDepth = 1
340 );
341 virtual bool Load( wxGDIImage* pImage
342 ,const wxString& rName
8ea3f821 343 ,HPS hPs
3b9e3455
DW
344 ,long lFlags
345 ,int nDesiredWidth
346 ,int nDesiredHeight
347 );
58b16424
DW
348 virtual bool Save( wxGDIImage* pImage
349 ,const wxString& rName
350 ,int lType
3b9e3455
DW
351 );
352private:
353 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
8bb6da4a 354}; // end of CLASS wxBitmapHandler
3b9e3455 355
0e320a79
DW
356#endif
357 // _WX_BITMAP_H_