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:
parent
c21b99e0e2
commit
327972e7b6
@ -243,7 +243,11 @@ protected:
|
|||||||
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
||||||
#include "wx/x11/bitmap.h"
|
#include "wx/x11/bitmap.h"
|
||||||
#elif defined(__WXGTK20__)
|
#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"
|
#include "wx/gtk/bitmap.h"
|
||||||
#elif defined(__WXGTK__)
|
#elif defined(__WXGTK__)
|
||||||
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
||||||
|
@ -41,7 +41,11 @@ public:
|
|||||||
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XBM
|
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XBM
|
||||||
#include "wx/motif/cursor.h"
|
#include "wx/motif/cursor.h"
|
||||||
#elif defined(__WXGTK20__)
|
#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"
|
#include "wx/gtk/cursor.h"
|
||||||
#elif defined(__WXGTK__)
|
#elif defined(__WXGTK__)
|
||||||
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
#define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
||||||
|
@ -174,7 +174,7 @@ enum wxStockCursor
|
|||||||
wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux
|
wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WINDOWS__
|
||||||
// Load from a resource
|
// Load from a resource
|
||||||
#define wxICON(X) wxIcon(wxT(#X))
|
#define wxICON(X) wxIcon(wxT(#X))
|
||||||
#elif defined(__WXPM__)
|
#elif defined(__WXPM__)
|
||||||
@ -204,7 +204,7 @@ enum wxStockCursor
|
|||||||
under Unix bitmaps live in XPMs and under Windows they're in ressources.
|
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)
|
#define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_BMP_RESOURCE)
|
||||||
#elif defined(__WXGTK__) || \
|
#elif defined(__WXGTK__) || \
|
||||||
defined(__WXMOTIF__) || \
|
defined(__WXMOTIF__) || \
|
||||||
|
@ -30,7 +30,11 @@
|
|||||||
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
||||||
#include "wx/motif/icon.h"
|
#include "wx/motif/icon.h"
|
||||||
#elif defined(__WXGTK20__)
|
#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"
|
#include "wx/generic/icon.h"
|
||||||
#elif defined(__WXGTK__)
|
#elif defined(__WXGTK__)
|
||||||
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
#define wxICON_DEFAULT_TYPE wxBITMAP_TYPE_XPM
|
||||||
|
@ -2235,10 +2235,102 @@ bool wxImage::HasOption(const wxString& name) const
|
|||||||
// image I/O
|
// image I/O
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool wxImage::LoadFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename),
|
// Under Windows we can load wxImage not only from files but also from
|
||||||
wxBitmapType WXUNUSED_UNLESS_STREAMS(type),
|
// 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) )
|
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
|
#if HAS_FILE_STREAMS
|
||||||
wxImageFileInputStream stream(filename);
|
wxImageFileInputStream stream(filename);
|
||||||
if ( stream.IsOk() )
|
if ( stream.IsOk() )
|
||||||
|
Loading…
Reference in New Issue
Block a user