xref: /trunk/main/sw/source/ui/shells/beziersh.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include "cmdid.h"
33 #include <svx/svdview.hxx>
34 #include <svl/srchitem.hxx>
35 #include <svl/eitem.hxx>
36 #include <svl/whiter.hxx>
37 #include <svx/svdopath.hxx>
38 #include <sfx2/request.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/objface.hxx>
41 
42 #include "wrtsh.hxx"
43 #include "view.hxx"
44 #include "edtwin.hxx"
45 #include "helpid.h"
46 #include "globals.hrc"
47 #include "drawbase.hxx"
48 #include "beziersh.hxx"
49 #include "popup.hrc"
50 #include "shells.hrc"
51 #define SwBezierShell
52 #include <sfx2/msg.hxx>
53 #include "swslots.hxx"
54 
55 #include <unomid.h>
56 
57 
58 SFX_IMPL_INTERFACE(SwBezierShell, SwBaseShell, SW_RES(STR_SHELLNAME_BEZIER))
59 {
60     SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU));
61     SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_BEZIER_TOOLBOX));
62 }
63 
64 TYPEINIT1(SwBezierShell,SwBaseShell)
65 
66 /*--------------------------------------------------------------------
67     Beschreibung:
68  --------------------------------------------------------------------*/
69 
70 
71 SwBezierShell::SwBezierShell(SwView &_rView):
72     SwBaseShell( _rView )
73 {
74     SetName(C2S("Bezier"));
75     SetHelpId(SW_BEZIERSHELL);
76 
77     SwWrtShell *pSh = &GetShell();
78     SdrView*    pSdrView = pSh->GetDrawView();
79     pSdrView->SetEliminatePolyPointLimitAngle(1500L);
80 }
81 
82 /*--------------------------------------------------------------------
83     Beschreibung:
84  --------------------------------------------------------------------*/
85 
86 
87 void SwBezierShell::Execute(SfxRequest &rReq)
88 {
89     SwWrtShell *pSh = &GetShell();
90     SdrView*    pSdrView = pSh->GetDrawView();
91     const SfxItemSet *pArgs = rReq.GetArgs();
92     sal_uInt16      nSlotId = rReq.GetSlot();
93     sal_Bool        bChanged = pSdrView->GetModel()->IsChanged();
94     pSdrView->GetModel()->SetChanged(sal_False);
95     const SfxPoolItem* pItem;
96     if(pArgs)
97         pArgs->GetItemState(nSlotId, sal_False, &pItem);
98 
99     switch (nSlotId)
100     {
101         case SID_DELETE:
102         case FN_BACKSPACE:
103             if (pSh->IsObjSelected())
104             {
105                 if (pSdrView->HasMarkedPoints())
106                     pSh->GetView().GetViewFrame()->GetDispatcher()->Execute(SID_BEZIER_DELETE, sal_False);
107                 else
108                 {
109                     pSh->DelSelectedObj();
110                     if (pSh->IsSelFrmMode())
111                     {
112                         pSh->LeaveSelFrmMode();
113                         pSh->NoEdit();
114                     }
115                     GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
116                 }
117             }
118             break;
119 
120         case FN_ESCAPE:
121             if (pSdrView->HasMarkedPoints())
122                 pSdrView->UnmarkAllPoints();
123             else
124             {
125                 if ( pSh->IsDrawCreate() )
126                 {
127                     GetView().GetDrawFuncPtr()->BreakCreate();
128                     GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
129                 }
130                 else if ( pSh->HasSelection() || GetView().IsDrawMode() )
131                 {
132                     GetView().LeaveDrawCreate();
133                     pSh->EnterStdMode();
134                     GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
135                 }
136             }
137             break;
138 
139         case SID_BEZIER_MOVE:
140         case SID_BEZIER_INSERT:
141             {
142                 GetView().GetEditWin().SetBezierMode(nSlotId);
143                 static sal_uInt16 __READONLY_DATA aInva[] =
144                                 {
145                                     SID_BEZIER_INSERT,
146                                     SID_BEZIER_MOVE,
147                                     0
148                                 };
149                 GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
150             }
151             break;
152 
153         case SID_BEZIER_DELETE:
154         case SID_BEZIER_CUTLINE:
155         case SID_BEZIER_CONVERT:
156         case SID_BEZIER_EDGE:
157         case SID_BEZIER_SMOOTH:
158         case SID_BEZIER_SYMMTR:
159         case SID_BEZIER_CLOSE:
160         case SID_BEZIER_ELIMINATE_POINTS:
161         {
162             const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
163 
164             if (rMarkList.GetMark(0) && !pSdrView->IsAction())
165             {
166                 switch (nSlotId)
167                 {
168                     case SID_BEZIER_DELETE:
169                         pSdrView->DeleteMarkedPoints();
170                         break;
171 
172                     case SID_BEZIER_CUTLINE:
173                         {
174                             pSdrView->RipUpAtMarkedPoints();
175                             pSh->CheckUnboundObjects();
176                         }
177                         break;
178 
179                     case SID_BEZIER_CONVERT:
180                     {
181                         pSdrView->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE);
182                         break;
183                     }
184 
185                     case SID_BEZIER_EDGE:
186                     case SID_BEZIER_SMOOTH:
187                     case SID_BEZIER_SYMMTR:
188                     {
189                         SdrPathSmoothKind eKind = SDRPATHSMOOTH_ASYMMETRIC;
190 
191                         switch (nSlotId)
192                         {
193                             case SID_BEZIER_EDGE:   eKind = SDRPATHSMOOTH_ANGULAR; break;
194                             case SID_BEZIER_SMOOTH: eKind = SDRPATHSMOOTH_ASYMMETRIC; break;
195                             case SID_BEZIER_SYMMTR: eKind = SDRPATHSMOOTH_SYMMETRIC; break;
196                         }
197 
198                         SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
199                         if (eKind != eSmooth)
200                         {
201                             pSdrView->SetMarkedPointsSmooth(eKind);
202 
203                             static sal_uInt16 __READONLY_DATA aInva[] =
204                                             {
205                                                 SID_BEZIER_SMOOTH,
206                                                 SID_BEZIER_EDGE,
207                                                 SID_BEZIER_SYMMTR,
208                                                 0
209                                             };
210                             GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
211                         }
212                         break;
213                     }
214 
215                     case SID_BEZIER_CLOSE:
216                     {
217                         SdrPathObj* pPathObj = (SdrPathObj*) rMarkList.GetMark(0)->GetMarkedSdrObj();
218                         pSdrView->UnmarkAllPoints();
219                         // Size aDist(GetView().GetEditWin().PixelToLogic(Size(8,8)));
220                         pPathObj->ToggleClosed(); // aDist.Width());
221                         break;
222                     }
223 
224                     case SID_BEZIER_ELIMINATE_POINTS:
225                         pSdrView->SetEliminatePolyPoints(!pSdrView->IsEliminatePolyPoints());
226                         break;
227                 }
228             }
229         }
230         break;
231 
232         default:
233             break;
234     }
235 
236     if (pSdrView->GetModel()->IsChanged())
237         GetShell().SetModified();
238     else if (bChanged)
239         pSdrView->GetModel()->SetChanged(sal_True);
240 }
241 
242 /*--------------------------------------------------------------------
243     Beschreibung:
244  --------------------------------------------------------------------*/
245 
246 
247 void SwBezierShell::GetState(SfxItemSet &rSet)
248 {
249     SdrView* pSdrView = GetShell().GetDrawView();
250 
251     SfxWhichIter aIter( rSet );
252     sal_uInt16 nWhich = aIter.FirstWhich();
253 
254     while( nWhich )
255     {
256         switch( nWhich )
257         {
258             case SID_BEZIER_MOVE:
259             case SID_BEZIER_INSERT:
260             {
261                 sal_uInt16 nEditMode = GetView().GetEditWin().GetBezierMode();
262 
263                 rSet.Put(SfxBoolItem(nWhich, nEditMode == nWhich));
264             }
265             break;
266 
267             case SID_BEZIER_CUTLINE:
268                 if (!pSdrView->IsRipUpAtMarkedPointsPossible())
269                 {
270                     rSet.DisableItem(SID_BEZIER_CUTLINE);
271                 }
272                 break;
273 
274             case SID_BEZIER_DELETE:
275                 if (!pSdrView->IsDeleteMarkedPointsPossible())
276                 {
277                     rSet.DisableItem(SID_BEZIER_DELETE);
278                 }
279                 break;
280 
281             case SID_BEZIER_CONVERT:
282                 if (!pSdrView->IsSetMarkedSegmentsKindPossible())
283                 {
284                     rSet.DisableItem(SID_BEZIER_CONVERT);
285                 }
286                 else
287                 {
288                     SdrPathSegmentKind eSegm = pSdrView->GetMarkedSegmentsKind();
289                     switch (eSegm)
290                     {
291                         case SDRPATHSEGMENT_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CONVERT); break;
292                         case SDRPATHSEGMENT_LINE    : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,sal_False)); break; // Button reingedrueckt = Kurve
293                         case SDRPATHSEGMENT_CURVE   : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,sal_True));  break;
294                         default:; //prevent warning
295                     }
296                 }
297                 break;
298 
299             case SID_BEZIER_EDGE:
300             case SID_BEZIER_SMOOTH:
301             case SID_BEZIER_SYMMTR:
302                 if (!pSdrView->IsSetMarkedPointsSmoothPossible())
303                     rSet.DisableItem(nWhich);
304                 else
305                 {
306                     SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
307                     sal_Bool bEnable = sal_False;
308                     switch (eSmooth)
309                     {
310                         case SDRPATHSMOOTH_DONTCARE  :
311                             break;
312                         case SDRPATHSMOOTH_ANGULAR   :
313                             bEnable = nWhich == SID_BEZIER_EDGE;
314                             break;
315                         case SDRPATHSMOOTH_ASYMMETRIC:
316                             bEnable = nWhich == SID_BEZIER_SMOOTH;
317                             break;
318                         case SDRPATHSMOOTH_SYMMETRIC :
319                             bEnable = nWhich == SID_BEZIER_SYMMTR;
320                             break;
321                     }
322                     rSet.Put(SfxBoolItem(nWhich, bEnable));
323                 }
324                 break;
325 
326             case SID_BEZIER_CLOSE:
327                 if (!pSdrView->IsOpenCloseMarkedObjectsPossible())
328                 {
329                     rSet.DisableItem(SID_BEZIER_CLOSE);
330                 }
331                 else
332                 {
333                     SdrObjClosedKind eClose = pSdrView->GetMarkedObjectsClosedState();
334                     switch (eClose)
335                     {
336                         case SDROBJCLOSED_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CLOSE); break;
337                         case SDROBJCLOSED_OPEN    : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,sal_False)); break;
338                         case SDROBJCLOSED_CLOSED  : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,sal_True)); break;
339                         default:; //prevent warning
340                     }
341                 }
342                 break;
343 
344             case SID_BEZIER_ELIMINATE_POINTS:
345                 rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, pSdrView->IsEliminatePolyPoints()));
346                 break;
347 
348             default:
349                 break;
350         }
351         nWhich = aIter.NextWhich();
352     }
353 }
354 
355 
356 
357