]> git.saurik.com Git - wxWidgets.git/blame - include/wx/palmos/bitmap.h
added wxTempFile::Flush() (dedicated to Theodore Ts'o and Ext4)
[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
b5dbe15d
VS
19class WXDLLIMPEXP_FWD_CORE wxBitmap;
20class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
21class WXDLLIMPEXP_FWD_CORE wxBitmapRefData;
22class WXDLLIMPEXP_FWD_CORE wxControl;
23class WXDLLIMPEXP_FWD_CORE wxCursor;
24class WXDLLIMPEXP_FWD_CORE wxDC;
ffecfa5a 25#if wxUSE_WXDIB
b5dbe15d 26class WXDLLIMPEXP_FWD_CORE wxDIB;
ffecfa5a 27#endif
b5dbe15d
VS
28class WXDLLIMPEXP_FWD_CORE wxIcon;
29class WXDLLIMPEXP_FWD_CORE wxImage;
30class WXDLLIMPEXP_FWD_CORE wxMask;
31class WXDLLIMPEXP_FWD_CORE wxPalette;
32class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
ffecfa5a
JS
33
34// ----------------------------------------------------------------------------
35// wxBitmap: a mono or colour bitmap
36// ----------------------------------------------------------------------------
37
53a2db12 38class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage
ffecfa5a
JS
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
452418c4 48 wxBitmap(const char* const* data);
ffecfa5a
JS
49
50 // Load a file or resource
cbea3ec6 51 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
ffecfa5a
JS
52
53 // New constructor for generalised creation from data
452418c4 54 wxBitmap(const void* data, long type, int width, int height, int depth = 1);
ffecfa5a
JS
55
56 // Create a new, uninitialized bitmap of the given size and depth (if it
57 // is omitted, will create a bitmap compatible with the display)
58 //
59 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
60 // taking a DC argument if you want to force using DDB in this case
732d8c74
FM
61 wxBitmap(int width, int height, int depth = -1) { /*TODO*/ }
62 wxBitmap(const wxSize& sz, int depth = -1) { /*TODO*/ }
ffecfa5a
JS
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
732d8c74 95 virtual ~wxBitmap() {}
ffecfa5a
JS
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
732d8c74
FM
115 virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
116 virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
117 { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
118
ffecfa5a 119 virtual bool Create(int width, int height, const wxDC& dc);
452418c4 120 virtual bool Create(const void* data, long type, int width, int height, int depth = 1);
cbea3ec6 121 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_DEFAULT_TYPE);
ffecfa5a
JS
122 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
123
124 wxBitmapRefData *GetBitmapData() const
125 { return (wxBitmapRefData *)m_refData; }
126
127 // raw bitmap access support functions
128 void *GetRawData(wxPixelDataBase& data, int bpp);
129 void UngetRawData(wxPixelDataBase& data);
130
131#if wxUSE_PALETTE
132 wxPalette* GetPalette() const;
133 void SetPalette(const wxPalette& palette);
134#endif // wxUSE_PALETTE
135
136 wxMask *GetMask() const;
137 void SetMask(wxMask *mask);
138
ffecfa5a
JS
139 // these functions are internal and shouldn't be used, they risk to
140 // disappear in the future
141 bool HasAlpha() const;
ffecfa5a 142
ffecfa5a
JS
143 // implementation only from now on
144 // -------------------------------
145
146public:
147 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
148 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
149
ffecfa5a
JS
150protected:
151 // common part of all ctors
152 void Init();
153
154 virtual wxGDIImageRefData *CreateData() const;
155
ffecfa5a
JS
156 // creates an uninitialized bitmap, called from Create()s above
157 bool DoCreate(int w, int h, int depth, WXHDC hdc);
158
159#if wxUSE_IMAGE && wxUSE_WXDIB
160 // creates the bitmap from wxImage, supposed to be called from ctor
161 bool CreateFromImage(const wxImage& image, int depth);
162
163 // creates a DDB from wxImage, supposed to be called from ctor
164 bool CreateFromImage(const wxImage& image, const wxDC& dc);
165
166 // common part of the 2 methods above (hdc may be 0)
167 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
168#endif // wxUSE_IMAGE
169
170private:
ffecfa5a
JS
171 DECLARE_DYNAMIC_CLASS(wxBitmap)
172};
173
174// ----------------------------------------------------------------------------
175// wxMask: a mono bitmap used for drawing bitmaps transparently.
176// ----------------------------------------------------------------------------
177
53a2db12 178class WXDLLIMPEXP_CORE wxMask : public wxObject
ffecfa5a
JS
179{
180public:
181 wxMask();
182
183 // Construct a mask from a bitmap and a colour indicating the transparent
184 // area
185 wxMask(const wxBitmap& bitmap, const wxColour& colour);
186
187 // Construct a mask from a bitmap and a palette index indicating the
188 // transparent area
189 wxMask(const wxBitmap& bitmap, int paletteIndex);
190
191 // Construct a mask from a mono bitmap (copies the bitmap).
192 wxMask(const wxBitmap& bitmap);
193
194 // construct a mask from the givne bitmap handle
195 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
196
197 virtual ~wxMask();
198
199 bool Create(const wxBitmap& bitmap, const wxColour& colour);
200 bool Create(const wxBitmap& bitmap, int paletteIndex);
201 bool Create(const wxBitmap& bitmap);
202
203 // Implementation
204 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
205 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
206
207protected:
208 WXHBITMAP m_maskBitmap;
209
210 DECLARE_DYNAMIC_CLASS(wxMask)
211};
212
213// ----------------------------------------------------------------------------
214// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
215// ----------------------------------------------------------------------------
216
53a2db12 217class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler
ffecfa5a
JS
218{
219public:
220 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
221 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
222 : wxGDIImageHandler(name, ext, type)
223 {
224 }
225
226 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
227 // old class which worked only with bitmaps
228 virtual bool Create(wxBitmap *bitmap,
452418c4 229 const void* data,
ffecfa5a
JS
230 long flags,
231 int width, int height, int depth = 1);
232 virtual bool LoadFile(wxBitmap *bitmap,
233 const wxString& name,
234 long flags,
235 int desiredWidth, int desiredHeight);
236 virtual bool SaveFile(wxBitmap *bitmap,
237 const wxString& name,
238 int type,
239 const wxPalette *palette = NULL);
240
241 virtual bool Create(wxGDIImage *image,
452418c4 242 const void* data,
ffecfa5a
JS
243 long flags,
244 int width, int height, int depth = 1);
245 virtual bool Load(wxGDIImage *image,
246 const wxString& name,
247 long flags,
248 int desiredWidth, int desiredHeight);
249 virtual bool Save(wxGDIImage *image,
250 const wxString& name,
251 int type);
252
253private:
254 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
255};
256
257#endif
258 // _WX_BITMAP_H_