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 .
21 #include "fuconarc.hxx"
22 #include <svx/svdpagv.hxx>
23 #include <svx/svdocirc.hxx>
24 #include <sfx2/request.hxx>
25 #include <svl/intitem.hxx>
26 #include <svl/aeitem.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <svx/svdobj.hxx>
29 #include <sfx2/viewfrm.hxx>
32 #include <svx/svxids.hrc>
37 #include "drawdoc.hxx"
38 #include "res_bmp.hrc"
40 #include "ViewShell.hxx"
41 #include "ViewShellBase.hxx"
42 #include "ToolBarManager.hxx"
44 #include <svx/sxciaitm.hxx>
48 TYPEINIT1( FuConstructArc
, FuConstruct
);
51 FuConstructArc::FuConstructArc (
57 : FuConstruct( pViewSh
, pWin
, pView
, pDoc
, rReq
)
61 FunctionReference
FuConstructArc::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
63 FuConstructArc
* pFunc
;
64 FunctionReference
xFunc( pFunc
= new FuConstructArc( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
65 xFunc
->DoExecute(rReq
);
66 pFunc
->SetPermanent(bPermanent
);
70 void FuConstructArc::DoExecute( SfxRequest
& rReq
)
72 FuConstruct::DoExecute( rReq
);
74 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
75 ToolBarManager::TBG_FUNCTION
,
76 ToolBarManager::msDrawingObjectToolBar
);
78 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
82 SFX_REQUEST_ARG (rReq
, pCenterX
, SfxUInt32Item
, ID_VAL_CENTER_X
, sal_False
);
83 SFX_REQUEST_ARG (rReq
, pCenterY
, SfxUInt32Item
, ID_VAL_CENTER_Y
, sal_False
);
84 SFX_REQUEST_ARG (rReq
, pAxisX
, SfxUInt32Item
, ID_VAL_AXIS_X
, sal_False
);
85 SFX_REQUEST_ARG (rReq
, pAxisY
, SfxUInt32Item
, ID_VAL_AXIS_Y
, sal_False
);
86 SFX_REQUEST_ARG (rReq
, pPhiStart
, SfxUInt32Item
, ID_VAL_ANGLESTART
, sal_False
);
87 SFX_REQUEST_ARG (rReq
, pPhiEnd
, SfxUInt32Item
, ID_VAL_ANGLEEND
, sal_False
);
89 Rectangle
aNewRectangle (pCenterX
->GetValue () - pAxisX
->GetValue () / 2,
90 pCenterY
->GetValue () - pAxisY
->GetValue () / 2,
91 pCenterX
->GetValue () + pAxisX
->GetValue () / 2,
92 pCenterY
->GetValue () + pAxisY
->GetValue () / 2);
94 Activate(); // sets aObjKind
95 SdrCircObj
* pNewCircle
=
96 new SdrCircObj((SdrObjKind
) mpView
->GetCurrentObjIdentifier(),
98 (long) (pPhiStart
->GetValue () * 10.0),
99 (long) (pPhiEnd
->GetValue () * 10.0));
100 SdrPageView
*pPV
= mpView
->GetSdrPageView();
102 mpView
->InsertObjectAtView(pNewCircle
, *pPV
, SDRINSERT_SETDEFLAYER
);
107 sal_Bool
FuConstructArc::MouseButtonDown( const MouseEvent
& rMEvt
)
109 sal_Bool bReturn
= FuConstruct::MouseButtonDown( rMEvt
);
111 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
113 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
114 mpWindow
->CaptureMouse();
115 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
116 mpView
->BegCreateObj(aPnt
, (OutputDevice
*) NULL
, nDrgLog
);
118 SdrObject
* pObj
= mpView
->GetCreateObj();
122 SfxItemSet
aAttr(mpDoc
->GetPool());
123 SetStyleSheet(aAttr
, pObj
);
125 pObj
->SetMergedItemSet(aAttr
);
134 sal_Bool
FuConstructArc::MouseMove( const MouseEvent
& rMEvt
)
136 return FuConstruct::MouseMove(rMEvt
);
140 sal_Bool
FuConstructArc::MouseButtonUp( const MouseEvent
& rMEvt
)
142 sal_Bool bReturn
= sal_False
;
143 sal_Bool bCreated
= sal_False
;
145 if ( mpView
->IsCreateObj() && rMEvt
.IsLeft() )
147 sal_uLong nCount
= mpView
->GetSdrPageView()->GetObjList()->GetObjCount();
149 if (mpView
->EndCreateObj(SDRCREATE_NEXTPOINT
) )
151 if (nCount
!= mpView
->GetSdrPageView()->GetObjList()->GetObjCount())
160 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
162 if (!bPermanent
&& bCreated
)
163 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SFX_CALLMODE_ASYNCHRON
);
169 * Process keyboard input
170 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
172 sal_Bool
FuConstructArc::KeyInput(const KeyEvent
& rKEvt
)
174 sal_Bool bReturn
= FuConstruct::KeyInput(rKEvt
);
179 void FuConstructArc::Activate()
186 case SID_DRAW_CIRCLEARC
:
193 case SID_DRAW_PIE_NOFILL
:
194 case SID_DRAW_CIRCLEPIE
:
195 case SID_DRAW_CIRCLEPIE_NOFILL
:
201 case SID_DRAW_ELLIPSECUT
:
202 case SID_DRAW_ELLIPSECUT_NOFILL
:
203 case SID_DRAW_CIRCLECUT
:
204 case SID_DRAW_CIRCLECUT_NOFILL
:
217 mpView
->SetCurrentObj((sal_uInt16
)aObjKind
);
219 FuConstruct::Activate();
223 void FuConstructArc::Deactivate()
225 FuConstruct::Deactivate();
228 SdrObject
* FuConstructArc::CreateDefaultObject(const sal_uInt16 nID
, const Rectangle
& rRectangle
)
231 SdrObject
* pObj
= SdrObjFactory::MakeNewObject(
232 mpView
->GetCurrentObjInventor(), mpView
->GetCurrentObjIdentifier(),
237 if(pObj
->ISA(SdrCircObj
))
239 Rectangle
aRect(rRectangle
);
241 if(SID_DRAW_ARC
== nID
||
242 SID_DRAW_CIRCLEARC
== nID
||
243 SID_DRAW_CIRCLEPIE
== nID
||
244 SID_DRAW_CIRCLEPIE_NOFILL
== nID
||
245 SID_DRAW_CIRCLECUT
== nID
||
246 SID_DRAW_CIRCLECUT_NOFILL
== nID
)
249 ImpForceQuadratic(aRect
);
252 pObj
->SetLogicRect(aRect
);
254 SfxItemSet
aAttr(mpDoc
->GetPool());
255 aAttr
.Put(SdrCircStartAngleItem(9000));
256 aAttr
.Put(SdrCircEndAngleItem(0));
258 if(SID_DRAW_PIE_NOFILL
== nID
||
259 SID_DRAW_CIRCLEPIE_NOFILL
== nID
||
260 SID_DRAW_ELLIPSECUT_NOFILL
== nID
||
261 SID_DRAW_CIRCLECUT_NOFILL
== nID
)
263 aAttr
.Put(XFillStyleItem(XFILL_NONE
));
266 pObj
->SetMergedItemSet(aAttr
);
270 OSL_FAIL("Object is NO circle object");
277 } // end of namespace sd
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */