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