#endif // wxUSE_PALETTE
wxArrayString m_optionNames;
wxArrayString m_optionValues;
+
+ DECLARE_NO_COPY_CLASS(wxImageRefData)
};
wxImageRefData::wxImageRefData()
wxFileOutputStream stream(filename);
- if ( stream.LastError() == wxStream_NOERROR )
+ if ( stream.IsOk() )
{
wxBufferedOutputStream bstream( stream );
return SaveFile(bstream, type);
wxFileOutputStream stream(filename);
- if ( stream.LastError() == wxStream_NOERROR )
+ if ( stream.IsOk() )
{
wxBufferedOutputStream bstream( stream );
return SaveFile(bstream, mimetype);
{
#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
handler = FindHandler(type);
- if (handler == NULL)
+ if (handler == 0)
{
wxLogWarning( _("No image handler for type %d defined."), type );
wxImageHandler *handler = FindHandlerMime(mimetype);
- if (handler == NULL)
+ if (handler == 0)
{
wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
wxImageHandler *handler = FindHandler(type);
- if (handler == NULL)
+ if (handler == 0)
{
wxLogWarning( _("No image handler for type %d defined."), type );
wxImageHandler *handler = FindHandlerMime(mimetype);
- if (handler == NULL)
+ if (handler == 0)
{
wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
// 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 )
// 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 )
wxImageHandler *wxImage::FindHandler( const wxString& name )
{
- wxNode *node = sm_handlers.First();
+ wxNode *node = sm_handlers.GetFirst();
while (node)
{
- wxImageHandler *handler = (wxImageHandler*)node->Data();
+ wxImageHandler *handler = (wxImageHandler*)node->GetData();
if (handler->GetName().Cmp(name) == 0) return handler;
- node = node->Next();
+ node = node->GetNext();
}
- return (wxImageHandler *)NULL;
+ return 0;
}
wxImageHandler *wxImage::FindHandler( const wxString& extension, long bitmapType )
{
- wxNode *node = sm_handlers.First();
+ wxNode *node = sm_handlers.GetFirst();
while (node)
{
- wxImageHandler *handler = (wxImageHandler*)node->Data();
+ wxImageHandler *handler = (wxImageHandler*)node->GetData();
if ( (handler->GetExtension().Cmp(extension) == 0) &&
(bitmapType == -1 || handler->GetType() == bitmapType) )
return handler;
- node = node->Next();
+ node = node->GetNext();
}
- return (wxImageHandler*)NULL;
+ return 0;
}
wxImageHandler *wxImage::FindHandler( long bitmapType )
{
- wxNode *node = sm_handlers.First();
+ wxNode *node = sm_handlers.GetFirst();
while (node)
{
- wxImageHandler *handler = (wxImageHandler *)node->Data();
+ wxImageHandler *handler = (wxImageHandler *)node->GetData();
if (handler->GetType() == bitmapType) return handler;
- node = node->Next();
+ node = node->GetNext();
}
- return NULL;
+ return 0;
}
wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype )
{
- wxNode *node = sm_handlers.First();
+ wxNode *node = sm_handlers.GetFirst();
while (node)
{
- wxImageHandler *handler = (wxImageHandler *)node->Data();
+ wxImageHandler *handler = (wxImageHandler *)node->GetData();
if (handler->GetMimeType().IsSameAs(mimetype, FALSE)) return handler;
- node = node->Next();
+ node = node->GetNext();
}
- return NULL;
+ return 0;
}
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()
{
- wxNode *node = sm_handlers.First();
+ wxNode *node = sm_handlers.GetFirst();
while (node)
{
- wxImageHandler *handler = (wxImageHandler *)node->Data();
- wxNode *next = node->Next();
+ wxImageHandler *handler = (wxImageHandler *)node->GetData();
+ wxNode *next = node->GetNext();
delete handler;
delete node;
node = next;
return CanRead(stream);
}
- else {
- wxLogError( _("Can't check image format of file '%s': file does not exist."), name.c_str() );
+ wxLogError( _("Can't check image format of file '%s': file does not exist."), name.c_str() );
+
+ return FALSE;
+}
+bool wxImageHandler::CallDoCanRead(wxInputStream& stream)
+{
+ off_t posOld = stream.TellI();
+ if ( posOld == wxInvalidOffset )
+ {
+ // can't test unseekable stream
return FALSE;
}
-// return FALSE;
+
+ bool ok = DoCanRead(stream);
+
+ // restore the old position to be able to test other formats and so on
+ if ( stream.SeekI(posOld) == wxInvalidOffset )
+ {
+ wxLogDebug(_T("Failed to rewind the stream in wxImageHandler!"));
+
+ // reading would fail anyhow as we're not at the right position
+ return FALSE;
+ }
+
+ return ok;
}
#endif // wxUSE_STREAMS
//-----------------------------------------------------------------------------
-// Deprecated wxBitmap convertion routines
+// Deprecated wxBitmap conversion routines
//-----------------------------------------------------------------------------
#if WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI