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