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 <hintids.hxx>
21 #include <swtypes.hxx>
22 #include <sfx2/objface.hxx>
23 #include <sfx2/request.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/viewfrm.hxx>
26 #include <svx/svdview.hxx>
27 #include <svl/whiter.hxx>
28 #include <svx/swframevalidation.hxx>
29 #include <svx/anchorid.hxx>
30 #include <svx/hlnkitem.hxx>
31 #include <osl/diagnose.h>
32 #include <drawdoc.hxx>
34 #include <fmtornt.hxx>
36 #include <swmodule.hxx>
40 #include <viewopt.hxx>
41 #include <dcontact.hxx>
43 #include <drawbase.hxx>
44 #include <drwbassh.hxx>
45 #include <swdtflvr.hxx>
46 #include <svx/svditer.hxx>
47 #define ShellClass_SwDrawBaseShell
48 #include <sfx2/msg.hxx>
49 #include <swslots.hxx>
50 #include <svx/svxdlg.hxx>
51 #include <svx/svdogrp.hxx>
52 #include <vcl/unohelp2.hxx>
53 #include <swabstdlg.hxx>
55 #include <com/sun/star/text/HoriOrientation.hpp>
56 #include <com/sun/star/text/VertOrientation.hpp>
57 #include <com/sun/star/text/RelOrientation.hpp>
58 #include <com/sun/star/uno/Reference.hxx>
59 #include <IDocumentDrawModelAccess.hxx>
60 #include <fmtfollowtextflow.hxx>
61 #include <textboxhelper.hxx>
62 #include <svx/diagram/IDiagramHelper.hxx>
64 using namespace ::com::sun::star
;
65 using namespace css::beans
;
66 using namespace css::drawing
;
67 using namespace css::uno
;
69 SFX_IMPL_SUPERCLASS_INTERFACE(SwDrawBaseShell
, SwBaseShell
)
71 void SwDrawBaseShell::InitInterface_Impl()
76 SwDrawBaseShell::SwDrawBaseShell(SwView
&_rView
)
81 SwEditWin
& rWin
= GetView().GetEditWin();
83 rWin
.SetBezierMode(SID_BEZIER_MOVE
);
85 if ( !_rView
.GetDrawFuncPtr() )
86 _rView
.GetEditWin().StdDrawMode( SdrObjKind::NONE
, true );
88 SwTransferable::CreateSelection( GetShell() );
91 SwDrawBaseShell::~SwDrawBaseShell()
95 SwTransferable::ClearSelection( GetShell() );
98 void SwDrawBaseShell::Execute(SfxRequest
const &rReq
)
100 SwWrtShell
*pSh
= &GetShell();
101 SdrView
* pSdrView
= pSh
->GetDrawView();
102 const SfxItemSet
*pArgs
= rReq
.GetArgs();
103 sal_uInt16 nSlotId
= rReq
.GetSlot();
104 bool bChanged
= pSdrView
->GetModel().IsChanged();
105 pSdrView
->GetModel().SetChanged(false);
106 const SfxPoolItem
* pItem
= nullptr;
108 pArgs
->GetItemState(nSlotId
, false, &pItem
);
110 bool bAlignPossible
= pSh
->IsAlignPossible();
112 bool bTopParam
= true, bBottomParam
= true;
114 SfxBindings
& rBind
= GetView().GetViewFrame().GetBindings();
118 case FN_DRAW_WRAP_DLG
:
120 if(pSdrView
->AreObjectsMarked())
124 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
125 if( rMarkList
.GetMark(0) != nullptr )
128 RES_LR_SPACE
, RES_UL_SPACE
,
129 RES_SURROUND
, RES_SURROUND
,
130 RES_ANCHOR
, RES_ANCHOR
,
131 RES_WRAP_INFLUENCE_ON_OBJPOS
, RES_WRAP_INFLUENCE_ON_OBJPOS
,
132 SID_HTML_MODE
, SID_HTML_MODE
,
133 FN_DRAW_WRAP_DLG
, FN_DRAW_WRAP_DLG
>
136 aSet
.Put(SfxBoolItem(SID_HTML_MODE
,
137 0 != ::GetHtmlMode(pSh
->GetView().GetDocShell())));
139 aSet
.Put(SfxInt16Item(FN_DRAW_WRAP_DLG
, pSh
->GetLayerId().get()));
141 pSh
->GetObjAttr(aSet
);
142 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
143 ScopedVclPtr
<SfxAbstractDialog
> pDlg(pFact
->CreateSwWrapDlg(GetView().GetFrameWeld(), aSet
, pSh
));
145 if (pDlg
->Execute() == RET_OK
)
147 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
148 if(const SfxInt16Item
* pWrapItem
= pOutSet
->GetItemIfSet(FN_DRAW_WRAP_DLG
, false))
150 short nLayer
= pWrapItem
->GetValue();
152 pSh
->SelectionToHeaven();
154 pSh
->SelectionToHell();
157 pSh
->SetObjAttr(*pOutSet
);
165 case SID_ATTR_TRANSFORM
:
167 if(pSdrView
->AreObjectsMarked())
171 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
172 if( rMarkList
.GetMark(0) != nullptr )
174 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
175 VclPtr
<SfxAbstractTabDialog
> pDlg
;
176 bool bCaption
= false;
178 // Allowed anchorages:
179 RndStdIds nAnchor
= pSh
->GetAnchorId();
180 SvxAnchorIds nAllowedAnchors
= SvxAnchorIds::Paragraph
| SvxAnchorIds::Character
| SvxAnchorIds::Page
;
181 sal_uInt16 nHtmlMode
= ::GetHtmlMode(pSh
->GetView().GetDocShell());
183 if ( pSh
->IsFlyInFly() )
184 nAllowedAnchors
|= SvxAnchorIds::Fly
;
186 if (pObj
->GetObjIdentifier() == SdrObjKind::Caption
)
191 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
192 VclPtr
<AbstractSvxCaptionDialog
> pCaptionDlg
=
193 pFact
->CreateCaptionDialog( rReq
.GetFrameWeld(), pSdrView
, nAllowedAnchors
);
194 pDlg
.reset(pCaptionDlg
);
195 pCaptionDlg
->SetValidateFramePosLink( LINK(this, SwDrawBaseShell
, ValidatePosition
) );
199 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
200 VclPtr
<AbstractSvxTransformTabDialog
> pTransform
=
201 pFact
->CreateSvxTransformTabDialog(rReq
.GetFrameWeld(), nullptr, pSdrView
, nAllowedAnchors
);
202 pDlg
.reset(pTransform
);
203 pTransform
->SetValidateFramePosLink( LINK(this, SwDrawBaseShell
, ValidatePosition
) );
205 SfxItemSet
aNewAttr(pSdrView
->GetGeoAttrFromMarked());
207 const WhichRangesContainer
& pRange
= pDlg
->GetInputRanges( *aNewAttr
.GetPool() );
208 SfxItemSet
aSet( *aNewAttr
.GetPool(), pRange
);
209 FieldUnit eMetric
= ::GetDfltMetric( dynamic_cast<SwWebView
*>(&GetView()) != nullptr );
210 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC
, static_cast< sal_uInt16
>(eMetric
)) );
212 aSet
.Put( aNewAttr
, false );
215 pSdrView
->GetAttributes( aSet
);
217 aSet
.Put(SfxInt16Item(SID_ATTR_TRANSFORM_ANCHOR
, static_cast<sal_Int16
>(nAnchor
)));
220 aSet
.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_VERTICAL_TEXT
, pSh
->IsFrameVertical(true, bRTL
, bVertL2R
)));
221 aSet
.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_RTL_TEXT
, bRTL
));
223 SwFrameFormat
* pFrameFormat
= FindFrameFormat( pObj
);
225 aSet
.Put( pFrameFormat
->GetFormatAttr(RES_FOLLOW_TEXT_FLOW
) );
227 SwFormatVertOrient
aVOrient(pFrameFormat
->GetFormatAttr(RES_VERT_ORIENT
));
228 aSet
.Put(SfxInt16Item(SID_ATTR_TRANSFORM_VERT_ORIENT
, aVOrient
.GetVertOrient()));
229 aSet
.Put(SfxInt16Item(SID_ATTR_TRANSFORM_VERT_RELATION
, aVOrient
.GetRelationOrient() ));
230 aSet
.Put(SfxInt32Item(SID_ATTR_TRANSFORM_VERT_POSITION
, aVOrient
.GetPos()));
232 SwFormatHoriOrient
aHOrient(pFrameFormat
->GetFormatAttr(RES_HORI_ORIENT
));
233 aSet
.Put(SfxInt16Item(SID_ATTR_TRANSFORM_HORI_ORIENT
, aHOrient
.GetHoriOrient()));
234 aSet
.Put(SfxInt16Item(SID_ATTR_TRANSFORM_HORI_RELATION
, aHOrient
.GetRelationOrient() ));
235 aSet
.Put(SfxBoolItem(SID_ATTR_TRANSFORM_HORI_MIRROR
, aHOrient
.IsPosToggle()));
236 aSet
.Put(SfxInt32Item(SID_ATTR_TRANSFORM_HORI_POSITION
, aHOrient
.GetPos()));
238 aSet
.Put(SfxUInt16Item(SID_HTML_MODE
, nHtmlMode
));
240 pDlg
->SetInputSet( &aSet
);
242 pDlg
->StartExecuteAsync([bCaption
, bChanged
, pDlg
, pFrameFormat
, pSdrView
,
243 pSh
, &rMarkList
, this](
245 pSdrView
->GetModel().SetChanged(false);
247 if (nResult
== RET_OK
)
249 SwFormatVertOrient
aVOrientFinal(pFrameFormat
->GetFormatAttr(RES_VERT_ORIENT
));
250 SwFormatHoriOrient
aHOrientFinal(pFrameFormat
->GetFormatAttr(RES_HORI_ORIENT
));
252 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
253 pSh
->StartAllAction();
256 pSh
->StartUndo(SwUndoId::INSFMTATTR
);
258 pSdrView
->SetGeoAttrToMarked(*pOutSet
);
261 pSdrView
->SetAttributes(*pOutSet
);
264 SfxItemState::SET
!= pOutSet
->GetItemState(
265 SID_ATTR_TRANSFORM_POS_X
, false ) &&
266 SfxItemState::SET
!= pOutSet
->GetItemState(
267 SID_ATTR_TRANSFORM_POS_Y
, false );
269 SfxItemSetFixed
<RES_FRMATR_BEGIN
, RES_FRMATR_END
- 1> aFrameAttrSet(GetPool());
271 bool bSingleSelection
= rMarkList
.GetMarkCount() == 1;
273 if(const SfxInt16Item
* pAnchorItem
= pOutSet
->GetItemIfSet(
274 SID_ATTR_TRANSFORM_ANCHOR
, false))
276 if(!bSingleSelection
)
277 pSh
->ChgAnchor(static_cast<RndStdIds
>(pAnchorItem
278 ->GetValue()), false, bPosCorr
);
281 SwFormatAnchor
aAnchor(pFrameFormat
->GetAnchor());
282 aAnchor
.SetType(static_cast<RndStdIds
>(pAnchorItem
->GetValue()));
283 aFrameAttrSet
.Put( aAnchor
);
286 const SfxInt16Item
* pHoriOrient
=
287 pOutSet
->GetItemIfSet(SID_ATTR_TRANSFORM_HORI_ORIENT
, false);
288 const SfxInt16Item
* pHoriRelation
=
289 pOutSet
->GetItemIfSet(SID_ATTR_TRANSFORM_HORI_RELATION
, false);
290 const SfxInt32Item
* pHoriPosition
=
291 pOutSet
->GetItemIfSet(SID_ATTR_TRANSFORM_HORI_POSITION
, false);
292 const SfxBoolItem
* pHoriMirror
=
293 pOutSet
->GetItemIfSet(SID_ATTR_TRANSFORM_HORI_MIRROR
, false);
294 if(pHoriOrient
|| pHoriRelation
|| pHoriPosition
|| pHoriMirror
)
297 aHOrientFinal
.SetHoriOrient(pHoriOrient
->GetValue());
299 aHOrientFinal
.SetRelationOrient(pHoriRelation
->GetValue());
301 aHOrientFinal
.SetPos( pHoriPosition
->GetValue());
303 aHOrientFinal
.SetPosToggle( pHoriMirror
->GetValue());
304 aFrameAttrSet
.Put(aHOrientFinal
);
307 const SfxInt16Item
* pVertOrient
=
308 pOutSet
->GetItemIfSet(SID_ATTR_TRANSFORM_VERT_ORIENT
, false);
309 const SfxInt16Item
* pVertRelation
=
310 pOutSet
->GetItemIfSet(SID_ATTR_TRANSFORM_VERT_RELATION
, false);
311 const SfxInt32Item
* pVertPosition
=
312 pOutSet
->GetItemIfSet(SID_ATTR_TRANSFORM_VERT_POSITION
, false);
313 if(pVertOrient
|| pVertRelation
|| pVertPosition
)
316 aVOrientFinal
.SetVertOrient(pVertOrient
->GetValue());
318 aVOrientFinal
.SetRelationOrient(pVertRelation
->GetValue());
320 aVOrientFinal
.SetPos( pVertPosition
->GetValue());
321 aFrameAttrSet
.Put( aVOrientFinal
);
323 const SwFormatFollowTextFlow
* pFollowItem
=
324 pOutSet
->GetItemIfSet(RES_FOLLOW_TEXT_FLOW
, false);
326 aFrameAttrSet
.Put(*pFollowItem
);
328 if(aFrameAttrSet
.Count())
329 pSh
->SetDrawingAttr(aFrameAttrSet
);
331 GetView().GetViewFrame().GetBindings().InvalidateAll(false);
334 pSh
->EndUndo( SwUndoId::INSFMTATTR
);
339 if (pSdrView
->GetModel().IsChanged())
342 pSdrView
->GetModel().SetChanged();
350 pSh
->StartAllAction();
351 pSdrView
->SetGeoAttrToMarked( *pArgs
);
352 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
353 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
356 SwFrameFormat
* pFrameFormat
= FindFrameFormat(pObj
);
359 const SwFormatAnchor
& rAnchor
= pFrameFormat
->GetAnchor();
360 // Don't change shape position / size, just update the anchor doc model
362 pSh
->ChgAnchor(rAnchor
.GetAnchorId(), /*bSameOnly=*/true);
373 if (pSh
->IsObjSelected() && !pSdrView
->IsTextEdit())
377 const Point aPt
= pSh
->GetObjRect().TopLeft(); // tdf#150589
379 if( GetView().IsDrawRotate() )
381 pSh
->SetDragMode( SdrDragMode::Move
);
382 GetView().FlipDrawRotate();
386 pSh
->DelSelectedObj();
389 GetView().GetEditWin().IsObjectSelect() )
391 // If basic call, then back to the text shell, because the
392 // Basic otherwise has no possibility to return.
393 if (GetView().GetDrawFuncPtr())
395 GetView().GetDrawFuncPtr()->Deactivate();
396 GetView().SetDrawFuncPtr(nullptr);
398 GetView().LeaveDrawCreate(); // Switch to selection mode
401 if (pSh
->IsSelFrameMode())
403 pSh
->LeaveSelFrameMode();
404 // #105852# FME <- perhaps fixed by tdf#150589
405 static_cast<SwEditShell
*>(pSh
)->SetCursor(aPt
);
412 if (pSh
->IsObjSelected() > 1 && pSh
->IsGroupAllowed())
414 pSh
->GroupSelection();
415 rBind
.Invalidate(SID_UNGROUP
);
420 if (pSh
->IsGroupSelected(true) && pSh
->IsUnGroupAllowed())
422 pSh
->UnGroupSelection();
423 rBind
.Invalidate(SID_GROUP
);
427 case SID_ENTER_GROUP
:
428 if (pSh
->IsGroupSelected(false))
430 pSdrView
->EnterMarkedGroup();
431 rBind
.InvalidateAll(false);
435 case SID_LEAVE_GROUP
:
436 if (pSdrView
->IsGroupEntered())
438 pSdrView
->LeaveOneGroup();
439 rBind
.Invalidate(SID_ENTER_GROUP
);
440 rBind
.Invalidate(SID_UNGROUP
);
444 case SID_REGENERATE_DIAGRAM
:
445 case SID_EDIT_DIAGRAM
:
447 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
449 if (1 == rMarkList
.GetMarkCount())
451 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
453 // Support advanced DiagramHelper
454 if(nullptr != pObj
&& pObj
->isDiagram())
456 if(SID_REGENERATE_DIAGRAM
== nSlotId
)
458 pSdrView
->UnmarkAll();
459 pObj
->getDiagramHelper()->reLayout(*static_cast<SdrObjGroup
*>(pObj
));
460 pSdrView
->MarkObj(pObj
, pSdrView
->GetSdrPageView());
462 else // SID_EDIT_DIAGRAM
464 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
465 ScopedVclPtr
<VclAbstractDialog
> pDlg
= pFact
->CreateDiagramDialog(
466 GetView().GetFrameWeld(),
467 *static_cast<SdrObjGroup
*>(pObj
));
475 case SID_OBJECT_ALIGN_LEFT
:
476 case SID_OBJECT_ALIGN_CENTER
:
477 case SID_OBJECT_ALIGN_RIGHT
:
478 case SID_OBJECT_ALIGN_UP
:
479 case SID_OBJECT_ALIGN_MIDDLE
:
480 case SID_OBJECT_ALIGN_DOWN
:
482 if ( bAlignPossible
)
484 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
485 if (rMarkList
.GetMarkCount() == 1
486 && !SwTextBoxHelper::hasTextFrame(rMarkList
.GetMark(0)->GetMarkedSdrObj()))
488 sal_Int16 nHorizOrient
= -1, nVertOrient
= -1;
492 case SID_OBJECT_ALIGN_LEFT
:
493 nHorizOrient
= text::HoriOrientation::LEFT
;
495 case SID_OBJECT_ALIGN_CENTER
:
496 nHorizOrient
= text::HoriOrientation::CENTER
;
498 case SID_OBJECT_ALIGN_RIGHT
:
499 nHorizOrient
= text::HoriOrientation::RIGHT
;
501 case SID_OBJECT_ALIGN_UP
:
502 nVertOrient
= text::VertOrientation::TOP
;
504 case SID_OBJECT_ALIGN_MIDDLE
:
505 nVertOrient
= text::VertOrientation::CENTER
;
507 case SID_OBJECT_ALIGN_DOWN
:
508 nVertOrient
= text::VertOrientation::BOTTOM
;
514 if (nHorizOrient
!= -1)
517 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
518 SwFrameFormat
* pFrameFormat
= FindFrameFormat( pObj
);
519 SwFormatHoriOrient
aHOrient(pFrameFormat
->GetFormatAttr(RES_HORI_ORIENT
));
520 aHOrient
.SetHoriOrient( nHorizOrient
);
521 pFrameFormat
->SetFormatAttr(aHOrient
);
525 if (nVertOrient
!= -1)
528 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
529 SwFrameFormat
* pFrameFormat
= FindFrameFormat( pObj
);
530 SwFormatVertOrient
aVOrient(pFrameFormat
->GetFormatAttr(RES_VERT_ORIENT
));
531 aVOrient
.SetVertOrient( nVertOrient
);
532 pFrameFormat
->SetFormatAttr(aVOrient
);
542 case SID_OBJECT_ALIGN_LEFT
:
543 pSdrView
->AlignMarkedObjects(SdrHorAlign::Left
, SdrVertAlign::NONE
);
545 case SID_OBJECT_ALIGN_CENTER
:
546 pSdrView
->AlignMarkedObjects(SdrHorAlign::Center
, SdrVertAlign::NONE
);
548 case SID_OBJECT_ALIGN_RIGHT
:
549 pSdrView
->AlignMarkedObjects(SdrHorAlign::Right
, SdrVertAlign::NONE
);
551 case SID_OBJECT_ALIGN_UP
:
552 pSdrView
->AlignMarkedObjects(SdrHorAlign::NONE
, SdrVertAlign::Top
);
554 case SID_OBJECT_ALIGN_MIDDLE
:
555 pSdrView
->AlignMarkedObjects(SdrHorAlign::NONE
, SdrVertAlign::Center
);
557 case SID_OBJECT_ALIGN_DOWN
:
558 pSdrView
->AlignMarkedObjects(SdrHorAlign::NONE
, SdrVertAlign::Bottom
);
569 case SID_FRAME_TO_TOP
:
570 pSh
->SelectionToTop( bTopParam
);
574 bBottomParam
= false;
576 case SID_FRAME_TO_BOTTOM
:
577 pSh
->SelectionToBottom( bBottomParam
);
584 if(1 == pSdrView
->GetMarkedObjectCount())
587 SdrObject
* pSelected
= pSdrView
->GetMarkedObjectByIndex(0);
588 OSL_ENSURE(pSelected
, "DrawViewShell::FuTemp03: nMarkCount, but no object (!)");
589 OUString
aName(pSelected
->GetName());
591 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
592 ScopedVclPtr
<AbstractSvxObjectNameDialog
> pDlg(pFact
->CreateSvxObjectNameDialog(GetView().GetFrameWeld(), aName
));
594 pDlg
->SetCheckNameHdl(LINK(this, SwDrawBaseShell
, CheckGroupShapeNameHdl
));
596 if(RET_OK
== pDlg
->Execute())
598 const OUString aOrigName
= aName
;
599 pDlg
->GetName(aName
);
600 pSelected
->SetName(aName
);
603 // update accessibility sidebar object name if we modify the object name on the navigator bar
604 if (!aName
.isEmpty() && aOrigName
!= aName
)
606 if (SwNode
* pSwNode
= FindFrameFormat(pSelected
)->GetAnchor().GetAnchorNode())
607 pSwNode
->resetAndQueueAccessibilityCheck(true);
616 case FN_TITLE_DESCRIPTION_SHAPE
:
620 if(1 == pSdrView
->GetMarkedObjectCount())
622 SdrObject
* pSelected
= pSdrView
->GetMarkedObjectByIndex(0);
623 OSL_ENSURE(pSelected
, "DrawViewShell::FuTemp03: nMarkCount, but no object (!)");
624 OUString
aTitle(pSelected
->GetTitle());
625 OUString
aDescription(pSelected
->GetDescription());
626 bool isDecorative(pSelected
->IsDecorative());
628 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
629 ScopedVclPtr
<AbstractSvxObjectTitleDescDialog
> pDlg(pFact
->CreateSvxObjectTitleDescDialog(GetView().GetFrameWeld(),
630 aTitle
, aDescription
, isDecorative
));
632 if(RET_OK
== pDlg
->Execute())
634 pDlg
->GetTitle(aTitle
);
635 pDlg
->GetDescription(aDescription
);
636 pDlg
->IsDecorative(isDecorative
);
638 pSelected
->SetTitle(aTitle
);
639 pSelected
->SetDescription(aDescription
);
640 pSelected
->SetDecorative(isDecorative
);
649 case SID_OPEN_HYPERLINK
:
651 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
652 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
653 LoadURL(GetShell(), pObj
->getHyperlink(), LoadUrlFlags::NewView
,
654 /*rTargetFrameName=*/OUString());
658 case SID_EDIT_HYPERLINK
:
659 case SID_HYPERLINK_DIALOG
:
661 GetView().GetViewFrame().SetChildWindow(SID_HYPERLINK_DIALOG
, true);
665 case SID_HYPERLINK_SETLINK
:
669 const SvxHyperlinkItem
& rHLinkItem
= *static_cast<const SvxHyperlinkItem
*>(pItem
);
670 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
671 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
672 pObj
->setHyperlink(rHLinkItem
.GetURL());
677 case SID_REMOVE_HYPERLINK
:
679 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
680 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
681 pObj
->setHyperlink(OUString());
685 case SID_COPY_HYPERLINK_LOCATION
:
687 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
688 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
689 uno::Reference
<datatransfer::clipboard::XClipboard
> xClipboard
690 = GetView().GetEditWin().GetClipboard();
691 vcl::unohelper::TextDataObject::CopyStringTo(pObj
->getHyperlink(), xClipboard
);
696 OSL_ENSURE(false, "wrong Dispatcher");
701 if(nSlotId
>= SID_OBJECT_ALIGN_LEFT
&& nSlotId
<= SID_OBJECT_ALIGN_DOWN
)
702 rBind
.Invalidate(SID_ATTR_LONG_LRSPACE
);
703 if (pSdrView
->GetModel().IsChanged())
706 pSdrView
->GetModel().SetChanged();
710 // Checks whether a given name is allowed for a group shape
712 IMPL_LINK( SwDrawBaseShell
, CheckGroupShapeNameHdl
, AbstractSvxObjectNameDialog
&, rNameDialog
, bool )
714 SwWrtShell
&rSh
= GetShell();
715 SdrView
*pSdrView
= rSh
.GetDrawView();
716 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
717 OSL_ENSURE(rMarkList
.GetMarkCount() == 1, "wrong draw selection");
718 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
719 const OUString sCurrentName
= pObj
->GetName();
721 rNameDialog
.GetName(sNewName
);
723 if (sNewName
.isEmpty() || sCurrentName
== sNewName
)
728 SwDrawModel
* pModel
= rSh
.getIDocumentDrawModelAccess().GetDrawModel();
729 SdrObjListIter
aIter( pModel
->GetPage(0), SdrIterMode::DeepWithGroups
);
730 while( aIter
.IsMore() )
732 SdrObject
* pTempObj
= aIter
.Next();
733 if ( pObj
!= pTempObj
&& pTempObj
->GetName() == sNewName
)
743 void SwDrawBaseShell::GetState(SfxItemSet
& rSet
)
745 SwWrtShell
&rSh
= GetShell();
746 SdrView
* pSdrView
= rSh
.GetDrawViewWithValidMarkList();
747 SfxWhichIter
aIter( rSet
);
748 sal_uInt16 nWhich
= aIter
.FirstWhich();
749 bool bProtected
= rSh
.IsSelObjProtected(FlyProtectFlags::Content
) != FlyProtectFlags::NONE
;
751 if (!bProtected
) // Look in the parent
752 bProtected
|= rSh
.IsSelObjProtected( FlyProtectFlags::Content
|FlyProtectFlags::Parent
) != FlyProtectFlags::NONE
;
758 case FN_DRAW_WRAP_DLG
:
759 case SID_ATTR_TRANSFORM
:
760 case SID_FRAME_TO_TOP
:
761 case SID_FRAME_TO_BOTTOM
:
766 if( bProtected
|| !rSh
.IsObjSelected() )
767 rSet
.DisableItem( nWhich
);
770 if ( rSh
.IsObjSelected() < 2 || bProtected
|| !rSh
.IsGroupAllowed() )
771 rSet
.DisableItem( nWhich
);
774 if ( !rSh
.IsGroupSelected(true) || bProtected
|| !rSh
.IsUnGroupAllowed() )
775 rSet
.DisableItem( nWhich
);
777 case SID_ENTER_GROUP
:
778 if ( !rSh
.IsGroupSelected(false) )
779 rSet
.DisableItem( nWhich
);
781 case SID_LEAVE_GROUP
:
782 if ( !pSdrView
->IsGroupEntered() )
783 rSet
.DisableItem( nWhich
);
785 case SID_OBJECT_ALIGN_LEFT
:
786 case SID_OBJECT_ALIGN_CENTER
:
787 case SID_OBJECT_ALIGN_RIGHT
:
788 case SID_OBJECT_ALIGN_UP
:
789 case SID_OBJECT_ALIGN_MIDDLE
:
790 case SID_OBJECT_ALIGN_DOWN
:
791 case SID_OBJECT_ALIGN
:
793 bool bDisableThis
= false;
794 bool bDisableHoriz
= false;
795 bool bHoriz
= (nWhich
== SID_OBJECT_ALIGN_LEFT
|| nWhich
== SID_OBJECT_ALIGN_CENTER
||
796 nWhich
== SID_OBJECT_ALIGN_RIGHT
);
797 bool bVert
= (nWhich
== SID_OBJECT_ALIGN_UP
|| nWhich
== SID_OBJECT_ALIGN_MIDDLE
||
798 nWhich
== SID_OBJECT_ALIGN_DOWN
);
799 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
800 if ( !rSh
.IsAlignPossible() || bProtected
)
803 rSet
.DisableItem( nWhich
);
805 else if ( rSh
.GetAnchorId() == RndStdIds::FLY_AS_CHAR
)
807 //if only one object is selected it can only be vertically
808 // aligned because it is character bound
809 if( rMarkList
.GetMarkCount() == 1 )
811 bDisableHoriz
= true;
812 rSet
.DisableItem(SID_OBJECT_ALIGN_LEFT
);
813 rSet
.DisableItem(SID_OBJECT_ALIGN_CENTER
);
814 rSet
.DisableItem(SID_OBJECT_ALIGN_RIGHT
);
818 if (bHoriz
&& !bDisableThis
&& !bDisableHoriz
&&
819 rMarkList
.GetMarkCount() == 1)
821 sal_Int16 nHoriOrient
= -1;
824 case SID_OBJECT_ALIGN_LEFT
:
825 nHoriOrient
= text::HoriOrientation::LEFT
;
827 case SID_OBJECT_ALIGN_CENTER
:
828 nHoriOrient
= text::HoriOrientation::CENTER
;
830 case SID_OBJECT_ALIGN_RIGHT
:
831 nHoriOrient
= text::HoriOrientation::RIGHT
;
837 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
838 SwFrameFormat
* pFrameFormat
= FindFrameFormat(pObj
);
839 SwFormatHoriOrient
aHOrient(pFrameFormat
->GetFormatAttr(RES_HORI_ORIENT
));
840 rSet
.Put(SfxBoolItem(nWhich
, aHOrient
.GetHoriOrient() == nHoriOrient
));
843 if (bVert
&& !bDisableThis
&& rMarkList
.GetMarkCount() == 1)
845 sal_Int16 nVertOrient
= -1;
848 case SID_OBJECT_ALIGN_UP
:
849 nVertOrient
= text::VertOrientation::TOP
;
851 case SID_OBJECT_ALIGN_MIDDLE
:
852 nVertOrient
= text::VertOrientation::CENTER
;
854 case SID_OBJECT_ALIGN_DOWN
:
855 nVertOrient
= text::VertOrientation::BOTTOM
;
861 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
862 SwFrameFormat
* pFrameFormat
= FindFrameFormat(pObj
);
863 SwFormatVertOrient
aVOrient(pFrameFormat
->GetFormatAttr(RES_VERT_ORIENT
));
864 rSet
.Put(SfxBoolItem(nWhich
, aVOrient
.GetVertOrient() == nVertOrient
));
871 if(1 != pSdrView
->GetMarkedObjectCount())
873 rSet
.DisableItem( nWhich
);
879 case FN_TITLE_DESCRIPTION_SHAPE
:
881 const bool bIsWebView(nullptr != dynamic_cast<SwWebView
*>(&GetView()));
883 if(!bIsWebView
&& 1 != pSdrView
->GetMarkedObjectCount())
885 rSet
.DisableItem( nWhich
);
890 case SID_OPEN_HYPERLINK
:
891 case SID_EDIT_HYPERLINK
:
892 case SID_HYPERLINK_DIALOG
:
893 case SID_REMOVE_HYPERLINK
:
894 case SID_COPY_HYPERLINK_LOCATION
:
896 if (pSdrView
->GetMarkedObjectCount() != 1)
898 rSet
.DisableItem(nWhich
);
902 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
903 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
904 SdrObjKind nObjType
= pObj
->GetObjIdentifier();
906 // Only enable hyperlink for the following types
909 case SdrObjKind::PathFill
:
910 case SdrObjKind::CircleSection
:
911 case SdrObjKind::Line
:
912 case SdrObjKind::CustomShape
:
913 case SdrObjKind::Text
:
914 case SdrObjKind::Rectangle
:
915 case SdrObjKind::Caption
:
916 case SdrObjKind::Polygon
:
917 case SdrObjKind::PolyLine
:
918 case SdrObjKind::E3D_Scene
:
919 case SdrObjKind::Measure
:
920 case SdrObjKind::Edge
:
923 rSet
.DisableItem(nWhich
);
927 if (nWhich
== SID_OPEN_HYPERLINK
|| nWhich
== SID_REMOVE_HYPERLINK
928 || nWhich
== SID_EDIT_HYPERLINK
|| nWhich
== SID_COPY_HYPERLINK_LOCATION
)
930 if (pObj
->getHyperlink().isEmpty())
931 rSet
.DisableItem(nWhich
);
936 case SID_HYPERLINK_GETLINK
:
938 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
939 if (rMarkList
.GetMark(0) != nullptr)
941 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
942 OUString sHyperLink
= pObj
->getHyperlink();
943 SvxHyperlinkItem aHLinkItem
;
944 aHLinkItem
.SetURL(sHyperLink
);
945 rSet
.Put(aHLinkItem
);
950 case SID_REGENERATE_DIAGRAM
:
951 case SID_EDIT_DIAGRAM
:
954 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
955 if (nullptr != rMarkList
.GetMark(0))
957 SdrObject
* pObj(rMarkList
.GetMark(0)->GetMarkedSdrObj());
959 if(nullptr != pObj
&& pObj
->isDiagram())
967 rSet
.DisableItem(nWhich
);
974 nWhich
= aIter
.NextWhich();
978 void SwDrawBaseShell::GetDrawAttrStateForIFBX( SfxItemSet
& rSet
)
980 SwWrtShell
*pSh
= &GetShell();
981 SdrView
* pSdrView
= pSh
->GetDrawView();
982 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
983 if( rMarkList
.GetMark(0) != nullptr )
985 SfxItemSet
aNewAttr(pSdrView
->GetGeoAttrFromMarked());
986 rSet
.Put(aNewAttr
,false);
990 bool SwDrawBaseShell::Disable(SfxItemSet
& rSet
, sal_uInt16 nWhich
)
992 bool bDisable
= GetShell().IsSelObjProtected(FlyProtectFlags::Content
) != FlyProtectFlags::NONE
;
997 rSet
.DisableItem( nWhich
);
1000 SfxWhichIter
aIter( rSet
);
1001 nWhich
= aIter
.FirstWhich();
1004 rSet
.DisableItem( nWhich
);
1005 nWhich
= aIter
.NextWhich();
1013 void SwDrawBaseShell::DisableState( SfxItemSet
& rSet
)
1015 SwWrtShell
*pSh
= &GetShell();
1016 SdrView
* pSdrView
= pSh
->GetDrawView();
1017 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
1018 const size_t nMarkCount
= rMarkList
.GetMarkCount();
1019 bool bShowArea
= true, bShowMeasure
= true;
1021 for (size_t i
= 0; i
< nMarkCount
&& i
< 50; ++i
)
1023 SdrObject
* pObj
= rMarkList
.GetMark(i
)->GetMarkedSdrObj();
1024 SdrObjKind nObjType
= pObj
->GetObjIdentifier();
1026 if ( nObjType
!= SdrObjKind::Measure
)
1027 bShowMeasure
= false;
1029 // If marked object is 2D, disable format area command.
1030 if ( nObjType
== SdrObjKind::PolyLine
||
1031 nObjType
== SdrObjKind::Line
||
1032 nObjType
== SdrObjKind::PathLine
||
1033 nObjType
== SdrObjKind::FreehandLine
||
1034 nObjType
== SdrObjKind::Edge
||
1035 nObjType
== SdrObjKind::CircleArc
||
1039 if (!bShowArea
&& !bShowMeasure
)
1044 rSet
.DisableItem(SID_ATTRIBUTES_AREA
);
1047 rSet
.DisableItem(SID_MEASURE_DLG
);
1053 // Validate of drawing positions
1055 IMPL_LINK(SwDrawBaseShell
, ValidatePosition
, SvxSwFrameValidation
&, rValidation
, void )
1057 SwWrtShell
*pSh
= &GetShell();
1058 rValidation
.nMinHeight
= MINFLY
;
1059 rValidation
.nMinWidth
= MINFLY
;
1063 // OD 18.09.2003 #i18732# - adjustment for allowing vertical position
1064 // aligned to page for fly frame anchored to paragraph or to character.
1065 const RndStdIds eAnchorType
= rValidation
.nAnchorType
;
1066 const SwFormatAnchor
* pAnchor
= nullptr;
1067 SdrView
* pSdrView
= pSh
->GetDrawView();
1068 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
1069 if( rMarkList
.GetMarkCount() == 1 )
1071 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
1072 SwFrameFormat
* pFrameFormat
= FindFrameFormat( pObj
);
1073 pAnchor
= &pFrameFormat
->GetAnchor();
1076 pSh
->CalcBoundRect( aBoundRect
, eAnchorType
,
1077 rValidation
.nHRelOrient
,
1078 rValidation
.nVRelOrient
,
1080 rValidation
.bFollowTextFlow
,
1081 rValidation
.bMirror
, nullptr, &rValidation
.aPercentSize
);
1083 bool bIsInVertical( false );
1087 bIsInVertical
= pSh
->IsFrameVertical(true, bRTL
, bVertL2R
);
1091 Point
aPos(aBoundRect
.Pos());
1092 tools::Long nTmp
= aPos
.X();
1093 aPos
.setX( aPos
.Y() );
1095 Size
aSize(aBoundRect
.SSize());
1096 nTmp
= aSize
.Width();
1097 aSize
.setWidth( aSize
.Height() );
1098 aSize
.setHeight( nTmp
);
1099 aBoundRect
.Chg( aPos
, aSize
);
1100 //exchange width/height to enable correct values
1101 nTmp
= rValidation
.nWidth
;
1102 rValidation
.nWidth
= rValidation
.nHeight
;
1103 rValidation
.nHeight
= nTmp
;
1105 if ((eAnchorType
== RndStdIds::FLY_AT_PAGE
) || (eAnchorType
== RndStdIds::FLY_AT_FLY
))
1108 rValidation
.nMinHPos
= aBoundRect
.Left();
1109 rValidation
.nMinVPos
= aBoundRect
.Top();
1110 SwTwips nH
= rValidation
.nHPos
;
1111 SwTwips nV
= rValidation
.nVPos
;
1113 if (rValidation
.nHPos
+ rValidation
.nWidth
> aBoundRect
.Right())
1115 if (rValidation
.nHoriOrient
== text::HoriOrientation::NONE
)
1117 rValidation
.nHPos
-= ((rValidation
.nHPos
+ rValidation
.nWidth
) - aBoundRect
.Right());
1118 nH
= rValidation
.nHPos
;
1121 rValidation
.nWidth
= aBoundRect
.Right() - rValidation
.nHPos
;
1124 if (rValidation
.nHPos
+ rValidation
.nWidth
> aBoundRect
.Right())
1125 rValidation
.nWidth
= aBoundRect
.Right() - rValidation
.nHPos
;
1127 if (rValidation
.nVPos
+ rValidation
.nHeight
> aBoundRect
.Bottom())
1129 if (rValidation
.nVertOrient
== text::VertOrientation::NONE
)
1131 rValidation
.nVPos
-= ((rValidation
.nVPos
+ rValidation
.nHeight
) - aBoundRect
.Bottom());
1132 nV
= rValidation
.nVPos
;
1135 rValidation
.nHeight
= aBoundRect
.Bottom() - rValidation
.nVPos
;
1138 if (rValidation
.nVPos
+ rValidation
.nHeight
> aBoundRect
.Bottom())
1139 rValidation
.nHeight
= aBoundRect
.Bottom() - rValidation
.nVPos
;
1141 if ( rValidation
.nVertOrient
!= text::VertOrientation::NONE
)
1142 nV
= aBoundRect
.Top();
1144 if ( rValidation
.nHoriOrient
!= text::HoriOrientation::NONE
)
1145 nH
= aBoundRect
.Left();
1147 rValidation
.nMaxHPos
= aBoundRect
.Right() - rValidation
.nWidth
;
1148 rValidation
.nMaxHeight
= aBoundRect
.Bottom() - nV
;
1150 rValidation
.nMaxVPos
= aBoundRect
.Bottom() - rValidation
.nHeight
;
1151 rValidation
.nMaxWidth
= aBoundRect
.Right() - nH
;
1153 else if ((eAnchorType
== RndStdIds::FLY_AT_PARA
) || (eAnchorType
== RndStdIds::FLY_AT_CHAR
))
1155 if (rValidation
.nHPos
+ rValidation
.nWidth
> aBoundRect
.Right())
1157 if (rValidation
.nHoriOrient
== text::HoriOrientation::NONE
)
1159 rValidation
.nHPos
-= ((rValidation
.nHPos
+ rValidation
.nWidth
) - aBoundRect
.Right());
1162 rValidation
.nWidth
= aBoundRect
.Right() - rValidation
.nHPos
;
1165 // OD 29.09.2003 #i17567#, #i18732# - consider following the text flow
1166 // and alignment at page areas.
1167 const bool bMaxVPosAtBottom
= !rValidation
.bFollowTextFlow
||
1168 rValidation
.nVRelOrient
== text::RelOrientation::PAGE_FRAME
||
1169 rValidation
.nVRelOrient
== text::RelOrientation::PAGE_PRINT_AREA
||
1170 rValidation
.nVRelOrient
== text::RelOrientation::PAGE_PRINT_AREA_BOTTOM
;
1172 SwTwips nTmpMaxVPos
= ( bMaxVPosAtBottom
1173 ? aBoundRect
.Bottom()
1174 : aBoundRect
.Height() ) -
1175 rValidation
.nHeight
;
1176 if ( rValidation
.nVPos
> nTmpMaxVPos
)
1178 if (rValidation
.nVertOrient
== text::VertOrientation::NONE
)
1180 rValidation
.nVPos
= nTmpMaxVPos
;
1184 rValidation
.nHeight
= ( bMaxVPosAtBottom
1185 ? aBoundRect
.Bottom()
1186 : aBoundRect
.Height() ) - rValidation
.nVPos
;
1191 rValidation
.nMinHPos
= aBoundRect
.Left();
1192 rValidation
.nMaxHPos
= aBoundRect
.Right() - rValidation
.nWidth
;
1194 rValidation
.nMinVPos
= aBoundRect
.Top();
1195 // OD 26.09.2003 #i17567#, #i18732# - determine maximum vertical position
1196 if ( bMaxVPosAtBottom
)
1198 rValidation
.nMaxVPos
= aBoundRect
.Bottom() - rValidation
.nHeight
;
1202 rValidation
.nMaxVPos
= aBoundRect
.Height() - rValidation
.nHeight
;
1205 // Maximum width height
1206 const SwTwips nH
= ( rValidation
.nHoriOrient
!= text::HoriOrientation::NONE
)
1208 : rValidation
.nHPos
;
1209 const SwTwips nV
= ( rValidation
.nVertOrient
!= text::VertOrientation::NONE
)
1211 : rValidation
.nVPos
;
1212 rValidation
.nMaxHeight
= rValidation
.nMaxVPos
+ rValidation
.nHeight
- nV
;
1213 rValidation
.nMaxWidth
= rValidation
.nMaxHPos
+ rValidation
.nWidth
- nH
;
1215 else if (eAnchorType
== RndStdIds::FLY_AS_CHAR
)
1217 rValidation
.nMinHPos
= 0;
1218 rValidation
.nMaxHPos
= 0;
1220 rValidation
.nMaxHeight
= aBoundRect
.Height();
1221 rValidation
.nMaxWidth
= aBoundRect
.Width();
1223 rValidation
.nMaxVPos
= aBoundRect
.Height();
1224 rValidation
.nMinVPos
= -aBoundRect
.Height() + rValidation
.nHeight
;
1225 if (rValidation
.nMaxVPos
< rValidation
.nMinVPos
)
1227 rValidation
.nMinVPos
= rValidation
.nMaxVPos
;
1228 rValidation
.nMaxVPos
= -aBoundRect
.Height();
1233 //restore width/height exchange
1234 tools::Long nTmp
= rValidation
.nWidth
;
1235 rValidation
.nWidth
= rValidation
.nHeight
;
1236 rValidation
.nHeight
= nTmp
;
1239 if (rValidation
.nMaxWidth
< rValidation
.nWidth
)
1240 rValidation
.nWidth
= rValidation
.nMaxWidth
;
1241 if (rValidation
.nMaxHeight
< rValidation
.nHeight
)
1242 rValidation
.nHeight
= rValidation
.nMaxHeight
;
1245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */