Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / view / cliputil.cxx
blobc79d1738c742f5ef8932ddb6f293f39e96aa8ccb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "cliputil.hxx"
11 #include "viewdata.hxx"
12 #include "tabvwsh.hxx"
13 #include "transobj.hxx"
14 #include "document.hxx"
15 #include "dpobject.hxx"
16 #include "globstr.hrc"
17 #include "clipparam.hxx"
18 #include "clipoptions.hxx"
19 #include "rangelst.hxx"
20 #include "viewutil.hxx"
21 #include "markdata.hxx"
22 #include <gridwin.hxx>
24 #include <vcl/waitobj.hxx>
25 #include <sfx2/classificationhelper.hxx>
27 namespace
30 /// Paste only if SfxClassificationHelper recommends so.
31 bool lcl_checkClassification(ScDocument* pSourceDoc, ScDocument* pDestinationDoc)
33 if (!pSourceDoc || !pDestinationDoc)
34 return true;
36 ScClipOptions* pSourceOptions = pSourceDoc->GetClipOptions();
37 SfxObjectShell* pDestinationShell = pDestinationDoc->GetDocumentShell();
38 if (!pSourceOptions || !pDestinationShell)
39 return true;
41 SfxClassificationCheckPasteResult eResult = SfxClassificationHelper::CheckPaste(pSourceOptions->m_xDocumentProperties, pDestinationShell->getDocProperties());
42 return SfxClassificationHelper::ShowPasteInfo(eResult);
47 void ScClipUtil::PasteFromClipboard( ScViewData* pViewData, ScTabViewShell* pTabViewShell, bool bShowDialog )
49 vcl::Window* pWin = pViewData->GetActiveWin();
50 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
51 ScDocument* pThisDoc = pViewData->GetDocument();
52 ScDPObject* pDPObj = pThisDoc->GetDPAtCursor( pViewData->GetCurX(),
53 pViewData->GetCurY(), pViewData->GetTabNo() );
54 if ( pOwnClip && pDPObj )
56 // paste from Calc into DataPilot table: sort (similar to drag & drop)
58 ScDocument* pClipDoc = pOwnClip->GetDocument();
59 SCTAB nSourceTab = pOwnClip->GetVisibleTab();
61 SCCOL nClipStartX;
62 SCROW nClipStartY;
63 SCCOL nClipEndX;
64 SCROW nClipEndY;
65 pClipDoc->GetClipStart( nClipStartX, nClipStartY );
66 pClipDoc->GetClipArea( nClipEndX, nClipEndY, true );
67 nClipEndX = nClipEndX + nClipStartX;
68 nClipEndY = nClipEndY + nClipStartY; // GetClipArea returns the difference
70 ScRange aSource( nClipStartX, nClipStartY, nSourceTab, nClipEndX, nClipEndY, nSourceTab );
71 bool bDone = pTabViewShell->DataPilotMove( aSource, pViewData->GetCurPos() );
72 if ( !bDone )
73 pTabViewShell->ErrorMessage( STR_ERR_DATAPILOT_INPUT );
75 else
77 // normal paste
78 WaitObject aWait( pViewData->GetDialogParent() );
79 if (!pOwnClip)
80 pTabViewShell->PasteFromSystem();
81 else
83 ScDocument* pClipDoc = pOwnClip->GetDocument();
84 InsertDeleteFlags nFlags = InsertDeleteFlags::ALL;
85 if (pClipDoc->GetClipParam().isMultiRange())
86 // For multi-range paste, we paste values by default.
87 nFlags &= ~InsertDeleteFlags::FORMULA;
89 if (lcl_checkClassification(pClipDoc, pThisDoc))
90 pTabViewShell->PasteFromClip( nFlags, pClipDoc,
91 ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE,
92 bShowDialog ); // allow warning dialog
95 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
98 bool ScClipUtil::CheckDestRanges(
99 ScDocument* pDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData& rMark, const ScRangeList& rDest)
101 for (size_t i = 0, n = rDest.size(); i < n; ++i)
103 ScRange aTest = *rDest[i];
104 // Check for filtered rows in all selected sheets.
105 ScMarkData::const_iterator itrTab = rMark.begin(), itrTabEnd = rMark.end();
106 for (; itrTab != itrTabEnd; ++itrTab)
108 aTest.aStart.SetTab(*itrTab);
109 aTest.aEnd.SetTab(*itrTab);
110 if (ScViewUtil::HasFiltered(aTest, pDoc))
112 // I don't know how to handle pasting into filtered rows yet.
113 return false;
117 // Destination range must be an exact multiple of the source range.
118 SCROW nRows = aTest.aEnd.Row() - aTest.aStart.Row() + 1;
119 SCCOL nCols = aTest.aEnd.Col() - aTest.aStart.Col() + 1;
120 SCROW nRowTest = (nRows / nSrcRows) * nSrcRows;
121 SCCOL nColTest = (nCols / nSrcCols) * nSrcCols;
122 if ( rDest.size() > 1 && ( nRows != nRowTest || nCols != nColTest ) )
124 // Destination range is not a multiple of the source range. Bail out.
125 return false;
128 return true;
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */