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() == MAXCOLCOUNT -1 || clipParam.maRanges[0].aEnd.Row() == MAXROWCOUNT - 1)
108  entireColumnOrRowSelected = true;
109  }
110  }
111  const SfxBoolItem* pItem = rThisDoc.GetAttr(nThisCol, nThisRow, nThisTab, ATTR_LINEBREAK);
112  if (pItem->GetValue() || entireColumnOrRowSelected)
113  {
115  pTabViewShell, true /* bColumns */, true /* bRows */, true /* bSizes*/,
116  true /* bHidden */, true /* bFiltered */, true /* bGroups */, nThisTab);
117  }
118  }
119  pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
120 }
121 
123  const ScDocument& rDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData& rMark, const ScRangeList& rDest)
124 {
125  for (size_t i = 0, n = rDest.size(); i < n; ++i)
126  {
127  ScRange aTest = rDest[i];
128  // Check for filtered rows in all selected sheets.
129  for (const auto& rTab : rMark)
130  {
131  aTest.aStart.SetTab(rTab);
132  aTest.aEnd.SetTab(rTab);
133  if (ScViewUtil::HasFiltered(aTest, rDoc))
134  {
135  // I don't know how to handle pasting into filtered rows yet.
136  return false;
137  }
138  }
139 
140  // Destination range must be an exact multiple of the source range.
141  SCROW nRows = aTest.aEnd.Row() - aTest.aStart.Row() + 1;
142  SCCOL nCols = aTest.aEnd.Col() - aTest.aStart.Col() + 1;
143  SCROW nRowTest = (nRows / nSrcRows) * nSrcRows;
144  SCCOL nColTest = (nCols / nSrcCols) * nSrcCols;
145  if ( rDest.size() > 1 && ( nRows != nRowTest || nCols != nColTest ) )
146  {
147  // Destination range is not a multiple of the source range. Bail out.
148  return false;
149  }
150  }
151  return true;
152 }
153 
154 /* 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:3201
ScAddress aStart
Definition: address.hxx:499
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:1413
SCROW Row() const
Definition: address.hxx:261
SCROW GetCurY() const
Definition: viewdata.hxx:401
sal_Int64 n
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
ScAddress aEnd
Definition: address.hxx:500
ScDocument & GetDocument() const
Definition: viewdata.hxx:379
SCTAB GetVisibleTab() const
Definition: transobj.hxx:88
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
Definition: tabvwshc.cxx:486
Stores options which are only relevant for clipboard documents.
Definition: clipoptions.hxx:21
constexpr TypedWhichId< ScLineBreakCell > ATTR_LINEBREAK(139)
const SCCOL MAXCOLCOUNT
Definition: address.hxx:63
void GetClipArea(SCCOL &nClipX, SCROW &nClipY, bool bIncludeFiltered)
Definition: document.cxx:3149
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:560
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
ScClipParam & GetClipParam()
Definition: document.cxx:2565
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:483
const SCROW MAXROWCOUNT
Definition: address.hxx:62
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4745
void SetTab(SCTAB nTabP)
Definition: address.hxx:282
static bool HasFiltered(const ScRange &rRange, const ScDocument &rDoc)
Definition: viewutil.cxx:272
int i
sal_Int16 SCCOL
Definition: types.hxx:21
InsertDeleteFlags
Definition: global.hxx:158
size_t size() const
Definition: rangelst.hxx:89
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3124
weld::Window * GetDialogParent()
Definition: viewdata.cxx:3118
ScRangeList maRanges
Definition: clipparam.hxx:34
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:862
SCCOL Col() const
Definition: address.hxx:266
SfxClassificationCheckPasteResult
ScAddress GetCurPos() const
Definition: viewdata.cxx:4076
bool CheckDestRanges(const ScDocument &rDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData &rMark, const ScRangeList &rDest)
Definition: cliputil.cxx:122
bool DataPilotMove(const ScRange &rSource, const ScAddress &rDest)
Definition: dbfunc3.cxx:1819
sal_Int32 SCROW
Definition: types.hxx:17
ScClipOptions * GetClipOptions()
Definition: document.hxx:634
static SC_DLLPUBLIC ScTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
Definition: transobj.cxx:194
css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties
Document properties.
Definition: clipoptions.hxx:25
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1057
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:514
sal_Int16 SCTAB
Definition: types.hxx:22
SCCOL GetCurX() const
Definition: viewdata.hxx:400
bool isMultiRange() const
Definition: clipparam.cxx:38