]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/bitmap.h
corrections for final release of Mac OS X
[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/gdiobj.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
22
23 // Bitmap
24 class WXDLLEXPORT wxDC;
25 class WXDLLEXPORT wxControl;
26 class WXDLLEXPORT wxBitmap;
27 class WXDLLEXPORT wxBitmapHandler;
28 class WXDLLEXPORT wxIcon;
29 class WXDLLEXPORT wxCursor;
30
31 GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
32 void wxMacDestroyGWorld( GWorldPtr gw ) ;
33 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
34 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
35 CTabHandle wxMacCreateColorTable( int numColors ) ;
36
37 // A mask is a mono bitmap used for drawing bitmaps
38 // transparently.
39 class WXDLLEXPORT wxMask: public wxObject
40 {
41 DECLARE_DYNAMIC_CLASS(wxMask)
42
43 public:
44 wxMask();
45
46 // Construct a mask from a bitmap and a colour indicating
47 // the transparent area
48 wxMask(const wxBitmap& bitmap, const wxColour& colour);
49
50 // Construct a mask from a bitmap and a palette index indicating
51 // the transparent area
52 wxMask(const wxBitmap& bitmap, int paletteIndex);
53
54 // Construct a mask from a mono bitmap (copies the bitmap).
55 wxMask(const wxBitmap& bitmap);
56
57 ~wxMask();
58
59 bool Create(const wxBitmap& bitmap, const wxColour& colour);
60 bool Create(const wxBitmap& bitmap, int paletteIndex);
61 bool Create(const wxBitmap& bitmap);
62
63 // Implementation
64 bool PointMasked(int x, int y);
65 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
66 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
67 protected:
68 WXHBITMAP m_maskBitmap;
69 };
70
71 enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict } ;
72
73 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
74 {
75 friend class WXDLLEXPORT wxBitmap;
76 friend class WXDLLEXPORT wxIcon;
77 friend class WXDLLEXPORT wxCursor;
78 public:
79 wxBitmapRefData();
80 ~wxBitmapRefData();
81
82 public:
83 int m_width;
84 int m_height;
85 int m_depth;
86 bool m_ok;
87 int m_numColors;
88 wxPalette m_bitmapPalette;
89 int m_quality;
90
91 int m_bitmapType ;
92 PicHandle m_hPict ;
93 WXHBITMAP m_hBitmap;
94 wxMask * m_bitmapMask; // Optional mask
95 };
96
97 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
98
99 class WXDLLEXPORT wxBitmapHandler: public wxObject
100 {
101 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
102 public:
103 wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; };
104 #ifdef __WXMAC_X__
105 virtual ~wxBitmapHandler() {} // Added min for Mac X
106 #endif
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);
111 virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
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; }
119 protected:
120 wxString m_name;
121 wxString m_extension;
122 long m_type;
123 };
124
125 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
126
127 class WXDLLEXPORT wxBitmap: public wxGDIObject
128 {
129 DECLARE_DYNAMIC_CLASS(wxBitmap)
130
131 friend class WXDLLEXPORT wxBitmapHandler;
132
133 public:
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
143 // Initialize with XPM data
144 wxBitmap(const char **data);
145 wxBitmap(char **data);
146
147 // Load a file or resource
148 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_PICT_RESOURCE);
149
150 // Constructor for generalised creation from data
151 wxBitmap(void *data, long type, int width, int height, int depth = 1);
152
153 // If depth is omitted, will create a bitmap compatible with the display
154 wxBitmap(int width, int height, int depth = -1);
155 ~wxBitmap();
156
157 // get the given part of bitmap
158 wxBitmap GetSubBitmap( const wxRect& rect ) const;
159
160 virtual bool Create(int width, int height, int depth = -1);
161 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
162 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
163 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
164
165 bool Ok() const;
166 int GetWidth() const;
167 int GetHeight() const;
168 int GetDepth() const;
169 int GetQuality() const;
170 void SetWidth(int w);
171 void SetHeight(int h);
172 void SetDepth(int d);
173 void SetQuality(int q);
174 void SetOk(bool isOk);
175
176 wxPalette* GetPalette() const;
177 void SetPalette(const wxPalette& palette);
178
179 wxMask *GetMask() const;
180 void SetMask(wxMask *mask) ;
181
182 int GetBitmapType() const;
183
184 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
185 inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
186 inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
187
188 // Format handling
189 static inline wxList& GetHandlers() { return sm_handlers; }
190 static void AddHandler(wxBitmapHandler *handler);
191 static void InsertHandler(wxBitmapHandler *handler);
192 static bool RemoveHandler(const wxString& name);
193 static wxBitmapHandler *FindHandler(const wxString& name);
194 static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType);
195 static wxBitmapHandler *FindHandler(long bitmapType);
196
197 static void InitStandardHandlers();
198 static void CleanUpHandlers();
199 protected:
200 static wxList sm_handlers;
201
202 // TODO: Implementation
203 public:
204 void SetHBITMAP(WXHBITMAP bmp);
205 WXHBITMAP GetHBITMAP() const;
206
207 PicHandle GetPict() const;
208
209 bool FreeResource(bool force = FALSE);
210 };
211 #endif
212 // _WX_BITMAP_H_