merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / undo / undoblk2.cxx
blob9c03e9a55fd3e107816e4b624cb55e4e5f9fa61c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undoblk2.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes -----------------------------------------------------
38 #ifndef PCH
39 #include "scitems.hxx" // SearchItem
40 #endif
42 // INCLUDE ---------------------------------------------------------------
44 #include "undoblk.hxx"
45 #include "document.hxx"
46 #include "docsh.hxx"
47 #include "tabvwsh.hxx"
48 #include "olinetab.hxx"
49 #include "globstr.hrc"
50 #include "global.hxx"
51 #include "target.hxx"
53 #include "undoolk.hxx" //! GetUndo ins Document verschieben!
56 // STATIC DATA -----------------------------------------------------------
58 TYPEINIT1(ScUndoWidthOrHeight, SfxUndoAction);
60 // -----------------------------------------------------------------------
65 // Spaltenbreiten oder Zeilenhoehen aendern
68 ScUndoWidthOrHeight::ScUndoWidthOrHeight( ScDocShell* pNewDocShell,
69 const ScMarkData& rMark,
70 SCCOLROW nNewStart, SCTAB nNewStartTab, SCCOLROW nNewEnd, SCTAB nNewEndTab,
71 ScDocument* pNewUndoDoc, SCCOLROW nNewCnt, SCCOLROW* pNewRanges,
72 ScOutlineTable* pNewUndoTab,
73 ScSizeMode eNewMode, USHORT nNewSizeTwips, BOOL bNewWidth ) :
74 ScSimpleUndo( pNewDocShell ),
75 aMarkData( rMark ),
76 nStart( nNewStart ),
77 nEnd( nNewEnd ),
78 nStartTab( nNewStartTab ),
79 nEndTab( nNewEndTab ),
80 pUndoDoc( pNewUndoDoc ),
81 pUndoTab( pNewUndoTab ),
82 nRangeCnt( nNewCnt ),
83 pRanges( pNewRanges ),
84 nNewSize( nNewSizeTwips ),
85 bWidth( bNewWidth ),
86 eMode( eNewMode ),
87 pDrawUndo( NULL )
89 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
92 __EXPORT ScUndoWidthOrHeight::~ScUndoWidthOrHeight()
94 delete[] pRanges;
95 delete pUndoDoc;
96 delete pUndoTab;
97 DeleteSdrUndoAction( pDrawUndo );
100 String __EXPORT ScUndoWidthOrHeight::GetComment() const
102 // [ "optimale " ] "Spaltenbreite" | "Zeilenhoehe"
103 return ( bWidth ?
104 ( ( eMode == SC_SIZE_OPTIMAL )?
105 ScGlobal::GetRscString( STR_UNDO_OPTCOLWIDTH ) :
106 ScGlobal::GetRscString( STR_UNDO_COLWIDTH )
108 ( ( eMode == SC_SIZE_OPTIMAL )?
109 ScGlobal::GetRscString( STR_UNDO_OPTROWHEIGHT ) :
110 ScGlobal::GetRscString( STR_UNDO_ROWHEIGHT )
111 ) );
114 void __EXPORT ScUndoWidthOrHeight::Undo()
116 BeginUndo();
118 ScDocument* pDoc = pDocShell->GetDocument();
119 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
121 SCCOLROW nPaintStart = nStart > 0 ? nStart-1 : static_cast<SCCOLROW>(0);
123 if (eMode==SC_SIZE_OPTIMAL)
125 if (pViewShell)
127 pViewShell->SetMarkData( aMarkData );
129 nPaintStart = 0; // paint all, because of changed selection
133 //! outlines from all tables?
134 if (pUndoTab) // Outlines mit gespeichert?
135 pDoc->SetOutlineTable( nStartTab, pUndoTab );
137 SCTAB nTabCount = pDoc->GetTableCount();
138 SCTAB nTab;
139 for (nTab=0; nTab<nTabCount; nTab++)
140 if (aMarkData.GetTableSelect(nTab))
142 if (bWidth) // Width
144 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
145 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE,
146 FALSE, pDoc );
147 pDoc->UpdatePageBreaks( nTab );
148 pDocShell->PostPaint( static_cast<SCCOL>(nPaintStart), 0, nTab,
149 MAXCOL, MAXROW, nTab, PAINT_GRID | PAINT_TOP );
151 else // Height
153 pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, FALSE, pDoc );
154 pDoc->UpdatePageBreaks( nTab );
155 pDocShell->PostPaint( 0, nPaintStart, nTab, MAXCOL, MAXROW, nTab, PAINT_GRID | PAINT_LEFT );
159 DoSdrUndoAction( pDrawUndo, pDoc );
161 if (pViewShell)
163 pViewShell->UpdateScrollBars();
165 SCTAB nCurrentTab = pViewShell->GetViewData()->GetTabNo();
166 if ( nCurrentTab < nStartTab || nCurrentTab > nEndTab )
167 pViewShell->SetTabNo( nStartTab );
170 EndUndo();
173 void __EXPORT ScUndoWidthOrHeight::Redo()
175 BeginRedo();
177 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
179 BOOL bPaintAll = FALSE;
180 if (eMode==SC_SIZE_OPTIMAL)
182 if (pViewShell)
184 pViewShell->SetMarkData( aMarkData );
186 bPaintAll = TRUE; // paint all, because of changed selection
190 if (pViewShell)
192 SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
193 if ( nTab < nStartTab || nTab > nEndTab )
194 pViewShell->SetTabNo( nStartTab );
197 // SetWidthOrHeight aendert aktuelle Tabelle !
198 pViewShell->SetWidthOrHeight( bWidth, nRangeCnt, pRanges, eMode, nNewSize, FALSE, TRUE, &aMarkData );
200 // paint grid if selection was changed directly at the MarkData
201 if (bPaintAll)
202 pDocShell->PostPaint( 0, 0, nStartTab, MAXCOL, MAXROW, nEndTab, PAINT_GRID );
204 EndRedo();
207 void __EXPORT ScUndoWidthOrHeight::Repeat(SfxRepeatTarget& rTarget)
209 if (rTarget.ISA(ScTabViewTarget))
210 ((ScTabViewTarget&)rTarget).GetViewShell()->SetMarkedWidthOrHeight( bWidth, eMode, nNewSize, TRUE );
213 BOOL __EXPORT ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget& rTarget) const
215 return (rTarget.ISA(ScTabViewTarget));