]> git.saurik.com Git - wxWidgets.git/blame - include/wx/palmos/bitmap.h
Warning fix (instead of silencing int->short with typecast, have the same type intern...
[wxWidgets.git] / include / wx / palmos / bitmap.h
CommitLineData
ffecfa5a
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/palmos/bitmap.h
3// Purpose: wxBitmap class
e1d63b79 4// Author: William Osborne - minimal working wxPalmOS port
ffecfa5a
JS
5// Modified by:
6// Created: 10/13/04
e1d63b79 7// RCS-ID: $Id$
ffecfa5a
JS
8// Copyright: (c) William Osborne
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_BITMAP_H_
13#define _WX_BITMAP_H_
14
ffecfa5a
JS
15#include "wx/palmos/gdiimage.h"
16#include "wx/gdicmn.h"
17#include "wx/palette.h"
18
19class WXDLLEXPORT wxBitmap;
20class WXDLLEXPORT wxBitmapHandler;
21class WXDLLEXPORT wxBitmapRefData;
22class WXDLLEXPORT wxControl;
23class WXDLLEXPORT wxCursor;
24class WXDLLEXPORT wxDC;
25#if wxUSE_WXDIB
26class WXDLLEXPORT wxDIB;
27#endif
28class WXDLLEXPORT wxIcon;
29class WXDLLEXPORT wxImage;
30class WXDLLEXPORT wxMask;
31class WXDLLEXPORT wxPalette;
32class WXDLLEXPORT wxPixelDataBase;
33
34// ----------------------------------------------------------------------------
35// wxBitmap: a mono or colour bitmap
36// ----------------------------------------------------------------------------
37
38class WXDLLEXPORT wxBitmap : public wxGDIImage
39{
40public:
41 // default ctor creates an invalid bitmap, you must Create() it later
42 wxBitmap() { Init(); }
43
44 // Copy constructors
45 wxBitmap(const wxBitmap& bitmap) { Init(); Ref(bitmap); }
46
47 // Initialize with raw data
48 wxBitmap(const char bits[], int width, int height, int depth = 1);
49
50 // Initialize with XPM data
51 wxBitmap(const char **data) { CreateFromXpm(data); }
52 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
53
54 // Load a file or resource
55 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
56
57 // New constructor for generalised creation from data
58 wxBitmap(void *data, long type, int width, int height, int depth = 1);
59
60 // Create a new, uninitialized bitmap of the given size and depth (if it
61 // is omitted, will create a bitmap compatible with the display)
62 //
63 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
64 // taking a DC argument if you want to force using DDB in this case
65 wxBitmap(int width, int height, int depth = -1);
66
67 // Create a bitmap compatible with the given DC
68 wxBitmap(int width, int height, const wxDC& dc);
69
70#if wxUSE_IMAGE && wxUSE_WXDIB
71 // Convert from wxImage
72 wxBitmap(const wxImage& image, int depth = -1)
73 { (void)CreateFromImage(image, depth); }
74
75 // Create a DDB compatible with the given DC from wxImage
76 wxBitmap(const wxImage& image, const wxDC& dc)
77 { (void)CreateFromImage(image, dc); }
78#endif // wxUSE_IMAGE
79
80 // we must have this, otherwise icons are silently copied into bitmaps using
81 // the copy ctor but the resulting bitmap is invalid!
82 wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
83
84 wxBitmap& operator=(const wxBitmap& bitmap)
85 {
86 if ( m_refData != bitmap.m_refData )
87 Ref(bitmap);
88 return *this;
89 }
90
91 wxBitmap& operator=(const wxIcon& icon)
92 {
93 (void)CopyFromIcon(icon);
94
95 return *this;
96 }
97
98 wxBitmap& operator=(const wxCursor& cursor)
99 {
100 (void)CopyFromCursor(cursor);
101
102 return *this;
103 }
104
105 virtual ~wxBitmap();
106
107#if wxUSE_IMAGE && wxUSE_WXDIB
108 wxImage ConvertToImage() const;
109#endif // wxUSE_IMAGE
110
111 // get the given part of bitmap
112 wxBitmap GetSubBitmap( const wxRect& rect ) const;
113
114 // copies the contents and mask of the given (colour) icon to the bitmap
115 bool CopyFromIcon(const wxIcon& icon);
116
117 // copies the contents and mask of the given cursor to the bitmap
118 bool CopyFromCursor(const wxCursor& cursor);
119
120#if wxUSE_WXDIB
121 // copies from a device independent bitmap
122 bool CopyFromDIB(const wxDIB& dib);
123#endif
124
125 virtual bool Create(int width, int height, int depth = -1);
126 virtual bool Create(int width, int height, const wxDC& dc);
127 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
128 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
129 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
130
131 wxBitmapRefData *GetBitmapData() const
132 { return (wxBitmapRefData *)m_refData; }
133
134 // raw bitmap access support functions
135 void *GetRawData(wxPixelDataBase& data, int bpp);
136 void UngetRawData(wxPixelDataBase& data);
137
138#if wxUSE_PALETTE
139 wxPalette* GetPalette() const;
140 void SetPalette(const wxPalette& palette);
141#endif // wxUSE_PALETTE
142
143 wxMask *GetMask() const;
144 void SetMask(wxMask *mask);
145
146 bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
147 bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
148
149 // these functions are internal and shouldn't be used, they risk to
150 // disappear in the future
151 bool HasAlpha() const;
152 void UseAlpha();
153
ffecfa5a
JS
154 // implementation only from now on
155 // -------------------------------
156
157public:
158 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
159 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
160
161#ifdef __WXDEBUG__
162 void SetSelectedInto(wxDC *dc);
163 wxDC *GetSelectedInto() const;
164#endif // __WXDEBUG__
165
166protected:
167 // common part of all ctors
168 void Init();
169
170 virtual wxGDIImageRefData *CreateData() const;
171
172 // creates the bitmap from XPM data, supposed to be called from ctor
173 bool CreateFromXpm(const char **bits);
174
175 // creates an uninitialized bitmap, called from Create()s above
176 bool DoCreate(int w, int h, int depth, WXHDC hdc);
177
178#if wxUSE_IMAGE && wxUSE_WXDIB
179 // creates the bitmap from wxImage, supposed to be called from ctor
180 bool CreateFromImage(const wxImage& image, int depth);
181
182 // creates a DDB from wxImage, supposed to be called from ctor
183 bool CreateFromImage(const wxImage& image, const wxDC& dc);
184
185 // common part of the 2 methods above (hdc may be 0)
186 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
187#endif // wxUSE_IMAGE
188
189private:
ffecfa5a
JS
190 DECLARE_DYNAMIC_CLASS(wxBitmap)
191};
192
193// ----------------------------------------------------------------------------
194// wxMask: a mono bitmap used for drawing bitmaps transparently.
195// ----------------------------------------------------------------------------
196
197class WXDLLEXPORT wxMask : public wxObject
198{
199public:
200 wxMask();
201
202 // Construct a mask from a bitmap and a colour indicating the transparent
203 // area
204 wxMask(const wxBitmap& bitmap, const wxColour& colour);
205
206 // Construct a mask from a bitmap and a palette index indicating the
207 // transparent area
208 wxMask(const wxBitmap& bitmap, int paletteIndex);
209
210 // Construct a mask from a mono bitmap (copies the bitmap).
211 wxMask(const wxBitmap& bitmap);
212
213 // construct a mask from the givne bitmap handle
214 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
215
216 virtual ~wxMask();
217
218 bool Create(const wxBitmap& bitmap, const wxColour& colour);
219 bool Create(const wxBitmap& bitmap, int paletteIndex);
220 bool Create(const wxBitmap& bitmap);
221
222 // Implementation
223 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
224 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
225
226protected:
227 WXHBITMAP m_maskBitmap;
228
229 DECLARE_DYNAMIC_CLASS(wxMask)
230};
231
232// ----------------------------------------------------------------------------
233// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
234// ----------------------------------------------------------------------------
235
236class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
237{
238public:
239 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
240 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
241 : wxGDIImageHandler(name, ext, type)
242 {
243 }
244
245 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
246 // old class which worked only with bitmaps
247 virtual bool Create(wxBitmap *bitmap,
248 void *data,
249 long flags,
250 int width, int height, int depth = 1);
251 virtual bool LoadFile(wxBitmap *bitmap,
252 const wxString& name,
253 long flags,
254 int desiredWidth, int desiredHeight);
255 virtual bool SaveFile(wxBitmap *bitmap,
256 const wxString& name,
257 int type,
258 const wxPalette *palette = NULL);
259
260 virtual bool Create(wxGDIImage *image,
261 void *data,
262 long flags,
263 int width, int height, int depth = 1);
264 virtual bool Load(wxGDIImage *image,
265 const wxString& name,
266 long flags,
267 int desiredWidth, int desiredHeight);
268 virtual bool Save(wxGDIImage *image,
269 const wxString& name,
270 int type);
271
272private:
273 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
274};
275
276#endif
277 // _WX_BITMAP_H_