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