1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/app.hxx>
22 #include <sfx2/msg.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <sfx2/objface.hxx>
26 #include <svx/svxids.hrc>
27 #include <svl/eitem.hxx>
28 #include <sfx2/request.hxx>
29 #include <svx/svdopath.hxx>
30 #include <svl/aeitem.hxx>
31 #include <svx/svdundo.hxx>
32 #include <sfx2/dispatch.hxx>
34 #include "sdresid.hxx"
36 #include "res_bmp.hrc"
38 #include "strings.hrc"
40 #include "DrawDocShell.hxx"
41 #include "ViewShell.hxx"
43 #include "drawview.hxx"
44 #include "drawdoc.hxx"
46 #include "fuconbez.hxx"
50 #define BezierObjectBar
51 #include "sdslots.hxx"
56 * Declare default interface (Slotmap must not be empty)
59 SFX_IMPL_INTERFACE(BezierObjectBar
, ::SfxShell
, SdResId(STR_BEZIEROBJECTBARSHELL
))
63 TYPEINIT1(BezierObjectBar
, ::SfxShell
);
66 BezierObjectBar::BezierObjectBar(
67 ViewShell
* pSdViewShell
,
69 : SfxShell(pSdViewShell
->GetViewShell()),
71 mpViewSh(pSdViewShell
)
73 DrawDocShell
* pDocShell
= mpViewSh
->GetDocSh();
74 SetPool(&pDocShell
->GetPool());
75 SetUndoManager(pDocShell
->GetUndoManager());
76 SetRepeatTarget(mpView
);
78 SetHelpId( SD_IF_SDDRAWBEZIEROBJECTBAR
);
82 BezierObjectBar::~BezierObjectBar()
84 SetRepeatTarget(NULL
);
89 * Status of attribute items.
92 void BezierObjectBar::GetAttrState(SfxItemSet
& rSet
)
94 SfxItemSet
aAttrSet( mpView
->GetDoc().GetPool() );
95 mpView
->GetAttributes( aAttrSet
);
96 rSet
.Put(aAttrSet
, sal_False
); // <- sal_False, so DontCare-Status gets aquired
98 FunctionReference
xFunc( mpViewSh
->GetCurrentFunction() );
102 if(xFunc
->ISA(FuSelection
))
104 sal_uInt16 nEditMode
= static_cast<FuSelection
*>(xFunc
.get())->GetEditMode();
105 rSet
.Put(SfxBoolItem(nEditMode
, sal_True
));
107 else if (xFunc
->ISA(FuConstructBezierPolygon
))
109 sal_uInt16 nEditMode
= static_cast<FuConstructBezierPolygon
*>(xFunc
.get())->GetEditMode();
110 rSet
.Put(SfxBoolItem(nEditMode
, sal_True
));
114 if(!mpView
->IsMoveAllowed() || !mpView
->IsResizeAllowed())
116 // #i77187# if object is move and/or size protected, do not allow point editing at all
117 rSet
.DisableItem(SID_BEZIER_MOVE
);
118 rSet
.DisableItem(SID_BEZIER_INSERT
);
120 rSet
.DisableItem(SID_BEZIER_DELETE
);
121 rSet
.DisableItem(SID_BEZIER_CUTLINE
);
122 rSet
.DisableItem(SID_BEZIER_CONVERT
);
124 rSet
.DisableItem(SID_BEZIER_EDGE
);
125 rSet
.DisableItem(SID_BEZIER_SMOOTH
);
126 rSet
.DisableItem(SID_BEZIER_SYMMTR
);
128 rSet
.DisableItem(SID_BEZIER_CLOSE
);
130 rSet
.DisableItem(SID_BEZIER_ELIMINATE_POINTS
);
134 IPolyPolygonEditorController
* pIPPEC
= 0;
135 if( mpView
->GetMarkedObjectList().GetMarkCount() )
138 pIPPEC
= dynamic_cast< IPolyPolygonEditorController
* >( mpView
->getSmartTags().getSelected().get() );
140 if ( !pIPPEC
|| !pIPPEC
->IsRipUpAtMarkedPointsPossible())
142 rSet
.DisableItem(SID_BEZIER_CUTLINE
);
144 if (!pIPPEC
|| !pIPPEC
->IsDeleteMarkedPointsPossible())
146 rSet
.DisableItem(SID_BEZIER_DELETE
);
148 if (!pIPPEC
|| !pIPPEC
->IsSetMarkedSegmentsKindPossible())
150 rSet
.DisableItem(SID_BEZIER_CONVERT
);
154 SdrPathSegmentKind eSegm
= pIPPEC
->GetMarkedSegmentsKind();
157 case SDRPATHSEGMENT_DONTCARE
: rSet
.InvalidateItem(SID_BEZIER_CONVERT
); break;
158 case SDRPATHSEGMENT_LINE
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,sal_False
)); break; // Button down = curve
159 case SDRPATHSEGMENT_CURVE
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,sal_True
)); break;
163 if (!pIPPEC
|| !pIPPEC
->IsSetMarkedPointsSmoothPossible())
165 rSet
.DisableItem(SID_BEZIER_EDGE
);
166 rSet
.DisableItem(SID_BEZIER_SMOOTH
);
167 rSet
.DisableItem(SID_BEZIER_SYMMTR
);
171 SdrPathSmoothKind eSmooth
= pIPPEC
->GetMarkedPointsSmooth();
174 case SDRPATHSMOOTH_DONTCARE
: break;
175 case SDRPATHSMOOTH_ANGULAR
: rSet
.Put(SfxBoolItem(SID_BEZIER_EDGE
, sal_True
)); break;
176 case SDRPATHSMOOTH_ASYMMETRIC
: rSet
.Put(SfxBoolItem(SID_BEZIER_SMOOTH
,sal_True
)); break;
177 case SDRPATHSMOOTH_SYMMETRIC
: rSet
.Put(SfxBoolItem(SID_BEZIER_SYMMTR
,sal_True
)); break;
180 if (!pIPPEC
|| !pIPPEC
->IsOpenCloseMarkedObjectsPossible())
182 rSet
.DisableItem(SID_BEZIER_CLOSE
);
186 SdrObjClosedKind eClose
= pIPPEC
->GetMarkedObjectsClosedState();
189 case SDROBJCLOSED_DONTCARE
: rSet
.InvalidateItem(SID_BEZIER_CLOSE
); break;
190 case SDROBJCLOSED_OPEN
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,sal_False
)); break;
191 case SDROBJCLOSED_CLOSED
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,sal_True
)); break;
197 rSet
.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS
, mpView
->IsEliminatePolyPoints()));
199 rSet
.DisableItem( SID_BEZIER_ELIMINATE_POINTS
); // only works for views
204 * Process SfxRequests
207 void BezierObjectBar::Execute(SfxRequest
& rReq
)
209 sal_uInt16 nSId
= rReq
.GetSlot();
213 case SID_BEZIER_CUTLINE
:
214 case SID_BEZIER_CONVERT
:
215 case SID_BEZIER_DELETE
:
216 case SID_BEZIER_EDGE
:
217 case SID_BEZIER_SMOOTH
:
218 case SID_BEZIER_SYMMTR
:
219 case SID_BEZIER_CLOSE
:
221 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
223 IPolyPolygonEditorController
* pIPPEC
= 0;
224 if( rMarkList
.GetMarkCount() )
227 pIPPEC
= dynamic_cast< IPolyPolygonEditorController
* >( mpView
->getSmartTags().getSelected().get() );
229 if( pIPPEC
&& !mpView
->IsAction())
233 case SID_BEZIER_DELETE
:
234 pIPPEC
->DeleteMarkedPoints();
237 case SID_BEZIER_CUTLINE
:
238 pIPPEC
->RipUpAtMarkedPoints();
241 case SID_BEZIER_CONVERT
:
243 pIPPEC
->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE
);
247 case SID_BEZIER_EDGE
:
248 case SID_BEZIER_SMOOTH
:
249 case SID_BEZIER_SYMMTR
:
251 SdrPathSmoothKind eKind
;
256 case SID_BEZIER_EDGE
: eKind
= SDRPATHSMOOTH_ANGULAR
; break;
257 case SID_BEZIER_SMOOTH
: eKind
= SDRPATHSMOOTH_ASYMMETRIC
; break;
258 case SID_BEZIER_SYMMTR
: eKind
= SDRPATHSMOOTH_SYMMETRIC
; break;
261 pIPPEC
->SetMarkedPointsSmooth(eKind
);
265 case SID_BEZIER_CLOSE
:
267 SdrPathObj
* pPathObj
= (SdrPathObj
*) rMarkList
.GetMark(0)->GetMarkedSdrObj();
268 const bool bUndo
= mpView
->IsUndoEnabled();
270 mpView
->BegUndo(String(SdResId(STR_UNDO_BEZCLOSE
)));
272 mpView
->UnmarkAllPoints();
275 mpView
->AddUndo(mpView
->GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pPathObj
));
277 pPathObj
->ToggleClosed();
286 if( (pIPPEC
== mpView
) && !mpView
->AreObjectsMarked() )
287 mpViewSh
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SFX_CALLMODE_ASYNCHRON
);
293 case SID_BEZIER_ELIMINATE_POINTS
:
295 mpView
->SetEliminatePolyPoints(!mpView
->IsEliminatePolyPoints());
296 Invalidate(SID_BEZIER_ELIMINATE_POINTS
);
301 case SID_BEZIER_MOVE
:
302 case SID_BEZIER_INSERT
:
304 FunctionReference
xFunc( mpViewSh
->GetCurrentFunction() );
308 if(xFunc
->ISA(FuSelection
))
310 static_cast<FuSelection
*>(xFunc
.get())->SetEditMode(rReq
.GetSlot());
312 else if(xFunc
->ISA(FuConstructBezierPolygon
))
314 static_cast<FuConstructBezierPolygon
*>(xFunc
.get())->SetEditMode(rReq
.GetSlot());
330 } // end of namespace sd
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */