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 licence
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 #include "wx/listimpl.cpp"
37 WX_DEFINE_LIST(wxGDIImageHandlerList
);
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // all image handlers are declared/defined in this file because the outside
44 // world doesn't have to know about them (but only about wxBITMAP_TYPE_XXX ids)
46 class WXDLLEXPORT wxBMPFileHandler
: public wxBitmapHandler
49 wxBMPFileHandler() : wxBitmapHandler(_T("Windows bitmap file"), _T("bmp"),
54 virtual bool LoadFile( wxBitmap
* pBitmap
55 ,const wxString
& rName
61 virtual bool SaveFile( wxBitmap
* pBitmap
62 ,const wxString
& rName
64 ,const wxPalette
* pPalette
= NULL
68 inline virtual bool LoadFile( wxBitmap
* pBitmap
75 return wxBitmapHandler
::LoadFile( pBitmap
82 DECLARE_DYNAMIC_CLASS(wxBMPFileHandler
)
85 class WXDLLEXPORT wxBMPResourceHandler
: public wxBitmapHandler
88 wxBMPResourceHandler() : wxBitmapHandler(_T("Windows bitmap resource"),
90 wxBITMAP_TYPE_BMP_RESOURCE
)
94 virtual bool LoadFile( wxBitmap
* pBitmap
102 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler
)
105 class WXDLLEXPORT wxIconHandler
: public wxGDIImageHandler
108 wxIconHandler( const wxString
& rName
109 ,const wxString
& rExt
111 ) : wxGDIImageHandler( rName
118 // creating and saving icons is not supported
119 virtual bool Create( wxGDIImage
* WXUNUSED(pImage
)
120 ,void* WXUNUSED(pData
)
121 ,long WXUNUSED(lFlags
)
122 ,int WXUNUSED(nWidth
)
123 ,int WXUNUSED(nHeight
)
124 ,int WXUNUSED(nDepth
) = 1
130 virtual bool Save( wxGDIImage
* WXUNUSED(pImage
)
131 ,const wxString
& WXUNUSED(rName
)
137 virtual bool Load( wxGDIImage
* pImage
138 ,const wxString
& rName
145 wxIcon
* pIcon
= wxDynamicCast(pImage
, wxIcon
);
146 wxCHECK_MSG(pIcon
, FALSE
, _T("wxIconHandler only works with icons"));
148 return LoadIcon( pIcon
158 virtual bool LoadIcon( wxIcon
* pIcon
159 ,const wxString
& rName
162 ,int nDesiredWidth
= -1
163 ,int nDesiredHeight
= -1
166 inline virtual bool Load( wxGDIImage
* pImage
177 class WXDLLEXPORT wxICOFileHandler
: public wxIconHandler
180 wxICOFileHandler() : wxIconHandler(_T("ICO icon file"),
186 virtual bool LoadIcon( wxIcon
* pIcon
187 ,const wxString
& rName
190 ,int nDesiredWidth
= -1
191 ,int nDesiredHeight
= -1
195 DECLARE_DYNAMIC_CLASS(wxICOFileHandler
)
198 class WXDLLEXPORT wxICOResourceHandler
: public wxIconHandler
201 wxICOResourceHandler() : wxIconHandler(_T("ICO resource"),
203 wxBITMAP_TYPE_ICO_RESOURCE
)
207 virtual bool LoadIcon( wxIcon
* pIcon
208 ,const wxString
& rName
211 ,int nDesiredWidth
= -1
212 ,int nDesiredHeight
= -1
216 DECLARE_DYNAMIC_CLASS(wxICOResourceHandler
)
219 // ----------------------------------------------------------------------------
221 // ----------------------------------------------------------------------------
223 #if !USE_SHARED_LIBRARIES
224 IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler
, wxBitmapHandler
)
225 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler
, wxBitmapHandler
)
226 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler
, wxObject
)
227 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler
, wxObject
)
230 // ----------------------------------------------------------------------------
232 // ----------------------------------------------------------------------------
234 static wxSize
GetHiconSize(WXHICON hicon
);
236 // ============================================================================
238 // ============================================================================
240 wxGDIImageHandlerList wxGDIImage
::ms_handlers
;
242 // ----------------------------------------------------------------------------
243 // wxGDIImage functions forwarded to wxGDIImageRefData
244 // ----------------------------------------------------------------------------
246 bool wxGDIImage
::FreeResource(
247 bool WXUNUSED(bForce
)
252 GetGDIImageData()->Free();
253 GetGDIImageData()->m_hHandle
= 0;
259 WXHANDLE wxGDIImage
::GetResourceHandle()
264 // ----------------------------------------------------------------------------
265 // wxGDIImage handler stuff
266 // ----------------------------------------------------------------------------
268 void wxGDIImage
::AddHandler(
269 wxGDIImageHandler
* pHandler
272 ms_handlers
.Append(pHandler
);
275 void wxGDIImage
::InsertHandler(
276 wxGDIImageHandler
* pHandler
279 ms_handlers
.Insert(pHandler
);
282 bool wxGDIImage
::RemoveHandler(
283 const wxString
& rName
286 wxGDIImageHandler
* pHandler
= FindHandler(rName
);
290 ms_handlers
.DeleteObject(pHandler
);
297 wxGDIImageHandler
* wxGDIImage
::FindHandler(
298 const wxString
& rName
301 wxNode
* pNode
= ms_handlers
.First();
305 wxGDIImageHandler
* pHandler
= (wxGDIImageHandler
*)pNode
->Data();
307 if (pHandler
->GetName() == rName
)
309 pNode
= pNode
->Next();
314 wxGDIImageHandler
* wxGDIImage
::FindHandler(
315 const wxString
& rExtension
319 wxNode
* pNode
= ms_handlers
.First();
323 wxGDIImageHandler
* pHandler
= (wxGDIImageHandler
*)pNode
->Data();
325 if ((pHandler
->GetExtension() = rExtension
) &&
326 (lType
== -1 || pHandler
->GetType() == lType
))
330 pNode
= pNode
->Next();
335 wxGDIImageHandler
* wxGDIImage
::FindHandler(
339 wxGDIImageHandlerList
::compatibility_iterator node
= ms_handlers
.GetFirst();
342 wxGDIImageHandler
*handler
= node
->GetData();
343 if ( handler
->GetType() == type
)
346 node
= node
->GetNext();
349 return((wxGDIImageHandler
*)NULL
);
352 void wxGDIImage
::CleanUpHandlers()
354 wxGDIImageHandlerList
::compatibility_iterator node
= ms_handlers
.GetFirst();
357 wxGDIImageHandler
*handler
= node
->GetData();
358 wxGDIImageHandlerList
::compatibility_iterator next
= node
->GetNext();
360 ms_handlers
.Erase( node
);
365 void wxGDIImage
::InitStandardHandlers()
367 AddHandler(new wxBMPResourceHandler
);
368 AddHandler(new wxBMPFileHandler
);
369 AddHandler(new wxICOResourceHandler
);
370 AddHandler(new wxICOFileHandler
);
373 // ----------------------------------------------------------------------------
375 // ----------------------------------------------------------------------------
377 bool wxBMPResourceHandler
::LoadFile(
385 SIZEL vSize
= {0, 0};
386 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
387 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
388 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
390 pBitmap
->SetHBITMAP((WXHBITMAP
)::GpiLoadBitmap( hPS
399 wxBitmapRefData
* pData
= pBitmap
->GetBitmapData();
403 BITMAPINFOHEADER vBmph
;
405 ::GpiQueryBitmapParameters(GetHbitmapOf(*pBitmap
), &vBmph
);
406 pData
->m_nWidth
= vBmph
.cx
;
407 pData
->m_nHeight
= vBmph
.cy
;
408 pData
->m_nDepth
= vBmph
.cBitCount
;
410 return(pBitmap
->Ok());
411 } // end of wxBMPResourceHandler::LoadFile
413 bool wxBMPFileHandler
::LoadFile(
415 , const wxString
& rName
417 , long WXUNUSED(lFlags
)
418 , int WXUNUSED(nDesiredWidth
)
419 , int WXUNUSED(nDesiredHeight
)
422 #if wxUSE_IMAGE_LOADING_IN_OS2
423 wxPalette
* pPalette
= NULL
;
425 bool bSuccess
= FALSE
; /* wxLoadIntoBitmap( WXSTRINGCAST rName
429 if (bSuccess
&& pPalette
)
431 pBitmap
->SetPalette(*pPalette
);
434 // it was copied by the bitmap if it was loaded successfully
443 bool wxBMPFileHandler
::SaveFile(
445 , const wxString
& rName
446 , int WXUNUSED(nType
)
447 , const wxPalette
* pPal
450 #if wxUSE_IMAGE_LOADING_IN_OS2
451 wxPalette
* pActualPalette
= (wxPalette
*)pPal
;
454 pActualPalette
= pBitmap
->GetPalette();
455 /* return(wxSaveBitmap( WXSTRINGCAST rName
465 // ----------------------------------------------------------------------------
467 // ----------------------------------------------------------------------------
469 bool wxICOFileHandler
::LoadIcon(
471 , const wxString
& rName
478 #if wxUSE_RESOURCE_LOADING_IN_OS2
490 bool wxICOResourceHandler
::LoadIcon(
492 , const wxString
& rName
495 , int WXUNUSED(nDesiredWidth
)
496 , int WXUNUSED(nDesiredHeight
)
501 hIcon
= ::WinLoadFileIcon( (PSZ
)rName
.c_str()
502 ,TRUE
// load for private use
505 pIcon
->SetSize(32, 32); // all OS/2 icons are 32 x 32
508 pIcon
->SetHICON((WXHICON
)hIcon
);
511 } // end of wxICOResourceHandler::LoadIcon
513 // ----------------------------------------------------------------------------
515 // ----------------------------------------------------------------------------
517 static wxSize
GetHiconSize(
521 wxSize
vSize(32, 32); // default
523 // all OS/2 icons are 32x32