LibreOffice Module sc (master) 1
undoblk2.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <undoblk.hxx>
21#include <document.hxx>
22#include <docsh.hxx>
23#include <tabvwsh.hxx>
24#include <olinetab.hxx>
25#include <globstr.hrc>
26#include <scresid.hxx>
27#include <global.hxx>
28#include <target.hxx>
29#include <columnspanset.hxx>
30
31#include <undoolk.hxx>
32
33#include <svx/svdundo.hxx>
34
37 const ScMarkData& rMark,
38 SCCOLROW nNewStart, SCTAB nNewStartTab, SCCOLROW nNewEnd, SCTAB nNewEndTab,
39 ScDocumentUniquePtr pNewUndoDoc, std::vector<sc::ColRowSpan>&& rRanges,
40 std::unique_ptr<ScOutlineTable> pNewUndoTab,
41 ScSizeMode eNewMode, sal_uInt16 nNewSizeTwips, bool bNewWidth ) :
42 ScSimpleUndo( pNewDocShell ),
43 aMarkData( rMark ),
44 nStart( nNewStart ),
45 nEnd( nNewEnd ),
46 nStartTab( nNewStartTab ),
47 nEndTab( nNewEndTab ),
48 pUndoDoc( std::move(pNewUndoDoc) ),
49 pUndoTab( std::move(pNewUndoTab) ),
50 maRanges( std::move(rRanges) ),
51 nNewSize( nNewSizeTwips ),
52 bWidth( bNewWidth ),
53 eMode( eNewMode )
54{
56}
57
59{
60 pUndoDoc.reset();
61 pUndoTab.reset();
62 pDrawUndo.reset();
63}
64
66{
67 // [ "optimal " ] "Column width" | "row height"
68 return ( bWidth ?
69 ( ( eMode == SC_SIZE_OPTIMAL )?
70 ScResId( STR_UNDO_OPTCOLWIDTH ) :
71 ScResId( STR_UNDO_COLWIDTH )
72 ) :
73 ( ( eMode == SC_SIZE_OPTIMAL )?
74 ScResId( STR_UNDO_OPTROWHEIGHT ) :
75 ScResId( STR_UNDO_ROWHEIGHT )
76 ) );
77}
78
80{
81 BeginUndo();
82
84
85 SCCOLROW nPaintStart = nStart > 0 ? nStart-1 : static_cast<SCCOLROW>(0);
86
88 {
90 nPaintStart = 0; // paint all, because of changed selection
91 }
92
94 if (pUndoTab) // Outlines are included when saving ?
95 rDoc.SetOutlineTable( nStartTab, pUndoTab.get() );
96
98 SCTAB nTabCount = rDoc.GetTableCount();
99 for (const auto& rTab : aMarkData)
100 {
101 if (rTab >= nTabCount)
102 break;
103
104 if (pViewShell)
105 pViewShell->OnLOKSetWidthOrHeight(nStart, bWidth);
106
107 if (bWidth) // Width
108 {
109 pUndoDoc->CopyToDocument(static_cast<SCCOL>(nStart), 0, rTab,
110 static_cast<SCCOL>(nEnd), rDoc.MaxRow(), rTab, InsertDeleteFlags::NONE,
111 false, rDoc);
112 rDoc.UpdatePageBreaks( rTab );
113 pDocShell->PostPaint( static_cast<SCCOL>(nPaintStart), 0, rTab,
114 rDoc.MaxCol(), rDoc.MaxRow(), rTab, PaintPartFlags::Grid | PaintPartFlags::Top );
115 }
116 else // Height
117 {
118 pUndoDoc->CopyToDocument(0, nStart, rTab, rDoc.MaxCol(), nEnd, rTab, InsertDeleteFlags::NONE, false, rDoc);
119 rDoc.UpdatePageBreaks( rTab );
120 pDocShell->PostPaint( 0, nPaintStart, rTab, rDoc.MaxCol(), rDoc.MaxRow(), rTab, PaintPartFlags::Grid | PaintPartFlags::Left );
121 }
122 }
123
124 DoSdrUndoAction( pDrawUndo.get(), &rDoc );
125
126 if (pViewShell)
127 {
128 SCTAB nCurrentTab = pViewShell->GetViewData().GetTabNo();
129 bool bAffectsVisibility = (eMode != SC_SIZE_ORIGINAL && eMode != SC_SIZE_VISOPT);
131 pViewShell, bWidth /* bColumns */, !bWidth /* bRows */,
132 true /* bSizes*/, bAffectsVisibility /* bHidden */, bAffectsVisibility /* bFiltered */,
133 false /* bGroups */, nCurrentTab);
135
136 if ( nCurrentTab < nStartTab || nCurrentTab > nEndTab )
137 pViewShell->SetTabNo( nStartTab );
138 }
139
140 EndUndo();
141}
142
144{
145 BeginRedo();
146
148
149 bool bPaintAll = false;
151 {
152 if ( SetViewMarkData( aMarkData ) )
153 bPaintAll = true; // paint all, because of changed selection
154 }
155
157 if (pViewShell)
158 {
159 SCTAB nTab = pViewShell->GetViewData().GetTabNo();
160 if ( nTab < nStartTab || nTab > nEndTab )
161 pViewShell->SetTabNo( nStartTab );
162
163 // SetWidthOrHeight changes current sheet!
164 pViewShell->SetWidthOrHeight(
166 }
167
168 // paint grid if selection was changed directly at the MarkData
169 if (bPaintAll)
171
172 EndRedo();
173}
174
175void ScUndoWidthOrHeight::Repeat(SfxRepeatTarget& rTarget)
176{
177 if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
178 pViewTarget->GetViewShell()->SetMarkedWidthOrHeight( bWidth, eMode, nNewSize );
179}
180
181bool ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget& rTarget) const
182{
183 return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
184}
185
186/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
void UpdatePageBreaks(SCTAB nTab, const ScRange *pUserArea=nullptr)
Definition: document.cxx:6210
bool SetOutlineTable(SCTAB nTab, const ScOutlineTable *pNewOutline)
Definition: documen3.cxx:754
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void BeginRedo()
Definition: undobase.cxx:145
void EndRedo()
Definition: undobase.cxx:154
bool SetViewMarkData(const ScMarkData &rMarkData)
Definition: undobase.cxx:55
void EndUndo()
Definition: undobase.cxx:125
ScDocShell * pDocShell
Definition: undobase.hxx:50
void BeginUndo()
Definition: undobase.cxx:90
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 ScTabViewShell * GetActiveViewShell()
Definition: tabvwsh4.cxx:1076
ScViewData & GetViewData()
Definition: tabview.hxx:344
void UpdateScrollBars(HeaderType eHeaderType=BOTH_HEADERS)
Definition: tabview4.cxx:389
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1819
virtual ~ScUndoWidthOrHeight() override
Definition: undoblk2.cxx:58
virtual void Undo() override
Definition: undoblk2.cxx:79
virtual void Repeat(SfxRepeatTarget &rTarget) override
Definition: undoblk2.cxx:175
std::vector< sc::ColRowSpan > maRanges
Definition: undoblk.hxx:385
std::unique_ptr< ScOutlineTable > pUndoTab
Definition: undoblk.hxx:384
std::unique_ptr< SdrUndoAction > pDrawUndo
Definition: undoblk.hxx:389
sal_uInt16 nNewSize
Definition: undoblk.hxx:386
ScDocumentUniquePtr pUndoDoc
Definition: undoblk.hxx:383
ScMarkData aMarkData
Definition: undoblk.hxx:378
virtual void Redo() override
Definition: undoblk2.cxx:143
ScUndoWidthOrHeight(ScDocShell *pNewDocShell, const ScMarkData &rMark, SCCOLROW nNewStart, SCTAB nNewStartTab, SCCOLROW nNewEnd, SCTAB nNewEndTab, ScDocumentUniquePtr pNewUndoDoc, std::vector< sc::ColRowSpan > &&rRanges, std::unique_ptr< ScOutlineTable > pNewUndoTab, ScSizeMode eNewMode, sal_uInt16 nNewSizeTwips, bool bNewWidth)
Change column widths or row heights.
Definition: undoblk2.cxx:36
virtual OUString GetComment() const override
Definition: undoblk2.cxx:65
virtual bool CanRepeat(SfxRepeatTarget &rTarget) const override
Definition: undoblk2.cxx:181
ScSizeMode eMode
Definition: undoblk.hxx:388
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void SetWidthOrHeight(bool bWidth, const std::vector< sc::ColRowSpan > &rRanges, ScSizeMode eMode, sal_uInt16 nSizeTwips, bool bRecord=true, const ScMarkData *pMarkData=nullptr)
Definition: viewfunc.cxx:2159
void OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth)
Definition: viewfunc.cxx:1697
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2720
FilterGroup & rTarget
ScSizeMode
Definition: global.hxx:351
@ SC_SIZE_OPTIMAL
Definition: global.hxx:353
@ SC_SIZE_VISOPT
Definition: global.hxx:355
@ SC_SIZE_ORIGINAL
Definition: global.hxx:356
Mode eMode
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
@ COLUMN_HEADER
Definition: tabview.hxx:59
@ ROW_HEADER
Definition: tabview.hxx:60
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
std::unique_ptr< SdrUndoAction > GetSdrUndoAction(ScDocument *pDoc)
Definition: undoolk.cxx:26
void DoSdrUndoAction(SdrUndoAction *pUndoAction, ScDocument *pDoc)
Definition: undoolk.cxx:35