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