xref: /aoo41x/main/sc/source/ui/view/tabview4.cxx (revision b3f79822)
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
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
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.
19*b3f79822SAndrew Rist  *
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 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //------------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vcl/help.hxx>
34cdf0e10cSrcweir #include <vcl/svapp.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "tabview.hxx"
37cdf0e10cSrcweir #include "document.hxx"
38cdf0e10cSrcweir #include "docsh.hxx"
39cdf0e10cSrcweir #include "scmod.hxx"
40cdf0e10cSrcweir #include "gridwin.hxx"
41cdf0e10cSrcweir #include "globstr.hrc"
42cdf0e10cSrcweir #include "cell.hxx"
43cdf0e10cSrcweir #include "dociter.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir extern sal_uInt16 nScFillModeMouseModifier;				// global.cxx
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //==================================================================
50cdf0e10cSrcweir 
51cdf0e10cSrcweir //
52cdf0e10cSrcweir // ---	Referenz-Eingabe / Fill-Cursor
53cdf0e10cSrcweir //
54cdf0e10cSrcweir 
HideTip()55cdf0e10cSrcweir void ScTabView::HideTip()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	if ( nTipVisible )
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 		Help::HideTip( nTipVisible );
60cdf0e10cSrcweir 		nTipVisible = 0;
61cdf0e10cSrcweir 	}
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
ShowRefTip()64cdf0e10cSrcweir void ScTabView::ShowRefTip()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
67cdf0e10cSrcweir 	if ( aViewData.GetRefType() == SC_REFTYPE_REF && Help::IsQuickHelpEnabled() )
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 		SCCOL nStartX = aViewData.GetRefStartX();
70cdf0e10cSrcweir 		SCROW nStartY = aViewData.GetRefStartY();
71cdf0e10cSrcweir 		SCCOL nEndX   = aViewData.GetRefEndX();
72cdf0e10cSrcweir 		SCROW nEndY   = aViewData.GetRefEndY();
73cdf0e10cSrcweir 		if ( nEndX != nStartX || nEndY != nStartY )		// nicht fuer einzelne Zelle
74cdf0e10cSrcweir 		{
75cdf0e10cSrcweir 			sal_Bool bLeft = ( nEndX < nStartX );
76cdf0e10cSrcweir 			sal_Bool bTop  = ( nEndY < nStartY );
77cdf0e10cSrcweir 			PutInOrder( nStartX, nEndX );
78cdf0e10cSrcweir 			PutInOrder( nStartY, nEndY );
79cdf0e10cSrcweir 			SCCOL nCols = nEndX+1-nStartX;
80cdf0e10cSrcweir 			SCROW nRows = nEndY+1-nStartY;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 			String aHelp = ScGlobal::GetRscString( STR_QUICKHELP_REF );
83cdf0e10cSrcweir 			aHelp.SearchAndReplace( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("%1")),
84cdf0e10cSrcweir 									String::CreateFromInt32(nRows) );
85cdf0e10cSrcweir 			aHelp.SearchAndReplace( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("%2")),
86cdf0e10cSrcweir 									String::CreateFromInt32(nCols) );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 			ScSplitPos eWhich = aViewData.GetActivePart();
89cdf0e10cSrcweir 			Window* pWin = pGridWin[eWhich];
90cdf0e10cSrcweir 			if ( pWin )
91cdf0e10cSrcweir 			{
92cdf0e10cSrcweir 				Point aStart = aViewData.GetScrPos( nStartX, nStartY, eWhich );
93cdf0e10cSrcweir 				Point aEnd = aViewData.GetScrPos( nEndX+1, nEndY+1, eWhich );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 				Point aPos( bLeft ? aStart.X() : ( aEnd.X() + 3 ),
96cdf0e10cSrcweir 							bTop ? aStart.Y() : ( aEnd.Y() + 3 ) );
97cdf0e10cSrcweir 				sal_uInt16 nFlags = ( bLeft ? QUICKHELP_RIGHT : QUICKHELP_LEFT ) |
98cdf0e10cSrcweir 								( bTop ? QUICKHELP_BOTTOM : QUICKHELP_TOP );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 				// nicht ueber die editierte Formel
101cdf0e10cSrcweir 				if ( !bTop && aViewData.HasEditView( eWhich ) &&
102cdf0e10cSrcweir 						nEndY+1 == aViewData.GetEditViewRow() )
103cdf0e10cSrcweir 				{
104cdf0e10cSrcweir 					//	dann an der oberen Kante der editierten Zelle ausrichten
105cdf0e10cSrcweir 					aPos.Y() -= 2;		// die 3 von oben
106cdf0e10cSrcweir 					nFlags = ( nFlags & ~QUICKHELP_TOP ) | QUICKHELP_BOTTOM;
107cdf0e10cSrcweir 				}
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 				Rectangle aRect( pWin->OutputToScreenPixel( aPos ), Size(1,1) );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 				//!	Test, ob geaendert ??
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 				HideTip();
114cdf0e10cSrcweir 				nTipVisible = Help::ShowTip( pWin, aRect, aHelp, nFlags );
115cdf0e10cSrcweir 				bDone = sal_True;
116cdf0e10cSrcweir 			}
117cdf0e10cSrcweir 		}
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	if (!bDone)
121cdf0e10cSrcweir 		HideTip();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
StopRefMode()124cdf0e10cSrcweir void ScTabView::StopRefMode()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	if (aViewData.IsRefMode())
127cdf0e10cSrcweir 	{
128cdf0e10cSrcweir 		aViewData.SetRefMode( sal_False, SC_REFTYPE_NONE );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 		HideTip();
131cdf0e10cSrcweir         UpdateShrinkOverlay();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		if ( aViewData.GetTabNo() >= aViewData.GetRefStartZ() &&
134cdf0e10cSrcweir 				aViewData.GetTabNo() <= aViewData.GetRefEndZ() )
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir 			ScDocument* pDoc = aViewData.GetDocument();
137cdf0e10cSrcweir 			SCCOL nStartX = aViewData.GetRefStartX();
138cdf0e10cSrcweir 			SCROW nStartY = aViewData.GetRefStartY();
139cdf0e10cSrcweir 			SCCOL nEndX = aViewData.GetRefEndX();
140cdf0e10cSrcweir 			SCROW nEndY = aViewData.GetRefEndY();
141cdf0e10cSrcweir 			if ( nStartX == nEndX && nStartY == nEndY )
142cdf0e10cSrcweir 				pDoc->ExtendMerge( nStartX, nStartY, nEndX, nEndY, aViewData.GetTabNo() );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 			PaintArea( nStartX,nStartY,nEndX,nEndY, SC_UPDATE_MARKS );
145cdf0e10cSrcweir 		}
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 		pSelEngine->Reset();
148cdf0e10cSrcweir 		pSelEngine->SetAddMode( sal_False );		//! sollte das nicht bei Reset passieren?
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		ScSplitPos eOld = pSelEngine->GetWhich();
151cdf0e10cSrcweir 		ScSplitPos eNew = aViewData.GetActivePart();
152cdf0e10cSrcweir 		if ( eNew != eOld )
153cdf0e10cSrcweir 		{
154cdf0e10cSrcweir 			pSelEngine->SetWindow( pGridWin[ eNew ] );
155cdf0e10cSrcweir 			pSelEngine->SetWhich( eNew );
156cdf0e10cSrcweir 			pSelEngine->SetVisibleArea( Rectangle(Point(),
157cdf0e10cSrcweir 										pGridWin[eNew]->GetOutputSizePixel()) );
158cdf0e10cSrcweir 			pGridWin[eOld]->MoveMouseStatus(*pGridWin[eNew]);
159cdf0e10cSrcweir 		}
160cdf0e10cSrcweir 	}
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	//	AlignToCursor(SC_FOLLOW_NONE): Only switch active part.
163cdf0e10cSrcweir 	//	This must also be done if no RefMode was active (for RangeFinder dragging),
164cdf0e10cSrcweir 	//	but if RefMode was set, AlignToCursor must be after SelectionEngine reset,
165cdf0e10cSrcweir 	//	so the SelectionEngine SetWindow call from AlignToCursor doesn't capture
166cdf0e10cSrcweir 	//	the mouse again when called from Tracking/MouseButtonUp (#94562#).
167cdf0e10cSrcweir 	AlignToCursor( aViewData.GetCurX(), aViewData.GetCurY(), SC_FOLLOW_NONE );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
DoneRefMode(sal_Bool bContinue)170cdf0e10cSrcweir void ScTabView::DoneRefMode( sal_Bool bContinue )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	ScDocument* pDoc = aViewData.GetDocument();
173cdf0e10cSrcweir 	if ( aViewData.GetRefType() == SC_REFTYPE_REF && bContinue )
174cdf0e10cSrcweir 		SC_MOD()->AddRefEntry();
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	sal_Bool bWasRef = aViewData.IsRefMode();
177cdf0e10cSrcweir 	aViewData.SetRefMode( sal_False, SC_REFTYPE_NONE );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	HideTip();
180cdf0e10cSrcweir     UpdateShrinkOverlay();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	//	Paint:
183cdf0e10cSrcweir 	if ( bWasRef && aViewData.GetTabNo() >= aViewData.GetRefStartZ() &&
184cdf0e10cSrcweir 					aViewData.GetTabNo() <= aViewData.GetRefEndZ() )
185cdf0e10cSrcweir 	{
186cdf0e10cSrcweir 		SCCOL nStartX = aViewData.GetRefStartX();
187cdf0e10cSrcweir 		SCROW nStartY = aViewData.GetRefStartY();
188cdf0e10cSrcweir 		SCCOL nEndX = aViewData.GetRefEndX();
189cdf0e10cSrcweir 		SCROW nEndY = aViewData.GetRefEndY();
190cdf0e10cSrcweir 		if ( nStartX == nEndX && nStartY == nEndY )
191cdf0e10cSrcweir 			pDoc->ExtendMerge( nStartX, nStartY, nEndX, nEndY, aViewData.GetTabNo() );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		PaintArea( nStartX,nStartY,nEndX,nEndY, SC_UPDATE_MARKS );
194cdf0e10cSrcweir 	}
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
UpdateRef(SCCOL nCurX,SCROW nCurY,SCTAB nCurZ)197cdf0e10cSrcweir void ScTabView::UpdateRef( SCCOL nCurX, SCROW nCurY, SCTAB nCurZ )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir 	ScDocument* pDoc = aViewData.GetDocument();
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	if (!aViewData.IsRefMode())
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		//	Das kommt vor, wenn bei einem Referenz-Dialog als erstes mit Control in die
204cdf0e10cSrcweir 		//	die Tabelle geklickt wird. Dann die neue Referenz an den alten Inhalt anhaengen:
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 		ScModule* pScMod = SC_MOD();
207cdf0e10cSrcweir 		if (pScMod->IsFormulaMode())
208cdf0e10cSrcweir 			pScMod->AddRefEntry();
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 		InitRefMode( nCurX, nCurY, nCurZ, SC_REFTYPE_REF );
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 	if ( nCurX != aViewData.GetRefEndX() || nCurY != aViewData.GetRefEndY() ||
214cdf0e10cSrcweir 		 nCurZ != aViewData.GetRefEndZ() )
215cdf0e10cSrcweir 	{
216cdf0e10cSrcweir 		ScMarkData& rMark = aViewData.GetMarkData();
217cdf0e10cSrcweir 		SCTAB nTab = aViewData.GetTabNo();
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 		SCCOL nStartX = aViewData.GetRefStartX();
220cdf0e10cSrcweir 		SCROW nStartY = aViewData.GetRefStartY();
221cdf0e10cSrcweir 		SCCOL nEndX = aViewData.GetRefEndX();
222cdf0e10cSrcweir 		SCROW nEndY = aViewData.GetRefEndY();
223cdf0e10cSrcweir 		if ( nStartX == nEndX && nStartY == nEndY )
224cdf0e10cSrcweir 			pDoc->ExtendMerge( nStartX, nStartY, nEndX, nEndY, nTab );
225cdf0e10cSrcweir 		ScUpdateRect aRect( nStartX, nStartY, nEndX, nEndY );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 		aViewData.SetRefEnd( nCurX, nCurY, nCurZ );
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 		nStartX = aViewData.GetRefStartX();
230cdf0e10cSrcweir 		nStartY = aViewData.GetRefStartY();
231cdf0e10cSrcweir 		nEndX = aViewData.GetRefEndX();
232cdf0e10cSrcweir 		nEndY = aViewData.GetRefEndY();
233cdf0e10cSrcweir 		if ( nStartX == nEndX && nStartY == nEndY )
234cdf0e10cSrcweir 			pDoc->ExtendMerge( nStartX, nStartY, nEndX, nEndY, nTab );
235cdf0e10cSrcweir 		aRect.SetNew( nStartX, nStartY, nEndX, nEndY );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 		ScRefType eType = aViewData.GetRefType();
238cdf0e10cSrcweir 		if ( eType == SC_REFTYPE_REF )
239cdf0e10cSrcweir 		{
240cdf0e10cSrcweir 			ScRange aRef(
241cdf0e10cSrcweir 					aViewData.GetRefStartX(), aViewData.GetRefStartY(), aViewData.GetRefStartZ(),
242cdf0e10cSrcweir 					aViewData.GetRefEndX(), aViewData.GetRefEndY(), aViewData.GetRefEndZ() );
243cdf0e10cSrcweir 			SC_MOD()->SetReference( aRef, pDoc, &rMark );
244cdf0e10cSrcweir 			ShowRefTip();
245cdf0e10cSrcweir 		}
246cdf0e10cSrcweir 		else if ( eType == SC_REFTYPE_EMBED_LT || eType == SC_REFTYPE_EMBED_RB )
247cdf0e10cSrcweir 		{
248cdf0e10cSrcweir 			PutInOrder(nStartX,nEndX);
249cdf0e10cSrcweir 			PutInOrder(nStartY,nEndY);
250cdf0e10cSrcweir 			pDoc->SetEmbedded( ScRange(nStartX,nStartY,nTab, nEndX,nEndY,nTab) );
251cdf0e10cSrcweir 			ScDocShell* pDocSh = aViewData.GetDocShell();
252cdf0e10cSrcweir 			pDocSh->UpdateOle( &aViewData, sal_True );
253cdf0e10cSrcweir 			pDocSh->SetDocumentModified();
254cdf0e10cSrcweir 		}
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 		SCCOL nPaintStartX;
257cdf0e10cSrcweir 		SCROW nPaintStartY;
258cdf0e10cSrcweir 		SCCOL nPaintEndX;
259cdf0e10cSrcweir 		SCROW nPaintEndY;
260cdf0e10cSrcweir 		if (aRect.GetDiff( nPaintStartX, nPaintStartY, nPaintEndX, nPaintEndY ))
261cdf0e10cSrcweir 			PaintArea( nPaintStartX, nPaintStartY, nPaintEndX, nPaintEndY, SC_UPDATE_MARKS );
262cdf0e10cSrcweir 	}
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 	//	Tip-Hilfe fuer Auto-Fill
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 	if ( aViewData.GetRefType() == SC_REFTYPE_FILL && Help::IsQuickHelpEnabled() )
267cdf0e10cSrcweir 	{
268cdf0e10cSrcweir 		String aHelpStr;
269cdf0e10cSrcweir 		ScRange aMarkRange;
270cdf0e10cSrcweir 		aViewData.GetSimpleArea( aMarkRange );
271cdf0e10cSrcweir 		SCCOL nEndX = aViewData.GetRefEndX();
272cdf0e10cSrcweir 		SCROW nEndY = aViewData.GetRefEndY();
273cdf0e10cSrcweir 		ScRange aDelRange;
274cdf0e10cSrcweir 		if ( aViewData.GetFillMode() == SC_FILL_MATRIX && !(nScFillModeMouseModifier & KEY_MOD1) )
275cdf0e10cSrcweir 		{
276cdf0e10cSrcweir 			aHelpStr = ScGlobal::GetRscString( STR_TIP_RESIZEMATRIX );
277cdf0e10cSrcweir 			SCCOL nCols = nEndX + 1 - aViewData.GetRefStartX();	// Reihenfolge ist richtig
278cdf0e10cSrcweir 			SCROW nRows = nEndY + 1 - aViewData.GetRefStartY();
279cdf0e10cSrcweir 			aHelpStr.SearchAndReplace( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("%1")),
280cdf0e10cSrcweir 									   String::CreateFromInt32(nRows) );
281cdf0e10cSrcweir 			aHelpStr.SearchAndReplace( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("%2")),
282cdf0e10cSrcweir 									   String::CreateFromInt32(nCols) );
283cdf0e10cSrcweir 		}
284cdf0e10cSrcweir 		else if ( aViewData.GetDelMark( aDelRange ) )
285cdf0e10cSrcweir 			aHelpStr = ScGlobal::GetRscString( STR_QUICKHELP_DELETE );
286cdf0e10cSrcweir 		else if ( nEndX != aMarkRange.aEnd.Col() || nEndY != aMarkRange.aEnd.Row() )
287cdf0e10cSrcweir 			aHelpStr = pDoc->GetAutoFillPreview( aMarkRange, nEndX, nEndY );
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 		//	je nach Richtung die obere oder untere Ecke:
290cdf0e10cSrcweir 		SCCOL nAddX = ( nEndX >= aMarkRange.aEnd.Col() ) ? 1 : 0;
291cdf0e10cSrcweir 		SCROW nAddY = ( nEndY >= aMarkRange.aEnd.Row() ) ? 1 : 0;
292cdf0e10cSrcweir 		Point aPos = aViewData.GetScrPos( nEndX+nAddX, nEndY+nAddY, aViewData.GetActivePart() );
293cdf0e10cSrcweir 		aPos.X() += 8;
294cdf0e10cSrcweir 		aPos.Y() += 4;
295cdf0e10cSrcweir 		Window* pWin = GetActiveWin();
296cdf0e10cSrcweir 		if ( pWin )
297cdf0e10cSrcweir 			aPos = pWin->OutputToScreenPixel( aPos );
298cdf0e10cSrcweir 		Rectangle aRect( aPos, aPos );
299cdf0e10cSrcweir 		sal_uInt16 nAlign = QUICKHELP_LEFT|QUICKHELP_TOP;
300cdf0e10cSrcweir 		Help::ShowQuickHelp(pWin, aRect, aHelpStr, nAlign);
301cdf0e10cSrcweir 	}
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
InitRefMode(SCCOL nCurX,SCROW nCurY,SCTAB nCurZ,ScRefType eType,sal_Bool bPaint)304cdf0e10cSrcweir void ScTabView::InitRefMode( SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, ScRefType eType, sal_Bool bPaint )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir 	ScDocument* pDoc = aViewData.GetDocument();
307cdf0e10cSrcweir 	ScMarkData& rMark = aViewData.GetMarkData();
308cdf0e10cSrcweir 	if (!aViewData.IsRefMode())
309cdf0e10cSrcweir 	{
310cdf0e10cSrcweir 		aViewData.SetRefMode( sal_True, eType );
311cdf0e10cSrcweir 		aViewData.SetRefStart( nCurX, nCurY, nCurZ );
312cdf0e10cSrcweir 		aViewData.SetRefEnd( nCurX, nCurY, nCurZ );
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 		if (nCurZ == aViewData.GetTabNo() && bPaint)
315cdf0e10cSrcweir 		{
316cdf0e10cSrcweir 			SCCOL nStartX = nCurX;
317cdf0e10cSrcweir 			SCROW nStartY = nCurY;
318cdf0e10cSrcweir 			SCCOL nEndX = nCurX;
319cdf0e10cSrcweir 			SCROW nEndY = nCurY;
320cdf0e10cSrcweir 			pDoc->ExtendMerge( nStartX, nStartY, nEndX, nEndY, aViewData.GetTabNo() );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 			//!	nur Markierung ueber Inhalte zeichnen!
323cdf0e10cSrcweir 			PaintArea( nStartX,nStartY,nEndX,nEndY, SC_UPDATE_MARKS );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 			//	SetReference ohne Merge-Anpassung
326cdf0e10cSrcweir 			ScRange aRef( nCurX,nCurY,nCurZ, nCurX,nCurY,nCurZ );
327cdf0e10cSrcweir 			SC_MOD()->SetReference( aRef, pDoc, &rMark );
328cdf0e10cSrcweir 		}
329cdf0e10cSrcweir 	}
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir //UNUSED2008-05  void ScTabView::EndSelection()
333cdf0e10cSrcweir //UNUSED2008-05  {
334cdf0e10cSrcweir //UNUSED2008-05      ScModule* pScMod = SC_MOD();
335cdf0e10cSrcweir //UNUSED2008-05      sal_Bool bRefMode = pScMod->IsFormulaMode();
336cdf0e10cSrcweir //UNUSED2008-05      if ( bRefMode )
337cdf0e10cSrcweir //UNUSED2008-05          pScMod->EndReference();
338cdf0e10cSrcweir //UNUSED2008-05  }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir // static
SetScrollBar(ScrollBar & rScroll,long nRangeMax,long nVisible,long nPos,sal_Bool bLayoutRTL)341cdf0e10cSrcweir void ScTabView::SetScrollBar( ScrollBar& rScroll, long nRangeMax, long nVisible, long nPos, sal_Bool bLayoutRTL )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     if ( nVisible == 0 )
344cdf0e10cSrcweir         nVisible = 1;       // #i59893# don't use visible size 0
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	//	RTL layout uses a negative range to simulate a mirrored scroll bar.
347cdf0e10cSrcweir 	//	SetScrollBar/GetScrollBarPos hide this so outside of these functions normal cell
348cdf0e10cSrcweir 	//	addresses can be used.
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	if ( bLayoutRTL )
351cdf0e10cSrcweir 	{
352cdf0e10cSrcweir 		rScroll.SetRange( Range( -nRangeMax, 0 ) );
353cdf0e10cSrcweir 		rScroll.SetVisibleSize( nVisible );
354cdf0e10cSrcweir 		rScroll.SetThumbPos( -nPos - nVisible );
355cdf0e10cSrcweir 	}
356cdf0e10cSrcweir 	else
357cdf0e10cSrcweir 	{
358cdf0e10cSrcweir 		rScroll.SetRange( Range( 0, nRangeMax ) );
359cdf0e10cSrcweir 		rScroll.SetVisibleSize( nVisible );
360cdf0e10cSrcweir 		rScroll.SetThumbPos( nPos );
361cdf0e10cSrcweir 	}
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir // static
GetScrollBarPos(ScrollBar & rScroll,sal_Bool bLayoutRTL)365cdf0e10cSrcweir long ScTabView::GetScrollBarPos( ScrollBar& rScroll, sal_Bool bLayoutRTL )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir 	if ( bLayoutRTL )
368cdf0e10cSrcweir 		return -rScroll.GetThumbPos() - rScroll.GetVisibleSize();
369cdf0e10cSrcweir 	else
370cdf0e10cSrcweir 		return rScroll.GetThumbPos();
371cdf0e10cSrcweir }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir //	UpdateScrollBars - sichtbaren Bereich und Scrollweite der Scrollbars einstellen
374cdf0e10cSrcweir 
lcl_UpdateBar(ScrollBar & rScroll,SCCOLROW nSize)375cdf0e10cSrcweir long lcl_UpdateBar( ScrollBar& rScroll, SCCOLROW nSize )		// Size = (komplette) Zellen
376cdf0e10cSrcweir {
377cdf0e10cSrcweir 	long nOldPos;
378cdf0e10cSrcweir 	long nNewPos;
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 	nOldPos = rScroll.GetThumbPos();
381cdf0e10cSrcweir 	rScroll.SetPageSize( static_cast<long>(nSize) );
382cdf0e10cSrcweir 	nNewPos = rScroll.GetThumbPos();
383cdf0e10cSrcweir #ifndef UNX
384cdf0e10cSrcweir 	rScroll.SetPageSize( 1 );				// immer moeglich !
385cdf0e10cSrcweir #endif
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 	return nNewPos - nOldPos;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
lcl_GetScrollRange(SCCOLROW nDocEnd,SCCOLROW nPos,SCCOLROW nVis,SCCOLROW nMax,SCCOLROW nStart)390cdf0e10cSrcweir long lcl_GetScrollRange( SCCOLROW nDocEnd, SCCOLROW nPos, SCCOLROW nVis, SCCOLROW nMax, SCCOLROW nStart )
391cdf0e10cSrcweir {
392cdf0e10cSrcweir 	// get the end (positive) of a scroll bar range that always starts at 0
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 	++nVis;
395cdf0e10cSrcweir 	++nMax;		// for partially visible cells
396cdf0e10cSrcweir 	SCCOLROW nEnd = Max(nDocEnd, (SCCOLROW)(nPos+nVis)) + nVis;
397cdf0e10cSrcweir 	if (nEnd > nMax)
398cdf0e10cSrcweir 		nEnd = nMax;
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 	return ( nEnd - nStart );		// for range starting at 0
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
UpdateScrollBars()403cdf0e10cSrcweir void ScTabView::UpdateScrollBars()
404cdf0e10cSrcweir {
405cdf0e10cSrcweir 	long		nDiff;
406cdf0e10cSrcweir 	sal_Bool		bTop =   ( aViewData.GetVSplitMode() != SC_SPLIT_NONE );
407cdf0e10cSrcweir 	sal_Bool		bRight = ( aViewData.GetHSplitMode() != SC_SPLIT_NONE );
408cdf0e10cSrcweir 	ScDocument*	pDoc = aViewData.GetDocument();
409cdf0e10cSrcweir 	SCTAB		nTab = aViewData.GetTabNo();
410cdf0e10cSrcweir     sal_Bool        bMirror = pDoc->IsLayoutRTL( nTab ) != Application::GetSettings().GetLayoutRTL();
411cdf0e10cSrcweir 	SCCOL		nUsedX;
412cdf0e10cSrcweir 	SCROW		nUsedY;
413cdf0e10cSrcweir 	pDoc->GetTableArea( nTab, nUsedX, nUsedY );		//! cachen !!!!!!!!!!!!!!!
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	SCCOL nVisXL = 0;
416cdf0e10cSrcweir 	SCCOL nVisXR = 0;
417cdf0e10cSrcweir 	SCROW nVisYB = 0;
418cdf0e10cSrcweir 	SCROW nVisYT = 0;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 	SCCOL nStartX = 0;
421cdf0e10cSrcweir 	SCROW nStartY = 0;
422cdf0e10cSrcweir 	if (aViewData.GetHSplitMode()==SC_SPLIT_FIX)
423cdf0e10cSrcweir 		nStartX = aViewData.GetFixPosX();
424cdf0e10cSrcweir 	if (aViewData.GetVSplitMode()==SC_SPLIT_FIX)
425cdf0e10cSrcweir 		nStartY = aViewData.GetFixPosY();
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 	nVisXL = aViewData.VisibleCellsX( SC_SPLIT_LEFT );
428cdf0e10cSrcweir 	long nMaxXL = lcl_GetScrollRange( nUsedX, aViewData.GetPosX(SC_SPLIT_LEFT), nVisXL, MAXCOL, 0 );
429cdf0e10cSrcweir     SetScrollBar( aHScrollLeft, nMaxXL, nVisXL, aViewData.GetPosX( SC_SPLIT_LEFT ), bMirror );
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 	nVisYB = aViewData.VisibleCellsY( SC_SPLIT_BOTTOM );
432cdf0e10cSrcweir 	long nMaxYB = lcl_GetScrollRange( nUsedY, aViewData.GetPosY(SC_SPLIT_BOTTOM), nVisYB, MAXROW, nStartY );
433cdf0e10cSrcweir 	SetScrollBar( aVScrollBottom, nMaxYB, nVisYB, aViewData.GetPosY( SC_SPLIT_BOTTOM ) - nStartY, sal_False );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 	if (bRight)
436cdf0e10cSrcweir 	{
437cdf0e10cSrcweir 		nVisXR = aViewData.VisibleCellsX( SC_SPLIT_RIGHT );
438cdf0e10cSrcweir 		long nMaxXR = lcl_GetScrollRange( nUsedX, aViewData.GetPosX(SC_SPLIT_RIGHT), nVisXR, MAXCOL, nStartX );
439cdf0e10cSrcweir         SetScrollBar( aHScrollRight, nMaxXR, nVisXR, aViewData.GetPosX( SC_SPLIT_RIGHT ) - nStartX, bMirror );
440cdf0e10cSrcweir 	}
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 	if (bTop)
443cdf0e10cSrcweir 	{
444cdf0e10cSrcweir 		nVisYT = aViewData.VisibleCellsY( SC_SPLIT_TOP );
445cdf0e10cSrcweir 		long nMaxYT = lcl_GetScrollRange( nUsedY, aViewData.GetPosY(SC_SPLIT_TOP), nVisYT, MAXROW, 0 );
446cdf0e10cSrcweir 		SetScrollBar( aVScrollTop, nMaxYT, nVisYT, aViewData.GetPosY( SC_SPLIT_TOP ), sal_False );
447cdf0e10cSrcweir 	}
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	//		Bereich testen
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 	nDiff = lcl_UpdateBar( aHScrollLeft, nVisXL );
452cdf0e10cSrcweir 	if (nDiff) ScrollX( nDiff, SC_SPLIT_LEFT );
453cdf0e10cSrcweir 	if (bRight)
454cdf0e10cSrcweir 	{
455cdf0e10cSrcweir 		nDiff = lcl_UpdateBar( aHScrollRight, nVisXR );
456cdf0e10cSrcweir 		if (nDiff) ScrollX( nDiff, SC_SPLIT_RIGHT );
457cdf0e10cSrcweir 	}
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 	nDiff = lcl_UpdateBar( aVScrollBottom, nVisYB );
460cdf0e10cSrcweir 	if (nDiff) ScrollY( nDiff, SC_SPLIT_BOTTOM );
461cdf0e10cSrcweir 	if (bTop)
462cdf0e10cSrcweir 	{
463cdf0e10cSrcweir 		nDiff = lcl_UpdateBar( aVScrollTop, nVisYT );
464cdf0e10cSrcweir 		if (nDiff) ScrollY( nDiff, SC_SPLIT_TOP );
465cdf0e10cSrcweir 	}
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 	//		set visible area for online spelling
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	if ( aViewData.IsActive() )
470cdf0e10cSrcweir 	{
471cdf0e10cSrcweir 		ScSplitPos eActive = aViewData.GetActivePart();
472cdf0e10cSrcweir 		ScHSplitPos eHWhich = WhichH( eActive );
473cdf0e10cSrcweir 		ScVSplitPos eVWhich = WhichV( eActive );
474cdf0e10cSrcweir 		SCCOL nPosX = aViewData.GetPosX(eHWhich);
475cdf0e10cSrcweir 		SCROW nPosY = aViewData.GetPosY(eVWhich);
476cdf0e10cSrcweir 		SCCOL nEndX = nPosX + ( ( eHWhich == SC_SPLIT_LEFT ) ? nVisXL : nVisXR );
477cdf0e10cSrcweir 		SCROW nEndY = nPosY + ( ( eVWhich == SC_SPLIT_TOP ) ? nVisYT : nVisYB );
478cdf0e10cSrcweir 		if ( nEndX > MAXCOL ) nEndX = MAXCOL;
479cdf0e10cSrcweir 		if ( nEndY > MAXROW ) nEndY = MAXROW;
480cdf0e10cSrcweir 		ScRange aVisible( nPosX, nPosY, nTab, nEndX, nEndY, nTab );
481cdf0e10cSrcweir 		if ( pDoc->SetVisibleSpellRange( aVisible ) )
482cdf0e10cSrcweir 			SC_MOD()->AnythingChanged();				// if visible area has changed
483cdf0e10cSrcweir 	}
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir #ifndef HDR_SLIDERSIZE
487cdf0e10cSrcweir #define HDR_SLIDERSIZE		2
488cdf0e10cSrcweir #endif
489cdf0e10cSrcweir 
InvertHorizontal(ScVSplitPos eWhich,long nDragPos)490cdf0e10cSrcweir void ScTabView::InvertHorizontal( ScVSplitPos eWhich, long nDragPos )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<4; i++)
493cdf0e10cSrcweir 		if (WhichV((ScSplitPos)i)==eWhich)
494cdf0e10cSrcweir 		{
495cdf0e10cSrcweir 			ScGridWindow* pWin = pGridWin[i];
496cdf0e10cSrcweir 			if (pWin)
497cdf0e10cSrcweir 			{
498cdf0e10cSrcweir 				Rectangle aRect( 0,nDragPos, pWin->GetOutputSizePixel().Width()-1,nDragPos+HDR_SLIDERSIZE-1 );
499cdf0e10cSrcweir 				pWin->Update();
500cdf0e10cSrcweir 				pWin->DoInvertRect( aRect );	// Pixel
501cdf0e10cSrcweir 			}
502cdf0e10cSrcweir 		}
503cdf0e10cSrcweir }
504cdf0e10cSrcweir 
InvertVertical(ScHSplitPos eWhich,long nDragPos)505cdf0e10cSrcweir void ScTabView::InvertVertical( ScHSplitPos eWhich, long nDragPos )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<4; i++)
508cdf0e10cSrcweir 		if (WhichH((ScSplitPos)i)==eWhich)
509cdf0e10cSrcweir 		{
510cdf0e10cSrcweir 			ScGridWindow* pWin = pGridWin[i];
511cdf0e10cSrcweir 			if (pWin)
512cdf0e10cSrcweir 			{
513cdf0e10cSrcweir 				Rectangle aRect( nDragPos,0, nDragPos+HDR_SLIDERSIZE-1,pWin->GetOutputSizePixel().Height()-1 );
514cdf0e10cSrcweir 				pWin->Update();
515cdf0e10cSrcweir 				pWin->DoInvertRect( aRect );	// Pixel
516cdf0e10cSrcweir 			}
517cdf0e10cSrcweir 		}
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir //==================================================================
521cdf0e10cSrcweir 
InterpretVisible()522cdf0e10cSrcweir void ScTabView::InterpretVisible()
523cdf0e10cSrcweir {
524cdf0e10cSrcweir 	//	make sure all visible cells are interpreted,
525cdf0e10cSrcweir 	//	so the next paint will not execute a macro function
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 	ScDocument* pDoc = aViewData.GetDocument();
528cdf0e10cSrcweir 	if ( !pDoc->GetAutoCalc() )
529cdf0e10cSrcweir 		return;
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 	SCTAB nTab = aViewData.GetTabNo();
532cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<4; i++)
533cdf0e10cSrcweir 	{
534cdf0e10cSrcweir 		//	rely on gridwin pointers to find used panes
535cdf0e10cSrcweir 		//	no IsVisible test in case the whole view is not yet shown
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 		if (pGridWin[i])
538cdf0e10cSrcweir 		{
539cdf0e10cSrcweir 			ScHSplitPos eHWhich = WhichH( ScSplitPos(i) );
540cdf0e10cSrcweir 			ScVSplitPos eVWhich = WhichV( ScSplitPos(i) );
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 			SCCOL	nX1 = aViewData.GetPosX( eHWhich );
543cdf0e10cSrcweir 			SCROW	nY1 = aViewData.GetPosY( eVWhich );
544cdf0e10cSrcweir 			SCCOL	nX2 = nX1 + aViewData.VisibleCellsX( eHWhich );
545cdf0e10cSrcweir 			SCROW	nY2 = nY1 + aViewData.VisibleCellsY( eVWhich );
546cdf0e10cSrcweir 
547cdf0e10cSrcweir 			if (nX2 > MAXCOL) nX2 = MAXCOL;
548cdf0e10cSrcweir 			if (nY2 > MAXROW) nY2 = MAXROW;
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 			ScCellIterator aIter( pDoc, nX1, nY1, nTab, nX2, nY2, nTab );
551cdf0e10cSrcweir 			ScBaseCell* pCell = aIter.GetFirst();
552cdf0e10cSrcweir 			while ( pCell )
553cdf0e10cSrcweir 			{
554cdf0e10cSrcweir 				if ( pCell->GetCellType() == CELLTYPE_FORMULA && ((ScFormulaCell*)pCell)->GetDirty() )
555cdf0e10cSrcweir 					((ScFormulaCell*)pCell)->Interpret();
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 				pCell = aIter.GetNext();
558cdf0e10cSrcweir 			}
559cdf0e10cSrcweir 		}
560cdf0e10cSrcweir 	}
561cdf0e10cSrcweir 
562cdf0e10cSrcweir     // #i65047# repaint during the above loop may have set the bNeedsRepaint flag
563cdf0e10cSrcweir     CheckNeedsRepaint();
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 
570