]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/bitmap.h
Doesn't reset the stream pos to 0 in CanRead().
[wxWidgets.git] / include / wx / os2 / bitmap.h
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: bitmap.h
3// Purpose: wxBitmap class
d88de032 4// Author: David Webster
0e320a79 5// Modified by:
d88de032 6// Created: 10/13/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
0e320a79
DW
15#include "wx/gdiobj.h"
16#include "wx/gdicmn.h"
17#include "wx/palette.h"
18
19// Bitmap
20class WXDLLEXPORT wxDC;
21class WXDLLEXPORT wxControl;
22class WXDLLEXPORT wxBitmap;
23class WXDLLEXPORT wxBitmapHandler;
24class WXDLLEXPORT wxIcon;
25class WXDLLEXPORT wxCursor;
d88de032 26class WXDLLEXPORT wxControl;
0e320a79
DW
27
28// A mask is a mono bitmap used for drawing bitmaps
29// transparently.
30class WXDLLEXPORT wxMask: public wxObject
31{
32 DECLARE_DYNAMIC_CLASS(wxMask)
33
34public:
35 wxMask();
36
37 // Construct a mask from a bitmap and a colour indicating
38 // the transparent area
39 wxMask(const wxBitmap& bitmap, const wxColour& colour);
40
41 // Construct a mask from a bitmap and a palette index indicating
42 // the transparent area
43 wxMask(const wxBitmap& bitmap, int paletteIndex);
44
45 // Construct a mask from a mono bitmap (copies the bitmap).
46 wxMask(const wxBitmap& bitmap);
47
48 ~wxMask();
49
50 bool Create(const wxBitmap& bitmap, const wxColour& colour);
51 bool Create(const wxBitmap& bitmap, int paletteIndex);
52 bool Create(const wxBitmap& bitmap);
53
0e320a79
DW
54 // Implementation
55 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
56 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
57protected:
58 WXHBITMAP m_maskBitmap;
0e320a79
DW
59};
60
61class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
62{
63 friend class WXDLLEXPORT wxBitmap;
64 friend class WXDLLEXPORT wxIcon;
65 friend class WXDLLEXPORT wxCursor;
66public:
67 wxBitmapRefData();
68 ~wxBitmapRefData();
69
70public:
71 int m_width;
72 int m_height;
73 int m_depth;
74 bool m_ok;
75 int m_numColors;
76 wxPalette m_bitmapPalette;
77 int m_quality;
78
ce44c50e
DW
79 WXHBITMAP m_hBitmap;
80 wxDC * m_selectedInto; // So bitmap knows whether it's been selected into
81
0e320a79
DW
82 wxMask * m_bitmapMask; // Optional mask
83};
84
85#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
86
87class WXDLLEXPORT wxBitmapHandler: public wxObject
88{
89 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
90public:
91 wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; };
92
93 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
94 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
95 int desiredWidth, int desiredHeight);
96 virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
97
98 inline void SetName(const wxString& name) { m_name = name; }
99 inline void SetExtension(const wxString& ext) { m_extension = ext; }
100 inline void SetType(long type) { m_type = type; }
101 inline wxString GetName() const { return m_name; }
102 inline wxString GetExtension() const { return m_extension; }
103 inline long GetType() const { return m_type; }
104protected:
105 wxString m_name;
106 wxString m_extension;
107 long m_type;
108};
109
110#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
111
112class WXDLLEXPORT wxBitmap: public wxGDIObject
113{
114 DECLARE_DYNAMIC_CLASS(wxBitmap)
115
116 friend class WXDLLEXPORT wxBitmapHandler;
117
118public:
119 wxBitmap(); // Platform-specific
120
121 // Copy constructors
d88de032 122 wxBitmap(const wxBitmap& bitmap);
0e320a79 123
d88de032 124 // Initialize with raw data
0e320a79
DW
125 wxBitmap(const char bits[], int width, int height, int depth = 1);
126
0e320a79 127 // Initialize with XPM data
d88de032 128 wxBitmap(char **data, wxControl *anItem = NULL);
0e320a79
DW
129
130 // Load a file or resource
0e320a79
DW
131 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
132
d88de032 133 // New constructor for generalised creation from data
0e320a79
DW
134 wxBitmap(void *data, long type, int width, int height, int depth = 1);
135
136 // If depth is omitted, will create a bitmap compatible with the display
137 wxBitmap(int width, int height, int depth = -1);
138 ~wxBitmap();
139
140 virtual bool Create(int width, int height, int depth = -1);
141 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
142 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
143 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
144
145 inline bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); }
146 inline int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); }
147 inline int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); }
148 inline int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); }
149 inline int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); }
150 void SetWidth(int w);
151 void SetHeight(int h);
152 void SetDepth(int d);
153 void SetQuality(int q);
154 void SetOk(bool isOk);
155
d88de032
DW
156#if WXWIN_COMPATIBILITY
157 inline wxPalette *GetColourMap(void) const { return GetPalette(); }
158 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
159#endif
0e320a79
DW
160 inline wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); }
161 void SetPalette(const wxPalette& palette);
162
163 inline wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); }
164 void SetMask(wxMask *mask) ;
165
166 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
d88de032 167
0e320a79
DW
168 inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
169 inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
170
171 // Format handling
172 static inline wxList& GetHandlers() { return sm_handlers; }
173 static void AddHandler(wxBitmapHandler *handler);
174 static void InsertHandler(wxBitmapHandler *handler);
175 static bool RemoveHandler(const wxString& name);
176 static wxBitmapHandler *FindHandler(const wxString& name);
177 static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType);
178 static wxBitmapHandler *FindHandler(long bitmapType);
179
180 static void InitStandardHandlers();
181 static void CleanUpHandlers();
182protected:
183 static wxList sm_handlers;
184
d88de032 185 // Implementation
0e320a79
DW
186public:
187 void SetHBITMAP(WXHBITMAP bmp);
188 inline WXHBITMAP GetHBITMAP() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); }
ce44c50e
DW
189 inline void SetSelectedInto(wxDC *dc) { if (M_BITMAPDATA) M_BITMAPDATA->m_selectedInto = dc; }
190 inline wxDC *GetSelectedInto(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_selectedInto : (wxDC*) NULL); }
d88de032
DW
191 bool FreeResource(bool force = FALSE);
192
193 // Creates a bitmap that matches the device context's depth, from
194 // an arbitray bitmap. At present, the original bitmap must have an
195 // associated palette. (TODO: use a default palette if no palette exists.)
196 // This function is necessary for you to Blit an arbitrary bitmap (which may have
197 // the wrong depth). wxDC::SelectObject will compare the depth of the bitmap
198 // with the DC's depth, and create a new bitmap if the depths differ.
199 // Eventually we should perhaps make this a public API function so that
200 // an app can efficiently produce bitmaps of the correct depth.
201 // The Windows solution is to use SetDibBits to blit an arbotrary DIB directly to a DC, but
202 // this is too Windows-specific, hence this solution of quietly converting the wxBitmap.
203 // Contributed by Frederic Villeneuve <frederic.villeneuve@natinst.com>
204 wxBitmap GetBitmapForDC(wxDC& dc) const;
0e320a79
DW
205};
206#endif
207 // _WX_BITMAP_H_