]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/stream.cpp
Don't use "Cancel" button in the about dialog of the listctrl sample.
[wxWidgets.git] / src / common / stream.cpp
index a3142a2843e2a600da70f9b8c4e37e4f19e3e483..f7cd2ea2c58db63aa52248adc2857100f501c1e5 100644 (file)
@@ -36,6 +36,7 @@
 #include <ctype.h>
 #include "wx/datstrm.h"
 #include "wx/textfile.h"
 #include <ctype.h>
 #include "wx/datstrm.h"
 #include "wx/textfile.h"
+#include "wx/scopeguard.h"
 
 // ----------------------------------------------------------------------------
 // constants
 
 // ----------------------------------------------------------------------------
 // constants
@@ -635,7 +636,7 @@ wxFileOffset wxStreamBuffer::Seek(wxFileOffset pos, wxSeekMode mode)
                 size_t int_diff = wx_truncate_cast(size_t, diff);
                 wxCHECK_MSG( (wxFileOffset)int_diff == diff, wxInvalidOffset, wxT("huge file not supported") );
                 SetIntPosition(int_diff);
                 size_t int_diff = wx_truncate_cast(size_t, diff);
                 wxCHECK_MSG( (wxFileOffset)int_diff == diff, wxInvalidOffset, wxT("huge file not supported") );
                 SetIntPosition(int_diff);
-                return pos;
+                return diff;
             }
 
         case wxFromEnd:
             }
 
         case wxFromEnd:
@@ -943,18 +944,18 @@ wxFileOffset wxInputStream::SeekI(wxFileOffset pos, wxSeekMode mode)
             bytes_read = Read(buf, WXSIZEOF(buf)).LastRead();
             if ( m_lasterror != wxSTREAM_NO_ERROR )
                 return wxInvalidOffset;
             bytes_read = Read(buf, WXSIZEOF(buf)).LastRead();
             if ( m_lasterror != wxSTREAM_NO_ERROR )
                 return wxInvalidOffset;
-            
+
             wxASSERT(bytes_read == WXSIZEOF(buf));
         }
             wxASSERT(bytes_read == WXSIZEOF(buf));
         }
-        
+
         // read the last 'pos' bytes
         bytes_read = Read(buf, (size_t)pos).LastRead();
         if ( m_lasterror != wxSTREAM_NO_ERROR )
             return wxInvalidOffset;
         // read the last 'pos' bytes
         bytes_read = Read(buf, (size_t)pos).LastRead();
         if ( m_lasterror != wxSTREAM_NO_ERROR )
             return wxInvalidOffset;
-        
+
         wxASSERT(bytes_read == (size_t)pos);
         wxASSERT(bytes_read == (size_t)pos);
-        
-        // we should now have seeked to the right position...
+
+        // we should now have sought to the right position...
         return TellI();
     }
 
         return TellI();
     }
 
@@ -1446,6 +1447,93 @@ void wxBufferedOutputStream::SetOutputStreamBuffer(wxStreamBuffer *buffer)
     m_o_streambuf = buffer;
 }
 
     m_o_streambuf = buffer;
 }
 
+// ---------------------------------------------------------------------------
+// wxWrapperInputStream implementation
+// ---------------------------------------------------------------------------
+
+wxWrapperInputStream::wxWrapperInputStream()
+{
+    m_lasterror = wxSTREAM_READ_ERROR;
+}
+
+wxWrapperInputStream::wxWrapperInputStream(wxInputStream& stream)
+    : wxFilterInputStream(stream)
+{
+    SynchronizeLastError();
+}
+
+wxWrapperInputStream::wxWrapperInputStream(wxInputStream *stream)
+    : wxFilterInputStream(stream)
+{
+    if ( m_parent_i_stream )
+        SynchronizeLastError();
+    else
+        m_lasterror = wxSTREAM_READ_ERROR;
+}
+
+void wxWrapperInputStream::InitParentStream(wxInputStream& stream)
+{
+    wxCHECK_RET( !m_parent_i_stream, "Can't init parent stream twice" );
+
+    m_parent_i_stream = &stream;
+
+    SynchronizeLastError();
+}
+
+void wxWrapperInputStream::InitParentStream(wxInputStream* stream)
+{
+    wxCHECK_RET( !m_parent_i_stream, "Can't init parent stream twice" );
+
+    m_parent_i_stream = stream;
+
+    if ( m_parent_i_stream )
+    {
+        m_owns = true;
+
+        SynchronizeLastError();
+    }
+}
+
+wxFileOffset wxWrapperInputStream::GetLength() const
+{
+    wxCHECK_MSG(m_parent_i_stream, wxInvalidOffset, "Stream not valid");
+
+    wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError);
+    return m_parent_i_stream->GetLength();
+}
+
+bool wxWrapperInputStream::IsSeekable() const
+{
+    wxCHECK_MSG(m_parent_i_stream, false, "Stream not valid");
+    return m_parent_i_stream->IsSeekable();
+}
+
+size_t wxWrapperInputStream::OnSysRead(void *buffer, size_t size)
+{
+    wxCHECK_MSG(m_parent_i_stream, false, "Stream not valid");
+
+    wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError);
+
+    m_parent_i_stream->Read(buffer, size);
+    return m_parent_i_stream->LastRead();
+}
+
+wxFileOffset wxWrapperInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
+{
+    wxCHECK_MSG(IsSeekable(), false, "Stream not seekable");
+
+    wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError);
+    return m_parent_i_stream->SeekI (pos, mode);
+}
+
+wxFileOffset wxWrapperInputStream::OnSysTell() const
+{
+    wxCHECK_MSG(m_parent_i_stream, false, "Stream not valid");
+
+    wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError);
+    return m_parent_i_stream->TellI();
+}
+
 // ----------------------------------------------------------------------------
 // Some IOManip function
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // Some IOManip function
 // ----------------------------------------------------------------------------