1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
25 #include "tabvwsh.hxx"
26 #include "olinetab.hxx"
27 #include "globstr.hrc"
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
, SCCOLROW nNewCnt
, SCCOLROW
* pNewRanges
,
40 ScOutlineTable
* pNewUndoTab
,
41 ScSizeMode eNewMode
, sal_uInt16 nNewSizeTwips
, sal_Bool bNewWidth
) :
42 ScSimpleUndo( pNewDocShell
),
46 nStartTab( nNewStartTab
),
47 nEndTab( nNewEndTab
),
48 pUndoDoc( pNewUndoDoc
),
49 pUndoTab( pNewUndoTab
),
51 pRanges( pNewRanges
),
52 nNewSize( nNewSizeTwips
),
57 pDrawUndo
= GetSdrUndoAction( pDocShell
->GetDocument() );
60 ScUndoWidthOrHeight::~ScUndoWidthOrHeight()
65 DeleteSdrUndoAction( pDrawUndo
);
68 OUString
ScUndoWidthOrHeight::GetComment() const
70 // [ "optimal " ] "Column width" | "row height"
72 ( ( eMode
== SC_SIZE_OPTIMAL
)?
73 ScGlobal::GetRscString( STR_UNDO_OPTCOLWIDTH
) :
74 ScGlobal::GetRscString( STR_UNDO_COLWIDTH
)
76 ( ( eMode
== SC_SIZE_OPTIMAL
)?
77 ScGlobal::GetRscString( STR_UNDO_OPTROWHEIGHT
) :
78 ScGlobal::GetRscString( STR_UNDO_ROWHEIGHT
)
82 void ScUndoWidthOrHeight::Undo()
86 ScDocument
* pDoc
= pDocShell
->GetDocument();
88 SCCOLROW nPaintStart
= nStart
> 0 ? nStart
-1 : static_cast<SCCOLROW
>(0);
90 if (eMode
==SC_SIZE_OPTIMAL
)
92 if ( SetViewMarkData( aMarkData
) )
93 nPaintStart
= 0; // paint all, because of changed selection
96 //! outlines from all tables?
97 if (pUndoTab
) // Outlines are included when saving ?
98 pDoc
->SetOutlineTable( nStartTab
, pUndoTab
);
100 SCTAB nTabCount
= pDoc
->GetTableCount();
101 ScMarkData::iterator itr
= aMarkData
.begin(), itrEnd
= aMarkData
.end();
102 for (; itr
!= itrEnd
&& *itr
< nTabCount
; ++itr
)
106 pUndoDoc
->CopyToDocument( static_cast<SCCOL
>(nStart
), 0, *itr
,
107 static_cast<SCCOL
>(nEnd
), MAXROW
, *itr
, IDF_NONE
,
109 pDoc
->UpdatePageBreaks( *itr
);
110 pDocShell
->PostPaint( static_cast<SCCOL
>(nPaintStart
), 0, *itr
,
111 MAXCOL
, MAXROW
, *itr
, PAINT_GRID
| PAINT_TOP
);
115 pUndoDoc
->CopyToDocument( 0, nStart
, *itr
, MAXCOL
, nEnd
, *itr
, IDF_NONE
, false, pDoc
);
116 pDoc
->UpdatePageBreaks( *itr
);
117 pDocShell
->PostPaint( 0, nPaintStart
, *itr
, MAXCOL
, MAXROW
, *itr
, PAINT_GRID
| PAINT_LEFT
);
121 DoSdrUndoAction( pDrawUndo
, pDoc
);
123 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
126 pViewShell
->UpdateScrollBars();
128 SCTAB nCurrentTab
= pViewShell
->GetViewData()->GetTabNo();
129 if ( nCurrentTab
< nStartTab
|| nCurrentTab
> nEndTab
)
130 pViewShell
->SetTabNo( nStartTab
);
136 void ScUndoWidthOrHeight::Redo()
140 sal_Bool bPaintAll
= false;
141 if (eMode
==SC_SIZE_OPTIMAL
)
143 if ( SetViewMarkData( aMarkData
) )
144 bPaintAll
= sal_True
; // paint all, because of changed selection
147 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
150 SCTAB nTab
= pViewShell
->GetViewData()->GetTabNo();
151 if ( nTab
< nStartTab
|| nTab
> nEndTab
)
152 pViewShell
->SetTabNo( nStartTab
);
154 // SetWidthOrHeight changes current sheet!
155 pViewShell
->SetWidthOrHeight( bWidth
, nRangeCnt
, pRanges
, eMode
, nNewSize
, false, true, &aMarkData
);
158 // paint grid if selection was changed directly at the MarkData
160 pDocShell
->PostPaint( 0, 0, nStartTab
, MAXCOL
, MAXROW
, nEndTab
, PAINT_GRID
);
165 void ScUndoWidthOrHeight::Repeat(SfxRepeatTarget
& rTarget
)
167 if (rTarget
.ISA(ScTabViewTarget
))
168 ((ScTabViewTarget
&)rTarget
).GetViewShell()->SetMarkedWidthOrHeight( bWidth
, eMode
, nNewSize
, sal_True
);
171 bool ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget
& rTarget
) const
173 return rTarget
.ISA(ScTabViewTarget
);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */