xref: /aoo41x/main/sc/source/ui/view/select.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 // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <tools/urlobj.hxx>
32cdf0e10cSrcweir #include <vcl/sound.hxx>
33cdf0e10cSrcweir #include <sfx2/docfile.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "select.hxx"
36cdf0e10cSrcweir #include "sc.hrc"
37cdf0e10cSrcweir #include "tabvwsh.hxx"
38cdf0e10cSrcweir #include "scmod.hxx"
39cdf0e10cSrcweir #include "document.hxx"
40cdf0e10cSrcweir //#include "dataobj.hxx"
41cdf0e10cSrcweir #include "transobj.hxx"
42cdf0e10cSrcweir #include "docsh.hxx"
43cdf0e10cSrcweir #include "tabprotection.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir extern sal_uInt16 nScFillModeMouseModifier;				// global.cxx
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using namespace com::sun::star;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
50cdf0e10cSrcweir 
51cdf0e10cSrcweir static Point aSwitchPos;				//! Member
52cdf0e10cSrcweir static sal_Bool bDidSwitch = sal_False;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // -----------------------------------------------------------------------
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //
57cdf0e10cSrcweir //					View (Gridwin / Tastatur)
58cdf0e10cSrcweir //
59cdf0e10cSrcweir 
60cdf0e10cSrcweir ScViewFunctionSet::ScViewFunctionSet( ScViewData* pNewViewData ) :
61cdf0e10cSrcweir 		pViewData( pNewViewData ),
62cdf0e10cSrcweir 		pEngine( NULL ),
63cdf0e10cSrcweir 		bAnchor( sal_False ),
64cdf0e10cSrcweir 		bStarted( sal_False )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	DBG_ASSERT(pViewData, "ViewData==0 bei FunctionSet");
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir ScSplitPos ScViewFunctionSet::GetWhich()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	if (pEngine)
72cdf0e10cSrcweir 		return pEngine->GetWhich();
73cdf0e10cSrcweir 	else
74cdf0e10cSrcweir 		return pViewData->GetActivePart();
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir void ScViewFunctionSet::SetSelectionEngine( ScViewSelectionEngine* pSelEngine )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir 	pEngine = pSelEngine;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir //		Drag & Drop
83cdf0e10cSrcweir 
84cdf0e10cSrcweir void __EXPORT ScViewFunctionSet::BeginDrag()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	SCsCOL nPosX;
89cdf0e10cSrcweir 	SCsROW nPosY;
90cdf0e10cSrcweir 	if (pEngine)
91cdf0e10cSrcweir 	{
92cdf0e10cSrcweir 		Point aMPos = pEngine->GetMousePosPixel();
93cdf0e10cSrcweir 		pViewData->GetPosFromPixel( aMPos.X(), aMPos.Y(), GetWhich(), nPosX, nPosY );
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir 	else
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		nPosX = pViewData->GetCurX();
98cdf0e10cSrcweir 		nPosY = pViewData->GetCurY();
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
102cdf0e10cSrcweir 	sal_Bool bRefMode = pScMod->IsFormulaMode();
103cdf0e10cSrcweir 	if (!bRefMode)
104cdf0e10cSrcweir 	{
105cdf0e10cSrcweir 		pViewData->GetView()->FakeButtonUp( GetWhich() );	// ButtonUp wird verschluckt
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		ScMarkData& rMark = pViewData->GetMarkData();
108cdf0e10cSrcweir //		rMark.SetMarking(sal_False);						// es fehlt ein ButtonUp
109cdf0e10cSrcweir 		rMark.MarkToSimple();
110cdf0e10cSrcweir 		if ( rMark.IsMarked() && !rMark.IsMultiMarked() )
111cdf0e10cSrcweir 		{
112cdf0e10cSrcweir 			ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
113cdf0e10cSrcweir 			// bApi = sal_True -> no error mesages
114cdf0e10cSrcweir 			sal_Bool bCopied = pViewData->GetView()->CopyToClip( pClipDoc, sal_False, sal_True );
115cdf0e10cSrcweir 			if ( bCopied )
116cdf0e10cSrcweir 			{
117cdf0e10cSrcweir 				sal_Int8 nDragActions = pViewData->GetView()->SelectionEditable() ?
118cdf0e10cSrcweir 										( DND_ACTION_COPYMOVE | DND_ACTION_LINK ) :
119cdf0e10cSrcweir 										( DND_ACTION_COPY | DND_ACTION_LINK );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 				ScDocShell* pDocSh = pViewData->GetDocShell();
122cdf0e10cSrcweir 				TransferableObjectDescriptor aObjDesc;
123cdf0e10cSrcweir 				pDocSh->FillTransferableObjectDescriptor( aObjDesc );
124cdf0e10cSrcweir 				aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
125cdf0e10cSrcweir 				// maSize is set in ScTransferObj ctor
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 				ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
128cdf0e10cSrcweir 				uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 				// set position of dragged cell within range
131cdf0e10cSrcweir 				ScRange aMarkRange = pTransferObj->GetRange();
132cdf0e10cSrcweir 				SCCOL nStartX = aMarkRange.aStart.Col();
133cdf0e10cSrcweir 				SCROW nStartY = aMarkRange.aStart.Row();
134cdf0e10cSrcweir 				SCCOL nHandleX = (nPosX >= (SCsCOL) nStartX) ? nPosX - nStartX : 0;
135cdf0e10cSrcweir 				SCROW nHandleY = (nPosY >= (SCsROW) nStartY) ? nPosY - nStartY : 0;
136cdf0e10cSrcweir 				pTransferObj->SetDragHandlePos( nHandleX, nHandleY );
137cdf0e10cSrcweir 				pTransferObj->SetVisibleTab( nTab );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 				pTransferObj->SetDragSource( pDocSh, rMark );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 				Window* pWindow = pViewData->GetActiveWin();
142cdf0e10cSrcweir 				if ( pWindow->IsTracking() )
143cdf0e10cSrcweir 					pWindow->EndTracking( ENDTRACK_CANCEL );	// abort selecting
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 				SC_MOD()->SetDragObject( pTransferObj, NULL );		// for internal D&D
146cdf0e10cSrcweir 				pTransferObj->StartDrag( pWindow, nDragActions );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 				return;			// dragging started
149cdf0e10cSrcweir 			}
150cdf0e10cSrcweir 			else
151cdf0e10cSrcweir 				delete pClipDoc;
152cdf0e10cSrcweir 		}
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	Sound::Beep();			// can't drag
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir //		Selektion
159cdf0e10cSrcweir 
160cdf0e10cSrcweir void __EXPORT ScViewFunctionSet::CreateAnchor()
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	if (bAnchor) return;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
165cdf0e10cSrcweir 	if (bRefMode)
166cdf0e10cSrcweir 		SetAnchor( pViewData->GetRefStartX(), pViewData->GetRefStartY() );
167cdf0e10cSrcweir 	else
168cdf0e10cSrcweir 		SetAnchor( pViewData->GetCurX(), pViewData->GetCurY() );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir void ScViewFunctionSet::SetAnchor( SCCOL nPosX, SCROW nPosY )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir 	sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
174cdf0e10cSrcweir 	ScTabView* pView = pViewData->GetView();
175cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	if (bRefMode)
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir 		pView->DoneRefMode( sal_False );
180cdf0e10cSrcweir 		aAnchorPos.Set( nPosX, nPosY, nTab );
181cdf0e10cSrcweir 		pView->InitRefMode( aAnchorPos.Col(), aAnchorPos.Row(), aAnchorPos.Tab(),
182cdf0e10cSrcweir 							SC_REFTYPE_REF );
183cdf0e10cSrcweir 		bStarted = sal_True;
184cdf0e10cSrcweir 	}
185cdf0e10cSrcweir 	else if (pViewData->IsAnyFillMode())
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		aAnchorPos.Set( nPosX, nPosY, nTab );
188cdf0e10cSrcweir 		bStarted = sal_True;
189cdf0e10cSrcweir 	}
190cdf0e10cSrcweir 	else
191cdf0e10cSrcweir 	{
192cdf0e10cSrcweir 		// nicht weg und gleich wieder hin
193cdf0e10cSrcweir 		if ( bStarted && pView->IsMarking( nPosX, nPosY, nTab ) )
194cdf0e10cSrcweir 		{
195cdf0e10cSrcweir 			// nix
196cdf0e10cSrcweir 		}
197cdf0e10cSrcweir 		else
198cdf0e10cSrcweir 		{
199cdf0e10cSrcweir 			pView->DoneBlockMode( sal_True );
200cdf0e10cSrcweir 			aAnchorPos.Set( nPosX, nPosY, nTab );
201cdf0e10cSrcweir 			ScMarkData& rMark = pViewData->GetMarkData();
202cdf0e10cSrcweir 			if ( rMark.IsMarked() || rMark.IsMultiMarked() )
203cdf0e10cSrcweir 			{
204cdf0e10cSrcweir 				pView->InitBlockMode( aAnchorPos.Col(), aAnchorPos.Row(),
205cdf0e10cSrcweir 										aAnchorPos.Tab(), sal_True );
206cdf0e10cSrcweir 				bStarted = sal_True;
207cdf0e10cSrcweir 			}
208cdf0e10cSrcweir 			else
209cdf0e10cSrcweir 				bStarted = sal_False;
210cdf0e10cSrcweir 		}
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 	bAnchor = sal_True;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir void __EXPORT ScViewFunctionSet::DestroyAnchor()
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
218cdf0e10cSrcweir 	if (bRefMode)
219cdf0e10cSrcweir 		pViewData->GetView()->DoneRefMode( sal_True );
220cdf0e10cSrcweir 	else
221cdf0e10cSrcweir 		pViewData->GetView()->DoneBlockMode( sal_True );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	bAnchor = sal_False;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir void ScViewFunctionSet::SetAnchorFlag( sal_Bool bSet )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir 	bAnchor = bSet;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir sal_Bool __EXPORT ScViewFunctionSet::SetCursorAtPoint( const Point& rPointPixel, sal_Bool /* bDontSelectAtCursor */ )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	if ( bDidSwitch )
234cdf0e10cSrcweir 	{
235cdf0e10cSrcweir 		if ( rPointPixel == aSwitchPos )
236cdf0e10cSrcweir 			return sal_False;					// nicht auf falschem Fenster scrollen
237cdf0e10cSrcweir 		else
238cdf0e10cSrcweir 			bDidSwitch = sal_False;
239cdf0e10cSrcweir 	}
240cdf0e10cSrcweir 	aSwitchPos = rPointPixel;		// nur wichtig, wenn bDidSwitch
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 	//	treat position 0 as -1, so scrolling is always possible
243cdf0e10cSrcweir 	//	(with full screen and hidden headers, the top left border may be at 0)
244cdf0e10cSrcweir 	//	(moved from ScViewData::GetPosFromPixel)
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	Point aEffPos = rPointPixel;
247cdf0e10cSrcweir 	if ( aEffPos.X() == 0 )
248cdf0e10cSrcweir 		aEffPos.X() = -1;
249cdf0e10cSrcweir 	if ( aEffPos.Y() == 0 )
250cdf0e10cSrcweir 		aEffPos.Y() = -1;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	//	Scrolling
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	Size aWinSize = pEngine->GetWindow()->GetOutputSizePixel();
255cdf0e10cSrcweir 	sal_Bool bRightScroll  = ( aEffPos.X() >= aWinSize.Width() );
256cdf0e10cSrcweir 	sal_Bool bBottomScroll = ( aEffPos.Y() >= aWinSize.Height() );
257cdf0e10cSrcweir 	sal_Bool bNegScroll    = ( aEffPos.X() < 0 || aEffPos.Y() < 0 );
258cdf0e10cSrcweir 	sal_Bool bScroll = bRightScroll || bBottomScroll || bNegScroll;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	SCsCOL	nPosX;
261cdf0e10cSrcweir 	SCsROW	nPosY;
262cdf0e10cSrcweir 	pViewData->GetPosFromPixel( aEffPos.X(), aEffPos.Y(), GetWhich(),
263cdf0e10cSrcweir 								nPosX, nPosY, sal_True, sal_True );		// mit Repair
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	//	fuer AutoFill in der Mitte der Zelle umschalten
266cdf0e10cSrcweir 	//	dabei aber nicht das Scrolling nach rechts/unten verhindern
267cdf0e10cSrcweir 	if ( pViewData->IsFillMode() || pViewData->GetFillMode() == SC_FILL_MATRIX )
268cdf0e10cSrcweir 	{
269cdf0e10cSrcweir 		sal_Bool bLeft, bTop;
270cdf0e10cSrcweir 		pViewData->GetMouseQuadrant( aEffPos, GetWhich(), nPosX, nPosY, bLeft, bTop );
271cdf0e10cSrcweir 		ScDocument* pDoc = pViewData->GetDocument();
272cdf0e10cSrcweir 		SCTAB nTab = pViewData->GetTabNo();
273cdf0e10cSrcweir 		if ( bLeft && !bRightScroll )
274cdf0e10cSrcweir 			do --nPosX; while ( nPosX>=0 && pDoc->ColHidden( nPosX, nTab ) );
275cdf0e10cSrcweir 		if ( bTop && !bBottomScroll )
276cdf0e10cSrcweir         {
277cdf0e10cSrcweir             if (--nPosY >= 0)
278cdf0e10cSrcweir             {
279cdf0e10cSrcweir                 nPosY = pDoc->LastVisibleRow(0, nPosY, nTab);
280cdf0e10cSrcweir                 if (!ValidRow(nPosY))
281cdf0e10cSrcweir                     nPosY = -1;
282cdf0e10cSrcweir             }
283cdf0e10cSrcweir         }
284cdf0e10cSrcweir 		//	negativ ist erlaubt
285cdf0e10cSrcweir 	}
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	//	ueber Fixier-Grenze bewegt?
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	ScSplitPos eWhich = GetWhich();
290cdf0e10cSrcweir 	if ( eWhich == pViewData->GetActivePart() )
291cdf0e10cSrcweir 	{
292cdf0e10cSrcweir 		if ( pViewData->GetHSplitMode() == SC_SPLIT_FIX )
293cdf0e10cSrcweir 			if ( aEffPos.X() >= aWinSize.Width() )
294cdf0e10cSrcweir 			{
295cdf0e10cSrcweir 				if ( eWhich == SC_SPLIT_TOPLEFT )
296cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_TOPRIGHT ), bScroll = sal_False, bDidSwitch = sal_True;
297cdf0e10cSrcweir 				else if ( eWhich == SC_SPLIT_BOTTOMLEFT )
298cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT ), bScroll = sal_False, bDidSwitch = sal_True;
299cdf0e10cSrcweir 			}
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 		if ( pViewData->GetVSplitMode() == SC_SPLIT_FIX )
302cdf0e10cSrcweir 			if ( aEffPos.Y() >= aWinSize.Height() )
303cdf0e10cSrcweir 			{
304cdf0e10cSrcweir 				if ( eWhich == SC_SPLIT_TOPLEFT )
305cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMLEFT ), bScroll = sal_False, bDidSwitch = sal_True;
306cdf0e10cSrcweir 				else if ( eWhich == SC_SPLIT_TOPRIGHT )
307cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT ), bScroll = sal_False, bDidSwitch = sal_True;
308cdf0e10cSrcweir 			}
309cdf0e10cSrcweir 	}
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 	pViewData->ResetOldCursor();
312cdf0e10cSrcweir 	return SetCursorAtCell( nPosX, nPosY, bScroll );
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir sal_Bool ScViewFunctionSet::SetCursorAtCell( SCsCOL nPosX, SCsROW nPosY, sal_Bool bScroll )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 	ScTabView* pView = pViewData->GetView();
318cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
319cdf0e10cSrcweir     ScDocument* pDoc = pViewData->GetDocument();
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     if ( pDoc->IsTabProtected(nTab) )
322cdf0e10cSrcweir     {
323cdf0e10cSrcweir         if (nPosX < 0 || nPosY < 0)
324cdf0e10cSrcweir             return false;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir         ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
327cdf0e10cSrcweir         bool bSkipProtected   = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
328cdf0e10cSrcweir         bool bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
329cdf0e10cSrcweir 
330cdf0e10cSrcweir         if ( bSkipProtected && bSkipUnprotected )
331cdf0e10cSrcweir             return sal_False;
332cdf0e10cSrcweir 
333cdf0e10cSrcweir         bool bCellProtected = pDoc->HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HASATTR_PROTECTED);
334cdf0e10cSrcweir         if ( (bCellProtected && bSkipProtected) || (!bCellProtected && bSkipUnprotected) )
335cdf0e10cSrcweir             // Don't select this cell!
336cdf0e10cSrcweir             return sal_False;
337cdf0e10cSrcweir     }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
340cdf0e10cSrcweir     ScTabViewShell* pViewShell = pViewData->GetViewShell();
341cdf0e10cSrcweir     bool bRefMode = ( pViewShell ? pViewShell->IsRefInputMode() : false );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 	sal_Bool bHide = !bRefMode && !pViewData->IsAnyFillMode() &&
344cdf0e10cSrcweir 			( nPosX != (SCsCOL) pViewData->GetCurX() || nPosY != (SCsROW) pViewData->GetCurY() );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	if (bHide)
347cdf0e10cSrcweir 		pView->HideAllCursors();
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	if (bScroll)
350cdf0e10cSrcweir 	{
351cdf0e10cSrcweir 		if (bRefMode)
352cdf0e10cSrcweir 		{
353cdf0e10cSrcweir 			ScSplitPos eWhich = GetWhich();
354cdf0e10cSrcweir 			pView->AlignToCursor( nPosX, nPosY, SC_FOLLOW_LINE, &eWhich );
355cdf0e10cSrcweir 		}
356cdf0e10cSrcweir 		else
357cdf0e10cSrcweir 			pView->AlignToCursor( nPosX, nPosY, SC_FOLLOW_LINE );
358cdf0e10cSrcweir 	}
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	if (bRefMode)
361cdf0e10cSrcweir 	{
362cdf0e10cSrcweir 		// #90910# if no input is possible from this doc, don't move the reference cursor around
363cdf0e10cSrcweir 		if ( !pScMod->IsModalMode(pViewData->GetSfxDocShell()) )
364cdf0e10cSrcweir 		{
365cdf0e10cSrcweir 			if (!bAnchor)
366cdf0e10cSrcweir 			{
367cdf0e10cSrcweir 				pView->DoneRefMode( sal_True );
368cdf0e10cSrcweir 				pView->InitRefMode( nPosX, nPosY, pViewData->GetTabNo(), SC_REFTYPE_REF );
369cdf0e10cSrcweir 			}
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 			pView->UpdateRef( nPosX, nPosY, pViewData->GetTabNo() );
372cdf0e10cSrcweir 		}
373cdf0e10cSrcweir 	}
374cdf0e10cSrcweir 	else if (pViewData->IsFillMode() ||
375cdf0e10cSrcweir 			(pViewData->GetFillMode() == SC_FILL_MATRIX && (nScFillModeMouseModifier & KEY_MOD1) ))
376cdf0e10cSrcweir 	{
377cdf0e10cSrcweir 		//	Wenn eine Matrix angefasst wurde, kann mit Ctrl auf AutoFill zurueckgeschaltet werden
378cdf0e10cSrcweir 
379cdf0e10cSrcweir         SCCOL nStartX, nEndX;
380cdf0e10cSrcweir         SCROW nStartY, nEndY; // Block
381cdf0e10cSrcweir         SCTAB nDummy;
382cdf0e10cSrcweir 		pViewData->GetSimpleArea( nStartX, nStartY, nDummy, nEndX, nEndY, nDummy );
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 		if (pViewData->GetRefType() != SC_REFTYPE_FILL)
385cdf0e10cSrcweir 		{
386cdf0e10cSrcweir 			pView->InitRefMode( nStartX, nStartY, nTab, SC_REFTYPE_FILL );
387cdf0e10cSrcweir 			CreateAnchor();
388cdf0e10cSrcweir 		}
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 		ScRange aDelRange;
391cdf0e10cSrcweir 		sal_Bool bOldDelMark = pViewData->GetDelMark( aDelRange );
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 		if ( nPosX+1 >= (SCsCOL) nStartX && nPosX <= (SCsCOL) nEndX &&
394cdf0e10cSrcweir 			 nPosY+1 >= (SCsROW) nStartY && nPosY <= (SCsROW) nEndY &&
395cdf0e10cSrcweir 			 ( nPosX != nEndX || nPosY != nEndY ) )						// verkleinern ?
396cdf0e10cSrcweir 		{
397cdf0e10cSrcweir 			//	Richtung (links oder oben)
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 			long nSizeX = 0;
400cdf0e10cSrcweir 			for (SCCOL i=nPosX+1; i<=nEndX; i++)
401cdf0e10cSrcweir 				nSizeX += pDoc->GetColWidth( i, nTab );
402cdf0e10cSrcweir 			long nSizeY = (long) pDoc->GetRowHeight( nPosY+1, nEndY, nTab );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 			SCCOL nDelStartX = nStartX;
405cdf0e10cSrcweir 			SCROW nDelStartY = nStartY;
406cdf0e10cSrcweir 			if ( nSizeX > nSizeY )
407cdf0e10cSrcweir 				nDelStartX = nPosX + 1;
408cdf0e10cSrcweir 			else
409cdf0e10cSrcweir 				nDelStartY = nPosY + 1;
410cdf0e10cSrcweir 			// 0 braucht nicht mehr getrennt abgefragt zu werden, weil nPosX/Y auch negativ wird
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 			if ( nDelStartX < nStartX )
413cdf0e10cSrcweir 				nDelStartX = nStartX;
414cdf0e10cSrcweir 			if ( nDelStartY < nStartY )
415cdf0e10cSrcweir 				nDelStartY = nStartY;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 			//	Bereich setzen
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 			pViewData->SetDelMark( ScRange( nDelStartX,nDelStartY,nTab,
420cdf0e10cSrcweir 											nEndX,nEndY,nTab ) );
421cdf0e10cSrcweir             pViewData->GetView()->UpdateShrinkOverlay();
422cdf0e10cSrcweir 
423cdf0e10cSrcweir #if 0
424cdf0e10cSrcweir 			if ( bOldDelMark )
425cdf0e10cSrcweir 			{
426cdf0e10cSrcweir 				ScUpdateRect aRect( aDelRange.aStart.Col(), aDelRange.aStart.Row(),
427cdf0e10cSrcweir 									aDelRange.aEnd.Col(), aDelRange.aEnd.Row() );
428cdf0e10cSrcweir 				aRect.SetNew( nDelStartX,nDelStartY, nEndX,nEndY );
429cdf0e10cSrcweir 				SCCOL nPaintStartX;
430cdf0e10cSrcweir 				SCROW nPaintStartY;
431cdf0e10cSrcweir 				SCCOL nPaintEndX;
432cdf0e10cSrcweir 				SCROW nPaintEndY;
433cdf0e10cSrcweir 				if (aRect.GetDiff( nPaintStartX, nPaintStartY, nPaintEndX, nPaintEndY ))
434cdf0e10cSrcweir 					pViewData->GetView()->
435cdf0e10cSrcweir 						PaintArea( nPaintStartX, nPaintStartY,
436cdf0e10cSrcweir 									nPaintEndX, nPaintEndY, SC_UPDATE_MARKS );
437cdf0e10cSrcweir 			}
438cdf0e10cSrcweir 			else
439cdf0e10cSrcweir #endif
440cdf0e10cSrcweir 				pViewData->GetView()->
441cdf0e10cSrcweir 					PaintArea( nStartX,nDelStartY, nEndX,nEndY, SC_UPDATE_MARKS );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 			nPosX = nEndX;		// roten Rahmen um ganzen Bereich lassen
444cdf0e10cSrcweir 			nPosY = nEndY;
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 			//	Referenz wieder richtigherum, falls unten umgedreht
447cdf0e10cSrcweir 			if ( nStartX != pViewData->GetRefStartX() || nStartY != pViewData->GetRefStartY() )
448cdf0e10cSrcweir 			{
449cdf0e10cSrcweir 				pViewData->GetView()->DoneRefMode();
450cdf0e10cSrcweir 				pViewData->GetView()->InitRefMode( nStartX, nStartY, nTab, SC_REFTYPE_FILL );
451cdf0e10cSrcweir 			}
452cdf0e10cSrcweir 		}
453cdf0e10cSrcweir 		else
454cdf0e10cSrcweir 		{
455cdf0e10cSrcweir 			if ( bOldDelMark )
456cdf0e10cSrcweir 			{
457cdf0e10cSrcweir 				pViewData->ResetDelMark();
458cdf0e10cSrcweir                 pViewData->GetView()->UpdateShrinkOverlay();
459cdf0e10cSrcweir 
460cdf0e10cSrcweir #if 0
461cdf0e10cSrcweir 				pViewData->GetView()->
462cdf0e10cSrcweir 					PaintArea( aDelRange.aStart.Col(), aDelRange.aStart.Row(),
463cdf0e10cSrcweir 							   aDelRange.aEnd.Col(), aDelRange.aEnd.Row(), SC_UPDATE_MARKS );
464cdf0e10cSrcweir #endif
465cdf0e10cSrcweir 			}
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 			sal_Bool bNegX = ( nPosX < (SCsCOL) nStartX );
468cdf0e10cSrcweir 			sal_Bool bNegY = ( nPosY < (SCsROW) nStartY );
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 			long nSizeX = 0;
471cdf0e10cSrcweir 			if ( bNegX )
472cdf0e10cSrcweir 			{
473cdf0e10cSrcweir 				//	#94321# in SetCursorAtPoint hidden columns are skipped.
474cdf0e10cSrcweir 				//	They must be skipped here too, or the result will always be the first hidden column.
475cdf0e10cSrcweir 				do ++nPosX; while ( nPosX<nStartX && pDoc->ColHidden(nPosX, nTab) );
476cdf0e10cSrcweir 				for (SCCOL i=nPosX; i<nStartX; i++)
477cdf0e10cSrcweir 					nSizeX += pDoc->GetColWidth( i, nTab );
478cdf0e10cSrcweir 			}
479cdf0e10cSrcweir 			else
480cdf0e10cSrcweir 				for (SCCOL i=nEndX+1; i<=nPosX; i++)
481cdf0e10cSrcweir 					nSizeX += pDoc->GetColWidth( i, nTab );
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 			long nSizeY = 0;
484cdf0e10cSrcweir 			if ( bNegY )
485cdf0e10cSrcweir 			{
486cdf0e10cSrcweir 				//	#94321# in SetCursorAtPoint hidden rows are skipped.
487cdf0e10cSrcweir 				//	They must be skipped here too, or the result will always be the first hidden row.
488cdf0e10cSrcweir                 if (++nPosY < nStartY)
489cdf0e10cSrcweir                 {
490cdf0e10cSrcweir                     nPosY = pDoc->FirstVisibleRow(nPosY, nStartY-1, nTab);
491cdf0e10cSrcweir                     if (!ValidRow(nPosY))
492cdf0e10cSrcweir                         nPosY = nStartY;
493cdf0e10cSrcweir                 }
494cdf0e10cSrcweir                 nSizeY += pDoc->GetRowHeight( nPosY, nStartY-1, nTab );
495cdf0e10cSrcweir 			}
496cdf0e10cSrcweir 			else
497cdf0e10cSrcweir                 nSizeY += pDoc->GetRowHeight( nEndY+1, nPosY, nTab );
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 			if ( nSizeX > nSizeY )			// Fill immer nur in einer Richtung
500cdf0e10cSrcweir 			{
501cdf0e10cSrcweir 				nPosY = nEndY;
502cdf0e10cSrcweir 				bNegY = sal_False;
503cdf0e10cSrcweir 			}
504cdf0e10cSrcweir 			else
505cdf0e10cSrcweir 			{
506cdf0e10cSrcweir 				nPosX = nEndX;
507cdf0e10cSrcweir 				bNegX = sal_False;
508cdf0e10cSrcweir 			}
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 			SCCOL nRefStX = bNegX ? nEndX : nStartX;
511cdf0e10cSrcweir 			SCROW nRefStY = bNegY ? nEndY : nStartY;
512cdf0e10cSrcweir 			if ( nRefStX != pViewData->GetRefStartX() || nRefStY != pViewData->GetRefStartY() )
513cdf0e10cSrcweir 			{
514cdf0e10cSrcweir 				pViewData->GetView()->DoneRefMode();
515cdf0e10cSrcweir 				pViewData->GetView()->InitRefMode( nRefStX, nRefStY, nTab, SC_REFTYPE_FILL );
516cdf0e10cSrcweir 			}
517cdf0e10cSrcweir 		}
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 		pView->UpdateRef( nPosX, nPosY, nTab );
520cdf0e10cSrcweir 	}
521cdf0e10cSrcweir 	else if (pViewData->IsAnyFillMode())
522cdf0e10cSrcweir 	{
523cdf0e10cSrcweir 		sal_uInt8 nMode = pViewData->GetFillMode();
524cdf0e10cSrcweir 		if ( nMode == SC_FILL_EMBED_LT || nMode == SC_FILL_EMBED_RB )
525cdf0e10cSrcweir 		{
526cdf0e10cSrcweir 			DBG_ASSERT( pDoc->IsEmbedded(), "!pDoc->IsEmbedded()" );
527cdf0e10cSrcweir             ScRange aRange;
528cdf0e10cSrcweir 			pDoc->GetEmbedded( aRange);
529cdf0e10cSrcweir 			ScRefType eRefMode = (nMode == SC_FILL_EMBED_LT) ? SC_REFTYPE_EMBED_LT : SC_REFTYPE_EMBED_RB;
530cdf0e10cSrcweir 			if (pViewData->GetRefType() != eRefMode)
531cdf0e10cSrcweir 			{
532cdf0e10cSrcweir 				if ( nMode == SC_FILL_EMBED_LT )
533cdf0e10cSrcweir 					pView->InitRefMode( aRange.aEnd.Col(), aRange.aEnd.Row(), nTab, eRefMode );
534cdf0e10cSrcweir 				else
535cdf0e10cSrcweir 					pView->InitRefMode( aRange.aStart.Col(), aRange.aStart.Row(), nTab, eRefMode );
536cdf0e10cSrcweir 				CreateAnchor();
537cdf0e10cSrcweir 			}
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 			pView->UpdateRef( nPosX, nPosY, nTab );
540cdf0e10cSrcweir 		}
541cdf0e10cSrcweir 		else if ( nMode == SC_FILL_MATRIX )
542cdf0e10cSrcweir 		{
543cdf0e10cSrcweir             SCCOL nStartX, nEndX;
544cdf0e10cSrcweir             SCROW nStartY, nEndY; // Block
545cdf0e10cSrcweir             SCTAB nDummy;
546cdf0e10cSrcweir 			pViewData->GetSimpleArea( nStartX, nStartY, nDummy, nEndX, nEndY, nDummy );
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 			if (pViewData->GetRefType() != SC_REFTYPE_FILL)
549cdf0e10cSrcweir 			{
550cdf0e10cSrcweir 				pView->InitRefMode( nStartX, nStartY, nTab, SC_REFTYPE_FILL );
551cdf0e10cSrcweir 				CreateAnchor();
552cdf0e10cSrcweir 			}
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 			if ( nPosX < nStartX ) nPosX = nStartX;
555cdf0e10cSrcweir 			if ( nPosY < nStartY ) nPosY = nStartY;
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 			pView->UpdateRef( nPosX, nPosY, nTab );
558cdf0e10cSrcweir 		}
559cdf0e10cSrcweir 		// else neue Modi
560cdf0e10cSrcweir 	}
561cdf0e10cSrcweir 	else					// normales Markieren
562cdf0e10cSrcweir 	{
563cdf0e10cSrcweir 		sal_Bool bHideCur = bAnchor && ( (SCCOL)nPosX != pViewData->GetCurX() ||
564cdf0e10cSrcweir 									 (SCROW)nPosY != pViewData->GetCurY() );
565cdf0e10cSrcweir 		if (bHideCur)
566cdf0e10cSrcweir 			pView->HideAllCursors();			// sonst zweimal: Block und SetCursor
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 		if (bAnchor)
569cdf0e10cSrcweir 		{
570cdf0e10cSrcweir 			if (!bStarted)
571cdf0e10cSrcweir 			{
572cdf0e10cSrcweir 				sal_Bool bMove = ( nPosX != (SCsCOL) aAnchorPos.Col() ||
573cdf0e10cSrcweir 								nPosY != (SCsROW) aAnchorPos.Row() );
574cdf0e10cSrcweir 				if ( bMove || ( pEngine && pEngine->GetMouseEvent().IsShift() ) )
575cdf0e10cSrcweir 				{
576cdf0e10cSrcweir 					pView->InitBlockMode( aAnchorPos.Col(), aAnchorPos.Row(),
577cdf0e10cSrcweir 											aAnchorPos.Tab(), sal_True );
578cdf0e10cSrcweir 					bStarted = sal_True;
579cdf0e10cSrcweir 				}
580cdf0e10cSrcweir 			}
581cdf0e10cSrcweir 			if (bStarted)
582cdf0e10cSrcweir 				pView->MarkCursor( (SCCOL) nPosX, (SCROW) nPosY, nTab, sal_False, sal_False, sal_True );
583cdf0e10cSrcweir 		}
584cdf0e10cSrcweir 		else
585cdf0e10cSrcweir 		{
586cdf0e10cSrcweir 			ScMarkData& rMark = pViewData->GetMarkData();
587cdf0e10cSrcweir 			if (rMark.IsMarked() || rMark.IsMultiMarked())
588cdf0e10cSrcweir 			{
589cdf0e10cSrcweir 				pView->DoneBlockMode(sal_True);
590cdf0e10cSrcweir 				pView->InitBlockMode( nPosX, nPosY, nTab, sal_True );
591cdf0e10cSrcweir 				pView->MarkCursor( (SCCOL) nPosX, (SCROW) nPosY, nTab );
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 				aAnchorPos.Set( nPosX, nPosY, nTab );
594cdf0e10cSrcweir 				bStarted = sal_True;
595cdf0e10cSrcweir 			}
596cdf0e10cSrcweir 			// #i3875# *Hack* When a new cell is Ctrl-clicked with no pre-selected cells,
597cdf0e10cSrcweir 			// it highlights that new cell as well as the old cell where the cursor is
598cdf0e10cSrcweir 			// positioned prior to the click.  A selection mode via Shift-F8 should also
599cdf0e10cSrcweir 			// follow the same behavior.
600cdf0e10cSrcweir 			else if ( pViewData->IsSelCtrlMouseClick() )
601cdf0e10cSrcweir 			{
602cdf0e10cSrcweir 				SCCOL nOldX = pViewData->GetCurX();
603cdf0e10cSrcweir 				SCROW nOldY = pViewData->GetCurY();
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 				pView->InitBlockMode( nOldX, nOldY, nTab, sal_True );
606cdf0e10cSrcweir 				pView->MarkCursor( (SCCOL) nOldX, (SCROW) nOldY, nTab );
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 				if ( nOldX != nPosX || nOldY != nPosY )
609cdf0e10cSrcweir 				{
610cdf0e10cSrcweir 					pView->DoneBlockMode( sal_True );
611cdf0e10cSrcweir 					pView->InitBlockMode( nPosX, nPosY, nTab, sal_True );
612cdf0e10cSrcweir 					pView->MarkCursor( (SCCOL) nPosX, (SCROW) nPosY, nTab );
613cdf0e10cSrcweir 					aAnchorPos.Set( nPosX, nPosY, nTab );
614cdf0e10cSrcweir 				}
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 				bStarted = sal_True;
617cdf0e10cSrcweir 			}
618cdf0e10cSrcweir 		}
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 		pView->SetCursor( (SCCOL) nPosX, (SCROW) nPosY );
621cdf0e10cSrcweir 		pViewData->SetRefStart( nPosX, nPosY, nTab );
622cdf0e10cSrcweir 		if (bHideCur)
623cdf0e10cSrcweir 			pView->ShowAllCursors();
624cdf0e10cSrcweir 	}
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 	if (bHide)
627cdf0e10cSrcweir 		pView->ShowAllCursors();
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 	return sal_True;
630cdf0e10cSrcweir }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir sal_Bool __EXPORT ScViewFunctionSet::IsSelectionAtPoint( const Point& rPointPixel )
633cdf0e10cSrcweir {
634cdf0e10cSrcweir 	sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
635cdf0e10cSrcweir 	if (bRefMode)
636cdf0e10cSrcweir 		return sal_False;
637cdf0e10cSrcweir 
638cdf0e10cSrcweir 	if (pViewData->IsAnyFillMode())
639cdf0e10cSrcweir 		return sal_False;
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
642cdf0e10cSrcweir 	if (bAnchor || !rMark.IsMultiMarked())
643cdf0e10cSrcweir 	{
644cdf0e10cSrcweir 		SCsCOL	nPosX;
645cdf0e10cSrcweir 		SCsROW	nPosY;
646cdf0e10cSrcweir 		pViewData->GetPosFromPixel( rPointPixel.X(), rPointPixel.Y(), GetWhich(), nPosX, nPosY );
647cdf0e10cSrcweir 		return pViewData->GetMarkData().IsCellMarked( (SCCOL) nPosX, (SCROW) nPosY );
648cdf0e10cSrcweir 	}
649cdf0e10cSrcweir 
650cdf0e10cSrcweir 	return sal_False;
651cdf0e10cSrcweir }
652cdf0e10cSrcweir 
653cdf0e10cSrcweir void __EXPORT ScViewFunctionSet::DeselectAtPoint( const Point& /* rPointPixel */ )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir 	//	gibt's nicht
656cdf0e10cSrcweir }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir void __EXPORT ScViewFunctionSet::DeselectAll()
659cdf0e10cSrcweir {
660cdf0e10cSrcweir 	if (pViewData->IsAnyFillMode())
661cdf0e10cSrcweir 		return;
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 	sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
664cdf0e10cSrcweir 	if (bRefMode)
665cdf0e10cSrcweir 	{
666cdf0e10cSrcweir 		pViewData->GetView()->DoneRefMode( sal_False );
667cdf0e10cSrcweir 	}
668cdf0e10cSrcweir 	else
669cdf0e10cSrcweir 	{
670cdf0e10cSrcweir 		pViewData->GetView()->DoneBlockMode( sal_False );
671cdf0e10cSrcweir 		pViewData->GetViewShell()->UpdateInputHandler();
672cdf0e10cSrcweir 	}
673cdf0e10cSrcweir 
674cdf0e10cSrcweir 	bAnchor = sal_False;
675cdf0e10cSrcweir }
676cdf0e10cSrcweir 
677cdf0e10cSrcweir //------------------------------------------------------------------------
678cdf0e10cSrcweir 
679cdf0e10cSrcweir ScViewSelectionEngine::ScViewSelectionEngine( Window* pWindow, ScTabView* pView,
680cdf0e10cSrcweir 												ScSplitPos eSplitPos ) :
681cdf0e10cSrcweir 		SelectionEngine( pWindow, pView->GetFunctionSet() ),
682cdf0e10cSrcweir 		eWhich( eSplitPos )
683cdf0e10cSrcweir {
684cdf0e10cSrcweir 	//	Parameter einstellen
685cdf0e10cSrcweir 	SetSelectionMode( MULTIPLE_SELECTION );
686cdf0e10cSrcweir 	EnableDrag( sal_True );
687cdf0e10cSrcweir }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 
690cdf0e10cSrcweir //------------------------------------------------------------------------
691cdf0e10cSrcweir 
692cdf0e10cSrcweir //
693cdf0e10cSrcweir //					Spalten- / Zeilenheader
694cdf0e10cSrcweir //
695cdf0e10cSrcweir 
696cdf0e10cSrcweir ScHeaderFunctionSet::ScHeaderFunctionSet( ScViewData* pNewViewData ) :
697cdf0e10cSrcweir 		pViewData( pNewViewData ),
698cdf0e10cSrcweir 		bColumn( sal_False ),
699cdf0e10cSrcweir 		eWhich( SC_SPLIT_TOPLEFT ),
700cdf0e10cSrcweir 		bAnchor( sal_False ),
701cdf0e10cSrcweir 		nCursorPos( 0 )
702cdf0e10cSrcweir {
703cdf0e10cSrcweir 	DBG_ASSERT(pViewData, "ViewData==0 bei FunctionSet");
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir void ScHeaderFunctionSet::SetColumn( sal_Bool bSet )
707cdf0e10cSrcweir {
708cdf0e10cSrcweir 	bColumn = bSet;
709cdf0e10cSrcweir }
710cdf0e10cSrcweir 
711cdf0e10cSrcweir void ScHeaderFunctionSet::SetWhich( ScSplitPos eNew )
712cdf0e10cSrcweir {
713cdf0e10cSrcweir 	eWhich = eNew;
714cdf0e10cSrcweir }
715cdf0e10cSrcweir 
716cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::BeginDrag()
717cdf0e10cSrcweir {
718cdf0e10cSrcweir 	// gippsnich
719cdf0e10cSrcweir }
720cdf0e10cSrcweir 
721cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::CreateAnchor()
722cdf0e10cSrcweir {
723cdf0e10cSrcweir 	if (bAnchor)
724cdf0e10cSrcweir 		return;
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 	ScTabView* pView = pViewData->GetView();
727cdf0e10cSrcweir 	pView->DoneBlockMode( sal_True );
728cdf0e10cSrcweir 	if (bColumn)
729cdf0e10cSrcweir 	{
730cdf0e10cSrcweir 		pView->InitBlockMode( static_cast<SCCOL>(nCursorPos), 0, pViewData->GetTabNo(), sal_True, sal_True, sal_False );
731cdf0e10cSrcweir 		pView->MarkCursor( static_cast<SCCOL>(nCursorPos), MAXROW, pViewData->GetTabNo() );
732cdf0e10cSrcweir 	}
733cdf0e10cSrcweir 	else
734cdf0e10cSrcweir 	{
735cdf0e10cSrcweir 		pView->InitBlockMode( 0, nCursorPos, pViewData->GetTabNo(), sal_True, sal_False, sal_True );
736cdf0e10cSrcweir 		pView->MarkCursor( MAXCOL, nCursorPos, pViewData->GetTabNo() );
737cdf0e10cSrcweir 	}
738cdf0e10cSrcweir 	bAnchor = sal_True;
739cdf0e10cSrcweir }
740cdf0e10cSrcweir 
741cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::DestroyAnchor()
742cdf0e10cSrcweir {
743cdf0e10cSrcweir 	pViewData->GetView()->DoneBlockMode( sal_True );
744cdf0e10cSrcweir 	bAnchor = sal_False;
745cdf0e10cSrcweir }
746cdf0e10cSrcweir 
747cdf0e10cSrcweir sal_Bool __EXPORT ScHeaderFunctionSet::SetCursorAtPoint( const Point& rPointPixel, sal_Bool /* bDontSelectAtCursor */ )
748cdf0e10cSrcweir {
749cdf0e10cSrcweir 	if ( bDidSwitch )
750cdf0e10cSrcweir 	{
751cdf0e10cSrcweir 		//	die naechste gueltige Position muss vom anderen Fenster kommen
752cdf0e10cSrcweir 		if ( rPointPixel == aSwitchPos )
753cdf0e10cSrcweir 			return sal_False;					// nicht auf falschem Fenster scrollen
754cdf0e10cSrcweir 		else
755cdf0e10cSrcweir 			bDidSwitch = sal_False;
756cdf0e10cSrcweir 	}
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 	//	Scrolling
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 	Size aWinSize = pViewData->GetActiveWin()->GetOutputSizePixel();
761cdf0e10cSrcweir 	sal_Bool bScroll;
762cdf0e10cSrcweir 	if (bColumn)
763cdf0e10cSrcweir 		bScroll = ( rPointPixel.X() < 0 || rPointPixel.X() >= aWinSize.Width() );
764cdf0e10cSrcweir 	else
765cdf0e10cSrcweir 		bScroll = ( rPointPixel.Y() < 0 || rPointPixel.Y() >= aWinSize.Height() );
766cdf0e10cSrcweir 
767cdf0e10cSrcweir 	//	ueber Fixier-Grenze bewegt?
768cdf0e10cSrcweir 
769cdf0e10cSrcweir 	sal_Bool bSwitched = sal_False;
770cdf0e10cSrcweir 	if ( bColumn )
771cdf0e10cSrcweir 	{
772cdf0e10cSrcweir 		if ( pViewData->GetHSplitMode() == SC_SPLIT_FIX )
773cdf0e10cSrcweir 		{
774cdf0e10cSrcweir 			if ( rPointPixel.X() > aWinSize.Width() )
775cdf0e10cSrcweir 			{
776cdf0e10cSrcweir 				if ( eWhich == SC_SPLIT_TOPLEFT )
777cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_TOPRIGHT ), bSwitched = sal_True;
778cdf0e10cSrcweir 				else if ( eWhich == SC_SPLIT_BOTTOMLEFT )
779cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT ), bSwitched = sal_True;
780cdf0e10cSrcweir 			}
781cdf0e10cSrcweir 		}
782cdf0e10cSrcweir 	}
783cdf0e10cSrcweir 	else				// Zeilenkoepfe
784cdf0e10cSrcweir 	{
785cdf0e10cSrcweir 		if ( pViewData->GetVSplitMode() == SC_SPLIT_FIX )
786cdf0e10cSrcweir 		{
787cdf0e10cSrcweir 			if ( rPointPixel.Y() > aWinSize.Height() )
788cdf0e10cSrcweir 			{
789cdf0e10cSrcweir 				if ( eWhich == SC_SPLIT_TOPLEFT )
790cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMLEFT ), bSwitched = sal_True;
791cdf0e10cSrcweir 				else if ( eWhich == SC_SPLIT_TOPRIGHT )
792cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT ), bSwitched = sal_True;
793cdf0e10cSrcweir 			}
794cdf0e10cSrcweir 		}
795cdf0e10cSrcweir 	}
796cdf0e10cSrcweir 	if (bSwitched)
797cdf0e10cSrcweir 	{
798cdf0e10cSrcweir 		aSwitchPos = rPointPixel;
799cdf0e10cSrcweir 		bDidSwitch = sal_True;
800cdf0e10cSrcweir 		return sal_False;				// nicht mit falschen Positionen rechnen
801cdf0e10cSrcweir 	}
802cdf0e10cSrcweir 
803cdf0e10cSrcweir 	//
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 	SCsCOL	nPosX;
806cdf0e10cSrcweir 	SCsROW	nPosY;
807cdf0e10cSrcweir 	pViewData->GetPosFromPixel( rPointPixel.X(), rPointPixel.Y(), pViewData->GetActivePart(),
808cdf0e10cSrcweir 								nPosX, nPosY, sal_False );
809cdf0e10cSrcweir 	if (bColumn)
810cdf0e10cSrcweir 	{
811cdf0e10cSrcweir 		nCursorPos = static_cast<SCCOLROW>(nPosX);
812cdf0e10cSrcweir 		nPosY = pViewData->GetPosY(WhichV(pViewData->GetActivePart()));
813cdf0e10cSrcweir 	}
814cdf0e10cSrcweir 	else
815cdf0e10cSrcweir 	{
816cdf0e10cSrcweir 		nCursorPos = static_cast<SCCOLROW>(nPosY);
817cdf0e10cSrcweir 		nPosX = pViewData->GetPosX(WhichH(pViewData->GetActivePart()));
818cdf0e10cSrcweir 	}
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 	ScTabView* pView = pViewData->GetView();
821cdf0e10cSrcweir 	sal_Bool bHide = pViewData->GetCurX() != nPosX ||
822cdf0e10cSrcweir 				 pViewData->GetCurY() != nPosY;
823cdf0e10cSrcweir 	if (bHide)
824cdf0e10cSrcweir 		pView->HideAllCursors();
825cdf0e10cSrcweir 
826cdf0e10cSrcweir 	if (bScroll)
827cdf0e10cSrcweir 		pView->AlignToCursor( nPosX, nPosY, SC_FOLLOW_LINE );
828cdf0e10cSrcweir 	pView->SetCursor( nPosX, nPosY );
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 	if ( !bAnchor || !pView->IsBlockMode() )
831cdf0e10cSrcweir 	{
832cdf0e10cSrcweir 		pView->DoneBlockMode( sal_True );
833cdf0e10cSrcweir 		pViewData->GetMarkData().MarkToMulti();			//! wer verstellt das ???
834cdf0e10cSrcweir 		pView->InitBlockMode( nPosX, nPosY, pViewData->GetTabNo(), sal_True, bColumn, !bColumn );
835cdf0e10cSrcweir 
836cdf0e10cSrcweir 		bAnchor = sal_True;
837cdf0e10cSrcweir 	}
838cdf0e10cSrcweir 
839cdf0e10cSrcweir 	pView->MarkCursor( nPosX, nPosY, pViewData->GetTabNo(), bColumn, !bColumn );
840cdf0e10cSrcweir 
841cdf0e10cSrcweir 	//	SelectionChanged innerhalb von HideCursor wegen UpdateAutoFillMark
842cdf0e10cSrcweir 	pView->SelectionChanged();
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 	if (bHide)
845cdf0e10cSrcweir 		pView->ShowAllCursors();
846cdf0e10cSrcweir 
847cdf0e10cSrcweir 	return sal_True;
848cdf0e10cSrcweir }
849cdf0e10cSrcweir 
850cdf0e10cSrcweir sal_Bool __EXPORT ScHeaderFunctionSet::IsSelectionAtPoint( const Point& rPointPixel )
851cdf0e10cSrcweir {
852cdf0e10cSrcweir 	SCsCOL	nPosX;
853cdf0e10cSrcweir 	SCsROW	nPosY;
854cdf0e10cSrcweir 	pViewData->GetPosFromPixel( rPointPixel.X(), rPointPixel.Y(), pViewData->GetActivePart(),
855cdf0e10cSrcweir 								nPosX, nPosY, sal_False );
856cdf0e10cSrcweir 
857cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
858cdf0e10cSrcweir 	if (bColumn)
859cdf0e10cSrcweir 		return rMark.IsColumnMarked( nPosX );
860cdf0e10cSrcweir 	else
861cdf0e10cSrcweir 		return rMark.IsRowMarked( nPosY );
862cdf0e10cSrcweir }
863cdf0e10cSrcweir 
864cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::DeselectAtPoint( const Point& /* rPointPixel */ )
865cdf0e10cSrcweir {
866cdf0e10cSrcweir }
867cdf0e10cSrcweir 
868cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::DeselectAll()
869cdf0e10cSrcweir {
870cdf0e10cSrcweir 	pViewData->GetView()->DoneBlockMode( sal_False );
871cdf0e10cSrcweir 	bAnchor = sal_False;
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
874cdf0e10cSrcweir //------------------------------------------------------------------------
875cdf0e10cSrcweir 
876cdf0e10cSrcweir ScHeaderSelectionEngine::ScHeaderSelectionEngine( Window* pWindow, ScHeaderFunctionSet* pFuncSet ) :
877cdf0e10cSrcweir 		SelectionEngine( pWindow, pFuncSet )
878cdf0e10cSrcweir {
879cdf0e10cSrcweir 	//	Parameter einstellen
880cdf0e10cSrcweir 	SetSelectionMode( MULTIPLE_SELECTION );
881cdf0e10cSrcweir 	EnableDrag( sal_False );
882cdf0e10cSrcweir }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 
888