xref: /aoo41x/main/sc/source/ui/view/drawview.cxx (revision 0deba7fb)
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 // INCLUDE ---------------------------------------------------------------
28 
29 #include <com/sun/star/embed/EmbedStates.hpp>
30 
31 #include <svx/svditer.hxx>
32 #include <svx/svdograf.hxx>
33 #include <svx/svdomedia.hxx>
34 #include <svx/svdogrp.hxx>
35 #include <svx/svdoole2.hxx>
36 #include <svx/svdouno.hxx>
37 #include <svx/svdpage.hxx>
38 #include <svx/svdundo.hxx>
39 #include <svx/svdocapt.hxx>
40 #include <editeng/outlobj.hxx>
41 #include <editeng/writingmodeitem.hxx>
42 #include <svx/sdrpaintwindow.hxx>
43 #include <sfx2/bindings.hxx>
44 #include <sfx2/viewfrm.hxx>
45 #include <svx/sdrundomanager.hxx>
46 
47 #include "drawview.hxx"
48 #include "global.hxx"
49 #include "viewdata.hxx"
50 #include "document.hxx"
51 #include "drawutil.hxx"
52 #include "futext.hxx"
53 #include "globstr.hrc"
54 #include "tabvwsh.hxx"
55 #include "client.hxx"
56 #include "scmod.hxx"
57 #include "drwlayer.hxx"
58 #include "docsh.hxx"
59 #include "viewuno.hxx"
60 #include "userdat.hxx"
61 #include "postit.hxx"
62 #include "undocell.hxx"
63 #include "document.hxx"
64 
65 #include "sc.hrc"
66 
67 using namespace com::sun::star;
68 
69 // -----------------------------------------------------------------------
70 
71 #define SC_HANDLESIZE_BIG		9
72 #define SC_HANDLESIZE_SMALL		7
73 
74 // -----------------------------------------------------------------------
75 
76 #ifdef _MSC_VER
77 #pragma optimize ( "", off )
78 #endif
79 
80 
81 void ScDrawView::Construct()
82 {
83 	EnableExtendedKeyInputDispatcher(sal_False);
84 	EnableExtendedMouseEventDispatcher(sal_False);
85 	EnableExtendedCommandEventDispatcher(sal_False);
86 
87 	SetFrameDragSingles(sal_True);
88 //	SetSolidMarkHdl(sal_True);				// einstellbar -> UpdateUserViewOptions
89 
90 	SetMinMoveDistancePixel( 2 );
91 	SetHitTolerancePixel( 2 );
92 
93 	if (pViewData)
94 	{
95 		SCTAB nViewTab = pViewData->GetTabNo();
96 		ShowSdrPage(GetModel()->GetPage(nViewTab));
97 
98 		sal_Bool bEx = pViewData->GetViewShell()->IsDrawSelMode();
99 		sal_Bool bProt = pDoc->IsTabProtected( nViewTab ) ||
100 					 pViewData->GetSfxDocShell()->IsReadOnly();
101 
102 		SdrLayer* pLayer;
103 		SdrLayerAdmin& rAdmin = GetModel()->GetLayerAdmin();
104 		pLayer = rAdmin.GetLayerPerID(SC_LAYER_BACK);
105 		if (pLayer)
106 			SetLayerLocked( pLayer->GetName(), bProt || !bEx );
107 		pLayer = rAdmin.GetLayerPerID(SC_LAYER_INTERN);
108 		if (pLayer)
109 			SetLayerLocked( pLayer->GetName(), sal_True );
110 		pLayer = rAdmin.GetLayerPerID(SC_LAYER_FRONT);
111 		if (pLayer)
112 		{
113 			SetLayerLocked( pLayer->GetName(), bProt );
114 			SetActiveLayer( pLayer->GetName() );		// FRONT als aktiven Layer setzen
115 		}
116 		pLayer = rAdmin.GetLayerPerID(SC_LAYER_CONTROLS);
117 		if (pLayer)
118 			SetLayerLocked( pLayer->GetName(), bProt );
119         pLayer = rAdmin.GetLayerPerID(SC_LAYER_HIDDEN);
120         if (pLayer)
121         {
122             SetLayerLocked( pLayer->GetName(), bProt );
123             SetLayerVisible( pLayer->GetName(), sal_False);
124         }
125 
126 		SetSwapAsynchron(sal_True);
127 	}
128 	else
129 	{
130 		ShowSdrPage(GetModel()->GetPage(nTab));
131 	}
132 
133 	UpdateUserViewOptions();
134 	RecalcScale();
135 	UpdateWorkArea();
136 
137 	bInConstruct = sal_False;
138 }
139 
140 void ScDrawView::ImplClearCalcDropMarker()
141 {
142 	if(pDropMarker)
143 	{
144 		delete pDropMarker;
145 		pDropMarker = 0L;
146 	}
147 }
148 
149 __EXPORT ScDrawView::~ScDrawView()
150 {
151 	ImplClearCalcDropMarker();
152 }
153 
154 void ScDrawView::AddCustomHdl()
155 {
156 	sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
157 
158 	const SdrMarkList &rMrkList = GetMarkedObjectList();
159 	sal_uInt32 nCount = rMrkList.GetMarkCount();
160 	for(sal_uInt32 nPos=0; nPos<nCount; nPos++ )
161 	{
162 		const SdrObject* pObj = rMrkList.GetMark(nPos)->GetMarkedSdrObj();
163 		if(ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
164 		{
165 			const sal_Int32 nDelta = 1;
166 
167 			Rectangle aBoundRect = pObj->GetCurrentBoundRect();
168 			Point aPos;
169 			if (bNegativePage)
170 			{
171 				aPos = aBoundRect.TopRight();
172 				aPos.X() = -aPos.X();			// so the loop below is the same
173 			}
174 			else
175 				aPos = aBoundRect.TopLeft();
176 			long nPosX = (long) (aPos.X() / HMM_PER_TWIPS) + nDelta;
177 			long nPosY = (long) (aPos.Y() / HMM_PER_TWIPS) + nDelta;
178 
179 			SCCOL nCol;
180 			sal_Int32 nWidth = 0;
181 
182 			for(nCol=0; nCol<=MAXCOL && nWidth<=nPosX; nCol++)
183 				nWidth += pDoc->GetColWidth(nCol,nTab);
184 
185 			if(nCol > 0)
186 				--nCol;
187 
188             SCROW nRow = nPosY <= 0 ? 0 : pDoc->GetRowForHeight( nTab,
189                     (sal_uLong) nPosY);
190 			if(nRow > 0)
191 				--nRow;
192 
193 			ScTabView* pView = pViewData->GetView();
194 			ScAddress aScAddress(nCol, nRow, nTab);
195 			pView->CreateAnchorHandles(aHdl, aScAddress);
196 		}
197 	}
198 }
199 
200 void ScDrawView::InvalidateAttribs()
201 {
202 	if (!pViewData) return;
203 	SfxBindings& rBindings = pViewData->GetBindings();
204 
205 		// echte Statuswerte:
206 	rBindings.InvalidateAll( sal_True );
207 }
208 
209 void ScDrawView::InvalidateDrawTextAttrs()
210 {
211 	if (!pViewData) return;
212 	SfxBindings& rBindings = pViewData->GetBindings();
213 
214 	//	cjk/ctl font items have no configured slots,
215 	//	need no invalidate
216 
217 	rBindings.Invalidate( SID_ATTR_CHAR_FONT );
218 	rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
219 	rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
220 	rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
221 	rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
222 	rBindings.Invalidate( SID_ULINE_VAL_NONE );
223 	rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
224 	rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
225 	rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
226 	rBindings.Invalidate( SID_ATTR_CHAR_OVERLINE );
227 	rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
228 	rBindings.Invalidate( SID_ATTR_PARA_ADJUST_LEFT );
229 	rBindings.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT );
230 	rBindings.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK );
231 	rBindings.Invalidate( SID_ATTR_PARA_ADJUST_CENTER);
232 	rBindings.Invalidate( SID_ALIGNLEFT );
233 	rBindings.Invalidate( SID_ALIGNCENTERHOR );
234 	rBindings.Invalidate( SID_ALIGNRIGHT );
235 	rBindings.Invalidate( SID_ALIGNBLOCK );
236 	rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_10 );
237 	rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_15 );
238 	rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_20 );
239 	rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
240 	rBindings.Invalidate( SID_SET_SUB_SCRIPT );
241 	rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
242 	rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
243 	rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
244 	rBindings.Invalidate( SID_TEXTDIRECTION_LEFT_TO_RIGHT );
245 	rBindings.Invalidate( SID_TEXTDIRECTION_TOP_TO_BOTTOM );
246 	rBindings.Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
247 	rBindings.Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
248     // pseudo slots for Format menu
249     rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
250     rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
251     rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
252     rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
253 }
254 
255 //void ScDrawView::DrawMarks( OutputDevice* pOut ) const
256 //{
257 //	DBG_ASSERT(pOut, "ScDrawView::DrawMarks: No OutputDevice (!)");
258 //	SdrPaintWindow* pPaintWindow = FindPaintWindow(*pOut);
259 //
260 //	if(pPaintWindow)
261 //	{
262 //		if(pPaintWindow->isXorVisible())
263 //		{
264 //			ToggleShownXor(pOut, 0L);
265 //		}
266 //	}
267 //}
268 
269 void ScDrawView::SetMarkedToLayer( sal_uInt8 nLayerNo )
270 {
271 	if (AreObjectsMarked())
272 	{
273 		//	#i11702# use SdrUndoObjectLayerChange for undo
274 		//	STR_UNDO_SELATTR is "Attributes" - should use a different text later
275 		BegUndo( ScGlobal::GetRscString( STR_UNDO_SELATTR ) );
276 
277 		const SdrMarkList& rMark = GetMarkedObjectList();
278 		sal_uLong nCount = rMark.GetMarkCount();
279 		for (sal_uLong i=0; i<nCount; i++)
280 		{
281 			SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
282 			if ( !pObj->ISA(SdrUnoObj) && (pObj->GetLayer() != SC_LAYER_INTERN) )
283 			{
284 				AddUndo( new SdrUndoObjectLayerChange( *pObj, pObj->GetLayer(), (SdrLayerID)nLayerNo) );
285 				pObj->SetLayer( nLayerNo );
286 			}
287 		}
288 
289 		EndUndo();
290 
291 		//	repaint is done in SetLayer
292 
293 		pViewData->GetDocShell()->SetDrawModified();
294 
295 		//	#84073# check mark list now instead of later in a timer
296 		CheckMarked();
297 		MarkListHasChanged();
298 	}
299 }
300 
301 bool ScDrawView::HasMarkedControl() const
302 {
303     SdrObjListIter aIter( GetMarkedObjectList() );
304     for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
305         if( pObj->ISA( SdrUnoObj ) )
306             return true;
307 	return false;
308 }
309 
310 bool ScDrawView::HasMarkedInternal() const
311 {
312     // internal objects should not be inside a group, but who knows...
313     SdrObjListIter aIter( GetMarkedObjectList() );
314     for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
315         if( pObj->GetLayer() == SC_LAYER_INTERN )
316             return true;
317 	return false;
318 }
319 
320 void ScDrawView::UpdateWorkArea()
321 {
322 	SdrPage* pPage = GetModel()->GetPage(static_cast<sal_uInt16>(nTab));
323 	if (pPage)
324 	{
325 		Point aPos;
326 		Size aPageSize( pPage->GetSize() );
327 		Rectangle aNewArea( aPos, aPageSize );
328 		if ( aPageSize.Width() < 0 )
329 		{
330 			//	RTL: from max.negative (left) to zero (right)
331 			aNewArea.Right() = 0;
332 			aNewArea.Left() = aPageSize.Width() + 1;
333 		}
334 		SetWorkArea( aNewArea );
335 	}
336 	else
337 	{
338 		DBG_ERROR("Page nicht gefunden");
339 	}
340 }
341 
342 void ScDrawView::DoCut()
343 {
344 	DoCopy();
345 	BegUndo( ScGlobal::GetRscString( STR_UNDO_CUT ) );
346 	DeleteMarked();		// auf dieser View - von der 505f Umstellung nicht betroffen
347 	EndUndo();
348 }
349 
350 void ScDrawView::GetScale( Fraction& rFractX, Fraction& rFractY ) const
351 {
352 	rFractX = aScaleX;
353 	rFractY = aScaleY;
354 }
355 
356 void ScDrawView::RecalcScale()
357 {
358 	double nPPTX;
359 	double nPPTY;
360 	Fraction aZoomX(1,1);
361 	Fraction aZoomY(1,1);
362 
363 	if (pViewData)
364 	{
365 		nTab = pViewData->GetTabNo();
366 		nPPTX = pViewData->GetPPTX();
367 		nPPTY = pViewData->GetPPTY();
368 		aZoomX = pViewData->GetZoomX();
369 		aZoomY = pViewData->GetZoomY();
370 	}
371 	else
372 	{
373 		Point aLogic = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
374 		nPPTX = aLogic.X() / 1000.0;
375 		nPPTY = aLogic.Y() / 1000.0;
376 											//! Zoom uebergeben ???
377 	}
378 
379 	SCCOL nEndCol = 0;
380 	SCROW nEndRow = 0;
381 	pDoc->GetTableArea( nTab, nEndCol, nEndRow );
382 	if (nEndCol<20)
383 		nEndCol = 20;
384 	if (nEndRow<20)
385         nEndRow = 20;   // #i116848# instead of a large row number for an empty sheet, heights are multiplied in CalcScale
386 
387 	ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, pDev,aZoomX,aZoomY,nPPTX,nPPTY,
388 							aScaleX,aScaleY );
389 }
390 
391 void ScDrawView::DoConnect(SdrOle2Obj* pOleObj)
392 {
393     if ( pViewData )
394         pViewData->GetViewShell()->ConnectObject( pOleObj );
395 }
396 
397 void ScDrawView::MarkListHasChanged()
398 {
399 	FmFormView::MarkListHasChanged();
400 
401 	UpdateBrowser();
402 
403 	ScTabViewShell* pViewSh = pViewData->GetViewShell();
404 
405     // #i110829# remove the cell selection only if drawing objects are selected
406     if ( !bInConstruct && GetMarkedObjectList().GetMarkCount() )
407 	{
408         pViewSh->Unmark();      // remove cell selection
409 
410 		//	#65379# end cell edit mode if drawing objects are selected
411         SC_MOD()->InputEnterHandler();
412 	}
413 
414 	//	IP deaktivieren
415 
416     ScModule* pScMod = SC_MOD();
417     bool bUnoRefDialog = pScMod->IsRefDialogOpen() && pScMod->GetCurRefDlgId() == WID_SIMPLE_REF;
418 
419 	ScClient* pClient = (ScClient*) pViewSh->GetIPClient();
420     if ( pClient && pClient->IsObjectInPlaceActive() && !bUnoRefDialog )
421 	{
422 		//	#41730# beim ViewShell::Activate aus dem Reset2Open nicht die Handles anzeigen
423 		//HMHbDisableHdl = sal_True;
424         pClient->DeactivateObject();
425 		//HMHbDisableHdl = sal_False;
426 		//	Image-Ole wieder durch Grafik ersetzen passiert jetzt in ScClient::UIActivate
427 	}
428 
429 	//	Ole-Objekt selektiert?
430 
431 	SdrOle2Obj* pOle2Obj = NULL;
432 	SdrGrafObj* pGrafObj = NULL;
433 	SdrMediaObj* pMediaObj = NULL;
434 
435 	const SdrMarkList& rMarkList = GetMarkedObjectList();
436 	sal_uLong nMarkCount = rMarkList.GetMarkCount();
437 
438 	if ( nMarkCount == 0 && !pViewData->GetViewShell()->IsDrawSelMode() && !bInConstruct )
439 	{
440 		//	relock layers that may have been unlocked before
441         LockBackgroundLayer();
442         LockInternalLayer();
443 	}
444 
445 	sal_Bool bSubShellSet = sal_False;
446 	if (nMarkCount == 1)
447 	{
448 		SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
449 		if (pObj->GetObjIdentifier() == OBJ_OLE2)
450 		{
451 			pOle2Obj = (SdrOle2Obj*) pObj;
452 			if (!pDoc->IsChart(pObj) )
453 				pViewSh->SetOleObjectShell(sal_True);
454 			else
455 				pViewSh->SetChartShell(sal_True);
456 			bSubShellSet = sal_True;
457 		}
458 		else if (pObj->GetObjIdentifier() == OBJ_GRAF)
459 		{
460 			pGrafObj = (SdrGrafObj*) pObj;
461 			pViewSh->SetGraphicShell(sal_True);
462 			bSubShellSet = sal_True;
463 		}
464 		else if (pObj->GetObjIdentifier() == OBJ_MEDIA)
465 		{
466 			pMediaObj = (SdrMediaObj*) pObj;
467 			pViewSh->SetMediaShell(sal_True);
468 			bSubShellSet = sal_True;
469 		}
470 		else if (pObj->GetObjIdentifier() != OBJ_TEXT   // Verhindern, das beim Anlegen
471 					|| !pViewSh->IsDrawTextShell())		// eines TextObjekts auf die
472 		{												// DrawShell umgeschaltet wird.
473 			pViewSh->SetDrawShell(sal_True);				//@#70206#
474 		}
475 	}
476 
477 	if ( nMarkCount && !bSubShellSet )
478 	{
479 		sal_Bool bOnlyControls = sal_True;
480 		sal_Bool bOnlyGraf     = sal_True;
481 		for (sal_uLong i=0; i<nMarkCount; i++)
482 		{
483 			SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
484 			if ( pObj->ISA( SdrObjGroup ) )
485 			{
486 				const SdrObjList *pLst = ((SdrObjGroup*)pObj)->GetSubList();
487 				sal_uLong nListCount = pLst->GetObjCount();
488 				if ( nListCount == 0 )
489 				{
490 					//	#104156# An empty group (may occur during Undo) is no control or graphics object.
491 					//	Creating the form shell during undo would lead to problems with the undo manager.
492 					bOnlyControls = sal_False;
493 					bOnlyGraf = sal_False;
494 				}
495 				for ( sal_uInt16 j = 0; j < nListCount; ++j )
496 				{
497 					SdrObject *pSubObj = pLst->GetObj( j );
498 
499 					if (!pSubObj->ISA(SdrUnoObj))
500 						bOnlyControls = sal_False;
501 					if (pSubObj->GetObjIdentifier() != OBJ_GRAF)
502 						bOnlyGraf = sal_False;
503 
504 					if ( !bOnlyControls && !bOnlyGraf ) break;
505 				}
506 			}
507 			else
508 			{
509 				if (!pObj->ISA(SdrUnoObj))
510 					bOnlyControls = sal_False;
511 				if (pObj->GetObjIdentifier() != OBJ_GRAF)
512 					bOnlyGraf = sal_False;
513 			}
514 
515 			if ( !bOnlyControls && !bOnlyGraf ) break;
516 		}
517 
518 		if(bOnlyControls)
519 		{
520 			pViewSh->SetDrawFormShell(sal_True);			// jetzt UNO-Controls
521 		}
522 		else if(bOnlyGraf)
523 		{
524 			pViewSh->SetGraphicShell(sal_True);
525 		}
526 		else if(nMarkCount>1)
527 		{
528 			pViewSh->SetDrawShell(sal_True);
529 		}
530 	}
531 
532 
533 
534 	//	Verben anpassen
535 
536 	SfxViewFrame* pViewFrame = pViewSh->GetViewFrame();
537     sal_Bool bOle = pViewSh->GetViewFrame()->GetFrame().IsInPlace();
538     uno::Sequence< embed::VerbDescriptor > aVerbs;
539 	if ( pOle2Obj && !bOle )
540 	{
541         uno::Reference < embed::XEmbeddedObject > xObj = pOle2Obj->GetObjRef();
542 		DBG_ASSERT( xObj.is(), "SdrOle2Obj ohne ObjRef" );
543         if (xObj.is())
544             aVerbs = xObj->getSupportedVerbs();
545 	}
546 	pViewSh->SetVerbs( aVerbs );
547 
548 	//	Image-Map Editor
549 
550 	if ( pOle2Obj )
551 		UpdateIMap( pOle2Obj );
552 	else if ( pGrafObj )
553 		UpdateIMap( pGrafObj );
554 
555 	InvalidateAttribs();				// nach dem IMap-Editor Update
556 	InvalidateDrawTextAttrs();
557 
558 	for(sal_uInt32 a(0L); a < PaintWindowCount(); a++)
559 	{
560 		SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
561 		OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
562 
563 		if(OUTDEV_WINDOW == rOutDev.GetOutDevType())
564 		{
565 			((Window&)rOutDev).Update();
566 		}
567 	}
568 
569 	//	uno object for view returns drawing objects as selection,
570 	//	so it must notify its SelectionChangeListeners
571 
572 	if (pViewFrame)
573 	{
574 		SfxFrame& rFrame = pViewFrame->GetFrame();
575 		uno::Reference<frame::XController> xController = rFrame.GetController();
576 		if (xController.is())
577 		{
578 			ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController );
579 			if (pImp)
580 				pImp->SelectionChanged();
581 		}
582 	}
583 
584 	//	update selection transfer object
585 
586 	pViewSh->CheckSelectionTransfer();
587 
588 }
589 
590 sal_Bool ScDrawView::SdrBeginTextEdit(
591     SdrObject* pObj,
592     SdrPageView* pPV,
593     ::Window* pWinL,
594     sal_Bool bIsNewObj,
595     SdrOutliner* pGivenOutliner,
596     OutlinerView* pGivenOutlinerView,
597     sal_Bool bDontDeleteOutliner,
598     sal_Bool bOnlyOneView,
599     sal_Bool bGrabFocus )
600 {
601     const sal_Bool bRet = FmFormView::SdrBeginTextEdit(
602         pObj, pPV, pWinL, bIsNewObj,
603         pGivenOutliner, pGivenOutlinerView, bDontDeleteOutliner,
604         bOnlyOneView, bGrabFocus );
605 
606     ScTabViewShell* pViewSh = pViewData->GetViewShell();
607     if ( pViewSh->GetViewFrame() )
608     {
609         SfxFrame& rFrame = pViewSh->GetViewFrame()->GetFrame();
610         uno::Reference< frame::XController > xController = rFrame.GetController();
611         if (xController.is())
612         {
613             ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController );
614             if (pImp)
615                 pImp->SelectionChanged();
616         }
617     }
618 
619     return bRet;
620 }
621 
622 
623 SdrEndTextEditKind ScDrawView::SdrEndTextEdit( sal_Bool bDontDeleteReally )
624 {
625     const SdrEndTextEditKind eRet = FmFormView::SdrEndTextEdit( bDontDeleteReally );
626 
627     ScTabViewShell* pViewSh = pViewData->GetViewShell();
628     if ( pViewSh->GetViewFrame() )
629     {
630         SfxFrame& rFrame = pViewSh->GetViewFrame()->GetFrame();
631         uno::Reference< frame::XController > xController = rFrame.GetController();
632         if (xController.is())
633         {
634             ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController );
635             if (pImp)
636                 pImp->SelectionChanged();
637         }
638     }
639 
640     return eRet;
641 }
642 
643 
644 void __EXPORT ScDrawView::ModelHasChanged()
645 {
646 	SdrObject* pEditObj = GetTextEditObject();
647 	if ( pEditObj && !pEditObj->IsInserted() && pViewData )
648 	{
649 		//	#111700# SdrObjEditView::ModelHasChanged will end text edit in this case,
650 		//	so make sure the EditEngine's undo manager is no longer used.
651 		pViewData->GetViewShell()->SetDrawTextUndo(NULL);
652 		SetCreateMode();	// don't leave FuText in a funny state
653 	}
654 
655 	FmFormView::ModelHasChanged();
656 }
657 
658 void __EXPORT ScDrawView::UpdateUserViewOptions()
659 {
660 	if (pViewData)
661 	{
662 		const ScViewOptions&	rOpt = pViewData->GetOptions();
663 		const ScGridOptions&	rGrid = rOpt.GetGridOptions();
664 
665 		sal_Bool bBigHdl = rOpt.GetOption( VOPT_BIGHANDLES );
666 
667 		SetDragStripes( rOpt.GetOption( VOPT_HELPLINES ) );
668 		SetSolidMarkHdl( rOpt.GetOption( VOPT_SOLIDHANDLES ) );
669 		SetMarkHdlSizePixel( bBigHdl ? SC_HANDLESIZE_BIG : SC_HANDLESIZE_SMALL );
670 
671 		SetGridVisible( rGrid.GetGridVisible() );
672 		SetSnapEnabled( rGrid.GetUseGridSnap() );
673 		SetGridSnap( rGrid.GetUseGridSnap() );
674 
675 		//	Snap from grid options is no longer used
676 //		SetSnapGrid( Size( rGrid.GetFldSnapX(), rGrid.GetFldSnapY() ) );
677 
678 		Fraction aFractX( rGrid.GetFldDrawX(), rGrid.GetFldDivisionX() + 1 );
679 		Fraction aFractY( rGrid.GetFldDrawY(), rGrid.GetFldDivisionY() + 1 );
680 		SetSnapGridWidth( aFractX, aFractY );
681 
682 		SetGridCoarse( Size( rGrid.GetFldDrawX(), rGrid.GetFldDrawY() ) );
683 		SetGridFine( Size( rGrid.GetFldDrawX() / (rGrid.GetFldDivisionX() + 1),
684 						   rGrid.GetFldDrawY() / (rGrid.GetFldDivisionY() + 1) ) );
685 	}
686 }
687 
688 #ifdef _MSC_VER
689 #pragma optimize ( "", on )
690 #endif
691 
692 //IAccessibility2 Implementation 2009-----
693 SdrObject* ScDrawView::GetObjectByName(const String& rName)
694 {
695 	SfxObjectShell*	pShell = pDoc->GetDocumentShell();
696 	if (pShell)
697 	{
698 		SdrModel* pDrawLayer = GetModel();
699 		sal_uInt16 nTabCount = pDoc->GetTableCount();
700 		for (sal_uInt16 i=0; i<nTabCount; i++)
701 		{
702 			SdrPage* pPage = pDrawLayer->GetPage(i);
703 			DBG_ASSERT(pPage,"Page ?");
704 			if (pPage)
705 			{
706 				SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
707 				SdrObject* pObject = aIter.Next();
708 				while (pObject)
709 				{
710 					if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
711 					{
712 						return pObject;
713 					}
714 					pObject = aIter.Next();
715 				}
716 			}
717 		}
718 	}
719 	return 0;
720 }
721 //Solution: realize multi-selection of objects
722 //==================================================
723 sal_Bool ScDrawView::SelectCurrentViewObject( const String& rName )
724 {
725 	sal_uInt16 nObjectTab = 0;
726 	SdrObject* pFound = NULL;
727        sal_Bool bUnMark=sal_False;
728 	SfxObjectShell*	pShell = pDoc->GetDocumentShell();
729 	if (pShell)
730 	{
731 		SdrModel* pDrawLayer = GetModel();
732 		sal_uInt16 nTabCount = pDoc->GetTableCount();
733 		for (sal_uInt16 i=0; i<nTabCount && !pFound; i++)
734 		{
735 			SdrPage* pPage = pDrawLayer->GetPage(i);
736 			DBG_ASSERT(pPage,"Page ?");
737 			if (pPage)
738 			{
739 				SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
740 				SdrObject* pObject = aIter.Next();
741 				while (pObject && !pFound)
742 				{
743 					if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
744 					{
745 						pFound = pObject;
746 						nObjectTab = i;
747 					}
748 					pObject = aIter.Next();
749 				}
750 			}
751 		}
752 	}
753 	if ( pFound )
754 	{
755 		ScTabView* pView = pViewData->GetView();
756 		if ( nObjectTab != nTab )								// Tabelle umschalten
757 			pView->SetTabNo( nObjectTab );
758 		DBG_ASSERT( nTab == nObjectTab, "Tabellen umschalten hat nicht geklappt" );
759 		pView->ScrollToObject( pFound );
760 		if ( pFound->GetLayer() == SC_LAYER_BACK &&
761 				!pViewData->GetViewShell()->IsDrawSelMode() &&
762 				!pDoc->IsTabProtected( nTab ) &&
763 				!pViewData->GetSfxDocShell()->IsReadOnly() )
764 		{
765 			SdrLayer* pLayer = GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_BACK);
766 			if (pLayer)
767 				SetLayerLocked( pLayer->GetName(), sal_False );
768 		}
769 		SdrPageView* pPV = GetSdrPageView();
770               bUnMark = IsObjMarked(pFound);
771 	       MarkObj( pFound, pPV, bUnMark);
772 	}
773 	return ( bUnMark );
774 }
775 //-----IAccessibility2 Implementation 2009
776 sal_Bool ScDrawView::SelectObject( const String& rName )
777 {
778 	UnmarkAll();
779 
780 	SCTAB nObjectTab = 0;
781 	SdrObject* pFound = NULL;
782 
783 	SfxObjectShell*	pShell = pDoc->GetDocumentShell();
784 	if (pShell)
785 	{
786 		SdrModel* pDrawLayer = GetModel();
787 		SCTAB nTabCount = pDoc->GetTableCount();
788 		for (SCTAB i=0; i<nTabCount && !pFound; i++)
789 		{
790 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
791 			DBG_ASSERT(pPage,"Page ?");
792 			if (pPage)
793 			{
794 				SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
795 				SdrObject* pObject = aIter.Next();
796 				while (pObject && !pFound)
797 				{
798 					if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
799 					{
800 						pFound = pObject;
801 						nObjectTab = i;
802 					}
803 					pObject = aIter.Next();
804 				}
805 			}
806 		}
807 	}
808 
809 	if ( pFound )
810 	{
811 		ScTabView* pView = pViewData->GetView();
812 		if ( nObjectTab != nTab )								// Tabelle umschalten
813 			pView->SetTabNo( nObjectTab );
814 
815 		DBG_ASSERT( nTab == nObjectTab, "Tabellen umschalten hat nicht geklappt" );
816 
817 		pView->ScrollToObject( pFound );
818 
819         /*  #61585# To select an object on the background layer, the layer has to
820             be unlocked even if exclusive drawing selection mode is not active
821             (this is reversed in MarkListHasChanged when nothing is selected) */
822 		if ( pFound->GetLayer() == SC_LAYER_BACK &&
823 				!pViewData->GetViewShell()->IsDrawSelMode() &&
824 				!pDoc->IsTabProtected( nTab ) &&
825 				!pViewData->GetSfxDocShell()->IsReadOnly() )
826 		{
827             UnlockBackgroundLayer();
828 		}
829 
830 		SdrPageView* pPV = GetSdrPageView();
831 		MarkObj( pFound, pPV );
832 	}
833 
834 	return ( pFound != NULL );
835 }
836 
837 //IAccessibility2 Implementation 2009-----
838 //Solution: If  object  is marked , return true , else return false .
839 //==================================================
840 sal_Bool ScDrawView::GetObjectIsMarked(  SdrObject* pObject  )
841 {
842        sal_Bool bisMarked =false;
843 	if (pObject )
844 	{
845 	      bisMarked = IsObjMarked(pObject);
846 	}
847 	return  bisMarked;
848 }
849 //-----IAccessibility2 Implementation 2009
850 //UNUSED2008-05  String ScDrawView::GetSelectedChartName() const
851 //UNUSED2008-05  {
852 //UNUSED2008-05      //  used for modifying a chart's data area - PersistName must always be used
853 //UNUSED2008-05      //  (as in ScDocument::FindChartData and UpdateChartArea)
854 //UNUSED2008-05
855 //UNUSED2008-05      const SdrMarkList& rMarkList = GetMarkedObjectList();
856 //UNUSED2008-05      if (rMarkList.GetMarkCount() == 1)
857 //UNUSED2008-05      {
858 //UNUSED2008-05          SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
859 //UNUSED2008-05          if (pObj->GetObjIdentifier() == OBJ_OLE2)
860 //UNUSED2008-05              if ( pDoc->IsChart(pObj) )
861 //UNUSED2008-05                  return static_cast<SdrOle2Obj*>(pObj)->GetPersistName();
862 //UNUSED2008-05      }
863 //UNUSED2008-05
864 //UNUSED2008-05      return EMPTY_STRING;        // nichts gefunden
865 //UNUSED2008-05  }
866 
867 FASTBOOL ScDrawView::InsertObjectSafe(SdrObject* pObj, SdrPageView& rPV, sal_uLong nOptions)
868 {
869 	//	Markierung nicht aendern, wenn Ole-Objekt aktiv
870 	//	(bei Drop aus Ole-Objekt wuerde sonst mitten im ExecuteDrag deaktiviert!)
871 
872 	if (pViewData)
873 	{
874 		SfxInPlaceClient* pClient = pViewData->GetViewShell()->GetIPClient();
875         if ( pClient && pClient->IsObjectInPlaceActive() )
876 			nOptions |= SDRINSERT_DONTMARK;
877 	}
878 
879 	return InsertObjectAtView( pObj, rPV, nOptions );
880 }
881 
882 SdrObject* ScDrawView::GetMarkedNoteCaption( ScDrawObjData** ppCaptData )
883 {
884     const SdrMarkList& rMarkList = GetMarkedObjectList();
885     if( pViewData && (rMarkList.GetMarkCount() == 1) )
886     {
887         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
888         if( ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, pViewData->GetTabNo() ) )
889         {
890             if( ppCaptData ) *ppCaptData = pCaptData;
891             return pObj;
892         }
893     }
894     return 0;
895 }
896 
897 void ScDrawView::LockCalcLayer( SdrLayerID nLayer, bool bLock )
898 {
899     SdrLayer* pLockLayer = GetModel()->GetLayerAdmin().GetLayerPerID( nLayer );
900     if( pLockLayer && (IsLayerLocked( pLockLayer->GetName() ) != bLock) )
901         SetLayerLocked( pLockLayer->GetName(), bLock );
902 }
903 
904 void __EXPORT ScDrawView::MakeVisible( const Rectangle& rRect, Window& rWin )
905 {
906 	//!	rWin richtig auswerten
907 	//!	ggf Zoom aendern
908 
909 	if ( pViewData && pViewData->GetActiveWin() == &rWin )
910 		pViewData->GetView()->MakeVisible( rRect );
911 }
912 
913 void ScDrawView::DeleteMarked()
914 {
915     // try to delete a note caption object with its cell note in the Calc document
916     ScDrawObjData* pCaptData = 0;
917     if( SdrObject* pCaptObj = GetMarkedNoteCaption( &pCaptData ) )
918     {
919         (void)pCaptObj; // prevent 'unused variable' compiler warning in pro builds
920         ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
921         ScDocShell* pDocShell = pViewData ? pViewData->GetDocShell() : 0;
922         ::svl::IUndoManager* pUndoMgr = pDocShell ? pDocShell->GetUndoManager() : 0;
923         bool bUndo = pDrawLayer && pDocShell && pUndoMgr && pDoc->IsUndoEnabled();
924 
925         // remove the cell note from document, we are its owner now
926         ScPostIt* pNote = pDoc->ReleaseNote( pCaptData->maStart );
927         DBG_ASSERT( pNote, "ScDrawView::DeleteMarked - cell note missing in document" );
928         if( pNote )
929         {
930             // rescue note data for undo (with pointer to caption object)
931             ScNoteData aNoteData = pNote->GetNoteData();
932             DBG_ASSERT( aNoteData.mpCaption == pCaptObj, "ScDrawView::DeleteMarked - caption object does not match" );
933             // collect the drawing undo action created while deleting the note
934             if( bUndo )
935                 pDrawLayer->BeginCalcUndo(false);
936             // delete the note (already removed from document above)
937             delete pNote;
938             // add the undo action for the note
939             if( bUndo )
940                 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, pCaptData->maStart, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
941             // repaint the cell to get rid of the note marker
942             if( pDocShell )
943                 pDocShell->PostPaintCell( pCaptData->maStart );
944             // done, return now to skip call of FmFormView::DeleteMarked()
945             return;
946         }
947     }
948 
949     FmFormView::DeleteMarked();
950 }
951 
952 SdrEndTextEditKind ScDrawView::ScEndTextEdit()
953 {
954 	sal_Bool bIsTextEdit = IsTextEdit();
955 	SdrEndTextEditKind eKind = SdrEndTextEdit();
956 
957 	if ( bIsTextEdit && pViewData )
958 		pViewData->GetViewShell()->SetDrawTextUndo(NULL);	// "normaler" Undo-Manager
959 
960 	return eKind;
961 }
962 
963 void ScDrawView::MarkDropObj( SdrObject* pObj )
964 {
965 	if ( pDropMarkObj != pObj )
966 	{
967 		pDropMarkObj = pObj;
968 		ImplClearCalcDropMarker();
969 
970 		if(pDropMarkObj)
971 		{
972 			pDropMarker = new SdrDropMarkerOverlay(*this, *pDropMarkObj);
973 		}
974 	}
975 }
976 
977 // support enhanced text edit for draw objects
978 SdrUndoManager* ScDrawView::getSdrUndoManagerForEnhancedTextEdit() const
979 {
980     return pDoc ? dynamic_cast< SdrUndoManager* >(pDoc->GetUndoManager()) : 0;
981 }
982 
983 // eof
984