]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/bitmap.h
Added patch that adds style flags for wxEditableListBox to not use
[wxWidgets.git] / include / wx / mac / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.h
3 // Purpose: wxBitmap class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
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/palette.h"
20
21 // Bitmap
22 class WXDLLEXPORT wxDC;
23 class WXDLLEXPORT wxControl;
24 class WXDLLEXPORT wxBitmap;
25 class WXDLLEXPORT wxBitmapHandler;
26 class WXDLLEXPORT wxIcon;
27 class WXDLLEXPORT wxCursor;
28 class WXDLLEXPORT wxImage;
29
30 // A mask is a mono bitmap used for drawing bitmaps
31 // transparently.
32 class WXDLLEXPORT wxMask: public wxObject
33 {
34 DECLARE_DYNAMIC_CLASS(wxMask)
35
36 public:
37 wxMask();
38
39 // Construct a mask from a bitmap and a colour indicating
40 // the transparent area
41 wxMask(const wxBitmap& bitmap, const wxColour& colour);
42
43 // Construct a mask from a bitmap and a palette index indicating
44 // the transparent area
45 wxMask(const wxBitmap& bitmap, int paletteIndex);
46
47 // Construct a mask from a mono bitmap (copies the bitmap).
48 wxMask(const wxBitmap& bitmap);
49
50 ~wxMask();
51
52 bool Create(const wxBitmap& bitmap, const wxColour& colour);
53 bool Create(const wxBitmap& bitmap, int paletteIndex);
54 bool Create(const wxBitmap& bitmap);
55
56 // Implementation
57 bool PointMasked(int x, int y);
58 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
59 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
60 protected:
61 WXHBITMAP m_maskBitmap;
62 };
63
64 enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict , kMacBitmapTypeIcon } ;
65
66 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
67 {
68 friend class WXDLLEXPORT wxBitmap;
69 friend class WXDLLEXPORT wxIcon;
70 friend class WXDLLEXPORT wxCursor;
71 public:
72 wxBitmapRefData();
73 ~wxBitmapRefData();
74
75 public:
76 int m_width;
77 int m_height;
78 int m_depth;
79 bool m_ok;
80 int m_numColors;
81 wxPalette m_bitmapPalette;
82 int m_quality;
83
84 int m_bitmapType ;
85 WXHMETAFILE m_hPict ;
86 WXHBITMAP m_hBitmap;
87 WXHICON m_hIcon ;
88 wxMask * m_bitmapMask; // Optional mask
89 };
90
91 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
92
93 class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
94 {
95 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
96 public:
97 wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; };
98 #ifdef __DARWIN__
99 virtual ~wxBitmapHandler() { }
100 #endif
101
102 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
103 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
104 int desiredWidth, int desiredHeight);
105 virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
106
107 inline void SetName(const wxString& name) { m_name = name; }
108 inline void SetExtension(const wxString& ext) { m_extension = ext; }
109 inline void SetType(long type) { m_type = type; }
110 inline wxString GetName() const { return m_name; }
111 inline wxString GetExtension() const { return m_extension; }
112 inline long GetType() const { return m_type; }
113 protected:
114 wxString m_name;
115 wxString m_extension;
116 long m_type;
117 };
118
119 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
120
121 class WXDLLEXPORT wxBitmap: public wxBitmapBase
122 {
123 DECLARE_DYNAMIC_CLASS(wxBitmap)
124
125 friend class WXDLLEXPORT wxBitmapHandler;
126
127 public:
128 wxBitmap(); // Platform-specific
129
130 // Copy constructors
131 inline wxBitmap(const wxBitmap& bitmap)
132 { Ref(bitmap); }
133
134 // Initialize with raw data.
135 wxBitmap(const char bits[], int width, int height, int depth = 1);
136
137 // Initialize with XPM data
138 bool CreateFromXpm(const char **bits);
139 wxBitmap(const char **bits);
140 wxBitmap(char **bits);
141
142 // Load a file or resource
143 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE);
144
145 // Constructor for generalised creation from data
146 wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
147
148 // If depth is omitted, will create a bitmap compatible with the display
149 wxBitmap(int width, int height, int depth = -1);
150
151 // Convert from wxImage:
152 wxBitmap(const wxImage& image, int depth = -1);
153
154 ~wxBitmap();
155
156 wxImage ConvertToImage() const;
157
158 // get the given part of bitmap
159 wxBitmap GetSubBitmap( const wxRect& rect ) const;
160
161 virtual bool Create(int width, int height, int depth = -1);
162 virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1);
163 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
164 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
165
166 // copies the contents and mask of the given (colour) icon to the bitmap
167 virtual bool CopyFromIcon(const wxIcon& icon);
168
169 bool Ok() const;
170 int GetWidth() const;
171 int GetHeight() const;
172 int GetDepth() const;
173 int GetQuality() const;
174 void SetWidth(int w);
175 void SetHeight(int h);
176 void SetDepth(int d);
177 void SetQuality(int q);
178 void SetOk(bool isOk);
179
180 wxPalette* GetPalette() const;
181 void SetPalette(const wxPalette& palette);
182
183 wxMask *GetMask() const;
184 void SetMask(wxMask *mask) ;
185
186 int GetBitmapType() const;
187
188 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
189 inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
190 inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
191
192 static void InitStandardHandlers();
193 protected:
194
195 // TODO: Implementation
196 public:
197 void SetHBITMAP(WXHBITMAP bmp);
198 WXHBITMAP GetHBITMAP() const;
199 void SetHICON(WXHICON ico);
200 inline WXHICON GetHICON() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hIcon : 0); }
201
202 WXHMETAFILE GetPict() const;
203
204 bool FreeResource(bool force = FALSE);
205 };
206 #endif
207 // _WX_BITMAP_H_