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