]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fileback.cpp
Add another test for the insertion point position after SetValue().
[wxWidgets.git] / src / common / fileback.cpp
index 3ca47715627a04421daeded0c8a76beb69e1c6b8..704b54e1657f1fa54621e1c7cfd5a7831f179c90 100644 (file)
@@ -14,9 +14,9 @@
     #pragma hdrstop
 #endif
 
     #pragma hdrstop
 #endif
 
-#if wxUSE_BACKINGFILE
+#if wxUSE_FILESYSTEM
 
 
-#include "wx/fileback.h"
+#include "wx/private/fileback.h"
 
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
 
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
@@ -82,8 +82,8 @@ wxBackingFileImpl::wxBackingFileImpl(wxInputStream *stream,
 {
     wxFileOffset len = m_stream->GetLength();
 
 {
     wxFileOffset len = m_stream->GetLength();
 
-    if (len >= 0 && len + size_t(0) < m_bufsize)
-        m_bufsize = len;
+    if (len >= 0 && len + size_t(1) < m_bufsize)
+        m_bufsize = size_t(len + 1);
 
     if (m_bufsize)
         m_buf = new char[m_bufsize];
 
     if (m_bufsize)
         m_buf = new char[m_bufsize];
@@ -114,7 +114,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos,
         size1 = reqestedSize;
         size2 = 0;
     } else if (pos < m_filelen) {
         size1 = reqestedSize;
         size2 = 0;
     } else if (pos < m_filelen) {
-        size1 = m_filelen - pos;
+        size1 = size_t(m_filelen - pos);
         size2 = reqestedSize - size1;
     } else {
         size1 = 0;
         size2 = reqestedSize - size1;
     } else {
         size1 = 0;
@@ -168,11 +168,9 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos,
                     m_filelen += count;
 
                     if (count < m_buflen) {
                     m_filelen += count;
 
                     if (count < m_buflen) {
-                        delete m_stream;
-                        m_stream = NULL;
+                        wxDELETE(m_stream);
                         if (count > 0) {
                         if (count > 0) {
-                            delete m_buf;
-                            m_buf = NULL;
+                            wxDELETEA(m_buf);
                             m_buflen = 0;
                         }
                         m_parenterror = wxSTREAM_READ_ERROR;
                             m_buflen = 0;
                         }
                         m_parenterror = wxSTREAM_READ_ERROR;
@@ -182,8 +180,7 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos,
                     m_buflen = 0;
 
                     if (!m_stream) {
                     m_buflen = 0;
 
                     if (!m_stream) {
-                        delete m_buf;
-                        m_buf = NULL;
+                        wxDELETEA(m_buf);
                     }
                 }
 
                     }
                 }
 
@@ -197,13 +194,12 @@ wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos,
                     m_parenterror = m_stream->GetLastError();
                     if (m_parenterror == wxSTREAM_NO_ERROR)
                         m_parenterror = wxSTREAM_EOF;
                     m_parenterror = m_stream->GetLastError();
                     if (m_parenterror == wxSTREAM_NO_ERROR)
                         m_parenterror = wxSTREAM_EOF;
-                    delete m_stream;
-                    m_stream = NULL;
+                    wxDELETE(m_stream);
                 }
             }
 
             // copy to the user's buffer
                 }
             }
 
             // copy to the user's buffer
-            size_t start = pos - m_filelen;
+            size_t start = size_t(pos - m_filelen);
             size_t len = wxMin(m_buflen - start, reqestedSize - *size);
 
             memcpy((char*)buffer + *size, m_buf + start, len);
             size_t len = wxMin(m_buflen - start, reqestedSize - *size);
 
             memcpy((char*)buffer + *size, m_buf + start, len);
@@ -271,6 +267,29 @@ wxBackedInputStream::wxBackedInputStream(const wxBackingFile& backer)
 {
 }
 
 {
 }
 
+wxFileOffset wxBackedInputStream::GetLength() const
+{
+    return m_backer.m_impl->GetLength();
+}
+
+wxFileOffset wxBackedInputStream::FindLength() const
+{
+    wxFileOffset len = GetLength();
+
+    if (len == wxInvalidOffset && IsOk()) {
+        // read a byte at 7ff...ffe
+        wxFileOffset pos = 1;
+        pos <<= sizeof(pos) * 8 - 1;
+        pos = ~pos - 1;
+        char ch;
+        size_t size = 1;
+        m_backer.m_impl->ReadAt(pos, &ch, &size);
+        len = GetLength();
+    }
+
+    return len;
+}
+
 size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
 {
     if (!IsOk())
 size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
 {
     if (!IsOk())
@@ -281,11 +300,6 @@ size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
     return size;
 }
 
     return size;
 }
 
-wxFileOffset wxBackedInputStream::GetLength() const
-{
-    return m_backer.m_impl->GetLength();
-}
-
 wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
 {
     switch (mode) {
 wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
 {
     switch (mode) {
@@ -317,4 +331,4 @@ wxFileOffset wxBackedInputStream::OnSysTell() const
     return m_pos;
 }
 
     return m_pos;
 }
 
-#endif // wxUSE_BACKINGFILE
+#endif // wxUSE_FILESYSTEM