]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/bitmap.h
don't try to refresh the menu bar before showing it, fixes crash on startup with...
[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 GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
31 void wxMacDestroyGWorld( GWorldPtr gw ) ;
32 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
33 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
34 CTabHandle wxMacCreateColorTable( int numColors ) ;
35
36 // A mask is a mono bitmap used for drawing bitmaps
37 // transparently.
38 class WXDLLEXPORT wxMask: public wxObject
39 {
40 DECLARE_DYNAMIC_CLASS(wxMask)
41
42 public:
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
62 // Implementation
63 bool PointMasked(int x, int y);
64 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
65 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
66 protected:
67 WXHBITMAP m_maskBitmap;
68 };
69
70 enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict , kMacBitmapTypeIcon } ;
71
72 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
73 {
74 friend class WXDLLEXPORT wxBitmap;
75 friend class WXDLLEXPORT wxIcon;
76 friend class WXDLLEXPORT wxCursor;
77 public:
78 wxBitmapRefData();
79 ~wxBitmapRefData();
80
81 public:
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
90 int m_bitmapType ;
91 PicHandle m_hPict ;
92 WXHBITMAP m_hBitmap;
93 WXHICON m_hIcon ;
94 wxMask * m_bitmapMask; // Optional mask
95 };
96
97 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
98
99 class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
100 {
101 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
102 public:
103 wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; };
104 #ifdef __DARWIN__
105 virtual ~wxBitmapHandler() { }
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(const 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 wxBitmapBase
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 bool CreateFromXpm(const char **bits);
145 wxBitmap(const char **bits);
146 wxBitmap(char **bits);
147
148 // Load a file or resource
149 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE);
150
151 // Constructor for generalised creation from data
152 wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
153
154 // If depth is omitted, will create a bitmap compatible with the display
155 wxBitmap(int width, int height, int depth = -1);
156
157 // Convert from wxImage:
158 wxBitmap(const wxImage& image, int depth = -1);
159
160 ~wxBitmap();
161
162 wxImage ConvertToImage() const;
163
164 // get the given part of bitmap
165 wxBitmap GetSubBitmap( const wxRect& rect ) const;
166
167 virtual bool Create(int width, int height, int depth = -1);
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);
174
175 bool Ok() const;
176 int GetWidth() const;
177 int GetHeight() const;
178 int GetDepth() const;
179 int GetQuality() const;
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
186 wxPalette* GetPalette() const;
187 void SetPalette(const wxPalette& palette);
188
189 wxMask *GetMask() const;
190 void SetMask(wxMask *mask) ;
191
192 int GetBitmapType() const;
193
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);
204 static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType type);
205 static wxBitmapHandler *FindHandler(wxBitmapType type);
206
207 static void InitStandardHandlers();
208 static void CleanUpHandlers();
209 protected:
210
211 // TODO: Implementation
212 public:
213 void SetHBITMAP(WXHBITMAP bmp);
214 WXHBITMAP GetHBITMAP() const;
215 void SetHICON(WXHICON ico);
216 inline WXHICON GetHICON() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hIcon : 0); }
217
218 PicHandle GetPict() const;
219
220 bool FreeResource(bool force = FALSE);
221 };
222 #endif
223 // _WX_BITMAP_H_