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 <svl/aeitem.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <svx/svdobj.hxx>
28 #include <sfx2/viewfrm.hxx>
30 #include <svx/svxids.hrc>
35 #include <drawdoc.hxx>
38 #include <ViewShell.hxx>
39 #include <ViewShellBase.hxx>
40 #include <ToolBarManager.hxx>
42 #include <svx/sxciaitm.hxx>
44 using namespace com::sun::star
;
49 FuConstructArc::FuConstructArc (
55 : FuConstruct( pViewSh
, pWin
, pView
, pDoc
, rReq
)
59 rtl::Reference
<FuPoor
> FuConstructArc::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
61 FuConstructArc
* pFunc
;
62 rtl::Reference
<FuPoor
> xFunc( pFunc
= new FuConstructArc( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
63 xFunc
->DoExecute(rReq
);
64 pFunc
->SetPermanent(bPermanent
);
68 void FuConstructArc::DoExecute( SfxRequest
& rReq
)
70 FuConstruct::DoExecute( rReq
);
72 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
73 ToolBarManager::ToolBarGroup::Function
,
74 ToolBarManager::msDrawingObjectToolBar
);
76 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
80 const SfxUInt32Item
* pCenterX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_CENTER_X
);
81 const SfxUInt32Item
* pCenterY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_CENTER_Y
);
82 const SfxUInt32Item
* pAxisX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_AXIS_X
);
83 const SfxUInt32Item
* pAxisY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_AXIS_Y
);
84 const SfxUInt32Item
* pPhiStart
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_ANGLESTART
);
85 const SfxUInt32Item
* pPhiEnd
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_ANGLEEND
);
87 ::tools::Rectangle
aNewRectangle (pCenterX
->GetValue () - pAxisX
->GetValue () / 2,
88 pCenterY
->GetValue () - pAxisY
->GetValue () / 2,
89 pCenterX
->GetValue () + pAxisX
->GetValue () / 2,
90 pCenterY
->GetValue () + pAxisY
->GetValue () / 2);
92 Activate(); // sets aObjKind
93 SdrCircObj
* pNewCircle
=
95 mpView
->getSdrModelFromSdrView(),
96 static_cast<SdrObjKind
>(mpView
->GetCurrentObjIdentifier()),
98 static_cast<long>(pPhiStart
->GetValue () * 10.0),
99 static_cast<long>(pPhiEnd
->GetValue () * 10.0));
100 SdrPageView
*pPV
= mpView
->GetSdrPageView();
102 mpView
->InsertObjectAtView(pNewCircle
, *pPV
, SdrInsertFlags::SETDEFLAYER
);
106 bool FuConstructArc::MouseButtonDown( const MouseEvent
& rMEvt
)
108 bool bReturn
= FuConstruct::MouseButtonDown( rMEvt
);
110 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
112 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
113 mpWindow
->CaptureMouse();
114 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
115 mpView
->BegCreateObj(aPnt
, nullptr, nDrgLog
);
117 SdrObject
* pObj
= mpView
->GetCreateObj();
121 SfxItemSet
aAttr(mpDoc
->GetPool());
122 SetStyleSheet(aAttr
, pObj
);
124 pObj
->SetMergedItemSet(aAttr
);
132 bool FuConstructArc::MouseButtonUp( const MouseEvent
& rMEvt
)
134 bool bReturn
= false;
135 bool bCreated
= false;
137 if ( mpView
->IsCreateObj() && rMEvt
.IsLeft() )
139 const size_t nCount
= mpView
->GetSdrPageView()->GetObjList()->GetObjCount();
141 if (mpView
->EndCreateObj(SdrCreateCmd::NextPoint
) )
143 if (nCount
!= mpView
->GetSdrPageView()->GetObjList()->GetObjCount())
152 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
154 if (!bPermanent
&& bCreated
)
155 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
160 void FuConstructArc::Activate()
167 case SID_DRAW_CIRCLEARC
:
174 case SID_DRAW_PIE_NOFILL
:
175 case SID_DRAW_CIRCLEPIE
:
176 case SID_DRAW_CIRCLEPIE_NOFILL
:
182 case SID_DRAW_ELLIPSECUT
:
183 case SID_DRAW_ELLIPSECUT_NOFILL
:
184 case SID_DRAW_CIRCLECUT
:
185 case SID_DRAW_CIRCLECUT_NOFILL
:
198 mpView
->SetCurrentObj(static_cast<sal_uInt16
>(aObjKind
));
200 FuConstruct::Activate();
203 SdrObject
* FuConstructArc::CreateDefaultObject(const sal_uInt16 nID
, const ::tools::Rectangle
& rRectangle
)
206 SdrObject
* pObj
= SdrObjFactory::MakeNewObject(
207 mpView
->getSdrModelFromSdrView(),
208 mpView
->GetCurrentObjInventor(),
209 mpView
->GetCurrentObjIdentifier());
213 if( dynamic_cast< const SdrCircObj
*>( pObj
) != nullptr)
215 ::tools::Rectangle
aRect(rRectangle
);
217 if(SID_DRAW_ARC
== nID
||
218 SID_DRAW_CIRCLEARC
== nID
||
219 SID_DRAW_CIRCLEPIE
== nID
||
220 SID_DRAW_CIRCLEPIE_NOFILL
== nID
||
221 SID_DRAW_CIRCLECUT
== nID
||
222 SID_DRAW_CIRCLECUT_NOFILL
== nID
)
225 ImpForceQuadratic(aRect
);
228 pObj
->SetLogicRect(aRect
);
230 SfxItemSet
aAttr(mpDoc
->GetPool());
231 aAttr
.Put(makeSdrCircStartAngleItem(9000));
232 aAttr
.Put(makeSdrCircEndAngleItem(0));
234 if(SID_DRAW_PIE_NOFILL
== nID
||
235 SID_DRAW_CIRCLEPIE_NOFILL
== nID
||
236 SID_DRAW_ELLIPSECUT_NOFILL
== nID
||
237 SID_DRAW_CIRCLECUT_NOFILL
== nID
)
239 aAttr
.Put(XFillStyleItem(drawing::FillStyle_NONE
));
242 pObj
->SetMergedItemSet(aAttr
);
246 OSL_FAIL("Object is NO circle object");
253 } // end of namespace sd
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */