1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/gdiimage.h
3 // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
5 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // NB: this is a private header, it is not intended to be directly included by
13 // user code (but may be included from other, public, wxWin headers
15 #ifndef _WX_MSW_GDIIMAGE_H_
16 #define _WX_MSW_GDIIMAGE_H_
18 #include "wx/gdiobj.h" // base class
19 #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
22 class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData
;
23 class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler
;
24 class WXDLLIMPEXP_FWD_CORE wxGDIImage
;
26 WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler
, wxGDIImageHandlerList
);
28 // ----------------------------------------------------------------------------
29 // wxGDIImageRefData: common data fields for all derived classes
30 // ----------------------------------------------------------------------------
32 class WXDLLIMPEXP_CORE wxGDIImageRefData
: public wxGDIRefData
37 m_width
= m_height
= m_depth
= 0;
42 wxGDIImageRefData(const wxGDIImageRefData
& data
) : wxGDIRefData()
44 m_width
= data
.m_width
;
45 m_height
= data
.m_height
;
46 m_depth
= data
.m_depth
;
48 // can't copy handles like this, derived class copy ctor must do it!
53 virtual bool IsOk() const { return m_handle
!= 0; }
55 void SetSize(int w
, int h
) { m_width
= w
; m_height
= h
; }
57 // free the ressources we allocated
58 virtual void Free() = 0;
60 // for compatibility, the member fields are public
62 // the size of the image
63 int m_width
, m_height
;
65 // the depth of the image
71 WXHANDLE m_handle
; // for untyped access
78 // ----------------------------------------------------------------------------
79 // wxGDIImage: this class supports GDI image handlers which may be registered
80 // dynamically and will be used for loading/saving the images in the specified
81 // format. It also falls back to wxImage if no appropriate image is found.
82 // ----------------------------------------------------------------------------
84 class WXDLLIMPEXP_CORE wxGDIImage
: public wxGDIObject
87 // handlers list interface
88 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
90 static void AddHandler(wxGDIImageHandler
*handler
);
91 static void InsertHandler(wxGDIImageHandler
*handler
);
92 static bool RemoveHandler(const wxString
& name
);
94 static wxGDIImageHandler
*FindHandler(const wxString
& name
);
95 static wxGDIImageHandler
*FindHandler(const wxString
& extension
, long type
);
96 static wxGDIImageHandler
*FindHandler(long type
);
98 static void InitStandardHandlers();
99 static void CleanUpHandlers();
101 // access to the ref data casted to the right type
102 wxGDIImageRefData
*GetGDIImageData() const
103 { return (wxGDIImageRefData
*)m_refData
; }
106 WXHANDLE
GetHandle() const
107 { return IsNull() ? 0 : GetGDIImageData()->m_handle
; }
108 void SetHandle(WXHANDLE handle
)
109 { AllocExclusive(); GetGDIImageData()->m_handle
= handle
; }
111 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width
; }
112 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height
; }
113 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth
; }
115 wxSize
GetSize() const
117 return IsNull() ? wxSize(0,0) :
118 wxSize(GetGDIImageData()->m_width
, GetGDIImageData()->m_height
);
121 void SetWidth(int w
) { AllocExclusive(); GetGDIImageData()->m_width
= w
; }
122 void SetHeight(int h
) { AllocExclusive(); GetGDIImageData()->m_height
= h
; }
123 void SetDepth(int d
) { AllocExclusive(); GetGDIImageData()->m_depth
= d
; }
125 void SetSize(int w
, int h
)
128 GetGDIImageData()->SetSize(w
, h
);
130 void SetSize(const wxSize
& size
) { SetSize(size
.x
, size
.y
); }
132 // forward some of base class virtuals to wxGDIImageRefData
133 bool FreeResource(bool force
= false);
134 virtual WXHANDLE
GetResourceHandle() const;
137 // create the data for the derived class here
138 virtual wxGDIImageRefData
*CreateData() const = 0;
140 // implement the wxGDIObject method in terms of our, more specific, one
141 virtual wxGDIRefData
*CreateGDIRefData() const { return CreateData(); }
143 // we can't [efficiently] clone objects of this class
144 virtual wxGDIRefData
*
145 CloneGDIRefData(const wxGDIRefData
*WXUNUSED(data
)) const
147 wxFAIL_MSG( wxT("must be implemented if used") );
152 static wxGDIImageHandlerList ms_handlers
;
155 // ----------------------------------------------------------------------------
156 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
157 // ----------------------------------------------------------------------------
159 class WXDLLIMPEXP_CORE wxGDIImageHandler
: public wxObject
163 wxGDIImageHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
164 wxGDIImageHandler(const wxString
& name
,
167 : m_name(name
), m_extension(ext
), m_type(type
) { }
170 void SetName(const wxString
& name
) { m_name
= name
; }
171 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
172 void SetType(wxBitmapType type
) { m_type
= type
; }
174 const wxString
& GetName() const { return m_name
; }
175 const wxString
& GetExtension() const { return m_extension
; }
176 wxBitmapType
GetType() const { return m_type
; }
178 // real handler operations: to implement in derived classes
179 virtual bool Create(wxGDIImage
*image
,
182 int width
, int height
, int depth
= 1) = 0;
183 virtual bool Load(wxGDIImage
*image
,
184 const wxString
& name
,
186 int desiredWidth
, int desiredHeight
) = 0;
187 virtual bool Save(const wxGDIImage
*image
,
188 const wxString
& name
,
189 wxBitmapType type
) const = 0;
193 wxString m_extension
;
197 #endif // _WX_MSW_GDIIMAGE_H_