Refactored the previous commit regarding wxIconBundle support for icons stored MS Windows resources.
This commit is contained in:
@@ -58,7 +58,7 @@ public:
|
|||||||
// initializes the bundle with a single icon
|
// initializes the bundle with a single icon
|
||||||
wxIconBundle(const wxIcon& icon);
|
wxIconBundle(const wxIcon& icon);
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#if defined( __WINDOWS__) && wxUSE_ICO_CUR
|
||||||
// initializes the bundle with the icons from a group icon stored as an MS Windows resource
|
// initializes the bundle with the icons from a group icon stored as an MS Windows resource
|
||||||
wxIconBundle(const wxString& resourceName, WXHINSTANCE module);
|
wxIconBundle(const wxString& resourceName, WXHINSTANCE module);
|
||||||
#endif
|
#endif
|
||||||
@@ -75,7 +75,7 @@ public:
|
|||||||
void AddIcon(wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY);
|
void AddIcon(wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY);
|
||||||
#endif // wxUSE_STREAMS && wxUSE_IMAGE
|
#endif // wxUSE_STREAMS && wxUSE_IMAGE
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#if defined( __WINDOWS__) && wxUSE_ICO_CUR
|
||||||
// loads all the icons from a group icon stored in an MS Windows resource
|
// loads all the icons from a group icon stored in an MS Windows resource
|
||||||
void AddIcon(const wxString& resourceName, WXHINSTANCE module);
|
void AddIcon(const wxString& resourceName, WXHINSTANCE module);
|
||||||
#endif
|
#endif
|
||||||
|
94
include/wx/private/icondir.h
Normal file
94
include/wx/private/icondir.h
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/private/icondir.h
|
||||||
|
// Purpose: Declarations of structs used for loading MS icons
|
||||||
|
// Author: wxWidgets team
|
||||||
|
// Created: 2017-05-19
|
||||||
|
// Copyright: (c) 2017 wxWidgets team
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_PRIVATE_ICONDIR_H_
|
||||||
|
#define _WX_PRIVATE_ICONDIR_H_
|
||||||
|
|
||||||
|
#include "wx/defs.h" // wxUint* declarations
|
||||||
|
|
||||||
|
|
||||||
|
// Structs declared here are used for loading group icons from
|
||||||
|
// .ICO files or MS Windows resources.
|
||||||
|
// Icon entry and directory structs for .ICO files and
|
||||||
|
// MS Windows resources are very similar but not identical.
|
||||||
|
|
||||||
|
|
||||||
|
#if wxUSE_ICO_CUR
|
||||||
|
|
||||||
|
|
||||||
|
#if wxUSE_STREAMS
|
||||||
|
|
||||||
|
// icon entry in .ICO files
|
||||||
|
struct ICONDIRENTRY
|
||||||
|
{
|
||||||
|
wxUint8 bWidth; // Width of the image
|
||||||
|
wxUint8 bHeight; // Height of the image (times 2)
|
||||||
|
wxUint8 bColorCount; // Number of colors in image (0 if >=8bpp)
|
||||||
|
wxUint8 bReserved; // Reserved
|
||||||
|
|
||||||
|
// these two are different in icons and cursors:
|
||||||
|
// icon or cursor
|
||||||
|
wxUint16 wPlanes; // Color Planes or XHotSpot
|
||||||
|
wxUint16 wBitCount; // Bits per pixel or YHotSpot
|
||||||
|
|
||||||
|
wxUint32 dwBytesInRes; // how many bytes in this resource?
|
||||||
|
wxUint32 dwImageOffset; // where in the file is this image
|
||||||
|
};
|
||||||
|
|
||||||
|
// icon directory in .ICO files
|
||||||
|
struct ICONDIR
|
||||||
|
{
|
||||||
|
wxUint16 idReserved; // Reserved
|
||||||
|
wxUint16 idType; // resource type (1 for icons, 2 for cursors)
|
||||||
|
wxUint16 idCount; // how many images?
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // #if wxUSE_STREAMS
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
|
||||||
|
#pragma pack(push)
|
||||||
|
#pragma pack(2)
|
||||||
|
|
||||||
|
// icon entry in MS Windows resources
|
||||||
|
struct GRPICONDIRENTRY
|
||||||
|
{
|
||||||
|
wxUint8 bWidth; // Width of the image
|
||||||
|
wxUint8 bHeight; // Height of the image (times 2)
|
||||||
|
wxUint8 bColorCount; // Number of colors in image (0 if >=8bpp)
|
||||||
|
wxUint8 bReserved; // Reserved
|
||||||
|
|
||||||
|
// these two are different in icons and cursors:
|
||||||
|
// icon or cursor
|
||||||
|
wxUint16 wPlanes; // Color Planes or XHotSpot
|
||||||
|
wxUint16 wBitCount; // Bits per pixel or YHotSpot
|
||||||
|
|
||||||
|
wxUint32 dwBytesInRes; // how many bytes in this resource?
|
||||||
|
|
||||||
|
wxUint16 nID; // actual icon resource ID
|
||||||
|
};
|
||||||
|
|
||||||
|
// icon directory in MS Windows resources
|
||||||
|
struct GRPICONDIR
|
||||||
|
{
|
||||||
|
wxUint16 idReserved; // Reserved
|
||||||
|
wxUint16 idType; // resource type (1 for icons, 2 for cursors)
|
||||||
|
wxUint16 idCount; // how many images?
|
||||||
|
GRPICONDIRENTRY idEntries[1]; // The entries for each image
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
#endif // #ifdef __WINDOWS__
|
||||||
|
|
||||||
|
|
||||||
|
#endif // #if wxUSE_ICO_CUR
|
||||||
|
|
||||||
|
#endif // #ifndef _WX_PRIVATE_ICONDIR_H_
|
@@ -31,6 +31,10 @@
|
|||||||
|
|
||||||
#include "wx/wfstream.h"
|
#include "wx/wfstream.h"
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
#include "wx/private/icondir.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "wx/arrimpl.cpp"
|
#include "wx/arrimpl.cpp"
|
||||||
WX_DEFINE_OBJARRAY(wxIconArray)
|
WX_DEFINE_OBJARRAY(wxIconArray)
|
||||||
|
|
||||||
@@ -93,7 +97,7 @@ wxIconBundle::wxIconBundle(const wxIcon& icon)
|
|||||||
AddIcon(icon);
|
AddIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#if defined( __WINDOWS__) && wxUSE_ICO_CUR
|
||||||
|
|
||||||
wxIconBundle::wxIconBundle(const wxString& resourceName, WXHINSTANCE module)
|
wxIconBundle::wxIconBundle(const wxString& resourceName, WXHINSTANCE module)
|
||||||
: wxGDIObject()
|
: wxGDIObject()
|
||||||
@@ -101,7 +105,7 @@ wxIconBundle::wxIconBundle(const wxString& resourceName, WXHINSTANCE module)
|
|||||||
AddIcon(resourceName, module);
|
AddIcon(resourceName, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif #if defined( __WINDOWS__) && wxUSE_ICO_CUR
|
||||||
|
|
||||||
wxGDIRefData *wxIconBundle::CreateGDIRefData() const
|
wxGDIRefData *wxIconBundle::CreateGDIRefData() const
|
||||||
{
|
{
|
||||||
@@ -206,40 +210,7 @@ void wxIconBundle::AddIcon(wxInputStream& stream, wxBitmapType type)
|
|||||||
|
|
||||||
#endif // wxUSE_STREAMS && wxUSE_IMAGE
|
#endif // wxUSE_STREAMS && wxUSE_IMAGE
|
||||||
|
|
||||||
|
#if defined( __WINDOWS__) && wxUSE_ICO_CUR
|
||||||
#ifdef __WINDOWS__
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// struct declarations taken from https://msdn.microsoft.com/en-us/library/ms997538.aspx
|
|
||||||
#pragma pack(push)
|
|
||||||
#pragma pack(2)
|
|
||||||
|
|
||||||
// individual icon entry in the icon directory resource
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
BYTE bWidth; // Width, in pixels, of the image
|
|
||||||
BYTE bHeight; // Height, in pixels, of the image
|
|
||||||
BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
|
|
||||||
BYTE bReserved; // Reserved
|
|
||||||
WORD wPlanes; // Color Planes
|
|
||||||
WORD wBitCount; // Bits per pixel
|
|
||||||
DWORD dwBytesInRes; // how many bytes in this resource?
|
|
||||||
WORD nID; // the ID
|
|
||||||
} GRPICONDIRENTRY, *LPGRPICONDIRENTRY;
|
|
||||||
|
|
||||||
// icon directory resource
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
WORD idReserved; // Reserved (must be 0)
|
|
||||||
WORD idType; // Resource type (1 for icons)
|
|
||||||
WORD idCount; // How many images?
|
|
||||||
GRPICONDIRENTRY idEntries[1]; // The entries for each image
|
|
||||||
} GRPICONDIR, *LPGRPICONDIR;
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
} // anonymous namespace
|
|
||||||
|
|
||||||
// Loads all the icons for an icon group (i.e., different sizes of one icon)
|
// Loads all the icons for an icon group (i.e., different sizes of one icon)
|
||||||
// stored as an MS Windows resource.
|
// stored as an MS Windows resource.
|
||||||
@@ -250,7 +221,10 @@ void wxIconBundle::AddIcon(const wxString& resourceName, WXHINSTANCE module)
|
|||||||
|
|
||||||
// load the icon directory resource
|
// load the icon directory resource
|
||||||
if ( !wxLoadUserResource(&data, &outLen, resourceName, RT_GROUP_ICON, module) )
|
if ( !wxLoadUserResource(&data, &outLen, resourceName, RT_GROUP_ICON, module) )
|
||||||
|
{
|
||||||
|
wxLogError(_("Failed to load icons from resource '%s'."), resourceName);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// load the individual icons referred from the icon directory
|
// load the individual icons referred from the icon directory
|
||||||
const GRPICONDIR* grpIconDir = static_cast<const GRPICONDIR*>(data);
|
const GRPICONDIR* grpIconDir = static_cast<const GRPICONDIR*>(data);
|
||||||
@@ -268,12 +242,16 @@ void wxIconBundle::AddIcon(const wxString& resourceName, WXHINSTANCE module)
|
|||||||
if ( hIcon && icon.CreateFromHICON(hIcon) )
|
if ( hIcon && icon.CreateFromHICON(hIcon) )
|
||||||
AddIcon(icon);
|
AddIcon(icon);
|
||||||
else
|
else
|
||||||
wxLogDebug(wxS("Could not create icon from resource with id %u."), iconID);
|
wxLogDebug(wxS("Failed to create icon from resource with id %u."), iconID);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogDebug(wxS("Failed to load icon with id %u for group icon resource '%s'."), iconID, resourceName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // #if defined( __WINDOWS__) && wxUSE_ICO_CUR
|
||||||
|
|
||||||
wxIcon wxIconBundle::GetIcon(const wxSize& size, int flags) const
|
wxIcon wxIconBundle::GetIcon(const wxSize& size, int flags) const
|
||||||
{
|
{
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include "wx/scopedarray.h"
|
#include "wx/scopedarray.h"
|
||||||
#include "wx/scopedptr.h"
|
#include "wx/scopedptr.h"
|
||||||
#include "wx/anidecod.h"
|
#include "wx/anidecod.h"
|
||||||
|
#include "wx/private/icondir.h"
|
||||||
|
|
||||||
// For memcpy
|
// For memcpy
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -1241,30 +1242,6 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxICOHandler, wxBMPHandler);
|
|||||||
|
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
|
|
||||||
struct ICONDIRENTRY
|
|
||||||
{
|
|
||||||
wxUint8 bWidth; // Width of the image
|
|
||||||
wxUint8 bHeight; // Height of the image (times 2)
|
|
||||||
wxUint8 bColorCount; // Number of colors in image (0 if >=8bpp)
|
|
||||||
wxUint8 bReserved; // Reserved
|
|
||||||
|
|
||||||
// these two are different in icons and cursors:
|
|
||||||
// icon or cursor
|
|
||||||
wxUint16 wPlanes; // Color Planes or XHotSpot
|
|
||||||
wxUint16 wBitCount; // Bits per pixel or YHotSpot
|
|
||||||
|
|
||||||
wxUint32 dwBytesInRes; // how many bytes in this resource?
|
|
||||||
wxUint32 dwImageOffset; // where in the file is this image
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ICONDIR
|
|
||||||
{
|
|
||||||
wxUint16 idReserved; // Reserved
|
|
||||||
wxUint16 idType; // resource type (1 for icons, 2 for cursors)
|
|
||||||
wxUint16 idCount; // how many images?
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
bool wxICOHandler::SaveFile(wxImage *image,
|
bool wxICOHandler::SaveFile(wxImage *image,
|
||||||
wxOutputStream& stream,
|
wxOutputStream& stream,
|
||||||
bool verbose)
|
bool verbose)
|
||||||
|
Reference in New Issue
Block a user