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 WXDLLEXPORT 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 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 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
81 // ----------------------------------------------------------------------------
83 class WXDLLEXPORT wxGDIImageHandler
: public wxObject
87 wxGDIImageHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
88 wxGDIImageHandler(const wxString
& name
,
91 : m_name(name
), m_extension(ext
)
97 void SetName(const wxString
& name
) { m_name
= name
; }
98 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
99 void SetType(long type
) { m_type
= type
; }
101 const wxString
& GetName() const { return m_name
; }
102 const wxString
& GetExtension() const { return m_extension
; }
103 long GetType() const { return m_type
; }
105 // real handler operations: to implement in derived classes
106 virtual bool Create(wxGDIImage
*image
,
109 int width
, int height
, int depth
= 1) = 0;
110 virtual bool Load(wxGDIImage
*image
,
111 const wxString
& name
,
113 int desiredWidth
, int desiredHeight
) = 0;
114 virtual bool Save(wxGDIImage
*image
,
115 const wxString
& name
,
120 wxString m_extension
;
124 // ----------------------------------------------------------------------------
125 // wxGDIImage: this class supports GDI image handlers which may be registered
126 // dynamically and will be used for loading/saving the images in the specified
127 // format. It also falls back to wxImage if no appropriate image is found.
128 // ----------------------------------------------------------------------------
130 class WXDLLEXPORT wxGDIImage
: public wxGDIObject
133 // handlers list interface
134 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
136 static void AddHandler(wxGDIImageHandler
*handler
);
137 static void InsertHandler(wxGDIImageHandler
*handler
);
138 static bool RemoveHandler(const wxString
& name
);
140 static wxGDIImageHandler
*FindHandler(const wxString
& name
);
141 static wxGDIImageHandler
*FindHandler(const wxString
& extension
, long type
);
142 static wxGDIImageHandler
*FindHandler(long type
);
144 static void InitStandardHandlers();
145 static void CleanUpHandlers();
147 // access to the ref data casted to the right type
148 wxGDIImageRefData
*GetGDIImageData() const
149 { return (wxGDIImageRefData
*)m_refData
; }
152 WXHANDLE
GetHandle() const
153 { return IsNull() ? 0 : GetGDIImageData()->m_handle
; }
154 void SetHandle(WXHANDLE handle
)
155 { AllocExclusive(); GetGDIImageData()->m_handle
= handle
; }
157 bool Ok() const { return IsOk(); }
158 bool IsOk() const { return GetHandle() != 0; }
160 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width
; }
161 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height
; }
162 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth
; }
164 void SetWidth(int w
) { AllocExclusive(); GetGDIImageData()->m_width
= w
; }
165 void SetHeight(int h
) { AllocExclusive(); GetGDIImageData()->m_height
= h
; }
166 void SetDepth(int d
) { AllocExclusive(); GetGDIImageData()->m_depth
= d
; }
168 void SetSize(int w
, int h
)
171 GetGDIImageData()->SetSize(w
, h
);
173 void SetSize(const wxSize
& size
) { SetSize(size
.x
, size
.y
); }
175 // forward some of base class virtuals to wxGDIImageRefData
176 bool FreeResource(bool force
= false);
177 virtual WXHANDLE
GetResourceHandle() const;
180 // create the data for the derived class here
181 virtual wxGDIImageRefData
*CreateData() const = 0;
183 // implement the wxObject method in terms of our, more specific, one
184 virtual wxObjectRefData
*CreateRefData() const { return CreateData(); }
186 static wxGDIImageHandlerList ms_handlers
;
189 #endif // _WX_MSW_GDIIMAGE_H_