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 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
125 if( rMarkList
.GetMarkCount() )
128 pIPPEC
= dynamic_cast< IPolyPolygonEditorController
* >( mpView
->getSmartTags().getSelected().get() );
130 if ( !pIPPEC
|| !pIPPEC
->IsRipUpAtMarkedPointsPossible())
132 rSet
.DisableItem(SID_BEZIER_CUTLINE
);
134 if (!pIPPEC
|| !pIPPEC
->IsDeleteMarkedPointsPossible())
136 rSet
.DisableItem(SID_BEZIER_DELETE
);
138 if (!pIPPEC
|| !pIPPEC
->IsSetMarkedSegmentsKindPossible())
140 rSet
.DisableItem(SID_BEZIER_CONVERT
);
144 SdrPathSegmentKind eSegm
= pIPPEC
->GetMarkedSegmentsKind();
147 case SdrPathSegmentKind::DontCare
: rSet
.InvalidateItem(SID_BEZIER_CONVERT
); break;
148 case SdrPathSegmentKind::Line
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,false)); break; // Button down = curve
149 case SdrPathSegmentKind::Curve
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,true)); break;
153 if (!pIPPEC
|| !pIPPEC
->IsSetMarkedPointsSmoothPossible())
155 rSet
.DisableItem(SID_BEZIER_EDGE
);
156 rSet
.DisableItem(SID_BEZIER_SMOOTH
);
157 rSet
.DisableItem(SID_BEZIER_SYMMTR
);
161 SdrPathSmoothKind eSmooth
= pIPPEC
->GetMarkedPointsSmooth();
164 case SdrPathSmoothKind::DontCare
: break;
165 case SdrPathSmoothKind::Angular
: rSet
.Put(SfxBoolItem(SID_BEZIER_EDGE
, true)); break;
166 case SdrPathSmoothKind::Asymmetric
: rSet
.Put(SfxBoolItem(SID_BEZIER_SMOOTH
,true)); break;
167 case SdrPathSmoothKind::Symmetric
: rSet
.Put(SfxBoolItem(SID_BEZIER_SYMMTR
,true)); break;
170 if (!pIPPEC
|| !pIPPEC
->IsOpenCloseMarkedObjectsPossible())
172 rSet
.DisableItem(SID_BEZIER_CLOSE
);
176 SdrObjClosedKind eClose
= pIPPEC
->GetMarkedObjectsClosedState();
179 case SdrObjClosedKind::DontCare
: rSet
.InvalidateItem(SID_BEZIER_CLOSE
); break;
180 case SdrObjClosedKind::Open
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,false)); break;
181 case SdrObjClosedKind::Closed
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,true)); break;
187 rSet
.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS
, mpView
->IsEliminatePolyPoints()));
189 rSet
.DisableItem( SID_BEZIER_ELIMINATE_POINTS
); // only works for views
194 * Process SfxRequests
197 void BezierObjectBar::Execute(SfxRequest
& rReq
)
199 sal_uInt16 nSId
= rReq
.GetSlot();
203 case SID_BEZIER_CUTLINE
:
204 case SID_BEZIER_CONVERT
:
205 case SID_BEZIER_DELETE
:
206 case SID_BEZIER_EDGE
:
207 case SID_BEZIER_SMOOTH
:
208 case SID_BEZIER_SYMMTR
:
209 case SID_BEZIER_CLOSE
:
212 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
214 IPolyPolygonEditorController
* pIPPEC
= nullptr;
215 if( rMarkList
.GetMarkCount() )
218 pIPPEC
= dynamic_cast< IPolyPolygonEditorController
* >( mpView
->getSmartTags().getSelected().get() );
220 if( pIPPEC
&& !mpView
->IsAction())
224 case SID_BEZIER_DELETE
:
225 pIPPEC
->DeleteMarkedPoints();
228 case SID_BEZIER_CUTLINE
:
229 pIPPEC
->RipUpAtMarkedPoints();
232 case SID_BEZIER_CONVERT
:
234 pIPPEC
->SetMarkedSegmentsKind(SdrPathSegmentKind::Toggle
);
238 case SID_BEZIER_EDGE
:
239 case SID_BEZIER_SMOOTH
:
240 case SID_BEZIER_SYMMTR
:
242 SdrPathSmoothKind eKind
;
247 case SID_BEZIER_EDGE
: eKind
= SdrPathSmoothKind::Angular
; break;
248 case SID_BEZIER_SMOOTH
: eKind
= SdrPathSmoothKind::Asymmetric
; break;
249 case SID_BEZIER_SYMMTR
: eKind
= SdrPathSmoothKind::Symmetric
; break;
252 pIPPEC
->SetMarkedPointsSmooth(eKind
);
256 case SID_BEZIER_CLOSE
:
258 SdrPathObj
* pPathObj
= static_cast<SdrPathObj
*>( rMarkList
.GetMark(0)->GetMarkedSdrObj() );
259 const bool bUndo
= mpView
->IsUndoEnabled();
261 mpView
->BegUndo(SdResId(STR_UNDO_BEZCLOSE
));
263 mpView
->UnmarkAllPoints();
266 mpView
->AddUndo(mpView
->GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pPathObj
));
268 pPathObj
->ToggleClosed();
277 if( (pIPPEC
== mpView
) && rMarkList
.GetMarkCount() == 0 )
278 mpViewSh
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
284 case SID_BEZIER_ELIMINATE_POINTS
:
286 mpView
->SetEliminatePolyPoints(!mpView
->IsEliminatePolyPoints());
287 Invalidate(SID_BEZIER_ELIMINATE_POINTS
);
292 case SID_BEZIER_MOVE
:
293 case SID_BEZIER_INSERT
:
295 rtl::Reference
<FuPoor
> xFunc( mpViewSh
->GetCurrentFunction() );
299 if( auto pFuSelection
= dynamic_cast<FuSelection
*>( xFunc
.get() ))
301 pFuSelection
->SetEditMode(rReq
.GetSlot());
303 else if( auto pFuPolygon
= dynamic_cast<FuConstructBezierPolygon
*>( xFunc
.get() ))
305 pFuPolygon
->SetEditMode(rReq
.GetSlot());
320 } // end of namespace sd
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */