xref: /trunk/main/sc/source/ui/undo/undoblk2.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // System - Includes -----------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #ifndef PCH
36*cdf0e10cSrcweir #include "scitems.hxx"              // SearchItem
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include "undoblk.hxx"
42*cdf0e10cSrcweir #include "document.hxx"
43*cdf0e10cSrcweir #include "docsh.hxx"
44*cdf0e10cSrcweir #include "tabvwsh.hxx"
45*cdf0e10cSrcweir #include "olinetab.hxx"
46*cdf0e10cSrcweir #include "globstr.hrc"
47*cdf0e10cSrcweir #include "global.hxx"
48*cdf0e10cSrcweir #include "target.hxx"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include "undoolk.hxx"              //! GetUndo ins Document verschieben!
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir TYPEINIT1(ScUndoWidthOrHeight,      SfxUndoAction);
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir // -----------------------------------------------------------------------
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //
62*cdf0e10cSrcweir //      Spaltenbreiten oder Zeilenhoehen aendern
63*cdf0e10cSrcweir //
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir ScUndoWidthOrHeight::ScUndoWidthOrHeight( ScDocShell* pNewDocShell,
66*cdf0e10cSrcweir                 const ScMarkData& rMark,
67*cdf0e10cSrcweir                 SCCOLROW nNewStart, SCTAB nNewStartTab, SCCOLROW nNewEnd, SCTAB nNewEndTab,
68*cdf0e10cSrcweir                 ScDocument* pNewUndoDoc, SCCOLROW nNewCnt, SCCOLROW* pNewRanges,
69*cdf0e10cSrcweir                 ScOutlineTable* pNewUndoTab,
70*cdf0e10cSrcweir                 ScSizeMode eNewMode, sal_uInt16 nNewSizeTwips, sal_Bool bNewWidth ) :
71*cdf0e10cSrcweir     ScSimpleUndo( pNewDocShell ),
72*cdf0e10cSrcweir     aMarkData( rMark ),
73*cdf0e10cSrcweir     nStart( nNewStart ),
74*cdf0e10cSrcweir     nEnd( nNewEnd ),
75*cdf0e10cSrcweir     nStartTab( nNewStartTab ),
76*cdf0e10cSrcweir     nEndTab( nNewEndTab ),
77*cdf0e10cSrcweir     pUndoDoc( pNewUndoDoc ),
78*cdf0e10cSrcweir     pUndoTab( pNewUndoTab ),
79*cdf0e10cSrcweir     nRangeCnt( nNewCnt ),
80*cdf0e10cSrcweir     pRanges( pNewRanges ),
81*cdf0e10cSrcweir     nNewSize( nNewSizeTwips ),
82*cdf0e10cSrcweir     bWidth( bNewWidth ),
83*cdf0e10cSrcweir     eMode( eNewMode ),
84*cdf0e10cSrcweir     pDrawUndo( NULL )
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir __EXPORT ScUndoWidthOrHeight::~ScUndoWidthOrHeight()
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir     delete[] pRanges;
92*cdf0e10cSrcweir     delete pUndoDoc;
93*cdf0e10cSrcweir     delete pUndoTab;
94*cdf0e10cSrcweir     DeleteSdrUndoAction( pDrawUndo );
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir String __EXPORT ScUndoWidthOrHeight::GetComment() const
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir     // [ "optimale " ] "Spaltenbreite" | "Zeilenhoehe"
100*cdf0e10cSrcweir     return ( bWidth ?
101*cdf0e10cSrcweir         ( ( eMode == SC_SIZE_OPTIMAL )?
102*cdf0e10cSrcweir         ScGlobal::GetRscString( STR_UNDO_OPTCOLWIDTH ) :
103*cdf0e10cSrcweir         ScGlobal::GetRscString( STR_UNDO_COLWIDTH )
104*cdf0e10cSrcweir         ) :
105*cdf0e10cSrcweir         ( ( eMode == SC_SIZE_OPTIMAL )?
106*cdf0e10cSrcweir         ScGlobal::GetRscString( STR_UNDO_OPTROWHEIGHT ) :
107*cdf0e10cSrcweir         ScGlobal::GetRscString( STR_UNDO_ROWHEIGHT )
108*cdf0e10cSrcweir         ) );
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void __EXPORT ScUndoWidthOrHeight::Undo()
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     BeginUndo();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     ScDocument* pDoc = pDocShell->GetDocument();
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     SCCOLROW nPaintStart = nStart > 0 ? nStart-1 : static_cast<SCCOLROW>(0);
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     if (eMode==SC_SIZE_OPTIMAL)
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         if ( SetViewMarkData( aMarkData ) )
122*cdf0e10cSrcweir             nPaintStart = 0;        // paint all, because of changed selection
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     //! outlines from all tables?
126*cdf0e10cSrcweir     if (pUndoTab)                                           // Outlines mit gespeichert?
127*cdf0e10cSrcweir         pDoc->SetOutlineTable( nStartTab, pUndoTab );
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     SCTAB nTabCount = pDoc->GetTableCount();
130*cdf0e10cSrcweir     SCTAB nTab;
131*cdf0e10cSrcweir     for (nTab=0; nTab<nTabCount; nTab++)
132*cdf0e10cSrcweir         if (aMarkData.GetTableSelect(nTab))
133*cdf0e10cSrcweir         {
134*cdf0e10cSrcweir             if (bWidth) // Width
135*cdf0e10cSrcweir             {
136*cdf0e10cSrcweir                 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
137*cdf0e10cSrcweir                         static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE,
138*cdf0e10cSrcweir                         sal_False, pDoc );
139*cdf0e10cSrcweir                 pDoc->UpdatePageBreaks( nTab );
140*cdf0e10cSrcweir                 pDocShell->PostPaint( static_cast<SCCOL>(nPaintStart), 0, nTab,
141*cdf0e10cSrcweir                         MAXCOL, MAXROW, nTab, PAINT_GRID | PAINT_TOP );
142*cdf0e10cSrcweir             }
143*cdf0e10cSrcweir             else        // Height
144*cdf0e10cSrcweir             {
145*cdf0e10cSrcweir                 pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, sal_False, pDoc );
146*cdf0e10cSrcweir                 pDoc->UpdatePageBreaks( nTab );
147*cdf0e10cSrcweir                 pDocShell->PostPaint( 0, nPaintStart, nTab, MAXCOL, MAXROW, nTab, PAINT_GRID | PAINT_LEFT );
148*cdf0e10cSrcweir             }
149*cdf0e10cSrcweir         }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     DoSdrUndoAction( pDrawUndo, pDoc );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
154*cdf0e10cSrcweir     if (pViewShell)
155*cdf0e10cSrcweir     {
156*cdf0e10cSrcweir         pViewShell->UpdateScrollBars();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir         SCTAB nCurrentTab = pViewShell->GetViewData()->GetTabNo();
159*cdf0e10cSrcweir         if ( nCurrentTab < nStartTab || nCurrentTab > nEndTab )
160*cdf0e10cSrcweir             pViewShell->SetTabNo( nStartTab );
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     EndUndo();
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir void __EXPORT ScUndoWidthOrHeight::Redo()
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     BeginRedo();
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     sal_Bool bPaintAll = sal_False;
171*cdf0e10cSrcweir     if (eMode==SC_SIZE_OPTIMAL)
172*cdf0e10cSrcweir     {
173*cdf0e10cSrcweir         if ( SetViewMarkData( aMarkData ) )
174*cdf0e10cSrcweir             bPaintAll = sal_True;       // paint all, because of changed selection
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
178*cdf0e10cSrcweir     if (pViewShell)
179*cdf0e10cSrcweir     {
180*cdf0e10cSrcweir         SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
181*cdf0e10cSrcweir         if ( nTab < nStartTab || nTab > nEndTab )
182*cdf0e10cSrcweir             pViewShell->SetTabNo( nStartTab );
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     // SetWidthOrHeight aendert aktuelle Tabelle !
186*cdf0e10cSrcweir     if ( pViewShell )
187*cdf0e10cSrcweir         pViewShell->SetWidthOrHeight( bWidth, nRangeCnt, pRanges, eMode, nNewSize, sal_False, sal_True, &aMarkData );
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     // paint grid if selection was changed directly at the MarkData
190*cdf0e10cSrcweir     if (bPaintAll)
191*cdf0e10cSrcweir         pDocShell->PostPaint( 0, 0, nStartTab, MAXCOL, MAXROW, nEndTab, PAINT_GRID );
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     EndRedo();
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir void __EXPORT ScUndoWidthOrHeight::Repeat(SfxRepeatTarget& rTarget)
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     if (rTarget.ISA(ScTabViewTarget))
199*cdf0e10cSrcweir         ((ScTabViewTarget&)rTarget).GetViewShell()->SetMarkedWidthOrHeight( bWidth, eMode, nNewSize, sal_True );
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir sal_Bool __EXPORT ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget& rTarget) const
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir     return (rTarget.ISA(ScTabViewTarget));
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 
208