1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/gdiimage.cpp
3 // Purpose: wxGDIImage implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
25 #include "wx/string.h"
29 #include "wx/os2/private.h"
30 #include "wx/os2/gdiimage.h"
32 #include "wx/listimpl.cpp"
33 WX_DEFINE_LIST(wxGDIImageHandlerList
)
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // all image handlers are declared/defined in this file because the outside
40 // world doesn't have to know about them (but only about wxBITMAP_TYPE_XXX ids)
42 class WXDLLEXPORT wxBMPFileHandler
: public wxBitmapHandler
45 wxBMPFileHandler() : wxBitmapHandler(_T("Windows bitmap file"), _T("bmp"),
50 virtual bool LoadFile( wxBitmap
* pBitmap
51 ,const wxString
& rName
57 virtual bool SaveFile( wxBitmap
* pBitmap
58 ,const wxString
& rName
60 ,const wxPalette
* pPalette
= NULL
64 inline virtual bool LoadFile( wxBitmap
* pBitmap
71 return wxBitmapHandler::LoadFile( pBitmap
78 DECLARE_DYNAMIC_CLASS(wxBMPFileHandler
)
81 class WXDLLEXPORT wxBMPResourceHandler
: public wxBitmapHandler
84 wxBMPResourceHandler() : wxBitmapHandler(_T("Windows bitmap resource"),
86 wxBITMAP_TYPE_BMP_RESOURCE
)
90 virtual bool LoadFile( wxBitmap
* pBitmap
98 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler
)
101 class WXDLLEXPORT wxIconHandler
: public wxGDIImageHandler
104 wxIconHandler( const wxString
& rName
105 ,const wxString
& rExt
107 ) : wxGDIImageHandler( rName
114 // creating and saving icons is not supported
115 virtual bool Create( wxGDIImage
* WXUNUSED(pImage
)
116 ,const void* WXUNUSED(pData
)
117 ,long WXUNUSED(lFlags
)
118 ,int WXUNUSED(nWidth
)
119 ,int WXUNUSED(nHeight
)
120 ,int WXUNUSED(nDepth
) = 1
126 virtual bool Save( wxGDIImage
* WXUNUSED(pImage
)
127 ,const wxString
& WXUNUSED(rName
)
133 virtual bool Load( wxGDIImage
* pImage
134 ,const wxString
& rName
141 wxIcon
* pIcon
= wxDynamicCast(pImage
, wxIcon
);
142 wxCHECK_MSG(pIcon
, false, _T("wxIconHandler only works with icons"));
144 return LoadIcon( pIcon
154 virtual bool LoadIcon( wxIcon
* pIcon
155 ,const wxString
& rName
158 ,int nDesiredWidth
= -1
159 ,int nDesiredHeight
= -1
162 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
),
164 long WXUNUSED(lFlags
),
165 int WXUNUSED(nDesiredWidth
),
166 int WXUNUSED(nDesiredHeight
) )
172 class WXDLLEXPORT wxICOFileHandler
: public wxIconHandler
175 wxICOFileHandler() : wxIconHandler(_T("ICO icon file"),
181 virtual bool LoadIcon( wxIcon
* pIcon
182 ,const wxString
& rName
185 ,int nDesiredWidth
= -1
186 ,int nDesiredHeight
= -1
190 DECLARE_DYNAMIC_CLASS(wxICOFileHandler
)
193 class WXDLLEXPORT wxICOResourceHandler
: public wxIconHandler
196 wxICOResourceHandler() : wxIconHandler(_T("ICO resource"),
198 wxBITMAP_TYPE_ICO_RESOURCE
)
202 virtual bool LoadIcon( wxIcon
* pIcon
203 ,const wxString
& rName
206 ,int nDesiredWidth
= -1
207 ,int nDesiredHeight
= -1
211 DECLARE_DYNAMIC_CLASS(wxICOResourceHandler
)
214 // ----------------------------------------------------------------------------
216 // ----------------------------------------------------------------------------
218 IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler
, wxBitmapHandler
)
219 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler
, wxBitmapHandler
)
220 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler
, wxObject
)
221 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler
, wxObject
)
223 // ============================================================================
225 // ============================================================================
227 wxGDIImageHandlerList
wxGDIImage::ms_handlers
;
229 // ----------------------------------------------------------------------------
230 // wxGDIImage functions forwarded to wxGDIImageRefData
231 // ----------------------------------------------------------------------------
233 bool wxGDIImage::FreeResource( bool WXUNUSED(bForce
) )
237 GetGDIImageData()->Free();
238 GetGDIImageData()->m_hHandle
= 0;
244 WXHANDLE
wxGDIImage::GetResourceHandle() const
249 // ----------------------------------------------------------------------------
250 // wxGDIImage handler stuff
251 // ----------------------------------------------------------------------------
253 void wxGDIImage::AddHandler( wxGDIImageHandler
* pHandler
)
255 ms_handlers
.Append(pHandler
);
258 void wxGDIImage::InsertHandler( wxGDIImageHandler
* pHandler
)
260 ms_handlers
.Insert(pHandler
);
263 bool wxGDIImage::RemoveHandler( const wxString
& rName
)
265 wxGDIImageHandler
* pHandler
= FindHandler(rName
);
269 ms_handlers
.DeleteObject(pHandler
);
276 wxGDIImageHandler
* wxGDIImage::FindHandler(
277 const wxString
& rName
280 wxGDIImageHandlerList::compatibility_iterator pNode
= ms_handlers
.GetFirst();
284 wxGDIImageHandler
* pHandler
= pNode
->GetData();
286 if ( pHandler
->GetName() == rName
)
288 pNode
= pNode
->GetNext();
290 return((wxGDIImageHandler
*)NULL
);
293 wxGDIImageHandler
* wxGDIImage::FindHandler(
294 const wxString
& rExtension
298 wxGDIImageHandlerList::compatibility_iterator pNode
= ms_handlers
.GetFirst();
301 wxGDIImageHandler
* pHandler
= pNode
->GetData();
303 if ( (pHandler
->GetExtension() == rExtension
) &&
304 (lType
== -1 || pHandler
->GetType() == lType
) )
308 pNode
= pNode
->GetNext();
310 return((wxGDIImageHandler
*)NULL
);
313 wxGDIImageHandler
* wxGDIImage::FindHandler(
317 wxGDIImageHandlerList::compatibility_iterator pNode
= ms_handlers
.GetFirst();
321 wxGDIImageHandler
* pHandler
= pNode
->GetData();
323 if ( pHandler
->GetType() == lType
)
325 pNode
= pNode
->GetNext();
327 return((wxGDIImageHandler
*)NULL
);
330 void wxGDIImage::CleanUpHandlers()
332 wxGDIImageHandlerList::compatibility_iterator pNode
= ms_handlers
.GetFirst();
336 wxGDIImageHandler
* pHandler
= pNode
->GetData();
337 wxGDIImageHandlerList::compatibility_iterator pNext
= pNode
->GetNext();
340 ms_handlers
.Erase( pNode
);
345 void wxGDIImage::InitStandardHandlers()
347 AddHandler(new wxBMPResourceHandler
);
348 AddHandler(new wxBMPFileHandler
);
349 AddHandler(new wxICOResourceHandler
);
350 AddHandler(new wxICOFileHandler
);
353 // ----------------------------------------------------------------------------
355 // ----------------------------------------------------------------------------
357 bool wxBMPResourceHandler::LoadFile( wxBitmap
* pBitmap
,
359 long WXUNUSED(lFlags
),
360 int WXUNUSED(nDesiredWidth
),
361 int WXUNUSED(nDesiredHeight
) )
363 SIZEL vSize
= {0, 0};
364 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
365 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
366 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
368 pBitmap
->SetHBITMAP((WXHBITMAP
)::GpiLoadBitmap( hPS
377 wxBitmapRefData
* pData
= pBitmap
->GetBitmapData();
381 BITMAPINFOHEADER vBmph
;
383 ::GpiQueryBitmapParameters(GetHbitmapOf(*pBitmap
), &vBmph
);
384 pData
->m_nWidth
= vBmph
.cx
;
385 pData
->m_nHeight
= vBmph
.cy
;
386 pData
->m_nDepth
= vBmph
.cBitCount
;
388 return(pBitmap
->Ok());
389 } // end of wxBMPResourceHandler::LoadFile
391 bool wxBMPFileHandler::LoadFile( wxBitmap
* pBitmap
,
392 const wxString
& WXUNUSED(rName
),
394 long WXUNUSED(lFlags
),
395 int WXUNUSED(nDesiredWidth
),
396 int WXUNUSED(nDesiredHeight
) )
398 #if defined(wxUSE_IMAGE_LOADING_IN_OS2) && wxUSE_IMAGE_LOADING_IN_OS2
399 wxPalette
* pPalette
= NULL
;
401 bool bSuccess
= false; /* wxLoadIntoBitmap( WXSTRINGCAST rName
405 if (bSuccess
&& pPalette
)
407 pBitmap
->SetPalette(*pPalette
);
410 // it was copied by the bitmap if it was loaded successfully
415 wxUnusedVar(pBitmap
);
420 bool wxBMPFileHandler::SaveFile( wxBitmap
* pBitmap
,
421 const wxString
& WXUNUSED(rName
),
423 const wxPalette
* pPal
)
425 #if defined(wxUSE_IMAGE_LOADING_IN_OS2) && wxUSE_IMAGE_LOADING_IN_OS2
426 wxPalette
* pActualPalette
= (wxPalette
*)pPal
;
429 pActualPalette
= pBitmap
->GetPalette();
430 /* return(wxSaveBitmap( WXSTRINGCAST rName
436 wxUnusedVar(pBitmap
);
442 // ----------------------------------------------------------------------------
444 // ----------------------------------------------------------------------------
446 bool wxICOFileHandler::LoadIcon( wxIcon
* pIcon
,
447 const wxString
& WXUNUSED(rName
),
449 long WXUNUSED(lFlags
),
450 int WXUNUSED(nDesiredWidth
),
451 int WXUNUSED(nDesiredHeight
) )
453 #if defined(wxUSE_RESOURCE_LOADING_IN_OS2) && wxUSE_RESOURCE_LOADING_IN_OS2
463 bool wxICOResourceHandler::LoadIcon( wxIcon
* pIcon
,
464 const wxString
& rName
,
466 long WXUNUSED(lFlags
),
467 int WXUNUSED(nDesiredWidth
),
468 int WXUNUSED(nDesiredHeight
) )
472 hIcon
= ::WinLoadFileIcon( rName
.c_str()
473 ,TRUE
// load for private use
476 pIcon
->SetSize(32, 32); // all OS/2 icons are 32 x 32
478 pIcon
->SetHICON((WXHICON
)hIcon
);
481 } // end of wxICOResourceHandler::LoadIcon