bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / view / cliputil.cxx
blobb3075ad81524240eb8733a155298bdaa1347d11c
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 "rangelst.hxx"
19 #include "viewutil.hxx"
20 #include "markdata.hxx"
22 #include "vcl/waitobj.hxx"
24 void ScClipUtil::PasteFromClipboard( ScViewData* pViewData, ScTabViewShell* pTabViewShell, bool bShowDialog )
26 Window* pWin = pViewData->GetActiveWin();
27 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
28 ScDocument* pThisDoc = pViewData->GetDocument();
29 ScDPObject* pDPObj = pThisDoc->GetDPAtCursor( pViewData->GetCurX(),
30 pViewData->GetCurY(), pViewData->GetTabNo() );
31 if ( pOwnClip && pDPObj )
33 // paste from Calc into DataPilot table: sort (similar to drag & drop)
35 ScDocument* pClipDoc = pOwnClip->GetDocument();
36 SCTAB nSourceTab = pOwnClip->GetVisibleTab();
38 SCCOL nClipStartX;
39 SCROW nClipStartY;
40 SCCOL nClipEndX;
41 SCROW nClipEndY;
42 pClipDoc->GetClipStart( nClipStartX, nClipStartY );
43 pClipDoc->GetClipArea( nClipEndX, nClipEndY, sal_True );
44 nClipEndX = nClipEndX + nClipStartX;
45 nClipEndY = nClipEndY + nClipStartY; // GetClipArea returns the difference
47 ScRange aSource( nClipStartX, nClipStartY, nSourceTab, nClipEndX, nClipEndY, nSourceTab );
48 sal_Bool bDone = pTabViewShell->DataPilotMove( aSource, pViewData->GetCurPos() );
49 if ( !bDone )
50 pTabViewShell->ErrorMessage( STR_ERR_DATAPILOT_INPUT );
52 else
54 // normal paste
55 WaitObject aWait( pViewData->GetDialogParent() );
56 if (!pOwnClip)
57 pTabViewShell->PasteFromSystem();
58 else
60 ScDocument* pClipDoc = pOwnClip->GetDocument();
61 sal_uInt16 nFlags = IDF_ALL;
62 if (pClipDoc->GetClipParam().isMultiRange())
63 // For multi-range paste, we paste values by default.
64 nFlags &= ~IDF_FORMULA;
66 pTabViewShell->PasteFromClip( nFlags, pClipDoc,
67 PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
68 bShowDialog ); // allow warning dialog
71 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
74 bool ScClipUtil::CheckDestRanges(
75 ScDocument* pDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData& rMark, const ScRangeList& rDest)
77 for (size_t i = 0, n = rDest.size(); i < n; ++i)
79 ScRange aTest = *rDest[i];
80 // Check for filtered rows in all selected sheets.
81 ScMarkData::const_iterator itrTab = rMark.begin(), itrTabEnd = rMark.end();
82 for (; itrTab != itrTabEnd; ++itrTab)
84 aTest.aStart.SetTab(*itrTab);
85 aTest.aEnd.SetTab(*itrTab);
86 if (ScViewUtil::HasFiltered(aTest, pDoc))
88 // I don't know how to handle pasting into filtered rows yet.
89 return false;
93 // Destination range must be an exact multiple of the source range.
94 SCROW nRows = aTest.aEnd.Row() - aTest.aStart.Row() + 1;
95 SCCOL nCols = aTest.aEnd.Col() - aTest.aStart.Col() + 1;
96 SCROW nRowTest = (nRows / nSrcRows) * nSrcRows;
97 SCCOL nColTest = (nCols / nSrcCols) * nSrcCols;
98 if ( rDest.size() > 1 && ( nRows != nRowTest || nCols != nColTest ) )
100 // Destination range is not a multiple of the source range. Bail out.
101 return false;
104 return true;
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */