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 <BezierObjectBar.hxx>
21 #include <sfx2/msg.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <sfx2/objface.hxx>
25 #include <svx/svxids.hrc>
26 #include <svl/eitem.hxx>
27 #include <sfx2/request.hxx>
28 #include <svx/svdopath.hxx>
29 #include <svx/svdundo.hxx>
30 #include <sfx2/dispatch.hxx>
32 #include <sdresid.hxx>
35 #include <strings.hrc>
37 #include <DrawDocShell.hxx>
38 #include <ViewShell.hxx>
39 #include <drawdoc.hxx>
41 #include <fuconbez.hxx>
44 #define ShellClass_BezierObjectBar
45 #include <sdslots.hxx>
50 * Declare default interface (Slotmap must not be empty)
52 SFX_IMPL_INTERFACE(BezierObjectBar
, ::SfxShell
)
54 void BezierObjectBar::InitInterface_Impl()
59 BezierObjectBar::BezierObjectBar(
60 ViewShell
* pSdViewShell
,
62 : SfxShell(pSdViewShell
->GetViewShell()),
64 mpViewSh(pSdViewShell
)
66 DrawDocShell
* pDocShell
= mpViewSh
->GetDocSh();
67 SetPool(&pDocShell
->GetPool());
68 SetUndoManager(pDocShell
->GetUndoManager());
69 SetRepeatTarget(mpView
);
72 BezierObjectBar::~BezierObjectBar()
74 SetRepeatTarget(nullptr);
78 * Status of attribute items.
81 void BezierObjectBar::GetAttrState(SfxItemSet
& rSet
)
83 SfxItemSet
aAttrSet( mpView
->GetDoc().GetPool() );
84 mpView
->GetAttributes( aAttrSet
);
85 rSet
.Put(aAttrSet
, false); // <- sal_False, so DontCare-Status gets acquired
87 rtl::Reference
<FuPoor
> xFunc( mpViewSh
->GetCurrentFunction() );
91 if( auto pFuSelection
= dynamic_cast< const FuSelection
*>( xFunc
.get() ))
93 sal_uInt16 nEditMode
= pFuSelection
->GetEditMode();
94 rSet
.Put(SfxBoolItem(nEditMode
, true));
96 else if( auto pFuPolygon
= dynamic_cast< const FuConstructBezierPolygon
*>( xFunc
.get() ))
98 sal_uInt16 nEditMode
= pFuPolygon
->GetEditMode();
99 rSet
.Put(SfxBoolItem(nEditMode
, true));
103 if(!mpView
->IsMoveAllowed() || !mpView
->IsResizeAllowed())
105 // #i77187# if object is move and/or size protected, do not allow point editing at all
106 rSet
.DisableItem(SID_BEZIER_MOVE
);
107 rSet
.DisableItem(SID_BEZIER_INSERT
);
109 rSet
.DisableItem(SID_BEZIER_DELETE
);
110 rSet
.DisableItem(SID_BEZIER_CUTLINE
);
111 rSet
.DisableItem(SID_BEZIER_CONVERT
);
113 rSet
.DisableItem(SID_BEZIER_EDGE
);
114 rSet
.DisableItem(SID_BEZIER_SMOOTH
);
115 rSet
.DisableItem(SID_BEZIER_SYMMTR
);
117 rSet
.DisableItem(SID_BEZIER_CLOSE
);
119 rSet
.DisableItem(SID_BEZIER_ELIMINATE_POINTS
);
123 IPolyPolygonEditorController
* pIPPEC
= nullptr;
124 if( mpView
->GetMarkedObjectList().GetMarkCount() )
127 pIPPEC
= dynamic_cast< IPolyPolygonEditorController
* >( mpView
->getSmartTags().getSelected().get() );
129 if ( !pIPPEC
|| !pIPPEC
->IsRipUpAtMarkedPointsPossible())
131 rSet
.DisableItem(SID_BEZIER_CUTLINE
);
133 if (!pIPPEC
|| !pIPPEC
->IsDeleteMarkedPointsPossible())
135 rSet
.DisableItem(SID_BEZIER_DELETE
);
137 if (!pIPPEC
|| !pIPPEC
->IsSetMarkedSegmentsKindPossible())
139 rSet
.DisableItem(SID_BEZIER_CONVERT
);
143 SdrPathSegmentKind eSegm
= pIPPEC
->GetMarkedSegmentsKind();
146 case SdrPathSegmentKind::DontCare
: rSet
.InvalidateItem(SID_BEZIER_CONVERT
); break;
147 case SdrPathSegmentKind::Line
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,false)); break; // Button down = curve
148 case SdrPathSegmentKind::Curve
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,true)); break;
152 if (!pIPPEC
|| !pIPPEC
->IsSetMarkedPointsSmoothPossible())
154 rSet
.DisableItem(SID_BEZIER_EDGE
);
155 rSet
.DisableItem(SID_BEZIER_SMOOTH
);
156 rSet
.DisableItem(SID_BEZIER_SYMMTR
);
160 SdrPathSmoothKind eSmooth
= pIPPEC
->GetMarkedPointsSmooth();
163 case SdrPathSmoothKind::DontCare
: break;
164 case SdrPathSmoothKind::Angular
: rSet
.Put(SfxBoolItem(SID_BEZIER_EDGE
, true)); break;
165 case SdrPathSmoothKind::Asymmetric
: rSet
.Put(SfxBoolItem(SID_BEZIER_SMOOTH
,true)); break;
166 case SdrPathSmoothKind::Symmetric
: rSet
.Put(SfxBoolItem(SID_BEZIER_SYMMTR
,true)); break;
169 if (!pIPPEC
|| !pIPPEC
->IsOpenCloseMarkedObjectsPossible())
171 rSet
.DisableItem(SID_BEZIER_CLOSE
);
175 SdrObjClosedKind eClose
= pIPPEC
->GetMarkedObjectsClosedState();
178 case SdrObjClosedKind::DontCare
: rSet
.InvalidateItem(SID_BEZIER_CLOSE
); break;
179 case SdrObjClosedKind::Open
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,false)); break;
180 case SdrObjClosedKind::Closed
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,true)); break;
186 rSet
.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS
, mpView
->IsEliminatePolyPoints()));
188 rSet
.DisableItem( SID_BEZIER_ELIMINATE_POINTS
); // only works for views
193 * Process SfxRequests
196 void BezierObjectBar::Execute(SfxRequest
& rReq
)
198 sal_uInt16 nSId
= rReq
.GetSlot();
202 case SID_BEZIER_CUTLINE
:
203 case SID_BEZIER_CONVERT
:
204 case SID_BEZIER_DELETE
:
205 case SID_BEZIER_EDGE
:
206 case SID_BEZIER_SMOOTH
:
207 case SID_BEZIER_SYMMTR
:
208 case SID_BEZIER_CLOSE
:
210 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
212 IPolyPolygonEditorController
* pIPPEC
= nullptr;
213 if( rMarkList
.GetMarkCount() )
216 pIPPEC
= dynamic_cast< IPolyPolygonEditorController
* >( mpView
->getSmartTags().getSelected().get() );
218 if( pIPPEC
&& !mpView
->IsAction())
222 case SID_BEZIER_DELETE
:
223 pIPPEC
->DeleteMarkedPoints();
226 case SID_BEZIER_CUTLINE
:
227 pIPPEC
->RipUpAtMarkedPoints();
230 case SID_BEZIER_CONVERT
:
232 pIPPEC
->SetMarkedSegmentsKind(SdrPathSegmentKind::Toggle
);
236 case SID_BEZIER_EDGE
:
237 case SID_BEZIER_SMOOTH
:
238 case SID_BEZIER_SYMMTR
:
240 SdrPathSmoothKind eKind
;
245 case SID_BEZIER_EDGE
: eKind
= SdrPathSmoothKind::Angular
; break;
246 case SID_BEZIER_SMOOTH
: eKind
= SdrPathSmoothKind::Asymmetric
; break;
247 case SID_BEZIER_SYMMTR
: eKind
= SdrPathSmoothKind::Symmetric
; break;
250 pIPPEC
->SetMarkedPointsSmooth(eKind
);
254 case SID_BEZIER_CLOSE
:
256 SdrPathObj
* pPathObj
= static_cast<SdrPathObj
*>( rMarkList
.GetMark(0)->GetMarkedSdrObj() );
257 const bool bUndo
= mpView
->IsUndoEnabled();
259 mpView
->BegUndo(SdResId(STR_UNDO_BEZCLOSE
));
261 mpView
->UnmarkAllPoints();
264 mpView
->AddUndo(mpView
->GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pPathObj
));
266 pPathObj
->ToggleClosed();
275 if( (pIPPEC
== mpView
) && !mpView
->AreObjectsMarked() )
276 mpViewSh
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
282 case SID_BEZIER_ELIMINATE_POINTS
:
284 mpView
->SetEliminatePolyPoints(!mpView
->IsEliminatePolyPoints());
285 Invalidate(SID_BEZIER_ELIMINATE_POINTS
);
290 case SID_BEZIER_MOVE
:
291 case SID_BEZIER_INSERT
:
293 rtl::Reference
<FuPoor
> xFunc( mpViewSh
->GetCurrentFunction() );
297 if( auto pFuSelection
= dynamic_cast<FuSelection
*>( xFunc
.get() ))
299 pFuSelection
->SetEditMode(rReq
.GetSlot());
301 else if( auto pFuPolygon
= dynamic_cast<FuConstructBezierPolygon
*>( xFunc
.get() ))
303 pFuPolygon
->SetEditMode(rReq
.GetSlot());
318 } // end of namespace sd
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */