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