android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / view / drbezob.cxx
blob0db363aa21b25da1819424271b1230c81bdd1eae
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 if( mpView->GetMarkedObjectList().GetMarkCount() )
125 pIPPEC = mpView;
126 else
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);
141 else
143 SdrPathSegmentKind eSegm = pIPPEC->GetMarkedSegmentsKind();
144 switch (eSegm)
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;
149 default: break;
152 if (!pIPPEC || !pIPPEC->IsSetMarkedPointsSmoothPossible())
154 rSet.DisableItem(SID_BEZIER_EDGE);
155 rSet.DisableItem(SID_BEZIER_SMOOTH);
156 rSet.DisableItem(SID_BEZIER_SYMMTR);
158 else
160 SdrPathSmoothKind eSmooth = pIPPEC->GetMarkedPointsSmooth();
161 switch (eSmooth)
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);
173 else
175 SdrObjClosedKind eClose = pIPPEC->GetMarkedObjectsClosedState();
176 switch (eClose)
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;
181 default: break;
185 if(pIPPEC == mpView)
186 rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, mpView->IsEliminatePolyPoints()));
187 else
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();
200 switch (nSId)
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() )
214 pIPPEC = mpView;
215 else
216 pIPPEC = dynamic_cast< IPolyPolygonEditorController* >( mpView->getSmartTags().getSelected().get() );
218 if( pIPPEC && !mpView->IsAction())
220 switch (nSId)
222 case SID_BEZIER_DELETE:
223 pIPPEC->DeleteMarkedPoints();
224 break;
226 case SID_BEZIER_CUTLINE:
227 pIPPEC->RipUpAtMarkedPoints();
228 break;
230 case SID_BEZIER_CONVERT:
232 pIPPEC->SetMarkedSegmentsKind(SdrPathSegmentKind::Toggle);
233 break;
236 case SID_BEZIER_EDGE:
237 case SID_BEZIER_SMOOTH:
238 case SID_BEZIER_SYMMTR:
240 SdrPathSmoothKind eKind;
242 switch (nSId)
244 default:
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);
251 break;
254 case SID_BEZIER_CLOSE:
256 SdrPathObj* pPathObj = static_cast<SdrPathObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
257 const bool bUndo = mpView->IsUndoEnabled();
258 if( bUndo )
259 mpView->BegUndo(SdResId(STR_UNDO_BEZCLOSE));
261 mpView->UnmarkAllPoints();
263 if( bUndo )
264 mpView->AddUndo(mpView->GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pPathObj));
266 pPathObj->ToggleClosed();
268 if( bUndo )
269 mpView->EndUndo();
270 break;
275 if( (pIPPEC == mpView) && !mpView->AreObjectsMarked() )
276 mpViewSh->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
278 rReq.Ignore();
280 break;
282 case SID_BEZIER_ELIMINATE_POINTS:
284 mpView->SetEliminatePolyPoints(!mpView->IsEliminatePolyPoints());
285 Invalidate(SID_BEZIER_ELIMINATE_POINTS);
286 rReq.Done();
288 break;
290 case SID_BEZIER_MOVE:
291 case SID_BEZIER_INSERT:
293 rtl::Reference<FuPoor> xFunc( mpViewSh->GetCurrentFunction() );
295 if(xFunc.is())
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());
307 rReq.Ignore ();
309 break;
311 default:
312 break;
315 Invalidate();
318 } // end of namespace sd
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */