]> git.saurik.com Git - wxWidgets.git/blame - include/wx/motif/bitmap.h
MicroWindows tweaks
[wxWidgets.git] / include / wx / motif / bitmap.h
CommitLineData
9b6dbb09
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: bitmap.h
3// Purpose: wxBitmap class
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_BITMAP_H_
13#define _WX_BITMAP_H_
14
15#ifdef __GNUG__
16#pragma interface "bitmap.h"
17#endif
18
19#include "wx/gdiobj.h"
20#include "wx/gdicmn.h"
21#include "wx/palette.h"
22
23// Bitmap
24class WXDLLEXPORT wxDC;
25class WXDLLEXPORT wxControl;
26class WXDLLEXPORT wxBitmap;
27class WXDLLEXPORT wxBitmapHandler;
28class WXDLLEXPORT wxIcon;
29class WXDLLEXPORT wxCursor;
fd859211 30class WXDLLEXPORT wxImage;
9b6dbb09
JS
31
32// A mask is a mono bitmap used for drawing bitmaps
33// transparently.
34class WXDLLEXPORT wxMask: public wxObject
35{
36 DECLARE_DYNAMIC_CLASS(wxMask)
37
38public:
39 wxMask();
40
41 // Construct a mask from a bitmap and a colour indicating
42 // the transparent area
43 wxMask(const wxBitmap& bitmap, const wxColour& colour);
44
45 // Construct a mask from a bitmap and a palette index indicating
46 // the transparent area
47 wxMask(const wxBitmap& bitmap, int paletteIndex);
48
49 // Construct a mask from a mono bitmap (copies the bitmap).
50 wxMask(const wxBitmap& bitmap);
51
52 ~wxMask();
53
54 bool Create(const wxBitmap& bitmap, const wxColour& colour);
55 bool Create(const wxBitmap& bitmap, int paletteIndex);
56 bool Create(const wxBitmap& bitmap);
57
72cdf4c9
VZ
58 WXPixmap GetPixmap() const { return m_pixmap; }
59 void SetPixmap(WXPixmap pixmap) { m_pixmap = pixmap; }
16c1f7f3 60
9b6dbb09 61protected:
16c1f7f3 62 WXPixmap m_pixmap;
9b6dbb09
JS
63};
64
65class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
66{
67 friend class WXDLLEXPORT wxBitmap;
68 friend class WXDLLEXPORT wxIcon;
69 friend class WXDLLEXPORT wxCursor;
70public:
71 wxBitmapRefData();
72 ~wxBitmapRefData();
73
74public:
f97c9854
JS
75 int m_width;
76 int m_height;
77 int m_depth;
78 bool m_ok;
79 int m_numColors;
80 wxPalette m_bitmapPalette;
81 int m_quality;
9b6dbb09 82
f97c9854 83 wxMask * m_bitmapMask; // Optional mask
16c1f7f3
JS
84
85 // Motif implementation
86public:
f97c9854
JS
87 WXPixmap m_pixmap;
88 WXDisplay* m_display;
89 bool m_freePixmap;
90 unsigned long* m_freeColors;
91 long m_freeColorsCount;
92
93 // These 5 variables are for wxControl
94 WXPixmap m_insensPixmap ;
95 WXPixmap m_labelPixmap ;
96 WXPixmap m_armPixmap ;
97 WXImage* m_image ;
98 WXImage* m_insensImage ;
9b6dbb09
JS
99};
100
101#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
102
103class WXDLLEXPORT wxBitmapHandler: public wxObject
104{
105 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
106public:
107 wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; };
108
109 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
110 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
111 int desiredWidth, int desiredHeight);
112 virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
113
72cdf4c9
VZ
114 void SetName(const wxString& name) { m_name = name; }
115 void SetExtension(const wxString& ext) { m_extension = ext; }
116 void SetType(long type) { m_type = type; }
117 wxString GetName() const { return m_name; }
118 wxString GetExtension() const { return m_extension; }
119 long GetType() const { return m_type; }
9b6dbb09
JS
120protected:
121 wxString m_name;
122 wxString m_extension;
123 long m_type;
124};
125
126#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
127
128class WXDLLEXPORT wxBitmap: public wxGDIObject
129{
130 DECLARE_DYNAMIC_CLASS(wxBitmap)
131
132 friend class WXDLLEXPORT wxBitmapHandler;
133
134public:
135 wxBitmap(); // Platform-specific
136
137 // Copy constructors
72cdf4c9 138 wxBitmap(const wxBitmap& bitmap)
244d3b67 139 { Ref(bitmap); }
9b6dbb09 140
f97c9854 141 // Initialize with raw XBM data
9b6dbb09
JS
142 wxBitmap(const char bits[], int width, int height, int depth = 1);
143
e838cc14
VZ
144 // from XPM
145 wxBitmap(const char **data) { (void)CreateFromXpm(data); }
146 wxBitmap(char **data) { (void)CreateFromXpm((const char **)data); }
147
148 // Initialize with XPM data -- deprecated
149 wxBitmap(char **data, wxControl* control);
9b6dbb09
JS
150
151 // Load a file or resource
cba2db0c 152 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_XPM);
9b6dbb09
JS
153
154 // Constructor for generalised creation from data
155 wxBitmap(void *data, long type, int width, int height, int depth = 1);
156
157 // If depth is omitted, will create a bitmap compatible with the display
158 wxBitmap(int width, int height, int depth = -1);
fd859211
VS
159
160 // Convert from wxImage:
161 wxBitmap(const wxImage& image, int depth = -1) { (void)CreateFromImage(image, depth); }
162
9b6dbb09
JS
163 ~wxBitmap();
164
165 virtual bool Create(int width, int height, int depth = -1);
166 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
1696c178
JJ
167
168 wxBitmap GetSubBitmap( const wxRect& rect ) const;
169
cba2db0c 170 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_XPM);
9b6dbb09 171 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
fd859211
VS
172
173 wxImage ConvertToImage() const;
9b6dbb09 174
72cdf4c9
VZ
175 bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); }
176 int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); }
177 int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); }
178 int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); }
179 int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); }
9b6dbb09
JS
180 void SetWidth(int w);
181 void SetHeight(int h);
182 void SetDepth(int d);
183 void SetQuality(int q);
184 void SetOk(bool isOk);
185
72cdf4c9 186 wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); }
9b6dbb09
JS
187 void SetPalette(const wxPalette& palette);
188
72cdf4c9 189 wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); }
9b6dbb09
JS
190 void SetMask(wxMask *mask) ;
191
72cdf4c9 192 wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
f6bcfd97
BP
193 bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
194 bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
9b6dbb09
JS
195
196 // Format handling
72cdf4c9 197 static wxList& GetHandlers() { return sm_handlers; }
9b6dbb09
JS
198 static void AddHandler(wxBitmapHandler *handler);
199 static void InsertHandler(wxBitmapHandler *handler);
200 static bool RemoveHandler(const wxString& name);
201 static wxBitmapHandler *FindHandler(const wxString& name);
202 static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType);
203 static wxBitmapHandler *FindHandler(long bitmapType);
204
205 static void InitStandardHandlers();
206 static void CleanUpHandlers();
16c1f7f3
JS
207
208 // Motif implementation
209public:
72cdf4c9 210 WXDisplay* GetDisplay() const { return M_BITMAPDATA->m_display; }
68be9f09 211 WXPixmap GetPixmap() const { return (WXPixmap) M_BITMAPDATA->m_pixmap; }
f97c9854
JS
212 virtual WXPixmap GetLabelPixmap(WXWidget w) ;
213 virtual WXPixmap GetArmPixmap(WXWidget w) ;
0d57be45 214 virtual WXPixmap GetInsensPixmap(WXWidget w = (WXWidget) 0) ;
68be9f09 215 void SetPixmapNull() { M_BITMAPDATA->m_pixmap = 0; }
16c1f7f3 216
9b6dbb09
JS
217protected:
218 static wxList sm_handlers;
e838cc14
VZ
219
220protected:
221 bool CreateFromXpm(const char **bits);
fd859211 222 bool CreateFromImage(const wxImage& image, int depth);
9b6dbb09 223};
321db4b6
JS
224
225// Creates a bitmap with transparent areas drawn in
226// the given colour.
d166a4f8 227wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour);
321db4b6 228
9b6dbb09
JS
229#endif
230 // _WX_BITMAP_H_