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