]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/bitmap.h
Move some things to wxBitmapBase to avoid much duplication.
[wxWidgets.git] / include / wx / cocoa / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/cocoa/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/07/19
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __WX_COCOA_BITMAP_H__
13 #define __WX_COCOA_BITMAP_H__
14
15 #include "wx/palette.h"
16
17 // Bitmap
18 class WXDLLEXPORT wxBitmap;
19 class WXDLLEXPORT wxIcon;
20 class WXDLLEXPORT wxCursor;
21 class WXDLLEXPORT wxImage;
22 class WXDLLEXPORT wxPixelDataBase;
23
24 // ========================================================================
25 // wxMask
26 // ========================================================================
27
28 // A mask is a 1-bit alpha bitmap used for drawing bitmaps transparently.
29 class WXDLLEXPORT wxMask: public wxObject
30 {
31 DECLARE_DYNAMIC_CLASS(wxMask)
32 public:
33 wxMask();
34
35 // Construct a mask from a bitmap and a colour indicating
36 // the transparent area
37 wxMask(const wxBitmap& bitmap, const wxColour& colour);
38
39 // Construct a mask from a bitmap and a palette index indicating
40 // the transparent area
41 wxMask(const wxBitmap& bitmap, int paletteIndex);
42
43 // Construct a mask from a mono bitmap (copies the bitmap).
44 wxMask(const wxBitmap& bitmap);
45
46 virtual ~wxMask();
47
48 bool Create(const wxBitmap& bitmap, const wxColour& colour);
49 bool Create(const wxBitmap& bitmap, int paletteIndex);
50 bool Create(const wxBitmap& bitmap);
51
52 // wxCocoa
53 inline WX_NSBitmapImageRep GetNSBitmapImageRep()
54 { return m_cocoaNSBitmapImageRep; }
55 protected:
56 WX_NSBitmapImageRep m_cocoaNSBitmapImageRep;
57 };
58
59 // ========================================================================
60 // wxBitmap
61 // ========================================================================
62 class WXDLLEXPORT wxBitmap: public wxGDIObject
63 {
64 DECLARE_DYNAMIC_CLASS(wxBitmap)
65 // ------------------------------------------------------------------------
66 // initialization
67 // ------------------------------------------------------------------------
68 public:
69 // Platform-specific default constructor
70 wxBitmap();
71 // Initialize with raw data.
72 wxBitmap(const char bits[], int width, int height, int depth = 1);
73 // Initialize with XPM data
74 wxBitmap(const char* const* bits);
75 // Load a file or resource
76 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
77 // Constructor for generalised creation from data
78 wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1);
79 // If depth is omitted, will create a bitmap compatible with the display
80 wxBitmap(int width, int height, int depth = -1);
81 // Convert from wxImage:
82 wxBitmap(const wxImage& image, int depth = -1)
83 { CreateFromImage(image, depth); }
84 // Convert from wxIcon
85 wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); }
86
87 // destructor
88 virtual ~wxBitmap();
89
90 // ------------------------------------------------------------------------
91 // Implementation
92 // ------------------------------------------------------------------------
93 public:
94 // Initialize from wxImage
95 bool CreateFromImage(const wxImage& image, int depth=-1);
96
97 virtual bool Create(int width, int height, int depth = -1);
98 virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
99 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
100 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
101
102 // copies the contents and mask of the given (colour) icon to the bitmap
103 virtual bool CopyFromIcon(const wxIcon& icon);
104
105 wxImage ConvertToImage() const;
106
107 // get the given part of bitmap
108 wxBitmap GetSubBitmap( const wxRect& rect ) const;
109
110 bool Ok() const;
111 int GetWidth() const;
112 int GetHeight() const;
113 int GetDepth() const;
114 int GetQuality() const;
115 void SetWidth(int w);
116 void SetHeight(int h);
117 void SetDepth(int d);
118 void SetQuality(int q);
119 void SetOk(bool isOk);
120
121 // raw bitmap access support functions
122 void *GetRawData(wxPixelDataBase& data, int bpp);
123 void UngetRawData(wxPixelDataBase& data);
124 void UseAlpha();
125
126 wxPalette* GetPalette() const;
127 void SetPalette(const wxPalette& palette);
128
129 wxMask *GetMask() const;
130 void SetMask(wxMask *mask) ;
131
132 int GetBitmapType() const;
133
134 inline bool operator == (const wxBitmap& bitmap) const
135 { return m_refData == bitmap.m_refData; }
136 inline bool operator != (const wxBitmap& bitmap) const
137 { return m_refData != bitmap.m_refData; }
138
139 // wxObjectRefData
140 wxObjectRefData *CreateRefData() const;
141 wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
142
143 // wxCocoa
144 WX_NSBitmapImageRep GetNSBitmapImageRep();
145 void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep);
146 WX_NSImage GetNSImage(bool useMask) const;
147
148 static void InitStandardHandlers() { }
149 static void CleanUpHandlers() { }
150 };
151
152 class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase
153 {
154 DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
155 };
156
157 #endif // __WX_COCOA_BITMAP_H__