tdf#90101 add .uno:PasteAsLink

No attributes or notes are pasted, i.e. only the links.
Links to dates loose the date formatting currently, see tdf#142093.

Paste As Link is only added as command.
No entries to menus or context menus are made
as this functionality is not widely used, see tdf#102255

Icons are added with tdf#141885

Change-Id: Ifbdaa076045b5f10073a658115fea211bb30e6a1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115137
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index 3d33e43..4bd6c19 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -431,11 +431,14 @@ class SvxSearchItem;
// default-ids for macros
#define SID_RECORDING_FLOATWINDOW           (SID_SFX_START + 800)
#define SID_RECORDMACRO                     (SID_SFX_START + 1669)

// Paste Special
#define SID_PASTE_ONLY_TEXT                 (SID_SFX_START + 802)
#define SID_PASTE_ONLY_FORMULA              (SID_SFX_START + 803)
#define SID_PASTE_ONLY_VALUE                (SID_SFX_START + 804)
#define SID_PASTE_TEXTIMPORT_DIALOG         (SID_SFX_START + 805)
#define SID_PASTE_TRANSPOSED                (SID_SFX_START + 812)
#define SID_PASTE_AS_LINK                   (SID_SFX_START + 813)

// Used for redaction
#define SID_SHAPE_NAME                      (SID_SFX_START + 808)
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index 2c09285..6c0e3d6 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -2621,6 +2621,17 @@
          <value>1</value>
        </prop>
      </node>
      <node oor:name=".uno:PasteAsLink" oor:op="replace">
        <prop oor:name="Label" oor:type="xs:string">
          <value xml:lang="en-US">Paste As Link </value>
        </prop>
        <prop oor:name="PopupLabel" oor:type="xs:string">
          <value xml:lang="en-US">As ~Link</value>
        </prop>
        <prop oor:name="Properties" oor:type="xs:int">
          <value>1</value>
        </prop>
      </node>
      <node oor:name=".uno:PasteTextImportDialog" oor:op="replace">
        <prop oor:name="Label" oor:type="xs:string">
          <value xml:lang="en-US">Use Text Import Dialog</value>
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index abd9ad4..e86bfbf 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -573,6 +573,63 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testPasteTransposed)
    CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight());
}

// Test the call of .uno:PasteAsLink (tdf#90101)
// Note: the paste as link functionaly is tested in ucalc
CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testPasteAsLink)
{
    mxComponent = loadFromDesktop("private:factory/scalc");
    ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get());
    CPPUNIT_ASSERT(pModelObj);
    ScDocument* pDoc = pModelObj->GetDocument();
    CPPUNIT_ASSERT(pDoc);

    insertStringToCell(*pModelObj, "A1", "1");
    insertStringToCell(*pModelObj, "A2", "a");
    insertStringToCell(*pModelObj, "A3", "=A1");

    // Add a note to A1
    goToCell("A1");
    uno::Sequence<beans::PropertyValue> aArgs
        = comphelper::InitPropertySequence({ { "Text", uno::makeAny(OUString("Note in A1")) } });
    dispatchCommand(mxComponent, ".uno:InsertAnnotation", aArgs);

    // Set A2 bold
    goToCell("A2");
    dispatchCommand(mxComponent, ".uno:Bold", {});

    // Check preconditions
    CPPUNIT_ASSERT_MESSAGE("There should be a note on A1", pDoc->HasNote(ScAddress(0, 0, 0)));
    const ScPatternAttr* pPattern = pDoc->GetPattern(0, 1, 0);
    vcl::Font aFont;
    pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight());

    goToCell("A1:A3");

    dispatchCommand(mxComponent, ".uno:Copy", {});

    goToCell("C1");

    dispatchCommand(mxComponent, ".uno:PasteAsLink", {});

    OUString aFormula;
    pDoc->GetFormula(2, 0, 0, aFormula);
    CPPUNIT_ASSERT_EQUAL(OUString("=$Sheet1.$A$1"), aFormula); // C1
    pDoc->GetFormula(2, 1, 0, aFormula);
    CPPUNIT_ASSERT_EQUAL(OUString("=$Sheet1.$A$2"), aFormula); // C2
    pDoc->GetFormula(2, 2, 0, aFormula);
    CPPUNIT_ASSERT_EQUAL(OUString("=$Sheet1.$A$3"), aFormula); // C3
    CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(2, 0, 0)); // C1
    CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(2, 2, 0)); // C3

    CPPUNIT_ASSERT_MESSAGE("There should be no note on C1", !pDoc->HasNote(ScAddress(2, 0, 0)));

    pPattern = pDoc->GetPattern(2, 1, 0);
    pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be normal (cell attributes should not be copied)",
                                 WEIGHT_NORMAL, aFont.GetWeight());
}

CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131442)
{
    mxComponent = loadFromDesktop("private:factory/scalc");
diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 0790f8c..c9eed43 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -178,6 +178,7 @@ interface CellSelection
    SID_PASTE_ONLY_FORMULA   [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ]
    SID_PASTE_ONLY_VALUE   [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ]
    SID_PASTE_TRANSPOSED   [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ]
    SID_PASTE_AS_LINK   [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ]
    SID_PASTE_TEXTIMPORT_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ]
    SID_CLIPBOARD_FORMAT_ITEMS  [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ]
    SID_EXTERNAL_SOURCE [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index d677e6a..256cab8 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -223,6 +223,7 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet )
            case SID_PASTE_ONLY_TEXT:
            case SID_PASTE_ONLY_FORMULA:
            case SID_PASTE_TRANSPOSED:
            case SID_PASTE_AS_LINK:
            case SID_PASTE_TEXTIMPORT_DIALOG:
                bDisable = GetViewData().SelectionForbidsCellFill();
                break;
@@ -528,6 +529,7 @@ IMPL_LINK( ScCellShell, ClipboardChanged, TransferableDataHelper*, pDataHelper, 
    rBindings.Invalidate( SID_PASTE_ONLY_TEXT );
    rBindings.Invalidate( SID_PASTE_ONLY_FORMULA );
    rBindings.Invalidate( SID_PASTE_TRANSPOSED );
    rBindings.Invalidate( SID_PASTE_AS_LINK );
    rBindings.Invalidate( SID_PASTE_TEXTIMPORT_DIALOG );
    rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
}
@@ -623,6 +625,7 @@ void ScCellShell::GetClipState( SfxItemSet& rSet )
        rSet.DisableItem( SID_PASTE_ONLY_TEXT );
        rSet.DisableItem( SID_PASTE_ONLY_FORMULA );
        rSet.DisableItem( SID_PASTE_TRANSPOSED );
        rSet.DisableItem( SID_PASTE_AS_LINK );
        rSet.DisableItem( SID_PASTE_TEXTIMPORT_DIALOG );
        rSet.DisableItem( SID_CLIPBOARD_FORMAT_ITEMS );
    }
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index f7abd19..1fac839 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -1528,6 +1528,24 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
            break;
        }
        case SID_PASTE_AS_LINK:
        {
            if (ScTransferObj::GetOwnClipboard(
                    ScTabViewShell::GetClipData(GetViewData().GetActiveWin()))) // own cell data
            {
                rReq.SetSlot(FID_INS_CELL_CONTENTS);
                // paste links to values/numbers, strings, formulas and dates
                // do not paste attributes, notes and objects
                rReq.AppendItem(SfxStringItem(FID_INS_CELL_CONTENTS, "VSFD"));
                rReq.AppendItem(SfxBoolItem(FN_PARAM_4, true)); // as link
                ExecuteSlot(rReq, GetInterface());
                rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
                pTabViewShell->CellContentChanged();
            }
            else
                rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
            break;
        }
        case SID_PASTE_TEXTIMPORT_DIALOG:
        {
            vcl::Window* pWin = GetViewData().GetActiveWin();
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index 0de7ed4..43dc58e 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -3160,6 +3160,23 @@ SfxVoidItem PasteTransposed SID_PASTE_TRANSPOSED
    GroupId = SfxGroupId::Edit;
]

SfxVoidItem PasteAsLink SID_PASTE_AS_LINK

[
    AutoUpdate = FALSE,
    FastCall = TRUE,
    ReadOnlyDoc = FALSE,
    Toggle = FALSE,
    Container = FALSE,
    RecordAbsolute = FALSE,
    RecordPerSet;

    AccelConfig = TRUE,
    MenuConfig = TRUE,
    ToolBoxConfig = TRUE,
    GroupId = SfxGroupId::Edit;
]

SfxVoidItem PasteTextImportDialog SID_PASTE_TEXTIMPORT_DIALOG

[