xref: /aoo42x/main/sc/source/ui/view/drawview.cxx (revision 4d7c9de0)
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 SdrObject* ScDrawView::GetObjectByName(const String& rName)
693 {
694 	SfxObjectShell*	pShell = pDoc->GetDocumentShell();
695 	if (pShell)
696 	{
697 		SdrModel* pDrawLayer = GetModel();
698 		sal_uInt16 nTabCount = pDoc->GetTableCount();
699 		for (sal_uInt16 i=0; i<nTabCount; i++)
700 		{
701 			SdrPage* pPage = pDrawLayer->GetPage(i);
702 			DBG_ASSERT(pPage,"Page ?");
703 			if (pPage)
704 			{
705 				SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
706 				SdrObject* pObject = aIter.Next();
707 				while (pObject)
708 				{
709 					if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
710 					{
711 						return pObject;
712 					}
713 					pObject = aIter.Next();
714 				}
715 			}
716 		}
717 	}
718 	return 0;
719 }
720 //Solution: realize multi-selection of objects
721 //==================================================
722 sal_Bool ScDrawView::SelectCurrentViewObject( const String& rName )
723 {
724 	sal_uInt16 nObjectTab = 0;
725 	SdrObject* pFound = NULL;
726        sal_Bool bUnMark=sal_False;
727 	SfxObjectShell*	pShell = pDoc->GetDocumentShell();
728 	if (pShell)
729 	{
730 		SdrModel* pDrawLayer = GetModel();
731 		sal_uInt16 nTabCount = pDoc->GetTableCount();
732 		for (sal_uInt16 i=0; i<nTabCount && !pFound; i++)
733 		{
734 			SdrPage* pPage = pDrawLayer->GetPage(i);
735 			DBG_ASSERT(pPage,"Page ?");
736 			if (pPage)
737 			{
738 				SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
739 				SdrObject* pObject = aIter.Next();
740 				while (pObject && !pFound)
741 				{
742 					if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
743 					{
744 						pFound = pObject;
745 						nObjectTab = i;
746 					}
747 					pObject = aIter.Next();
748 				}
749 			}
750 		}
751 	}
752 	if ( pFound )
753 	{
754 		ScTabView* pView = pViewData->GetView();
755 		if ( nObjectTab != nTab )								// Tabelle umschalten
756 			pView->SetTabNo( nObjectTab );
757 		DBG_ASSERT( nTab == nObjectTab, "Tabellen umschalten hat nicht geklappt" );
758 		pView->ScrollToObject( pFound );
759 		if ( pFound->GetLayer() == SC_LAYER_BACK &&
760 				!pViewData->GetViewShell()->IsDrawSelMode() &&
761 				!pDoc->IsTabProtected( nTab ) &&
762 				!pViewData->GetSfxDocShell()->IsReadOnly() )
763 		{
764 			SdrLayer* pLayer = GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_BACK);
765 			if (pLayer)
766 				SetLayerLocked( pLayer->GetName(), sal_False );
767 		}
768 		SdrPageView* pPV = GetSdrPageView();
769               bUnMark = IsObjMarked(pFound);
770 	       MarkObj( pFound, pPV, bUnMark);
771 	}
772 	return ( bUnMark );
773 }
774 sal_Bool ScDrawView::SelectObject( const String& rName )
775 {
776 	UnmarkAll();
777 
778 	SCTAB nObjectTab = 0;
779 	SdrObject* pFound = NULL;
780 
781 	SfxObjectShell*	pShell = pDoc->GetDocumentShell();
782 	if (pShell)
783 	{
784 		SdrModel* pDrawLayer = GetModel();
785 		SCTAB nTabCount = pDoc->GetTableCount();
786 		for (SCTAB i=0; i<nTabCount && !pFound; i++)
787 		{
788 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
789 			DBG_ASSERT(pPage,"Page ?");
790 			if (pPage)
791 			{
792 				SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
793 				SdrObject* pObject = aIter.Next();
794 				while (pObject && !pFound)
795 				{
796 					if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
797 					{
798 						pFound = pObject;
799 						nObjectTab = i;
800 					}
801 					pObject = aIter.Next();
802 				}
803 			}
804 		}
805 	}
806 
807 	if ( pFound )
808 	{
809 		ScTabView* pView = pViewData->GetView();
810 		if ( nObjectTab != nTab )								// Tabelle umschalten
811 			pView->SetTabNo( nObjectTab );
812 
813 		DBG_ASSERT( nTab == nObjectTab, "Tabellen umschalten hat nicht geklappt" );
814 
815 		pView->ScrollToObject( pFound );
816 
817         /*  #61585# To select an object on the background layer, the layer has to
818             be unlocked even if exclusive drawing selection mode is not active
819             (this is reversed in MarkListHasChanged when nothing is selected) */
820 		if ( pFound->GetLayer() == SC_LAYER_BACK &&
821 				!pViewData->GetViewShell()->IsDrawSelMode() &&
822 				!pDoc->IsTabProtected( nTab ) &&
823 				!pViewData->GetSfxDocShell()->IsReadOnly() )
824 		{
825             UnlockBackgroundLayer();
826 		}
827 
828 		SdrPageView* pPV = GetSdrPageView();
829 		MarkObj( pFound, pPV );
830 	}
831 
832 	return ( pFound != NULL );
833 }
834 
835 //Solution: If  object  is marked , return true , else return false .
836 //==================================================
837 sal_Bool ScDrawView::GetObjectIsMarked(  SdrObject* pObject  )
838 {
839        sal_Bool bisMarked =false;
840 	if (pObject )
841 	{
842 	      bisMarked = IsObjMarked(pObject);
843 	}
844 	return  bisMarked;
845 }
846 //UNUSED2008-05  String ScDrawView::GetSelectedChartName() const
847 //UNUSED2008-05  {
848 //UNUSED2008-05      //  used for modifying a chart's data area - PersistName must always be used
849 //UNUSED2008-05      //  (as in ScDocument::FindChartData and UpdateChartArea)
850 //UNUSED2008-05
851 //UNUSED2008-05      const SdrMarkList& rMarkList = GetMarkedObjectList();
852 //UNUSED2008-05      if (rMarkList.GetMarkCount() == 1)
853 //UNUSED2008-05      {
854 //UNUSED2008-05          SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
855 //UNUSED2008-05          if (pObj->GetObjIdentifier() == OBJ_OLE2)
856 //UNUSED2008-05              if ( pDoc->IsChart(pObj) )
857 //UNUSED2008-05                  return static_cast<SdrOle2Obj*>(pObj)->GetPersistName();
858 //UNUSED2008-05      }
859 //UNUSED2008-05
860 //UNUSED2008-05      return EMPTY_STRING;        // nichts gefunden
861 //UNUSED2008-05  }
862 
863 FASTBOOL ScDrawView::InsertObjectSafe(SdrObject* pObj, SdrPageView& rPV, sal_uLong nOptions)
864 {
865 	//	Markierung nicht aendern, wenn Ole-Objekt aktiv
866 	//	(bei Drop aus Ole-Objekt wuerde sonst mitten im ExecuteDrag deaktiviert!)
867 
868 	if (pViewData)
869 	{
870 		SfxInPlaceClient* pClient = pViewData->GetViewShell()->GetIPClient();
871         if ( pClient && pClient->IsObjectInPlaceActive() )
872 			nOptions |= SDRINSERT_DONTMARK;
873 	}
874 
875 	return InsertObjectAtView( pObj, rPV, nOptions );
876 }
877 
878 SdrObject* ScDrawView::GetMarkedNoteCaption( ScDrawObjData** ppCaptData )
879 {
880     const SdrMarkList& rMarkList = GetMarkedObjectList();
881     if( pViewData && (rMarkList.GetMarkCount() == 1) )
882     {
883         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
884         if( ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, pViewData->GetTabNo() ) )
885         {
886             if( ppCaptData ) *ppCaptData = pCaptData;
887             return pObj;
888         }
889     }
890     return 0;
891 }
892 
893 void ScDrawView::LockCalcLayer( SdrLayerID nLayer, bool bLock )
894 {
895     SdrLayer* pLockLayer = GetModel()->GetLayerAdmin().GetLayerPerID( nLayer );
896     if( pLockLayer && (IsLayerLocked( pLockLayer->GetName() ) != bLock) )
897         SetLayerLocked( pLockLayer->GetName(), bLock );
898 }
899 
900 void __EXPORT ScDrawView::MakeVisible( const Rectangle& rRect, Window& rWin )
901 {
902 	//!	rWin richtig auswerten
903 	//!	ggf Zoom aendern
904 
905 	if ( pViewData && pViewData->GetActiveWin() == &rWin )
906 		pViewData->GetView()->MakeVisible( rRect );
907 }
908 
909 void ScDrawView::DeleteMarked()
910 {
911     // try to delete a note caption object with its cell note in the Calc document
912     ScDrawObjData* pCaptData = 0;
913     if( SdrObject* pCaptObj = GetMarkedNoteCaption( &pCaptData ) )
914     {
915         (void)pCaptObj; // prevent 'unused variable' compiler warning in pro builds
916         ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
917         ScDocShell* pDocShell = pViewData ? pViewData->GetDocShell() : 0;
918         ::svl::IUndoManager* pUndoMgr = pDocShell ? pDocShell->GetUndoManager() : 0;
919         bool bUndo = pDrawLayer && pDocShell && pUndoMgr && pDoc->IsUndoEnabled();
920 
921         // remove the cell note from document, we are its owner now
922         ScPostIt* pNote = pDoc->ReleaseNote( pCaptData->maStart );
923         DBG_ASSERT( pNote, "ScDrawView::DeleteMarked - cell note missing in document" );
924         if( pNote )
925         {
926             // rescue note data for undo (with pointer to caption object)
927             ScNoteData aNoteData = pNote->GetNoteData();
928             DBG_ASSERT( aNoteData.mpCaption == pCaptObj, "ScDrawView::DeleteMarked - caption object does not match" );
929             // collect the drawing undo action created while deleting the note
930             if( bUndo )
931                 pDrawLayer->BeginCalcUndo(false);
932             // delete the note (already removed from document above)
933             delete pNote;
934             // add the undo action for the note
935             if( bUndo )
936                 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, pCaptData->maStart, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
937             // repaint the cell to get rid of the note marker
938             if( pDocShell )
939                 pDocShell->PostPaintCell( pCaptData->maStart );
940             // done, return now to skip call of FmFormView::DeleteMarked()
941             return;
942         }
943     }
944 
945     FmFormView::DeleteMarked();
946 }
947 
948 SdrEndTextEditKind ScDrawView::ScEndTextEdit()
949 {
950 	sal_Bool bIsTextEdit = IsTextEdit();
951 	SdrEndTextEditKind eKind = SdrEndTextEdit();
952 
953 	if ( bIsTextEdit && pViewData )
954 		pViewData->GetViewShell()->SetDrawTextUndo(NULL);	// "normaler" Undo-Manager
955 
956 	return eKind;
957 }
958 
959 void ScDrawView::MarkDropObj( SdrObject* pObj )
960 {
961 	if ( pDropMarkObj != pObj )
962 	{
963 		pDropMarkObj = pObj;
964 		ImplClearCalcDropMarker();
965 
966 		if(pDropMarkObj)
967 		{
968 			pDropMarker = new SdrDropMarkerOverlay(*this, *pDropMarkObj);
969 		}
970 	}
971 }
972 
973 // support enhanced text edit for draw objects
974 SdrUndoManager* ScDrawView::getSdrUndoManagerForEnhancedTextEdit() const
975 {
976     return pDoc ? dynamic_cast< SdrUndoManager* >(pDoc->GetUndoManager()) : 0;
977 }
978 
979 // eof
980