]> git.saurik.com Git - wxWidgets.git/blame - src/os2/gdiimage.cpp
Add missing c_str() call to fix wxGTK ANSI+STL build.
[wxWidgets.git] / src / os2 / gdiimage.cpp
CommitLineData
b4eb4c6b 1///////////////////////////////////////////////////////////////////////////////
63a3cd7a 2// Name: src/os2/gdiimage.cpp
b4eb4c6b
DW
3// Purpose: wxGDIImage implementation
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 20.11.99
b4eb4c6b 7// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 8// Licence: wxWindows licence
b4eb4c6b
DW
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22
23#ifndef WX_PRECOMP
24 #include "wx/string.h"
670f9935 25 #include "wx/app.h"
b4eb4c6b
DW
26#endif // WX_PRECOMP
27
28#include "wx/os2/private.h"
b4eb4c6b
DW
29#include "wx/os2/gdiimage.h"
30
258f5b3e 31#include "wx/listimpl.cpp"
412e0d47 32WX_DEFINE_LIST(wxGDIImageHandlerList)
258f5b3e 33
b4eb4c6b
DW
34// ----------------------------------------------------------------------------
35// private classes
36// ----------------------------------------------------------------------------
37
38// all image handlers are declared/defined in this file because the outside
39// world doesn't have to know about them (but only about wxBITMAP_TYPE_XXX ids)
40
41class WXDLLEXPORT wxBMPFileHandler : public wxBitmapHandler
42{
43public:
9a83f860 44 wxBMPFileHandler() : wxBitmapHandler(wxT("Windows bitmap file"), wxT("bmp"),
b4eb4c6b
DW
45 wxBITMAP_TYPE_BMP)
46 {
47 }
48
49 virtual bool LoadFile( wxBitmap* pBitmap
50 ,const wxString& rName
51 ,HPS hPs
6b5c2d52 52 ,wxBitmapType lFlags
b4eb4c6b
DW
53 ,int nDesiredWidth
54 ,int nDesiredHeight
55 );
56 virtual bool SaveFile( wxBitmap* pBitmap
57 ,const wxString& rName
6b5c2d52 58 ,wxBitmapType lType
b4eb4c6b
DW
59 ,const wxPalette* pPalette = NULL
60 );
61
62private:
3029781e
DW
63 inline virtual bool LoadFile( wxBitmap* pBitmap
64 ,int nId
6b5c2d52 65 ,wxBitmapType lFlags
3029781e
DW
66 ,int nDesiredWidth
67 ,int nDesiredHeight
68 )
69 {
70 return wxBitmapHandler::LoadFile( pBitmap
71 ,nId
72 ,lFlags
73 ,nDesiredWidth
74 ,nDesiredHeight
75 );
76 }
b4eb4c6b
DW
77 DECLARE_DYNAMIC_CLASS(wxBMPFileHandler)
78};
79
80class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
81{
82public:
9a83f860 83 wxBMPResourceHandler() : wxBitmapHandler(wxT("Windows bitmap resource"),
b4eb4c6b
DW
84 wxEmptyString,
85 wxBITMAP_TYPE_BMP_RESOURCE)
86 {
87 }
88
89 virtual bool LoadFile( wxBitmap* pBitmap
3029781e 90 ,int nId
6b5c2d52 91 ,wxBitmapType lFlags
b4eb4c6b
DW
92 ,int nDesiredWidth
93 ,int nDesiredHeight
94 );
95
96private:
97 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
98};
99
100class WXDLLEXPORT wxIconHandler : public wxGDIImageHandler
101{
102public:
103 wxIconHandler( const wxString& rName
104 ,const wxString& rExt
6b5c2d52 105 ,wxBitmapType lType
b4eb4c6b
DW
106 ) : wxGDIImageHandler( rName
107 ,rExt
108 ,lType
109 )
110 {
111 }
112
113 // creating and saving icons is not supported
114 virtual bool Create( wxGDIImage* WXUNUSED(pImage)
452418c4 115 ,const void* WXUNUSED(pData)
6b5c2d52 116 ,wxBitmapType WXUNUSED(lFlags)
b4eb4c6b
DW
117 ,int WXUNUSED(nWidth)
118 ,int WXUNUSED(nHeight)
119 ,int WXUNUSED(nDepth) = 1
120 )
121 {
63a3cd7a 122 return false;
b4eb4c6b
DW
123 }
124
6b5c2d52
SN
125 virtual bool Save( const wxGDIImage* WXUNUSED(pImage)
126 ,const wxString& WXUNUSED(rName)
127 ,wxBitmapType WXUNUSED(nType)
128 ) const
b4eb4c6b 129 {
63a3cd7a 130 return false;
b4eb4c6b
DW
131 }
132 virtual bool Load( wxGDIImage* pImage
133 ,const wxString& rName
134 ,HPS hPs
6b5c2d52 135 ,wxBitmapType lFlags
b4eb4c6b
DW
136 ,int nDesiredWidth
137 ,int nDesiredHeight
138 )
139 {
140 wxIcon* pIcon = wxDynamicCast(pImage, wxIcon);
9a83f860 141 wxCHECK_MSG(pIcon, false, wxT("wxIconHandler only works with icons"));
b4eb4c6b
DW
142
143 return LoadIcon( pIcon
144 ,rName
145 ,hPs
146 ,lFlags
147 ,nDesiredWidth
148 ,nDesiredHeight
149 );
150 }
151
152protected:
153 virtual bool LoadIcon( wxIcon* pIcon
154 ,const wxString& rName
155 ,HPS hPs
6b5c2d52 156 ,wxBitmapType lFlags
b4eb4c6b
DW
157 ,int nDesiredWidth = -1
158 ,int nDesiredHeight = -1
159 ) = 0;
3029781e 160private:
6670f564
WS
161 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage),
162 int WXUNUSED(nId),
6b5c2d52 163 wxBitmapType WXUNUSED(lFlags),
6670f564
WS
164 int WXUNUSED(nDesiredWidth),
165 int WXUNUSED(nDesiredHeight) )
3029781e 166 {
6670f564 167 return false;
3029781e 168 }
b4eb4c6b
DW
169};
170
171class WXDLLEXPORT wxICOFileHandler : public wxIconHandler
172{
173public:
9a83f860
VZ
174 wxICOFileHandler() : wxIconHandler(wxT("ICO icon file"),
175 wxT("ico"),
b4eb4c6b
DW
176 wxBITMAP_TYPE_ICO)
177 {
178 }
179
180 virtual bool LoadIcon( wxIcon * pIcon
181 ,const wxString& rName
182 ,HPS hPs
6b5c2d52 183 ,wxBitmapType lFlags
b4eb4c6b
DW
184 ,int nDesiredWidth = -1
185 ,int nDesiredHeight = -1
186 );
187
188private:
189 DECLARE_DYNAMIC_CLASS(wxICOFileHandler)
190};
191
192class WXDLLEXPORT wxICOResourceHandler: public wxIconHandler
193{
194public:
9a83f860
VZ
195 wxICOResourceHandler() : wxIconHandler(wxT("ICO resource"),
196 wxT("ico"),
b4eb4c6b
DW
197 wxBITMAP_TYPE_ICO_RESOURCE)
198 {
199 }
200
201 virtual bool LoadIcon( wxIcon* pIcon
202 ,const wxString& rName
203 ,HPS hPs
6b5c2d52 204 ,wxBitmapType lFlags
b4eb4c6b
DW
205 ,int nDesiredWidth = -1
206 ,int nDesiredHeight = -1
207 );
208
209private:
210 DECLARE_DYNAMIC_CLASS(wxICOResourceHandler)
211};
212
213// ----------------------------------------------------------------------------
214// wxWin macros
215// ----------------------------------------------------------------------------
216
62f864c3
VZ
217IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler, wxBitmapHandler)
218IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
219IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler, wxObject)
220IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler, wxObject)
b4eb4c6b 221
b4eb4c6b
DW
222// ============================================================================
223// implementation
224// ============================================================================
225
258f5b3e 226wxGDIImageHandlerList wxGDIImage::ms_handlers;
b4eb4c6b
DW
227
228// ----------------------------------------------------------------------------
229// wxGDIImage functions forwarded to wxGDIImageRefData
230// ----------------------------------------------------------------------------
231
6670f564 232bool wxGDIImage::FreeResource( bool WXUNUSED(bForce) )
b4eb4c6b
DW
233{
234 if ( !IsNull() )
235 {
236 GetGDIImageData()->Free();
237 GetGDIImageData()->m_hHandle = 0;
238 }
239
6670f564 240 return true;
b4eb4c6b
DW
241}
242
17b1d76b 243WXHANDLE wxGDIImage::GetResourceHandle() const
b4eb4c6b
DW
244{
245 return GetHandle();
246}
247
248// ----------------------------------------------------------------------------
249// wxGDIImage handler stuff
250// ----------------------------------------------------------------------------
251
6670f564 252void wxGDIImage::AddHandler( wxGDIImageHandler* pHandler )
b4eb4c6b
DW
253{
254 ms_handlers.Append(pHandler);
255}
256
6670f564 257void wxGDIImage::InsertHandler( wxGDIImageHandler* pHandler )
b4eb4c6b
DW
258{
259 ms_handlers.Insert(pHandler);
260}
261
6670f564 262bool wxGDIImage::RemoveHandler( const wxString& rName )
b4eb4c6b
DW
263{
264 wxGDIImageHandler* pHandler = FindHandler(rName);
265
266 if (pHandler)
267 {
268 ms_handlers.DeleteObject(pHandler);
6670f564 269 return true;
b4eb4c6b
DW
270 }
271 else
6670f564 272 return false;
b4eb4c6b
DW
273}
274
275wxGDIImageHandler* wxGDIImage::FindHandler(
276 const wxString& rName
277)
278{
53ac3021
DW
279 wxGDIImageHandlerList::compatibility_iterator pNode = ms_handlers.GetFirst();
280
281 while ( pNode )
b4eb4c6b 282 {
53ac3021
DW
283 wxGDIImageHandler* pHandler = pNode->GetData();
284
285 if ( pHandler->GetName() == rName )
286 return pHandler;
287 pNode = pNode->GetNext();
b4eb4c6b 288 }
d3b9f782 289 return(NULL);
b4eb4c6b
DW
290}
291
292wxGDIImageHandler* wxGDIImage::FindHandler(
293 const wxString& rExtension
6b5c2d52 294, wxBitmapType lType
b4eb4c6b
DW
295)
296{
53ac3021
DW
297 wxGDIImageHandlerList::compatibility_iterator pNode = ms_handlers.GetFirst();
298 while ( pNode )
b4eb4c6b 299 {
53ac3021
DW
300 wxGDIImageHandler* pHandler = pNode->GetData();
301
96ad3e4e 302 if ( (pHandler->GetExtension() == rExtension) &&
53ac3021 303 (lType == -1 || pHandler->GetType() == lType) )
b4eb4c6b 304 {
53ac3021 305 return pHandler;
b4eb4c6b 306 }
53ac3021 307 pNode = pNode->GetNext();
b4eb4c6b 308 }
d3b9f782 309 return(NULL);
b4eb4c6b
DW
310}
311
312wxGDIImageHandler* wxGDIImage::FindHandler(
6b5c2d52 313 wxBitmapType lType
b4eb4c6b
DW
314)
315{
53ac3021
DW
316 wxGDIImageHandlerList::compatibility_iterator pNode = ms_handlers.GetFirst();
317
318 while ( pNode )
b4eb4c6b 319 {
53ac3021 320 wxGDIImageHandler* pHandler = pNode->GetData();
b4eb4c6b 321
53ac3021
DW
322 if ( pHandler->GetType() == lType )
323 return pHandler;
324 pNode = pNode->GetNext();
b4eb4c6b 325 }
d3b9f782 326 return(NULL);
b4eb4c6b
DW
327}
328
329void wxGDIImage::CleanUpHandlers()
330{
53ac3021
DW
331 wxGDIImageHandlerList::compatibility_iterator pNode = ms_handlers.GetFirst();
332
333 while ( pNode )
b4eb4c6b 334 {
53ac3021
DW
335 wxGDIImageHandler* pHandler = pNode->GetData();
336 wxGDIImageHandlerList::compatibility_iterator pNext = pNode->GetNext();
337
338 delete pHandler;
339 ms_handlers.Erase( pNode );
340 pNode = pNext;
b4eb4c6b
DW
341 }
342}
343
344void wxGDIImage::InitStandardHandlers()
345{
346 AddHandler(new wxBMPResourceHandler);
347 AddHandler(new wxBMPFileHandler);
b4eb4c6b
DW
348 AddHandler(new wxICOResourceHandler);
349 AddHandler(new wxICOFileHandler);
350}
351
352// ----------------------------------------------------------------------------
353// wxBitmap handlers
354// ----------------------------------------------------------------------------
355
6670f564
WS
356bool wxBMPResourceHandler::LoadFile( wxBitmap* pBitmap,
357 int nId,
6b5c2d52 358 wxBitmapType WXUNUSED(lFlags),
6670f564
WS
359 int WXUNUSED(nDesiredWidth),
360 int WXUNUSED(nDesiredHeight) )
b4eb4c6b 361{
3029781e
DW
362 SIZEL vSize = {0, 0};
363 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
364 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
365 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
366
367 pBitmap->SetHBITMAP((WXHBITMAP)::GpiLoadBitmap( hPS
368 ,NULLHANDLE
369 ,nId
370 ,0
371 ,0
372 ));
373 ::GpiDestroyPS(hPS);
374 ::DevCloseDC(hDC);
375
376 wxBitmapRefData* pData = pBitmap->GetBitmapData();
377
a1b806b9 378 if ( pBitmap->IsOk() )
b4eb4c6b 379 {
3029781e 380 BITMAPINFOHEADER vBmph;
b4eb4c6b 381
3029781e
DW
382 ::GpiQueryBitmapParameters(GetHbitmapOf(*pBitmap), &vBmph);
383 pData->m_nWidth = vBmph.cx;
384 pData->m_nHeight = vBmph.cy;
385 pData->m_nDepth = vBmph.cBitCount;
b4eb4c6b 386 }
a1b806b9 387 return(pBitmap->IsOk());
3029781e 388} // end of wxBMPResourceHandler::LoadFile
b4eb4c6b 389
6670f564
WS
390bool wxBMPFileHandler::LoadFile( wxBitmap* pBitmap,
391 const wxString& WXUNUSED(rName),
392 HPS WXUNUSED(hPs),
6b5c2d52 393 wxBitmapType WXUNUSED(lFlags),
6670f564
WS
394 int WXUNUSED(nDesiredWidth),
395 int WXUNUSED(nDesiredHeight) )
b4eb4c6b 396{
63a3cd7a 397#if defined(wxUSE_IMAGE_LOADING_IN_OS2) && wxUSE_IMAGE_LOADING_IN_OS2
6670f564 398 wxPalette* pPalette = NULL;
b4eb4c6b 399
6670f564
WS
400 bool bSuccess = false; /* wxLoadIntoBitmap( WXSTRINGCAST rName
401 ,pBitmap
402 ,&pPalette
403 ) != 0; */
b4eb4c6b
DW
404 if (bSuccess && pPalette)
405 {
406 pBitmap->SetPalette(*pPalette);
407 }
408
409 // it was copied by the bitmap if it was loaded successfully
410 delete pPalette;
411
412 return(bSuccess);
413#else
6670f564
WS
414 wxUnusedVar(pBitmap);
415 return false;
b4eb4c6b
DW
416#endif
417}
418
6670f564
WS
419bool wxBMPFileHandler::SaveFile( wxBitmap* pBitmap,
420 const wxString& WXUNUSED(rName),
6b5c2d52 421 wxBitmapType WXUNUSED(nType),
6670f564 422 const wxPalette* pPal )
b4eb4c6b 423{
63a3cd7a 424#if defined(wxUSE_IMAGE_LOADING_IN_OS2) && wxUSE_IMAGE_LOADING_IN_OS2
6670f564 425 wxPalette* pActualPalette = (wxPalette *)pPal;
b4eb4c6b
DW
426
427 if (!pActualPalette)
428 pActualPalette = pBitmap->GetPalette();
429 /* return(wxSaveBitmap( WXSTRINGCAST rName
430 ,pBitmap
431 ,pActualPalette
432 ) != 0); */
6670f564 433 return false;
b4eb4c6b 434#else
6670f564
WS
435 wxUnusedVar(pBitmap);
436 wxUnusedVar(pPal);
437 return false;
b4eb4c6b
DW
438#endif
439}
440
441// ----------------------------------------------------------------------------
442// wxIcon handlers
443// ----------------------------------------------------------------------------
444
6670f564
WS
445bool wxICOFileHandler::LoadIcon( wxIcon* pIcon,
446 const wxString& WXUNUSED(rName),
447 HPS WXUNUSED(hPs),
6b5c2d52 448 wxBitmapType WXUNUSED(lFlags),
6670f564
WS
449 int WXUNUSED(nDesiredWidth),
450 int WXUNUSED(nDesiredHeight) )
b4eb4c6b 451{
63a3cd7a 452#if defined(wxUSE_RESOURCE_LOADING_IN_OS2) && wxUSE_RESOURCE_LOADING_IN_OS2
b4eb4c6b
DW
453 pIcon->UnRef();
454
6670f564 455 return false;
b4eb4c6b 456#else
6670f564
WS
457 wxUnusedVar(pIcon);
458 return false;
b4eb4c6b
DW
459#endif
460}
461
6670f564
WS
462bool wxICOResourceHandler::LoadIcon( wxIcon* pIcon,
463 const wxString& rName,
464 HPS WXUNUSED(hPs),
6b5c2d52 465 wxBitmapType WXUNUSED(lFlags),
6670f564
WS
466 int WXUNUSED(nDesiredWidth),
467 int WXUNUSED(nDesiredHeight) )
b4eb4c6b 468{
22e90769 469 HPOINTER hIcon;
b4eb4c6b 470
96ad3e4e 471 hIcon = ::WinLoadFileIcon( rName.c_str()
22e90769
DW
472 ,TRUE // load for private use
473 );
b4eb4c6b 474
22e90769 475 pIcon->SetSize(32, 32); // all OS/2 icons are 32 x 32
b4eb4c6b 476
22e90769 477 pIcon->SetHICON((WXHICON)hIcon);
b4eb4c6b 478
a1b806b9 479 return pIcon->IsOk();
22e90769 480} // end of wxICOResourceHandler::LoadIcon