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 licence
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_
19 #include "wx/gdiobj.h" // base class
20 #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
23 class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData
;
24 class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler
;
25 class WXDLLIMPEXP_FWD_CORE wxGDIImage
;
27 WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler
, wxGDIImageHandlerList
);
29 // ----------------------------------------------------------------------------
30 // wxGDIImageRefData: common data fields for all derived classes
31 // ----------------------------------------------------------------------------
33 class WXDLLIMPEXP_CORE wxGDIImageRefData
: public wxGDIRefData
38 m_width
= m_height
= m_depth
= 0;
43 wxGDIImageRefData(const wxGDIImageRefData
& data
) : wxGDIRefData(data
)
45 m_width
= data
.m_width
;
46 m_height
= data
.m_height
;
47 m_depth
= data
.m_depth
;
49 // can't copy handles like this, derived class copy ctor must do it!
54 virtual bool IsOk() const { return m_handle
!= 0; }
56 void SetSize(int w
, int h
) { m_width
= w
; m_height
= h
; }
58 // free the ressources we allocated
59 virtual void Free() = 0;
61 // for compatibility, the member fields are public
63 // the size of the image
64 int m_width
, m_height
;
66 // the depth of the image
72 WXHANDLE m_handle
; // for untyped access
79 // ----------------------------------------------------------------------------
80 // wxGDIImage: this class supports GDI image handlers which may be registered
81 // dynamically and will be used for loading/saving the images in the specified
82 // format. It also falls back to wxImage if no appropriate image is found.
83 // ----------------------------------------------------------------------------
85 class WXDLLIMPEXP_CORE wxGDIImage
: public wxGDIObject
88 // handlers list interface
89 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
91 static void AddHandler(wxGDIImageHandler
*handler
);
92 static void InsertHandler(wxGDIImageHandler
*handler
);
93 static bool RemoveHandler(const wxString
& name
);
95 static wxGDIImageHandler
*FindHandler(const wxString
& name
);
96 static wxGDIImageHandler
*FindHandler(const wxString
& extension
, long type
);
97 static wxGDIImageHandler
*FindHandler(long type
);
99 static void InitStandardHandlers();
100 static void CleanUpHandlers();
102 // access to the ref data casted to the right type
103 wxGDIImageRefData
*GetGDIImageData() const
104 { return (wxGDIImageRefData
*)m_refData
; }
107 WXHANDLE
GetHandle() const
108 { return IsNull() ? 0 : GetGDIImageData()->m_handle
; }
109 void SetHandle(WXHANDLE handle
)
110 { AllocExclusive(); GetGDIImageData()->m_handle
= handle
; }
112 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width
; }
113 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height
; }
114 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth
; }
116 void SetWidth(int w
) { AllocExclusive(); GetGDIImageData()->m_width
= w
; }
117 void SetHeight(int h
) { AllocExclusive(); GetGDIImageData()->m_height
= h
; }
118 void SetDepth(int d
) { AllocExclusive(); GetGDIImageData()->m_depth
= d
; }
120 void SetSize(int w
, int h
)
123 GetGDIImageData()->SetSize(w
, h
);
125 void SetSize(const wxSize
& size
) { SetSize(size
.x
, size
.y
); }
127 // forward some of base class virtuals to wxGDIImageRefData
128 bool FreeResource(bool force
= false);
129 virtual WXHANDLE
GetResourceHandle() const;
132 // create the data for the derived class here
133 virtual wxGDIImageRefData
*CreateData() const = 0;
135 // implement the wxGDIObject method in terms of our, more specific, one
136 virtual wxGDIRefData
*CreateGDIRefData() const { return CreateData(); }
138 // we can't [efficiently] clone objects of this class
139 virtual wxGDIRefData
*
140 CloneGDIRefData(const wxGDIRefData
*WXUNUSED(data
)) const
142 wxFAIL_MSG( _T("must be implemented if used") );
147 static wxGDIImageHandlerList ms_handlers
;
150 // ----------------------------------------------------------------------------
151 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
152 // ----------------------------------------------------------------------------
154 class WXDLLIMPEXP_CORE wxGDIImageHandler
: public wxObject
158 wxGDIImageHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
159 wxGDIImageHandler(const wxString
& name
,
162 : m_name(name
), m_extension(ext
), m_type(type
) { }
165 void SetName(const wxString
& name
) { m_name
= name
; }
166 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
167 void SetType(wxBitmapType type
) { m_type
= type
; }
169 const wxString
& GetName() const { return m_name
; }
170 const wxString
& GetExtension() const { return m_extension
; }
171 wxBitmapType
GetType() const { return m_type
; }
173 // real handler operations: to implement in derived classes
174 virtual bool Create(wxGDIImage
*image
,
177 int width
, int height
, int depth
= 1) = 0;
178 virtual bool Load(wxGDIImage
*image
,
179 const wxString
& name
,
181 int desiredWidth
, int desiredHeight
) = 0;
182 virtual bool Save(const wxGDIImage
*image
,
183 const wxString
& name
,
184 wxBitmapType type
) const = 0;
188 wxString m_extension
;
192 #endif // _WX_MSW_GDIIMAGE_H_