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 // ----------------------------------------------------------------------------
32 // wxGDIImageRefData: common data fields for all derived classes
33 // ----------------------------------------------------------------------------
35 class WXDLLEXPORT wxGDIImageRefData
: public wxGDIRefData
40 m_nWidth
= m_nHeight
= m_nDepth
= 0;
56 { m_nWidth
= nW
; m_nHeight
= nH
; }
58 // free the ressources we allocated
59 virtual void Free() { };
61 // for compatibility, the member fields are public
63 // the size of the image
67 // the depth of the image
73 WXHANDLE m_hHandle
; // for untyped access
82 // ----------------------------------------------------------------------------
83 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
84 // ----------------------------------------------------------------------------
86 class WXDLLEXPORT wxGDIImageHandler
: public wxObject
90 wxGDIImageHandler() { m_lType
= wxBITMAP_TYPE_INVALID
; }
91 wxGDIImageHandler( const wxString
& rName
102 void SetName(const wxString
& rName
) { m_sName
= rName
; }
103 void SetExtension(const wxString
& rExt
) { m_sExtension
= rExt
; }
104 void SetType(long lType
) { m_lType
= lType
; }
106 wxString
GetName() const { return m_sName
; }
107 wxString
GetExtension() const { return m_sExtension
; }
108 long GetType() const { return m_lType
; }
110 // real handler operations: to implement in derived classes
111 virtual bool Create( wxGDIImage
* pImage
118 virtual bool Load( wxGDIImage
* pImage
119 ,const wxString
& rName
125 virtual bool Load( wxGDIImage
* pImage
131 virtual bool Save( wxGDIImage
* pImage
132 ,const wxString
& rName
138 wxString m_sExtension
;
140 }; // end of wxGDIImageHandler
142 // ----------------------------------------------------------------------------
143 // wxGDIImage: this class supports GDI image handlers which may be registered
144 // dynamically and will be used for loading/saving the images in the specified
145 // format. It also falls back to wxImage if no appropriate image is found.
146 // ----------------------------------------------------------------------------
148 class WXDLLEXPORT wxGDIImage
: public wxGDIObject
151 // handlers list interface
152 static wxList
& GetHandlers() { return ms_handlers
; }
154 static void AddHandler(wxGDIImageHandler
* hHandler
);
155 static void InsertHandler(wxGDIImageHandler
* hHandler
);
156 static bool RemoveHandler(const wxString
& rName
);
158 static wxGDIImageHandler
* FindHandler(const wxString
& rName
);
159 static wxGDIImageHandler
* FindHandler(const wxString
& rExtension
, long lType
);
160 static wxGDIImageHandler
* FindHandler(long lType
);
162 static void InitStandardHandlers();
163 static void CleanUpHandlers();
165 // access to the ref data casted to the right type
166 wxGDIImageRefData
*GetGDIImageData() const
167 { return (wxGDIImageRefData
*)m_refData
; }
169 // create data if we don't have it yet
170 void EnsureHasData() { if ( IsNull() ) m_refData
= CreateData(); }
173 WXHANDLE
GetHandle() const
175 wxGDIImageRefData
* pData
;
177 pData
= GetGDIImageData();
181 return pData
->m_hHandle
;
183 void SetHandle(WXHANDLE hHandle
)
185 wxGDIImageRefData
* pData
;
188 pData
= GetGDIImageData();
189 pData
->m_hHandle
= hHandle
;
192 bool Ok() const { return GetHandle() != 0; }
194 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_nWidth
; }
195 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_nHeight
; }
196 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_nDepth
; }
198 void SetWidth(int nW
) { EnsureHasData(); GetGDIImageData()->m_nWidth
= nW
; }
199 void SetHeight(int nH
) { EnsureHasData(); GetGDIImageData()->m_nHeight
= nH
; }
200 void SetDepth(int nD
) { EnsureHasData(); GetGDIImageData()->m_nDepth
= nD
; }
207 GetGDIImageData()->SetSize(nW
, nH
);
209 void SetSize(const wxSize
& rSize
) { SetSize(rSize
.x
, rSize
.y
); }
211 UINT
GetId(void) const
213 wxGDIImageRefData
* pData
;
215 pData
= GetGDIImageData();
220 } // end of WxWinGdi_CGDIImage::GetId
223 wxGDIImageRefData
* pData
;
226 pData
= GetGDIImageData();
229 // forward some of base class virtuals to wxGDIImageRefData
230 bool FreeResource(bool bForce
= FALSE
);
231 virtual WXHANDLE
GetResourceHandle();
234 // create the data for the derived class here
235 virtual wxGDIImageRefData
* CreateData() const = 0;
237 static wxList ms_handlers
;
240 #endif // _WX_MSW_GDIIMAGE_H_