]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #6538 (Figure: relative path changed to absolute on copy/paste)
authorEnrico Forestieri <forenr@lyx.org>
Sat, 11 Dec 2010 23:04:24 +0000 (23:04 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Sat, 11 Dec 2010 23:04:24 +0000 (23:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36835 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiClipboard.cpp
src/frontends/qt4/GuiClipboard.h
src/insets/InsetTabular.cpp

index 297b828948e45612d0a50456fcfe8ddfe70f4526..d8f6d5f96c27c285fb8bf3b47b52a5982569f705 100644 (file)
@@ -45,6 +45,8 @@
 #include <QString>
 #include <QStringList>
 
+#include <boost/crc.hpp>
+
 #include <memory>
 #include <map>
 #include <iostream>
@@ -349,6 +351,13 @@ void GuiClipboard::put(string const & lyx, docstring const & text)
        if (!lyx.empty()) {
                QByteArray const qlyx(lyx.c_str(), lyx.size());
                data->setData(lyxMimeType(), qlyx);
+               // If the OS has not the concept of clipboard ownership,
+               // we recognize internal data through its checksum.
+               if (!hasInternal()) {
+                       boost::crc_32_type crc32;
+                       crc32.process_bytes(lyx.c_str(), lyx.size());
+                       checksum = crc32.checksum();
+               }
        }
        // Don't test for text.empty() since we want to be able to clear the
        // clipboard.
@@ -414,11 +423,22 @@ bool GuiClipboard::hasGraphicsContents(Clipboard::GraphicsType type) const
 
 bool GuiClipboard::isInternal() const
 {
+       if (!hasLyXContents())
+               return false;
+
        // ownsClipboard() is also true for stuff coming from dialogs, e.g.
-       // the preamble dialog
-       // FIXME: This does only work on X11, since ownsClipboard() is
-       // hardwired to return false on Windows and OS X.
-       return qApp->clipboard()->ownsClipboard() && hasLyXContents();
+       // the preamble dialog. This does only work on X11 and Windows, since
+       // ownsClipboard() is hardwired to return false on OS X.
+       if (hasInternal())
+               return qApp->clipboard()->ownsClipboard();
+
+       // We are running on OS X: Check whether clipboard data is from
+       // ourself by comparing its checksum with the stored one.
+       QByteArray const ar = cache_.data(lyxMimeType());
+       string const data(ar.data(), ar.count());
+       boost::crc_32_type crc32;
+       crc32.process_bytes(data.c_str(), data.size());
+       return checksum == crc32.checksum();
 }
 
 
@@ -426,8 +446,10 @@ bool GuiClipboard::hasInternal() const
 {
        // Windows and Mac OS X does not have the concept of ownership;
        // the clipboard is a fully global resource so all applications 
-       // are notified of changes.
-#if (defined(Q_WS_X11))
+       // are notified of changes. However, on Windows ownership is
+       // emulated by Qt through the OleIsCurrentClipboard() API, while
+       // on Mac OS X we deal with this issue by ourself.
+#if (defined(Q_WS_X11) || defined(Q_WS_WIN))
        return true;
 #else
        return false;
index 5e1327352df3bdf45deb6414a51765d4fdf3bd74..a6540f1ce8a15eef7bfcc90d7c6cbfa8309d982a 100644 (file)
@@ -20,6 +20,8 @@
 #include <QObject>
 #include <QStringList>
 
+#include <boost/cstdint.hpp>
+
 namespace lyx {
 namespace frontend {
 
@@ -90,6 +92,8 @@ private:
        /// the cached mime data used to describe the information
        /// that can be stored in the clipboard
        CacheMimeData cache_;
+       /// checksum for internal clipboard data (used on Mac) 
+       boost::uint32_t checksum;
 };
 
 QString const lyxMimeType();
index c41cea76c1c4b0a7e1085105b4eeec92c8bedec0..eff906305729498d525d82d3bc0c6697db0a0bd9 100644 (file)
@@ -4170,8 +4170,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                                cell(cur.idx())->dispatch(cur, cmd);
                        break;
                }
-               if (theClipboard().isInternal() ||
-                   (!theClipboard().hasInternal() && theClipboard().hasLyXContents())) {
+               if (theClipboard().isInternal()) {
                        cur.recordUndoInset(INSERT_UNDO);
                        pasteClipboard(cur);
                }