docthemes: Save themes def. to a file when added to ColorSets
[LibreOffice.git] / sw / source / uibase / shells / beziersh.cxx
blob7302e26e3f8428278067deef9daef006cd9141bb
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 <cmdid.h>
21 #include <svx/svdview.hxx>
22 #include <svl/eitem.hxx>
23 #include <svl/whiter.hxx>
24 #include <svx/svdopath.hxx>
25 #include <vcl/EnumContext.hxx>
26 #include <sfx2/request.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/objface.hxx>
29 #include <sfx2/viewfrm.hxx>
31 #include <wrtsh.hxx>
32 #include <view.hxx>
33 #include <edtwin.hxx>
34 #include <drawbase.hxx>
35 #include <beziersh.hxx>
36 #define ShellClass_SwBezierShell
37 #include <sfx2/msg.hxx>
38 #include <swslots.hxx>
40 SFX_IMPL_INTERFACE(SwBezierShell, SwBaseShell)
42 void SwBezierShell::InitInterface_Impl()
44 GetStaticInterface()->RegisterPopupMenu(u"draw"_ustr);
46 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Bezier_Toolbox_Sw);
50 SwBezierShell::SwBezierShell(SwView &_rView):
51 SwBaseShell( _rView )
53 SetName(u"Bezier"_ustr);
55 SwWrtShell *pSh = &GetShell();
56 SdrView* pSdrView = pSh->GetDrawView();
57 pSdrView->SetEliminatePolyPointLimitAngle(1500_deg100);
59 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Draw));
62 void SwBezierShell::Execute(SfxRequest const &rReq)
64 SwWrtShell *pSh = &GetShell();
65 SdrView* pSdrView = pSh->GetDrawView();
66 const SfxItemSet *pArgs = rReq.GetArgs();
67 sal_uInt16 nSlotId = rReq.GetSlot();
68 bool bChanged = pSdrView->GetModel().IsChanged();
69 pSdrView->GetModel().SetChanged(false);
70 const SfxPoolItem* pItem;
71 if(pArgs)
72 pArgs->GetItemState(nSlotId, false, &pItem);
74 switch (nSlotId)
76 case SID_DELETE:
77 case FN_BACKSPACE:
78 if (pSh->GetSelectedObjCount())
80 if (pSdrView->HasMarkedPoints())
81 pSh->GetView().GetViewFrame().GetDispatcher()->Execute(SID_BEZIER_DELETE);
82 else
84 pSh->DelSelectedObj();
85 if (pSh->IsSelFrameMode())
87 pSh->LeaveSelFrameMode();
88 pSh->NoEdit();
90 GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
93 break;
95 case FN_ESCAPE:
96 if (pSdrView->HasMarkedPoints())
97 pSdrView->UnmarkAllPoints();
98 else
100 if ( pSh->IsDrawCreate() )
102 GetView().GetDrawFuncPtr()->BreakCreate();
103 GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
105 else if ( pSh->HasSelection() || GetView().IsDrawMode() )
107 GetView().LeaveDrawCreate();
108 pSh->EnterStdMode();
109 GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
112 break;
114 case SID_BEZIER_MOVE:
115 case SID_BEZIER_INSERT:
117 GetView().GetEditWin().SetBezierMode(nSlotId);
118 static sal_uInt16 aInva[] =
120 SID_BEZIER_INSERT,
121 SID_BEZIER_MOVE,
124 GetView().GetViewFrame().GetBindings().Invalidate(aInva);
126 break;
128 case SID_BEZIER_DELETE:
129 case SID_BEZIER_CUTLINE:
130 case SID_BEZIER_CONVERT:
131 case SID_BEZIER_EDGE:
132 case SID_BEZIER_SMOOTH:
133 case SID_BEZIER_SYMMTR:
134 case SID_BEZIER_CLOSE:
135 case SID_BEZIER_ELIMINATE_POINTS:
137 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
139 if (rMarkList.GetMark(0) && !pSdrView->IsAction())
141 switch (nSlotId)
143 case SID_BEZIER_DELETE:
144 pSdrView->DeleteMarkedPoints();
145 break;
147 case SID_BEZIER_CUTLINE:
149 pSdrView->RipUpAtMarkedPoints();
150 pSh->CheckUnboundObjects();
152 break;
154 case SID_BEZIER_CONVERT:
156 pSdrView->SetMarkedSegmentsKind(SdrPathSegmentKind::Toggle);
157 break;
160 case SID_BEZIER_EDGE:
161 case SID_BEZIER_SMOOTH:
162 case SID_BEZIER_SYMMTR:
164 SdrPathSmoothKind eKind = SdrPathSmoothKind::Asymmetric;
166 switch (nSlotId)
168 case SID_BEZIER_EDGE: eKind = SdrPathSmoothKind::Angular; break;
169 case SID_BEZIER_SMOOTH: eKind = SdrPathSmoothKind::Asymmetric; break;
170 case SID_BEZIER_SYMMTR: eKind = SdrPathSmoothKind::Symmetric; break;
173 SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
174 if (eKind != eSmooth)
176 pSdrView->SetMarkedPointsSmooth(eKind);
178 static sal_uInt16 aInva[] =
180 SID_BEZIER_SMOOTH,
181 SID_BEZIER_EDGE,
182 SID_BEZIER_SYMMTR,
185 GetView().GetViewFrame().GetBindings().Invalidate(aInva);
187 break;
190 case SID_BEZIER_CLOSE:
192 SdrPathObj* pPathObj = static_cast<SdrPathObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
193 pSdrView->UnmarkAllPoints();
194 // Size aDist(GetView().GetEditWin().PixelToLogic(Size(8,8)));
195 pPathObj->ToggleClosed(); // aDist.Width());
196 break;
199 case SID_BEZIER_ELIMINATE_POINTS:
200 pSdrView->SetEliminatePolyPoints(!pSdrView->IsEliminatePolyPoints());
201 break;
205 break;
207 default:
208 break;
211 if (pSdrView->GetModel().IsChanged())
212 GetShell().SetModified();
213 else if (bChanged)
214 pSdrView->GetModel().SetChanged();
217 void SwBezierShell::GetState(SfxItemSet &rSet)
219 SdrView* pSdrView = GetShell().GetDrawView();
221 SfxWhichIter aIter( rSet );
222 sal_uInt16 nWhich = aIter.FirstWhich();
224 while( nWhich )
226 switch( nWhich )
228 case SID_BEZIER_MOVE:
229 case SID_BEZIER_INSERT:
231 sal_uInt16 nEditMode = GetView().GetEditWin().GetBezierMode();
233 rSet.Put(SfxBoolItem(nWhich, nEditMode == nWhich));
235 break;
237 case SID_BEZIER_CUTLINE:
238 if (!pSdrView->IsRipUpAtMarkedPointsPossible())
240 rSet.DisableItem(SID_BEZIER_CUTLINE);
242 break;
244 case SID_BEZIER_DELETE:
245 if (!pSdrView->IsDeleteMarkedPointsPossible())
247 rSet.DisableItem(SID_BEZIER_DELETE);
249 break;
251 case SID_BEZIER_CONVERT:
252 if (!pSdrView->IsSetMarkedSegmentsKindPossible())
254 rSet.DisableItem(SID_BEZIER_CONVERT);
256 else
258 SdrPathSegmentKind eSegm = pSdrView->GetMarkedSegmentsKind();
259 switch (eSegm)
261 case SdrPathSegmentKind::DontCare: rSet.InvalidateItem(SID_BEZIER_CONVERT); break;
262 case SdrPathSegmentKind::Line : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,false)); break; // Button pressed = curve
263 case SdrPathSegmentKind::Curve : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,true)); break;
264 default:; //prevent warning
267 break;
269 case SID_BEZIER_EDGE:
270 case SID_BEZIER_SMOOTH:
271 case SID_BEZIER_SYMMTR:
272 if (!pSdrView->IsSetMarkedPointsSmoothPossible())
273 rSet.DisableItem(nWhich);
274 else
276 SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
277 bool bEnable = false;
278 switch (eSmooth)
280 case SdrPathSmoothKind::DontCare :
281 break;
282 case SdrPathSmoothKind::Angular :
283 bEnable = nWhich == SID_BEZIER_EDGE;
284 break;
285 case SdrPathSmoothKind::Asymmetric:
286 bEnable = nWhich == SID_BEZIER_SMOOTH;
287 break;
288 case SdrPathSmoothKind::Symmetric :
289 bEnable = nWhich == SID_BEZIER_SYMMTR;
290 break;
292 rSet.Put(SfxBoolItem(nWhich, bEnable));
294 break;
296 case SID_BEZIER_CLOSE:
297 if (!pSdrView->IsOpenCloseMarkedObjectsPossible())
299 rSet.DisableItem(SID_BEZIER_CLOSE);
301 else
303 SdrObjClosedKind eClose = pSdrView->GetMarkedObjectsClosedState();
304 switch (eClose)
306 case SdrObjClosedKind::DontCare: rSet.InvalidateItem(SID_BEZIER_CLOSE); break;
307 case SdrObjClosedKind::Open : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,false)); break;
308 case SdrObjClosedKind::Closed : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,true)); break;
309 default:; //prevent warning
312 break;
314 case SID_BEZIER_ELIMINATE_POINTS:
315 rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, pSdrView->IsEliminatePolyPoints()));
316 break;
318 default:
319 break;
321 nWhich = aIter.NextWhich();
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */