xref: /aoo41x/main/sc/source/ui/view/select.cxx (revision 0deba7fb)
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 <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() );
372*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
373*0deba7fbSSteve Yin 			pView->SelectionChanged();
374*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
375cdf0e10cSrcweir 		}
376cdf0e10cSrcweir 	}
377cdf0e10cSrcweir 	else if (pViewData->IsFillMode() ||
378cdf0e10cSrcweir 			(pViewData->GetFillMode() == SC_FILL_MATRIX && (nScFillModeMouseModifier & KEY_MOD1) ))
379cdf0e10cSrcweir 	{
380cdf0e10cSrcweir 		//	Wenn eine Matrix angefasst wurde, kann mit Ctrl auf AutoFill zurueckgeschaltet werden
381cdf0e10cSrcweir 
382cdf0e10cSrcweir         SCCOL nStartX, nEndX;
383cdf0e10cSrcweir         SCROW nStartY, nEndY; // Block
384cdf0e10cSrcweir         SCTAB nDummy;
385cdf0e10cSrcweir 		pViewData->GetSimpleArea( nStartX, nStartY, nDummy, nEndX, nEndY, nDummy );
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 		if (pViewData->GetRefType() != SC_REFTYPE_FILL)
388cdf0e10cSrcweir 		{
389cdf0e10cSrcweir 			pView->InitRefMode( nStartX, nStartY, nTab, SC_REFTYPE_FILL );
390cdf0e10cSrcweir 			CreateAnchor();
391cdf0e10cSrcweir 		}
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 		ScRange aDelRange;
394cdf0e10cSrcweir 		sal_Bool bOldDelMark = pViewData->GetDelMark( aDelRange );
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 		if ( nPosX+1 >= (SCsCOL) nStartX && nPosX <= (SCsCOL) nEndX &&
397cdf0e10cSrcweir 			 nPosY+1 >= (SCsROW) nStartY && nPosY <= (SCsROW) nEndY &&
398cdf0e10cSrcweir 			 ( nPosX != nEndX || nPosY != nEndY ) )						// verkleinern ?
399cdf0e10cSrcweir 		{
400cdf0e10cSrcweir 			//	Richtung (links oder oben)
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 			long nSizeX = 0;
403cdf0e10cSrcweir 			for (SCCOL i=nPosX+1; i<=nEndX; i++)
404cdf0e10cSrcweir 				nSizeX += pDoc->GetColWidth( i, nTab );
405cdf0e10cSrcweir 			long nSizeY = (long) pDoc->GetRowHeight( nPosY+1, nEndY, nTab );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 			SCCOL nDelStartX = nStartX;
408cdf0e10cSrcweir 			SCROW nDelStartY = nStartY;
409cdf0e10cSrcweir 			if ( nSizeX > nSizeY )
410cdf0e10cSrcweir 				nDelStartX = nPosX + 1;
411cdf0e10cSrcweir 			else
412cdf0e10cSrcweir 				nDelStartY = nPosY + 1;
413cdf0e10cSrcweir 			// 0 braucht nicht mehr getrennt abgefragt zu werden, weil nPosX/Y auch negativ wird
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 			if ( nDelStartX < nStartX )
416cdf0e10cSrcweir 				nDelStartX = nStartX;
417cdf0e10cSrcweir 			if ( nDelStartY < nStartY )
418cdf0e10cSrcweir 				nDelStartY = nStartY;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 			//	Bereich setzen
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 			pViewData->SetDelMark( ScRange( nDelStartX,nDelStartY,nTab,
423cdf0e10cSrcweir 											nEndX,nEndY,nTab ) );
424cdf0e10cSrcweir             pViewData->GetView()->UpdateShrinkOverlay();
425cdf0e10cSrcweir 
426cdf0e10cSrcweir #if 0
427cdf0e10cSrcweir 			if ( bOldDelMark )
428cdf0e10cSrcweir 			{
429cdf0e10cSrcweir 				ScUpdateRect aRect( aDelRange.aStart.Col(), aDelRange.aStart.Row(),
430cdf0e10cSrcweir 									aDelRange.aEnd.Col(), aDelRange.aEnd.Row() );
431cdf0e10cSrcweir 				aRect.SetNew( nDelStartX,nDelStartY, nEndX,nEndY );
432cdf0e10cSrcweir 				SCCOL nPaintStartX;
433cdf0e10cSrcweir 				SCROW nPaintStartY;
434cdf0e10cSrcweir 				SCCOL nPaintEndX;
435cdf0e10cSrcweir 				SCROW nPaintEndY;
436cdf0e10cSrcweir 				if (aRect.GetDiff( nPaintStartX, nPaintStartY, nPaintEndX, nPaintEndY ))
437cdf0e10cSrcweir 					pViewData->GetView()->
438cdf0e10cSrcweir 						PaintArea( nPaintStartX, nPaintStartY,
439cdf0e10cSrcweir 									nPaintEndX, nPaintEndY, SC_UPDATE_MARKS );
440cdf0e10cSrcweir 			}
441cdf0e10cSrcweir 			else
442cdf0e10cSrcweir #endif
443cdf0e10cSrcweir 				pViewData->GetView()->
444cdf0e10cSrcweir 					PaintArea( nStartX,nDelStartY, nEndX,nEndY, SC_UPDATE_MARKS );
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 			nPosX = nEndX;		// roten Rahmen um ganzen Bereich lassen
447cdf0e10cSrcweir 			nPosY = nEndY;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 			//	Referenz wieder richtigherum, falls unten umgedreht
450cdf0e10cSrcweir 			if ( nStartX != pViewData->GetRefStartX() || nStartY != pViewData->GetRefStartY() )
451cdf0e10cSrcweir 			{
452cdf0e10cSrcweir 				pViewData->GetView()->DoneRefMode();
453cdf0e10cSrcweir 				pViewData->GetView()->InitRefMode( nStartX, nStartY, nTab, SC_REFTYPE_FILL );
454cdf0e10cSrcweir 			}
455cdf0e10cSrcweir 		}
456cdf0e10cSrcweir 		else
457cdf0e10cSrcweir 		{
458cdf0e10cSrcweir 			if ( bOldDelMark )
459cdf0e10cSrcweir 			{
460cdf0e10cSrcweir 				pViewData->ResetDelMark();
461cdf0e10cSrcweir                 pViewData->GetView()->UpdateShrinkOverlay();
462cdf0e10cSrcweir 
463cdf0e10cSrcweir #if 0
464cdf0e10cSrcweir 				pViewData->GetView()->
465cdf0e10cSrcweir 					PaintArea( aDelRange.aStart.Col(), aDelRange.aStart.Row(),
466cdf0e10cSrcweir 							   aDelRange.aEnd.Col(), aDelRange.aEnd.Row(), SC_UPDATE_MARKS );
467cdf0e10cSrcweir #endif
468cdf0e10cSrcweir 			}
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 			sal_Bool bNegX = ( nPosX < (SCsCOL) nStartX );
471cdf0e10cSrcweir 			sal_Bool bNegY = ( nPosY < (SCsROW) nStartY );
472cdf0e10cSrcweir 
473cdf0e10cSrcweir 			long nSizeX = 0;
474cdf0e10cSrcweir 			if ( bNegX )
475cdf0e10cSrcweir 			{
476cdf0e10cSrcweir 				//	#94321# in SetCursorAtPoint hidden columns are skipped.
477cdf0e10cSrcweir 				//	They must be skipped here too, or the result will always be the first hidden column.
478cdf0e10cSrcweir 				do ++nPosX; while ( nPosX<nStartX && pDoc->ColHidden(nPosX, nTab) );
479cdf0e10cSrcweir 				for (SCCOL i=nPosX; i<nStartX; i++)
480cdf0e10cSrcweir 					nSizeX += pDoc->GetColWidth( i, nTab );
481cdf0e10cSrcweir 			}
482cdf0e10cSrcweir 			else
483cdf0e10cSrcweir 				for (SCCOL i=nEndX+1; i<=nPosX; i++)
484cdf0e10cSrcweir 					nSizeX += pDoc->GetColWidth( i, nTab );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 			long nSizeY = 0;
487cdf0e10cSrcweir 			if ( bNegY )
488cdf0e10cSrcweir 			{
489cdf0e10cSrcweir 				//	#94321# in SetCursorAtPoint hidden rows are skipped.
490cdf0e10cSrcweir 				//	They must be skipped here too, or the result will always be the first hidden row.
491cdf0e10cSrcweir                 if (++nPosY < nStartY)
492cdf0e10cSrcweir                 {
493cdf0e10cSrcweir                     nPosY = pDoc->FirstVisibleRow(nPosY, nStartY-1, nTab);
494cdf0e10cSrcweir                     if (!ValidRow(nPosY))
495cdf0e10cSrcweir                         nPosY = nStartY;
496cdf0e10cSrcweir                 }
497cdf0e10cSrcweir                 nSizeY += pDoc->GetRowHeight( nPosY, nStartY-1, nTab );
498cdf0e10cSrcweir 			}
499cdf0e10cSrcweir 			else
500cdf0e10cSrcweir                 nSizeY += pDoc->GetRowHeight( nEndY+1, nPosY, nTab );
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 			if ( nSizeX > nSizeY )			// Fill immer nur in einer Richtung
503cdf0e10cSrcweir 			{
504cdf0e10cSrcweir 				nPosY = nEndY;
505cdf0e10cSrcweir 				bNegY = sal_False;
506cdf0e10cSrcweir 			}
507cdf0e10cSrcweir 			else
508cdf0e10cSrcweir 			{
509cdf0e10cSrcweir 				nPosX = nEndX;
510cdf0e10cSrcweir 				bNegX = sal_False;
511cdf0e10cSrcweir 			}
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 			SCCOL nRefStX = bNegX ? nEndX : nStartX;
514cdf0e10cSrcweir 			SCROW nRefStY = bNegY ? nEndY : nStartY;
515cdf0e10cSrcweir 			if ( nRefStX != pViewData->GetRefStartX() || nRefStY != pViewData->GetRefStartY() )
516cdf0e10cSrcweir 			{
517cdf0e10cSrcweir 				pViewData->GetView()->DoneRefMode();
518cdf0e10cSrcweir 				pViewData->GetView()->InitRefMode( nRefStX, nRefStY, nTab, SC_REFTYPE_FILL );
519cdf0e10cSrcweir 			}
520cdf0e10cSrcweir 		}
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 		pView->UpdateRef( nPosX, nPosY, nTab );
523cdf0e10cSrcweir 	}
524cdf0e10cSrcweir 	else if (pViewData->IsAnyFillMode())
525cdf0e10cSrcweir 	{
526cdf0e10cSrcweir 		sal_uInt8 nMode = pViewData->GetFillMode();
527cdf0e10cSrcweir 		if ( nMode == SC_FILL_EMBED_LT || nMode == SC_FILL_EMBED_RB )
528cdf0e10cSrcweir 		{
529cdf0e10cSrcweir 			DBG_ASSERT( pDoc->IsEmbedded(), "!pDoc->IsEmbedded()" );
530cdf0e10cSrcweir             ScRange aRange;
531cdf0e10cSrcweir 			pDoc->GetEmbedded( aRange);
532cdf0e10cSrcweir 			ScRefType eRefMode = (nMode == SC_FILL_EMBED_LT) ? SC_REFTYPE_EMBED_LT : SC_REFTYPE_EMBED_RB;
533cdf0e10cSrcweir 			if (pViewData->GetRefType() != eRefMode)
534cdf0e10cSrcweir 			{
535cdf0e10cSrcweir 				if ( nMode == SC_FILL_EMBED_LT )
536cdf0e10cSrcweir 					pView->InitRefMode( aRange.aEnd.Col(), aRange.aEnd.Row(), nTab, eRefMode );
537cdf0e10cSrcweir 				else
538cdf0e10cSrcweir 					pView->InitRefMode( aRange.aStart.Col(), aRange.aStart.Row(), nTab, eRefMode );
539cdf0e10cSrcweir 				CreateAnchor();
540cdf0e10cSrcweir 			}
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 			pView->UpdateRef( nPosX, nPosY, nTab );
543cdf0e10cSrcweir 		}
544cdf0e10cSrcweir 		else if ( nMode == SC_FILL_MATRIX )
545cdf0e10cSrcweir 		{
546cdf0e10cSrcweir             SCCOL nStartX, nEndX;
547cdf0e10cSrcweir             SCROW nStartY, nEndY; // Block
548cdf0e10cSrcweir             SCTAB nDummy;
549cdf0e10cSrcweir 			pViewData->GetSimpleArea( nStartX, nStartY, nDummy, nEndX, nEndY, nDummy );
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 			if (pViewData->GetRefType() != SC_REFTYPE_FILL)
552cdf0e10cSrcweir 			{
553cdf0e10cSrcweir 				pView->InitRefMode( nStartX, nStartY, nTab, SC_REFTYPE_FILL );
554cdf0e10cSrcweir 				CreateAnchor();
555cdf0e10cSrcweir 			}
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 			if ( nPosX < nStartX ) nPosX = nStartX;
558cdf0e10cSrcweir 			if ( nPosY < nStartY ) nPosY = nStartY;
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 			pView->UpdateRef( nPosX, nPosY, nTab );
561cdf0e10cSrcweir 		}
562cdf0e10cSrcweir 		// else neue Modi
563cdf0e10cSrcweir 	}
564cdf0e10cSrcweir 	else					// normales Markieren
565cdf0e10cSrcweir 	{
566cdf0e10cSrcweir 		sal_Bool bHideCur = bAnchor && ( (SCCOL)nPosX != pViewData->GetCurX() ||
567cdf0e10cSrcweir 									 (SCROW)nPosY != pViewData->GetCurY() );
568cdf0e10cSrcweir 		if (bHideCur)
569cdf0e10cSrcweir 			pView->HideAllCursors();			// sonst zweimal: Block und SetCursor
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 		if (bAnchor)
572cdf0e10cSrcweir 		{
573cdf0e10cSrcweir 			if (!bStarted)
574cdf0e10cSrcweir 			{
575cdf0e10cSrcweir 				sal_Bool bMove = ( nPosX != (SCsCOL) aAnchorPos.Col() ||
576cdf0e10cSrcweir 								nPosY != (SCsROW) aAnchorPos.Row() );
577cdf0e10cSrcweir 				if ( bMove || ( pEngine && pEngine->GetMouseEvent().IsShift() ) )
578cdf0e10cSrcweir 				{
579cdf0e10cSrcweir 					pView->InitBlockMode( aAnchorPos.Col(), aAnchorPos.Row(),
580cdf0e10cSrcweir 											aAnchorPos.Tab(), sal_True );
581cdf0e10cSrcweir 					bStarted = sal_True;
582cdf0e10cSrcweir 				}
583cdf0e10cSrcweir 			}
584cdf0e10cSrcweir 			if (bStarted)
585cdf0e10cSrcweir 				pView->MarkCursor( (SCCOL) nPosX, (SCROW) nPosY, nTab, sal_False, sal_False, sal_True );
586cdf0e10cSrcweir 		}
587cdf0e10cSrcweir 		else
588cdf0e10cSrcweir 		{
589cdf0e10cSrcweir 			ScMarkData& rMark = pViewData->GetMarkData();
590cdf0e10cSrcweir 			if (rMark.IsMarked() || rMark.IsMultiMarked())
591cdf0e10cSrcweir 			{
592cdf0e10cSrcweir 				pView->DoneBlockMode(sal_True);
593cdf0e10cSrcweir 				pView->InitBlockMode( nPosX, nPosY, nTab, sal_True );
594cdf0e10cSrcweir 				pView->MarkCursor( (SCCOL) nPosX, (SCROW) nPosY, nTab );
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 				aAnchorPos.Set( nPosX, nPosY, nTab );
597cdf0e10cSrcweir 				bStarted = sal_True;
598cdf0e10cSrcweir 			}
599cdf0e10cSrcweir 			// #i3875# *Hack* When a new cell is Ctrl-clicked with no pre-selected cells,
600cdf0e10cSrcweir 			// it highlights that new cell as well as the old cell where the cursor is
601cdf0e10cSrcweir 			// positioned prior to the click.  A selection mode via Shift-F8 should also
602cdf0e10cSrcweir 			// follow the same behavior.
603cdf0e10cSrcweir 			else if ( pViewData->IsSelCtrlMouseClick() )
604cdf0e10cSrcweir 			{
605cdf0e10cSrcweir 				SCCOL nOldX = pViewData->GetCurX();
606cdf0e10cSrcweir 				SCROW nOldY = pViewData->GetCurY();
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 				pView->InitBlockMode( nOldX, nOldY, nTab, sal_True );
609cdf0e10cSrcweir 				pView->MarkCursor( (SCCOL) nOldX, (SCROW) nOldY, nTab );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 				if ( nOldX != nPosX || nOldY != nPosY )
612cdf0e10cSrcweir 				{
613cdf0e10cSrcweir 					pView->DoneBlockMode( sal_True );
614cdf0e10cSrcweir 					pView->InitBlockMode( nPosX, nPosY, nTab, sal_True );
615cdf0e10cSrcweir 					pView->MarkCursor( (SCCOL) nPosX, (SCROW) nPosY, nTab );
616cdf0e10cSrcweir 					aAnchorPos.Set( nPosX, nPosY, nTab );
617cdf0e10cSrcweir 				}
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 				bStarted = sal_True;
620cdf0e10cSrcweir 			}
621cdf0e10cSrcweir 		}
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 		pView->SetCursor( (SCCOL) nPosX, (SCROW) nPosY );
624cdf0e10cSrcweir 		pViewData->SetRefStart( nPosX, nPosY, nTab );
625cdf0e10cSrcweir 		if (bHideCur)
626cdf0e10cSrcweir 			pView->ShowAllCursors();
627cdf0e10cSrcweir 	}
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 	if (bHide)
630cdf0e10cSrcweir 		pView->ShowAllCursors();
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 	return sal_True;
633cdf0e10cSrcweir }
634cdf0e10cSrcweir 
635cdf0e10cSrcweir sal_Bool __EXPORT ScViewFunctionSet::IsSelectionAtPoint( const Point& rPointPixel )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir 	sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
638cdf0e10cSrcweir 	if (bRefMode)
639cdf0e10cSrcweir 		return sal_False;
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 	if (pViewData->IsAnyFillMode())
642cdf0e10cSrcweir 		return sal_False;
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
645cdf0e10cSrcweir 	if (bAnchor || !rMark.IsMultiMarked())
646cdf0e10cSrcweir 	{
647cdf0e10cSrcweir 		SCsCOL	nPosX;
648cdf0e10cSrcweir 		SCsROW	nPosY;
649cdf0e10cSrcweir 		pViewData->GetPosFromPixel( rPointPixel.X(), rPointPixel.Y(), GetWhich(), nPosX, nPosY );
650cdf0e10cSrcweir 		return pViewData->GetMarkData().IsCellMarked( (SCCOL) nPosX, (SCROW) nPosY );
651cdf0e10cSrcweir 	}
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 	return sal_False;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir void __EXPORT ScViewFunctionSet::DeselectAtPoint( const Point& /* rPointPixel */ )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir 	//	gibt's nicht
659cdf0e10cSrcweir }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir void __EXPORT ScViewFunctionSet::DeselectAll()
662cdf0e10cSrcweir {
663cdf0e10cSrcweir 	if (pViewData->IsAnyFillMode())
664cdf0e10cSrcweir 		return;
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 	sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
667cdf0e10cSrcweir 	if (bRefMode)
668cdf0e10cSrcweir 	{
669cdf0e10cSrcweir 		pViewData->GetView()->DoneRefMode( sal_False );
670cdf0e10cSrcweir 	}
671cdf0e10cSrcweir 	else
672cdf0e10cSrcweir 	{
673cdf0e10cSrcweir 		pViewData->GetView()->DoneBlockMode( sal_False );
674cdf0e10cSrcweir 		pViewData->GetViewShell()->UpdateInputHandler();
675cdf0e10cSrcweir 	}
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 	bAnchor = sal_False;
678cdf0e10cSrcweir }
679cdf0e10cSrcweir 
680cdf0e10cSrcweir //------------------------------------------------------------------------
681cdf0e10cSrcweir 
682cdf0e10cSrcweir ScViewSelectionEngine::ScViewSelectionEngine( Window* pWindow, ScTabView* pView,
683cdf0e10cSrcweir 												ScSplitPos eSplitPos ) :
684cdf0e10cSrcweir 		SelectionEngine( pWindow, pView->GetFunctionSet() ),
685cdf0e10cSrcweir 		eWhich( eSplitPos )
686cdf0e10cSrcweir {
687cdf0e10cSrcweir 	//	Parameter einstellen
688cdf0e10cSrcweir 	SetSelectionMode( MULTIPLE_SELECTION );
689cdf0e10cSrcweir 	EnableDrag( sal_True );
690cdf0e10cSrcweir }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir 
693cdf0e10cSrcweir //------------------------------------------------------------------------
694cdf0e10cSrcweir 
695cdf0e10cSrcweir //
696cdf0e10cSrcweir //					Spalten- / Zeilenheader
697cdf0e10cSrcweir //
698cdf0e10cSrcweir 
699cdf0e10cSrcweir ScHeaderFunctionSet::ScHeaderFunctionSet( ScViewData* pNewViewData ) :
700cdf0e10cSrcweir 		pViewData( pNewViewData ),
701cdf0e10cSrcweir 		bColumn( sal_False ),
702cdf0e10cSrcweir 		eWhich( SC_SPLIT_TOPLEFT ),
703cdf0e10cSrcweir 		bAnchor( sal_False ),
704cdf0e10cSrcweir 		nCursorPos( 0 )
705cdf0e10cSrcweir {
706cdf0e10cSrcweir 	DBG_ASSERT(pViewData, "ViewData==0 bei FunctionSet");
707cdf0e10cSrcweir }
708cdf0e10cSrcweir 
709cdf0e10cSrcweir void ScHeaderFunctionSet::SetColumn( sal_Bool bSet )
710cdf0e10cSrcweir {
711cdf0e10cSrcweir 	bColumn = bSet;
712cdf0e10cSrcweir }
713cdf0e10cSrcweir 
714cdf0e10cSrcweir void ScHeaderFunctionSet::SetWhich( ScSplitPos eNew )
715cdf0e10cSrcweir {
716cdf0e10cSrcweir 	eWhich = eNew;
717cdf0e10cSrcweir }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::BeginDrag()
720cdf0e10cSrcweir {
721cdf0e10cSrcweir 	// gippsnich
722cdf0e10cSrcweir }
723cdf0e10cSrcweir 
724cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::CreateAnchor()
725cdf0e10cSrcweir {
726cdf0e10cSrcweir 	if (bAnchor)
727cdf0e10cSrcweir 		return;
728cdf0e10cSrcweir 
729cdf0e10cSrcweir 	ScTabView* pView = pViewData->GetView();
730cdf0e10cSrcweir 	pView->DoneBlockMode( sal_True );
731cdf0e10cSrcweir 	if (bColumn)
732cdf0e10cSrcweir 	{
733cdf0e10cSrcweir 		pView->InitBlockMode( static_cast<SCCOL>(nCursorPos), 0, pViewData->GetTabNo(), sal_True, sal_True, sal_False );
734cdf0e10cSrcweir 		pView->MarkCursor( static_cast<SCCOL>(nCursorPos), MAXROW, pViewData->GetTabNo() );
735cdf0e10cSrcweir 	}
736cdf0e10cSrcweir 	else
737cdf0e10cSrcweir 	{
738cdf0e10cSrcweir 		pView->InitBlockMode( 0, nCursorPos, pViewData->GetTabNo(), sal_True, sal_False, sal_True );
739cdf0e10cSrcweir 		pView->MarkCursor( MAXCOL, nCursorPos, pViewData->GetTabNo() );
740cdf0e10cSrcweir 	}
741cdf0e10cSrcweir 	bAnchor = sal_True;
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
744cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::DestroyAnchor()
745cdf0e10cSrcweir {
746cdf0e10cSrcweir 	pViewData->GetView()->DoneBlockMode( sal_True );
747cdf0e10cSrcweir 	bAnchor = sal_False;
748cdf0e10cSrcweir }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir sal_Bool __EXPORT ScHeaderFunctionSet::SetCursorAtPoint( const Point& rPointPixel, sal_Bool /* bDontSelectAtCursor */ )
751cdf0e10cSrcweir {
752cdf0e10cSrcweir 	if ( bDidSwitch )
753cdf0e10cSrcweir 	{
754cdf0e10cSrcweir 		//	die naechste gueltige Position muss vom anderen Fenster kommen
755cdf0e10cSrcweir 		if ( rPointPixel == aSwitchPos )
756cdf0e10cSrcweir 			return sal_False;					// nicht auf falschem Fenster scrollen
757cdf0e10cSrcweir 		else
758cdf0e10cSrcweir 			bDidSwitch = sal_False;
759cdf0e10cSrcweir 	}
760cdf0e10cSrcweir 
761cdf0e10cSrcweir 	//	Scrolling
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 	Size aWinSize = pViewData->GetActiveWin()->GetOutputSizePixel();
764cdf0e10cSrcweir 	sal_Bool bScroll;
765cdf0e10cSrcweir 	if (bColumn)
766cdf0e10cSrcweir 		bScroll = ( rPointPixel.X() < 0 || rPointPixel.X() >= aWinSize.Width() );
767cdf0e10cSrcweir 	else
768cdf0e10cSrcweir 		bScroll = ( rPointPixel.Y() < 0 || rPointPixel.Y() >= aWinSize.Height() );
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 	//	ueber Fixier-Grenze bewegt?
771cdf0e10cSrcweir 
772cdf0e10cSrcweir 	sal_Bool bSwitched = sal_False;
773cdf0e10cSrcweir 	if ( bColumn )
774cdf0e10cSrcweir 	{
775cdf0e10cSrcweir 		if ( pViewData->GetHSplitMode() == SC_SPLIT_FIX )
776cdf0e10cSrcweir 		{
777cdf0e10cSrcweir 			if ( rPointPixel.X() > aWinSize.Width() )
778cdf0e10cSrcweir 			{
779cdf0e10cSrcweir 				if ( eWhich == SC_SPLIT_TOPLEFT )
780cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_TOPRIGHT ), bSwitched = sal_True;
781cdf0e10cSrcweir 				else if ( eWhich == SC_SPLIT_BOTTOMLEFT )
782cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT ), bSwitched = sal_True;
783cdf0e10cSrcweir 			}
784cdf0e10cSrcweir 		}
785cdf0e10cSrcweir 	}
786cdf0e10cSrcweir 	else				// Zeilenkoepfe
787cdf0e10cSrcweir 	{
788cdf0e10cSrcweir 		if ( pViewData->GetVSplitMode() == SC_SPLIT_FIX )
789cdf0e10cSrcweir 		{
790cdf0e10cSrcweir 			if ( rPointPixel.Y() > aWinSize.Height() )
791cdf0e10cSrcweir 			{
792cdf0e10cSrcweir 				if ( eWhich == SC_SPLIT_TOPLEFT )
793cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMLEFT ), bSwitched = sal_True;
794cdf0e10cSrcweir 				else if ( eWhich == SC_SPLIT_TOPRIGHT )
795cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT ), bSwitched = sal_True;
796cdf0e10cSrcweir 			}
797cdf0e10cSrcweir 		}
798cdf0e10cSrcweir 	}
799cdf0e10cSrcweir 	if (bSwitched)
800cdf0e10cSrcweir 	{
801cdf0e10cSrcweir 		aSwitchPos = rPointPixel;
802cdf0e10cSrcweir 		bDidSwitch = sal_True;
803cdf0e10cSrcweir 		return sal_False;				// nicht mit falschen Positionen rechnen
804cdf0e10cSrcweir 	}
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 	//
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 	SCsCOL	nPosX;
809cdf0e10cSrcweir 	SCsROW	nPosY;
810cdf0e10cSrcweir 	pViewData->GetPosFromPixel( rPointPixel.X(), rPointPixel.Y(), pViewData->GetActivePart(),
811cdf0e10cSrcweir 								nPosX, nPosY, sal_False );
812cdf0e10cSrcweir 	if (bColumn)
813cdf0e10cSrcweir 	{
814cdf0e10cSrcweir 		nCursorPos = static_cast<SCCOLROW>(nPosX);
815cdf0e10cSrcweir 		nPosY = pViewData->GetPosY(WhichV(pViewData->GetActivePart()));
816cdf0e10cSrcweir 	}
817cdf0e10cSrcweir 	else
818cdf0e10cSrcweir 	{
819cdf0e10cSrcweir 		nCursorPos = static_cast<SCCOLROW>(nPosY);
820cdf0e10cSrcweir 		nPosX = pViewData->GetPosX(WhichH(pViewData->GetActivePart()));
821cdf0e10cSrcweir 	}
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 	ScTabView* pView = pViewData->GetView();
824cdf0e10cSrcweir 	sal_Bool bHide = pViewData->GetCurX() != nPosX ||
825cdf0e10cSrcweir 				 pViewData->GetCurY() != nPosY;
826cdf0e10cSrcweir 	if (bHide)
827cdf0e10cSrcweir 		pView->HideAllCursors();
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 	if (bScroll)
830cdf0e10cSrcweir 		pView->AlignToCursor( nPosX, nPosY, SC_FOLLOW_LINE );
831cdf0e10cSrcweir 	pView->SetCursor( nPosX, nPosY );
832cdf0e10cSrcweir 
833cdf0e10cSrcweir 	if ( !bAnchor || !pView->IsBlockMode() )
834cdf0e10cSrcweir 	{
835cdf0e10cSrcweir 		pView->DoneBlockMode( sal_True );
836cdf0e10cSrcweir 		pViewData->GetMarkData().MarkToMulti();			//! wer verstellt das ???
837cdf0e10cSrcweir 		pView->InitBlockMode( nPosX, nPosY, pViewData->GetTabNo(), sal_True, bColumn, !bColumn );
838cdf0e10cSrcweir 
839cdf0e10cSrcweir 		bAnchor = sal_True;
840cdf0e10cSrcweir 	}
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 	pView->MarkCursor( nPosX, nPosY, pViewData->GetTabNo(), bColumn, !bColumn );
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 	//	SelectionChanged innerhalb von HideCursor wegen UpdateAutoFillMark
845cdf0e10cSrcweir 	pView->SelectionChanged();
846cdf0e10cSrcweir 
847cdf0e10cSrcweir 	if (bHide)
848cdf0e10cSrcweir 		pView->ShowAllCursors();
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 	return sal_True;
851cdf0e10cSrcweir }
852cdf0e10cSrcweir 
853cdf0e10cSrcweir sal_Bool __EXPORT ScHeaderFunctionSet::IsSelectionAtPoint( const Point& rPointPixel )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir 	SCsCOL	nPosX;
856cdf0e10cSrcweir 	SCsROW	nPosY;
857cdf0e10cSrcweir 	pViewData->GetPosFromPixel( rPointPixel.X(), rPointPixel.Y(), pViewData->GetActivePart(),
858cdf0e10cSrcweir 								nPosX, nPosY, sal_False );
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
861cdf0e10cSrcweir 	if (bColumn)
862cdf0e10cSrcweir 		return rMark.IsColumnMarked( nPosX );
863cdf0e10cSrcweir 	else
864cdf0e10cSrcweir 		return rMark.IsRowMarked( nPosY );
865cdf0e10cSrcweir }
866cdf0e10cSrcweir 
867cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::DeselectAtPoint( const Point& /* rPointPixel */ )
868cdf0e10cSrcweir {
869cdf0e10cSrcweir }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir void __EXPORT ScHeaderFunctionSet::DeselectAll()
872cdf0e10cSrcweir {
873cdf0e10cSrcweir 	pViewData->GetView()->DoneBlockMode( sal_False );
874cdf0e10cSrcweir 	bAnchor = sal_False;
875cdf0e10cSrcweir }
876cdf0e10cSrcweir 
877cdf0e10cSrcweir //------------------------------------------------------------------------
878cdf0e10cSrcweir 
879cdf0e10cSrcweir ScHeaderSelectionEngine::ScHeaderSelectionEngine( Window* pWindow, ScHeaderFunctionSet* pFuncSet ) :
880cdf0e10cSrcweir 		SelectionEngine( pWindow, pFuncSet )
881cdf0e10cSrcweir {
882cdf0e10cSrcweir 	//	Parameter einstellen
883cdf0e10cSrcweir 	SetSelectionMode( MULTIPLE_SELECTION );
884cdf0e10cSrcweir 	EnableDrag( sal_False );
885cdf0e10cSrcweir }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 
891