]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/bitmap.h
Added long-filename functions & normalisation; patch to Watcom makefiles
[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;
30
03e11df5
GD
31GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
32void wxMacDestroyGWorld( GWorldPtr gw ) ;
519cb848 33PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
03e11df5 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
SC
63 // Implementation
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
519cb848
SC
70enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict } ;
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;
0dbd6262
SC
93 wxMask * m_bitmapMask; // Optional mask
94};
95
96#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
97
98class WXDLLEXPORT wxBitmapHandler: public wxObject
99{
100 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
101public:
102 wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; };
03e11df5
GD
103#ifdef __WXMAC_X__
104 virtual ~wxBitmapHandler() {} // Added min for Mac X
105#endif
0dbd6262
SC
106
107 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
108 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
109 int desiredWidth, int desiredHeight);
110 virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
111
112 inline void SetName(const wxString& name) { m_name = name; }
113 inline void SetExtension(const wxString& ext) { m_extension = ext; }
114 inline void SetType(long type) { m_type = type; }
115 inline wxString GetName() const { return m_name; }
116 inline wxString GetExtension() const { return m_extension; }
117 inline long GetType() const { return m_type; }
118protected:
119 wxString m_name;
120 wxString m_extension;
121 long m_type;
122};
123
124#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
125
126class WXDLLEXPORT wxBitmap: public wxGDIObject
127{
128 DECLARE_DYNAMIC_CLASS(wxBitmap)
129
130 friend class WXDLLEXPORT wxBitmapHandler;
131
132public:
133 wxBitmap(); // Platform-specific
134
135 // Copy constructors
136 inline wxBitmap(const wxBitmap& bitmap)
137 { Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); }
138
139 // Initialize with raw data.
140 wxBitmap(const char bits[], int width, int height, int depth = 1);
141
0dbd6262
SC
142 // Initialize with XPM data
143 wxBitmap(const char **data);
03e11df5 144 wxBitmap(char **data);
0dbd6262
SC
145
146 // Load a file or resource
519cb848 147 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_PICT_RESOURCE);
0dbd6262
SC
148
149 // Constructor for generalised creation from data
150 wxBitmap(void *data, long type, int width, int height, int depth = 1);
151
152 // If depth is omitted, will create a bitmap compatible with the display
153 wxBitmap(int width, int height, int depth = -1);
154 ~wxBitmap();
155
156 virtual bool Create(int width, int height, int depth = -1);
157 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
158 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
159 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
160
161 inline bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); }
162 inline int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); }
163 inline int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); }
164 inline int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); }
165 inline int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); }
166 void SetWidth(int w);
167 void SetHeight(int h);
168 void SetDepth(int d);
169 void SetQuality(int q);
170 void SetOk(bool isOk);
171
172 inline wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); }
173 void SetPalette(const wxPalette& palette);
174
175 inline wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); }
176 void SetMask(wxMask *mask) ;
177
178 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
179 inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
180 inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
181
182 // Format handling
183 static inline wxList& GetHandlers() { return sm_handlers; }
184 static void AddHandler(wxBitmapHandler *handler);
185 static void InsertHandler(wxBitmapHandler *handler);
186 static bool RemoveHandler(const wxString& name);
187 static wxBitmapHandler *FindHandler(const wxString& name);
188 static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType);
189 static wxBitmapHandler *FindHandler(long bitmapType);
190
191 static void InitStandardHandlers();
192 static void CleanUpHandlers();
193protected:
194 static wxList sm_handlers;
195
0dbd6262
SC
196 // TODO: Implementation
197public:
198 void SetHBITMAP(WXHBITMAP bmp);
199 inline WXHBITMAP GetHBITMAP() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); }
03e11df5 200
0dbd6262 201 bool FreeResource(bool force = FALSE);
0dbd6262
SC
202};
203#endif
204 // _WX_BITMAP_H_