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;
44 #if WXWIN_COMPATIBILITY_2
46 #endif // WXWIN_COMPATIBILITY_2
60 { m_nWidth
= nW
; m_nHeight
= nH
; }
62 // free the ressources we allocated
63 virtual void Free() { };
65 // for compatibility, the member fields are public
67 // the size of the image
71 // the depth of the image
77 WXHANDLE m_hHandle
; // for untyped access
83 // this filed is redundant and using it is error prone but keep it for
84 // backwards compatibility
85 #if WXWIN_COMPATIBILITY_2
86 void SetOk() { m_bOk
= m_hHandle
!= 0; }
89 #endif // WXWIN_COMPATIBILITY_2
93 // ----------------------------------------------------------------------------
94 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
95 // ----------------------------------------------------------------------------
97 class WXDLLEXPORT wxGDIImageHandler
: public wxObject
101 wxGDIImageHandler() { m_lType
= wxBITMAP_TYPE_INVALID
; }
102 wxGDIImageHandler( const wxString
& rName
103 ,const wxString
& rExt
113 void SetName(const wxString
& rName
) { m_sName
= rName
; }
114 void SetExtension(const wxString
& rExt
) { m_sExtension
= rExt
; }
115 void SetType(long lType
) { m_lType
= lType
; }
117 wxString
GetName() const { return m_sName
; }
118 wxString
GetExtension() const { return m_sExtension
; }
119 long GetType() const { return m_lType
; }
121 // real handler operations: to implement in derived classes
122 virtual bool Create( wxGDIImage
* pImage
129 virtual bool Load( wxGDIImage
* pImage
130 ,const wxString
& rName
136 virtual bool Load( wxGDIImage
* pImage
142 virtual bool Save( wxGDIImage
* pImage
143 ,const wxString
& rName
149 wxString m_sExtension
;
151 }; // end of wxGDIImageHandler
153 // ----------------------------------------------------------------------------
154 // wxGDIImage: this class supports GDI image handlers which may be registered
155 // dynamically and will be used for loading/saving the images in the specified
156 // format. It also falls back to wxImage if no appropriate image is found.
157 // ----------------------------------------------------------------------------
159 class WXDLLEXPORT wxGDIImage
: public wxGDIObject
162 // handlers list interface
163 static wxList
& GetHandlers() { return ms_handlers
; }
165 static void AddHandler(wxGDIImageHandler
* hHandler
);
166 static void InsertHandler(wxGDIImageHandler
* hHandler
);
167 static bool RemoveHandler(const wxString
& rName
);
169 static wxGDIImageHandler
* FindHandler(const wxString
& rName
);
170 static wxGDIImageHandler
* FindHandler(const wxString
& rExtension
, long lType
);
171 static wxGDIImageHandler
* FindHandler(long lType
);
173 static void InitStandardHandlers();
174 static void CleanUpHandlers();
176 // access to the ref data casted to the right type
177 wxGDIImageRefData
*GetGDIImageData() const
178 { return (wxGDIImageRefData
*)m_refData
; }
180 // create data if we don't have it yet
181 void EnsureHasData() { if ( IsNull() ) m_refData
= CreateData(); }
184 WXHANDLE
GetHandle() const
186 wxGDIImageRefData
* pData
;
188 pData
= GetGDIImageData();
192 return pData
->m_hHandle
;
194 void SetHandle(WXHANDLE hHandle
)
196 wxGDIImageRefData
* pData
;
199 pData
= GetGDIImageData();
200 pData
->m_hHandle
= hHandle
;
203 bool Ok() const { return GetHandle() != 0; }
205 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_nWidth
; }
206 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_nHeight
; }
207 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_nDepth
; }
209 void SetWidth(int nW
) { EnsureHasData(); GetGDIImageData()->m_nWidth
= nW
; }
210 void SetHeight(int nH
) { EnsureHasData(); GetGDIImageData()->m_nHeight
= nH
; }
211 void SetDepth(int nD
) { EnsureHasData(); GetGDIImageData()->m_nDepth
= nD
; }
218 GetGDIImageData()->SetSize(nW
, nH
);
220 void SetSize(const wxSize
& rSize
) { SetSize(rSize
.x
, rSize
.y
); }
222 UINT
GetId(void) const
224 wxGDIImageRefData
* pData
;
226 pData
= GetGDIImageData();
231 } // end of WxWinGdi_CGDIImage::GetId
234 wxGDIImageRefData
* pData
;
237 pData
= GetGDIImageData();
240 // forward some of base class virtuals to wxGDIImageRefData
241 bool FreeResource(bool bForce
= FALSE
);
242 virtual WXHANDLE
GetResourceHandle();
245 // create the data for the derived class here
246 virtual wxGDIImageRefData
* CreateData() const = 0;
248 static wxList ms_handlers
;
251 #endif // _WX_MSW_GDIIMAGE_H_