/src/libreoffice/sw/source/uibase/shells/beziersh.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
30 | | |
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> |
39 | | |
40 | | SFX_IMPL_INTERFACE(SwBezierShell, SwBaseShell) |
41 | | |
42 | | void SwBezierShell::InitInterface_Impl() |
43 | 9 | { |
44 | 9 | GetStaticInterface()->RegisterPopupMenu(u"draw"_ustr); |
45 | | |
46 | 9 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Bezier_Toolbox_Sw); |
47 | 9 | } |
48 | | |
49 | | |
50 | | SwBezierShell::SwBezierShell(SwView &_rView): |
51 | 0 | SwBaseShell( _rView ) |
52 | 0 | { |
53 | 0 | SetName(u"Bezier"_ustr); |
54 | |
|
55 | 0 | SwWrtShell *pSh = &GetShell(); |
56 | 0 | SdrView* pSdrView = pSh->GetDrawView(); |
57 | 0 | pSdrView->SetEliminatePolyPointLimitAngle(1500_deg100); |
58 | |
|
59 | 0 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Draw)); |
60 | 0 | } |
61 | | |
62 | | void SwBezierShell::Execute(SfxRequest const &rReq) |
63 | 0 | { |
64 | 0 | SwWrtShell *pSh = &GetShell(); |
65 | 0 | SdrView* pSdrView = pSh->GetDrawView(); |
66 | 0 | const SfxItemSet *pArgs = rReq.GetArgs(); |
67 | 0 | sal_uInt16 nSlotId = rReq.GetSlot(); |
68 | 0 | bool bChanged = pSdrView->GetModel().IsChanged(); |
69 | 0 | pSdrView->GetModel().SetChanged(false); |
70 | 0 | const SfxPoolItem* pItem; |
71 | 0 | if(pArgs) |
72 | 0 | pArgs->GetItemState(nSlotId, false, &pItem); |
73 | |
|
74 | 0 | switch (nSlotId) |
75 | 0 | { |
76 | 0 | case SID_DELETE: |
77 | 0 | case FN_BACKSPACE: |
78 | 0 | if (pSh->GetSelectedObjCount()) |
79 | 0 | { |
80 | 0 | if (pSdrView->HasMarkedPoints()) |
81 | 0 | pSh->GetView().GetViewFrame().GetDispatcher()->Execute(SID_BEZIER_DELETE); |
82 | 0 | else |
83 | 0 | { |
84 | 0 | pSh->DelSelectedObj(); |
85 | 0 | if (pSh->IsSelFrameMode()) |
86 | 0 | { |
87 | 0 | pSh->LeaveSelFrameMode(); |
88 | 0 | pSh->NoEdit(); |
89 | 0 | } |
90 | 0 | GetView().AttrChangedNotify(nullptr); // Shell change if applicable... |
91 | 0 | } |
92 | 0 | } |
93 | 0 | break; |
94 | | |
95 | 0 | case FN_ESCAPE: |
96 | 0 | if (pSdrView->HasMarkedPoints()) |
97 | 0 | pSdrView->UnmarkAllPoints(); |
98 | 0 | else |
99 | 0 | { |
100 | 0 | if ( pSh->IsDrawCreate() ) |
101 | 0 | { |
102 | 0 | GetView().GetDrawFuncPtr()->BreakCreate(); |
103 | 0 | GetView().AttrChangedNotify(nullptr); // Shell change if applicable... |
104 | 0 | } |
105 | 0 | else if ( pSh->HasSelection() || GetView().IsDrawMode() ) |
106 | 0 | { |
107 | 0 | GetView().LeaveDrawCreate(); |
108 | 0 | pSh->EnterStdMode(); |
109 | 0 | GetView().AttrChangedNotify(nullptr); // Shell change if applicable... |
110 | 0 | } |
111 | 0 | } |
112 | 0 | break; |
113 | | |
114 | 0 | case SID_BEZIER_MOVE: |
115 | 0 | case SID_BEZIER_INSERT: |
116 | 0 | { |
117 | 0 | GetView().GetEditWin().SetBezierMode(nSlotId); |
118 | 0 | static const sal_uInt16 aInva[] = |
119 | 0 | { |
120 | 0 | SID_BEZIER_INSERT, |
121 | 0 | SID_BEZIER_MOVE, |
122 | 0 | 0 |
123 | 0 | }; |
124 | 0 | GetView().GetViewFrame().GetBindings().Invalidate(aInva); |
125 | 0 | } |
126 | 0 | break; |
127 | | |
128 | 0 | case SID_BEZIER_DELETE: |
129 | 0 | case SID_BEZIER_CUTLINE: |
130 | 0 | case SID_BEZIER_CONVERT: |
131 | 0 | case SID_BEZIER_EDGE: |
132 | 0 | case SID_BEZIER_SMOOTH: |
133 | 0 | case SID_BEZIER_SYMMTR: |
134 | 0 | case SID_BEZIER_CLOSE: |
135 | 0 | case SID_BEZIER_ELIMINATE_POINTS: |
136 | 0 | { |
137 | 0 | const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList(); |
138 | |
|
139 | 0 | if (rMarkList.GetMark(0) && !pSdrView->IsAction()) |
140 | 0 | { |
141 | 0 | switch (nSlotId) |
142 | 0 | { |
143 | 0 | case SID_BEZIER_DELETE: |
144 | 0 | pSdrView->DeleteMarkedPoints(); |
145 | 0 | break; |
146 | | |
147 | 0 | case SID_BEZIER_CUTLINE: |
148 | 0 | { |
149 | 0 | pSdrView->RipUpAtMarkedPoints(); |
150 | 0 | pSh->CheckUnboundObjects(); |
151 | 0 | } |
152 | 0 | break; |
153 | | |
154 | 0 | case SID_BEZIER_CONVERT: |
155 | 0 | { |
156 | 0 | pSdrView->SetMarkedSegmentsKind(SdrPathSegmentKind::Toggle); |
157 | 0 | break; |
158 | 0 | } |
159 | | |
160 | 0 | case SID_BEZIER_EDGE: |
161 | 0 | case SID_BEZIER_SMOOTH: |
162 | 0 | case SID_BEZIER_SYMMTR: |
163 | 0 | { |
164 | 0 | SdrPathSmoothKind eKind = SdrPathSmoothKind::Asymmetric; |
165 | |
|
166 | 0 | switch (nSlotId) |
167 | 0 | { |
168 | 0 | case SID_BEZIER_EDGE: eKind = SdrPathSmoothKind::Angular; break; |
169 | 0 | case SID_BEZIER_SMOOTH: eKind = SdrPathSmoothKind::Asymmetric; break; |
170 | 0 | case SID_BEZIER_SYMMTR: eKind = SdrPathSmoothKind::Symmetric; break; |
171 | 0 | } |
172 | | |
173 | 0 | SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth(); |
174 | 0 | if (eKind != eSmooth) |
175 | 0 | { |
176 | 0 | pSdrView->SetMarkedPointsSmooth(eKind); |
177 | |
|
178 | 0 | static const sal_uInt16 aInva[] = |
179 | 0 | { |
180 | 0 | SID_BEZIER_SMOOTH, |
181 | 0 | SID_BEZIER_EDGE, |
182 | 0 | SID_BEZIER_SYMMTR, |
183 | 0 | 0 |
184 | 0 | }; |
185 | 0 | GetView().GetViewFrame().GetBindings().Invalidate(aInva); |
186 | 0 | } |
187 | 0 | break; |
188 | 0 | } |
189 | | |
190 | 0 | case SID_BEZIER_CLOSE: |
191 | 0 | { |
192 | 0 | SdrPathObj* pPathObj = static_cast<SdrPathObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() ); |
193 | 0 | pSdrView->UnmarkAllPoints(); |
194 | | // Size aDist(GetView().GetEditWin().PixelToLogic(Size(8,8))); |
195 | 0 | pPathObj->ToggleClosed(); // aDist.Width()); |
196 | 0 | break; |
197 | 0 | } |
198 | | |
199 | 0 | case SID_BEZIER_ELIMINATE_POINTS: |
200 | 0 | pSdrView->SetEliminatePolyPoints(!pSdrView->IsEliminatePolyPoints()); |
201 | 0 | break; |
202 | 0 | } |
203 | 0 | } |
204 | 0 | } |
205 | 0 | break; |
206 | | |
207 | 0 | default: |
208 | 0 | break; |
209 | 0 | } |
210 | | |
211 | 0 | if (pSdrView->GetModel().IsChanged()) |
212 | 0 | GetShell().SetModified(); |
213 | 0 | else if (bChanged) |
214 | 0 | pSdrView->GetModel().SetChanged(); |
215 | 0 | } |
216 | | |
217 | | void SwBezierShell::GetState(SfxItemSet &rSet) |
218 | 0 | { |
219 | 0 | SdrView* pSdrView = GetShell().GetDrawView(); |
220 | |
|
221 | 0 | SfxWhichIter aIter( rSet ); |
222 | 0 | sal_uInt16 nWhich = aIter.FirstWhich(); |
223 | |
|
224 | 0 | while( nWhich ) |
225 | 0 | { |
226 | 0 | switch( nWhich ) |
227 | 0 | { |
228 | 0 | case SID_BEZIER_MOVE: |
229 | 0 | case SID_BEZIER_INSERT: |
230 | 0 | { |
231 | 0 | sal_uInt16 nEditMode = GetView().GetEditWin().GetBezierMode(); |
232 | |
|
233 | 0 | rSet.Put(SfxBoolItem(nWhich, nEditMode == nWhich)); |
234 | 0 | } |
235 | 0 | break; |
236 | | |
237 | 0 | case SID_BEZIER_CUTLINE: |
238 | 0 | if (!pSdrView->IsRipUpAtMarkedPointsPossible()) |
239 | 0 | { |
240 | 0 | rSet.DisableItem(SID_BEZIER_CUTLINE); |
241 | 0 | } |
242 | 0 | break; |
243 | | |
244 | 0 | case SID_BEZIER_DELETE: |
245 | 0 | if (!pSdrView->IsDeleteMarkedPointsPossible()) |
246 | 0 | { |
247 | 0 | rSet.DisableItem(SID_BEZIER_DELETE); |
248 | 0 | } |
249 | 0 | break; |
250 | | |
251 | 0 | case SID_BEZIER_CONVERT: |
252 | 0 | if (!pSdrView->IsSetMarkedSegmentsKindPossible()) |
253 | 0 | { |
254 | 0 | rSet.DisableItem(SID_BEZIER_CONVERT); |
255 | 0 | } |
256 | 0 | else |
257 | 0 | { |
258 | 0 | SdrPathSegmentKind eSegm = pSdrView->GetMarkedSegmentsKind(); |
259 | 0 | switch (eSegm) |
260 | 0 | { |
261 | 0 | case SdrPathSegmentKind::DontCare: rSet.InvalidateItem(SID_BEZIER_CONVERT); break; |
262 | 0 | case SdrPathSegmentKind::Line : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,false)); break; // Button pressed = curve |
263 | 0 | case SdrPathSegmentKind::Curve : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,true)); break; |
264 | 0 | default:; //prevent warning |
265 | 0 | } |
266 | 0 | } |
267 | 0 | break; |
268 | | |
269 | 0 | case SID_BEZIER_EDGE: |
270 | 0 | case SID_BEZIER_SMOOTH: |
271 | 0 | case SID_BEZIER_SYMMTR: |
272 | 0 | if (!pSdrView->IsSetMarkedPointsSmoothPossible()) |
273 | 0 | rSet.DisableItem(nWhich); |
274 | 0 | else |
275 | 0 | { |
276 | 0 | SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth(); |
277 | 0 | bool bEnable = false; |
278 | 0 | switch (eSmooth) |
279 | 0 | { |
280 | 0 | case SdrPathSmoothKind::DontCare : |
281 | 0 | break; |
282 | 0 | case SdrPathSmoothKind::Angular : |
283 | 0 | bEnable = nWhich == SID_BEZIER_EDGE; |
284 | 0 | break; |
285 | 0 | case SdrPathSmoothKind::Asymmetric: |
286 | 0 | bEnable = nWhich == SID_BEZIER_SMOOTH; |
287 | 0 | break; |
288 | 0 | case SdrPathSmoothKind::Symmetric : |
289 | 0 | bEnable = nWhich == SID_BEZIER_SYMMTR; |
290 | 0 | break; |
291 | 0 | } |
292 | 0 | rSet.Put(SfxBoolItem(nWhich, bEnable)); |
293 | 0 | } |
294 | 0 | break; |
295 | | |
296 | 0 | case SID_BEZIER_CLOSE: |
297 | 0 | if (!pSdrView->IsOpenCloseMarkedObjectsPossible()) |
298 | 0 | { |
299 | 0 | rSet.DisableItem(SID_BEZIER_CLOSE); |
300 | 0 | } |
301 | 0 | else |
302 | 0 | { |
303 | 0 | SdrObjClosedKind eClose = pSdrView->GetMarkedObjectsClosedState(); |
304 | 0 | switch (eClose) |
305 | 0 | { |
306 | 0 | case SdrObjClosedKind::DontCare: rSet.InvalidateItem(SID_BEZIER_CLOSE); break; |
307 | 0 | case SdrObjClosedKind::Open : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,false)); break; |
308 | 0 | case SdrObjClosedKind::Closed : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,true)); break; |
309 | 0 | default:; //prevent warning |
310 | 0 | } |
311 | 0 | } |
312 | 0 | break; |
313 | | |
314 | 0 | case SID_BEZIER_ELIMINATE_POINTS: |
315 | 0 | rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, pSdrView->IsEliminatePolyPoints())); |
316 | 0 | break; |
317 | | |
318 | 0 | default: |
319 | 0 | break; |
320 | 0 | } |
321 | 0 | nWhich = aIter.NextWhich(); |
322 | 0 | } |
323 | 0 | } |
324 | | |
325 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |