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 sal_uInt32 nCount
= rMrkList
.GetMarkCount();
139 for(sal_uInt32 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(aHdl
, 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_PARA_ADJUST_LEFT
);
179 rBindings
.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT
);
180 rBindings
.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK
);
181 rBindings
.Invalidate( SID_ATTR_PARA_ADJUST_CENTER
);
182 rBindings
.Invalidate( SID_ALIGNLEFT
);
183 rBindings
.Invalidate( SID_ALIGNCENTERHOR
);
184 rBindings
.Invalidate( SID_ALIGNRIGHT
);
185 rBindings
.Invalidate( SID_ALIGNBLOCK
);
186 rBindings
.Invalidate( SID_ATTR_PARA_LINESPACE_10
);
187 rBindings
.Invalidate( SID_ATTR_PARA_LINESPACE_15
);
188 rBindings
.Invalidate( SID_ATTR_PARA_LINESPACE_20
);
189 rBindings
.Invalidate( SID_SET_SUPER_SCRIPT
);
190 rBindings
.Invalidate( SID_SET_SUB_SCRIPT
);
191 rBindings
.Invalidate( SID_ATTR_CHAR_KERNING
);
192 rBindings
.Invalidate( SID_ATTR_CHAR_STRIKEOUT
);
193 rBindings
.Invalidate( SID_ATTR_CHAR_SHADOWED
);
194 rBindings
.Invalidate( SID_TEXTDIRECTION_LEFT_TO_RIGHT
);
195 rBindings
.Invalidate( SID_TEXTDIRECTION_TOP_TO_BOTTOM
);
196 rBindings
.Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT
);
197 rBindings
.Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT
);
198 rBindings
.Invalidate( SID_TABLE_VERT_NONE
);
199 rBindings
.Invalidate( SID_TABLE_VERT_CENTER
);
200 rBindings
.Invalidate( SID_TABLE_VERT_BOTTOM
);
201 // pseudo slots for Format menu
202 rBindings
.Invalidate( SID_ALIGN_ANY_LEFT
);
203 rBindings
.Invalidate( SID_ALIGN_ANY_HCENTER
);
204 rBindings
.Invalidate( SID_ALIGN_ANY_RIGHT
);
205 rBindings
.Invalidate( SID_ALIGN_ANY_JUSTIFIED
);
208 void ScDrawView::SetMarkedToLayer( sal_uInt8 nLayerNo
)
210 if (AreObjectsMarked())
212 // #i11702# use SdrUndoObjectLayerChange for undo
213 // STR_UNDO_SELATTR is "Attributes" - should use a different text later
214 BegUndo( ScGlobal::GetRscString( STR_UNDO_SELATTR
) );
216 const SdrMarkList
& rMark
= GetMarkedObjectList();
217 sal_uLong nCount
= rMark
.GetMarkCount();
218 for (sal_uLong i
=0; i
<nCount
; i
++)
220 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
221 if ( !pObj
->ISA(SdrUnoObj
) && (pObj
->GetLayer() != SC_LAYER_INTERN
) )
223 AddUndo( new SdrUndoObjectLayerChange( *pObj
, pObj
->GetLayer(), (SdrLayerID
)nLayerNo
) );
224 pObj
->SetLayer( nLayerNo
);
230 // repaint is done in SetLayer
232 pViewData
->GetDocShell()->SetDrawModified();
234 // check mark list now instead of later in a timer
236 MarkListHasChanged();
240 bool ScDrawView::HasMarkedControl() const
242 SdrObjListIter
aIter( GetMarkedObjectList() );
243 for( SdrObject
* pObj
= aIter
.Next(); pObj
; pObj
= aIter
.Next() )
244 if( pObj
->ISA( SdrUnoObj
) )
249 bool ScDrawView::HasMarkedInternal() const
251 // internal objects should not be inside a group, but who knows...
252 SdrObjListIter
aIter( GetMarkedObjectList() );
253 for( SdrObject
* pObj
= aIter
.Next(); pObj
; pObj
= aIter
.Next() )
254 if( pObj
->GetLayer() == SC_LAYER_INTERN
)
259 void ScDrawView::UpdateWorkArea()
261 SdrPage
* pPage
= GetModel()->GetPage(static_cast<sal_uInt16
>(nTab
));
265 Size
aPageSize( pPage
->GetSize() );
266 Rectangle
aNewArea( aPos
, aPageSize
);
267 if ( aPageSize
.Width() < 0 )
269 // RTL: from max.negative (left) to zero (right)
270 aNewArea
.Right() = 0;
271 aNewArea
.Left() = aPageSize
.Width() + 1;
273 SetWorkArea( aNewArea
);
277 OSL_FAIL("Page nicht gefunden");
281 void ScDrawView::DoCut()
284 BegUndo( ScGlobal::GetRscString( STR_UNDO_CUT
) );
285 DeleteMarked(); // auf dieser View - von der 505f Umstellung nicht betroffen
289 void ScDrawView::GetScale( Fraction
& rFractX
, Fraction
& rFractY
) const
295 void ScDrawView::RecalcScale()
299 Fraction
aZoomX(1,1);
300 Fraction
aZoomY(1,1);
304 nTab
= pViewData
->GetTabNo();
305 nPPTX
= pViewData
->GetPPTX();
306 nPPTY
= pViewData
->GetPPTY();
307 aZoomX
= pViewData
->GetZoomX();
308 aZoomY
= pViewData
->GetZoomY();
312 Point aLogic
= pDev
->LogicToPixel( Point(1000,1000), MAP_TWIP
);
313 nPPTX
= aLogic
.X() / 1000.0;
314 nPPTY
= aLogic
.Y() / 1000.0;
315 //! Zoom uebergeben ???
320 pDoc
->GetTableArea( nTab
, nEndCol
, nEndRow
);
326 ScDrawUtil::CalcScale( pDoc
, nTab
, 0,0, nEndCol
,nEndRow
, pDev
,aZoomX
,aZoomY
,nPPTX
,nPPTY
,
328 SdrPageView
* pPV
= GetSdrPageView();
329 if ( pViewData
&& pPV
)
331 if ( SdrPage
* pPage
= pPV
->GetPage() )
333 sal_uLong nCount
= pPage
->GetObjCount();
334 for ( sal_uLong i
= 0; i
< nCount
; i
++ )
336 SdrObject
* pObj
= pPage
->GetObj( i
);
337 // Align objects to nearset grid position
344 void ScDrawView::DoConnect(SdrOle2Obj
* pOleObj
)
347 pViewData
->GetViewShell()->ConnectObject( pOleObj
);
350 void ScDrawView::MarkListHasChanged()
352 FmFormView::MarkListHasChanged();
356 ScTabViewShell
* pViewSh
= pViewData
->GetViewShell();
358 // #i110829# remove the cell selection only if drawing objects are selected
359 if ( !bInConstruct
&& GetMarkedObjectList().GetMarkCount() )
361 pViewSh
->Unmark(); // remove cell selection
363 // end cell edit mode if drawing objects are selected
364 SC_MOD()->InputEnterHandler();
369 ScModule
* pScMod
= SC_MOD();
370 bool bUnoRefDialog
= pScMod
->IsRefDialogOpen() && pScMod
->GetCurRefDlgId() == WID_SIMPLE_REF
;
372 ScClient
* pClient
= (ScClient
*) pViewSh
->GetIPClient();
373 if ( pClient
&& pClient
->IsObjectInPlaceActive() && !bUnoRefDialog
)
375 // beim ViewShell::Activate aus dem Reset2Open nicht die Handles anzeigen
376 pClient
->DeactivateObject();
377 // Image-Ole wieder durch Grafik ersetzen passiert jetzt in ScClient::UIActivate
380 // Ole-Objekt selektiert?
382 SdrOle2Obj
* pOle2Obj
= NULL
;
383 SdrGrafObj
* pGrafObj
= NULL
;
385 const SdrMarkList
& rMarkList
= GetMarkedObjectList();
386 sal_uLong nMarkCount
= rMarkList
.GetMarkCount();
388 if ( nMarkCount
== 0 && !pViewData
->GetViewShell()->IsDrawSelMode() && !bInConstruct
)
390 // relock layers that may have been unlocked before
391 LockBackgroundLayer();
395 bool bSubShellSet
= false;
398 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
399 if (pObj
->GetObjIdentifier() == OBJ_OLE2
)
401 pOle2Obj
= (SdrOle2Obj
*) pObj
;
402 if (!pDoc
->IsChart(pObj
) )
403 pViewSh
->SetOleObjectShell(true);
405 pViewSh
->SetChartShell(true);
408 else if (pObj
->GetObjIdentifier() == OBJ_GRAF
)
410 pGrafObj
= (SdrGrafObj
*) pObj
;
411 pViewSh
->SetGraphicShell(true);
414 else if (pObj
->GetObjIdentifier() == OBJ_MEDIA
)
416 pViewSh
->SetMediaShell(true);
419 else if (pObj
->GetObjIdentifier() != OBJ_TEXT
// Verhindern, das beim Anlegen
420 || !pViewSh
->IsDrawTextShell()) // eines TextObjekts auf die
421 { // DrawShell umgeschaltet wird.
422 pViewSh
->SetDrawShell(true); //@#70206#
426 if ( nMarkCount
&& !bSubShellSet
)
428 bool bOnlyControls
= true;
429 bool bOnlyGraf
= true;
430 for (sal_uLong i
=0; i
<nMarkCount
; i
++)
432 SdrObject
* pObj
= rMarkList
.GetMark(i
)->GetMarkedSdrObj();
433 if ( pObj
->ISA( SdrObjGroup
) )
435 const SdrObjList
*pLst
= ((SdrObjGroup
*)pObj
)->GetSubList();
436 sal_uLong nListCount
= pLst
->GetObjCount();
437 if ( nListCount
== 0 )
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 bOnlyControls
= false;
444 for ( sal_uInt16 j
= 0; j
< nListCount
; ++j
)
446 SdrObject
*pSubObj
= pLst
->GetObj( j
);
448 if (!pSubObj
->ISA(SdrUnoObj
))
449 bOnlyControls
= false;
450 if (pSubObj
->GetObjIdentifier() != OBJ_GRAF
)
453 if ( !bOnlyControls
&& !bOnlyGraf
) break;
458 if (!pObj
->ISA(SdrUnoObj
))
459 bOnlyControls
= false;
460 if (pObj
->GetObjIdentifier() != OBJ_GRAF
)
464 if ( !bOnlyControls
&& !bOnlyGraf
) break;
469 pViewSh
->SetDrawFormShell(true); // jetzt UNO-Controls
473 pViewSh
->SetGraphicShell(true);
475 else if(nMarkCount
>1)
477 pViewSh
->SetDrawShell(true);
483 SfxViewFrame
* pViewFrame
= pViewSh
->GetViewFrame();
484 bool bOle
= pViewSh
->GetViewFrame()->GetFrame().IsInPlace();
485 uno::Sequence
< embed::VerbDescriptor
> aVerbs
;
486 if ( pOle2Obj
&& !bOle
)
488 uno::Reference
< embed::XEmbeddedObject
> xObj
= pOle2Obj
->GetObjRef();
489 OSL_ENSURE( xObj
.is(), "SdrOle2Obj ohne ObjRef" );
491 aVerbs
= xObj
->getSupportedVerbs();
493 pViewSh
->SetVerbs( aVerbs
);
498 UpdateIMap( pOle2Obj
);
500 UpdateIMap( pGrafObj
);
502 InvalidateAttribs(); // nach dem IMap-Editor Update
503 InvalidateDrawTextAttrs();
505 for(sal_uInt32
a(0L); a
< PaintWindowCount(); a
++)
507 SdrPaintWindow
* pPaintWindow
= GetPaintWindow(a
);
508 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
510 if(OUTDEV_WINDOW
== rOutDev
.GetOutDevType())
512 ((Window
&)rOutDev
).Update();
516 // uno object for view returns drawing objects as selection,
517 // so it must notify its SelectionChangeListeners
521 SfxFrame
& rFrame
= pViewFrame
->GetFrame();
522 uno::Reference
<frame::XController
> xController
= rFrame
.GetController();
523 if (xController
.is())
525 ScTabViewObj
* pImp
= ScTabViewObj::getImplementation( xController
);
527 pImp
->SelectionChanged();
531 // update selection transfer object
533 pViewSh
->CheckSelectionTransfer();
537 bool ScDrawView::SdrBeginTextEdit(
542 SdrOutliner
* pGivenOutliner
,
543 OutlinerView
* pGivenOutlinerView
,
544 bool bDontDeleteOutliner
,
548 const bool bRet
= FmFormView::SdrBeginTextEdit(
549 pObj
, pPV
, pWinL
, bIsNewObj
,
550 pGivenOutliner
, pGivenOutlinerView
, bDontDeleteOutliner
,
551 bOnlyOneView
, bGrabFocus
);
553 ScTabViewShell
* pViewSh
= pViewData
->GetViewShell();
554 if ( pViewSh
->GetViewFrame() )
556 SfxFrame
& rFrame
= pViewSh
->GetViewFrame()->GetFrame();
557 uno::Reference
< frame::XController
> xController
= rFrame
.GetController();
558 if (xController
.is())
560 ScTabViewObj
* pImp
= ScTabViewObj::getImplementation( xController
);
562 pImp
->SelectionChanged();
570 SdrEndTextEditKind
ScDrawView::SdrEndTextEdit( bool bDontDeleteReally
)
572 const SdrEndTextEditKind eRet
= FmFormView::SdrEndTextEdit( bDontDeleteReally
);
574 ScTabViewShell
* pViewSh
= pViewData
->GetViewShell();
575 if ( pViewSh
->GetViewFrame() )
577 SfxFrame
& rFrame
= pViewSh
->GetViewFrame()->GetFrame();
578 uno::Reference
< frame::XController
> xController
= rFrame
.GetController();
579 if (xController
.is())
581 ScTabViewObj
* pImp
= ScTabViewObj::getImplementation( xController
);
583 pImp
->SelectionChanged();
591 void ScDrawView::ModelHasChanged()
593 SdrObject
* pEditObj
= GetTextEditObject();
594 if ( pEditObj
&& !pEditObj
->IsInserted() && pViewData
)
596 // SdrObjEditView::ModelHasChanged will end text edit in this case,
597 // so make sure the EditEngine's undo manager is no longer used.
598 pViewData
->GetViewShell()->SetDrawTextUndo(NULL
);
599 SetCreateMode(); // don't leave FuText in a funny state
602 FmFormView::ModelHasChanged();
605 void ScDrawView::UpdateUserViewOptions()
609 const ScViewOptions
& rOpt
= pViewData
->GetOptions();
610 const ScGridOptions
& rGrid
= rOpt
.GetGridOptions();
612 SetDragStripes( rOpt
.GetOption( VOPT_HELPLINES
) );
613 SetMarkHdlSizePixel( SC_HANDLESIZE_BIG
);
615 SetGridVisible( rGrid
.GetGridVisible() );
616 SetSnapEnabled( rGrid
.GetUseGridSnap() );
617 SetGridSnap( rGrid
.GetUseGridSnap() );
619 Fraction
aFractX( rGrid
.GetFldDrawX(), rGrid
.GetFldDivisionX() + 1 );
620 Fraction
aFractY( rGrid
.GetFldDrawY(), rGrid
.GetFldDivisionY() + 1 );
621 SetSnapGridWidth( aFractX
, aFractY
);
623 SetGridCoarse( Size( rGrid
.GetFldDrawX(), rGrid
.GetFldDrawY() ) );
624 SetGridFine( Size( rGrid
.GetFldDrawX() / (rGrid
.GetFldDivisionX() + 1),
625 rGrid
.GetFldDrawY() / (rGrid
.GetFldDivisionY() + 1) ) );
629 SdrObject
* ScDrawView::GetObjectByName(const OUString
& rName
)
631 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
634 SdrModel
* pDrawLayer
= GetModel();
635 sal_uInt16 nTabCount
= pDoc
->GetTableCount();
636 for (sal_uInt16 i
=0; i
<nTabCount
; i
++)
638 SdrPage
* pPage
= pDrawLayer
->GetPage(i
);
639 DBG_ASSERT(pPage
,"Page ?");
642 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
643 SdrObject
* pObject
= aIter
.Next();
646 if ( ScDrawLayer::GetVisibleName( pObject
) == rName
)
650 pObject
= aIter
.Next();
658 //realize multi-selection of objects
660 bool ScDrawView::SelectCurrentViewObject( const OUString
& rName
)
662 sal_uInt16 nObjectTab
= 0;
663 SdrObject
* pFound
= NULL
;
664 bool bUnMark
= false;
665 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
668 SdrModel
* pDrawLayer
= GetModel();
669 sal_uInt16 nTabCount
= pDoc
->GetTableCount();
670 for (sal_uInt16 i
=0; i
<nTabCount
&& !pFound
; i
++)
672 SdrPage
* pPage
= pDrawLayer
->GetPage(i
);
673 DBG_ASSERT(pPage
,"Page ?");
676 SdrObjListIter
aIter( *pPage
, IM_DEEPWITHGROUPS
);
677 SdrObject
* pObject
= aIter
.Next();
678 while (pObject
&& !pFound
)
680 if ( ScDrawLayer::GetVisibleName( pObject
) == rName
)
685 pObject
= aIter
.Next();
692 ScTabView
* pView
= pViewData
->GetView();
693 if ( nObjectTab
!= nTab
) // Tabelle umschalten
694 pView
->SetTabNo( nObjectTab
);
695 DBG_ASSERT( nTab
== nObjectTab
, "Tabellen umschalten hat nicht geklappt" );
696 pView
->ScrollToObject( pFound
);
697 if ( pFound
->GetLayer() == SC_LAYER_BACK
&&
698 !pViewData
->GetViewShell()->IsDrawSelMode() &&
699 !pDoc
->IsTabProtected( nTab
) &&
700 !pViewData
->GetSfxDocShell()->IsReadOnly() )
702 SdrLayer
* pLayer
= GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_BACK
);
704 SetLayerLocked( pLayer
->GetName(), false );
706 SdrPageView
* pPV
= GetSdrPageView();
707 bUnMark
= IsObjMarked(pFound
);
708 MarkObj( pFound
, pPV
, bUnMark
);
713 bool ScDrawView::SelectObject( const OUString
& rName
)
717 SCTAB nObjectTab
= 0;
718 SdrObject
* pFound
= NULL
;
720 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
723 SdrModel
* pDrawLayer
= GetModel();
724 SCTAB nTabCount
= pDoc
->GetTableCount();
725 for (SCTAB i
=0; i
<nTabCount
&& !pFound
; i
++)
727 SdrPage
* pPage
= pDrawLayer
->GetPage(static_cast<sal_uInt16
>(i
));
728 OSL_ENSURE(pPage
,"Page ?");
731 SdrObjListIter
aIter( *pPage
, IM_DEEPWITHGROUPS
);
732 SdrObject
* pObject
= aIter
.Next();
733 while (pObject
&& !pFound
)
735 if ( ScDrawLayer::GetVisibleName( pObject
) == rName
)
740 pObject
= aIter
.Next();
748 ScTabView
* pView
= pViewData
->GetView();
749 if ( nObjectTab
!= nTab
) // Tabelle umschalten
750 pView
->SetTabNo( nObjectTab
);
752 OSL_ENSURE( nTab
== nObjectTab
, "Tabellen umschalten hat nicht geklappt" );
754 pView
->ScrollToObject( pFound
);
756 /* To select an object on the background layer, the layer has to
757 be unlocked even if exclusive drawing selection mode is not active
758 (this is reversed in MarkListHasChanged when nothing is selected) */
759 if ( pFound
->GetLayer() == SC_LAYER_BACK
&&
760 !pViewData
->GetViewShell()->IsDrawSelMode() &&
761 !pDoc
->IsTabProtected( nTab
) &&
762 !pViewData
->GetSfxDocShell()->IsReadOnly() )
764 UnlockBackgroundLayer();
767 SdrPageView
* pPV
= GetSdrPageView();
768 MarkObj( pFound
, pPV
);
771 return ( pFound
!= NULL
);
774 //If object is marked , return true , else return false .
775 bool ScDrawView::GetObjectIsMarked( SdrObject
* pObject
)
777 bool bisMarked
= false;
780 bisMarked
= IsObjMarked(pObject
);
785 bool ScDrawView::InsertObjectSafe(SdrObject
* pObj
, SdrPageView
& rPV
, sal_uLong nOptions
)
787 // Markierung nicht aendern, wenn Ole-Objekt aktiv
788 // (bei Drop aus Ole-Objekt wuerde sonst mitten im ExecuteDrag deaktiviert!)
792 SfxInPlaceClient
* pClient
= pViewData
->GetViewShell()->GetIPClient();
793 if ( pClient
&& pClient
->IsObjectInPlaceActive() )
794 nOptions
|= SDRINSERT_DONTMARK
;
797 return InsertObjectAtView( pObj
, rPV
, nOptions
);
800 SdrObject
* ScDrawView::GetMarkedNoteCaption( ScDrawObjData
** ppCaptData
)
802 const SdrMarkList
& rMarkList
= GetMarkedObjectList();
803 if( pViewData
&& (rMarkList
.GetMarkCount() == 1) )
805 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
806 if( ScDrawObjData
* pCaptData
= ScDrawLayer::GetNoteCaptionData( pObj
, pViewData
->GetTabNo() ) )
808 if( ppCaptData
) *ppCaptData
= pCaptData
;
815 void ScDrawView::LockCalcLayer( SdrLayerID nLayer
, bool bLock
)
817 SdrLayer
* pLockLayer
= GetModel()->GetLayerAdmin().GetLayerPerID( nLayer
);
818 if( pLockLayer
&& (IsLayerLocked( pLockLayer
->GetName() ) != bLock
) )
819 SetLayerLocked( pLockLayer
->GetName(), bLock
);
822 void ScDrawView::MakeVisible( const Rectangle
& rRect
, Window
& rWin
)
824 //! rWin richtig auswerten
827 if ( pViewData
&& pViewData
->GetActiveWin() == &rWin
)
828 pViewData
->GetView()->MakeVisible( rRect
);
831 void ScDrawView::DeleteMarked()
833 // try to delete a note caption object with its cell note in the Calc document
834 ScDrawObjData
* pCaptData
= 0;
835 if( SdrObject
* pCaptObj
= GetMarkedNoteCaption( &pCaptData
) )
837 (void)pCaptObj
; // prevent 'unused variable' compiler warning in pro builds
838 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
839 ScDocShell
* pDocShell
= pViewData
? pViewData
->GetDocShell() : 0;
840 ::svl::IUndoManager
* pUndoMgr
= pDocShell
? pDocShell
->GetUndoManager() : 0;
841 bool bUndo
= pDrawLayer
&& pDocShell
&& pUndoMgr
&& pDoc
->IsUndoEnabled();
843 // remove the cell note from document, we are its owner now
844 ScPostIt
* pNote
= pDoc
->ReleaseNote( pCaptData
->maStart
);
845 OSL_ENSURE( pNote
, "ScDrawView::DeleteMarked - cell note missing in document" );
848 // rescue note data for undo (with pointer to caption object)
849 ScNoteData aNoteData
= pNote
->GetNoteData();
850 OSL_ENSURE( aNoteData
.mpCaption
== pCaptObj
, "ScDrawView::DeleteMarked - caption object does not match" );
851 // collect the drawing undo action created while deleting the note
853 pDrawLayer
->BeginCalcUndo(false);
854 // delete the note (already removed from document above)
856 // add the undo action for the note
858 pUndoMgr
->AddUndoAction( new ScUndoReplaceNote( *pDocShell
, pCaptData
->maStart
, aNoteData
, false, pDrawLayer
->GetCalcUndo() ) );
859 // repaint the cell to get rid of the note marker
861 pDocShell
->PostPaintCell( pCaptData
->maStart
);
862 // done, return now to skip call of FmFormView::DeleteMarked()
867 FmFormView::DeleteMarked();
870 SdrEndTextEditKind
ScDrawView::ScEndTextEdit()
872 bool bIsTextEdit
= IsTextEdit();
873 SdrEndTextEditKind eKind
= SdrEndTextEdit();
875 if ( bIsTextEdit
&& pViewData
)
876 pViewData
->GetViewShell()->SetDrawTextUndo(NULL
); // "normaler" Undo-Manager
881 void ScDrawView::MarkDropObj( SdrObject
* pObj
)
883 if ( pDropMarkObj
!= pObj
)
886 ImplClearCalcDropMarker();
890 pDropMarker
= new SdrDropMarkerOverlay(*this, *pDropMarkObj
);
895 // In order to counteract the effects of rounding due to the nature of how the
896 // grid positions are calcuated and drawn we calculate the offset needed at the
897 // current zoom to be applied to an SrdObject when it is drawn in order to make
898 // sure that it's position relative to the nearest cell anchor doesn't change.
899 // Of course not all shape(s)/control(s) are cell anchored, if the
900 // object doesn't have a cell anchor we synthesise a temporary anchor.
901 void ScDrawView::SyncForGrid( SdrObject
* pObj
)
903 // process members of a group shape separately
904 if ( pObj
->ISA( SdrObjGroup
) )
906 SdrObjList
*pLst
= ((SdrObjGroup
*)pObj
)->GetSubList();
907 for ( sal_uLong i
= 0, nCount
= pLst
->GetObjCount(); i
< nCount
; ++i
)
908 SyncForGrid( pLst
->GetObj( i
) );
911 ScSplitPos eWhich
= pViewData
->GetActivePart();
912 ScGridWindow
* pGridWin
= (ScGridWindow
*)pViewData
->GetActiveWin();
913 ScDrawObjData
* pData
= ScDrawLayer::GetObjData( pObj
);
919 aOldStt
= pData
->maStart
;
923 // Page anchored object so...
924 // synthesise an anchor ( but don't attach it to
925 // the object as we want to maintain page anchoring )
926 ScDrawObjData aAnchor
;
927 ScDrawLayer::GetCellAnchorFromPosition( *pObj
, aAnchor
, *pDoc
, GetTab() );
928 aOldStt
= aAnchor
.maStart
;
930 MapMode aDrawMode
= pGridWin
->GetDrawMapMode();
931 // find pos anchor position
932 Point
aOldPos( pDoc
->GetColOffset( aOldStt
.Col(), aOldStt
.Tab() ), pDoc
->GetRowOffset( aOldStt
.Row(), aOldStt
.Tab() ) );
933 aOldPos
.X() = sc::TwipsToHMM( aOldPos
.X() );
934 aOldPos
.Y() = sc::TwipsToHMM( aOldPos
.Y() );
935 // find position of same point on the screen ( e.g. grid )
936 Point aCurPos
= pViewData
->GetScrPos( aOldStt
.Col(), aOldStt
.Row(), eWhich
, true );
937 Point aCurPosHmm
= pGridWin
->PixelToLogic(aCurPos
, aDrawMode
);
938 Point aGridOff
= ( aCurPosHmm
- aOldPos
);
939 // fdo#63878 Fix the X position for RTL Sheet
940 if( pDoc
->IsNegativePage( GetTab() ) )
941 aGridOff
.setX( aCurPosHmm
.getX() + aOldPos
.getX() );
942 pObj
->SetGridOffset( aGridOff
);
946 // support enhanced text edit for draw objects
947 SdrUndoManager
* ScDrawView::getSdrUndoManagerForEnhancedTextEdit() const
949 return pDoc
? dynamic_cast< SdrUndoManager
* >(pDoc
->GetUndoManager()) : 0;
952 // #i123922# helper to apply a Graphic to an existing SdrObject
953 SdrObject
* ScDrawView::ApplyGraphicToObject(
954 SdrObject
& rHitObject
,
955 const Graphic
& rGraphic
,
956 const OUString
& rBeginUndoText
,
957 const OUString
& rFile
,
958 const OUString
& rFilter
)
960 if(dynamic_cast< SdrGrafObj
* >(&rHitObject
))
962 SdrGrafObj
* pNewGrafObj
= (SdrGrafObj
*)rHitObject
.Clone();
964 pNewGrafObj
->SetGraphic(rGraphic
);
965 BegUndo(rBeginUndoText
);
966 ReplaceObjectAtView(&rHitObject
, *GetSdrPageView(), pNewGrafObj
);
968 // set in all cases - the Clone() will have copied an existing link (!)
969 pNewGrafObj
->SetGraphicLink( rFile
, ""/*TODO?*/, rFilter
);
974 else if(rHitObject
.IsClosedObj() && !dynamic_cast< SdrOle2Obj
* >(&rHitObject
))
976 AddUndo(new SdrUndoAttrObj(rHitObject
));
978 SfxItemSet
aSet(GetModel()->GetItemPool(), XATTR_FILLSTYLE
, XATTR_FILLBITMAP
);
980 aSet
.Put(XFillStyleItem(XFILL_BITMAP
));
981 aSet
.Put(XFillBitmapItem(OUString(), rGraphic
));
982 rHitObject
.SetMergedItemSetAndBroadcast(aSet
);
989 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */