]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/anidecod.cpp
Return NULL from wxWindow::GetCapture() when the capture is being lost.
[wxWidgets.git] / src / common / anidecod.cpp
index ee6f88ab0a43db7f714586b4db1355419f77c6e9..d62c00b45535a92df7101c14aa72b02364975d94 100644 (file)
@@ -2,7 +2,6 @@
 // Name:        src/common/anidecod.cpp
 // Purpose:     wxANIDecoder, ANI reader for wxImage and wxAnimation
 // Author:      Francesco Montorsi
-// RCS-ID:      $Id$
 // Copyright:   (c) Francesco Montorsi
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -113,10 +112,10 @@ wxColour wxANIDecoder::GetTransparentColour(unsigned int frame) const
 // ANI reading and decoding
 //---------------------------------------------------------------------------
 
-bool wxANIDecoder::CanRead(wxInputStream& stream) const
+bool wxANIDecoder::DoCanRead(wxInputStream& stream) const
 {
     wxInt32 FCC1, FCC2;
-    wxUint32 datalen ;
+    wxUint32 datalen;
 
     wxInt32 riff32;
     memcpy( &riff32, "RIFF", 4 );
@@ -127,7 +126,11 @@ bool wxANIDecoder::CanRead(wxInputStream& stream) const
     wxInt32 anih32;
     memcpy( &anih32, "anih", 4 );
 
-    stream.SeekI(0);
+    if ( stream.IsSeekable() && stream.SeekI(0) == wxInvalidOffset )
+    {
+        return false;
+    }
+
     if ( !stream.Read(&FCC1, 4) )
         return false;
 
@@ -154,7 +157,8 @@ bool wxANIDecoder::CanRead(wxInputStream& stream) const
         }
         else
         {
-            stream.SeekI(stream.TellI() + datalen);
+            if ( stream.SeekI(stream.TellI() + datalen) == wxInvalidOffset )
+                return false;
         }
 
         // try to read next data chunk:
@@ -220,8 +224,13 @@ bool wxANIDecoder::Load( wxInputStream& stream )
     wxInt32 seq32;
     memcpy( &seq32, "seq ", 4 );
 
-    stream.SeekI(0);
-    stream.Read(&FCC1, 4);
+    if ( stream.IsSeekable() && stream.SeekI(0) == wxInvalidOffset )
+    {
+        return false;
+    }
+
+    if ( !stream.Read(&FCC1, 4) )
+        return false;
     if ( FCC1 != riff32 )
         return false;
 
@@ -232,10 +241,12 @@ bool wxANIDecoder::Load( wxInputStream& stream )
     m_info.Clear();
 
     // we have a riff file:
-    while ( stream.IsOk() )
+    while ( !stream.Eof() )
     {
         // we always have a data size:
-        stream.Read(&datalen, 4);
+        if (!stream.Read(&datalen, 4))
+            return false;
+
         datalen = wxINT32_SWAP_ON_BE(datalen);
 
         //data should be padded to make even number of bytes
@@ -244,7 +255,8 @@ bool wxANIDecoder::Load( wxInputStream& stream )
         // now either data or a FCC:
         if ( (FCC1 == riff32) || (FCC1 == list32) )
         {
-            stream.Read(&FCC2, 4);
+            if (!stream.Read(&FCC2, 4))
+                return false;
         }
         else if ( FCC1 == anih32 )
         {
@@ -255,7 +267,8 @@ bool wxANIDecoder::Load( wxInputStream& stream )
                 return false;       // already parsed an ani header?
 
             struct wxANIHeader header;
-            stream.Read(&header, sizeof(wxANIHeader));
+            if (!stream.Read(&header, sizeof(wxANIHeader)))
+                return false;
             header.AdjustEndianness();
 
             // we should have a global frame size
@@ -280,7 +293,8 @@ bool wxANIDecoder::Load( wxInputStream& stream )
             wxASSERT(m_info.GetCount() == m_nFrames);
             for (unsigned int i=0; i<m_nFrames; i++)
             {
-                stream.Read(&FCC2, 4);
+                if (!stream.Read(&FCC2, 4))
+                    return false;
                 m_info[i].m_delay = wxINT32_SWAP_ON_BE(FCC2) * 1000 / 60;
             }
         }
@@ -293,7 +307,8 @@ bool wxANIDecoder::Load( wxInputStream& stream )
             wxASSERT(m_info.GetCount() == m_nFrames);
             for (unsigned int i=0; i<m_nFrames; i++)
             {
-                stream.Read(&FCC2, 4);
+                if (!stream.Read(&FCC2, 4))
+                    return false;
                 m_info[i].m_imageIndex = wxINT32_SWAP_ON_BE(FCC2);
             }
         }
@@ -304,15 +319,23 @@ bool wxANIDecoder::Load( wxInputStream& stream )
             if (!sm_handler.DoLoadFile(&image, stream, false /* verbose */, -1))
                 return false;
 
+            image.SetType(wxBITMAP_TYPE_ANI);
             m_images.Add(image);
         }
         else
         {
-            stream.SeekI(stream.TellI() + datalen);
+            if ( stream.SeekI(stream.TellI() + datalen) == wxInvalidOffset )
+                return false;
         }
 
         // try to read next data chunk:
-        stream.Read(&FCC1, 4);
+        if ( !stream.Read(&FCC1, 4) && !stream.Eof())
+        {
+            // we didn't reach the EOF! An other kind of error has occurred...
+            return false;
+        }
+        //else: proceed with the parsing of the next header block or
+        //      exiting this loop (if stream.Eof() == true)
     }
 
     if (m_nFrames==0)