]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/bitmap.h
A fix for attribrute sorting, but it's still broken if there are
[wxWidgets.git] / include / wx / mac / bitmap.h
CommitLineData
0dbd6262
SC
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__
b698c8e9 16 #pragma interface "bitmap.h"
0dbd6262
SC
17#endif
18
0dbd6262
SC
19#include "wx/palette.h"
20
21// Bitmap
22class WXDLLEXPORT wxDC;
23class WXDLLEXPORT wxControl;
24class WXDLLEXPORT wxBitmap;
25class WXDLLEXPORT wxBitmapHandler;
26class WXDLLEXPORT wxIcon;
27class WXDLLEXPORT wxCursor;
fd859211 28class WXDLLEXPORT wxImage;
0dbd6262 29
03e11df5
GD
30GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
31void wxMacDestroyGWorld( GWorldPtr gw ) ;
519cb848 32PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
03e11df5 33void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
519cb848
SC
34CTabHandle wxMacCreateColorTable( int numColors ) ;
35
0dbd6262
SC
36// A mask is a mono bitmap used for drawing bitmaps
37// transparently.
38class WXDLLEXPORT wxMask: public wxObject
39{
40 DECLARE_DYNAMIC_CLASS(wxMask)
41
42public:
43 wxMask();
44
45 // Construct a mask from a bitmap and a colour indicating
46 // the transparent area
47 wxMask(const wxBitmap& bitmap, const wxColour& colour);
48
49 // Construct a mask from a bitmap and a palette index indicating
50 // the transparent area
51 wxMask(const wxBitmap& bitmap, int paletteIndex);
52
53 // Construct a mask from a mono bitmap (copies the bitmap).
54 wxMask(const wxBitmap& bitmap);
55
56 ~wxMask();
57
58 bool Create(const wxBitmap& bitmap, const wxColour& colour);
59 bool Create(const wxBitmap& bitmap, int paletteIndex);
60 bool Create(const wxBitmap& bitmap);
61
0dbd6262 62 // Implementation
5fde6fcc 63 bool PointMasked(int x, int y);
0dbd6262
SC
64 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
65 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
66protected:
67 WXHBITMAP m_maskBitmap;
0dbd6262
SC
68};
69
3dec57ad 70enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict , kMacBitmapTypeIcon } ;
519cb848 71
0dbd6262
SC
72class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
73{
74 friend class WXDLLEXPORT wxBitmap;
75 friend class WXDLLEXPORT wxIcon;
76 friend class WXDLLEXPORT wxCursor;
77public:
78 wxBitmapRefData();
79 ~wxBitmapRefData();
80
81public:
82 int m_width;
83 int m_height;
84 int m_depth;
85 bool m_ok;
86 int m_numColors;
87 wxPalette m_bitmapPalette;
88 int m_quality;
89
519cb848
SC
90 int m_bitmapType ;
91 PicHandle m_hPict ;
92 WXHBITMAP m_hBitmap;
3dec57ad 93 WXHICON m_hIcon ;
0dbd6262
SC
94 wxMask * m_bitmapMask; // Optional mask
95};
96
97#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
98
584bede0 99class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
0dbd6262
SC
100{
101 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
102public:
103 wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; };
f11bdd03
GD
104#ifdef __DARWIN__
105 virtual ~wxBitmapHandler() { }
03e11df5 106#endif
0dbd6262
SC
107
108 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
109 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
110 int desiredWidth, int desiredHeight);
584bede0 111 virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
0dbd6262
SC
112
113 inline void SetName(const wxString& name) { m_name = name; }
114 inline void SetExtension(const wxString& ext) { m_extension = ext; }
115 inline void SetType(long type) { m_type = type; }
116 inline wxString GetName() const { return m_name; }
117 inline wxString GetExtension() const { return m_extension; }
118 inline long GetType() const { return m_type; }
119protected:
120 wxString m_name;
121 wxString m_extension;
122 long m_type;
123};
124
125#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
126
584bede0 127class WXDLLEXPORT wxBitmap: public wxBitmapBase
0dbd6262
SC
128{
129 DECLARE_DYNAMIC_CLASS(wxBitmap)
130
131 friend class WXDLLEXPORT wxBitmapHandler;
132
133public:
134 wxBitmap(); // Platform-specific
135
136 // Copy constructors
137 inline wxBitmap(const wxBitmap& bitmap)
138 { Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); }
139
140 // Initialize with raw data.
141 wxBitmap(const char bits[], int width, int height, int depth = 1);
142
0dbd6262 143 // Initialize with XPM data
b7d667c5
GD
144 bool CreateFromXpm(const char **bits);
145 wxBitmap(const char **bits);
146 wxBitmap(char **bits);
0dbd6262
SC
147
148 // Load a file or resource
584bede0 149 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE);
0dbd6262
SC
150
151 // Constructor for generalised creation from data
584bede0 152 wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
0dbd6262
SC
153
154 // If depth is omitted, will create a bitmap compatible with the display
155 wxBitmap(int width, int height, int depth = -1);
fd859211
VS
156
157 // Convert from wxImage:
158 wxBitmap(const wxImage& image, int depth = -1);
159
0dbd6262 160 ~wxBitmap();
fd859211
VS
161
162 wxImage ConvertToImage() const;
0dbd6262 163
5fde6fcc
GD
164 // get the given part of bitmap
165 wxBitmap GetSubBitmap( const wxRect& rect ) const;
166
0dbd6262 167 virtual bool Create(int width, int height, int depth = -1);
584bede0
GD
168 virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1);
169 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
170 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
171
172 // copies the contents and mask of the given (colour) icon to the bitmap
173 virtual bool CopyFromIcon(const wxIcon& icon);
0dbd6262 174
5fde6fcc
GD
175 bool Ok() const;
176 int GetWidth() const;
177 int GetHeight() const;
178 int GetDepth() const;
179 int GetQuality() const;
0dbd6262
SC
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
5fde6fcc 186 wxPalette* GetPalette() const;
0dbd6262
SC
187 void SetPalette(const wxPalette& palette);
188
5fde6fcc 189 wxMask *GetMask() const;
0dbd6262
SC
190 void SetMask(wxMask *mask) ;
191
5fde6fcc
GD
192 int GetBitmapType() const;
193
0dbd6262
SC
194 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
195 inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
196 inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
197
198 // Format handling
199 static inline wxList& GetHandlers() { return sm_handlers; }
200 static void AddHandler(wxBitmapHandler *handler);
201 static void InsertHandler(wxBitmapHandler *handler);
202 static bool RemoveHandler(const wxString& name);
203 static wxBitmapHandler *FindHandler(const wxString& name);
584bede0
GD
204 static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType type);
205 static wxBitmapHandler *FindHandler(wxBitmapType type);
0dbd6262
SC
206
207 static void InitStandardHandlers();
208 static void CleanUpHandlers();
209protected:
0dbd6262 210
0dbd6262
SC
211 // TODO: Implementation
212public:
213 void SetHBITMAP(WXHBITMAP bmp);
5fde6fcc 214 WXHBITMAP GetHBITMAP() const;
3dec57ad
SC
215 void SetHICON(WXHICON ico);
216 inline WXHICON GetHICON() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hIcon : 0); }
03e11df5 217
5fde6fcc
GD
218 PicHandle GetPict() const;
219
0dbd6262 220 bool FreeResource(bool force = FALSE);
0dbd6262
SC
221};
222#endif
223 // _WX_BITMAP_H_