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