]> git.saurik.com Git - wxWidgets.git/blame - include/wx/motif/bitmap.h
added support for GTK2 label mnemonics (patch #689573)
[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{
83df96d6
JS
36 DECLARE_DYNAMIC_CLASS(wxMask)
37
9b6dbb09 38public:
83df96d6
JS
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
58 WXPixmap GetPixmap() const { return m_pixmap; }
59 void SetPixmap(WXPixmap pixmap) { m_pixmap = pixmap; }
60
9b6dbb09 61protected:
83df96d6 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();
83df96d6 73
9b6dbb09 74public:
83df96d6
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;
82
83 wxMask * m_bitmapMask; // Optional mask
84
85 // Motif implementation
16c1f7f3 86public:
83df96d6
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
1bc822df 103class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
9b6dbb09 104{
9b6dbb09 105public:
1bc822df
MB
106 wxBitmapHandler() : wxBitmapHandlerBase() { }
107
108 virtual bool Create(wxBitmap *bitmap, void *data, long flags,
109 int width, int height, int depth = 1)
110 {
111 return false;
112 }
113
83df96d6 114 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1bc822df
MB
115 int desiredWidth, int desiredHeight)
116 {
117 return false;
118 }
119
120 virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name,
121 int type, const wxPalette *palette = NULL)
122 {
123 return false;
124 }
125private:
126 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
9b6dbb09
JS
127};
128
129#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
130
1bc822df 131class WXDLLEXPORT wxBitmap: public wxBitmapBase
9b6dbb09 132{
83df96d6
JS
133 DECLARE_DYNAMIC_CLASS(wxBitmap)
134
135 friend class WXDLLEXPORT wxBitmapHandler;
136
9b6dbb09 137public:
83df96d6
JS
138 wxBitmap(); // Platform-specific
139
140 // Copy constructors
141 wxBitmap(const wxBitmap& bitmap)
142 { Ref(bitmap); }
143
144 // Initialize with raw XBM data
145 wxBitmap(const char bits[], int width, int height, int depth = 1);
146
147 // from XPM
148 wxBitmap(const char **data) { (void)CreateFromXpm(data); }
149 wxBitmap(char **data) { (void)CreateFromXpm((const char **)data); }
150
151 // Initialize with XPM data -- deprecated
152 wxBitmap(char **data, wxControl* control);
153
154 // Load a file or resource
1bc822df 155 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_XPM);
83df96d6
JS
156
157 // Constructor for generalised creation from data
1bc822df
MB
158 wxBitmap(void *data, wxBitmapType type,
159 int width, int height, int depth = 1);
83df96d6
JS
160
161 // If depth is omitted, will create a bitmap compatible with the display
162 wxBitmap(int width, int height, int depth = -1);
163
164 // Convert from wxImage:
165 wxBitmap(const wxImage& image, int depth = -1) { (void)CreateFromImage(image, depth); }
166
167 ~wxBitmap();
168
169 virtual bool Create(int width, int height, int depth = -1);
1bc822df
MB
170 virtual bool Create(void *data, wxBitmapType type,
171 int width, int height, int depth = 1);
83df96d6
JS
172
173 wxBitmap GetSubBitmap( const wxRect& rect ) const;
174
1bc822df
MB
175 virtual bool LoadFile(const wxString& name,
176 wxBitmapType type = wxBITMAP_TYPE_XPM);
177 virtual bool SaveFile(const wxString& name, wxBitmapType type,
178 const wxPalette *cmap = NULL) const;
83df96d6
JS
179
180 wxImage ConvertToImage() const;
329e276a
VS
181
182 // copies the contents and mask of the given (colour) icon to the bitmap
183 virtual bool CopyFromIcon(const wxIcon& icon);
83df96d6
JS
184
185 bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); }
186 int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); }
187 int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); }
188 int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); }
189 int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); }
190 void SetWidth(int w);
191 void SetHeight(int h);
192 void SetDepth(int d);
193 void SetQuality(int q);
194 void SetOk(bool isOk);
195
196 wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); }
197 void SetPalette(const wxPalette& palette);
198
199 wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); }
200 void SetMask(wxMask *mask) ;
201
202 wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
203 bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
204 bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
205
206 // Format handling
83df96d6 207 static void InitStandardHandlers();
83df96d6
JS
208
209 // Motif implementation
16c1f7f3 210public:
83df96d6
JS
211 WXDisplay* GetDisplay() const { return M_BITMAPDATA->m_display; }
212 WXPixmap GetPixmap() const { return (WXPixmap) M_BITMAPDATA->m_pixmap; }
213 virtual WXPixmap GetLabelPixmap(WXWidget w) ;
214 virtual WXPixmap GetArmPixmap(WXWidget w) ;
215 virtual WXPixmap GetInsensPixmap(WXWidget w = (WXWidget) 0) ;
216 void SetPixmapNull() { M_BITMAPDATA->m_pixmap = 0; }
217
e838cc14
VZ
218protected:
219 bool CreateFromXpm(const char **bits);
fd859211 220 bool CreateFromImage(const wxImage& image, int depth);
9b6dbb09 221};
321db4b6
JS
222
223// Creates a bitmap with transparent areas drawn in
224// the given colour.
d166a4f8 225wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour);
321db4b6 226
9b6dbb09 227#endif
83df96d6 228// _WX_BITMAP_H_