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 "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>
30 /// Paste only if SfxClassificationHelper recommends so.
31 bool lcl_checkClassification(ScDocument
* pSourceDoc
, ScDocument
* pDestinationDoc
)
33 if (!pSourceDoc
|| !pDestinationDoc
)
36 ScClipOptions
* pSourceOptions
= pSourceDoc
->GetClipOptions();
37 SfxObjectShell
* pDestinationShell
= pDestinationDoc
->GetDocumentShell();
38 if (!pSourceOptions
|| !pDestinationShell
)
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();
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() );
73 pTabViewShell
->ErrorMessage( STR_ERR_DATAPILOT_INPUT
);
78 WaitObject
aWait( pViewData
->GetDialogParent() );
80 pTabViewShell
->PasteFromSystem();
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.
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.
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */