1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/gdiimage.cpp
3 // Purpose: wxGDIImage implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "gdiimage.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
29 #include "wx/string.h"
32 #include "wx/os2/private.h"
34 #include "wx/os2/gdiimage.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 // all image handlers are declared/defined in this file because the outside
41 // world doesn't have to know about them (but only about wxBITMAP_TYPE_XXX ids)
43 class WXDLLEXPORT wxBMPFileHandler
: public wxBitmapHandler
46 wxBMPFileHandler() : wxBitmapHandler(_T("Windows bitmap file"), _T("bmp"),
51 virtual bool LoadFile( wxBitmap
* pBitmap
52 ,const wxString
& rName
58 virtual bool SaveFile( wxBitmap
* pBitmap
59 ,const wxString
& rName
61 ,const wxPalette
* pPalette
= NULL
65 inline virtual bool LoadFile( wxBitmap
* pBitmap
72 return wxBitmapHandler::LoadFile( pBitmap
79 DECLARE_DYNAMIC_CLASS(wxBMPFileHandler
)
82 class WXDLLEXPORT wxBMPResourceHandler
: public wxBitmapHandler
85 wxBMPResourceHandler() : wxBitmapHandler(_T("Windows bitmap resource"),
87 wxBITMAP_TYPE_BMP_RESOURCE
)
91 virtual bool LoadFile( wxBitmap
* pBitmap
99 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler
)
102 class WXDLLEXPORT wxIconHandler
: public wxGDIImageHandler
105 wxIconHandler( const wxString
& rName
106 ,const wxString
& rExt
108 ) : wxGDIImageHandler( rName
115 // creating and saving icons is not supported
116 virtual bool Create( wxGDIImage
* WXUNUSED(pImage
)
117 ,void* WXUNUSED(pData
)
118 ,long WXUNUSED(lFlags
)
119 ,int WXUNUSED(nWidth
)
120 ,int WXUNUSED(nHeight
)
121 ,int WXUNUSED(nDepth
) = 1
127 virtual bool Save( wxGDIImage
* WXUNUSED(pImage
)
128 ,const wxString
& WXUNUSED(rName
)
134 virtual bool Load( wxGDIImage
* pImage
135 ,const wxString
& rName
142 wxIcon
* pIcon
= wxDynamicCast(pImage
, wxIcon
);
143 wxCHECK_MSG(pIcon
, FALSE
, _T("wxIconHandler only works with icons"));
145 return LoadIcon( pIcon
155 virtual bool LoadIcon( wxIcon
* pIcon
156 ,const wxString
& rName
159 ,int nDesiredWidth
= -1
160 ,int nDesiredHeight
= -1
163 inline virtual bool Load( wxGDIImage
* pImage
174 class WXDLLEXPORT wxICOFileHandler
: public wxIconHandler
177 wxICOFileHandler() : wxIconHandler(_T("ICO icon file"),
183 virtual bool LoadIcon( wxIcon
* pIcon
184 ,const wxString
& rName
187 ,int nDesiredWidth
= -1
188 ,int nDesiredHeight
= -1
192 DECLARE_DYNAMIC_CLASS(wxICOFileHandler
)
195 class WXDLLEXPORT wxICOResourceHandler
: public wxIconHandler
198 wxICOResourceHandler() : wxIconHandler(_T("ICO resource"),
200 wxBITMAP_TYPE_ICO_RESOURCE
)
204 virtual bool LoadIcon( wxIcon
* pIcon
205 ,const wxString
& rName
208 ,int nDesiredWidth
= -1
209 ,int nDesiredHeight
= -1
213 DECLARE_DYNAMIC_CLASS(wxICOResourceHandler
)
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 #if !USE_SHARED_LIBRARIES
221 IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler
, wxBitmapHandler
)
222 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler
, wxBitmapHandler
)
223 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler
, wxObject
)
224 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler
, wxObject
)
227 // ----------------------------------------------------------------------------
229 // ----------------------------------------------------------------------------
231 static wxSize
GetHiconSize(WXHICON hicon
);
233 // ============================================================================
235 // ============================================================================
237 wxList
wxGDIImage::ms_handlers
;
239 // ----------------------------------------------------------------------------
240 // wxGDIImage functions forwarded to wxGDIImageRefData
241 // ----------------------------------------------------------------------------
243 bool wxGDIImage::FreeResource(
244 bool WXUNUSED(bForce
)
249 GetGDIImageData()->Free();
250 GetGDIImageData()->m_hHandle
= 0;
256 WXHANDLE
wxGDIImage::GetResourceHandle()
261 // ----------------------------------------------------------------------------
262 // wxGDIImage handler stuff
263 // ----------------------------------------------------------------------------
265 void wxGDIImage::AddHandler(
266 wxGDIImageHandler
* pHandler
269 ms_handlers
.Append(pHandler
);
272 void wxGDIImage::InsertHandler(
273 wxGDIImageHandler
* pHandler
276 ms_handlers
.Insert(pHandler
);
279 bool wxGDIImage::RemoveHandler(
280 const wxString
& rName
283 wxGDIImageHandler
* pHandler
= FindHandler(rName
);
287 ms_handlers
.DeleteObject(pHandler
);
294 wxGDIImageHandler
* wxGDIImage::FindHandler(
295 const wxString
& rName
298 wxNode
* pNode
= ms_handlers
.First();
302 wxGDIImageHandler
* pHandler
= (wxGDIImageHandler
*)pNode
->Data();
304 if (pHandler
->GetName() == rName
)
306 pNode
= pNode
->Next();
311 wxGDIImageHandler
* wxGDIImage::FindHandler(
312 const wxString
& rExtension
316 wxNode
* pNode
= ms_handlers
.First();
320 wxGDIImageHandler
* pHandler
= (wxGDIImageHandler
*)pNode
->Data();
322 if ((pHandler
->GetExtension() = rExtension
) &&
323 (lType
== -1 || pHandler
->GetType() == lType
))
327 pNode
= pNode
->Next();
332 wxGDIImageHandler
* wxGDIImage::FindHandler(
336 wxNode
* pNode
= ms_handlers
.First();
340 wxGDIImageHandler
* pHandler
= (wxGDIImageHandler
*)pNode
->Data();
342 if (pHandler
->GetType() == lType
)
344 pNode
= pNode
->Next();
349 void wxGDIImage::CleanUpHandlers()
351 wxNode
* pNode
= ms_handlers
.First();
355 wxGDIImageHandler
* pHandler
= (wxGDIImageHandler
*)pNode
->Data();
356 wxNode
* pNext
= pNode
->Next();
359 #if (!(defined(__VISAGECPP__) && (__IBMCPP__ < 400 || __IBMC__ < 400 )))
366 void wxGDIImage::InitStandardHandlers()
368 AddHandler(new wxBMPResourceHandler
);
369 AddHandler(new wxBMPFileHandler
);
370 AddHandler(new wxICOResourceHandler
);
371 AddHandler(new wxICOFileHandler
);
374 // ----------------------------------------------------------------------------
376 // ----------------------------------------------------------------------------
378 bool wxBMPResourceHandler::LoadFile(
386 SIZEL vSize
= {0, 0};
387 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
388 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
389 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
391 pBitmap
->SetHBITMAP((WXHBITMAP
)::GpiLoadBitmap( hPS
400 wxBitmapRefData
* pData
= pBitmap
->GetBitmapData();
404 BITMAPINFOHEADER vBmph
;
406 ::GpiQueryBitmapParameters(GetHbitmapOf(*pBitmap
), &vBmph
);
407 pData
->m_nWidth
= vBmph
.cx
;
408 pData
->m_nHeight
= vBmph
.cy
;
409 pData
->m_nDepth
= vBmph
.cBitCount
;
411 return(pBitmap
->Ok());
412 } // end of wxBMPResourceHandler::LoadFile
414 bool wxBMPFileHandler::LoadFile(
416 , const wxString
& rName
418 , long WXUNUSED(lFlags
)
419 , int WXUNUSED(nDesiredWidth
)
420 , int WXUNUSED(nDesiredHeight
)
423 #if wxUSE_IMAGE_LOADING_IN_OS2
424 wxPalette
* pPalette
= NULL
;
426 bool bSuccess
= FALSE
; /* wxLoadIntoBitmap( WXSTRINGCAST rName
430 if (bSuccess
&& pPalette
)
432 pBitmap
->SetPalette(*pPalette
);
435 // it was copied by the bitmap if it was loaded successfully
444 bool wxBMPFileHandler::SaveFile(
446 , const wxString
& rName
447 , int WXUNUSED(nType
)
448 , const wxPalette
* pPal
451 #if wxUSE_IMAGE_LOADING_IN_OS2
452 wxPalette
* pActualPalette
= (wxPalette
*)pPal
;
455 pActualPalette
= pBitmap
->GetPalette();
456 /* return(wxSaveBitmap( WXSTRINGCAST rName
466 // ----------------------------------------------------------------------------
468 // ----------------------------------------------------------------------------
470 bool wxICOFileHandler::LoadIcon(
472 , const wxString
& rName
479 #if wxUSE_RESOURCE_LOADING_IN_OS2
491 bool wxICOResourceHandler::LoadIcon(
493 , const wxString
& rName
496 , int WXUNUSED(nDesiredWidth
)
497 , int WXUNUSED(nDesiredHeight
)
502 hIcon
= ::WinLoadFileIcon( (PSZ
)rName
.c_str()
503 ,TRUE
// load for private use
506 pIcon
->SetSize(32, 32); // all OS/2 icons are 32 x 32
509 pIcon
->SetHICON((WXHICON
)hIcon
);
512 } // end of wxICOResourceHandler::LoadIcon
514 // ----------------------------------------------------------------------------
516 // ----------------------------------------------------------------------------
518 static wxSize
GetHiconSize(
522 wxSize
vSize(32, 32); // default
524 // all OS/2 icons are 32x32