]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
Added wxStrnicmp and to wchar.h, not yet for Unicode mode.
[wxWidgets.git] / include / wx / os2 / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BITMAP_H_
13 #define _WX_BITMAP_H_
14
15 #include "wx/gdiobj.h"
16 #include "wx/gdicmn.h"
17 #include "wx/palette.h"
18
19 // Bitmap
20 class WXDLLEXPORT wxDC;
21 class WXDLLEXPORT wxControl;
22 class WXDLLEXPORT wxBitmap;
23 class WXDLLEXPORT wxBitmapHandler;
24 class WXDLLEXPORT wxIcon;
25 class WXDLLEXPORT wxCursor;
26 class WXDLLEXPORT wxControl;
27
28 // A mask is a mono bitmap used for drawing bitmaps
29 // transparently.
30 class WXDLLEXPORT wxMask: public wxObject
31 {
32 DECLARE_DYNAMIC_CLASS(wxMask)
33
34 public:
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
54 // Implementation
55 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
56 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
57 protected:
58 WXHBITMAP m_maskBitmap;
59 };
60
61 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
62 {
63 friend class WXDLLEXPORT wxBitmap;
64 friend class WXDLLEXPORT wxIcon;
65 friend class WXDLLEXPORT wxCursor;
66 public:
67 wxBitmapRefData();
68 ~wxBitmapRefData();
69
70 public:
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
79 WXHBITMAP m_hBitmap;
80 wxDC * m_selectedInto; // So bitmap knows whether it's been selected into
81
82 wxMask * m_bitmapMask; // Optional mask
83 };
84
85 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
86
87 class WXDLLEXPORT wxBitmapHandler: public wxObject
88 {
89 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
90 public:
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; }
104 protected:
105 wxString m_name;
106 wxString m_extension;
107 long m_type;
108 };
109
110 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
111
112 class WXDLLEXPORT wxBitmap: public wxGDIObject
113 {
114 DECLARE_DYNAMIC_CLASS(wxBitmap)
115
116 friend class WXDLLEXPORT wxBitmapHandler;
117
118 public:
119 wxBitmap(); // Platform-specific
120
121 // Copy constructors
122 wxBitmap(const wxBitmap& bitmap);
123
124 // Initialize with raw data
125 wxBitmap(const char bits[], int width, int height, int depth = 1);
126
127 // Initialize with XPM data
128 wxBitmap(char **data, wxControl *anItem = NULL);
129
130 // Load a file or resource
131 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
132
133 // New constructor for generalised creation from data
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
156 #if WXWIN_COMPATIBILITY
157 inline wxPalette *GetColourMap(void) const { return GetPalette(); }
158 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
159 #endif
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; }
167
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();
182 protected:
183 static wxList sm_handlers;
184
185 // Implementation
186 public:
187 void SetHBITMAP(WXHBITMAP bmp);
188 inline WXHBITMAP GetHBITMAP() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); }
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); }
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;
205 };
206 #endif
207 // _WX_BITMAP_H_