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 <attrib.hxx>
12 #include <viewdata.hxx>
13 #include <tabvwsh.hxx>
14 #include <transobj.hxx>
15 #include <document.hxx>
16 #include <dpobject.hxx>
17 #include <globstr.hrc>
18 #include <clipparam.hxx>
19 #include <clipoptions.hxx>
20 #include <rangelst.hxx>
21 #include <viewutil.hxx>
22 #include <markdata.hxx>
23 #include <gridwin.hxx>
24 #include <scitems.hxx>
25 
27 #include <comphelper/lok.hxx>
28 
29 namespace
30 {
31 
33 bool lcl_checkClassification(ScDocument* pSourceDoc, const ScDocument& rDestinationDoc)
34 {
35  if (!pSourceDoc)
36  return true;
37 
38  ScClipOptions* pSourceOptions = pSourceDoc->GetClipOptions();
39  SfxObjectShell* pDestinationShell = rDestinationDoc.GetDocumentShell();
40  if (!pSourceOptions || !pDestinationShell)
41  return true;
42 
45 }
46 
47 }
48 
49 void ScClipUtil::PasteFromClipboard( ScViewData& rViewData, ScTabViewShell* pTabViewShell, bool bShowDialog )
50 {
52  ScDocument& rThisDoc = rViewData.GetDocument();
53  SCCOL nThisCol = rViewData.GetCurX();
54  SCROW nThisRow = rViewData.GetCurY();
55  SCTAB nThisTab = rViewData.GetTabNo();
56  ScDPObject* pDPObj = rThisDoc.GetDPAtCursor( nThisCol, nThisRow, nThisTab );
57 
58  if ( pOwnClip && pDPObj )
59  {
60  // paste from Calc into DataPilot table: sort (similar to drag & drop)
61 
62  ScDocument* pClipDoc = pOwnClip->GetDocument();
63  SCTAB nSourceTab = pOwnClip->GetVisibleTab();
64 
65  SCCOL nClipStartX;
66  SCROW nClipStartY;
67  SCCOL nClipEndX;
68  SCROW nClipEndY;
69  pClipDoc->GetClipStart( nClipStartX, nClipStartY );
70  pClipDoc->GetClipArea( nClipEndX, nClipEndY, true );
71  nClipEndX = nClipEndX + nClipStartX;
72  nClipEndY = nClipEndY + nClipStartY; // GetClipArea returns the difference
73 
74  ScRange aSource( nClipStartX, nClipStartY, nSourceTab, nClipEndX, nClipEndY, nSourceTab );
75  bool bDone = pTabViewShell->DataPilotMove( aSource, rViewData.GetCurPos() );
76  if ( !bDone )
77  pTabViewShell->ErrorMessage( STR_ERR_DATAPILOT_INPUT );
78  }
79  else
80  {
81  // normal paste
82  weld::WaitObject aWait( rViewData.GetDialogParent() );
83  if (!pOwnClip)
84  pTabViewShell->PasteFromSystem();
85  else
86  {
87  ScDocument* pClipDoc = pOwnClip->GetDocument();
89  if (pClipDoc->GetClipParam().isMultiRange())
90  // For multi-range paste, we paste values by default.
91  nFlags &= ~InsertDeleteFlags::FORMULA;
92 
93  if (lcl_checkClassification(pClipDoc, rThisDoc))
94  pTabViewShell->PasteFromClip( nFlags, pClipDoc,
95  ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE,
96  bShowDialog ); // allow warning dialog
97  }
98  }
100  {
101  bool entireColumnOrRowSelected = false;
102  if (pOwnClip)
103  {
104  ScClipParam clipParam = pOwnClip->GetDocument()->GetClipParam();
105  if (clipParam.maRanges.size() > 0)
106  {
107  if (clipParam.maRanges[0].aEnd.Col() == pOwnClip->GetDocument()->MaxCol()
108  || clipParam.maRanges[0].aEnd.Row() == pOwnClip->GetDocument()->MaxRow())
109  {
110  entireColumnOrRowSelected = true;
111  }
112  }
113  }
114  const SfxBoolItem* pItem = rThisDoc.GetAttr(nThisCol, nThisRow, nThisTab, ATTR_LINEBREAK);
115  if (pItem->GetValue() || entireColumnOrRowSelected)
116  {
118  pTabViewShell, true /* bColumns */, true /* bRows */, true /* bSizes*/,
119  true /* bHidden */, true /* bFiltered */, true /* bGroups */, nThisTab);
120  }
121  }
122  pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
123 }
124 
126  const ScDocument& rDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData& rMark, const ScRangeList& rDest)
127 {
128  for (size_t i = 0, n = rDest.size(); i < n; ++i)
129  {
130  ScRange aTest = rDest[i];
131  // Check for filtered rows in all selected sheets.
132  for (const auto& rTab : rMark)
133  {
134  aTest.aStart.SetTab(rTab);
135  aTest.aEnd.SetTab(rTab);
136  if (ScViewUtil::HasFiltered(aTest, rDoc))
137  {
138  // I don't know how to handle pasting into filtered rows yet.
139  return false;
140  }
141  }
142 
143  // Destination range must be an exact multiple of the source range.
144  SCROW nRows = aTest.aEnd.Row() - aTest.aStart.Row() + 1;
145  SCCOL nCols = aTest.aEnd.Col() - aTest.aStart.Col() + 1;
146  SCROW nRowTest = (nRows / nSrcRows) * nSrcRows;
147  SCCOL nColTest = (nCols / nSrcCols) * nSrcCols;
148  if ( rDest.size() > 1 && ( nRows != nRowTest || nCols != nColTest ) )
149  {
150  // Destination range is not a multiple of the source range. Bail out.
151  return false;
152  }
153  }
154  return true;
155 }
156 
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool GetValue() const
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:377
void GetClipStart(SCCOL &nClipX, SCROW &nClipY)
Definition: document.cxx:3221
ScAddress aStart
Definition: address.hxx:497
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1446
SCROW Row() const
Definition: address.hxx:274
SCROW GetCurY() const
Definition: viewdata.hxx:402
sal_Int64 n
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScAddress aEnd
Definition: address.hxx:498
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
SCTAB GetVisibleTab() const
Definition: transobj.hxx:88
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
Definition: tabvwshc.cxx:494
Stores options which are only relevant for clipboard documents.
Definition: clipoptions.hxx:21
constexpr TypedWhichId< ScLineBreakCell > ATTR_LINEBREAK(139)
void GetClipArea(SCCOL &nClipX, SCROW &nClipY, bool bIncludeFiltered)
Definition: document.cxx:3169
static void notifyAllViewsSheetGeomInvalidation(const SfxViewShell *pForViewShell, bool bColumns, bool bRows, bool bSizes, bool bHidden, bool bFiltered, bool bGroups, SCTAB nCurrentTabIndex)
Emits a LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY for all views whose current tab is equal to nCurrentTa...
Definition: tabvwshc.cxx:568
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
ScClipParam & GetClipParam()
Definition: document.cxx:2592
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:891
static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult)
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:80
SC_DLLPUBLIC void PasteFromSystem()
Definition: viewfun3.cxx:485
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4764
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:890
static bool HasFiltered(const ScRange &rRange, const ScDocument &rDoc)
Definition: viewutil.cxx:271
int i
sal_Int16 SCCOL
Definition: types.hxx:21
InsertDeleteFlags
Definition: global.hxx:147
size_t size() const
Definition: rangelst.hxx:89
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3151
SC_DLLPUBLIC bool PasteFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction=ScPasteFunc::NONE, bool bSkipEmptyCells=false, bool bTranspose=false, bool bAsLink=false, InsCellCmd eMoveMode=INS_NONE, InsertDeleteFlags nUndoExtraFlags=InsertDeleteFlags::NONE, bool bAllowDialogs=false)
Definition: viewfun3.cxx:872
weld::Window * GetDialogParent()
Definition: viewdata.cxx:3145
ScRangeList maRanges
Definition: clipparam.hxx:34
SCCOL Col() const
Definition: address.hxx:279
SfxClassificationCheckPasteResult
ScAddress GetCurPos() const
Definition: viewdata.cxx:4121
bool CheckDestRanges(const ScDocument &rDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData &rMark, const ScRangeList &rDest)
Definition: cliputil.cxx:125
bool DataPilotMove(const ScRange &rSource, const ScAddress &rDest)
Definition: dbfunc3.cxx:1819
sal_Int32 SCROW
Definition: types.hxx:17
ScClipOptions * GetClipOptions()
Definition: document.hxx:645
static SC_DLLPUBLIC ScTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
Definition: transobj.cxx:197
css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties
Document properties.
Definition: clipoptions.hxx:25
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1080
SC_DLLPUBLIC void PasteFromClipboard(ScViewData &rViewData, ScTabViewShell *pTabViewShell, bool bShowDialog)
Definition: cliputil.cxx:49
This struct stores general clipboard parameters associated with a ScDocument instance created in clip...
Definition: clipparam.hxx:30
SC_DLLPUBLIC void CellContentChanged()
Definition: tabview3.cxx:513
sal_Int16 SCTAB
Definition: types.hxx:22
SCCOL GetCurX() const
Definition: viewdata.hxx:401
bool isMultiRange() const
Definition: clipparam.cxx:38