1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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 wxSize
GetSize() const
118 return IsNull() ? wxSize(0,0) :
119 wxSize(GetGDIImageData()->m_width
, GetGDIImageData()->m_height
);
122 void SetWidth(int w
) { AllocExclusive(); GetGDIImageData()->m_width
= w
; }
123 void SetHeight(int h
) { AllocExclusive(); GetGDIImageData()->m_height
= h
; }
124 void SetDepth(int d
) { AllocExclusive(); GetGDIImageData()->m_depth
= d
; }
126 void SetSize(int w
, int h
)
129 GetGDIImageData()->SetSize(w
, h
);
131 void SetSize(const wxSize
& size
) { SetSize(size
.x
, size
.y
); }
133 // forward some of base class virtuals to wxGDIImageRefData
134 bool FreeResource(bool force
= false);
135 virtual WXHANDLE
GetResourceHandle() const;
138 // create the data for the derived class here
139 virtual wxGDIImageRefData
*CreateData() const = 0;
141 // implement the wxGDIObject method in terms of our, more specific, one
142 virtual wxGDIRefData
*CreateGDIRefData() const { return CreateData(); }
144 // we can't [efficiently] clone objects of this class
145 virtual wxGDIRefData
*
146 CloneGDIRefData(const wxGDIRefData
*WXUNUSED(data
)) const
148 wxFAIL_MSG( wxT("must be implemented if used") );
153 static wxGDIImageHandlerList ms_handlers
;
156 // ----------------------------------------------------------------------------
157 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
158 // ----------------------------------------------------------------------------
160 class WXDLLIMPEXP_CORE wxGDIImageHandler
: public wxObject
164 wxGDIImageHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
165 wxGDIImageHandler(const wxString
& name
,
168 : m_name(name
), m_extension(ext
), m_type(type
) { }
171 void SetName(const wxString
& name
) { m_name
= name
; }
172 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
173 void SetType(wxBitmapType type
) { m_type
= type
; }
175 const wxString
& GetName() const { return m_name
; }
176 const wxString
& GetExtension() const { return m_extension
; }
177 wxBitmapType
GetType() const { return m_type
; }
179 // real handler operations: to implement in derived classes
180 virtual bool Create(wxGDIImage
*image
,
183 int width
, int height
, int depth
= 1) = 0;
184 virtual bool Load(wxGDIImage
*image
,
185 const wxString
& name
,
187 int desiredWidth
, int desiredHeight
) = 0;
188 virtual bool Save(const wxGDIImage
*image
,
189 const wxString
& name
,
190 wxBitmapType type
) const = 0;
194 wxString m_extension
;
198 #endif // _WX_MSW_GDIIMAGE_H_