1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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_
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_nWidth
= m_nHeight
= m_nDepth
= 0;
44 virtual bool IsOk() const
54 { m_nWidth
= nW
; m_nHeight
= nH
; }
56 // free the ressources we allocated
57 virtual void Free() { };
59 // for compatibility, the member fields are public
61 // the size of the image
65 // the depth of the image
71 WXHANDLE m_hHandle
; // for untyped access
80 // ----------------------------------------------------------------------------
81 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
82 // ----------------------------------------------------------------------------
84 class WXDLLIMPEXP_CORE wxGDIImageHandler
: public wxObject
88 wxGDIImageHandler() { m_lType
= wxBITMAP_TYPE_INVALID
; }
89 wxGDIImageHandler( const wxString
& rName
100 void SetName(const wxString
& rName
) { m_sName
= rName
; }
101 void SetExtension(const wxString
& rExt
) { m_sExtension
= rExt
; }
102 void SetType(wxBitmapType lType
) { m_lType
= lType
; }
104 wxString
GetName() const { return m_sName
; }
105 wxString
GetExtension() const { return m_sExtension
; }
106 wxBitmapType
GetType() const { return m_lType
; }
108 // real handler operations: to implement in derived classes
109 virtual bool Create( wxGDIImage
* pImage
116 virtual bool Load( wxGDIImage
* pImage
117 ,const wxString
& rName
123 virtual bool Load( wxGDIImage
* pImage
129 virtual bool Save( const wxGDIImage
* pImage
130 ,const wxString
& rName
136 wxString m_sExtension
;
137 wxBitmapType m_lType
;
138 }; // end of wxGDIImageHandler
140 // ----------------------------------------------------------------------------
141 // wxGDIImage: this class supports GDI image handlers which may be registered
142 // dynamically and will be used for loading/saving the images in the specified
143 // format. It also falls back to wxImage if no appropriate image is found.
144 // ----------------------------------------------------------------------------
146 class WXDLLIMPEXP_CORE wxGDIImage
: public wxGDIObject
149 // handlers list interface
150 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
152 static void AddHandler(wxGDIImageHandler
* hHandler
);
153 static void InsertHandler(wxGDIImageHandler
* hHandler
);
154 static bool RemoveHandler(const wxString
& rName
);
156 static wxGDIImageHandler
* FindHandler(const wxString
& rName
);
157 static wxGDIImageHandler
* FindHandler(const wxString
& rExtension
, wxBitmapType lType
);
158 static wxGDIImageHandler
* FindHandler(wxBitmapType lType
);
160 static void InitStandardHandlers();
161 static void CleanUpHandlers();
163 // access to the ref data casted to the right type
164 wxGDIImageRefData
*GetGDIImageData() const
165 { return (wxGDIImageRefData
*)m_refData
; }
167 // create data if we don't have it yet
168 void EnsureHasData() { if ( IsNull() ) m_refData
= CreateData(); }
171 WXHANDLE
GetHandle() const
173 wxGDIImageRefData
* pData
;
175 pData
= GetGDIImageData();
179 return pData
->m_hHandle
;
181 void SetHandle(WXHANDLE hHandle
)
183 wxGDIImageRefData
* pData
;
186 pData
= GetGDIImageData();
187 pData
->m_hHandle
= hHandle
;
190 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_nWidth
; }
191 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_nHeight
; }
192 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_nDepth
; }
194 wxSize
GetSize() const
196 return IsNull() ? wxSize(0,0) :
197 wxSize(GetGDIImageData()->m_nWidth
, GetGDIImageData()->m_nHeight
);
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 unsigned int GetId(void) const
215 wxGDIImageRefData
* pData
;
217 pData
= GetGDIImageData();
222 } // end of WxWinGdi_CGDIImage::GetId
223 void SetId(unsigned int uId
)
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() const;
236 // create the data for the derived class here
237 virtual wxGDIImageRefData
* CreateData() const = 0;
238 virtual wxGDIRefData
*CreateGDIRefData() const { return CreateData(); }
240 // we can't [efficiently] clone objects of this class
241 virtual wxGDIRefData
*
242 CloneGDIRefData(const wxGDIRefData
*WXUNUSED(data
)) const
244 wxFAIL_MSG( wxT("must be implemented if used") );
249 static wxGDIImageHandlerList ms_handlers
;
252 #endif // _WX_MSW_GDIIMAGE_H_