1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/gdiimage.h
3 // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
5 // Author: Vadim Zeitlin
9 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows license
11 ///////////////////////////////////////////////////////////////////////////////
13 // NB: this is a private header, it is not intended to be directly included by
14 // user code (but may be included from other, public, wxWin headers
16 #ifndef _WX_MSW_GDIIMAGE_H_
17 #define _WX_MSW_GDIIMAGE_H_
20 #pragma interface "gdiimage.h"
23 #include "wx/gdiobj.h" // base class
24 #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
27 class WXDLLEXPORT wxGDIImageRefData
;
28 class WXDLLEXPORT wxGDIImageHandler
;
29 class WXDLLEXPORT wxGDIImage
;
31 WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler
, wxGDIImageHandlerList
);
33 // ----------------------------------------------------------------------------
34 // wxGDIImageRefData: common data fields for all derived classes
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxGDIImageRefData
: public wxGDIRefData
42 m_width
= m_height
= m_depth
= 0;
46 #if WXWIN_COMPATIBILITY_2
48 #endif // WXWIN_COMPATIBILITY_2
52 bool IsOk() const { return m_handle
!= 0; }
54 void SetSize(int w
, int h
) { m_width
= w
; m_height
= h
; }
56 // free the ressources we allocated
57 virtual void Free() = 0;
59 // for compatibility, the member fields are public
61 // the size of the image
62 int m_width
, m_height
;
64 // the depth of the image
70 WXHANDLE m_handle
; // for untyped access
76 // this filed is redundant and using it is error prone but keep it for
77 // backwards compatibility
78 #if WXWIN_COMPATIBILITY_2
79 void SetOk() { m_ok
= m_handle
!= 0; }
82 #endif // WXWIN_COMPATIBILITY_2
85 // ----------------------------------------------------------------------------
86 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
87 // ----------------------------------------------------------------------------
89 class WXDLLEXPORT wxGDIImageHandler
: public wxObject
93 wxGDIImageHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
94 wxGDIImageHandler(const wxString
& name
,
97 : m_name(name
), m_extension(ext
)
103 void SetName(const wxString
& name
) { m_name
= name
; }
104 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
105 void SetType(long type
) { m_type
= type
; }
107 wxString
GetName() const { return m_name
; }
108 wxString
GetExtension() const { return m_extension
; }
109 long GetType() const { return m_type
; }
111 // real handler operations: to implement in derived classes
112 virtual bool Create(wxGDIImage
*image
,
115 int width
, int height
, int depth
= 1) = 0;
116 virtual bool Load(wxGDIImage
*image
,
117 const wxString
& name
,
119 int desiredWidth
, int desiredHeight
) = 0;
120 virtual bool Save(wxGDIImage
*image
,
121 const wxString
& name
,
126 wxString m_extension
;
130 // ----------------------------------------------------------------------------
131 // wxGDIImage: this class supports GDI image handlers which may be registered
132 // dynamically and will be used for loading/saving the images in the specified
133 // format. It also falls back to wxImage if no appropriate image is found.
134 // ----------------------------------------------------------------------------
136 class WXDLLEXPORT wxGDIImage
: public wxGDIObject
139 // handlers list interface
140 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
142 static void AddHandler(wxGDIImageHandler
*handler
);
143 static void InsertHandler(wxGDIImageHandler
*handler
);
144 static bool RemoveHandler(const wxString
& name
);
146 static wxGDIImageHandler
*FindHandler(const wxString
& name
);
147 static wxGDIImageHandler
*FindHandler(const wxString
& extension
, long type
);
148 static wxGDIImageHandler
*FindHandler(long type
);
150 static void InitStandardHandlers();
151 static void CleanUpHandlers();
153 // access to the ref data casted to the right type
154 wxGDIImageRefData
*GetGDIImageData() const
155 { return (wxGDIImageRefData
*)m_refData
; }
157 // create data if we don't have it yet
158 void EnsureHasData() { if ( IsNull() ) m_refData
= CreateData(); }
161 WXHANDLE
GetHandle() const
162 { return IsNull() ? 0 : GetGDIImageData()->m_handle
; }
163 void SetHandle(WXHANDLE handle
)
164 { EnsureHasData(); GetGDIImageData()->m_handle
= handle
; }
166 bool Ok() const { return GetHandle() != 0; }
168 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width
; }
169 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height
; }
170 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth
; }
172 void SetWidth(int w
) { EnsureHasData(); GetGDIImageData()->m_width
= w
; }
173 void SetHeight(int h
) { EnsureHasData(); GetGDIImageData()->m_height
= h
; }
174 void SetDepth(int d
) { EnsureHasData(); GetGDIImageData()->m_depth
= d
; }
176 void SetSize(int w
, int h
)
179 GetGDIImageData()->SetSize(w
, h
);
181 void SetSize(const wxSize
& size
) { SetSize(size
.x
, size
.y
); }
183 // forward some of base class virtuals to wxGDIImageRefData
184 bool FreeResource(bool force
= FALSE
);
185 virtual WXHANDLE
GetResourceHandle() const;
188 // create the data for the derived class here
189 virtual wxGDIImageRefData
*CreateData() const = 0;
191 static wxGDIImageHandlerList ms_handlers
;
194 #endif // _WX_MSW_GDIIMAGE_H_