]> git.saurik.com Git - wxWidgets.git/blame - src/msw/gdiimage.cpp
Compilation fix for !wxUSE_OWNER_DRAWN.
[wxWidgets.git] / src / msw / gdiimage.cpp
CommitLineData
0d0512bd 1///////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/msw/gdiimage.cpp
0d0512bd
VZ
3// Purpose: wxGDIImage implementation
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 20.11.99
0d0512bd 7// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 8// Licence: wxWindows licence
0d0512bd
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
0d0512bd
VZ
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
27 #include "wx/string.h"
f94dfb38 28 #include "wx/log.h"
670f9935 29 #include "wx/app.h"
0bca0373 30 #include "wx/bitmap.h"
0d0512bd
VZ
31#endif // WX_PRECOMP
32
e42a6c18
VZ
33#include "wx/msw/private.h"
34
474df218 35#include "wx/msw/gdiimage.h"
4676948b
JS
36
37#if wxUSE_WXDIB
474df218 38#include "wx/msw/dib.h"
4676948b
JS
39#endif
40
c3f641cb
VZ
41// By default, use PNG resource handler if we can, i.e. have support for
42// loading PNG images in the library. This symbol could be predefined as 0 to
43// avoid doing this if anybody ever needs to do it for some reason.
44#if !defined(wxUSE_PNG_RESOURCE_HANDLER) && wxUSE_LIBPNG && wxUSE_IMAGE
45 #define wxUSE_PNG_RESOURCE_HANDLER 1
46#endif
47
48#if wxUSE_PNG_RESOURCE_HANDLER
49 #include "wx/image.h"
50 #include "wx/utils.h" // For wxLoadUserResource()
51#endif
52
4676948b
JS
53#ifdef __WXWINCE__
54#include <winreg.h>
55#include <shellapi.h>
56#endif
f66f0fd7 57
419430a0
JS
58#include "wx/file.h"
59
d162a7ee 60#include "wx/listimpl.cpp"
259c43f6 61WX_DEFINE_LIST(wxGDIImageHandlerList)
d162a7ee 62
0d0512bd
VZ
63// ----------------------------------------------------------------------------
64// private classes
65// ----------------------------------------------------------------------------
66
04ef50df
JS
67#ifndef __WXMICROWIN__
68
0d0512bd
VZ
69// all image handlers are declared/defined in this file because the outside
70// world doesn't have to know about them (but only about wxBITMAP_TYPE_XXX ids)
71
72class WXDLLEXPORT wxBMPFileHandler : public wxBitmapHandler
73{
74public:
9a83f860 75 wxBMPFileHandler() : wxBitmapHandler(wxT("Windows bitmap file"), wxT("bmp"),
0d0512bd
VZ
76 wxBITMAP_TYPE_BMP)
77 {
78 }
79
80 virtual bool LoadFile(wxBitmap *bitmap,
e86f2cc8 81 const wxString& name, wxBitmapType flags,
0d0512bd 82 int desiredWidth, int desiredHeight);
e86f2cc8
FM
83 virtual bool SaveFile(const wxBitmap *bitmap,
84 const wxString& name, wxBitmapType type,
85 const wxPalette *palette = NULL) const;
0d0512bd
VZ
86
87private:
88 DECLARE_DYNAMIC_CLASS(wxBMPFileHandler)
89};
90
91class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
92{
93public:
9a83f860 94 wxBMPResourceHandler() : wxBitmapHandler(wxT("Windows bitmap resource"),
0d0512bd
VZ
95 wxEmptyString,
96 wxBITMAP_TYPE_BMP_RESOURCE)
97 {
98 }
99
100 virtual bool LoadFile(wxBitmap *bitmap,
e86f2cc8 101 const wxString& name, wxBitmapType flags,
0d0512bd
VZ
102 int desiredWidth, int desiredHeight);
103
104private:
105 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
106};
107
108class WXDLLEXPORT wxIconHandler : public wxGDIImageHandler
109{
110public:
e86f2cc8 111 wxIconHandler(const wxString& name, const wxString& ext, wxBitmapType type)
0d0512bd
VZ
112 : wxGDIImageHandler(name, ext, type)
113 {
114 }
115
116 // creating and saving icons is not supported
117 virtual bool Create(wxGDIImage *WXUNUSED(image),
452418c4 118 const void* WXUNUSED(data),
e86f2cc8 119 wxBitmapType WXUNUSED(flags),
0d0512bd
VZ
120 int WXUNUSED(width),
121 int WXUNUSED(height),
122 int WXUNUSED(depth) = 1)
123 {
4f8090e0 124 return false;
0d0512bd
VZ
125 }
126
e86f2cc8 127 virtual bool Save(const wxGDIImage *WXUNUSED(image),
0d0512bd 128 const wxString& WXUNUSED(name),
e86f2cc8 129 wxBitmapType WXUNUSED(type)) const
0d0512bd 130 {
4f8090e0 131 return false;
0d0512bd
VZ
132 }
133
134 virtual bool Load(wxGDIImage *image,
135 const wxString& name,
e86f2cc8 136 wxBitmapType flags,
0d0512bd
VZ
137 int desiredWidth, int desiredHeight)
138 {
139 wxIcon *icon = wxDynamicCast(image, wxIcon);
9a83f860 140 wxCHECK_MSG( icon, false, wxT("wxIconHandler only works with icons") );
0d0512bd
VZ
141
142 return LoadIcon(icon, name, flags, desiredWidth, desiredHeight);
143 }
144
145protected:
146 virtual bool LoadIcon(wxIcon *icon,
e86f2cc8 147 const wxString& name, wxBitmapType flags,
0d0512bd
VZ
148 int desiredWidth = -1, int desiredHeight = -1) = 0;
149};
150
151class WXDLLEXPORT wxICOFileHandler : public wxIconHandler
152{
153public:
9a83f860
VZ
154 wxICOFileHandler() : wxIconHandler(wxT("ICO icon file"),
155 wxT("ico"),
0d0512bd
VZ
156 wxBITMAP_TYPE_ICO)
157 {
158 }
159
795c9ab8 160protected:
0d0512bd 161 virtual bool LoadIcon(wxIcon *icon,
e86f2cc8 162 const wxString& name, wxBitmapType flags,
0d0512bd
VZ
163 int desiredWidth = -1, int desiredHeight = -1);
164
165private:
166 DECLARE_DYNAMIC_CLASS(wxICOFileHandler)
167};
168
169class WXDLLEXPORT wxICOResourceHandler: public wxIconHandler
170{
171public:
9a83f860
VZ
172 wxICOResourceHandler() : wxIconHandler(wxT("ICO resource"),
173 wxT("ico"),
0d0512bd
VZ
174 wxBITMAP_TYPE_ICO_RESOURCE)
175 {
176 }
177
795c9ab8 178protected:
0d0512bd 179 virtual bool LoadIcon(wxIcon *icon,
e86f2cc8 180 const wxString& name, wxBitmapType flags,
0d0512bd
VZ
181 int desiredWidth = -1, int desiredHeight = -1);
182
183private:
184 DECLARE_DYNAMIC_CLASS(wxICOResourceHandler)
185};
186
c3f641cb
VZ
187#if wxUSE_PNG_RESOURCE_HANDLER
188
189class WXDLLEXPORT wxPNGResourceHandler : public wxBitmapHandler
190{
191public:
192 wxPNGResourceHandler() : wxBitmapHandler(wxS("Windows PNG resource"),
193 wxString(),
194 wxBITMAP_TYPE_PNG_RESOURCE)
195 {
196 }
197
198 virtual bool LoadFile(wxBitmap *bitmap,
199 const wxString& name, wxBitmapType flags,
200 int desiredWidth, int desiredHeight);
201
202private:
203 wxDECLARE_DYNAMIC_CLASS(wxPNGResourceHandler);
204};
205
206#endif // wxUSE_PNG_RESOURCE_HANDLER
207
0d0512bd
VZ
208// ----------------------------------------------------------------------------
209// wxWin macros
210// ----------------------------------------------------------------------------
211
621b3e21
VZ
212IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler, wxBitmapHandler)
213IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
214IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler, wxObject)
215IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler, wxObject)
c3f641cb
VZ
216#if wxUSE_PNG_RESOURCE_HANDLER
217IMPLEMENT_DYNAMIC_CLASS(wxPNGResourceHandler, wxBitmapHandler)
218#endif // wxUSE_PNG_RESOURCE_HANDLER
0d0512bd
VZ
219
220// ----------------------------------------------------------------------------
221// private functions
222// ----------------------------------------------------------------------------
223
04ef50df
JS
224#endif
225 // __MICROWIN__
0d0512bd
VZ
226
227// ============================================================================
228// implementation
229// ============================================================================
230
d162a7ee 231wxGDIImageHandlerList wxGDIImage::ms_handlers;
0d0512bd
VZ
232
233// ----------------------------------------------------------------------------
234// wxGDIImage functions forwarded to wxGDIImageRefData
235// ----------------------------------------------------------------------------
236
237bool wxGDIImage::FreeResource(bool WXUNUSED(force))
238{
239 if ( !IsNull() )
240 {
241 GetGDIImageData()->Free();
242 GetGDIImageData()->m_handle = 0;
243 }
244
4f8090e0 245 return true;
0d0512bd
VZ
246}
247
2b5f62a0 248WXHANDLE wxGDIImage::GetResourceHandle() const
0d0512bd
VZ
249{
250 return GetHandle();
251}
252
253// ----------------------------------------------------------------------------
254// wxGDIImage handler stuff
255// ----------------------------------------------------------------------------
256
257void wxGDIImage::AddHandler(wxGDIImageHandler *handler)
258{
259 ms_handlers.Append(handler);
260}
261
262void wxGDIImage::InsertHandler(wxGDIImageHandler *handler)
263{
264 ms_handlers.Insert(handler);
265}
266
267bool wxGDIImage::RemoveHandler(const wxString& name)
268{
269 wxGDIImageHandler *handler = FindHandler(name);
270 if ( handler )
271 {
272 ms_handlers.DeleteObject(handler);
4f8090e0 273 return true;
0d0512bd
VZ
274 }
275 else
4f8090e0 276 return false;
0d0512bd
VZ
277}
278
279wxGDIImageHandler *wxGDIImage::FindHandler(const wxString& name)
280{
222ed1d6 281 wxGDIImageHandlerList::compatibility_iterator node = ms_handlers.GetFirst();
0d0512bd
VZ
282 while ( node )
283 {
d162a7ee 284 wxGDIImageHandler *handler = node->GetData();
0d0512bd
VZ
285 if ( handler->GetName() == name )
286 return handler;
4f8090e0 287 node = node->GetNext();
0d0512bd
VZ
288 }
289
290 return NULL;
291}
292
293wxGDIImageHandler *wxGDIImage::FindHandler(const wxString& extension,
294 long type)
295{
222ed1d6 296 wxGDIImageHandlerList::compatibility_iterator node = ms_handlers.GetFirst();
0d0512bd
VZ
297 while ( node )
298 {
d162a7ee 299 wxGDIImageHandler *handler = node->GetData();
795c9ab8 300 if ( (handler->GetExtension() == extension) &&
0d0512bd
VZ
301 (type == -1 || handler->GetType() == type) )
302 {
303 return handler;
304 }
305
4f8090e0 306 node = node->GetNext();
0d0512bd
VZ
307 }
308 return NULL;
309}
310
311wxGDIImageHandler *wxGDIImage::FindHandler(long type)
312{
222ed1d6 313 wxGDIImageHandlerList::compatibility_iterator node = ms_handlers.GetFirst();
0d0512bd
VZ
314 while ( node )
315 {
d162a7ee 316 wxGDIImageHandler *handler = node->GetData();
0d0512bd
VZ
317 if ( handler->GetType() == type )
318 return handler;
319
4f8090e0 320 node = node->GetNext();
0d0512bd
VZ
321 }
322
323 return NULL;
324}
325
326void wxGDIImage::CleanUpHandlers()
327{
222ed1d6 328 wxGDIImageHandlerList::compatibility_iterator node = ms_handlers.GetFirst();
0d0512bd
VZ
329 while ( node )
330 {
d162a7ee 331 wxGDIImageHandler *handler = node->GetData();
222ed1d6 332 wxGDIImageHandlerList::compatibility_iterator next = node->GetNext();
0d0512bd 333 delete handler;
222ed1d6 334 ms_handlers.Erase( node );
0d0512bd
VZ
335 node = next;
336 }
337}
338
339void wxGDIImage::InitStandardHandlers()
340{
04ef50df 341#ifndef __WXMICROWIN__
0d0512bd
VZ
342 AddHandler(new wxBMPResourceHandler);
343 AddHandler(new wxBMPFileHandler);
0d0512bd 344 AddHandler(new wxICOFileHandler);
c3f641cb
VZ
345 AddHandler(new wxICOResourceHandler);
346#if wxUSE_PNG_RESOURCE_HANDLER
347 AddHandler(new wxPNGResourceHandler);
348#endif // wxUSE_PNG_RESOURCE_HANDLER
04ef50df 349#endif
0d0512bd
VZ
350}
351
04ef50df
JS
352#ifndef __WXMICROWIN__
353
0d0512bd
VZ
354// ----------------------------------------------------------------------------
355// wxBitmap handlers
356// ----------------------------------------------------------------------------
357
358bool wxBMPResourceHandler::LoadFile(wxBitmap *bitmap,
e86f2cc8 359 const wxString& name, wxBitmapType WXUNUSED(flags),
0d0512bd
VZ
360 int WXUNUSED(desiredWidth),
361 int WXUNUSED(desiredHeight))
362{
363 // TODO: load colourmap.
017dc06b 364 bitmap->SetHBITMAP((WXHBITMAP)::LoadBitmap(wxGetInstance(), name.t_str()));
0d0512bd 365
a1b806b9 366 if ( !bitmap->IsOk() )
0d0512bd
VZ
367 {
368 // it's probably not found
369 wxLogError(wxT("Can't load bitmap '%s' from resources! Check .rc file."),
370 name.c_str());
8bbbae21 371
4f8090e0 372 return false;
8bbbae21
VZ
373 }
374
375 BITMAP bm;
376 if ( !::GetObject(GetHbitmapOf(*bitmap), sizeof(BITMAP), (LPSTR) &bm) )
377 {
378 wxLogLastError(wxT("GetObject(HBITMAP)"));
0d0512bd
VZ
379 }
380
8bbbae21
VZ
381 bitmap->SetWidth(bm.bmWidth);
382 bitmap->SetHeight(bm.bmHeight);
383 bitmap->SetDepth(bm.bmBitsPixel);
384
9542f0a1
VZ
385 // use 0xc0c0c0 as transparent colour by default
386 bitmap->SetMask(new wxMask(*bitmap, *wxLIGHT_GREY));
387
4f8090e0 388 return true;
0d0512bd
VZ
389}
390
391bool wxBMPFileHandler::LoadFile(wxBitmap *bitmap,
e86f2cc8 392 const wxString& name, wxBitmapType WXUNUSED(flags),
0d0512bd
VZ
393 int WXUNUSED(desiredWidth),
394 int WXUNUSED(desiredHeight))
395{
4676948b 396#if wxUSE_WXDIB
9a83f860 397 wxCHECK_MSG( bitmap, false, wxT("NULL bitmap in LoadFile") );
d275c7eb 398
474df218 399 wxDIB dib(name);
0d0512bd 400
a91bcd3b 401 return dib.IsOk() && bitmap->CopyFromDIB(dib);
4676948b 402#else
213ceb3f 403 return false;
4676948b 404#endif
0d0512bd
VZ
405}
406
e86f2cc8 407bool wxBMPFileHandler::SaveFile(const wxBitmap *bitmap,
0d0512bd 408 const wxString& name,
e86f2cc8
FM
409 wxBitmapType WXUNUSED(type),
410 const wxPalette * WXUNUSED(pal)) const
0d0512bd 411{
4676948b 412#if wxUSE_WXDIB
9a83f860 413 wxCHECK_MSG( bitmap, false, wxT("NULL bitmap in SaveFile") );
2b254edf
VZ
414
415 wxDIB dib(*bitmap);
416
417 return dib.Save(name);
4676948b 418#else
213ceb3f 419 return false;
4676948b 420#endif
0d0512bd
VZ
421}
422
423// ----------------------------------------------------------------------------
424// wxIcon handlers
425// ----------------------------------------------------------------------------
426
427bool wxICOFileHandler::LoadIcon(wxIcon *icon,
428 const wxString& name,
e86f2cc8 429 wxBitmapType WXUNUSED(flags),
0d0512bd
VZ
430 int desiredWidth, int desiredHeight)
431{
0d0512bd
VZ
432 icon->UnRef();
433
a4352768
VZ
434 HICON hicon = NULL;
435
2dace059
VZ
436 // Parse the filename: it may be of the form "filename;n" in order to
437 // specify the nth icon in the file.
438 //
439 // For the moment, ignore the issue of possible semicolons in the
440 // filename.
ff9aab3c 441 int iconIndex = 0;
2dace059 442 wxString nameReal(name);
ff9aab3c 443 wxString strIconIndex = name.AfterLast(wxT(';'));
b642d457 444 if (strIconIndex != name)
ff9aab3c
JS
445 {
446 iconIndex = wxAtoi(strIconIndex);
2dace059 447 nameReal = name.BeforeLast(wxT(';'));
ff9aab3c
JS
448 }
449
2b5f62a0
VZ
450#if 0
451 // If we don't know what size icon we're looking for,
452 // try to find out what's there.
453 // Unfortunately this doesn't work, because ExtractIconEx
454 // will scale the icon to the 'desired' size, even if that
455 // size of icon isn't explicitly stored. So we would have
456 // to parse the icon file outselves.
457 if ( desiredWidth == -1 &&
458 desiredHeight == -1)
459 {
460 // Try loading a large icon first
461 if ( ::ExtractIconEx(nameReal, iconIndex, &hicon, NULL, 1) == 1)
462 {
463 }
464 // Then try loading a small icon
465 else if ( ::ExtractIconEx(nameReal, iconIndex, NULL, &hicon, 1) == 1)
466 {
467 }
468 }
469 else
470#endif
4676948b 471 // were we asked for a large icon?
a4352768
VZ
472 if ( desiredWidth == ::GetSystemMetrics(SM_CXICON) &&
473 desiredHeight == ::GetSystemMetrics(SM_CYICON) )
474 {
ff9aab3c 475 // get the specified large icon from file
017dc06b 476 if ( !::ExtractIconEx(nameReal.t_str(), iconIndex, &hicon, NULL, 1) )
a4352768
VZ
477 {
478 // it is not an error, but it might still be useful to be informed
479 // about it optionally
9a83f860
VZ
480 wxLogTrace(wxT("iconload"),
481 wxT("No large icons found in the file '%s'."),
a4352768
VZ
482 name.c_str());
483 }
484 }
485 else if ( desiredWidth == ::GetSystemMetrics(SM_CXSMICON) &&
486 desiredHeight == ::GetSystemMetrics(SM_CYSMICON) )
487 {
ff9aab3c 488 // get the specified small icon from file
017dc06b 489 if ( !::ExtractIconEx(nameReal.t_str(), iconIndex, NULL, &hicon, 1) )
a4352768 490 {
9a83f860
VZ
491 wxLogTrace(wxT("iconload"),
492 wxT("No small icons found in the file '%s'."),
a4352768
VZ
493 name.c_str());
494 }
495 }
496 //else: not standard size, load below
497
4676948b 498#ifndef __WXWINCE__
a4352768
VZ
499 if ( !hicon )
500 {
d8f3f983 501 // take any size icon from the file by index
017dc06b 502 hicon = ::ExtractIcon(wxGetInstance(), nameReal.t_str(), iconIndex);
a4352768 503 }
4676948b 504#endif
a4352768 505
0d0512bd
VZ
506 if ( !hicon )
507 {
9a83f860 508 wxLogSysError(wxT("Failed to load icon from the file '%s'"),
0d0512bd
VZ
509 name.c_str());
510
4f8090e0 511 return false;
0d0512bd
VZ
512 }
513
973abcbb
VZ
514 if ( !icon->CreateFromHICON(hicon) )
515 return false;
0d0512bd 516
973abcbb
VZ
517 if ( (desiredWidth != -1 && desiredWidth != icon->GetWidth()) ||
518 (desiredHeight != -1 && desiredHeight != icon->GetHeight()) )
0d0512bd 519 {
9a83f860
VZ
520 wxLogTrace(wxT("iconload"),
521 wxT("Returning false from wxICOFileHandler::Load because of the size mismatch: actual (%d, %d), requested (%d, %d)"),
973abcbb 522 icon->GetWidth(), icon->GetHeight(),
a4352768 523 desiredWidth, desiredHeight);
0d0512bd 524
973abcbb 525 icon->UnRef();
0d0512bd 526
4f8090e0 527 return false;
0d0512bd
VZ
528 }
529
973abcbb 530 return true;
0d0512bd
VZ
531}
532
533bool wxICOResourceHandler::LoadIcon(wxIcon *icon,
534 const wxString& name,
e86f2cc8 535 wxBitmapType WXUNUSED(flags),
0d0512bd
VZ
536 int desiredWidth, int desiredHeight)
537{
538 HICON hicon;
539
9cb9fdb3
VZ
540 // do we need the icon of the specific size or would any icon do?
541 bool hasSize = desiredWidth != -1 || desiredHeight != -1;
542
543 wxASSERT_MSG( !hasSize || (desiredWidth != -1 && desiredHeight != -1),
9a83f860 544 wxT("width and height should be either both -1 or not") );
9cb9fdb3 545
2dace059
VZ
546 // try to load the icon from this program first to allow overriding the
547 // standard icons (although why one would want to do it considering that
548 // we already have wxApp::GetStdIcon() is unclear)
9990cb50
VZ
549
550 // note that we can't just always call LoadImage() because it seems to do
551 // some icon rescaling internally which results in very ugly 16x16 icons
9990cb50 552 if ( hasSize )
0d0512bd 553 {
017dc06b 554 hicon = (HICON)::LoadImage(wxGetInstance(), name.t_str(), IMAGE_ICON,
9990cb50
VZ
555 desiredWidth, desiredHeight,
556 LR_DEFAULTCOLOR);
0d0512bd 557 }
9990cb50 558 else
9990cb50 559 {
017dc06b 560 hicon = ::LoadIcon(wxGetInstance(), name.t_str());
9990cb50 561 }
fea2b62e 562
2dace059 563 // next check if it's not a standard icon
4676948b 564#ifndef __WXWINCE__
9cb9fdb3 565 if ( !hicon && !hasSize )
2dace059
VZ
566 {
567 static const struct
568 {
569 const wxChar *name;
570 LPTSTR id;
571 } stdIcons[] =
572 {
573 { wxT("wxICON_QUESTION"), IDI_QUESTION },
574 { wxT("wxICON_WARNING"), IDI_EXCLAMATION },
575 { wxT("wxICON_ERROR"), IDI_HAND },
c2edb18a 576 { wxT("wxICON_INFORMATION"), IDI_ASTERISK },
2dace059
VZ
577 };
578
579 for ( size_t nIcon = 0; !hicon && nIcon < WXSIZEOF(stdIcons); nIcon++ )
580 {
581 if ( name == stdIcons[nIcon].name )
582 {
9cb9fdb3 583 hicon = ::LoadIcon((HINSTANCE)NULL, stdIcons[nIcon].id);
fde87a82 584 break;
2dace059
VZ
585 }
586 }
587 }
4676948b 588#endif
2dace059 589
973abcbb 590 return icon->CreateFromHICON((WXHICON)hicon);
0d0512bd
VZ
591}
592
c3f641cb
VZ
593#if wxUSE_PNG_RESOURCE_HANDLER
594
595// ----------------------------------------------------------------------------
596// PNG handler
597// ----------------------------------------------------------------------------
598
599bool wxPNGResourceHandler::LoadFile(wxBitmap *bitmap,
600 const wxString& name,
601 wxBitmapType WXUNUSED(flags),
602 int WXUNUSED(desiredWidth),
603 int WXUNUSED(desiredHeight))
604{
605 const void* pngData = NULL;
606 size_t pngSize = 0;
607
608 // Currently we hardcode RCDATA resource type as this is what is usually
609 // used for the embedded images. We could allow specifying the type as part
610 // of the name in the future (e.g. "type:name" or something like this) if
611 // really needed.
612 if ( !wxLoadUserResource(&pngData, &pngSize,
613 name,
614 RT_RCDATA,
615 wxGetInstance()) )
616 {
617 // Notice that this message is not translated because only the
618 // programmer (and not the end user) can make any use of it.
619 wxLogError(wxS("Bitmap in PNG format \"%s\" not found, check ")
620 wxS("that the resource file contains \"RCDATA\" ")
621 wxS("resource with this name."),
622 name);
623
624 return false;
625 }
626
627 *bitmap = wxBitmap::NewFromPNGData(pngData, pngSize);
628 if ( !bitmap->IsOk() )
629 {
630 wxLogError(wxS("Couldn't load resource bitmap \"%s\" as a PNG. "),
631 wxS("Have you registered PNG image handler?"),
632 name);
633
634 return false;
635 }
636
637 return true;
638}
639
640#endif // wxUSE_PNG_RESOURCE_HANDLER
641
0d0512bd
VZ
642// ----------------------------------------------------------------------------
643// private functions
644// ----------------------------------------------------------------------------
645
0c0d1521 646wxSize wxGetHiconSize(HICON WXUNUSED_IN_WINCE(hicon))
0d0512bd 647{
ab3d29ea 648 wxSize size;
7010702f 649
4676948b 650#ifndef __WXWINCE__
ab3d29ea 651 if ( hicon )
0d0512bd
VZ
652 {
653 ICONINFO info;
654 if ( !::GetIconInfo(hicon, &info) )
655 {
f6bcfd97 656 wxLogLastError(wxT("GetIconInfo"));
0d0512bd
VZ
657 }
658 else
659 {
660 HBITMAP hbmp = info.hbmMask;
661 if ( hbmp )
662 {
663 BITMAP bm;
664 if ( ::GetObject(hbmp, sizeof(BITMAP), (LPSTR) &bm) )
665 {
666 size = wxSize(bm.bmWidth, bm.bmHeight);
667 }
668
669 ::DeleteObject(info.hbmMask);
670 }
671 if ( info.hbmColor )
672 ::DeleteObject(info.hbmColor);
673 }
674 }
ab3d29ea
VZ
675
676 if ( !size.x )
677#endif // !__WXWINCE__
678 {
679 // use default icon size on this hardware
680 size.x = ::GetSystemMetrics(SM_CXICON);
681 size.y = ::GetSystemMetrics(SM_CYICON);
682 }
0c0d1521 683
0d0512bd
VZ
684 return size;
685}
474df218
VZ
686
687#endif // __WXMICROWIN__