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
29namespace
30{
31
33bool 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
49void 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 {
85 pTabViewShell->PasteFromSystem();
86 // Anchor To Cell rather than To Page
87 ScDrawView* pDrawView = pTabViewShell->GetScDrawView();
88 if(pDrawView && 1 == pDrawView->GetMarkedObjectCount())
89 {
90 SdrObject* pPickObj = pDrawView->GetMarkedObjectByIndex(0);
91 if(pPickObj)
92 {
93 ScDrawLayer::SetCellAnchoredFromPosition( *pPickObj, rThisDoc, nThisTab, false );
94 }
95 }
96 }
97 else
98 {
99 ScDocument* pClipDoc = pOwnClip->GetDocument();
101 if (pClipDoc->GetClipParam().isMultiRange())
102 // For multi-range paste, we paste values by default.
104
105 if (lcl_checkClassification(pClipDoc, rThisDoc))
106 pTabViewShell->PasteFromClip( nFlags, pClipDoc,
108 bShowDialog ); // allow warning dialog
109 }
110 }
112 {
113 bool entireColumnOrRowSelected = false;
114 if (pOwnClip)
115 {
116 ScClipParam clipParam = pOwnClip->GetDocument()->GetClipParam();
117 if (clipParam.maRanges.size() > 0)
118 {
119 if (clipParam.maRanges[0].aEnd.Col() == pOwnClip->GetDocument()->MaxCol()
120 || clipParam.maRanges[0].aEnd.Row() == pOwnClip->GetDocument()->MaxRow())
121 {
122 entireColumnOrRowSelected = true;
123 }
124 }
125 }
126 const SfxBoolItem* pItem = rThisDoc.GetAttr(nThisCol, nThisRow, nThisTab, ATTR_LINEBREAK);
127 if (pItem->GetValue() || entireColumnOrRowSelected)
128 {
130 pTabViewShell, true /* bColumns */, true /* bRows */, true /* bSizes*/,
131 true /* bHidden */, true /* bFiltered */, true /* bGroups */, nThisTab);
132 }
133 }
134 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
135}
136
138 const ScDocument& rDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData& rMark, const ScRangeList& rDest)
139{
140 for (size_t i = 0, n = rDest.size(); i < n; ++i)
141 {
142 ScRange aTest = rDest[i];
143 // Check for filtered rows in all selected sheets.
144 for (const auto& rTab : rMark)
145 {
146 aTest.aStart.SetTab(rTab);
147 aTest.aEnd.SetTab(rTab);
148 if (ScViewUtil::HasFiltered(aTest, rDoc))
149 {
150 // I don't know how to handle pasting into filtered rows yet.
151 return false;
152 }
153 }
154
155 // Destination range must be an exact multiple of the source range.
156 SCROW nRows = aTest.aEnd.Row() - aTest.aStart.Row() + 1;
157 SCCOL nCols = aTest.aEnd.Col() - aTest.aStart.Col() + 1;
158 SCROW nRowTest = (nRows / nSrcRows) * nSrcRows;
159 SCCOL nColTest = (nCols / nSrcCols) * nSrcCols;
160 if ( rDest.size() > 1 && ( nRows != nRowTest || nCols != nColTest ) )
161 {
162 // Destination range is not a multiple of the source range. Bail out.
163 return false;
164 }
165 }
166 return true;
167}
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCROW Row() const
Definition: address.hxx:274
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SCCOL Col() const
Definition: address.hxx:279
Stores options which are only relevant for clipboard documents.
Definition: clipoptions.hxx:22
css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties
Document properties.
Definition: clipoptions.hxx:25
bool DataPilotMove(const ScRange &rSource, const ScAddress &rDest)
Definition: dbfunc3.cxx:1817
ScClipParam & GetClipParam()
Definition: document.cxx:2564
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:377
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1083
void GetClipArea(SCCOL &nClipX, SCROW &nClipY, bool bIncludeFiltered)
Definition: document.cxx:3147
ScClipOptions * GetClipOptions()
Definition: document.hxx:647
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4684
void GetClipStart(SCCOL &nClipX, SCROW &nClipY)
Definition: document.cxx:3199
static void SetCellAnchoredFromPosition(SdrObject &rObj, const ScDocument &rDoc, SCTAB nTab, bool bResizeWithCell)
Definition: drwlayer.cxx:2575
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
size_t size() const
Definition: rangelst.hxx:89
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
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:593
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
Definition: tabvwshc.cxx:519
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1553
SC_DLLPUBLIC void CellContentChanged()
Definition: tabview3.cxx:513
ScDrawView * GetScDrawView()
Definition: tabview.hxx:352
ScDocument * GetDocument() const
Definition: transobj.hxx:82
SCTAB GetVisibleTab() const
Definition: transobj.hxx:90
static SC_DLLPUBLIC ScTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
Definition: transobj.cxx:199
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3162
weld::Window * GetDialogParent()
Definition: viewdata.cxx:3156
ScAddress GetCurPos() const
Definition: viewdata.cxx:4119
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCCOL GetCurX() const
Definition: viewdata.hxx:401
SC_DLLPUBLIC void PasteFromSystem()
Definition: viewfun3.cxx:484
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:871
static bool HasFiltered(const ScRange &rRange, const ScDocument &rDoc)
Definition: viewutil.cxx:271
SdrObject * GetMarkedObjectByIndex(size_t nNum) const
size_t GetMarkedObjectCount() const
bool GetValue() const
static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult)
static SfxClassificationCheckPasteResult CheckPaste(const css::uno::Reference< css::document::XDocumentProperties > &xSource, const css::uno::Reference< css::document::XDocumentProperties > &xDestination)
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
SfxClassificationCheckPasteResult
@ INS_NONE
Definition: global.hxx:295
InsertDeleteFlags
Definition: global.hxx:149
sal_Int64 n
SC_DLLPUBLIC void PasteFromClipboard(ScViewData &rViewData, ScTabViewShell *pTabViewShell, bool bShowDialog)
Definition: cliputil.cxx:49
bool CheckDestRanges(const ScDocument &rDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData &rMark, const ScRangeList &rDest)
Definition: cliputil.cxx:137
int i
constexpr TypedWhichId< ScLineBreakCell > ATTR_LINEBREAK(139)
This struct stores general clipboard parameters associated with a ScDocument instance created in clip...
Definition: clipparam.hxx:31
bool isMultiRange() const
Definition: clipparam.cxx:38
ScRangeList maRanges
Definition: clipparam.hxx:34
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17