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)
8 // Copyright: (c) 1999 David Webster
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // NB: this is a private header, it is not intended to be directly included by
13 // user code (but may be included from other, public, wxWin headers
15 #ifndef _WX_OS2_GDIIMAGE_H_
16 #define _WX_OS2_GDIIMAGE_H_
18 #include "wx/gdiobj.h" // base class
19 #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
22 class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData
;
23 class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler
;
24 class WXDLLIMPEXP_FWD_CORE wxGDIImage
;
26 WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler
, wxGDIImageHandlerList
);
28 // ----------------------------------------------------------------------------
29 // wxGDIImageRefData: common data fields for all derived classes
30 // ----------------------------------------------------------------------------
32 class WXDLLIMPEXP_CORE wxGDIImageRefData
: public wxGDIRefData
37 m_nWidth
= m_nHeight
= m_nDepth
= 0;
43 virtual bool IsOk() const
53 { m_nWidth
= nW
; m_nHeight
= nH
; }
55 // free the ressources we allocated
56 virtual void Free() { }
58 // for compatibility, the member fields are public
60 // the size of the image
64 // the depth of the image
70 WXHANDLE m_hHandle
; // for untyped access
79 // ----------------------------------------------------------------------------
80 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
81 // ----------------------------------------------------------------------------
83 class WXDLLIMPEXP_CORE wxGDIImageHandler
: public wxObject
87 wxGDIImageHandler() { m_lType
= wxBITMAP_TYPE_INVALID
; }
88 wxGDIImageHandler( const wxString
& rName
99 void SetName(const wxString
& rName
) { m_sName
= rName
; }
100 void SetExtension(const wxString
& rExt
) { m_sExtension
= rExt
; }
101 void SetType(wxBitmapType lType
) { m_lType
= lType
; }
103 wxString
GetName() const { return m_sName
; }
104 wxString
GetExtension() const { return m_sExtension
; }
105 wxBitmapType
GetType() const { return m_lType
; }
107 // real handler operations: to implement in derived classes
108 virtual bool Create( wxGDIImage
* pImage
115 virtual bool Load( wxGDIImage
* pImage
116 ,const wxString
& rName
122 virtual bool Load( wxGDIImage
* pImage
128 virtual bool Save( const wxGDIImage
* pImage
129 ,const wxString
& rName
135 wxString m_sExtension
;
136 wxBitmapType m_lType
;
137 }; // end of wxGDIImageHandler
139 // ----------------------------------------------------------------------------
140 // wxGDIImage: this class supports GDI image handlers which may be registered
141 // dynamically and will be used for loading/saving the images in the specified
142 // format. It also falls back to wxImage if no appropriate image is found.
143 // ----------------------------------------------------------------------------
145 class WXDLLIMPEXP_CORE wxGDIImage
: public wxGDIObject
148 // handlers list interface
149 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
151 static void AddHandler(wxGDIImageHandler
* hHandler
);
152 static void InsertHandler(wxGDIImageHandler
* hHandler
);
153 static bool RemoveHandler(const wxString
& rName
);
155 static wxGDIImageHandler
* FindHandler(const wxString
& rName
);
156 static wxGDIImageHandler
* FindHandler(const wxString
& rExtension
, wxBitmapType lType
);
157 static wxGDIImageHandler
* FindHandler(wxBitmapType lType
);
159 static void InitStandardHandlers();
160 static void CleanUpHandlers();
162 // access to the ref data casted to the right type
163 wxGDIImageRefData
*GetGDIImageData() const
164 { return (wxGDIImageRefData
*)m_refData
; }
166 // create data if we don't have it yet
167 void EnsureHasData() { if ( IsNull() ) m_refData
= CreateData(); }
170 WXHANDLE
GetHandle() const
172 wxGDIImageRefData
* pData
;
174 pData
= GetGDIImageData();
178 return pData
->m_hHandle
;
180 void SetHandle(WXHANDLE hHandle
)
182 wxGDIImageRefData
* pData
;
185 pData
= GetGDIImageData();
186 pData
->m_hHandle
= hHandle
;
189 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_nWidth
; }
190 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_nHeight
; }
191 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_nDepth
; }
193 wxSize
GetSize() const
195 return IsNull() ? wxSize(0,0) :
196 wxSize(GetGDIImageData()->m_nWidth
, GetGDIImageData()->m_nHeight
);
199 void SetWidth(int nW
) { EnsureHasData(); GetGDIImageData()->m_nWidth
= nW
; }
200 void SetHeight(int nH
) { EnsureHasData(); GetGDIImageData()->m_nHeight
= nH
; }
201 void SetDepth(int nD
) { EnsureHasData(); GetGDIImageData()->m_nDepth
= nD
; }
208 GetGDIImageData()->SetSize(nW
, nH
);
210 void SetSize(const wxSize
& rSize
) { SetSize(rSize
.x
, rSize
.y
); }
212 unsigned int GetId(void) const
214 wxGDIImageRefData
* pData
;
216 pData
= GetGDIImageData();
221 } // end of WxWinGdi_CGDIImage::GetId
222 void SetId(unsigned int uId
)
224 wxGDIImageRefData
* pData
;
227 pData
= GetGDIImageData();
230 // forward some of base class virtuals to wxGDIImageRefData
231 bool FreeResource(bool bForce
= false);
232 virtual WXHANDLE
GetResourceHandle() const;
235 // create the data for the derived class here
236 virtual wxGDIImageRefData
* CreateData() const = 0;
237 virtual wxGDIRefData
*CreateGDIRefData() const { return CreateData(); }
239 // we can't [efficiently] clone objects of this class
240 virtual wxGDIRefData
*
241 CloneGDIRefData(const wxGDIRefData
*WXUNUSED(data
)) const
243 wxFAIL_MSG( wxT("must be implemented if used") );
248 static wxGDIImageHandlerList ms_handlers
;
251 #endif // _WX_MSW_GDIIMAGE_H_