Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
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"
21 :
22 : #include "vcl/waitobj.hxx"
23 :
24 0 : void ScClipUtil::PasteFromClipboard( ScViewData* pViewData, ScTabViewShell* pTabViewShell, bool bShowDialog )
25 : {
26 0 : Window* pWin = pViewData->GetActiveWin();
27 0 : ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
28 0 : ScDocument* pThisDoc = pViewData->GetDocument();
29 0 : ScDPObject* pDPObj = pThisDoc->GetDPAtCursor( pViewData->GetCurX(),
30 0 : pViewData->GetCurY(), pViewData->GetTabNo() );
31 0 : if ( pOwnClip && pDPObj )
32 : {
33 : // paste from Calc into DataPilot table: sort (similar to drag & drop)
34 :
35 0 : ScDocument* pClipDoc = pOwnClip->GetDocument();
36 0 : SCTAB nSourceTab = pOwnClip->GetVisibleTab();
37 :
38 : SCCOL nClipStartX;
39 : SCROW nClipStartY;
40 : SCCOL nClipEndX;
41 : SCROW nClipEndY;
42 0 : pClipDoc->GetClipStart( nClipStartX, nClipStartY );
43 0 : pClipDoc->GetClipArea( nClipEndX, nClipEndY, true );
44 0 : nClipEndX = nClipEndX + nClipStartX;
45 0 : nClipEndY = nClipEndY + nClipStartY; // GetClipArea returns the difference
46 :
47 0 : ScRange aSource( nClipStartX, nClipStartY, nSourceTab, nClipEndX, nClipEndY, nSourceTab );
48 0 : sal_Bool bDone = pTabViewShell->DataPilotMove( aSource, pViewData->GetCurPos() );
49 0 : if ( !bDone )
50 0 : pTabViewShell->ErrorMessage( STR_ERR_DATAPILOT_INPUT );
51 : }
52 : else
53 : {
54 : // normal paste
55 0 : WaitObject aWait( pViewData->GetDialogParent() );
56 0 : if (!pOwnClip)
57 0 : pTabViewShell->PasteFromSystem();
58 : else
59 : {
60 0 : ScDocument* pClipDoc = pOwnClip->GetDocument();
61 0 : sal_uInt16 nFlags = IDF_ALL;
62 0 : if (pClipDoc->GetClipParam().isMultiRange())
63 : // For multi-range paste, we paste values by default.
64 0 : nFlags &= ~IDF_FORMULA;
65 :
66 : pTabViewShell->PasteFromClip( nFlags, pClipDoc,
67 : PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
68 0 : bShowDialog ); // allow warning dialog
69 0 : }
70 : }
71 0 : pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
72 0 : }
73 :
74 0 : bool ScClipUtil::CheckDestRanges(
75 : ScDocument* pDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData& rMark, const ScRangeList& rDest)
76 : {
77 0 : for (size_t i = 0, n = rDest.size(); i < n; ++i)
78 : {
79 0 : ScRange aTest = *rDest[i];
80 : // Check for filtered rows in all selected sheets.
81 0 : ScMarkData::const_iterator itrTab = rMark.begin(), itrTabEnd = rMark.end();
82 0 : for (; itrTab != itrTabEnd; ++itrTab)
83 : {
84 0 : aTest.aStart.SetTab(*itrTab);
85 0 : aTest.aEnd.SetTab(*itrTab);
86 0 : if (ScViewUtil::HasFiltered(aTest, pDoc))
87 : {
88 : // I don't know how to handle pasting into filtered rows yet.
89 0 : return false;
90 : }
91 : }
92 :
93 : // Destination range must be an exact multiple of the source range.
94 0 : SCROW nRows = aTest.aEnd.Row() - aTest.aStart.Row() + 1;
95 0 : SCCOL nCols = aTest.aEnd.Col() - aTest.aStart.Col() + 1;
96 0 : SCROW nRowTest = (nRows / nSrcRows) * nSrcRows;
97 0 : SCCOL nColTest = (nCols / nSrcCols) * nSrcCols;
98 0 : if ( rDest.size() > 1 && ( nRows != nRowTest || nCols != nColTest ) )
99 : {
100 : // Destination range is not a multiple of the source range. Bail out.
101 0 : return false;
102 : }
103 : }
104 0 : return true;
105 0 : }
106 :
107 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|