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