X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cee875e32996e5c5eb8b788cfe84e2bf2a078f53..b356aa554a82f4d82f0c12abb83eb4656204fe7a:/src/common/iconbndl.cpp?ds=sidebyside diff --git a/src/common/iconbndl.cpp b/src/common/iconbndl.cpp index 825a6431e6..26073476f3 100644 --- a/src/common/iconbndl.cpp +++ b/src/common/iconbndl.cpp @@ -26,6 +26,8 @@ #include "wx/stream.h" #endif +#include "wx/wfstream.h" + #include "wx/arrimpl.cpp" WX_DEFINE_OBJARRAY(wxIconArray) @@ -55,13 +57,13 @@ wxIconBundle::wxIconBundle() { } +#if wxUSE_STREAMS wxIconBundle::wxIconBundle(const wxString& file, wxBitmapType type) : wxGDIObject() { AddIcon(file, type); } -#if wxUSE_STREAMS wxIconBundle::wxIconBundle(wxInputStream& stream, wxBitmapType type) : wxGDIObject() { @@ -90,37 +92,51 @@ void wxIconBundle::DeleteIcons() UnRef(); } +#if wxUSE_STREAMS + namespace { // Adds icon from 'input' to the bundle. Shows 'errorMessage' on failure // (it must contain "%d", because it is used to report # of image in the file // that failed to load): -template void DoAddIcon(wxIconBundle& bundle, - T& input, wxBitmapType type, + wxInputStream& input, + wxBitmapType type, const wxString& errorMessage) { -#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB) wxImage image; + const wxFileOffset posOrig = input.TellI(); + const size_t count = wxImage::GetImageCount(input, type); for ( size_t i = 0; i < count; ++i ) { + if ( i ) + { + // the call to LoadFile() for the first sub-image updated the + // stream position but we need to start reading the subsequent + // sub-image at the image beginning too + input.SeekI(posOrig); + } + if ( !image.LoadFile(input, type, i) ) { wxLogError(errorMessage, i); continue; } + if ( type == wxBITMAP_TYPE_ANY ) + { + // store the type so that we don't need to try all handlers again + // for the subsequent images, they should all be of the same type + type = image.GetType(); + } + wxIcon tmp; tmp.CopyFromBitmap(wxBitmap(image)); bundle.AddIcon(tmp); } -#else // !wxUSE_IMAGE - wxUnusedVar(input); - wxUnusedVar(type); -#endif // wxUSE_IMAGE/!wxUSE_IMAGE } } // anonymous namespace @@ -140,19 +156,20 @@ void wxIconBundle::AddIcon(const wxString& file, wxBitmapType type) } #endif // __WXMAC__ + wxFFileInputStream stream(file); DoAddIcon ( *this, - file, type, + stream, type, wxString::Format(_("Failed to load image %%d from file '%s'."), file) ); } -#if wxUSE_STREAMS void wxIconBundle::AddIcon(wxInputStream& stream, wxBitmapType type) { DoAddIcon(*this, stream, type, _("Failed to load image %d from stream.")); } + #endif // wxUSE_STREAMS wxIcon wxIconBundle::GetIcon(const wxSize& size) const