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 <fuconarc.hxx>
21 #include <svx/svdpagv.hxx>
22 #include <svx/svdocirc.hxx>
23 #include <sfx2/request.hxx>
24 #include <svl/intitem.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <svx/svdobj.hxx>
27 #include <sfx2/viewfrm.hxx>
29 #include <svx/svxids.hrc>
32 #include <drawdoc.hxx>
35 #include <ViewShell.hxx>
36 #include <ViewShellBase.hxx>
37 #include <ToolBarManager.hxx>
39 #include <svx/sxciaitm.hxx>
41 using namespace com::sun::star
;
46 FuConstructArc::FuConstructArc (
52 : FuConstruct( pViewSh
, pWin
, pView
, pDoc
, rReq
)
56 rtl::Reference
<FuPoor
> FuConstructArc::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
58 FuConstructArc
* pFunc
;
59 rtl::Reference
<FuPoor
> xFunc( pFunc
= new FuConstructArc( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
60 xFunc
->DoExecute(rReq
);
61 pFunc
->SetPermanent(bPermanent
);
65 void FuConstructArc::DoExecute( SfxRequest
& rReq
)
67 FuConstruct::DoExecute( rReq
);
69 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
70 ToolBarManager::ToolBarGroup::Function
,
71 ToolBarManager::msDrawingObjectToolBar
);
73 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
78 const SfxUInt32Item
* pCenterX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_CENTER_X
);
79 const SfxUInt32Item
* pCenterY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_CENTER_Y
);
80 const SfxUInt32Item
* pAxisX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_AXIS_X
);
81 const SfxUInt32Item
* pAxisY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_AXIS_Y
);
82 const SfxUInt32Item
* pPhiStart
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_ANGLESTART
);
83 const SfxUInt32Item
* pPhiEnd
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_ANGLEEND
);
85 ::tools::Rectangle
aNewRectangle (pCenterX
->GetValue () - pAxisX
->GetValue () / 2,
86 pCenterY
->GetValue () - pAxisY
->GetValue () / 2,
87 pCenterX
->GetValue () + pAxisX
->GetValue () / 2,
88 pCenterY
->GetValue () + pAxisY
->GetValue () / 2);
90 Activate(); // sets aObjKind
91 SdrCircObj
* pNewCircle
=
93 mpView
->getSdrModelFromSdrView(),
94 static_cast<SdrObjKind
>(mpView
->GetCurrentObjIdentifier()),
96 static_cast<long>(pPhiStart
->GetValue () * 10.0),
97 static_cast<long>(pPhiEnd
->GetValue () * 10.0));
98 SdrPageView
*pPV
= mpView
->GetSdrPageView();
100 mpView
->InsertObjectAtView(pNewCircle
, *pPV
, SdrInsertFlags::SETDEFLAYER
);
103 bool FuConstructArc::MouseButtonDown( const MouseEvent
& rMEvt
)
105 bool bReturn
= FuConstruct::MouseButtonDown( rMEvt
);
107 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
109 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
110 mpWindow
->CaptureMouse();
111 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
112 mpView
->BegCreateObj(aPnt
, nullptr, nDrgLog
);
114 SdrObject
* pObj
= mpView
->GetCreateObj();
118 SfxItemSet
aAttr(mpDoc
->GetPool());
119 SetStyleSheet(aAttr
, pObj
);
121 pObj
->SetMergedItemSet(aAttr
);
129 bool FuConstructArc::MouseButtonUp( const MouseEvent
& rMEvt
)
131 bool bReturn
= false;
132 bool bCreated
= false;
134 if ( mpView
->IsCreateObj() && rMEvt
.IsLeft() )
136 const size_t nCount
= mpView
->GetSdrPageView()->GetObjList()->GetObjCount();
138 if (mpView
->EndCreateObj(SdrCreateCmd::NextPoint
) )
140 if (nCount
!= mpView
->GetSdrPageView()->GetObjList()->GetObjCount())
149 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
151 if (!bPermanent
&& bCreated
)
152 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
157 void FuConstructArc::Activate()
164 case SID_DRAW_CIRCLEARC
:
171 case SID_DRAW_PIE_NOFILL
:
172 case SID_DRAW_CIRCLEPIE
:
173 case SID_DRAW_CIRCLEPIE_NOFILL
:
179 case SID_DRAW_ELLIPSECUT
:
180 case SID_DRAW_ELLIPSECUT_NOFILL
:
181 case SID_DRAW_CIRCLECUT
:
182 case SID_DRAW_CIRCLECUT_NOFILL
:
195 mpView
->SetCurrentObj(static_cast<sal_uInt16
>(aObjKind
));
197 FuConstruct::Activate();
200 SdrObjectUniquePtr
FuConstructArc::CreateDefaultObject(const sal_uInt16 nID
, const ::tools::Rectangle
& rRectangle
)
203 SdrObjectUniquePtr
pObj(SdrObjFactory::MakeNewObject(
204 mpView
->getSdrModelFromSdrView(),
205 mpView
->GetCurrentObjInventor(),
206 mpView
->GetCurrentObjIdentifier()));
210 if( dynamic_cast< const SdrCircObj
*>( pObj
.get() ) != nullptr)
212 ::tools::Rectangle
aRect(rRectangle
);
214 if(SID_DRAW_ARC
== nID
||
215 SID_DRAW_CIRCLEARC
== nID
||
216 SID_DRAW_CIRCLEPIE
== nID
||
217 SID_DRAW_CIRCLEPIE_NOFILL
== nID
||
218 SID_DRAW_CIRCLECUT
== nID
||
219 SID_DRAW_CIRCLECUT_NOFILL
== nID
)
222 ImpForceQuadratic(aRect
);
225 pObj
->SetLogicRect(aRect
);
227 SfxItemSet
aAttr(mpDoc
->GetPool());
228 aAttr
.Put(makeSdrCircStartAngleItem(9000));
229 aAttr
.Put(makeSdrCircEndAngleItem(0));
231 if(SID_DRAW_PIE_NOFILL
== nID
||
232 SID_DRAW_CIRCLEPIE_NOFILL
== nID
||
233 SID_DRAW_ELLIPSECUT_NOFILL
== nID
||
234 SID_DRAW_CIRCLECUT_NOFILL
== nID
)
236 aAttr
.Put(XFillStyleItem(drawing::FillStyle_NONE
));
239 pObj
->SetMergedItemSet(aAttr
);
243 OSL_FAIL("Object is NO circle object");
250 } // end of namespace sd
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */