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
* WXUNUSED(pImage
),
168 long WXUNUSED(lFlags
),
169 int WXUNUSED(nDesiredWidth
),
170 int WXUNUSED(nDesiredHeight
) )
176 class WXDLLEXPORT wxICOFileHandler
: public wxIconHandler
179 wxICOFileHandler() : wxIconHandler(_T("ICO icon file"),
185 virtual bool LoadIcon( wxIcon
* pIcon
186 ,const wxString
& rName
189 ,int nDesiredWidth
= -1
190 ,int nDesiredHeight
= -1
194 DECLARE_DYNAMIC_CLASS(wxICOFileHandler
)
197 class WXDLLEXPORT wxICOResourceHandler
: public wxIconHandler
200 wxICOResourceHandler() : wxIconHandler(_T("ICO resource"),
202 wxBITMAP_TYPE_ICO_RESOURCE
)
206 virtual bool LoadIcon( wxIcon
* pIcon
207 ,const wxString
& rName
210 ,int nDesiredWidth
= -1
211 ,int nDesiredHeight
= -1
215 DECLARE_DYNAMIC_CLASS(wxICOResourceHandler
)
218 // ----------------------------------------------------------------------------
220 // ----------------------------------------------------------------------------
222 #if !USE_SHARED_LIBRARIES
223 IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler
, wxBitmapHandler
)
224 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler
, wxBitmapHandler
)
225 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler
, wxObject
)
226 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler
, wxObject
)
229 // ============================================================================
231 // ============================================================================
233 wxGDIImageHandlerList
wxGDIImage::ms_handlers
;
235 // ----------------------------------------------------------------------------
236 // wxGDIImage functions forwarded to wxGDIImageRefData
237 // ----------------------------------------------------------------------------
239 bool wxGDIImage::FreeResource( bool WXUNUSED(bForce
) )
243 GetGDIImageData()->Free();
244 GetGDIImageData()->m_hHandle
= 0;
250 WXHANDLE
wxGDIImage::GetResourceHandle()
255 // ----------------------------------------------------------------------------
256 // wxGDIImage handler stuff
257 // ----------------------------------------------------------------------------
259 void wxGDIImage::AddHandler( wxGDIImageHandler
* pHandler
)
261 ms_handlers
.Append(pHandler
);
264 void wxGDIImage::InsertHandler( wxGDIImageHandler
* pHandler
)
266 ms_handlers
.Insert(pHandler
);
269 bool wxGDIImage::RemoveHandler( const wxString
& rName
)
271 wxGDIImageHandler
* pHandler
= FindHandler(rName
);
275 ms_handlers
.DeleteObject(pHandler
);
282 wxGDIImageHandler
* wxGDIImage::FindHandler(
283 const wxString
& rName
286 wxGDIImageHandlerList::compatibility_iterator pNode
= ms_handlers
.GetFirst();
290 wxGDIImageHandler
* pHandler
= pNode
->GetData();
292 if ( pHandler
->GetName() == rName
)
294 pNode
= pNode
->GetNext();
296 return((wxGDIImageHandler
*)NULL
);
299 wxGDIImageHandler
* wxGDIImage::FindHandler(
300 const wxString
& rExtension
304 wxGDIImageHandlerList::compatibility_iterator pNode
= ms_handlers
.GetFirst();
307 wxGDIImageHandler
* pHandler
= pNode
->GetData();
309 if ( (pHandler
->GetExtension() = rExtension
) &&
310 (lType
== -1 || pHandler
->GetType() == lType
) )
314 pNode
= pNode
->GetNext();
316 return((wxGDIImageHandler
*)NULL
);
319 wxGDIImageHandler
* wxGDIImage::FindHandler(
323 wxGDIImageHandlerList::compatibility_iterator pNode
= ms_handlers
.GetFirst();
327 wxGDIImageHandler
* pHandler
= pNode
->GetData();
329 if ( pHandler
->GetType() == lType
)
331 pNode
= pNode
->GetNext();
333 return((wxGDIImageHandler
*)NULL
);
336 void wxGDIImage::CleanUpHandlers()
338 wxGDIImageHandlerList::compatibility_iterator pNode
= ms_handlers
.GetFirst();
342 wxGDIImageHandler
* pHandler
= pNode
->GetData();
343 wxGDIImageHandlerList::compatibility_iterator pNext
= pNode
->GetNext();
346 ms_handlers
.Erase( pNode
);
351 void wxGDIImage::InitStandardHandlers()
353 AddHandler(new wxBMPResourceHandler
);
354 AddHandler(new wxBMPFileHandler
);
355 AddHandler(new wxICOResourceHandler
);
356 AddHandler(new wxICOFileHandler
);
359 // ----------------------------------------------------------------------------
361 // ----------------------------------------------------------------------------
363 bool wxBMPResourceHandler::LoadFile( wxBitmap
* pBitmap
,
365 long WXUNUSED(lFlags
),
366 int WXUNUSED(nDesiredWidth
),
367 int WXUNUSED(nDesiredHeight
) )
369 SIZEL vSize
= {0, 0};
370 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
371 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
372 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
374 pBitmap
->SetHBITMAP((WXHBITMAP
)::GpiLoadBitmap( hPS
383 wxBitmapRefData
* pData
= pBitmap
->GetBitmapData();
387 BITMAPINFOHEADER vBmph
;
389 ::GpiQueryBitmapParameters(GetHbitmapOf(*pBitmap
), &vBmph
);
390 pData
->m_nWidth
= vBmph
.cx
;
391 pData
->m_nHeight
= vBmph
.cy
;
392 pData
->m_nDepth
= vBmph
.cBitCount
;
394 return(pBitmap
->Ok());
395 } // end of wxBMPResourceHandler::LoadFile
397 bool wxBMPFileHandler::LoadFile( wxBitmap
* pBitmap
,
398 const wxString
& WXUNUSED(rName
),
400 long WXUNUSED(lFlags
),
401 int WXUNUSED(nDesiredWidth
),
402 int WXUNUSED(nDesiredHeight
) )
404 #if wxUSE_IMAGE_LOADING_IN_OS2
405 wxPalette
* pPalette
= NULL
;
407 bool bSuccess
= false; /* wxLoadIntoBitmap( WXSTRINGCAST rName
411 if (bSuccess
&& pPalette
)
413 pBitmap
->SetPalette(*pPalette
);
416 // it was copied by the bitmap if it was loaded successfully
421 wxUnusedVar(pBitmap
);
426 bool wxBMPFileHandler::SaveFile( wxBitmap
* pBitmap
,
427 const wxString
& WXUNUSED(rName
),
429 const wxPalette
* pPal
)
431 #if wxUSE_IMAGE_LOADING_IN_OS2
432 wxPalette
* pActualPalette
= (wxPalette
*)pPal
;
435 pActualPalette
= pBitmap
->GetPalette();
436 /* return(wxSaveBitmap( WXSTRINGCAST rName
442 wxUnusedVar(pBitmap
);
448 // ----------------------------------------------------------------------------
450 // ----------------------------------------------------------------------------
452 bool wxICOFileHandler::LoadIcon( wxIcon
* pIcon
,
453 const wxString
& WXUNUSED(rName
),
455 long WXUNUSED(lFlags
),
456 int WXUNUSED(nDesiredWidth
),
457 int WXUNUSED(nDesiredHeight
) )
459 #if wxUSE_RESOURCE_LOADING_IN_OS2
469 bool wxICOResourceHandler::LoadIcon( wxIcon
* pIcon
,
470 const wxString
& rName
,
472 long WXUNUSED(lFlags
),
473 int WXUNUSED(nDesiredWidth
),
474 int WXUNUSED(nDesiredHeight
) )
478 hIcon
= ::WinLoadFileIcon( (PSZ
)rName
.c_str()
479 ,TRUE
// load for private use
482 pIcon
->SetSize(32, 32); // all OS/2 icons are 32 x 32
484 pIcon
->SetHICON((WXHICON
)hIcon
);
487 } // end of wxICOResourceHandler::LoadIcon