]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/bitmap.h
Same as last one..
[wxWidgets.git] / include / wx / msw / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __BITMAPH__
13 #define __BITMAPH__
14
15 #ifdef __GNUG__
16 #pragma interface "bitmap.h"
17 #endif
18
19 #include "wx/gdiobj.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
22
23 // Bitmap
24 class WXDLLEXPORT wxDC;
25 class WXDLLEXPORT wxControl;
26 class WXDLLEXPORT wxBitmap;
27 class WXDLLEXPORT wxBitmapHandler;
28 class WXDLLEXPORT wxIcon;
29 class WXDLLEXPORT wxCursor;
30
31 // A mask is a mono bitmap used for drawing bitmaps
32 // transparently.
33 class WXDLLEXPORT wxMask: public wxObject
34 {
35 DECLARE_DYNAMIC_CLASS(wxMask)
36
37 public:
38 wxMask(void);
39
40 // Construct a mask from a bitmap and a colour indicating
41 // the transparent area
42 wxMask(const wxBitmap& bitmap, const wxColour& colour);
43
44 // Construct a mask from a bitmap and a palette index indicating
45 // the transparent area
46 wxMask(const wxBitmap& bitmap, const int paletteIndex);
47
48 // Construct a mask from a mono bitmap (copies the bitmap).
49 wxMask(const wxBitmap& bitmap);
50
51 ~wxMask(void);
52
53 bool Create(const wxBitmap& bitmap, const wxColour& colour);
54 bool Create(const wxBitmap& bitmap, const int paletteIndex);
55 bool Create(const wxBitmap& bitmap);
56
57 // Implementation
58 inline WXHBITMAP GetMaskBitmap(void) const { return m_maskBitmap; }
59 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
60 protected:
61 WXHBITMAP m_maskBitmap;
62 };
63
64 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
65 {
66 friend class WXDLLEXPORT wxBitmap;
67 friend class WXDLLEXPORT wxIcon;
68 friend class WXDLLEXPORT wxCursor;
69 public:
70 wxBitmapRefData(void);
71 ~wxBitmapRefData(void);
72
73 public:
74 int m_width;
75 int m_height;
76 int m_depth;
77 bool m_ok;
78 int m_numColors;
79 wxPalette m_bitmapPalette;
80 int m_quality;
81
82 #ifdef __WINDOWS__
83 WXHBITMAP m_hBitmap;
84 wxDC * m_selectedInto; // So bitmap knows whether it's been selected into
85 // a device context (for error checking)
86 wxMask * m_bitmapMask; // Option mask
87 #endif
88 };
89
90 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
91
92 class WXDLLEXPORT wxBitmapHandler: public wxObject
93 {
94 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
95 public:
96 wxBitmapHandler(void) { m_name = ""; m_extension = ""; m_type = 0; };
97
98 virtual bool Create(wxBitmap *bitmap, void *data, const long flags, const int width, const int height, const int depth = 1);
99 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, const long flags,
100 int desiredWidth, int desiredHeight);
101 virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, const int type, const wxPalette *palette = NULL);
102
103 inline void SetName(const wxString& name) { m_name = name; }
104 inline void SetExtension(const wxString& ext) { m_extension = ext; }
105 inline void SetType(const long type) { m_type = type; }
106 inline wxString GetName(void) const { return m_name; }
107 inline wxString GetExtension(void) const { return m_extension; }
108 inline long GetType(void) const { return m_type; }
109 protected:
110 wxString m_name;
111 wxString m_extension;
112 long m_type;
113 };
114 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
115
116 class WXDLLEXPORT wxBitmap: public wxGDIObject
117 {
118 DECLARE_DYNAMIC_CLASS(wxBitmap)
119
120 friend class WXDLLEXPORT wxBitmapHandler;
121
122 public:
123 wxBitmap(void); // Platform-specific
124
125 // Copy constructors
126 inline wxBitmap(const wxBitmap& bitmap)
127 { Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); }
128 inline wxBitmap(const wxBitmap* bitmap) { if (bitmap) Ref(*bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); }
129
130 // Initialize with raw data
131 wxBitmap(const char bits[], const int width, const int height, const int depth = 1);
132
133 #if USE_XPM_IN_MSW
134 // Initialize with XPM data
135 wxBitmap(const char **data, wxItem *anItem = NULL);
136 #endif
137
138 // Load a file or resource
139 wxBitmap(const wxString& name, const long type = wxBITMAP_TYPE_BMP_RESOURCE);
140
141 // New constructor for generalised creation from data
142 wxBitmap(void *data, const long type, const int width, const int height, const int depth = 1);
143
144 // If depth is omitted, will create a bitmap compatible with the display
145 wxBitmap(const int width, const int height, const int depth = -1);
146 ~wxBitmap(void);
147
148 virtual bool Create(const int width, const int height, const int depth = -1);
149 virtual bool Create(void *data, const long type, const int width, const int height, const int depth = 1);
150 virtual bool LoadFile(const wxString& name, const long type = wxBITMAP_TYPE_BMP_RESOURCE);
151 virtual bool SaveFile(const wxString& name, const int type, const wxPalette *cmap = NULL);
152
153 inline bool Ok(void) const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); }
154 inline int GetWidth(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); }
155 inline int GetHeight(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); }
156 inline int GetDepth(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); }
157 inline int GetQuality(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); }
158 void SetWidth(int w);
159 void SetHeight(int h);
160 void SetDepth(int d);
161 void SetQuality(int q);
162 void SetOk(bool isOk);
163 #if WXWIN_COMPATIBILITY
164 inline wxPalette *GetColourMap(void) const { return GetPalette(); }
165 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
166 #endif
167 inline wxPalette* GetPalette(void) const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : NULL); }
168 void SetPalette(const wxPalette& palette);
169
170 inline wxMask *GetMask(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : NULL); }
171 void SetMask(wxMask *mask) ;
172
173 inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
174 inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
175 inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
176
177 // Format handling
178 static inline wxList& GetHandlers(void) { return sm_handlers; }
179 static void AddHandler(wxBitmapHandler *handler);
180 static void InsertHandler(wxBitmapHandler *handler);
181 static bool RemoveHandler(const wxString& name);
182 static wxBitmapHandler *FindHandler(const wxString& name);
183 static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType);
184 static wxBitmapHandler *FindHandler(long bitmapType);
185
186 static void InitStandardHandlers(void);
187 static void CleanUpHandlers(void);
188 protected:
189 static wxList sm_handlers;
190
191 // Implementation
192 public:
193 void SetHBITMAP(WXHBITMAP bmp);
194 inline WXHBITMAP GetHBITMAP(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); }
195 inline void SetSelectedInto(wxDC *dc) { if (M_BITMAPDATA) M_BITMAPDATA->m_selectedInto = dc; }
196 inline wxDC *GetSelectedInto(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_selectedInto : NULL); }
197 bool FreeResource(bool force = FALSE);
198
199 };
200 #endif
201 // __BITMAPH__