[Libreoffice-commits] core.git: sc/inc sc/source

Marco Cecchetti marco.cecchetti at collabora.com
Thu Jul 27 09:41:48 UTC 2017


 sc/inc/clipparam.hxx              |    6 ++++++
 sc/source/core/data/clipparam.cxx |    6 ++++--
 sc/source/ui/view/cellsh.cxx      |   23 +++++++++++++++++++++++
 sc/source/ui/view/viewfun3.cxx    |   25 +++++++++++++++++++++++++
 4 files changed, 58 insertions(+), 2 deletions(-)

New commits:
commit f0684222540b96d8366ce175c522b64472361b80
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Wed May 24 20:46:31 2017 +0200

    lok: sc: copy / paste confusion -- workaround
    
    Problem:
    
    1. (a) copied April
    2. (a) pasted -> April
    3. (b) copied March
    4. (a) pasted -> March [should have been April]
    
    where (a), (b) are different views
    
    Solution:
    A real solution would require to have one clipboard per view.
    This patch is only a workaround, which doesn't allow to paste content
    which has been copied in a different view; it takes also care to
    disable the "Paste" entry in the context menu.
    
    Change-Id: I3254f130af106299b0b519884a4ca03db08fc4c8
    Reviewed-on: https://gerrit.libreoffice.org/40459
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/sc/inc/clipparam.hxx b/sc/inc/clipparam.hxx
index 2e5dece711e8..16555225d074 100644
--- a/sc/inc/clipparam.hxx
+++ b/sc/inc/clipparam.hxx
@@ -26,6 +26,8 @@
 
 #include <vector>
 
+class SfxViewShell;
+
 /**
  * This struct stores general clipboard parameters associated with a
  * ScDocument instance created in clipboard mode.
@@ -38,6 +40,7 @@ struct ScClipParam
     Direction           meDirection;
     bool                mbCutMode;
     sal_uInt32          mnSourceDocID;
+    SfxViewShell*       mpSourceView;
     ScRangeListVector   maProtectedChartRangesVector;
 
     ScClipParam();
@@ -67,6 +70,9 @@ struct ScClipParam
 
     sal_uInt32 getSourceDocID() const { return mnSourceDocID; }
     void setSourceDocID( sal_uInt32 nVal ) { mnSourceDocID = nVal; }
+
+    SfxViewShell* getSourceView() const { return mpSourceView; }
+    void setSourceView( SfxViewShell* pSourceView ) { mpSourceView = pSourceView; }
 };
 
 #endif
diff --git a/sc/source/core/data/clipparam.cxx b/sc/source/core/data/clipparam.cxx
index 9c08d6093dfc..bc856672fbba 100644
--- a/sc/source/core/data/clipparam.cxx
+++ b/sc/source/core/data/clipparam.cxx
@@ -23,14 +23,16 @@
 ScClipParam::ScClipParam() :
     meDirection(Unspecified),
     mbCutMode(false),
-    mnSourceDocID(0)
+    mnSourceDocID(0),
+    mpSourceView(nullptr)
 {
 }
 
 ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) :
     meDirection(Unspecified),
     mbCutMode(bCutMode),
-    mnSourceDocID(0)
+    mnSourceDocID(0),
+    mpSourceView(nullptr)
 {
     maRanges.Append(rRange);
 }
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index 202598956891..cf410346c6c1 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -605,6 +605,29 @@ void ScCellShell::GetClipState( SfxItemSet& rSet )
             bDisable = true;
     }
 
+    // This is only a workaround, we don't want that text content copied
+    // in one view is pasted in a different view.
+    // This part of the patch takes care to disable the "Paste" entry
+    // in the context menu.
+    // TODO: implement a solution providing one clipboard per view
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(nullptr);
+        if (pOwnClip)
+        {
+            ScDocument* pClipDoc = pOwnClip->GetDocument();
+            if (pClipDoc)
+            {
+                ScTabViewShell* pThisView = GetViewData()->GetViewShell();
+                ScTabViewShell* pSourceView = dynamic_cast<ScTabViewShell*>(pClipDoc->GetClipParam().getSourceView());
+                if (pThisView && pSourceView && pThisView != pSourceView)
+                {
+                    bDisable = true;
+                }
+            }
+        }
+    }
+
     if (bDisable)
     {
         rSet.DisableItem( SID_PASTE );
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 0c675ecd6c12..4fab715aafd5 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -37,6 +37,9 @@
 #include <sot/exchange.hxx>
 #include <memory>
 
+#include <comphelper/lok.hxx>
+#include <sfx2/lokhelper.hxx>
+
 #include "attrib.hxx"
 #include "patattr.hxx"
 #include "dociter.hxx"
@@ -224,6 +227,14 @@ bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRanges, b
             // and lose the 'if' above
             aClipParam.setSourceDocID( pDoc->GetDocumentID() );
 
+            // This is only a workaround, which doesn't allow to paste content
+            // in one view which has been copied in a different view.
+            // TODO: implement a solution providing one clipboard per view
+            if (comphelper::LibreOfficeKit::isActive())
+            {
+                aClipParam.setSourceView(GetViewData().GetViewShell());
+            }
+
             if (SfxObjectShell* pObjectShell = pDoc->GetDocumentShell())
             {
                 // Copy document properties from pObjectShell to pClipDoc (to its clip options, as it has no object shell).
@@ -862,6 +873,20 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
     if (GetViewData().SelectionForbidsCellFill())
         return false;
 
+    // This is only a workaround, which doesn't allow to paste content
+    // in one view which has been copied in a different view.
+    // TODO: implement a solution providing one clipboard per view
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        ScTabViewShell* pThisView = GetViewData().GetViewShell();
+        ScTabViewShell* pSourceView = dynamic_cast<ScTabViewShell*>(pClipDoc->GetClipParam().getSourceView());
+
+        if (pThisView && pSourceView && pThisView != pSourceView)
+        {
+            return false;
+        }
+    }
+
     //  undo: save all or no content
     InsertDeleteFlags nContFlags = InsertDeleteFlags::NONE;
     if (nFlags & InsertDeleteFlags::CONTENTS)


More information about the Libreoffice-commits mailing list