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