cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / drbezob.cxx
blob5ffa21e149fe2c3269f7f9866cbbf5380618f4f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
40 #include <fusel.hxx>
41 #include <fuconbez.hxx>
43 using namespace sd;
44 #define ShellClass_BezierObjectBar
45 #include <sdslots.hxx>
47 namespace sd {
49 /**
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,
61 ::sd::View* pSdView)
62 : SfxShell(pSdViewShell->GetViewShell()),
63 mpView(pSdView),
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);
77 /**
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() );
89 if(xFunc.is())
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);
121 else
123 IPolyPolygonEditorController* pIPPEC = nullptr;
124 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
125 if( rMarkList.GetMarkCount() )
126 pIPPEC = mpView;
127 else
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);
142 else
144 SdrPathSegmentKind eSegm = pIPPEC->GetMarkedSegmentsKind();
145 switch (eSegm)
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;
150 default: break;
153 if (!pIPPEC || !pIPPEC->IsSetMarkedPointsSmoothPossible())
155 rSet.DisableItem(SID_BEZIER_EDGE);
156 rSet.DisableItem(SID_BEZIER_SMOOTH);
157 rSet.DisableItem(SID_BEZIER_SYMMTR);
159 else
161 SdrPathSmoothKind eSmooth = pIPPEC->GetMarkedPointsSmooth();
162 switch (eSmooth)
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);
174 else
176 SdrObjClosedKind eClose = pIPPEC->GetMarkedObjectsClosedState();
177 switch (eClose)
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;
182 default: break;
186 if(pIPPEC == mpView)
187 rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, mpView->IsEliminatePolyPoints()));
188 else
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();
201 switch (nSId)
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:
211 assert(mpView);
212 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
214 IPolyPolygonEditorController* pIPPEC = nullptr;
215 if( rMarkList.GetMarkCount() )
216 pIPPEC = mpView;
217 else
218 pIPPEC = dynamic_cast< IPolyPolygonEditorController* >( mpView->getSmartTags().getSelected().get() );
220 if( pIPPEC && !mpView->IsAction())
222 switch (nSId)
224 case SID_BEZIER_DELETE:
225 pIPPEC->DeleteMarkedPoints();
226 break;
228 case SID_BEZIER_CUTLINE:
229 pIPPEC->RipUpAtMarkedPoints();
230 break;
232 case SID_BEZIER_CONVERT:
234 pIPPEC->SetMarkedSegmentsKind(SdrPathSegmentKind::Toggle);
235 break;
238 case SID_BEZIER_EDGE:
239 case SID_BEZIER_SMOOTH:
240 case SID_BEZIER_SYMMTR:
242 SdrPathSmoothKind eKind;
244 switch (nSId)
246 default:
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);
253 break;
256 case SID_BEZIER_CLOSE:
258 SdrPathObj* pPathObj = static_cast<SdrPathObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
259 const bool bUndo = mpView->IsUndoEnabled();
260 if( bUndo )
261 mpView->BegUndo(SdResId(STR_UNDO_BEZCLOSE));
263 mpView->UnmarkAllPoints();
265 if( bUndo )
266 mpView->AddUndo(mpView->GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pPathObj));
268 pPathObj->ToggleClosed();
270 if( bUndo )
271 mpView->EndUndo();
272 break;
277 if( (pIPPEC == mpView) && rMarkList.GetMarkCount() == 0 )
278 mpViewSh->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
280 rReq.Ignore();
282 break;
284 case SID_BEZIER_ELIMINATE_POINTS:
286 mpView->SetEliminatePolyPoints(!mpView->IsEliminatePolyPoints());
287 Invalidate(SID_BEZIER_ELIMINATE_POINTS);
288 rReq.Done();
290 break;
292 case SID_BEZIER_MOVE:
293 case SID_BEZIER_INSERT:
295 rtl::Reference<FuPoor> xFunc( mpViewSh->GetCurrentFunction() );
297 if(xFunc.is())
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());
309 rReq.Ignore ();
311 break;
313 default:
314 break;
317 Invalidate();
320 } // end of namespace sd
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */