Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / cliputil.cxx
blob723bb899a09aba85a9a924702805891c0229e4b0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * Major Contributor(s):
16 * Copyright (C) 2011 Kohei Yoshida <kohei.yoshida@suse.com>
18 * All Rights Reserved.
20 * For minor contributions see the git repository.
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 * instead of those above.
29 #include "cliputil.hxx"
30 #include "viewdata.hxx"
31 #include "tabvwsh.hxx"
32 #include "transobj.hxx"
33 #include "document.hxx"
34 #include "dpobject.hxx"
35 #include "globstr.hrc"
36 #include "clipparam.hxx"
37 #include "rangelst.hxx"
38 #include "viewutil.hxx"
39 #include "markdata.hxx"
41 #include "vcl/waitobj.hxx"
43 void ScClipUtil::PasteFromClipboard( ScViewData* pViewData, ScTabViewShell* pTabViewShell, bool bShowDialog )
45 Window* pWin = pViewData->GetActiveWin();
46 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
47 ScDocument* pThisDoc = pViewData->GetDocument();
48 ScDPObject* pDPObj = pThisDoc->GetDPAtCursor( pViewData->GetCurX(),
49 pViewData->GetCurY(), pViewData->GetTabNo() );
50 if ( pOwnClip && pDPObj )
52 // paste from Calc into DataPilot table: sort (similar to drag & drop)
54 ScDocument* pClipDoc = pOwnClip->GetDocument();
55 SCTAB nSourceTab = pOwnClip->GetVisibleTab();
57 SCCOL nClipStartX;
58 SCROW nClipStartY;
59 SCCOL nClipEndX;
60 SCROW nClipEndY;
61 pClipDoc->GetClipStart( nClipStartX, nClipStartY );
62 pClipDoc->GetClipArea( nClipEndX, nClipEndY, sal_True );
63 nClipEndX = nClipEndX + nClipStartX;
64 nClipEndY = nClipEndY + nClipStartY; // GetClipArea returns the difference
66 ScRange aSource( nClipStartX, nClipStartY, nSourceTab, nClipEndX, nClipEndY, nSourceTab );
67 sal_Bool bDone = pTabViewShell->DataPilotMove( aSource, pViewData->GetCurPos() );
68 if ( !bDone )
69 pTabViewShell->ErrorMessage( STR_ERR_DATAPILOT_INPUT );
71 else
73 // normal paste
74 WaitObject aWait( pViewData->GetDialogParent() );
75 if (!pOwnClip)
76 pTabViewShell->PasteFromSystem();
77 else
79 ScDocument* pClipDoc = pOwnClip->GetDocument();
80 sal_uInt16 nFlags = IDF_ALL;
81 if (pClipDoc->GetClipParam().isMultiRange())
82 // For multi-range paste, we paste values by default.
83 nFlags &= ~IDF_FORMULA;
85 pTabViewShell->PasteFromClip( nFlags, pClipDoc,
86 PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
87 bShowDialog ); // allow warning dialog
90 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
93 bool ScClipUtil::CheckDestRanges(
94 ScDocument* pDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData& rMark, const ScRangeList& rDest)
96 for (size_t i = 0, n = rDest.size(); i < n; ++i)
98 ScRange aTest = *rDest[i];
99 // Check for filtered rows in all selected sheets.
100 ScMarkData::const_iterator itrTab = rMark.begin(), itrTabEnd = rMark.end();
101 for (; itrTab != itrTabEnd; ++itrTab)
103 aTest.aStart.SetTab(*itrTab);
104 aTest.aEnd.SetTab(*itrTab);
105 if (ScViewUtil::HasFiltered(aTest, pDoc))
107 // I don't know how to handle pasting into filtered rows yet.
108 return false;
112 // Destination range must be an exact multiple of the source range.
113 SCROW nRows = aTest.aEnd.Row() - aTest.aStart.Row() + 1;
114 SCCOL nCols = aTest.aEnd.Col() - aTest.aStart.Col() + 1;
115 SCROW nRowTest = (nRows / nSrcRows) * nSrcRows;
116 SCCOL nColTest = (nCols / nSrcCols) * nSrcCols;
117 if ( rDest.size() > 1 && ( nRows != nRowTest || nCols != nColTest ) )
119 // Destination range is not a multiple of the source range. Bail out.
120 return false;
123 return true;
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */