Update git submodules
[LibreOffice.git] / sd / source / ui / func / fuconarc.cxx
blob35b2c33b4ad730f66ca83da7f6581a2ea3189ac0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
32 #include <Window.hxx>
33 #include <drawdoc.hxx>
35 #include <View.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;
45 namespace sd {
48 FuConstructArc::FuConstructArc (
49 ViewShell* pViewSh,
50 ::sd::Window* pWin,
51 ::sd::View* pView,
52 SdDrawDocument* pDoc,
53 SfxRequest& rReq )
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);
64 return xFunc;
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 ();
77 if (!pArgs)
78 return;
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 =
94 new SdrCircObj(
95 mpView->getSdrModelFromSdrView(),
96 ToSdrCircKind(mpView->GetCurrentObjIdentifier()),
97 aNewRectangle,
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(DRGPIX,0)).Width() );
114 mpView->BegCreateObj(aPnt, nullptr, nDrgLog);
116 SdrObject* pObj = mpView->GetCreateObj();
118 if (pObj)
120 SfxItemSet aAttr(mpDoc->GetPool());
121 SetStyleSheet(aAttr, pObj);
123 pObj->SetMergedItemSet(aAttr);
126 bReturn = true;
128 return bReturn;
131 bool FuConstructArc::MouseButtonUp( const MouseEvent& rMEvt )
133 bool bReturn = false;
134 bool bCreated = false;
136 if ( mpView->IsCreateObj() && rMEvt.IsLeft() )
138 const size_t nCount = mpView->GetSdrPageView()->GetObjList()->GetObjCount();
140 if (mpView->EndCreateObj(SdrCreateCmd::NextPoint) )
142 if (nCount != mpView->GetSdrPageView()->GetObjList()->GetObjCount())
144 bCreated = true;
148 bReturn = true;
151 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
153 if (!bPermanent && bCreated)
154 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
156 return bReturn;
159 void FuConstructArc::Activate()
161 SdrObjKind aObjKind;
163 switch( nSlotId )
165 case SID_DRAW_ARC :
166 case SID_DRAW_CIRCLEARC:
168 aObjKind = SdrObjKind::CircleArc;
170 break;
172 case SID_DRAW_PIE :
173 case SID_DRAW_PIE_NOFILL :
174 case SID_DRAW_CIRCLEPIE :
175 case SID_DRAW_CIRCLEPIE_NOFILL:
177 aObjKind = SdrObjKind::CircleSection;
179 break;
181 case SID_DRAW_ELLIPSECUT :
182 case SID_DRAW_ELLIPSECUT_NOFILL:
183 case SID_DRAW_CIRCLECUT :
184 case SID_DRAW_CIRCLECUT_NOFILL :
186 aObjKind = SdrObjKind::CircleCut;
188 break;
190 default:
192 aObjKind = SdrObjKind::CircleArc;
194 break;
197 mpView->SetCurrentObj(aObjKind);
199 FuConstruct::Activate();
202 rtl::Reference<SdrObject> FuConstructArc::CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle)
205 rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject(
206 mpView->getSdrModelFromSdrView(),
207 mpView->GetCurrentObjInventor(),
208 mpView->GetCurrentObjIdentifier()));
210 if(pObj)
212 if( dynamic_cast< const SdrCircObj *>( pObj.get() ) != nullptr)
214 ::tools::Rectangle aRect(rRectangle);
216 if(SID_DRAW_ARC == nID ||
217 SID_DRAW_CIRCLEARC == nID ||
218 SID_DRAW_CIRCLEPIE == nID ||
219 SID_DRAW_CIRCLEPIE_NOFILL == nID ||
220 SID_DRAW_CIRCLECUT == nID ||
221 SID_DRAW_CIRCLECUT_NOFILL == nID)
223 // force quadratic
224 ImpForceQuadratic(aRect);
227 pObj->SetLogicRect(aRect);
229 SfxItemSet aAttr(mpDoc->GetPool());
230 aAttr.Put(makeSdrCircStartAngleItem(9000_deg100));
231 aAttr.Put(makeSdrCircEndAngleItem(0_deg100));
233 if(SID_DRAW_PIE_NOFILL == nID ||
234 SID_DRAW_CIRCLEPIE_NOFILL == nID ||
235 SID_DRAW_ELLIPSECUT_NOFILL == nID ||
236 SID_DRAW_CIRCLECUT_NOFILL == nID)
238 aAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
241 pObj->SetMergedItemSet(aAttr);
243 else
245 OSL_FAIL("Object is NO circle object");
249 return pObj;
252 } // end of namespace sd
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */