fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / undo / undoblk2.cxx
blobdfd6242346a95e23e7efd0a945a3e567f22345e2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
22 #include "undoblk.hxx"
23 #include "document.hxx"
24 #include "docsh.hxx"
25 #include "tabvwsh.hxx"
26 #include "olinetab.hxx"
27 #include "globstr.hrc"
28 #include "global.hxx"
29 #include "target.hxx"
31 #include "undoolk.hxx"
33 TYPEINIT1(ScUndoWidthOrHeight, SfxUndoAction);
35 /** Change column widths or row heights */
36 ScUndoWidthOrHeight::ScUndoWidthOrHeight( ScDocShell* pNewDocShell,
37 const ScMarkData& rMark,
38 SCCOLROW nNewStart, SCTAB nNewStartTab, SCCOLROW nNewEnd, SCTAB nNewEndTab,
39 ScDocument* pNewUndoDoc, const std::vector<sc::ColRowSpan>& rRanges,
40 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( pNewUndoDoc ),
49 pUndoTab( pNewUndoTab ),
50 maRanges(rRanges),
51 nNewSize( nNewSizeTwips ),
52 bWidth( bNewWidth ),
53 eMode( eNewMode ),
54 pDrawUndo( NULL )
56 pDrawUndo = GetSdrUndoAction( &pDocShell->GetDocument() );
59 ScUndoWidthOrHeight::~ScUndoWidthOrHeight()
61 delete pUndoDoc;
62 delete pUndoTab;
63 DeleteSdrUndoAction( pDrawUndo );
66 OUString ScUndoWidthOrHeight::GetComment() const
68 // [ "optimal " ] "Column width" | "row height"
69 return ( bWidth ?
70 ( ( eMode == SC_SIZE_OPTIMAL )?
71 ScGlobal::GetRscString( STR_UNDO_OPTCOLWIDTH ) :
72 ScGlobal::GetRscString( STR_UNDO_COLWIDTH )
73 ) :
74 ( ( eMode == SC_SIZE_OPTIMAL )?
75 ScGlobal::GetRscString( STR_UNDO_OPTROWHEIGHT ) :
76 ScGlobal::GetRscString( STR_UNDO_ROWHEIGHT )
77 ) );
80 void ScUndoWidthOrHeight::Undo()
82 BeginUndo();
84 ScDocument& rDoc = pDocShell->GetDocument();
86 SCCOLROW nPaintStart = nStart > 0 ? nStart-1 : static_cast<SCCOLROW>(0);
88 if (eMode==SC_SIZE_OPTIMAL)
90 if ( SetViewMarkData( aMarkData ) )
91 nPaintStart = 0; // paint all, because of changed selection
94 //! outlines from all tables?
95 if (pUndoTab) // Outlines are included when saving ?
96 rDoc.SetOutlineTable( nStartTab, pUndoTab );
98 SCTAB nTabCount = rDoc.GetTableCount();
99 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
100 for (; itr != itrEnd && *itr < nTabCount; ++itr)
102 if (bWidth) // Width
104 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, *itr,
105 static_cast<SCCOL>(nEnd), MAXROW, *itr, IDF_NONE,
106 false, &rDoc );
107 rDoc.UpdatePageBreaks( *itr );
108 pDocShell->PostPaint( static_cast<SCCOL>(nPaintStart), 0, *itr,
109 MAXCOL, MAXROW, *itr, PAINT_GRID | PAINT_TOP );
111 else // Height
113 pUndoDoc->CopyToDocument( 0, nStart, *itr, MAXCOL, nEnd, *itr, IDF_NONE, false, &rDoc );
114 rDoc.UpdatePageBreaks( *itr );
115 pDocShell->PostPaint( 0, nPaintStart, *itr, MAXCOL, MAXROW, *itr, PAINT_GRID | PAINT_LEFT );
119 DoSdrUndoAction( pDrawUndo, &rDoc );
121 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
122 if (pViewShell)
124 pViewShell->UpdateScrollBars();
126 SCTAB nCurrentTab = pViewShell->GetViewData().GetTabNo();
127 if ( nCurrentTab < nStartTab || nCurrentTab > nEndTab )
128 pViewShell->SetTabNo( nStartTab );
131 EndUndo();
134 void ScUndoWidthOrHeight::Redo()
136 BeginRedo();
138 bool bPaintAll = false;
139 if (eMode==SC_SIZE_OPTIMAL)
141 if ( SetViewMarkData( aMarkData ) )
142 bPaintAll = true; // paint all, because of changed selection
145 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
146 if (pViewShell)
148 SCTAB nTab = pViewShell->GetViewData().GetTabNo();
149 if ( nTab < nStartTab || nTab > nEndTab )
150 pViewShell->SetTabNo( nStartTab );
152 // SetWidthOrHeight changes current sheet!
153 pViewShell->SetWidthOrHeight(
154 bWidth, maRanges, eMode, nNewSize, false, true, &aMarkData);
157 // paint grid if selection was changed directly at the MarkData
158 if (bPaintAll)
159 pDocShell->PostPaint( 0, 0, nStartTab, MAXCOL, MAXROW, nEndTab, PAINT_GRID );
161 EndRedo();
164 void ScUndoWidthOrHeight::Repeat(SfxRepeatTarget& rTarget)
166 if (rTarget.ISA(ScTabViewTarget))
167 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->SetMarkedWidthOrHeight( bWidth, eMode, nNewSize, true );
170 bool ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget& rTarget) const
172 return rTarget.ISA(ScTabViewTarget);
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */