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>
28 #include <osl/diagnose.h>
30 #include <svx/svxids.hrc>
33 #include <drawdoc.hxx>
36 #include <ViewShell.hxx>
37 #include <ViewShellBase.hxx>
38 #include <ToolBarManager.hxx>
40 #include <svx/sxciaitm.hxx>
41 #include <svx/xfillit0.hxx>
43 using namespace com::sun::star
;
48 FuConstructArc::FuConstructArc (
54 : FuConstruct( pViewSh
, pWin
, pView
, pDoc
, rReq
)
58 rtl::Reference
<FuPoor
> FuConstructArc::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
60 FuConstructArc
* pFunc
;
61 rtl::Reference
<FuPoor
> xFunc( pFunc
= new FuConstructArc( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
62 xFunc
->DoExecute(rReq
);
63 pFunc
->SetPermanent(bPermanent
);
67 void FuConstructArc::DoExecute( SfxRequest
& rReq
)
69 FuConstruct::DoExecute( rReq
);
71 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
72 ToolBarManager::ToolBarGroup::Function
,
73 ToolBarManager::msDrawingObjectToolBar
);
75 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 rtl::Reference
<SdrCircObj
> pNewCircle
=
95 mpView
->getSdrModelFromSdrView(),
96 ToSdrCircKind(mpView
->GetCurrentObjIdentifier()),
98 Degree100(pPhiStart
->GetValue() * 10),
99 Degree100(pPhiEnd
->GetValue() * 10));
100 SdrPageView
*pPV
= mpView
->GetSdrPageView();
102 mpView
->InsertObjectAtView(pNewCircle
.get(), *pPV
, SdrInsertFlags::SETDEFLAYER
);
105 bool FuConstructArc::MouseButtonDown( const MouseEvent
& rMEvt
)
107 bool bReturn
= FuConstruct::MouseButtonDown( rMEvt
);
109 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
111 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
112 mpWindow
->CaptureMouse();
113 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(mpView
->GetDragThresholdPixels(),0)).Width() );
114 mpView
->BegCreateObj(aPnt
, nullptr, nDrgLog
);
116 SdrObject
* pObj
= mpView
->GetCreateObj();
120 SfxItemSet
aAttr(mpDoc
->GetPool());
121 SetStyleSheet(aAttr
, pObj
);
123 pObj
->SetMergedItemSet(aAttr
);
131 bool FuConstructArc::MouseButtonUp( const MouseEvent
& rMEvt
)
133 if (rMEvt
.IsLeft() && IsIgnoreUnexpectedMouseButtonUp())
136 bool bReturn
= false;
137 bool bCreated
= false;
139 if ( mpView
->IsCreateObj() && rMEvt
.IsLeft() )
141 const size_t nCount
= mpView
->GetSdrPageView()->GetObjList()->GetObjCount();
143 if (mpView
->EndCreateObj(SdrCreateCmd::NextPoint
) )
145 if (nCount
!= mpView
->GetSdrPageView()->GetObjList()->GetObjCount())
154 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
156 if (!bPermanent
&& bCreated
)
157 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
162 void FuConstructArc::Activate()
169 case SID_DRAW_CIRCLEARC
:
171 aObjKind
= SdrObjKind::CircleArc
;
176 case SID_DRAW_PIE_NOFILL
:
177 case SID_DRAW_CIRCLEPIE
:
178 case SID_DRAW_CIRCLEPIE_NOFILL
:
180 aObjKind
= SdrObjKind::CircleSection
;
184 case SID_DRAW_ELLIPSECUT
:
185 case SID_DRAW_ELLIPSECUT_NOFILL
:
186 case SID_DRAW_CIRCLECUT
:
187 case SID_DRAW_CIRCLECUT_NOFILL
:
189 aObjKind
= SdrObjKind::CircleCut
;
195 aObjKind
= SdrObjKind::CircleArc
;
200 mpView
->SetCurrentObj(aObjKind
);
202 FuConstruct::Activate();
205 rtl::Reference
<SdrObject
> FuConstructArc::CreateDefaultObject(const sal_uInt16 nID
, const ::tools::Rectangle
& rRectangle
)
208 rtl::Reference
<SdrObject
> pObj(SdrObjFactory::MakeNewObject(
209 mpView
->getSdrModelFromSdrView(),
210 mpView
->GetCurrentObjInventor(),
211 mpView
->GetCurrentObjIdentifier()));
215 if( dynamic_cast< const SdrCircObj
*>( pObj
.get() ) != nullptr)
217 ::tools::Rectangle
aRect(rRectangle
);
219 if(SID_DRAW_ARC
== nID
||
220 SID_DRAW_CIRCLEARC
== nID
||
221 SID_DRAW_CIRCLEPIE
== nID
||
222 SID_DRAW_CIRCLEPIE_NOFILL
== nID
||
223 SID_DRAW_CIRCLECUT
== nID
||
224 SID_DRAW_CIRCLECUT_NOFILL
== nID
)
227 ImpForceQuadratic(aRect
);
230 pObj
->SetLogicRect(aRect
);
232 SfxItemSet
aAttr(mpDoc
->GetPool());
233 aAttr
.Put(makeSdrCircStartAngleItem(9000_deg100
));
234 aAttr
.Put(makeSdrCircEndAngleItem(0_deg100
));
236 if(SID_DRAW_PIE_NOFILL
== nID
||
237 SID_DRAW_CIRCLEPIE_NOFILL
== nID
||
238 SID_DRAW_ELLIPSECUT_NOFILL
== nID
||
239 SID_DRAW_CIRCLECUT_NOFILL
== nID
)
241 aAttr
.Put(XFillStyleItem(drawing::FillStyle_NONE
));
244 pObj
->SetMergedItemSet(aAttr
);
248 OSL_FAIL("Object is NO circle object");
255 } // end of namespace sd
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */