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