LibreOffice Module sc (master)  1
cliputil.cxx
Go to the documentation of this file.
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 <clipoptions.hxx>
19 #include <rangelst.hxx>
20 #include <viewutil.hxx>
21 #include <markdata.hxx>
22 #include <gridwin.hxx>
23 
25 
26 namespace
27 {
28 
30 bool lcl_checkClassification(ScDocument* pSourceDoc, const ScDocument* pDestinationDoc)
31 {
32  if (!pSourceDoc || !pDestinationDoc)
33  return true;
34 
35  ScClipOptions* pSourceOptions = pSourceDoc->GetClipOptions();
36  SfxObjectShell* pDestinationShell = pDestinationDoc->GetDocumentShell();
37  if (!pSourceOptions || !pDestinationShell)
38  return true;
39 
42 }
43 
44 }
45 
46 void ScClipUtil::PasteFromClipboard( ScViewData* pViewData, ScTabViewShell* pTabViewShell, bool bShowDialog )
47 {
49  ScDocument* pThisDoc = pViewData->GetDocument();
50  ScDPObject* pDPObj = pThisDoc->GetDPAtCursor( pViewData->GetCurX(),
51  pViewData->GetCurY(), pViewData->GetTabNo() );
52  if ( pOwnClip && pDPObj )
53  {
54  // paste from Calc into DataPilot table: sort (similar to drag & drop)
55 
56  ScDocument* pClipDoc = pOwnClip->GetDocument();
57  SCTAB nSourceTab = pOwnClip->GetVisibleTab();
58 
59  SCCOL nClipStartX;
60  SCROW nClipStartY;
61  SCCOL nClipEndX;
62  SCROW nClipEndY;
63  pClipDoc->GetClipStart( nClipStartX, nClipStartY );
64  pClipDoc->GetClipArea( nClipEndX, nClipEndY, true );
65  nClipEndX = nClipEndX + nClipStartX;
66  nClipEndY = nClipEndY + nClipStartY; // GetClipArea returns the difference
67 
68  ScRange aSource( nClipStartX, nClipStartY, nSourceTab, nClipEndX, nClipEndY, nSourceTab );
69  bool bDone = pTabViewShell->DataPilotMove( aSource, pViewData->GetCurPos() );
70  if ( !bDone )
71  pTabViewShell->ErrorMessage( STR_ERR_DATAPILOT_INPUT );
72  }
73  else
74  {
75  // normal paste
76  weld::WaitObject aWait( pViewData->GetDialogParent() );
77  if (!pOwnClip)
78  pTabViewShell->PasteFromSystem();
79  else
80  {
81  ScDocument* pClipDoc = pOwnClip->GetDocument();
83  if (pClipDoc->GetClipParam().isMultiRange())
84  // For multi-range paste, we paste values by default.
85  nFlags &= ~InsertDeleteFlags::FORMULA;
86 
87  if (lcl_checkClassification(pClipDoc, pThisDoc))
88  pTabViewShell->PasteFromClip( nFlags, pClipDoc,
89  ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE,
90  bShowDialog ); // allow warning dialog
91  }
92  }
93  pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
94 }
95 
97  const ScDocument* pDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData& rMark, const ScRangeList& rDest)
98 {
99  for (size_t i = 0, n = rDest.size(); i < n; ++i)
100  {
101  ScRange aTest = rDest[i];
102  // Check for filtered rows in all selected sheets.
103  for (const auto& rTab : rMark)
104  {
105  aTest.aStart.SetTab(rTab);
106  aTest.aEnd.SetTab(rTab);
107  if (ScViewUtil::HasFiltered(aTest, pDoc))
108  {
109  // I don't know how to handle pasting into filtered rows yet.
110  return false;
111  }
112  }
113 
114  // Destination range must be an exact multiple of the source range.
115  SCROW nRows = aTest.aEnd.Row() - aTest.aStart.Row() + 1;
116  SCCOL nCols = aTest.aEnd.Col() - aTest.aStart.Col() + 1;
117  SCROW nRowTest = (nRows / nSrcRows) * nSrcRows;
118  SCCOL nColTest = (nCols / nSrcCols) * nSrcCols;
119  if ( rDest.size() > 1 && ( nRows != nRowTest || nCols != nColTest ) )
120  {
121  // Destination range is not a multiple of the source range. Bail out.
122  return false;
123  }
124  }
125  return true;
126 }
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:358
void GetClipStart(SCCOL &nClipX, SCROW &nClipY)
Definition: document.cxx:3173
ScAddress aStart
Definition: address.hxx:500
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
SCROW Row() const
Definition: address.hxx:262
SCROW GetCurY() const
Definition: viewdata.hxx:402
sal_Int64 n
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
static bool HasFiltered(const ScRange &rRange, const ScDocument *pDoc)
Definition: viewutil.cxx:272
ScAddress aEnd
Definition: address.hxx:501
SCTAB GetVisibleTab() const
Definition: transobj.hxx:89
bool CheckDestRanges(const ScDocument *pDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData &rMark, const ScRangeList &rDest)
Definition: cliputil.cxx:96
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
Definition: tabvwshc.cxx:483
Stores options which are only relevant for clipboard documents.
Definition: clipoptions.hxx:19
void GetClipArea(SCCOL &nClipX, SCROW &nClipY, bool bIncludeFiltered)
Definition: document.cxx:3121
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
ScClipParam & GetClipParam()
Definition: document.cxx:2552
static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult)
ScDocument * GetDocument() const
Definition: viewdata.cxx:859
static SfxClassificationCheckPasteResult CheckPaste(const css::uno::Reference< css::document::XDocumentProperties > &xSource, const css::uno::Reference< css::document::XDocumentProperties > &xDestination)
ScDocument * GetDocument() const
Definition: transobj.hxx:81
SC_DLLPUBLIC void PasteFromSystem()
Definition: viewfun3.cxx:483
void PasteFromClipboard(ScViewData *pViewData, ScTabViewShell *pTabViewShell, bool bShowDialog)
Definition: cliputil.cxx:46
void SetTab(SCTAB nTabP)
Definition: address.hxx:283
int i
sal_Int16 SCCOL
Definition: types.hxx:22
InsertDeleteFlags
Definition: global.hxx:158
size_t size() const
Definition: rangelst.hxx:90
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3069
weld::Window * GetDialogParent()
Definition: viewdata.cxx:3063
SC_DLLPUBLIC bool PasteFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction=ScPasteFunc::NONE, bool bSkipEmpty=false, bool bTranspose=false, bool bAsLink=false, InsCellCmd eMoveMode=INS_NONE, InsertDeleteFlags nUndoExtraFlags=InsertDeleteFlags::NONE, bool bAllowDialogs=false)
Definition: viewfun3.cxx:876
SCCOL Col() const
Definition: address.hxx:267
SfxClassificationCheckPasteResult
ScAddress GetCurPos() const
Definition: viewdata.cxx:4023
bool DataPilotMove(const ScRange &rSource, const ScAddress &rDest)
Definition: dbfunc3.cxx:1817
sal_Int32 SCROW
Definition: types.hxx:18
ScClipOptions * GetClipOptions()
Definition: document.hxx:642
void ErrorMessage(const char *pGlobStrId)
Definition: tabview2.cxx:1412
static SC_DLLPUBLIC ScTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
Definition: transobj.cxx:196
css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties
Document properties.
Definition: clipoptions.hxx:23
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1058
SC_DLLPUBLIC void CellContentChanged()
Definition: tabview3.cxx:503
sal_Int16 SCTAB
Definition: types.hxx:23
SCCOL GetCurX() const
Definition: viewdata.hxx:401
bool isMultiRange() const
Definition: clipparam.cxx:38