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