1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/embed/EmbedStates.hpp>
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>
39 #include "drawview.hxx"
41 #include "viewdata.hxx"
42 #include "document.hxx"
43 #include "drawutil.hxx"
45 #include "globstr.hrc"
46 #include "tabvwsh.hxx"
49 #include "drwlayer.hxx"
51 #include "viewuno.hxx"
52 #include "userdat.hxx"
54 #include "undocell.hxx"
55 #include "gridwin.hxx"
59 using namespace com::sun::star
;
61 #define SC_HANDLESIZE_BIG 9
63 void ScDrawView::Construct()
65 EnableExtendedKeyInputDispatcher(false);
66 EnableExtendedMouseEventDispatcher(false);
67 EnableExtendedCommandEventDispatcher(false);
69 SetFrameDragSingles(true);
71 SetMinMoveDistancePixel( 2 );
72 SetHitTolerancePixel( 2 );
76 SCTAB nViewTab
= pViewData
->GetTabNo();
77 ShowSdrPage(GetModel()->GetPage(nViewTab
));
79 bool bEx
= pViewData
->GetViewShell()->IsDrawSelMode();
80 bool bProt
= pDoc
->IsTabProtected( nViewTab
) ||
81 pViewData
->GetSfxDocShell()->IsReadOnly();
84 SdrLayerAdmin
& rAdmin
= GetModel()->GetLayerAdmin();
85 pLayer
= rAdmin
.GetLayerPerID(SC_LAYER_BACK
);
87 SetLayerLocked( pLayer
->GetName(), bProt
|| !bEx
);
88 pLayer
= rAdmin
.GetLayerPerID(SC_LAYER_INTERN
);
90 SetLayerLocked( pLayer
->GetName(), true );
91 pLayer
= rAdmin
.GetLayerPerID(SC_LAYER_FRONT
);
94 SetLayerLocked( pLayer
->GetName(), bProt
);
95 SetActiveLayer( pLayer
->GetName() ); // set active layer to FRONT
97 pLayer
= rAdmin
.GetLayerPerID(SC_LAYER_CONTROLS
);
99 SetLayerLocked( pLayer
->GetName(), bProt
);
100 pLayer
= rAdmin
.GetLayerPerID(SC_LAYER_HIDDEN
);
103 SetLayerLocked( pLayer
->GetName(), bProt
);
104 SetLayerVisible( pLayer
->GetName(), false);
107 SetSwapAsynchron(true);
111 ShowSdrPage(GetModel()->GetPage(nTab
));
114 UpdateUserViewOptions();
118 bInConstruct
= false;
121 void ScDrawView::ImplClearCalcDropMarker()
130 ScDrawView::~ScDrawView()
132 ImplClearCalcDropMarker();
135 void ScDrawView::AddCustomHdl()
137 const SdrMarkList
&rMrkList
= GetMarkedObjectList();
138 const size_t nCount
= rMrkList
.GetMarkCount();
139 for(size_t nPos
=0; nPos
<nCount
; ++nPos
)
141 SdrObject
* pObj
= rMrkList
.GetMark(nPos
)->GetMarkedSdrObj();
142 if (ScDrawObjData
*pAnchor
= ScDrawLayer::GetObjDataTab(pObj
, nTab
))
144 if (ScTabView
* pView
= pViewData
->GetView())
145 pView
->CreateAnchorHandles(maHdlList
, pAnchor
->maStart
);
150 void ScDrawView::InvalidateAttribs()
152 if (!pViewData
) return;
153 SfxBindings
& rBindings
= pViewData
->GetBindings();
155 // true status values:
156 rBindings
.InvalidateAll( true );
159 void ScDrawView::InvalidateDrawTextAttrs()
161 if (!pViewData
) return;
162 SfxBindings
& rBindings
= pViewData
->GetBindings();
164 // cjk/ctl font items have no configured slots,
165 // need no invalidate
167 rBindings
.Invalidate( SID_ATTR_CHAR_FONT
);
168 rBindings
.Invalidate( SID_ATTR_CHAR_FONTHEIGHT
);
169 rBindings
.Invalidate( SID_ATTR_CHAR_WEIGHT
);
170 rBindings
.Invalidate( SID_ATTR_CHAR_POSTURE
);
171 rBindings
.Invalidate( SID_ATTR_CHAR_UNDERLINE
);
172 rBindings
.Invalidate( SID_ULINE_VAL_NONE
);
173 rBindings
.Invalidate( SID_ULINE_VAL_SINGLE
);
174 rBindings
.Invalidate( SID_ULINE_VAL_DOUBLE
);
175 rBindings
.Invalidate( SID_ULINE_VAL_DOTTED
);
176 rBindings
.Invalidate( SID_ATTR_CHAR_OVERLINE
);
177 rBindings
.Invalidate( SID_ATTR_CHAR_COLOR
);
178 rBindings
.Invalidate( SID_ATTR_CHAR_BACK_COLOR
);
179 rBindings
.Invalidate( SID_ATTR_PARA_ADJUST_LEFT
);
180 rBindings
.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT
);
181 rBindings
.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK
);
182 rBindings
.Invalidate( SID_ATTR_PARA_ADJUST_CENTER
);
183 rBindings
.Invalidate( SID_ALIGNLEFT
);
184 rBindings
.Invalidate( SID_ALIGNCENTERHOR
);
185 rBindings
.Invalidate( SID_ALIGNRIGHT
);
186 rBindings
.Invalidate( SID_ALIGNBLOCK
);
187 rBindings
.Invalidate( SID_ATTR_PARA_LINESPACE_10
);
188 rBindings
.Invalidate( SID_ATTR_PARA_LINESPACE_15
);
189 rBindings
.Invalidate( SID_ATTR_PARA_LINESPACE_20
);
190 rBindings
.Invalidate( SID_SET_SUPER_SCRIPT
);
191 rBindings
.Invalidate( SID_SET_SUB_SCRIPT
);
192 rBindings
.Invalidate( SID_ATTR_CHAR_KERNING
);
193 rBindings
.Invalidate( SID_ATTR_CHAR_STRIKEOUT
);
194 rBindings
.Invalidate( SID_ATTR_CHAR_SHADOWED
);
195 rBindings
.Invalidate( SID_TEXTDIRECTION_LEFT_TO_RIGHT
);
196 rBindings
.Invalidate( SID_TEXTDIRECTION_TOP_TO_BOTTOM
);
197 rBindings
.Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT
);
198 rBindings
.Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT
);
199 rBindings
.Invalidate( SID_TABLE_VERT_NONE
);
200 rBindings
.Invalidate( SID_TABLE_VERT_CENTER
);
201 rBindings
.Invalidate( SID_TABLE_VERT_BOTTOM
);
202 // pseudo slots for Format menu
203 rBindings
.Invalidate( SID_ALIGN_ANY_LEFT
);
204 rBindings
.Invalidate( SID_ALIGN_ANY_HCENTER
);
205 rBindings
.Invalidate( SID_ALIGN_ANY_RIGHT
);
206 rBindings
.Invalidate( SID_ALIGN_ANY_JUSTIFIED
);
209 void ScDrawView::SetMarkedToLayer( sal_uInt8 nLayerNo
)
211 if (AreObjectsMarked())
213 // #i11702# use SdrUndoObjectLayerChange for undo
214 // STR_UNDO_SELATTR is "Attributes" - should use a different text later
215 BegUndo( ScGlobal::GetRscString( STR_UNDO_SELATTR
) );
217 const SdrMarkList
& rMark
= GetMarkedObjectList();
218 const size_t nCount
= rMark
.GetMarkCount();
219 for (size_t i
=0; i
<nCount
; ++i
)
221 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
222 if ( !pObj
->ISA(SdrUnoObj
) && (pObj
->GetLayer() != SC_LAYER_INTERN
) )
224 AddUndo( new SdrUndoObjectLayerChange( *pObj
, pObj
->GetLayer(), (SdrLayerID
)nLayerNo
) );
225 pObj
->SetLayer( nLayerNo
);
231 // repaint is done in SetLayer
233 pViewData
->GetDocShell()->SetDrawModified();
235 // check mark list now instead of later in a timer
237 MarkListHasChanged();
241 bool ScDrawView::HasMarkedControl() const
243 SdrObjListIter
aIter( GetMarkedObjectList() );
244 for( SdrObject
* pObj
= aIter
.Next(); pObj
; pObj
= aIter
.Next() )
245 if( pObj
->ISA( SdrUnoObj
) )
250 bool ScDrawView::HasMarkedInternal() const
252 // internal objects should not be inside a group, but who knows...
253 SdrObjListIter
aIter( GetMarkedObjectList() );
254 for( SdrObject
* pObj
= aIter
.Next(); pObj
; pObj
= aIter
.Next() )
255 if( pObj
->GetLayer() == SC_LAYER_INTERN
)
260 void ScDrawView::UpdateWorkArea()
262 SdrPage
* pPage
= GetModel()->GetPage(static_cast<sal_uInt16
>(nTab
));
266 Size
aPageSize( pPage
->GetSize() );
267 Rectangle
aNewArea( aPos
, aPageSize
);
268 if ( aPageSize
.Width() < 0 )
270 // RTL: from max.negative (left) to zero (right)
271 aNewArea
.Right() = 0;
272 aNewArea
.Left() = aPageSize
.Width() + 1;
274 SetWorkArea( aNewArea
);
278 OSL_FAIL("Page nicht gefunden");
282 void ScDrawView::DoCut()
285 BegUndo( ScGlobal::GetRscString( STR_UNDO_CUT
) );
286 DeleteMarked(); // auf dieser View - von der 505f Umstellung nicht betroffen
290 void ScDrawView::GetScale( Fraction
& rFractX
, Fraction
& rFractY
) const
296 void ScDrawView::RecalcScale()
300 Fraction
aZoomX(1,1);
301 Fraction
aZoomY(1,1);
305 nTab
= pViewData
->GetTabNo();
306 nPPTX
= pViewData
->GetPPTX();
307 nPPTY
= pViewData
->GetPPTY();
308 aZoomX
= pViewData
->GetZoomX();
309 aZoomY
= pViewData
->GetZoomY();
313 Point aLogic
= pDev
->LogicToPixel( Point(1000,1000), MAP_TWIP
);
314 nPPTX
= aLogic
.X() / 1000.0;
315 nPPTY
= aLogic
.Y() / 1000.0;
316 //! Zoom uebergeben ???
321 pDoc
->GetTableArea( nTab
, nEndCol
, nEndRow
);
327 ScDrawUtil::CalcScale( pDoc
, nTab
, 0,0, nEndCol
,nEndRow
, pDev
,aZoomX
,aZoomY
,nPPTX
,nPPTY
,
329 SdrPageView
* pPV
= GetSdrPageView();
330 if ( pViewData
&& pPV
)
332 if ( SdrPage
* pPage
= pPV
->GetPage() )
334 const size_t nCount
= pPage
->GetObjCount();
335 for ( size_t i
= 0; i
< nCount
; ++i
)
337 SdrObject
* pObj
= pPage
->GetObj( i
);
338 // Align objects to nearset grid position
345 void ScDrawView::DoConnect(SdrOle2Obj
* pOleObj
)
348 pViewData
->GetViewShell()->ConnectObject( pOleObj
);
351 void ScDrawView::MarkListHasChanged()
353 FmFormView::MarkListHasChanged();
355 ScTabViewShell
* pViewSh
= pViewData
->GetViewShell();
357 // #i110829# remove the cell selection only if drawing objects are selected
358 if ( !bInConstruct
&& GetMarkedObjectList().GetMarkCount() )
360 pViewSh
->Unmark(); // remove cell selection
362 // end cell edit mode if drawing objects are selected
363 SC_MOD()->InputEnterHandler();
368 ScModule
* pScMod
= SC_MOD();
369 bool bUnoRefDialog
= pScMod
->IsRefDialogOpen() && pScMod
->GetCurRefDlgId() == WID_SIMPLE_REF
;
371 ScClient
* pClient
= static_cast<ScClient
*>( pViewSh
->GetIPClient() );
372 if ( pClient
&& pClient
->IsObjectInPlaceActive() && !bUnoRefDialog
)
374 // beim ViewShell::Activate aus dem Reset2Open nicht die Handles anzeigen
375 pClient
->DeactivateObject();
376 // Image-Ole wieder durch Grafik ersetzen passiert jetzt in ScClient::UIActivate
379 // Ole-Objekt selektiert?
381 SdrOle2Obj
* pOle2Obj
= NULL
;
382 SdrGrafObj
* pGrafObj
= NULL
;
384 const SdrMarkList
& rMarkList
= GetMarkedObjectList();
385 const size_t nMarkCount
= rMarkList
.GetMarkCount();
387 if ( nMarkCount
== 0 && !pViewData
->GetViewShell()->IsDrawSelMode() && !bInConstruct
)
389 // relock layers that may have been unlocked before
390 LockBackgroundLayer();
394 bool bSubShellSet
= false;
397 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
398 if (pObj
->GetObjIdentifier() == OBJ_OLE2
)
400 pOle2Obj
= static_cast<SdrOle2Obj
*>(pObj
);
401 if (!ScDocument::IsChart(pObj
) )
402 pViewSh
->SetOleObjectShell(true);
404 pViewSh
->SetChartShell(true);
407 else if (pObj
->GetObjIdentifier() == OBJ_GRAF
)
409 pGrafObj
= static_cast<SdrGrafObj
*>(pObj
);
410 pViewSh
->SetGraphicShell(true);
413 else if (pObj
->GetObjIdentifier() == OBJ_MEDIA
)
415 pViewSh
->SetMediaShell(true);
418 else if (pObj
->GetObjIdentifier() != OBJ_TEXT
// Verhindern, das beim Anlegen
419 || !pViewSh
->IsDrawTextShell()) // eines TextObjekts auf die
420 { // DrawShell umgeschaltet wird.
421 pViewSh
->SetDrawShell(true); //@#70206#
425 if ( nMarkCount
&& !bSubShellSet
)
427 bool bOnlyControls
= true;
428 bool bOnlyGraf
= true;
429 for (size_t i
=0; i
<nMarkCount
; ++i
)
431 SdrObject
* pObj
= rMarkList
.GetMark(i
)->GetMarkedSdrObj();
432 if ( pObj
->ISA( SdrObjGroup
) )
434 const SdrObjList
*pLst
= static_cast<SdrObjGroup
*>(pObj
)->GetSubList();
435 const size_t nListCount
= pLst
->GetObjCount();
436 if ( nListCount
== 0 )
438 // An empty group (may occur during Undo) is no control or graphics object.
439 // Creating the form shell during undo would lead to problems with the undo manager.
440 bOnlyControls
= false;
443 for ( size_t j
= 0; j
< nListCount
; ++j
)
445 SdrObject
*pSubObj
= pLst
->GetObj( j
);
447 if (!pSubObj
->ISA(SdrUnoObj
))
448 bOnlyControls
= false;
449 if (pSubObj
->GetObjIdentifier() != OBJ_GRAF
)
452 if ( !bOnlyControls
&& !bOnlyGraf
) break;
457 if (!pObj
->ISA(SdrUnoObj
))
458 bOnlyControls
= false;
459 if (pObj
->GetObjIdentifier() != OBJ_GRAF
)
463 if ( !bOnlyControls
&& !bOnlyGraf
) break;
468 pViewSh
->SetDrawFormShell(true); // jetzt UNO-Controls
472 pViewSh
->SetGraphicShell(true);
474 else if(nMarkCount
>1)
476 pViewSh
->SetDrawShell(true);
482 SfxViewFrame
* pViewFrame
= pViewSh
->GetViewFrame();
483 bool bOle
= pViewSh
->GetViewFrame()->GetFrame().IsInPlace();
484 uno::Sequence
< embed::VerbDescriptor
> aVerbs
;
485 if ( pOle2Obj
&& !bOle
)
487 uno::Reference
< embed::XEmbeddedObject
> xObj
= pOle2Obj
->GetObjRef();
488 OSL_ENSURE( xObj
.is(), "SdrOle2Obj ohne ObjRef" );
490 aVerbs
= xObj
->getSupportedVerbs();
492 pViewSh
->SetVerbs( aVerbs
);
497 UpdateIMap( pOle2Obj
);
499 UpdateIMap( pGrafObj
);
501 InvalidateAttribs(); // nach dem IMap-Editor Update
502 InvalidateDrawTextAttrs();
504 for(sal_uInt32
a(0L); a
< PaintWindowCount(); a
++)
506 SdrPaintWindow
* pPaintWindow
= GetPaintWindow(a
);
507 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
509 if(OUTDEV_WINDOW
== rOutDev
.GetOutDevType())
511 static_cast<vcl::Window
&>(rOutDev
).Update();
515 // uno object for view returns drawing objects as selection,
516 // so it must notify its SelectionChangeListeners
520 SfxFrame
& rFrame
= pViewFrame
->GetFrame();
521 uno::Reference
<frame::XController
> xController
= rFrame
.GetController();
522 if (xController
.is())
524 ScTabViewObj
* pImp
= ScTabViewObj::getImplementation( xController
);
526 pImp
->SelectionChanged();
530 // update selection transfer object
532 pViewSh
->CheckSelectionTransfer();
536 bool ScDrawView::SdrBeginTextEdit(
541 SdrOutliner
* pGivenOutliner
,
542 OutlinerView
* pGivenOutlinerView
,
543 bool bDontDeleteOutliner
,
547 const bool bRet
= FmFormView::SdrBeginTextEdit(
548 pObj
, pPV
, pWinL
, bIsNewObj
,
549 pGivenOutliner
, pGivenOutlinerView
, bDontDeleteOutliner
,
550 bOnlyOneView
, bGrabFocus
);
552 ScTabViewShell
* pViewSh
= pViewData
->GetViewShell();
553 if ( pViewSh
->GetViewFrame() )
555 SfxFrame
& rFrame
= pViewSh
->GetViewFrame()->GetFrame();
556 uno::Reference
< frame::XController
> xController
= rFrame
.GetController();
557 if (xController
.is())
559 ScTabViewObj
* pImp
= ScTabViewObj::getImplementation( xController
);
561 pImp
->SelectionChanged();
568 SdrEndTextEditKind
ScDrawView::SdrEndTextEdit( bool bDontDeleteReally
)
570 const SdrEndTextEditKind eRet
= FmFormView::SdrEndTextEdit( bDontDeleteReally
);
572 ScTabViewShell
* pViewSh
= pViewData
->GetViewShell();
573 if ( pViewSh
->GetViewFrame() )
575 SfxFrame
& rFrame
= pViewSh
->GetViewFrame()->GetFrame();
576 uno::Reference
< frame::XController
> xController
= rFrame
.GetController();
577 if (xController
.is())
579 ScTabViewObj
* pImp
= ScTabViewObj::getImplementation( xController
);
581 pImp
->SelectionChanged();
588 void ScDrawView::ModelHasChanged()
590 SdrObject
* pEditObj
= GetTextEditObject();
591 if ( pEditObj
&& !pEditObj
->IsInserted() && pViewData
)
593 // SdrObjEditView::ModelHasChanged will end text edit in this case,
594 // so make sure the EditEngine's undo manager is no longer used.
595 pViewData
->GetViewShell()->SetDrawTextUndo(NULL
);
596 SetCreateMode(); // don't leave FuText in a funny state
599 FmFormView::ModelHasChanged();
602 void ScDrawView::UpdateUserViewOptions()
606 const ScViewOptions
& rOpt
= pViewData
->GetOptions();
607 const ScGridOptions
& rGrid
= rOpt
.GetGridOptions();
609 SetDragStripes( rOpt
.GetOption( VOPT_HELPLINES
) );
610 SetMarkHdlSizePixel( SC_HANDLESIZE_BIG
);
612 SetGridVisible( rGrid
.GetGridVisible() );
613 SetSnapEnabled( rGrid
.GetUseGridSnap() );
614 SetGridSnap( rGrid
.GetUseGridSnap() );
616 Fraction
aFractX( rGrid
.GetFieldDrawX(), rGrid
.GetFieldDivisionX() + 1 );
617 Fraction
aFractY( rGrid
.GetFieldDrawY(), rGrid
.GetFieldDivisionY() + 1 );
618 SetSnapGridWidth( aFractX
, aFractY
);
620 SetGridCoarse( Size( rGrid
.GetFieldDrawX(), rGrid
.GetFieldDrawY() ) );
621 SetGridFine( Size( rGrid
.GetFieldDrawX() / (rGrid
.GetFieldDivisionX() + 1),
622 rGrid
.GetFieldDrawY() / (rGrid
.GetFieldDivisionY() + 1) ) );
626 SdrObject
* ScDrawView::GetObjectByName(const OUString
& rName
)
628 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
631 SdrModel
* pDrawLayer
= GetModel();
632 sal_uInt16 nTabCount
= pDoc
->GetTableCount();
633 for (sal_uInt16 i
=0; i
<nTabCount
; i
++)
635 SdrPage
* pPage
= pDrawLayer
->GetPage(i
);
636 DBG_ASSERT(pPage
,"Page ?");
639 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
640 SdrObject
* pObject
= aIter
.Next();
643 if ( ScDrawLayer::GetVisibleName( pObject
) == rName
)
647 pObject
= aIter
.Next();
655 //realize multi-selection of objects
657 bool ScDrawView::SelectCurrentViewObject( const OUString
& rName
)
659 sal_uInt16 nObjectTab
= 0;
660 SdrObject
* pFound
= NULL
;
661 bool bUnMark
= false;
662 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
665 SdrModel
* pDrawLayer
= GetModel();
666 sal_uInt16 nTabCount
= pDoc
->GetTableCount();
667 for (sal_uInt16 i
=0; i
<nTabCount
&& !pFound
; i
++)
669 SdrPage
* pPage
= pDrawLayer
->GetPage(i
);
670 DBG_ASSERT(pPage
,"Page ?");
673 SdrObjListIter
aIter( *pPage
, IM_DEEPWITHGROUPS
);
674 SdrObject
* pObject
= aIter
.Next();
675 while (pObject
&& !pFound
)
677 if ( ScDrawLayer::GetVisibleName( pObject
) == rName
)
682 pObject
= aIter
.Next();
689 ScTabView
* pView
= pViewData
->GetView();
690 if ( nObjectTab
!= nTab
) // Tabelle umschalten
691 pView
->SetTabNo( nObjectTab
);
692 DBG_ASSERT( nTab
== nObjectTab
, "Tabellen umschalten hat nicht geklappt" );
693 pView
->ScrollToObject( pFound
);
694 if ( pFound
->GetLayer() == SC_LAYER_BACK
&&
695 !pViewData
->GetViewShell()->IsDrawSelMode() &&
696 !pDoc
->IsTabProtected( nTab
) &&
697 !pViewData
->GetSfxDocShell()->IsReadOnly() )
699 SdrLayer
* pLayer
= GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_BACK
);
701 SetLayerLocked( pLayer
->GetName(), false );
703 SdrPageView
* pPV
= GetSdrPageView();
704 bUnMark
= IsObjMarked(pFound
);
705 MarkObj( pFound
, pPV
, bUnMark
);
710 bool ScDrawView::SelectObject( const OUString
& rName
)
714 SCTAB nObjectTab
= 0;
715 SdrObject
* pFound
= NULL
;
717 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
720 SdrModel
* pDrawLayer
= GetModel();
721 SCTAB nTabCount
= pDoc
->GetTableCount();
722 for (SCTAB i
=0; i
<nTabCount
&& !pFound
; i
++)
724 SdrPage
* pPage
= pDrawLayer
->GetPage(static_cast<sal_uInt16
>(i
));
725 OSL_ENSURE(pPage
,"Page ?");
728 SdrObjListIter
aIter( *pPage
, IM_DEEPWITHGROUPS
);
729 SdrObject
* pObject
= aIter
.Next();
730 while (pObject
&& !pFound
)
732 if ( ScDrawLayer::GetVisibleName( pObject
) == rName
)
737 pObject
= aIter
.Next();
745 ScTabView
* pView
= pViewData
->GetView();
746 if ( nObjectTab
!= nTab
) // Tabelle umschalten
747 pView
->SetTabNo( nObjectTab
);
749 OSL_ENSURE( nTab
== nObjectTab
, "Tabellen umschalten hat nicht geklappt" );
751 pView
->ScrollToObject( pFound
);
753 /* To select an object on the background layer, the layer has to
754 be unlocked even if exclusive drawing selection mode is not active
755 (this is reversed in MarkListHasChanged when nothing is selected) */
756 if ( pFound
->GetLayer() == SC_LAYER_BACK
&&
757 !pViewData
->GetViewShell()->IsDrawSelMode() &&
758 !pDoc
->IsTabProtected( nTab
) &&
759 !pViewData
->GetSfxDocShell()->IsReadOnly() )
761 UnlockBackgroundLayer();
764 SdrPageView
* pPV
= GetSdrPageView();
765 MarkObj( pFound
, pPV
);
768 return ( pFound
!= NULL
);
771 //If object is marked , return true , else return false .
772 bool ScDrawView::GetObjectIsMarked( SdrObject
* pObject
)
774 bool bisMarked
= false;
777 bisMarked
= IsObjMarked(pObject
);
782 bool ScDrawView::InsertObjectSafe(SdrObject
* pObj
, SdrPageView
& rPV
, SdrInsertFlags nOptions
)
784 // Markierung nicht aendern, wenn Ole-Objekt aktiv
785 // (bei Drop aus Ole-Objekt wuerde sonst mitten im ExecuteDrag deaktiviert!)
789 SfxInPlaceClient
* pClient
= pViewData
->GetViewShell()->GetIPClient();
790 if ( pClient
&& pClient
->IsObjectInPlaceActive() )
791 nOptions
|= SdrInsertFlags::DONTMARK
;
794 return InsertObjectAtView( pObj
, rPV
, nOptions
);
797 SdrObject
* ScDrawView::GetMarkedNoteCaption( ScDrawObjData
** ppCaptData
)
799 const SdrMarkList
& rMarkList
= GetMarkedObjectList();
800 if( pViewData
&& (rMarkList
.GetMarkCount() == 1) )
802 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
803 if( ScDrawObjData
* pCaptData
= ScDrawLayer::GetNoteCaptionData( pObj
, pViewData
->GetTabNo() ) )
805 if( ppCaptData
) *ppCaptData
= pCaptData
;
812 void ScDrawView::LockCalcLayer( SdrLayerID nLayer
, bool bLock
)
814 SdrLayer
* pLockLayer
= GetModel()->GetLayerAdmin().GetLayerPerID( nLayer
);
815 if( pLockLayer
&& (IsLayerLocked( pLockLayer
->GetName() ) != bLock
) )
816 SetLayerLocked( pLockLayer
->GetName(), bLock
);
819 void ScDrawView::MakeVisible( const Rectangle
& rRect
, vcl::Window
& rWin
)
821 //! rWin richtig auswerten
824 if ( pViewData
&& pViewData
->GetActiveWin() == &rWin
)
825 pViewData
->GetView()->MakeVisible( rRect
);
828 void ScDrawView::DeleteMarked()
830 // try to delete a note caption object with its cell note in the Calc document
831 ScDrawObjData
* pCaptData
= 0;
832 if( SdrObject
* pCaptObj
= GetMarkedNoteCaption( &pCaptData
) )
834 (void)pCaptObj
; // prevent 'unused variable' compiler warning in pro builds
835 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
836 ScDocShell
* pDocShell
= pViewData
? pViewData
->GetDocShell() : 0;
837 ::svl::IUndoManager
* pUndoMgr
= pDocShell
? pDocShell
->GetUndoManager() : 0;
838 bool bUndo
= pDrawLayer
&& pDocShell
&& pUndoMgr
&& pDoc
->IsUndoEnabled();
840 // remove the cell note from document, we are its owner now
841 ScPostIt
* pNote
= pDoc
->ReleaseNote( pCaptData
->maStart
);
842 OSL_ENSURE( pNote
, "ScDrawView::DeleteMarked - cell note missing in document" );
845 // rescue note data for undo (with pointer to caption object)
846 ScNoteData aNoteData
= pNote
->GetNoteData();
847 OSL_ENSURE( aNoteData
.mpCaption
== pCaptObj
, "ScDrawView::DeleteMarked - caption object does not match" );
848 // collect the drawing undo action created while deleting the note
850 pDrawLayer
->BeginCalcUndo(false);
851 // delete the note (already removed from document above)
853 // add the undo action for the note
855 pUndoMgr
->AddUndoAction( new ScUndoReplaceNote( *pDocShell
, pCaptData
->maStart
, aNoteData
, false, pDrawLayer
->GetCalcUndo() ) );
856 // repaint the cell to get rid of the note marker
858 pDocShell
->PostPaintCell( pCaptData
->maStart
);
859 // done, return now to skip call of FmFormView::DeleteMarked()
864 FmFormView::DeleteMarked();
867 SdrEndTextEditKind
ScDrawView::ScEndTextEdit()
869 bool bIsTextEdit
= IsTextEdit();
870 SdrEndTextEditKind eKind
= SdrEndTextEdit();
872 if ( bIsTextEdit
&& pViewData
)
873 pViewData
->GetViewShell()->SetDrawTextUndo(NULL
); // "normaler" Undo-Manager
878 void ScDrawView::MarkDropObj( SdrObject
* pObj
)
880 if ( pDropMarkObj
!= pObj
)
883 ImplClearCalcDropMarker();
887 pDropMarker
= new SdrDropMarkerOverlay(*this, *pDropMarkObj
);
892 // In order to counteract the effects of rounding due to the nature of how the
893 // grid positions are calcuated and drawn we calculate the offset needed at the
894 // current zoom to be applied to an SrdObject when it is drawn in order to make
895 // sure that it's position relative to the nearest cell anchor doesn't change.
896 // Of course not all shape(s)/control(s) are cell anchored, if the
897 // object doesn't have a cell anchor we synthesise a temporary anchor.
898 void ScDrawView::SyncForGrid( SdrObject
* pObj
)
900 // process members of a group shape separately
901 if ( pObj
->ISA( SdrObjGroup
) )
903 SdrObjList
*pLst
= static_cast<SdrObjGroup
*>(pObj
)->GetSubList();
904 for ( size_t i
= 0, nCount
= pLst
->GetObjCount(); i
< nCount
; ++i
)
905 SyncForGrid( pLst
->GetObj( i
) );
908 ScSplitPos eWhich
= pViewData
->GetActivePart();
909 ScGridWindow
* pGridWin
= pViewData
->GetActiveWin();
910 ScDrawObjData
* pData
= ScDrawLayer::GetObjData( pObj
);
914 if( pData
&& pData
->maStart
.IsValid())
916 aOldStt
= pData
->maStart
;
920 // Page anchored object so...
921 // synthesise an anchor ( but don't attach it to
922 // the object as we want to maintain page anchoring )
923 ScDrawObjData aAnchor
;
924 ScDrawLayer::GetCellAnchorFromPosition( *pObj
, aAnchor
, *pDoc
, GetTab() );
925 aOldStt
= aAnchor
.maStart
;
927 MapMode aDrawMode
= pGridWin
->GetDrawMapMode();
928 // find pos anchor position
929 Point
aOldPos( pDoc
->GetColOffset( aOldStt
.Col(), aOldStt
.Tab() ), pDoc
->GetRowOffset( aOldStt
.Row(), aOldStt
.Tab() ) );
930 aOldPos
.X() = sc::TwipsToHMM( aOldPos
.X() );
931 aOldPos
.Y() = sc::TwipsToHMM( aOldPos
.Y() );
932 // find position of same point on the screen ( e.g. grid )
933 Point aCurPos
= pViewData
->GetScrPos( aOldStt
.Col(), aOldStt
.Row(), eWhich
, true );
934 Point aCurPosHmm
= pGridWin
->PixelToLogic(aCurPos
, aDrawMode
);
935 Point aGridOff
= ( aCurPosHmm
- aOldPos
);
936 // fdo#63878 Fix the X position for RTL Sheet
937 if( pDoc
->IsNegativePage( GetTab() ) )
938 aGridOff
.setX( aCurPosHmm
.getX() + aOldPos
.getX() );
939 pObj
->SetGridOffset( aGridOff
);
943 // support enhanced text edit for draw objects
944 SdrUndoManager
* ScDrawView::getSdrUndoManagerForEnhancedTextEdit() const
946 return pDoc
? dynamic_cast< SdrUndoManager
* >(pDoc
->GetUndoManager()) : 0;
949 // #i123922# helper to apply a Graphic to an existing SdrObject
950 SdrObject
* ScDrawView::ApplyGraphicToObject(
951 SdrObject
& rHitObject
,
952 const Graphic
& rGraphic
,
953 const OUString
& rBeginUndoText
,
954 const OUString
& rFile
,
955 const OUString
& rFilter
)
957 if(dynamic_cast< SdrGrafObj
* >(&rHitObject
))
959 SdrGrafObj
* pNewGrafObj
= static_cast<SdrGrafObj
*>(rHitObject
.Clone());
961 pNewGrafObj
->SetGraphic(rGraphic
);
962 BegUndo(rBeginUndoText
);
963 ReplaceObjectAtView(&rHitObject
, *GetSdrPageView(), pNewGrafObj
);
965 // set in all cases - the Clone() will have copied an existing link (!)
966 pNewGrafObj
->SetGraphicLink( rFile
, ""/*TODO?*/, rFilter
);
971 else if(rHitObject
.IsClosedObj() && !dynamic_cast< SdrOle2Obj
* >(&rHitObject
))
973 AddUndo(new SdrUndoAttrObj(rHitObject
));
975 SfxItemSet
aSet(GetModel()->GetItemPool(), XATTR_FILLSTYLE
, XATTR_FILLBITMAP
);
977 aSet
.Put(XFillStyleItem(drawing::FillStyle_BITMAP
));
978 aSet
.Put(XFillBitmapItem(OUString(), rGraphic
));
979 rHitObject
.SetMergedItemSetAndBroadcast(aSet
);
986 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */