xref: /aoo41x/main/sc/source/ui/view/tabview2.cxx (revision 4d7c9de0)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "scitems.hxx"
32cdf0e10cSrcweir #include <editeng/eeitem.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <vcl/timer.hxx>
36cdf0e10cSrcweir #include <vcl/msgbox.hxx>
37cdf0e10cSrcweir #include <sfx2/app.hxx>
38cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
39cdf0e10cSrcweir #include <sfx2/bindings.hxx>
40cdf0e10cSrcweir #include <sfx2/childwin.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include "attrib.hxx"
43cdf0e10cSrcweir #include "pagedata.hxx"
44cdf0e10cSrcweir #include "tabview.hxx"
45cdf0e10cSrcweir #include "tabvwsh.hxx"
46cdf0e10cSrcweir #include "printfun.hxx"
47cdf0e10cSrcweir #include "stlpool.hxx"
48cdf0e10cSrcweir #include "docsh.hxx"
49cdf0e10cSrcweir #include "gridwin.hxx"
50cdf0e10cSrcweir #include "olinewin.hxx"
51cdf0e10cSrcweir #include "uiitems.hxx"
52cdf0e10cSrcweir #include "sc.hrc"
53cdf0e10cSrcweir #include "viewutil.hxx"
54cdf0e10cSrcweir #include "colrowba.hxx"
55cdf0e10cSrcweir #include "waitoff.hxx"
56cdf0e10cSrcweir #include "globstr.hrc"
57cdf0e10cSrcweir #include "scmod.hxx"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #define SC_BLOCKMODE_NONE		0
60cdf0e10cSrcweir #define SC_BLOCKMODE_NORMAL		1
61cdf0e10cSrcweir #define SC_BLOCKMODE_OWN		2
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //
66cdf0e10cSrcweir //          Markier - Funktionen
67cdf0e10cSrcweir //
68cdf0e10cSrcweir 
PaintMarks(SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow)69cdf0e10cSrcweir void ScTabView::PaintMarks(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	if (!ValidCol(nStartCol)) nStartCol = MAXCOL;
72cdf0e10cSrcweir 	if (!ValidRow(nStartRow)) nStartRow = MAXROW;
73cdf0e10cSrcweir 	if (!ValidCol(nEndCol)) nEndCol = MAXCOL;
74cdf0e10cSrcweir 	if (!ValidRow(nEndRow)) nEndRow = MAXROW;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	sal_Bool bLeft = (nStartCol==0 && nEndCol==MAXCOL);
77cdf0e10cSrcweir 	sal_Bool bTop = (nStartRow==0 && nEndRow==MAXROW);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	if (bLeft)
80cdf0e10cSrcweir 		PaintLeftArea( nStartRow, nEndRow );
81cdf0e10cSrcweir 	if (bTop)
82cdf0e10cSrcweir 		PaintTopArea( nStartCol, nEndCol );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	aViewData.GetDocument()->ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow,
85cdf0e10cSrcweir 											aViewData.GetTabNo() );
86cdf0e10cSrcweir 	PaintArea( nStartCol, nStartRow, nEndCol, nEndRow, SC_UPDATE_MARKS );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
IsMarking(SCCOL nCol,SCROW nRow,SCTAB nTab) const89cdf0e10cSrcweir sal_Bool ScTabView::IsMarking( SCCOL nCol, SCROW nRow, SCTAB nTab ) const
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	return bIsBlockMode
92cdf0e10cSrcweir 		&& nBlockStartX == nCol
93cdf0e10cSrcweir 		&& nBlockStartY == nRow
94cdf0e10cSrcweir 		&& nBlockStartZ == nTab;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
InitOwnBlockMode()97cdf0e10cSrcweir void ScTabView::InitOwnBlockMode()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	if (!bIsBlockMode)
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		//	Wenn keine (alte) Markierung mehr da ist, Anker in SelectionEngine loeschen:
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		ScMarkData& rMark = aViewData.GetMarkData();
104cdf0e10cSrcweir 		if (!rMark.IsMarked() && !rMark.IsMultiMarked())
105cdf0e10cSrcweir 			GetSelEngine()->CursorPosChanging( sal_False, sal_False );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //		bIsBlockMode = sal_True;
108cdf0e10cSrcweir 		bIsBlockMode = SC_BLOCKMODE_OWN;			//! Variable umbenennen!
109cdf0e10cSrcweir 		nBlockStartX = 0;
110cdf0e10cSrcweir 		nBlockStartY = 0;
111cdf0e10cSrcweir 		nBlockStartZ = 0;
112cdf0e10cSrcweir 		nBlockEndX = 0;
113cdf0e10cSrcweir 		nBlockEndY = 0;
114cdf0e10cSrcweir 		nBlockEndZ = 0;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		SelectionChanged();		// Status wird mit gesetzer Markierung abgefragt
117cdf0e10cSrcweir 	}
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
InitBlockMode(SCCOL nCurX,SCROW nCurY,SCTAB nCurZ,sal_Bool bTestNeg,sal_Bool bCols,sal_Bool bRows,sal_Bool bForceNeg)120cdf0e10cSrcweir void ScTabView::InitBlockMode( SCCOL nCurX, SCROW nCurY, SCTAB nCurZ,
121*0deba7fbSSteve Yin 								sal_Bool bTestNeg, sal_Bool bCols, sal_Bool bRows, sal_Bool bForceNeg )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	if (!bIsBlockMode)
124cdf0e10cSrcweir 	{
125cdf0e10cSrcweir 		if (!ValidCol(nCurX)) nCurX = MAXCOL;
126cdf0e10cSrcweir 		if (!ValidRow(nCurY)) nCurY = MAXROW;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		ScMarkData& rMark = aViewData.GetMarkData();
129cdf0e10cSrcweir 		SCTAB nTab = aViewData.GetTabNo();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 		//	Teil von Markierung aufheben?
132*0deba7fbSSteve Yin 		if (bForceNeg)
133*0deba7fbSSteve Yin 			bBlockNeg = sal_True;
134*0deba7fbSSteve Yin 		else if (bTestNeg)
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir 			if ( bCols )
137cdf0e10cSrcweir 				bBlockNeg = rMark.IsColumnMarked( nCurX );
138cdf0e10cSrcweir 			else if ( bRows )
139cdf0e10cSrcweir 				bBlockNeg = rMark.IsRowMarked( nCurY );
140cdf0e10cSrcweir 			else
141cdf0e10cSrcweir 				bBlockNeg = rMark.IsCellMarked( nCurX, nCurY );
142cdf0e10cSrcweir 		}
143cdf0e10cSrcweir 		else
144cdf0e10cSrcweir 			bBlockNeg = sal_False;
145cdf0e10cSrcweir 		rMark.SetMarkNegative(bBlockNeg);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir //		bIsBlockMode = sal_True;
148cdf0e10cSrcweir 		bIsBlockMode = SC_BLOCKMODE_NORMAL;			//! Variable umbenennen!
149cdf0e10cSrcweir 		bBlockCols = bCols;
150cdf0e10cSrcweir 		bBlockRows = bRows;
151cdf0e10cSrcweir 		nBlockStartX = nBlockStartXOrig = nCurX;
152cdf0e10cSrcweir 		nBlockStartY = nBlockStartYOrig = nCurY;
153cdf0e10cSrcweir 		nBlockStartZ = nCurZ;
154cdf0e10cSrcweir 		nBlockEndX = nOldCurX = nBlockStartX;
155cdf0e10cSrcweir 		nBlockEndY = nOldCurY = nBlockStartY;
156cdf0e10cSrcweir 		nBlockEndZ = nBlockStartZ;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 		if (bBlockCols)
159cdf0e10cSrcweir 		{
160cdf0e10cSrcweir 			nBlockStartY = nBlockStartYOrig = 0;
161cdf0e10cSrcweir 			nBlockEndY = MAXROW;
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		if (bBlockRows)
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir 			nBlockStartX = nBlockStartXOrig = 0;
167cdf0e10cSrcweir 			nBlockEndX = MAXCOL;
168cdf0e10cSrcweir 		}
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 		rMark.SetMarkArea( ScRange( nBlockStartX,nBlockStartY, nTab, nBlockEndX,nBlockEndY, nTab ) );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir #ifdef OLD_SELECTION_PAINT
173cdf0e10cSrcweir 		InvertBlockMark( nBlockStartX,nBlockStartY,nBlockEndX,nBlockEndY );
174cdf0e10cSrcweir #endif
175cdf0e10cSrcweir 		UpdateSelectionOverlay();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		bNewStartIfMarking = sal_False;		// use only once
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
SetNewStartIfMarking()181cdf0e10cSrcweir void ScTabView::SetNewStartIfMarking()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir 	bNewStartIfMarking = sal_True;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
DoneBlockMode(sal_Bool bContinue)186cdf0e10cSrcweir void ScTabView::DoneBlockMode( sal_Bool bContinue )            // Default FALSE
187cdf0e10cSrcweir {
188cdf0e10cSrcweir 	//	Wenn zwischen Tabellen- und Header SelectionEngine gewechselt wird,
189cdf0e10cSrcweir 	//	wird evtl. DeselectAll gerufen, weil die andere Engine keinen Anker hat.
190cdf0e10cSrcweir 	//	Mit bMoveIsShift wird verhindert, dass dann die Selektion aufgehoben wird.
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	if (bIsBlockMode && !bMoveIsShift)
193cdf0e10cSrcweir 	{
194cdf0e10cSrcweir 		ScMarkData& rMark = aViewData.GetMarkData();
195cdf0e10cSrcweir 		sal_Bool bFlag = rMark.GetMarkingFlag();
196cdf0e10cSrcweir 		rMark.SetMarking(sal_False);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 		if (bBlockNeg && !bContinue)
199cdf0e10cSrcweir 			rMark.MarkToMulti();
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 		if (bContinue)
202cdf0e10cSrcweir 			rMark.MarkToMulti();
203cdf0e10cSrcweir 		else
204cdf0e10cSrcweir 		{
205cdf0e10cSrcweir 			//	Die Tabelle kann an dieser Stelle ungueltig sein, weil DoneBlockMode
206cdf0e10cSrcweir 			//	aus SetTabNo aufgerufen wird
207cdf0e10cSrcweir 			//	(z.B. wenn die aktuelle Tabelle von einer anderen View aus geloescht wird)
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 			SCTAB nTab = aViewData.GetTabNo();
210cdf0e10cSrcweir 			ScDocument* pDoc = aViewData.GetDocument();
211cdf0e10cSrcweir 			if ( pDoc->HasTable(nTab) )
212cdf0e10cSrcweir 				PaintBlock( sal_True );								// sal_True -> Block loeschen
213cdf0e10cSrcweir 			else
214cdf0e10cSrcweir 				rMark.ResetMark();
215cdf0e10cSrcweir 		}
216cdf0e10cSrcweir //		bIsBlockMode = sal_False;
217cdf0e10cSrcweir 		bIsBlockMode = SC_BLOCKMODE_NONE;			//! Variable umbenennen!
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 		rMark.SetMarking(bFlag);
220cdf0e10cSrcweir 		rMark.SetMarkNegative(sal_False);
221cdf0e10cSrcweir 	}
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
MarkCursor(SCCOL nCurX,SCROW nCurY,SCTAB nCurZ,sal_Bool bCols,sal_Bool bRows,sal_Bool bCellSelection)224cdf0e10cSrcweir void ScTabView::MarkCursor( SCCOL nCurX, SCROW nCurY, SCTAB nCurZ,
225cdf0e10cSrcweir                             sal_Bool bCols, sal_Bool bRows, sal_Bool bCellSelection )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir 	if (!ValidCol(nCurX)) nCurX = MAXCOL;
228cdf0e10cSrcweir 	if (!ValidRow(nCurY)) nCurY = MAXROW;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 	if (!bIsBlockMode)
231cdf0e10cSrcweir 	{
232cdf0e10cSrcweir 		DBG_ERROR( "MarkCursor nicht im BlockMode" );
233cdf0e10cSrcweir 		InitBlockMode( nCurX, nCurY, nCurZ, sal_False, bCols, bRows );
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	if (bCols)
237cdf0e10cSrcweir 		nCurY = MAXROW;
238cdf0e10cSrcweir 	if (bRows)
239cdf0e10cSrcweir 		nCurX = MAXCOL;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 	ScMarkData& rMark = aViewData.GetMarkData();
242cdf0e10cSrcweir 	DBG_ASSERT(rMark.IsMarked() || rMark.IsMultiMarked(), "MarkCursor, !IsMarked()");
243cdf0e10cSrcweir 	ScRange aMarkRange;
244cdf0e10cSrcweir 	rMark.GetMarkArea(aMarkRange);
245cdf0e10cSrcweir 	if (( aMarkRange.aStart.Col() != nBlockStartX && aMarkRange.aEnd.Col() != nBlockStartX ) ||
246cdf0e10cSrcweir 		( aMarkRange.aStart.Row() != nBlockStartY && aMarkRange.aEnd.Row() != nBlockStartY ) ||
247cdf0e10cSrcweir 		( bIsBlockMode == SC_BLOCKMODE_OWN ))
248cdf0e10cSrcweir 	{
249cdf0e10cSrcweir 		//	Markierung ist veraendert worden
250cdf0e10cSrcweir 		//	(z.B. MarkToSimple, wenn per negativ alles bis auf ein Rechteck geloescht wurde)
251cdf0e10cSrcweir 		//	oder nach InitOwnBlockMode wird mit Shift-Klick weitermarkiert...
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 		sal_Bool bOldShift = bMoveIsShift;
254cdf0e10cSrcweir 		bMoveIsShift = sal_False;				//	wirklich umsetzen
255cdf0e10cSrcweir 		DoneBlockMode(sal_False);				//!	direkt Variablen setzen? (-> kein Geflacker)
256cdf0e10cSrcweir 		bMoveIsShift = bOldShift;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 		InitBlockMode( aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
259cdf0e10cSrcweir 						nBlockStartZ, rMark.IsMarkNegative(), bCols, bRows );
260cdf0e10cSrcweir 	}
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 	SCCOL nOldBlockEndX = nBlockEndX;
263cdf0e10cSrcweir 	SCROW nOldBlockEndY = nBlockEndY;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	if ( nCurX != nOldCurX || nCurY != nOldCurY )
266cdf0e10cSrcweir 	{
267cdf0e10cSrcweir         // Current cursor has moved
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 		SCTAB		nTab = nCurZ;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir #ifdef OLD_SELECTION_PAINT
272cdf0e10cSrcweir 		SCCOL		nDrawStartCol;
273cdf0e10cSrcweir 		SCROW		nDrawStartRow;
274cdf0e10cSrcweir 		SCCOL		nDrawEndCol;
275cdf0e10cSrcweir 		SCROW		nDrawEndRow;
276cdf0e10cSrcweir #endif
277cdf0e10cSrcweir 
278cdf0e10cSrcweir         // Set old selection area
279cdf0e10cSrcweir 		ScUpdateRect aRect( nBlockStartX, nBlockStartY, nOldBlockEndX, nOldBlockEndY );
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         if ( bCellSelection )
282cdf0e10cSrcweir         {
283cdf0e10cSrcweir             // Expand selection area accordingly when the current selection ends
284cdf0e10cSrcweir             // with a merged cell.
285cdf0e10cSrcweir             SCsCOL nCurXOffset = 0;
286cdf0e10cSrcweir             SCsCOL nBlockStartXOffset = 0;
287cdf0e10cSrcweir             SCsROW nCurYOffset = 0;
288cdf0e10cSrcweir             SCsROW nBlockStartYOffset = 0;
289cdf0e10cSrcweir             sal_Bool bBlockStartMerged = sal_False;
290cdf0e10cSrcweir             const ScMergeAttr* pMergeAttr = NULL;
291cdf0e10cSrcweir             ScDocument* pDocument = aViewData.GetDocument();
292cdf0e10cSrcweir 
293cdf0e10cSrcweir             // The following block checks whether or not the "BlockStart" (anchor)
294cdf0e10cSrcweir             // cell is merged.  If it's merged, it'll then move the position of the
295cdf0e10cSrcweir             // anchor cell to the corner that's diagonally opposite of the
296cdf0e10cSrcweir             // direction of a current selection area.  For instance, if a current
297cdf0e10cSrcweir             // selection is moving in the upperleft direction, the anchor cell will
298cdf0e10cSrcweir             // move to the lower-right corner of the merged anchor cell, and so on.
299cdf0e10cSrcweir 
300cdf0e10cSrcweir             pMergeAttr = static_cast<const ScMergeAttr*>(
301cdf0e10cSrcweir                 pDocument->GetAttr( nBlockStartXOrig, nBlockStartYOrig, nTab, ATTR_MERGE ) );
302cdf0e10cSrcweir             if ( pMergeAttr->IsMerged() )
303cdf0e10cSrcweir             {
304cdf0e10cSrcweir                 SCsCOL nColSpan = pMergeAttr->GetColMerge();
305cdf0e10cSrcweir                 SCsROW nRowSpan = pMergeAttr->GetRowMerge();
306cdf0e10cSrcweir 
307cdf0e10cSrcweir                 if ( !( nCurX >= nBlockStartXOrig + nColSpan - 1 && nCurY >= nBlockStartYOrig + nRowSpan - 1 ) )
308cdf0e10cSrcweir                 {
309cdf0e10cSrcweir                     nBlockStartX = nCurX >= nBlockStartXOrig ? nBlockStartXOrig : nBlockStartXOrig + nColSpan - 1;
310cdf0e10cSrcweir                     nBlockStartY = nCurY >= nBlockStartYOrig ? nBlockStartYOrig : nBlockStartYOrig + nRowSpan - 1;
311cdf0e10cSrcweir                     nCurXOffset  = nCurX >= nBlockStartXOrig && nCurX < nBlockStartXOrig + nColSpan - 1 ?
312cdf0e10cSrcweir                         nBlockStartXOrig - nCurX + nColSpan - 1 : 0;
313cdf0e10cSrcweir                     nCurYOffset  = nCurY >= nBlockStartYOrig && nCurY < nBlockStartYOrig + nRowSpan - 1 ?
314cdf0e10cSrcweir                         nBlockStartYOrig - nCurY + nRowSpan - 1 : 0;
315cdf0e10cSrcweir                     bBlockStartMerged = sal_True;
316cdf0e10cSrcweir                 }
317cdf0e10cSrcweir             }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir             // The following block checks whether or not the current cell is
320cdf0e10cSrcweir             // merged.  If it is, it'll then set the appropriate X & Y offset
321cdf0e10cSrcweir             // values (nCurXOffset & nCurYOffset) such that the selection area will
322cdf0e10cSrcweir             // grow by those specified offset amounts.  Note that the values of
323cdf0e10cSrcweir             // nCurXOffset/nCurYOffset may also be specified in the previous code
324cdf0e10cSrcweir             // block, in which case whichever value is greater will take on.
325cdf0e10cSrcweir 
326cdf0e10cSrcweir             pMergeAttr = static_cast<const ScMergeAttr*>(
327cdf0e10cSrcweir                 pDocument->GetAttr( nCurX, nCurY, nTab, ATTR_MERGE ) );
328cdf0e10cSrcweir             if ( pMergeAttr->IsMerged() )
329cdf0e10cSrcweir             {
330cdf0e10cSrcweir                 SCsCOL nColSpan = pMergeAttr->GetColMerge();
331cdf0e10cSrcweir                 SCsROW nRowSpan = pMergeAttr->GetRowMerge();
332cdf0e10cSrcweir 
333cdf0e10cSrcweir                 if ( !( nBlockStartX >= nCurX + nColSpan - 1 && nBlockStartY >= nCurY + nRowSpan - 1 ) )
334cdf0e10cSrcweir                 {
335cdf0e10cSrcweir                     if ( nBlockStartX <= nCurX + nColSpan - 1 )
336cdf0e10cSrcweir                     {
337cdf0e10cSrcweir                         SCsCOL nCurXOffsetTemp = nCurX < nCurX + nColSpan - 1 ? nColSpan - 1 : 0;
338cdf0e10cSrcweir                         nCurXOffset = nCurXOffset > nCurXOffsetTemp ? nCurXOffset : nCurXOffsetTemp;
339cdf0e10cSrcweir                     }
340cdf0e10cSrcweir                     if ( nBlockStartY <= nCurY + nRowSpan - 1 )
341cdf0e10cSrcweir                     {
342cdf0e10cSrcweir                         SCsROW nCurYOffsetTemp = nCurY < nCurY + nRowSpan - 1 ? nRowSpan - 1 : 0;
343cdf0e10cSrcweir                         nCurYOffset = nCurYOffset > nCurYOffsetTemp ? nCurYOffset : nCurYOffsetTemp;
344cdf0e10cSrcweir                     }
345cdf0e10cSrcweir                     if ( !( nBlockStartX <= nCurX && nBlockStartY <= nCurY ) &&
346cdf0e10cSrcweir                          !( nBlockStartX > nCurX + nColSpan - 1 && nBlockStartY > nCurY + nRowSpan - 1 ) )
347cdf0e10cSrcweir                     {
348cdf0e10cSrcweir                         nBlockStartXOffset = nBlockStartX > nCurX && nBlockStartX <= nCurX + nColSpan - 1 ? nCurX - nBlockStartX : 0;
349cdf0e10cSrcweir                         nBlockStartYOffset = nBlockStartY > nCurY && nBlockStartY <= nCurY + nRowSpan - 1 ? nCurY - nBlockStartY : 0;
350cdf0e10cSrcweir                     }
351cdf0e10cSrcweir                 }
352cdf0e10cSrcweir             }
353cdf0e10cSrcweir             else
354cdf0e10cSrcweir             {
355cdf0e10cSrcweir                 // The current cell is not merged.  Move the anchor cell to its
356cdf0e10cSrcweir                 // original position.
357cdf0e10cSrcweir                 if ( !bBlockStartMerged )
358cdf0e10cSrcweir                 {
359cdf0e10cSrcweir                     nBlockStartX = nBlockStartXOrig;
360cdf0e10cSrcweir                     nBlockStartY = nBlockStartYOrig;
361cdf0e10cSrcweir                 }
362cdf0e10cSrcweir             }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir             nBlockStartX = nBlockStartX + nBlockStartXOffset >= 0 ? nBlockStartX + nBlockStartXOffset : 0;
365cdf0e10cSrcweir             nBlockStartY = nBlockStartY + nBlockStartYOffset >= 0 ? nBlockStartY + nBlockStartYOffset : 0;
366cdf0e10cSrcweir             nBlockEndX = nCurX + nCurXOffset > MAXCOL ? MAXCOL : nCurX + nCurXOffset;
367cdf0e10cSrcweir             nBlockEndY = nCurY + nCurYOffset > MAXROW ? MAXROW : nCurY + nCurYOffset;
368cdf0e10cSrcweir         }
369cdf0e10cSrcweir         else
370cdf0e10cSrcweir         {
371cdf0e10cSrcweir             nBlockEndX = nCurX;
372cdf0e10cSrcweir             nBlockEndY = nCurY;
373cdf0e10cSrcweir         }
374cdf0e10cSrcweir         // end of "if ( bCellSelection )"
375cdf0e10cSrcweir 
376cdf0e10cSrcweir         // Set new selection area
377cdf0e10cSrcweir 		aRect.SetNew( nBlockStartX, nBlockStartY, nBlockEndX, nBlockEndY );
378cdf0e10cSrcweir 		rMark.SetMarkArea( ScRange( nBlockStartX, nBlockStartY, nTab, nBlockEndX, nBlockEndY, nTab ) );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir #ifdef OLD_SELECTION_PAINT
381cdf0e10cSrcweir 		sal_Bool bCont;
382cdf0e10cSrcweir 		sal_Bool bDraw = aRect.GetXorDiff( nDrawStartCol, nDrawStartRow,
383cdf0e10cSrcweir 										nDrawEndCol, nDrawEndRow, bCont );
384cdf0e10cSrcweir 		if ( bDraw )
385cdf0e10cSrcweir 		{
386cdf0e10cSrcweir //?			PutInOrder( nDrawStartCol, nDrawEndCol );
387cdf0e10cSrcweir //?			PutInOrder( nDrawStartRow, nDrawEndRow );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 			HideAllCursors();
390cdf0e10cSrcweir 			InvertBlockMark( nDrawStartCol, nDrawStartRow, nDrawEndCol, nDrawEndRow );
391cdf0e10cSrcweir 			if (bCont)
392cdf0e10cSrcweir 			{
393cdf0e10cSrcweir 				aRect.GetContDiff( nDrawStartCol, nDrawStartRow, nDrawEndCol, nDrawEndRow );
394cdf0e10cSrcweir 				InvertBlockMark( nDrawStartCol, nDrawStartRow, nDrawEndCol, nDrawEndRow );
395cdf0e10cSrcweir 			}
396cdf0e10cSrcweir 			ShowAllCursors();
397cdf0e10cSrcweir 		}
398cdf0e10cSrcweir #endif
399cdf0e10cSrcweir         UpdateSelectionOverlay();
400cdf0e10cSrcweir 
401cdf0e10cSrcweir         nOldCurX = nCurX;
402cdf0e10cSrcweir         nOldCurY = nCurY;
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 		aViewData.GetViewShell()->UpdateInputHandler();
405cdf0e10cSrcweir //		InvalidateAttribs();
406cdf0e10cSrcweir 	}
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 	if ( !bCols && !bRows )
409cdf0e10cSrcweir 		aHdrFunc.SetAnchorFlag( sal_False );
410cdf0e10cSrcweir }
411cdf0e10cSrcweir 
UpdateSelectionOverlay()412cdf0e10cSrcweir void ScTabView::UpdateSelectionOverlay()
413cdf0e10cSrcweir {
414cdf0e10cSrcweir     for (sal_uInt16 i=0; i<4; i++)
415cdf0e10cSrcweir         if ( pGridWin[i] && pGridWin[i]->IsVisible() )
416cdf0e10cSrcweir             pGridWin[i]->UpdateSelectionOverlay();
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
UpdateShrinkOverlay()419cdf0e10cSrcweir void ScTabView::UpdateShrinkOverlay()
420cdf0e10cSrcweir {
421cdf0e10cSrcweir     for (sal_uInt16 i=0; i<4; i++)
422cdf0e10cSrcweir         if ( pGridWin[i] && pGridWin[i]->IsVisible() )
423cdf0e10cSrcweir             pGridWin[i]->UpdateShrinkOverlay();
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
UpdateAllOverlays()426cdf0e10cSrcweir void ScTabView::UpdateAllOverlays()
427cdf0e10cSrcweir {
428cdf0e10cSrcweir     for (sal_uInt16 i=0; i<4; i++)
429cdf0e10cSrcweir         if ( pGridWin[i] && pGridWin[i]->IsVisible() )
430cdf0e10cSrcweir             pGridWin[i]->UpdateAllOverlays();
431cdf0e10cSrcweir }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir //!
434cdf0e10cSrcweir //!	PaintBlock in zwei Methoden aufteilen: RepaintBlock und RemoveBlock o.ae.
435cdf0e10cSrcweir //!
436cdf0e10cSrcweir 
PaintBlock(sal_Bool bReset)437cdf0e10cSrcweir void ScTabView::PaintBlock( sal_Bool bReset )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir 	ScDocument* pDoc = aViewData.GetDocument();
440cdf0e10cSrcweir 	ScMarkData& rMark = aViewData.GetMarkData();
441cdf0e10cSrcweir 	SCTAB nTab = aViewData.GetTabNo();
442cdf0e10cSrcweir 	sal_Bool bMark = rMark.IsMarked();
443cdf0e10cSrcweir 	sal_Bool bMulti = rMark.IsMultiMarked();
444cdf0e10cSrcweir 	if (bMark || bMulti)
445cdf0e10cSrcweir 	{
446cdf0e10cSrcweir 		ScRange aMarkRange;
447cdf0e10cSrcweir 		HideAllCursors();
448cdf0e10cSrcweir 		if (bMulti)
449cdf0e10cSrcweir 		{
450cdf0e10cSrcweir 			sal_Bool bFlag = rMark.GetMarkingFlag();
451cdf0e10cSrcweir 			rMark.SetMarking(sal_False);
452cdf0e10cSrcweir 			rMark.MarkToMulti();
453cdf0e10cSrcweir 			rMark.GetMultiMarkArea(aMarkRange);
454cdf0e10cSrcweir 			rMark.MarkToSimple();
455cdf0e10cSrcweir 			rMark.SetMarking(bFlag);
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 			bMark = rMark.IsMarked();
458cdf0e10cSrcweir 			bMulti = rMark.IsMultiMarked();
459cdf0e10cSrcweir 		}
460cdf0e10cSrcweir 		else
461cdf0e10cSrcweir 			rMark.GetMarkArea(aMarkRange);
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 		nBlockStartX = aMarkRange.aStart.Col();
464cdf0e10cSrcweir 		nBlockStartY = aMarkRange.aStart.Row();
465cdf0e10cSrcweir 		nBlockStartZ = aMarkRange.aStart.Tab();
466cdf0e10cSrcweir 		nBlockEndX = aMarkRange.aEnd.Col();
467cdf0e10cSrcweir 		nBlockEndY = aMarkRange.aEnd.Row();
468cdf0e10cSrcweir 		nBlockEndZ = aMarkRange.aEnd.Tab();
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 		sal_Bool bDidReset = sal_False;
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 		if ( nTab>=nBlockStartZ && nTab<=nBlockEndZ )
473cdf0e10cSrcweir 		{
474cdf0e10cSrcweir 			if ( bReset )
475cdf0e10cSrcweir 			{
476cdf0e10cSrcweir 				// Invertieren beim Loeschen nur auf aktiver View
477cdf0e10cSrcweir 				if ( aViewData.IsActive() )
478cdf0e10cSrcweir 				{
479cdf0e10cSrcweir 					sal_uInt16 i;
480cdf0e10cSrcweir 					if ( bMulti )
481cdf0e10cSrcweir 					{
482cdf0e10cSrcweir #ifdef OLD_SELECTION_PAINT
483cdf0e10cSrcweir 						for (i=0; i<4; i++)
484cdf0e10cSrcweir 							if (pGridWin[i] && pGridWin[i]->IsVisible())
485cdf0e10cSrcweir 								pGridWin[i]->InvertSimple( nBlockStartX, nBlockStartY,
486cdf0e10cSrcweir 															nBlockEndX, nBlockEndY,
487cdf0e10cSrcweir 															sal_True, sal_True );
488cdf0e10cSrcweir #endif
489cdf0e10cSrcweir 						rMark.ResetMark();
490cdf0e10cSrcweir                         UpdateSelectionOverlay();
491cdf0e10cSrcweir 						bDidReset = sal_True;
492cdf0e10cSrcweir 					}
493cdf0e10cSrcweir 					else
494cdf0e10cSrcweir 					{
495cdf0e10cSrcweir #ifdef OLD_SELECTION_PAINT
496cdf0e10cSrcweir 						// (mis)use InvertBlockMark to remove all of the selection
497cdf0e10cSrcweir 						// -> set bBlockNeg (like when removing parts of a selection)
498cdf0e10cSrcweir 						//	  and convert everything to Multi
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 						rMark.MarkToMulti();
501cdf0e10cSrcweir 						sal_Bool bOld = bBlockNeg;
502cdf0e10cSrcweir 						bBlockNeg = sal_True;
503cdf0e10cSrcweir 						// #73130# (negative) MarkArea must be set in case of repaint
504cdf0e10cSrcweir 						rMark.SetMarkArea( ScRange( nBlockStartX,nBlockStartY, nTab,
505cdf0e10cSrcweir 													nBlockEndX,nBlockEndY, nTab ) );
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 						InvertBlockMark( nBlockStartX, nBlockStartY, nBlockEndX, nBlockEndY );
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 						bBlockNeg = bOld;
510cdf0e10cSrcweir #endif
511cdf0e10cSrcweir 						rMark.ResetMark();
512cdf0e10cSrcweir                         UpdateSelectionOverlay();
513cdf0e10cSrcweir 						bDidReset = sal_True;
514cdf0e10cSrcweir 					}
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 					//	repaint if controls are touched (#69680# in both cases)
517cdf0e10cSrcweir 					// #i74768# Forms are rendered by DrawingLayer's EndDrawLayers()
518cdf0e10cSrcweir 					static bool bSuppressControlExtraStuff(true);
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 					if(!bSuppressControlExtraStuff)
521cdf0e10cSrcweir 					{
522cdf0e10cSrcweir 						Rectangle aMMRect = pDoc->GetMMRect(nBlockStartX,nBlockStartY,nBlockEndX,nBlockEndY, nTab);
523cdf0e10cSrcweir 						if (pDoc->HasControl( nTab, aMMRect ))
524cdf0e10cSrcweir 						{
525cdf0e10cSrcweir 							for (i=0; i<4; i++)
526cdf0e10cSrcweir 							{
527cdf0e10cSrcweir 								if (pGridWin[i] && pGridWin[i]->IsVisible())
528cdf0e10cSrcweir 								{
529cdf0e10cSrcweir 									//	MapMode muss logischer (1/100mm) sein !!!
530cdf0e10cSrcweir 									pDoc->InvalidateControls( pGridWin[i], nTab, aMMRect );
531cdf0e10cSrcweir 									pGridWin[i]->Update();
532cdf0e10cSrcweir 								}
533cdf0e10cSrcweir 							}
534cdf0e10cSrcweir 						}
535cdf0e10cSrcweir 					}
536cdf0e10cSrcweir 				}
537cdf0e10cSrcweir 			}
538cdf0e10cSrcweir 			else
539cdf0e10cSrcweir 				PaintMarks( nBlockStartX, nBlockStartY, nBlockEndX, nBlockEndY );
540cdf0e10cSrcweir 		}
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 		if ( bReset && !bDidReset )
543cdf0e10cSrcweir 			rMark.ResetMark();
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 		ShowAllCursors();
546cdf0e10cSrcweir 	}
547cdf0e10cSrcweir }
548cdf0e10cSrcweir 
SelectAll(sal_Bool bContinue)549cdf0e10cSrcweir void ScTabView::SelectAll( sal_Bool bContinue )
550cdf0e10cSrcweir {
551cdf0e10cSrcweir 	ScMarkData& rMark = aViewData.GetMarkData();
552cdf0e10cSrcweir 	SCTAB nTab = aViewData.GetTabNo();
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 	if (rMark.IsMarked())
555cdf0e10cSrcweir 	{
556cdf0e10cSrcweir 		ScRange aMarkRange;
557cdf0e10cSrcweir 		rMark.GetMarkArea( aMarkRange );
558cdf0e10cSrcweir 		if ( aMarkRange == ScRange( 0,0,nTab, MAXCOL,MAXROW,nTab ) )
559cdf0e10cSrcweir 			return;
560cdf0e10cSrcweir 	}
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 	DoneBlockMode( bContinue );
563cdf0e10cSrcweir 	InitBlockMode( 0,0,nTab );
564cdf0e10cSrcweir 	MarkCursor( MAXCOL,MAXROW,nTab );
565cdf0e10cSrcweir 
566cdf0e10cSrcweir 	SelectionChanged();
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
SelectAllTables()569cdf0e10cSrcweir void ScTabView::SelectAllTables()
570cdf0e10cSrcweir {
571cdf0e10cSrcweir 	ScDocument* pDoc = aViewData.GetDocument();
572cdf0e10cSrcweir 	ScMarkData& rMark = aViewData.GetMarkData();
573cdf0e10cSrcweir //    SCTAB nTab = aViewData.GetTabNo();
574cdf0e10cSrcweir 	SCTAB nCount = pDoc->GetTableCount();
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	if (nCount>1)
577cdf0e10cSrcweir 	{
578cdf0e10cSrcweir 		for (SCTAB i=0; i<nCount; i++)
579cdf0e10cSrcweir 			rMark.SelectTable( i, sal_True );
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 		//		Markierungen werden per Default nicht pro Tabelle gehalten
582cdf0e10cSrcweir //		pDoc->ExtendMarksFromTable( nTab );
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 		aViewData.GetDocShell()->PostPaintExtras();
585cdf0e10cSrcweir         SfxBindings& rBind = aViewData.GetBindings();
586cdf0e10cSrcweir         rBind.Invalidate( FID_FILL_TAB );
587cdf0e10cSrcweir         rBind.Invalidate( FID_TAB_DESELECTALL );
588cdf0e10cSrcweir 	}
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
DeselectAllTables()591cdf0e10cSrcweir void ScTabView::DeselectAllTables()
592cdf0e10cSrcweir {
593cdf0e10cSrcweir     ScDocument* pDoc = aViewData.GetDocument();
594cdf0e10cSrcweir     ScMarkData& rMark = aViewData.GetMarkData();
595cdf0e10cSrcweir     SCTAB nTab = aViewData.GetTabNo();
596cdf0e10cSrcweir     SCTAB nCount = pDoc->GetTableCount();
597cdf0e10cSrcweir 
598cdf0e10cSrcweir     for (SCTAB i=0; i<nCount; i++)
599cdf0e10cSrcweir         rMark.SelectTable( i, ( i == nTab ) );
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     aViewData.GetDocShell()->PostPaintExtras();
602cdf0e10cSrcweir     SfxBindings& rBind = aViewData.GetBindings();
603cdf0e10cSrcweir     rBind.Invalidate( FID_FILL_TAB );
604cdf0e10cSrcweir     rBind.Invalidate( FID_TAB_DESELECTALL );
605cdf0e10cSrcweir }
606cdf0e10cSrcweir 
lcl_FitsInWindow(double fScaleX,double fScaleY,sal_uInt16 nZoom,long nWindowX,long nWindowY,ScDocument * pDoc,SCTAB nTab,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,SCCOL nFixPosX,SCROW nFixPosY)607cdf0e10cSrcweir sal_Bool lcl_FitsInWindow( double fScaleX, double fScaleY, sal_uInt16 nZoom,
608cdf0e10cSrcweir 						long nWindowX, long nWindowY, ScDocument* pDoc, SCTAB nTab,
609cdf0e10cSrcweir 						SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
610cdf0e10cSrcweir 						SCCOL nFixPosX, SCROW nFixPosY )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir 	double fZoomFactor = (double)Fraction(nZoom,100);
613cdf0e10cSrcweir 	fScaleX *= fZoomFactor;
614cdf0e10cSrcweir 	fScaleY *= fZoomFactor;
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 	long nBlockX = 0;
617cdf0e10cSrcweir 	SCCOL nCol;
618cdf0e10cSrcweir 	for (nCol=0; nCol<nFixPosX; nCol++)
619cdf0e10cSrcweir 	{
620cdf0e10cSrcweir 		//	for frozen panes, add both parts
621cdf0e10cSrcweir 		sal_uInt16 nColTwips = pDoc->GetColWidth( nCol, nTab );
622cdf0e10cSrcweir 		if (nColTwips)
623cdf0e10cSrcweir 		{
624cdf0e10cSrcweir 			nBlockX += (long)(nColTwips * fScaleX);
625cdf0e10cSrcweir 			if (nBlockX > nWindowX)
626cdf0e10cSrcweir 				return sal_False;
627cdf0e10cSrcweir 		}
628cdf0e10cSrcweir 	}
629cdf0e10cSrcweir 	for (nCol=nStartCol; nCol<=nEndCol; nCol++)
630cdf0e10cSrcweir 	{
631cdf0e10cSrcweir 		sal_uInt16 nColTwips = pDoc->GetColWidth( nCol, nTab );
632cdf0e10cSrcweir 		if (nColTwips)
633cdf0e10cSrcweir 		{
634cdf0e10cSrcweir 			nBlockX += (long)(nColTwips * fScaleX);
635cdf0e10cSrcweir 			if (nBlockX > nWindowX)
636cdf0e10cSrcweir 				return sal_False;
637cdf0e10cSrcweir 		}
638cdf0e10cSrcweir 	}
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 	long nBlockY = 0;
641cdf0e10cSrcweir     for (SCROW nRow = 0; nRow <= nFixPosY-1; ++nRow)
642cdf0e10cSrcweir 	{
643cdf0e10cSrcweir         if (pDoc->RowHidden(nRow, nTab))
644cdf0e10cSrcweir             continue;
645cdf0e10cSrcweir 
646cdf0e10cSrcweir 		//	for frozen panes, add both parts
647cdf0e10cSrcweir         sal_uInt16 nRowTwips = pDoc->GetRowHeight(nRow, nTab);
648cdf0e10cSrcweir 		if (nRowTwips)
649cdf0e10cSrcweir 		{
650cdf0e10cSrcweir 			nBlockY += (long)(nRowTwips * fScaleY);
651cdf0e10cSrcweir 			if (nBlockY > nWindowY)
652cdf0e10cSrcweir 				return sal_False;
653cdf0e10cSrcweir 		}
654cdf0e10cSrcweir 	}
655cdf0e10cSrcweir     for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
656cdf0e10cSrcweir 	{
657cdf0e10cSrcweir         sal_uInt16 nRowTwips = pDoc->GetRowHeight(nRow, nTab);
658cdf0e10cSrcweir 		if (nRowTwips)
659cdf0e10cSrcweir 		{
660cdf0e10cSrcweir 			nBlockY += (long)(nRowTwips * fScaleY);
661cdf0e10cSrcweir 			if (nBlockY > nWindowY)
662cdf0e10cSrcweir 				return sal_False;
663cdf0e10cSrcweir 		}
664cdf0e10cSrcweir 	}
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 	return sal_True;
667cdf0e10cSrcweir }
668cdf0e10cSrcweir 
CalcZoom(SvxZoomType eType,sal_uInt16 nOldZoom)669cdf0e10cSrcweir sal_uInt16 ScTabView::CalcZoom( SvxZoomType eType, sal_uInt16 nOldZoom )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir 	sal_uInt16 nZoom = 0; // Ergebnis
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 	switch ( eType )
674cdf0e10cSrcweir 	{
675cdf0e10cSrcweir 		case SVX_ZOOM_PERCENT: // rZoom ist kein besonderer prozentualer Wert
676cdf0e10cSrcweir 			nZoom = nOldZoom;
677cdf0e10cSrcweir 			break;
678cdf0e10cSrcweir 
679cdf0e10cSrcweir 		case SVX_ZOOM_OPTIMAL:	// nZoom entspricht der optimalen Gr"o\se
680cdf0e10cSrcweir 			{
681cdf0e10cSrcweir 				ScMarkData& rMark = aViewData.GetMarkData();
682cdf0e10cSrcweir 				ScDocument* pDoc = aViewData.GetDocument();
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 				if (!rMark.IsMarked() && !rMark.IsMultiMarked())
685cdf0e10cSrcweir 					nZoom = 100;				// nothing selected
686cdf0e10cSrcweir 				else
687cdf0e10cSrcweir 				{
688cdf0e10cSrcweir 					SCTAB	nTab = aViewData.GetTabNo();
689cdf0e10cSrcweir 					ScRange aMarkRange;
690cdf0e10cSrcweir 					if ( aViewData.GetSimpleArea( aMarkRange ) != SC_MARK_SIMPLE )
691cdf0e10cSrcweir 						rMark.GetMultiMarkArea( aMarkRange );
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 					SCCOL	nStartCol = aMarkRange.aStart.Col();
694cdf0e10cSrcweir 					SCROW	nStartRow = aMarkRange.aStart.Row();
695cdf0e10cSrcweir 					SCTAB	nStartTab = aMarkRange.aStart.Tab();
696cdf0e10cSrcweir 					SCCOL	nEndCol = aMarkRange.aEnd.Col();
697cdf0e10cSrcweir 					SCROW	nEndRow = aMarkRange.aEnd.Row();
698cdf0e10cSrcweir 					SCTAB	nEndTab = aMarkRange.aEnd.Tab();
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 					if ( nTab < nStartTab && nTab > nEndTab )
701cdf0e10cSrcweir 						nTab = nStartTab;
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 					ScSplitPos eUsedPart = aViewData.GetActivePart();
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 					SCCOL nFixPosX = 0;
706cdf0e10cSrcweir 					SCROW nFixPosY = 0;
707cdf0e10cSrcweir 					if ( aViewData.GetHSplitMode() == SC_SPLIT_FIX )
708cdf0e10cSrcweir 					{
709cdf0e10cSrcweir 						//	use right part
710cdf0e10cSrcweir 						eUsedPart = (WhichV(eUsedPart)==SC_SPLIT_TOP) ? SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT;
711cdf0e10cSrcweir 						nFixPosX = aViewData.GetFixPosX();
712cdf0e10cSrcweir 						if ( nStartCol < nFixPosX )
713cdf0e10cSrcweir 							nStartCol = nFixPosX;
714cdf0e10cSrcweir 					}
715cdf0e10cSrcweir 					if ( aViewData.GetVSplitMode() == SC_SPLIT_FIX )
716cdf0e10cSrcweir 					{
717cdf0e10cSrcweir 						//	use bottom part
718cdf0e10cSrcweir 						eUsedPart = (WhichH(eUsedPart)==SC_SPLIT_LEFT) ? SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT;
719cdf0e10cSrcweir 						nFixPosY = aViewData.GetFixPosY();
720cdf0e10cSrcweir 						if ( nStartRow < nFixPosY )
721cdf0e10cSrcweir 							nStartRow = nFixPosY;
722cdf0e10cSrcweir 					}
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 					if (pGridWin[eUsedPart])
725cdf0e10cSrcweir 					{
726cdf0e10cSrcweir 						//	Because scale is rounded to pixels, the only reliable way to find
727cdf0e10cSrcweir 						//	the right scale is to check if a zoom fits
728cdf0e10cSrcweir 
729cdf0e10cSrcweir 						Size aWinSize = pGridWin[eUsedPart]->GetOutputSizePixel();
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 						//	for frozen panes, use sum of both parts for calculation
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 						if ( nFixPosX != 0 )
734cdf0e10cSrcweir 							aWinSize.Width() += GetGridWidth( SC_SPLIT_LEFT );
735cdf0e10cSrcweir 						if ( nFixPosY != 0 )
736cdf0e10cSrcweir 							aWinSize.Height() += GetGridHeight( SC_SPLIT_TOP );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 						ScDocShell* pDocSh = aViewData.GetDocShell();
739cdf0e10cSrcweir 						double nPPTX = ScGlobal::nScreenPPTX / pDocSh->GetOutputFactor();
740cdf0e10cSrcweir 						double nPPTY = ScGlobal::nScreenPPTY;
741cdf0e10cSrcweir 
742cdf0e10cSrcweir 						sal_uInt16 nMin = MINZOOM;
743cdf0e10cSrcweir 						sal_uInt16 nMax = MAXZOOM;
744cdf0e10cSrcweir 						while ( nMax > nMin )
745cdf0e10cSrcweir 						{
746cdf0e10cSrcweir 							sal_uInt16 nTest = (nMin+nMax+1)/2;
747cdf0e10cSrcweir 							if ( lcl_FitsInWindow(
748cdf0e10cSrcweir 										nPPTX, nPPTY, nTest, aWinSize.Width(), aWinSize.Height(),
749cdf0e10cSrcweir 										pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow,
750cdf0e10cSrcweir 										nFixPosX, nFixPosY ) )
751cdf0e10cSrcweir 								nMin = nTest;
752cdf0e10cSrcweir 							else
753cdf0e10cSrcweir 								nMax = nTest-1;
754cdf0e10cSrcweir 						}
755cdf0e10cSrcweir 						DBG_ASSERT( nMin == nMax, "Schachtelung ist falsch" );
756cdf0e10cSrcweir 						nZoom = nMin;
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 						if ( nZoom != nOldZoom )
759cdf0e10cSrcweir 						{
760cdf0e10cSrcweir 							// scroll to block only in active split part
761cdf0e10cSrcweir 							// (the part for which the size was calculated)
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 							if ( nStartCol <= nEndCol )
764cdf0e10cSrcweir 								aViewData.SetPosX( WhichH(eUsedPart), nStartCol );
765cdf0e10cSrcweir 							if ( nStartRow <= nEndRow )
766cdf0e10cSrcweir 								aViewData.SetPosY( WhichV(eUsedPart), nStartRow );
767cdf0e10cSrcweir 						}
768cdf0e10cSrcweir 					}
769cdf0e10cSrcweir 				}
770cdf0e10cSrcweir 			}
771cdf0e10cSrcweir 			break;
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 			case SVX_ZOOM_WHOLEPAGE:	// nZoom entspricht der ganzen Seite oder
774cdf0e10cSrcweir 			case SVX_ZOOM_PAGEWIDTH:	// nZoom entspricht der Seitenbreite
775cdf0e10cSrcweir 				{
776cdf0e10cSrcweir 					SCTAB				nCurTab		= aViewData.GetTabNo();
777cdf0e10cSrcweir 					ScDocument*			pDoc		= aViewData.GetDocument();
778cdf0e10cSrcweir 					ScStyleSheetPool*	pStylePool  = pDoc->GetStyleSheetPool();
779cdf0e10cSrcweir 					SfxStyleSheetBase*	pStyleSheet =
780cdf0e10cSrcweir 											pStylePool->Find( pDoc->GetPageStyle( nCurTab ),
781cdf0e10cSrcweir 															  SFX_STYLE_FAMILY_PAGE );
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 					DBG_ASSERT( pStyleSheet, "PageStyle not found :-/" );
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 					if ( pStyleSheet )
786cdf0e10cSrcweir 					{
787cdf0e10cSrcweir 						ScPrintFunc aPrintFunc( aViewData.GetDocShell(),
788cdf0e10cSrcweir 												aViewData.GetViewShell()->GetPrinter(sal_True),
789cdf0e10cSrcweir 												nCurTab );
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 						Size aPageSize = aPrintFunc.GetDataSize();
792cdf0e10cSrcweir 
793cdf0e10cSrcweir 						//	use the size of the largest GridWin for normal split,
794cdf0e10cSrcweir 						//	or both combined for frozen panes, with the (document) size
795cdf0e10cSrcweir 						//	of the frozen part added to the page size
796cdf0e10cSrcweir 						//	(with frozen panes, the size of the individual parts
797cdf0e10cSrcweir 						//	depends on the scale that is to be calculated)
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 						if ( !pGridWin[SC_SPLIT_BOTTOMLEFT] ) return 0;
800cdf0e10cSrcweir 						Size aWinSize = pGridWin[SC_SPLIT_BOTTOMLEFT]->GetOutputSizePixel();
801cdf0e10cSrcweir 						ScSplitMode eHMode = aViewData.GetHSplitMode();
802cdf0e10cSrcweir 						if ( eHMode != SC_SPLIT_NONE && pGridWin[SC_SPLIT_BOTTOMRIGHT] )
803cdf0e10cSrcweir 						{
804cdf0e10cSrcweir 							long nOtherWidth = pGridWin[SC_SPLIT_BOTTOMRIGHT]->
805cdf0e10cSrcweir 														GetOutputSizePixel().Width();
806cdf0e10cSrcweir 							if ( eHMode == SC_SPLIT_FIX )
807cdf0e10cSrcweir 							{
808cdf0e10cSrcweir 								aWinSize.Width() += nOtherWidth;
809cdf0e10cSrcweir 								for ( SCCOL nCol = aViewData.GetPosX(SC_SPLIT_LEFT);
810cdf0e10cSrcweir 										nCol < aViewData.GetFixPosX(); nCol++ )
811cdf0e10cSrcweir 									aPageSize.Width() += pDoc->GetColWidth( nCol, nCurTab );
812cdf0e10cSrcweir 							}
813cdf0e10cSrcweir 							else if ( nOtherWidth > aWinSize.Width() )
814cdf0e10cSrcweir 								aWinSize.Width() = nOtherWidth;
815cdf0e10cSrcweir 						}
816cdf0e10cSrcweir 						ScSplitMode eVMode = aViewData.GetVSplitMode();
817cdf0e10cSrcweir 						if ( eVMode != SC_SPLIT_NONE && pGridWin[SC_SPLIT_TOPLEFT] )
818cdf0e10cSrcweir 						{
819cdf0e10cSrcweir 							long nOtherHeight = pGridWin[SC_SPLIT_TOPLEFT]->
820cdf0e10cSrcweir 														GetOutputSizePixel().Height();
821cdf0e10cSrcweir 							if ( eVMode == SC_SPLIT_FIX )
822cdf0e10cSrcweir 							{
823cdf0e10cSrcweir 								aWinSize.Height() += nOtherHeight;
824cdf0e10cSrcweir                                 aPageSize.Height() += pDoc->GetRowHeight(
825cdf0e10cSrcweir                                         aViewData.GetPosY(SC_SPLIT_TOP),
826cdf0e10cSrcweir                                         aViewData.GetFixPosY()-1, nCurTab);
827cdf0e10cSrcweir 							}
828cdf0e10cSrcweir 							else if ( nOtherHeight > aWinSize.Height() )
829cdf0e10cSrcweir 								aWinSize.Height() = nOtherHeight;
830cdf0e10cSrcweir 						}
831cdf0e10cSrcweir 
832cdf0e10cSrcweir 						double nPPTX = ScGlobal::nScreenPPTX / aViewData.GetDocShell()->GetOutputFactor();
833cdf0e10cSrcweir 						double nPPTY = ScGlobal::nScreenPPTY;
834cdf0e10cSrcweir 
835cdf0e10cSrcweir 						long nZoomX = (long) ( aWinSize.Width() * 100 /
836cdf0e10cSrcweir 											   ( aPageSize.Width() * nPPTX ) );
837cdf0e10cSrcweir 						long nZoomY = (long) ( aWinSize.Height() * 100 /
838cdf0e10cSrcweir 											   ( aPageSize.Height() * nPPTY ) );
839cdf0e10cSrcweir 						long nNew = nZoomX;
840cdf0e10cSrcweir 
841cdf0e10cSrcweir 						if (eType == SVX_ZOOM_WHOLEPAGE && nZoomY < nNew)
842cdf0e10cSrcweir 							nNew = nZoomY;
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 						nZoom = (sal_uInt16) nNew;
845cdf0e10cSrcweir 					}
846cdf0e10cSrcweir 				}
847cdf0e10cSrcweir 				break;
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 		default:
850cdf0e10cSrcweir 			DBG_ERROR("Unknown Zoom-Revision");
851cdf0e10cSrcweir 			nZoom = 0;
852cdf0e10cSrcweir 	}
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 	return nZoom;
855cdf0e10cSrcweir }
856cdf0e10cSrcweir 
857cdf0e10cSrcweir //	wird z.B. gerufen, wenn sich das View-Fenster verschiebt:
858cdf0e10cSrcweir 
StopMarking()859cdf0e10cSrcweir void ScTabView::StopMarking()
860cdf0e10cSrcweir {
861cdf0e10cSrcweir 	ScSplitPos eActive = aViewData.GetActivePart();
862cdf0e10cSrcweir 	if (pGridWin[eActive])
863cdf0e10cSrcweir 		pGridWin[eActive]->StopMarking();
864cdf0e10cSrcweir 
865cdf0e10cSrcweir 	ScHSplitPos eH = WhichH(eActive);
866cdf0e10cSrcweir 	if (pColBar[eH])
867cdf0e10cSrcweir 		pColBar[eH]->StopMarking();
868cdf0e10cSrcweir 
869cdf0e10cSrcweir 	ScVSplitPos eV = WhichV(eActive);
870cdf0e10cSrcweir 	if (pRowBar[eV])
871cdf0e10cSrcweir 		pRowBar[eV]->StopMarking();
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
HideNoteMarker()874cdf0e10cSrcweir void ScTabView::HideNoteMarker()
875cdf0e10cSrcweir {
876cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<4; i++)
877cdf0e10cSrcweir 		if (pGridWin[i] && pGridWin[i]->IsVisible())
878cdf0e10cSrcweir 			pGridWin[i]->HideNoteMarker();
879cdf0e10cSrcweir }
880cdf0e10cSrcweir 
MakeDrawLayer()881cdf0e10cSrcweir void ScTabView::MakeDrawLayer()
882cdf0e10cSrcweir {
883cdf0e10cSrcweir 	if (!pDrawView)
884cdf0e10cSrcweir 	{
885cdf0e10cSrcweir 		aViewData.GetDocShell()->MakeDrawLayer();
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 		//	pDrawView wird per Notify gesetzt
888cdf0e10cSrcweir 		DBG_ASSERT(pDrawView,"ScTabView::MakeDrawLayer funktioniert nicht");
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 		// #114409#
891cdf0e10cSrcweir 		for(sal_uInt16 a(0); a < 4; a++)
892cdf0e10cSrcweir 		{
893cdf0e10cSrcweir 			if(pGridWin[a])
894cdf0e10cSrcweir 			{
895cdf0e10cSrcweir 				pGridWin[a]->DrawLayerCreated();
896cdf0e10cSrcweir 			}
897cdf0e10cSrcweir 		}
898cdf0e10cSrcweir 	}
899cdf0e10cSrcweir }
900cdf0e10cSrcweir 
ErrorMessage(sal_uInt16 nGlobStrId)901cdf0e10cSrcweir void ScTabView::ErrorMessage( sal_uInt16 nGlobStrId )
902cdf0e10cSrcweir {
903cdf0e10cSrcweir     if ( SC_MOD()->IsInExecuteDrop() )
904cdf0e10cSrcweir     {
905cdf0e10cSrcweir         // #i28468# don't show error message when called from Drag&Drop, silently abort instead
906cdf0e10cSrcweir         return;
907cdf0e10cSrcweir     }
908cdf0e10cSrcweir 
909cdf0e10cSrcweir 	StopMarking();		// falls per Focus aus MouseButtonDown aufgerufen
910cdf0e10cSrcweir 
911cdf0e10cSrcweir 	Window* pParent = aViewData.GetDialogParent();
912cdf0e10cSrcweir 	ScWaitCursorOff aWaitOff( pParent );
913cdf0e10cSrcweir 	sal_Bool bFocus = pParent && pParent->HasFocus();
914cdf0e10cSrcweir 
915cdf0e10cSrcweir 	if(nGlobStrId==STR_PROTECTIONERR)
916cdf0e10cSrcweir 	{
917cdf0e10cSrcweir 		if(aViewData.GetDocShell()->IsReadOnly())
918cdf0e10cSrcweir 		{
919cdf0e10cSrcweir 			nGlobStrId=STR_READONLYERR;
920cdf0e10cSrcweir 		}
921cdf0e10cSrcweir 	}
922cdf0e10cSrcweir 
923cdf0e10cSrcweir 	InfoBox aBox( pParent, ScGlobal::GetRscString( nGlobStrId ) );
924cdf0e10cSrcweir 	aBox.Execute();
925cdf0e10cSrcweir 	if (bFocus)
926cdf0e10cSrcweir 		pParent->GrabFocus();
927cdf0e10cSrcweir }
928cdf0e10cSrcweir 
GetParentOrChild(sal_uInt16 nChildId)929cdf0e10cSrcweir Window* ScTabView::GetParentOrChild( sal_uInt16 nChildId )
930cdf0e10cSrcweir {
931cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = aViewData.GetViewShell()->GetViewFrame();
932cdf0e10cSrcweir 
933cdf0e10cSrcweir 	if ( pViewFrm->HasChildWindow(nChildId) )
934cdf0e10cSrcweir 	{
935cdf0e10cSrcweir 		SfxChildWindow* pChild = pViewFrm->GetChildWindow(nChildId);
936cdf0e10cSrcweir 		if (pChild)
937cdf0e10cSrcweir 		{
938cdf0e10cSrcweir 			Window* pWin = pChild->GetWindow();
939cdf0e10cSrcweir 			if (pWin && pWin->IsVisible())
940cdf0e10cSrcweir 				return pWin;
941cdf0e10cSrcweir 		}
942cdf0e10cSrcweir 	}
943cdf0e10cSrcweir 
944cdf0e10cSrcweir 	return aViewData.GetDialogParent();
945cdf0e10cSrcweir }
946cdf0e10cSrcweir 
UpdatePageBreakData(sal_Bool bForcePaint)947cdf0e10cSrcweir void ScTabView::UpdatePageBreakData( sal_Bool bForcePaint )
948cdf0e10cSrcweir {
949cdf0e10cSrcweir 	ScPageBreakData* pNewData = NULL;
950cdf0e10cSrcweir 
951cdf0e10cSrcweir 	if (aViewData.IsPagebreakMode())
952cdf0e10cSrcweir 	{
953cdf0e10cSrcweir 		ScDocShell* pDocSh = aViewData.GetDocShell();
954cdf0e10cSrcweir 		ScDocument* pDoc = pDocSh->GetDocument();
955cdf0e10cSrcweir 		SCTAB nTab = aViewData.GetTabNo();
956cdf0e10cSrcweir 
957cdf0e10cSrcweir 		sal_uInt16 nCount = pDoc->GetPrintRangeCount(nTab);
958cdf0e10cSrcweir 		if (!nCount)
959cdf0e10cSrcweir 			nCount = 1;
960cdf0e10cSrcweir 		pNewData = new ScPageBreakData(nCount);
961cdf0e10cSrcweir 
962cdf0e10cSrcweir 		ScPrintFunc aPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab, 0,0,NULL, NULL, pNewData );
963cdf0e10cSrcweir 		//	ScPrintFunc fuellt im ctor die PageBreakData
964cdf0e10cSrcweir 		if ( nCount > 1 )
965cdf0e10cSrcweir 		{
966cdf0e10cSrcweir 			aPrintFunc.ResetBreaks(nTab);
967cdf0e10cSrcweir 			pNewData->AddPages();
968cdf0e10cSrcweir 		}
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 		//	Druckbereiche veraendert?
971cdf0e10cSrcweir 		if ( bForcePaint || ( pPageBreakData && !pPageBreakData->IsEqual( *pNewData ) ) )
972cdf0e10cSrcweir 			PaintGrid();
973cdf0e10cSrcweir 	}
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 	delete pPageBreakData;
976cdf0e10cSrcweir 	pPageBreakData = pNewData;
977cdf0e10cSrcweir }
978cdf0e10cSrcweir 
979cdf0e10cSrcweir 
980cdf0e10cSrcweir 
981