]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/bitmap.h
Ensure that the NSTableColumn width is that of its largest item to enable
[wxWidgets.git] / include / wx / mac / carbon / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BITMAP_H_
13 #define _WX_BITMAP_H_
14
15 #include "wx/palette.h"
16
17 // Bitmap
18 class WXDLLIMPEXP_FWD_CORE wxBitmap;
19 class wxBitmapRefData ;
20 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
21 class WXDLLIMPEXP_FWD_CORE wxControl;
22 class WXDLLIMPEXP_FWD_CORE wxCursor;
23 class WXDLLIMPEXP_FWD_CORE wxDC;
24 class WXDLLIMPEXP_FWD_CORE wxIcon;
25 class WXDLLIMPEXP_FWD_CORE wxImage;
26 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
27
28 // A mask is a bitmap used for drawing bitmaps
29 // Internally it is stored as a 8 bit deep memory chunk, 0 = black means the source will be drawn
30 // 255 = white means the source will not be drawn, no other values will be present
31 // 8 bit is chosen only for performance reasons, note also that this is the inverse value range
32 // from alpha, where 0 = invisible , 255 = fully drawn
33
34 class WXDLLEXPORT wxMask: public wxObject
35 {
36 DECLARE_DYNAMIC_CLASS(wxMask)
37
38 public:
39 wxMask();
40
41 // Copy constructor
42 wxMask(const wxMask& mask);
43
44 // Construct a mask from a bitmap and a colour indicating
45 // the transparent area
46 wxMask(const wxBitmap& bitmap, const wxColour& colour);
47
48 // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent)
49 wxMask(const wxBitmap& bitmap);
50
51 // implementation helper only : construct a mask from a 32 bit memory buffer
52 wxMask(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ;
53
54 virtual ~wxMask();
55
56 bool Create(const wxBitmap& bitmap, const wxColour& colour);
57 bool Create(const wxBitmap& bitmap);
58 bool Create(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ;
59
60 // Implementation below
61
62 void Init() ;
63
64 // a 8 bit depth mask
65 void* GetRawAccess() const;
66 int GetBytesPerRow() const { return m_bytesPerRow ; }
67 // renders/updates native representation when necessary
68 void RealizeNative() ;
69
70 WXHBITMAP GetHBITMAP() const ;
71
72
73 private:
74 wxMemoryBuffer m_memBuf ;
75 int m_bytesPerRow ;
76 int m_width ;
77 int m_height ;
78
79 WXHBITMAP m_maskBitmap ;
80
81 };
82
83 class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
84 {
85 DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
86 };
87
88 class WXDLLEXPORT wxBitmap: public wxBitmapBase
89 {
90 DECLARE_DYNAMIC_CLASS(wxBitmap)
91
92 friend class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
93
94 public:
95 wxBitmap(); // Platform-specific
96
97 // Initialize with raw data.
98 wxBitmap(const char bits[], int width, int height, int depth = 1);
99
100 // Initialize with XPM data
101 wxBitmap(const char* const* bits);
102
103 // Load a file or resource
104 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE);
105
106 // Constructor for generalised creation from data
107 wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1);
108
109 // If depth is omitted, will create a bitmap compatible with the display
110 wxBitmap(int width, int height, int depth = -1);
111
112 // Convert from wxImage:
113 wxBitmap(const wxImage& image, int depth = -1);
114
115 // Convert from wxIcon
116 wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); }
117
118 virtual ~wxBitmap();
119
120 wxImage ConvertToImage() const;
121
122 // get the given part of bitmap
123 wxBitmap GetSubBitmap( const wxRect& rect ) const;
124
125 virtual bool Create(int width, int height, int depth = -1);
126 virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
127 // virtual bool Create( WXHICON icon) ;
128 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
129 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
130
131 wxBitmapRefData *GetBitmapData() const
132 { return (wxBitmapRefData *)m_refData; }
133
134 // copies the contents and mask of the given (colour) icon to the bitmap
135 virtual bool CopyFromIcon(const wxIcon& icon);
136
137 int GetWidth() const;
138 int GetHeight() const;
139 int GetDepth() const;
140 void SetWidth(int w);
141 void SetHeight(int h);
142 void SetDepth(int d);
143 void SetOk(bool isOk);
144
145 #if wxUSE_PALETTE
146 wxPalette* GetPalette() const;
147 void SetPalette(const wxPalette& palette);
148 #endif // wxUSE_PALETTE
149
150 wxMask *GetMask() const;
151 void SetMask(wxMask *mask) ;
152
153 static void InitStandardHandlers();
154
155 // raw bitmap access support functions, for internal use only
156 void *GetRawData(wxPixelDataBase& data, int bpp);
157 void UngetRawData(wxPixelDataBase& data);
158
159 // these functions are internal and shouldn't be used, they risk to
160 // disappear in the future
161 bool HasAlpha() const;
162 void UseAlpha();
163
164 // returns the 'native' implementation, a GWorldPtr for the content and one for the mask
165 WXHBITMAP GetHBITMAP( WXHBITMAP * mask = NULL ) const;
166
167 // returns a CGImageRef which must released after usage with CGImageRelease
168 CGImageRef CreateCGImage() const ;
169
170 // returns a IconRef which must be retained before and released after usage
171 IconRef GetIconRef() const;
172 // returns a IconRef which must be released after usage
173 IconRef CreateIconRef() const;
174 // get read only access to the underlying buffer
175 void *GetRawAccess() const ;
176 // brackets to the underlying OS structure for read/write access
177 // makes sure that no cached images will be constructed until terminated
178 void *BeginRawAccess() ;
179 void EndRawAccess() ;
180
181 protected:
182 virtual wxGDIRefData *CreateGDIRefData() const;
183 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
184 };
185
186 #endif // _WX_BITMAP_H_