Author: forenr
Date: Wed Jan  5 15:02:35 2011
New Revision: 37114
URL: http://www.lyx.org/trac/changeset/37114

Log:
Fix bug #6538 (Figure: relative path changed to absolute on copy/paste)

Modified:
   lyx-devel/branches/BRANCH_1_6_X/src/frontends/qt4/GuiClipboard.cpp
   lyx-devel/branches/BRANCH_1_6_X/src/frontends/qt4/GuiClipboard.h
   lyx-devel/branches/BRANCH_1_6_X/src/insets/InsetTabular.cpp
   lyx-devel/branches/BRANCH_1_6_X/status.16x

Modified: lyx-devel/branches/BRANCH_1_6_X/src/frontends/qt4/GuiClipboard.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/frontends/qt4/GuiClipboard.cpp  Wed Jan 
 5 14:57:02 2011        (r37113)
+++ lyx-devel/branches/BRANCH_1_6_X/src/frontends/qt4/GuiClipboard.cpp  Wed Jan 
 5 15:02:35 2011        (r37114)
@@ -44,6 +44,8 @@
 #include <QString>
 #include <QStringList>
 
+#include <boost/crc.hpp>
+
 #include <memory>
 #include <map>
 
@@ -325,6 +327,13 @@
        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.
@@ -397,11 +406,26 @@
 
 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.
+       QMimeData const * source =
+               qApp->clipboard()->mimeData(QClipboard::Clipboard);
+       if (!source)
+               return false;
+       QByteArray const ar = source->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();
 }
 
 
@@ -409,8 +433,10 @@
 {
        // 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;

Modified: lyx-devel/branches/BRANCH_1_6_X/src/frontends/qt4/GuiClipboard.h
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/frontends/qt4/GuiClipboard.h    Wed Jan 
 5 14:57:02 2011        (r37113)
+++ lyx-devel/branches/BRANCH_1_6_X/src/frontends/qt4/GuiClipboard.h    Wed Jan 
 5 15:02:35 2011        (r37114)
@@ -18,6 +18,8 @@
 
 #include <QObject>
 
+#include <boost/cstdint.hpp>
+
 namespace lyx {
 namespace frontend {
 
@@ -57,6 +59,8 @@
        bool text_clipboard_empty_;
        bool has_lyx_contents_;
        bool has_graphics_contents_;
+       /// checksum for internal clipboard data (used on Mac) 
+       boost::uint32_t checksum;
 };
 
 QString const lyxMimeType();

Modified: lyx-devel/branches/BRANCH_1_6_X/src/insets/InsetTabular.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/insets/InsetTabular.cpp Wed Jan  5 
14:57:02 2011        (r37113)
+++ lyx-devel/branches/BRANCH_1_6_X/src/insets/InsetTabular.cpp Wed Jan  5 
15:02:35 2011        (r37114)
@@ -3729,8 +3729,7 @@
                                cell(cur.idx())->dispatch(cur, cmd);
                        break;
                }
-               if (theClipboard().isInternal() ||
-                   !theClipboard().hasInternal() && 
theClipboard().hasLyXContents()) {
+               if (theClipboard().isInternal()) {
                        cur.recordUndoInset(INSERT_UNDO);
                        pasteClipboard(cur);
                }

Modified: lyx-devel/branches/BRANCH_1_6_X/status.16x
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/status.16x  Wed Jan  5 14:57:02 2011        
(r37113)
+++ lyx-devel/branches/BRANCH_1_6_X/status.16x  Wed Jan  5 15:02:35 2011        
(r37114)
@@ -117,6 +117,9 @@
 - Don't allow to make tables within floats "long" as this could lead to
   LaTeX errors (bug 6585).
 
+- Don't use absolute paths on internal copy/paste operations on Mac
+  (bug 6538).
+
 - Correct the denomination of the languages Norsk and Nynorsk.
 
 - Do not allow to put the cursor in an InsetInfo. Instead, a context

Reply via email to