1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/os2/gdiimage.h
3 // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
5 // Author: David Webster (adapted from msw version by Vadim Zeitlin)
9 // Copyright: (c) 1999 David Webster
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_OS2_GDIIMAGE_H_
17 #define _WX_OS2_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_nWidth
= m_nHeight
= m_nDepth
= 0;
58 { m_nWidth
= nW
; m_nHeight
= nH
; }
60 // free the ressources we allocated
61 virtual void Free() { };
63 // for compatibility, the member fields are public
65 // the size of the image
69 // the depth of the image
75 WXHANDLE m_hHandle
; // for untyped access
84 // ----------------------------------------------------------------------------
85 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
86 // ----------------------------------------------------------------------------
88 class WXDLLEXPORT wxGDIImageHandler
: public wxObject
92 wxGDIImageHandler() { m_lType
= wxBITMAP_TYPE_INVALID
; }
93 wxGDIImageHandler( const wxString
& rName
104 void SetName(const wxString
& rName
) { m_sName
= rName
; }
105 void SetExtension(const wxString
& rExt
) { m_sExtension
= rExt
; }
106 void SetType(long lType
) { m_lType
= lType
; }
108 wxString
GetName() const { return m_sName
; }
109 wxString
GetExtension() const { return m_sExtension
; }
110 long GetType() const { return m_lType
; }
112 // real handler operations: to implement in derived classes
113 virtual bool Create( wxGDIImage
* pImage
120 virtual bool Load( wxGDIImage
* pImage
121 ,const wxString
& rName
127 virtual bool Load( wxGDIImage
* pImage
133 virtual bool Save( wxGDIImage
* pImage
134 ,const wxString
& rName
140 wxString m_sExtension
;
142 }; // end of wxGDIImageHandler
144 // ----------------------------------------------------------------------------
145 // wxGDIImage: this class supports GDI image handlers which may be registered
146 // dynamically and will be used for loading/saving the images in the specified
147 // format. It also falls back to wxImage if no appropriate image is found.
148 // ----------------------------------------------------------------------------
150 class WXDLLEXPORT wxGDIImage
: public wxGDIObject
153 // handlers list interface
154 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
156 static void AddHandler(wxGDIImageHandler
* hHandler
);
157 static void InsertHandler(wxGDIImageHandler
* hHandler
);
158 static bool RemoveHandler(const wxString
& rName
);
160 static wxGDIImageHandler
* FindHandler(const wxString
& rName
);
161 static wxGDIImageHandler
* FindHandler(const wxString
& rExtension
, long lType
);
162 static wxGDIImageHandler
* FindHandler(long lType
);
164 static void InitStandardHandlers();
165 static void CleanUpHandlers();
167 // access to the ref data casted to the right type
168 wxGDIImageRefData
*GetGDIImageData() const
169 { return (wxGDIImageRefData
*)m_refData
; }
171 // create data if we don't have it yet
172 void EnsureHasData() { if ( IsNull() ) m_refData
= CreateData(); }
175 WXHANDLE
GetHandle() const
177 wxGDIImageRefData
* pData
;
179 pData
= GetGDIImageData();
183 return pData
->m_hHandle
;
185 void SetHandle(WXHANDLE hHandle
)
187 wxGDIImageRefData
* pData
;
190 pData
= GetGDIImageData();
191 pData
->m_hHandle
= hHandle
;
194 bool Ok() const { return GetHandle() != 0; }
196 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_nWidth
; }
197 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_nHeight
; }
198 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_nDepth
; }
200 void SetWidth(int nW
) { EnsureHasData(); GetGDIImageData()->m_nWidth
= nW
; }
201 void SetHeight(int nH
) { EnsureHasData(); GetGDIImageData()->m_nHeight
= nH
; }
202 void SetDepth(int nD
) { EnsureHasData(); GetGDIImageData()->m_nDepth
= nD
; }
209 GetGDIImageData()->SetSize(nW
, nH
);
211 void SetSize(const wxSize
& rSize
) { SetSize(rSize
.x
, rSize
.y
); }
213 UINT
GetId(void) const
215 wxGDIImageRefData
* pData
;
217 pData
= GetGDIImageData();
222 } // end of WxWinGdi_CGDIImage::GetId
225 wxGDIImageRefData
* pData
;
228 pData
= GetGDIImageData();
231 // forward some of base class virtuals to wxGDIImageRefData
232 bool FreeResource(bool bForce
= FALSE
);
233 virtual WXHANDLE
GetResourceHandle();
236 // create the data for the derived class here
237 virtual wxGDIImageRefData
* CreateData() const = 0;
239 static wxGDIImageHandlerList ms_handlers
;
242 #endif // _WX_MSW_GDIIMAGE_H_