1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_COCOA_BITMAP_H__
13 #define __WX_COCOA_BITMAP_H__
15 #include "wx/palette.h"
18 class WXDLLIMPEXP_FWD_CORE wxBitmap
;
19 class WXDLLIMPEXP_FWD_CORE wxIcon
;
20 class WXDLLIMPEXP_FWD_CORE wxCursor
;
21 class WXDLLIMPEXP_FWD_CORE wxImage
;
22 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase
;
24 // ========================================================================
26 // ========================================================================
28 // A mask is a 1-bit alpha bitmap used for drawing bitmaps transparently.
29 class WXDLLEXPORT wxMask
: public wxObject
31 DECLARE_DYNAMIC_CLASS(wxMask
)
35 // Construct a mask from a bitmap and a colour indicating
36 // the transparent area
37 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
39 // Construct a mask from a bitmap and a palette index indicating
40 // the transparent area
41 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
43 // Construct a mask from a mono bitmap (copies the bitmap).
44 wxMask(const wxBitmap
& bitmap
);
47 wxMask(const wxMask
& src
);
51 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
52 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
53 bool Create(const wxBitmap
& bitmap
);
56 inline WX_NSBitmapImageRep
GetNSBitmapImageRep()
57 { return m_cocoaNSBitmapImageRep
; }
59 WX_NSBitmapImageRep m_cocoaNSBitmapImageRep
;
62 // ========================================================================
64 // ========================================================================
65 class WXDLLEXPORT wxBitmap
: public wxGDIObject
67 DECLARE_DYNAMIC_CLASS(wxBitmap
)
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
72 // Platform-specific default constructor
74 // Initialize with raw data.
75 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
76 // Initialize with XPM data
77 wxBitmap(const char* const* bits
);
78 // Load a file or resource
79 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
80 // Construct from Cocoa's NSImage
81 wxBitmap(NSImage
* cocoaNSImage
);
82 // Construct from Cocoa's NSBitmapImageRep
83 wxBitmap(NSBitmapImageRep
* cocoaNSBitmapImageRep
);
84 // Constructor for generalised creation from data
85 wxBitmap(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
86 // If depth is omitted, will create a bitmap compatible with the display
87 wxBitmap(int width
, int height
, int depth
= -1);
88 // Convert from wxImage:
89 wxBitmap(const wxImage
& image
, int depth
= -1)
90 { CreateFromImage(image
, depth
); }
91 // Convert from wxIcon
92 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
101 // Initialize from wxImage
102 bool CreateFromImage(const wxImage
& image
, int depth
=-1);
104 virtual bool Create(int width
, int height
, int depth
= -1);
105 bool Create(NSImage
* cocoaNSImage
);
106 bool Create(NSBitmapImageRep
* cocoaNSBitmapImageRep
);
107 virtual bool Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
108 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
109 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
111 // copies the contents and mask of the given (colour) icon to the bitmap
112 virtual bool CopyFromIcon(const wxIcon
& icon
);
114 wxImage
ConvertToImage() const;
116 // get the given part of bitmap
117 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
119 bool Ok() const { return IsOk(); }
121 int GetWidth() const;
122 int GetHeight() const;
123 int GetDepth() const;
124 int GetQuality() const;
125 void SetWidth(int w
);
126 void SetHeight(int h
);
127 void SetDepth(int d
);
128 void SetQuality(int q
);
129 void SetOk(bool isOk
);
131 // raw bitmap access support functions
132 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
133 void UngetRawData(wxPixelDataBase
& data
);
135 wxPalette
* GetPalette() const;
136 void SetPalette(const wxPalette
& palette
);
138 wxMask
*GetMask() const;
139 void SetMask(wxMask
*mask
) ;
141 int GetBitmapType() const;
144 wxObjectRefData
*CreateRefData() const;
145 wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
148 WX_NSBitmapImageRep
GetNSBitmapImageRep();
149 void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep
);
150 WX_NSImage
GetNSImage(bool useMask
) const;
152 static void InitStandardHandlers() { }
153 static void CleanUpHandlers() { }
156 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxBitmapHandlerBase
158 DECLARE_ABSTRACT_CLASS(wxBitmapHandler
)
162 // __WX_COCOA_BITMAP_H__