X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/39d16996b7616bf8090b140db74fd0b52d50d169..a949e8fac2666418b2a6eb15e94959563cf8aad6:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index 3241ed03cd..5a357beca3 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -964,7 +964,7 @@ bool wxImage::SaveFile( const wxString& filename, int type ) const wxFileOutputStream stream(filename); - if ( stream.LastError() == wxStream_NOERROR ) + if ( stream.IsOk() ) { wxBufferedOutputStream bstream( stream ); return SaveFile(bstream, type); @@ -981,7 +981,7 @@ bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) con wxFileOutputStream stream(filename); - if ( stream.LastError() == wxStream_NOERROR ) + if ( stream.IsOk() ) { wxBufferedOutputStream bstream( stream ); return SaveFile(bstream, mimetype); @@ -1005,10 +1005,11 @@ int wxImage::GetImageCount( const wxString &name, long type ) { #if wxUSE_STREAMS wxFileInputStream stream(name); - return GetImageCount(stream, type); -#else - return 0; + if (stream.Ok()) + return GetImageCount(stream, type); #endif + + return 0; } #if wxUSE_STREAMS @@ -1092,7 +1093,7 @@ bool wxImage::LoadFile( wxInputStream& stream, long type, int index ) handler = FindHandler(type); - if (handler == NULL) + if (handler == 0) { wxLogWarning( _("No image handler for type %d defined."), type ); @@ -1110,7 +1111,7 @@ bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int ind wxImageHandler *handler = FindHandlerMime(mimetype); - if (handler == NULL) + if (handler == 0) { wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() ); @@ -1126,7 +1127,7 @@ bool wxImage::SaveFile( wxOutputStream& stream, int type ) const wxImageHandler *handler = FindHandler(type); - if (handler == NULL) + if (handler == 0) { wxLogWarning( _("No image handler for type %d defined."), type ); @@ -1142,7 +1143,7 @@ bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const wxImageHandler *handler = FindHandlerMime(mimetype); - if (handler == NULL) + if (handler == 0) { wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() ); @@ -1158,7 +1159,23 @@ void wxImage::AddHandler( wxImageHandler *handler ) // make sure that the memory will be freed at the program end sm_handlers.DeleteContents(TRUE); - sm_handlers.Append( handler ); + // Check for an existing handler of the type being added. + if (FindHandler( handler->GetType() ) == 0) + { + sm_handlers.Append( handler ); + } + else + { + // This is not documented behaviour, merely the simplest 'fix' + // for preventing duplicate additions. If someone ever has + // a good reason to add and remove duplicate handlers (and they + // may) we should probably refcount the duplicates. + // also an issue in InsertHandler below. + + wxLogDebug( _T("Adding duplicate image handler for '%s'"), + handler->GetName().c_str() ); + delete handler; + } } void wxImage::InsertHandler( wxImageHandler *handler ) @@ -1166,7 +1183,18 @@ void wxImage::InsertHandler( wxImageHandler *handler ) // make sure that the memory will be freed at the program end sm_handlers.DeleteContents(TRUE); - sm_handlers.Insert( handler ); + // Check for an existing handler of the type being added. + if (FindHandler( handler->GetType() ) == 0) + { + sm_handlers.Insert( handler ); + } + else + { + // see AddHandler for additional comments. + wxLogDebug( _T("Inserting duplicate image handler for '%s'"), + handler->GetName().c_str() ); + delete handler; + } } bool wxImage::RemoveHandler( const wxString& name ) @@ -1191,7 +1219,7 @@ wxImageHandler *wxImage::FindHandler( const wxString& name ) node = node->Next(); } - return (wxImageHandler *)NULL; + return 0; } wxImageHandler *wxImage::FindHandler( const wxString& extension, long bitmapType ) @@ -1205,7 +1233,7 @@ wxImageHandler *wxImage::FindHandler( const wxString& extension, long bitmapType return handler; node = node->Next(); } - return (wxImageHandler*)NULL; + return 0; } wxImageHandler *wxImage::FindHandler( long bitmapType ) @@ -1217,7 +1245,7 @@ wxImageHandler *wxImage::FindHandler( long bitmapType ) if (handler->GetType() == bitmapType) return handler; node = node->Next(); } - return NULL; + return 0; } wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype ) @@ -1229,7 +1257,7 @@ wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype ) if (handler->GetMimeType().IsSameAs(mimetype, FALSE)) return handler; node = node->Next(); } - return NULL; + return 0; } void wxImage::InitStandardHandlers() @@ -1237,10 +1265,6 @@ void wxImage::InitStandardHandlers() #if wxUSE_STREAMS AddHandler(new wxBMPHandler); #endif // wxUSE_STREAMS - -#if wxUSE_XPM && !defined(__WXGTK__) && !defined(__WXMOTIF__) - AddHandler(new wxXPMHandler); -#endif } void wxImage::CleanUpHandlers() @@ -1319,7 +1343,7 @@ bool wxImageHandler::CallDoCanRead(wxInputStream& stream) //----------------------------------------------------------------------------- -// Deprecated wxBitmap convertion routines +// Deprecated wxBitmap conversion routines //----------------------------------------------------------------------------- #if WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI