1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/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 WXDLLEXPORT wxBitmap
;
19 class WXDLLEXPORT wxIcon
;
20 class WXDLLEXPORT wxCursor
;
21 class WXDLLEXPORT wxImage
;
22 class WXDLLEXPORT 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
);
48 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
49 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
50 bool Create(const wxBitmap
& bitmap
);
53 inline WX_NSBitmapImageRep
GetNSBitmapImageRep()
54 { return m_cocoaNSBitmapImageRep
; }
56 WX_NSBitmapImageRep m_cocoaNSBitmapImageRep
;
59 // ========================================================================
61 // ========================================================================
62 class WXDLLEXPORT wxBitmap
: public wxGDIObject
64 DECLARE_DYNAMIC_CLASS(wxBitmap
)
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 // Platform-specific default constructor
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 **bits
) { CreateFromXpm(bits
); }
75 wxBitmap(char **bits
) { CreateFromXpm((const char**)bits
); }
76 // Load a file or resource
77 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
78 // Constructor for generalised creation from data
79 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
80 // If depth is omitted, will create a bitmap compatible with the display
81 wxBitmap(int width
, int height
, int depth
= -1);
82 // Convert from wxImage:
83 wxBitmap(const wxImage
& image
, int depth
= -1)
84 { CreateFromImage(image
, depth
); }
85 // Convert from wxIcon
86 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
91 // ------------------------------------------------------------------------
93 // ------------------------------------------------------------------------
95 // Initialize with XPM data
96 bool CreateFromXpm(const char **bits
);
97 // Initialize from wxImage
98 bool CreateFromImage(const wxImage
& image
, int depth
=-1);
100 virtual bool Create(int width
, int height
, int depth
= -1);
101 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
102 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
103 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
105 // copies the contents and mask of the given (colour) icon to the bitmap
106 virtual bool CopyFromIcon(const wxIcon
& icon
);
108 wxImage
ConvertToImage() const;
110 // get the given part of bitmap
111 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
114 int GetWidth() const;
115 int GetHeight() const;
116 int GetDepth() const;
117 int GetQuality() const;
118 void SetWidth(int w
);
119 void SetHeight(int h
);
120 void SetDepth(int d
);
121 void SetQuality(int q
);
122 void SetOk(bool isOk
);
124 // raw bitmap access support functions
125 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
126 void UngetRawData(wxPixelDataBase
& data
);
129 wxPalette
* GetPalette() const;
130 void SetPalette(const wxPalette
& palette
);
132 wxMask
*GetMask() const;
133 void SetMask(wxMask
*mask
) ;
135 int GetBitmapType() const;
137 inline bool operator == (const wxBitmap
& bitmap
) const
138 { return m_refData
== bitmap
.m_refData
; }
139 inline bool operator != (const wxBitmap
& bitmap
) const
140 { return m_refData
!= bitmap
.m_refData
; }
143 wxObjectRefData
*CreateRefData() const;
144 wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
147 WX_NSBitmapImageRep
GetNSBitmapImageRep();
148 void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep
);
149 WX_NSImage
GetNSImage(bool useMask
) const;
151 static void InitStandardHandlers() { }
152 static void CleanUpHandlers() { }
155 #endif // __WX_COCOA_BITMAP_H__