bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuconarc.cxx
blobcc7d3769f0e0a868045cb357f99af377791bff5f
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 <svl/aeitem.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <svx/svdobj.hxx>
28 #include <sfx2/viewfrm.hxx>
30 #include <svx/svxids.hrc>
31 #include <math.h>
33 #include "app.hrc"
34 #include "Window.hxx"
35 #include "drawdoc.hxx"
36 #include "res_bmp.hrc"
37 #include "View.hxx"
38 #include "ViewShell.hxx"
39 #include "ViewShellBase.hxx"
40 #include "ToolBarManager.hxx"
42 #include <svx/sxciaitm.hxx>
44 using namespace com::sun::star;
46 namespace sd {
48 TYPEINIT1( FuConstructArc, FuConstruct );
50 FuConstructArc::FuConstructArc (
51 ViewShell* pViewSh,
52 ::sd::Window* pWin,
53 ::sd::View* pView,
54 SdDrawDocument* pDoc,
55 SfxRequest& rReq )
56 : FuConstruct( pViewSh, pWin, pView, pDoc, rReq )
60 rtl::Reference<FuPoor> FuConstructArc::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
62 FuConstructArc* pFunc;
63 rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructArc( pViewSh, pWin, pView, pDoc, rReq ) );
64 xFunc->DoExecute(rReq);
65 pFunc->SetPermanent(bPermanent);
66 return xFunc;
69 void FuConstructArc::DoExecute( SfxRequest& rReq )
71 FuConstruct::DoExecute( rReq );
73 mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
74 ToolBarManager::TBG_FUNCTION,
75 ToolBarManager::msDrawingObjectToolBar);
77 const SfxItemSet *pArgs = rReq.GetArgs ();
79 if (pArgs)
81 SFX_REQUEST_ARG (rReq, pCenterX, SfxUInt32Item, ID_VAL_CENTER_X, false);
82 SFX_REQUEST_ARG (rReq, pCenterY, SfxUInt32Item, ID_VAL_CENTER_Y, false);
83 SFX_REQUEST_ARG (rReq, pAxisX, SfxUInt32Item, ID_VAL_AXIS_X, false);
84 SFX_REQUEST_ARG (rReq, pAxisY, SfxUInt32Item, ID_VAL_AXIS_Y, false);
85 SFX_REQUEST_ARG (rReq, pPhiStart, SfxUInt32Item, ID_VAL_ANGLESTART, false);
86 SFX_REQUEST_ARG (rReq, pPhiEnd, SfxUInt32Item, ID_VAL_ANGLEEND, false);
88 Rectangle aNewRectangle (pCenterX->GetValue () - pAxisX->GetValue () / 2,
89 pCenterY->GetValue () - pAxisY->GetValue () / 2,
90 pCenterX->GetValue () + pAxisX->GetValue () / 2,
91 pCenterY->GetValue () + pAxisY->GetValue () / 2);
93 Activate(); // sets aObjKind
94 SdrCircObj* pNewCircle =
95 new SdrCircObj((SdrObjKind) mpView->GetCurrentObjIdentifier(),
96 aNewRectangle,
97 (long) (pPhiStart->GetValue () * 10.0),
98 (long) (pPhiEnd->GetValue () * 10.0));
99 SdrPageView *pPV = mpView->GetSdrPageView();
101 mpView->InsertObjectAtView(pNewCircle, *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, (OutputDevice*) NULL, 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::MouseMove( const MouseEvent& rMEvt )
133 return FuConstruct::MouseMove(rMEvt);
136 bool FuConstructArc::MouseButtonUp( const MouseEvent& rMEvt )
138 bool bReturn = false;
139 bool bCreated = false;
141 if ( mpView->IsCreateObj() && rMEvt.IsLeft() )
143 const size_t nCount = mpView->GetSdrPageView()->GetObjList()->GetObjCount();
145 if (mpView->EndCreateObj(SDRCREATE_NEXTPOINT) )
147 if (nCount != mpView->GetSdrPageView()->GetObjList()->GetObjCount())
149 bCreated = true;
153 bReturn = true;
156 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
158 if (!bPermanent && bCreated)
159 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
161 return bReturn;
165 * Process keyboard input
166 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
168 bool FuConstructArc::KeyInput(const KeyEvent& rKEvt)
170 return FuConstruct::KeyInput(rKEvt);
173 void FuConstructArc::Activate()
175 SdrObjKind aObjKind;
177 switch( nSlotId )
179 case SID_DRAW_ARC :
180 case SID_DRAW_CIRCLEARC:
182 aObjKind = OBJ_CARC;
184 break;
186 case SID_DRAW_PIE :
187 case SID_DRAW_PIE_NOFILL :
188 case SID_DRAW_CIRCLEPIE :
189 case SID_DRAW_CIRCLEPIE_NOFILL:
191 aObjKind = OBJ_SECT;
193 break;
195 case SID_DRAW_ELLIPSECUT :
196 case SID_DRAW_ELLIPSECUT_NOFILL:
197 case SID_DRAW_CIRCLECUT :
198 case SID_DRAW_CIRCLECUT_NOFILL :
200 aObjKind = OBJ_CCUT;
202 break;
204 default:
206 aObjKind = OBJ_CARC;
208 break;
211 mpView->SetCurrentObj((sal_uInt16)aObjKind);
213 FuConstruct::Activate();
216 void FuConstructArc::Deactivate()
218 FuConstruct::Deactivate();
221 SdrObject* FuConstructArc::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
224 SdrObject* pObj = SdrObjFactory::MakeNewObject(
225 mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
226 0L, mpDoc);
228 if(pObj)
230 if(pObj->ISA(SdrCircObj))
232 Rectangle aRect(rRectangle);
234 if(SID_DRAW_ARC == nID ||
235 SID_DRAW_CIRCLEARC == nID ||
236 SID_DRAW_CIRCLEPIE == nID ||
237 SID_DRAW_CIRCLEPIE_NOFILL == nID ||
238 SID_DRAW_CIRCLECUT == nID ||
239 SID_DRAW_CIRCLECUT_NOFILL == nID)
241 // force quadratic
242 ImpForceQuadratic(aRect);
245 pObj->SetLogicRect(aRect);
247 SfxItemSet aAttr(mpDoc->GetPool());
248 aAttr.Put(makeSdrCircStartAngleItem(9000));
249 aAttr.Put(makeSdrCircEndAngleItem(0));
251 if(SID_DRAW_PIE_NOFILL == nID ||
252 SID_DRAW_CIRCLEPIE_NOFILL == nID ||
253 SID_DRAW_ELLIPSECUT_NOFILL == nID ||
254 SID_DRAW_CIRCLECUT_NOFILL == nID)
256 aAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
259 pObj->SetMergedItemSet(aAttr);
261 else
263 OSL_FAIL("Object is NO circle object");
267 return pObj;
270 } // end of namespace sd
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */