xref: /trunk/main/sc/source/ui/undo/undoblk2.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // System - Includes -----------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef PCH
32cdf0e10cSrcweir #include "scitems.hxx"              // SearchItem
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "undoblk.hxx"
38cdf0e10cSrcweir #include "document.hxx"
39cdf0e10cSrcweir #include "docsh.hxx"
40cdf0e10cSrcweir #include "tabvwsh.hxx"
41cdf0e10cSrcweir #include "olinetab.hxx"
42cdf0e10cSrcweir #include "globstr.hrc"
43cdf0e10cSrcweir #include "global.hxx"
44cdf0e10cSrcweir #include "target.hxx"
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "undoolk.hxx"              //! GetUndo ins Document verschieben!
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
50cdf0e10cSrcweir 
51cdf0e10cSrcweir TYPEINIT1(ScUndoWidthOrHeight,      SfxUndoAction);
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // -----------------------------------------------------------------------
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //
58cdf0e10cSrcweir //      Spaltenbreiten oder Zeilenhoehen aendern
59cdf0e10cSrcweir //
60cdf0e10cSrcweir 
ScUndoWidthOrHeight(ScDocShell * pNewDocShell,const ScMarkData & rMark,SCCOLROW nNewStart,SCTAB nNewStartTab,SCCOLROW nNewEnd,SCTAB nNewEndTab,ScDocument * pNewUndoDoc,SCCOLROW nNewCnt,SCCOLROW * pNewRanges,ScOutlineTable * pNewUndoTab,ScSizeMode eNewMode,sal_uInt16 nNewSizeTwips,sal_Bool bNewWidth)61cdf0e10cSrcweir ScUndoWidthOrHeight::ScUndoWidthOrHeight( ScDocShell* pNewDocShell,
62cdf0e10cSrcweir                 const ScMarkData& rMark,
63cdf0e10cSrcweir                 SCCOLROW nNewStart, SCTAB nNewStartTab, SCCOLROW nNewEnd, SCTAB nNewEndTab,
64cdf0e10cSrcweir                 ScDocument* pNewUndoDoc, SCCOLROW nNewCnt, SCCOLROW* pNewRanges,
65cdf0e10cSrcweir                 ScOutlineTable* pNewUndoTab,
66cdf0e10cSrcweir                 ScSizeMode eNewMode, sal_uInt16 nNewSizeTwips, sal_Bool bNewWidth ) :
67cdf0e10cSrcweir     ScSimpleUndo( pNewDocShell ),
68cdf0e10cSrcweir     aMarkData( rMark ),
69cdf0e10cSrcweir     nStart( nNewStart ),
70cdf0e10cSrcweir     nEnd( nNewEnd ),
71cdf0e10cSrcweir     nStartTab( nNewStartTab ),
72cdf0e10cSrcweir     nEndTab( nNewEndTab ),
73cdf0e10cSrcweir     pUndoDoc( pNewUndoDoc ),
74cdf0e10cSrcweir     pUndoTab( pNewUndoTab ),
75cdf0e10cSrcweir     nRangeCnt( nNewCnt ),
76cdf0e10cSrcweir     pRanges( pNewRanges ),
77cdf0e10cSrcweir     nNewSize( nNewSizeTwips ),
78cdf0e10cSrcweir     bWidth( bNewWidth ),
79cdf0e10cSrcweir     eMode( eNewMode ),
80cdf0e10cSrcweir     pDrawUndo( NULL )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
~ScUndoWidthOrHeight()85cdf0e10cSrcweir __EXPORT ScUndoWidthOrHeight::~ScUndoWidthOrHeight()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     delete[] pRanges;
88cdf0e10cSrcweir     delete pUndoDoc;
89cdf0e10cSrcweir     delete pUndoTab;
90cdf0e10cSrcweir     DeleteSdrUndoAction( pDrawUndo );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
GetComment() const93cdf0e10cSrcweir String __EXPORT ScUndoWidthOrHeight::GetComment() const
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     // [ "optimale " ] "Spaltenbreite" | "Zeilenhoehe"
96cdf0e10cSrcweir     return ( bWidth ?
97cdf0e10cSrcweir         ( ( eMode == SC_SIZE_OPTIMAL )?
98cdf0e10cSrcweir         ScGlobal::GetRscString( STR_UNDO_OPTCOLWIDTH ) :
99cdf0e10cSrcweir         ScGlobal::GetRscString( STR_UNDO_COLWIDTH )
100cdf0e10cSrcweir         ) :
101cdf0e10cSrcweir         ( ( eMode == SC_SIZE_OPTIMAL )?
102cdf0e10cSrcweir         ScGlobal::GetRscString( STR_UNDO_OPTROWHEIGHT ) :
103cdf0e10cSrcweir         ScGlobal::GetRscString( STR_UNDO_ROWHEIGHT )
104cdf0e10cSrcweir         ) );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
Undo()107cdf0e10cSrcweir void __EXPORT ScUndoWidthOrHeight::Undo()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     BeginUndo();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     ScDocument* pDoc = pDocShell->GetDocument();
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     SCCOLROW nPaintStart = nStart > 0 ? nStart-1 : static_cast<SCCOLROW>(0);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     if (eMode==SC_SIZE_OPTIMAL)
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir         if ( SetViewMarkData( aMarkData ) )
118cdf0e10cSrcweir             nPaintStart = 0;        // paint all, because of changed selection
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     //! outlines from all tables?
122cdf0e10cSrcweir     if (pUndoTab)                                           // Outlines mit gespeichert?
123cdf0e10cSrcweir         pDoc->SetOutlineTable( nStartTab, pUndoTab );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     SCTAB nTabCount = pDoc->GetTableCount();
126cdf0e10cSrcweir     SCTAB nTab;
127cdf0e10cSrcweir     for (nTab=0; nTab<nTabCount; nTab++)
128cdf0e10cSrcweir         if (aMarkData.GetTableSelect(nTab))
129cdf0e10cSrcweir         {
130cdf0e10cSrcweir             if (bWidth) // Width
131cdf0e10cSrcweir             {
132cdf0e10cSrcweir                 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
133cdf0e10cSrcweir                         static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE,
134cdf0e10cSrcweir                         sal_False, pDoc );
135cdf0e10cSrcweir                 pDoc->UpdatePageBreaks( nTab );
136cdf0e10cSrcweir                 pDocShell->PostPaint( static_cast<SCCOL>(nPaintStart), 0, nTab,
137cdf0e10cSrcweir                         MAXCOL, MAXROW, nTab, PAINT_GRID | PAINT_TOP );
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir             else        // Height
140cdf0e10cSrcweir             {
141cdf0e10cSrcweir                 pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, sal_False, pDoc );
142cdf0e10cSrcweir                 pDoc->UpdatePageBreaks( nTab );
143cdf0e10cSrcweir                 pDocShell->PostPaint( 0, nPaintStart, nTab, MAXCOL, MAXROW, nTab, PAINT_GRID | PAINT_LEFT );
144cdf0e10cSrcweir             }
145cdf0e10cSrcweir         }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     DoSdrUndoAction( pDrawUndo, pDoc );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
150cdf0e10cSrcweir     if (pViewShell)
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         pViewShell->UpdateScrollBars();
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         SCTAB nCurrentTab = pViewShell->GetViewData()->GetTabNo();
155cdf0e10cSrcweir         if ( nCurrentTab < nStartTab || nCurrentTab > nEndTab )
156cdf0e10cSrcweir             pViewShell->SetTabNo( nStartTab );
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     EndUndo();
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
Redo()162cdf0e10cSrcweir void __EXPORT ScUndoWidthOrHeight::Redo()
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     BeginRedo();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     sal_Bool bPaintAll = sal_False;
167cdf0e10cSrcweir     if (eMode==SC_SIZE_OPTIMAL)
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         if ( SetViewMarkData( aMarkData ) )
170cdf0e10cSrcweir             bPaintAll = sal_True;       // paint all, because of changed selection
171cdf0e10cSrcweir     }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
174cdf0e10cSrcweir     if (pViewShell)
175cdf0e10cSrcweir     {
176cdf0e10cSrcweir         SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
177cdf0e10cSrcweir         if ( nTab < nStartTab || nTab > nEndTab )
178cdf0e10cSrcweir             pViewShell->SetTabNo( nStartTab );
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     // SetWidthOrHeight aendert aktuelle Tabelle !
182cdf0e10cSrcweir     if ( pViewShell )
183cdf0e10cSrcweir         pViewShell->SetWidthOrHeight( bWidth, nRangeCnt, pRanges, eMode, nNewSize, sal_False, sal_True, &aMarkData );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     // paint grid if selection was changed directly at the MarkData
186cdf0e10cSrcweir     if (bPaintAll)
187cdf0e10cSrcweir         pDocShell->PostPaint( 0, 0, nStartTab, MAXCOL, MAXROW, nEndTab, PAINT_GRID );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     EndRedo();
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
Repeat(SfxRepeatTarget & rTarget)192cdf0e10cSrcweir void __EXPORT ScUndoWidthOrHeight::Repeat(SfxRepeatTarget& rTarget)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     if (rTarget.ISA(ScTabViewTarget))
195cdf0e10cSrcweir         ((ScTabViewTarget&)rTarget).GetViewShell()->SetMarkedWidthOrHeight( bWidth, eMode, nNewSize, sal_True );
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
CanRepeat(SfxRepeatTarget & rTarget) const198cdf0e10cSrcweir sal_Bool __EXPORT ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget& rTarget) const
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     return (rTarget.ISA(ScTabViewTarget));
201cdf0e10cSrcweir }
202