Use bitmaps from resources by default in wxGTK under Windows.

Use wxBITMAP_TYPE_{BMP,CUR,ICON}_RESOURCE by default under Windows, even for
non-wxMSW ports.

Also allow loading wxImage from resources in all ports under MSW as a side
effect of this change.

Closes #14425.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71889 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-06-30 16:33:23 +00:00
parent c21b99e0e2
commit 327972e7b6
5 changed files with 111 additions and 7 deletions

View File

@ -243,7 +243,11 @@ protected:
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
#include "wx/x11/bitmap.h"
#elif defined(__WXGTK20__)
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
#ifdef __WINDOWS__
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
#else
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
#endif
#include "wx/gtk/bitmap.h"
#elif defined(__WXGTK__)
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM

View File

@ -41,7 +41,11 @@ public:
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XBM
#include "wx/motif/cursor.h"
#elif defined(__WXGTK20__)
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XPM
#ifdef __WINDOWS__
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_CUR_RESOURCE
#else
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XPM
#endif
#include "wx/gtk/cursor.h"
#elif defined(__WXGTK__)
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XPM

View File

@ -174,7 +174,7 @@ enum wxStockCursor
wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux
*/
#ifdef __WXMSW__
#ifdef __WINDOWS__
// Load from a resource
#define wxICON(X) wxIcon(wxT(#X))
#elif defined(__WXPM__)
@ -204,7 +204,7 @@ enum wxStockCursor
under Unix bitmaps live in XPMs and under Windows they're in ressources.
*/
#if defined(__WXMSW__) || defined(__WXPM__)
#if defined(__WINDOWS__) || defined(__WXPM__)
#define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_BMP_RESOURCE)
#elif defined(__WXGTK__) || \
defined(__WXMOTIF__) || \

View File

@ -30,7 +30,11 @@
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_XPM
#include "wx/motif/icon.h"
#elif defined(__WXGTK20__)
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_XPM
#ifdef __WINDOWS__
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_ICO_RESOURCE
#else
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_XPM
#endif
#include "wx/generic/icon.h"
#elif defined(__WXGTK__)
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_XPM

View File

@ -2235,10 +2235,102 @@ bool wxImage::HasOption(const wxString& name) const
// image I/O
// ----------------------------------------------------------------------------
bool wxImage::LoadFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename),
wxBitmapType WXUNUSED_UNLESS_STREAMS(type),
// Under Windows we can load wxImage not only from files but also from
// resources.
#if defined(__WINDOWS__) && wxUSE_WXDIB && wxUSE_IMAGE
#define HAS_LOAD_FROM_RESOURCE
#endif
#ifdef HAS_LOAD_FROM_RESOURCE
#include "wx/msw/dib.h"
#include "wx/msw/private.h"
static wxImage LoadImageFromResource(const wxString &name, wxBitmapType type)
{
AutoHBITMAP
hBitmap,
hMask;
if ( type == wxBITMAP_TYPE_BMP_RESOURCE )
{
hBitmap = ::LoadBitmap(wxGetInstance(), name.t_str());
if ( !hBitmap )
{
wxLogError(_("Failed to load bitmap \"%s\" from resources."), name);
}
}
else if ( type == wxBITMAP_TYPE_ICO_RESOURCE )
{
const HICON hIcon = ::LoadIcon(wxGetInstance(), name.t_str());
if ( !hIcon )
{
wxLogError(_("Failed to load icon \"%s\" from resources."), name);
}
else
{
ICONINFO info;
if ( !::GetIconInfo(hIcon, &info) )
{
wxLogLastError(wxT("GetIconInfo"));
return wxImage();
}
hBitmap = info.hbmColor;
hMask = info.hbmMask;
}
}
else if ( type == wxBITMAP_TYPE_CUR_RESOURCE )
{
wxLogDebug(wxS("Loading cursors from resources is not implemented."));
}
else
{
wxFAIL_MSG(wxS("Invalid bitmap resource type."));
}
if ( !hBitmap )
return wxImage();
wxImage image = wxDIB(hBitmap).ConvertToImage();
if ( hMask )
{
const wxImage mask = wxDIB(hMask).ConvertToImage();
image.SetMaskFromImage(mask, 255, 255, 255);
}
else
{
// Light gray colour is a default mask
image.SetMaskColour(0xc0, 0xc0, 0xc0);
}
image.InitAlpha();
return image;
}
#endif // HAS_LOAD_FROM_RESOURCE
bool wxImage::LoadFile( const wxString& filename,
wxBitmapType type,
int WXUNUSED_UNLESS_STREAMS(index) )
{
#ifdef HAS_LOAD_FROM_RESOURCE
if ( type == wxBITMAP_TYPE_BMP_RESOURCE
|| type == wxBITMAP_TYPE_ICO_RESOURCE
|| type == wxBITMAP_TYPE_CUR_RESOURCE)
{
const wxImage image = ::LoadImageFromResource(filename, type);
if ( image.IsOk() )
{
*this = image;
return true;
}
}
#endif // HAS_LOAD_FROM_RESOURCE
#if HAS_FILE_STREAMS
wxImageFileInputStream stream(filename);
if ( stream.IsOk() )