1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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 #include <gridwin.hxx>
23 #include <vcl/waitobj.hxx>
25 void ScClipUtil::PasteFromClipboard( ScViewData
* pViewData
, ScTabViewShell
* pTabViewShell
, bool bShowDialog
)
27 vcl::Window
* pWin
= pViewData
->GetActiveWin();
28 ScTransferObj
* pOwnClip
= ScTransferObj::GetOwnClipboard( pWin
);
29 ScDocument
* pThisDoc
= pViewData
->GetDocument();
30 ScDPObject
* pDPObj
= pThisDoc
->GetDPAtCursor( pViewData
->GetCurX(),
31 pViewData
->GetCurY(), pViewData
->GetTabNo() );
32 if ( pOwnClip
&& pDPObj
)
34 // paste from Calc into DataPilot table: sort (similar to drag & drop)
36 ScDocument
* pClipDoc
= pOwnClip
->GetDocument();
37 SCTAB nSourceTab
= pOwnClip
->GetVisibleTab();
43 pClipDoc
->GetClipStart( nClipStartX
, nClipStartY
);
44 pClipDoc
->GetClipArea( nClipEndX
, nClipEndY
, true );
45 nClipEndX
= nClipEndX
+ nClipStartX
;
46 nClipEndY
= nClipEndY
+ nClipStartY
; // GetClipArea returns the difference
48 ScRange
aSource( nClipStartX
, nClipStartY
, nSourceTab
, nClipEndX
, nClipEndY
, nSourceTab
);
49 bool bDone
= pTabViewShell
->DataPilotMove( aSource
, pViewData
->GetCurPos() );
51 pTabViewShell
->ErrorMessage( STR_ERR_DATAPILOT_INPUT
);
56 WaitObject
aWait( pViewData
->GetDialogParent() );
58 pTabViewShell
->PasteFromSystem();
61 ScDocument
* pClipDoc
= pOwnClip
->GetDocument();
62 InsertDeleteFlags nFlags
= IDF_ALL
;
63 if (pClipDoc
->GetClipParam().isMultiRange())
64 // For multi-range paste, we paste values by default.
65 nFlags
&= ~IDF_FORMULA
;
67 pTabViewShell
->PasteFromClip( nFlags
, pClipDoc
,
68 PASTE_NOFUNC
, false, false, false, INS_NONE
, IDF_NONE
,
69 bShowDialog
); // allow warning dialog
72 pTabViewShell
->CellContentChanged(); // => PasteFromSystem() ???
75 bool ScClipUtil::CheckDestRanges(
76 ScDocument
* pDoc
, SCCOL nSrcCols
, SCROW nSrcRows
, const ScMarkData
& rMark
, const ScRangeList
& rDest
)
78 for (size_t i
= 0, n
= rDest
.size(); i
< n
; ++i
)
80 ScRange aTest
= *rDest
[i
];
81 // Check for filtered rows in all selected sheets.
82 ScMarkData::const_iterator itrTab
= rMark
.begin(), itrTabEnd
= rMark
.end();
83 for (; itrTab
!= itrTabEnd
; ++itrTab
)
85 aTest
.aStart
.SetTab(*itrTab
);
86 aTest
.aEnd
.SetTab(*itrTab
);
87 if (ScViewUtil::HasFiltered(aTest
, pDoc
))
89 // I don't know how to handle pasting into filtered rows yet.
94 // Destination range must be an exact multiple of the source range.
95 SCROW nRows
= aTest
.aEnd
.Row() - aTest
.aStart
.Row() + 1;
96 SCCOL nCols
= aTest
.aEnd
.Col() - aTest
.aStart
.Col() + 1;
97 SCROW nRowTest
= (nRows
/ nSrcRows
) * nSrcRows
;
98 SCCOL nColTest
= (nCols
/ nSrcCols
) * nSrcCols
;
99 if ( rDest
.size() > 1 && ( nRows
!= nRowTest
|| nCols
!= nColTest
) )
101 // Destination range is not a multiple of the source range. Bail out.
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */