xref: /aoo41x/main/sd/source/ui/func/fuconarc.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "fuconarc.hxx"
32 #include <svx/svdpagv.hxx>
33 #include <svx/svdocirc.hxx>
34 #include <sfx2/request.hxx>
35 #include <svl/intitem.hxx>
36 #include <svl/aeitem.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <svx/svdobj.hxx>
39 #include <sfx2/viewfrm.hxx>
40 
41 
42 #include <svx/svxids.hrc>
43 #include <math.h>
44 
45 #include "app.hrc"
46 #include "Window.hxx"
47 #include "drawdoc.hxx"
48 #include "res_bmp.hrc"
49 #include "View.hxx"
50 #include "ViewShell.hxx"
51 #include "ViewShellBase.hxx"
52 #include "ToolBarManager.hxx"
53 
54 // #97016#
55 #include <svx/sxciaitm.hxx>
56 
57 namespace sd {
58 
59 TYPEINIT1( FuConstructArc, FuConstruct );
60 
61 /*************************************************************************
62 |*
63 |* Konstruktor
64 |*
65 \************************************************************************/
66 
67 FuConstructArc::FuConstructArc (
68     ViewShell*	pViewSh,
69     ::sd::Window*		pWin,
70     ::sd::View* 		pView,
71     SdDrawDocument* pDoc,
72     SfxRequest& 	rReq )
73 	: FuConstruct( pViewSh, pWin, pView, pDoc, rReq )
74 {
75 }
76 
77 FunctionReference FuConstructArc::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent  )
78 {
79 	FuConstructArc* pFunc;
80 	FunctionReference xFunc( pFunc = new FuConstructArc( pViewSh, pWin, pView, pDoc, rReq ) );
81 	xFunc->DoExecute(rReq);
82 	pFunc->SetPermanent(bPermanent);
83 	return xFunc;
84 }
85 
86 void FuConstructArc::DoExecute( SfxRequest& rReq )
87 {
88 	FuConstruct::DoExecute( rReq );
89 
90     mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
91         ToolBarManager::TBG_FUNCTION,
92         ToolBarManager::msDrawingObjectToolBar);
93 
94 	const SfxItemSet *pArgs = rReq.GetArgs ();
95 
96 	if (pArgs)
97 	{
98 		SFX_REQUEST_ARG (rReq, pCenterX, SfxUInt32Item, ID_VAL_CENTER_X, sal_False);
99 		SFX_REQUEST_ARG (rReq, pCenterY, SfxUInt32Item, ID_VAL_CENTER_Y, sal_False);
100 		SFX_REQUEST_ARG (rReq, pAxisX, SfxUInt32Item, ID_VAL_AXIS_X, sal_False);
101 		SFX_REQUEST_ARG (rReq, pAxisY, SfxUInt32Item, ID_VAL_AXIS_Y, sal_False);
102 		SFX_REQUEST_ARG (rReq, pPhiStart, SfxUInt32Item, ID_VAL_ANGLESTART, sal_False);
103 		SFX_REQUEST_ARG (rReq, pPhiEnd, SfxUInt32Item, ID_VAL_ANGLEEND, sal_False);
104 
105 		Rectangle	aNewRectangle (pCenterX->GetValue () - pAxisX->GetValue () / 2,
106 								   pCenterY->GetValue () - pAxisY->GetValue () / 2,
107 								   pCenterX->GetValue () + pAxisX->GetValue () / 2,
108 								   pCenterY->GetValue () + pAxisY->GetValue () / 2);
109 
110 		Activate();  // Setzt aObjKind
111 		SdrCircObj* pNewCircle =
112 		new SdrCircObj((SdrObjKind) mpView->GetCurrentObjIdentifier(),
113 					   aNewRectangle,
114 					   (long) (pPhiStart->GetValue () * 10.0),
115 					   (long) (pPhiEnd->GetValue () * 10.0));
116 		SdrPageView *pPV = mpView->GetSdrPageView();
117 
118 		mpView->InsertObjectAtView(pNewCircle, *pPV, SDRINSERT_SETDEFLAYER);
119 	}
120 }
121 
122 /*************************************************************************
123 |*
124 |* MouseButtonDown-event
125 |*
126 \************************************************************************/
127 
128 sal_Bool FuConstructArc::MouseButtonDown( const MouseEvent& rMEvt )
129 {
130 	sal_Bool bReturn = FuConstruct::MouseButtonDown( rMEvt );
131 
132 	if ( rMEvt.IsLeft() && !mpView->IsAction() )
133 	{
134 		Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
135 		mpWindow->CaptureMouse();
136 		sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
137 		mpView->BegCreateObj(aPnt, (OutputDevice*) NULL, nDrgLog);
138 
139 		SdrObject* pObj = mpView->GetCreateObj();
140 
141 		if (pObj)
142 		{
143 			SfxItemSet aAttr(mpDoc->GetPool());
144 			SetStyleSheet(aAttr, pObj);
145 
146 //-/			pObj->NbcSetAttributes(aAttr, sal_False);
147 			pObj->SetMergedItemSet(aAttr);
148 		}
149 
150 		bReturn = sal_True;
151 	}
152 	return bReturn;
153 }
154 
155 /*************************************************************************
156 |*
157 |* MouseMove-event
158 |*
159 \************************************************************************/
160 
161 sal_Bool FuConstructArc::MouseMove( const MouseEvent& rMEvt )
162 {
163 	return FuConstruct::MouseMove(rMEvt);
164 }
165 
166 /*************************************************************************
167 |*
168 |* MouseButtonUp-event
169 |*
170 \************************************************************************/
171 
172 sal_Bool FuConstructArc::MouseButtonUp( const MouseEvent& rMEvt )
173 {
174 	sal_Bool bReturn = sal_False;
175 	sal_Bool bCreated = sal_False;
176 
177 	if ( mpView->IsCreateObj() && rMEvt.IsLeft() )
178 	{
179 		Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
180 
181 		sal_uLong nCount = mpView->GetSdrPageView()->GetObjList()->GetObjCount();
182 
183 		if (mpView->EndCreateObj(SDRCREATE_NEXTPOINT) )
184 		{
185 			if (nCount != mpView->GetSdrPageView()->GetObjList()->GetObjCount())
186 			{
187 				bCreated = sal_True;
188 			}
189 		}
190 
191 		bReturn = sal_True;
192 	}
193 
194 	bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
195 
196 	if (!bPermanent && bCreated)
197 		mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
198 
199 	return bReturn;
200 }
201 
202 /*************************************************************************
203 |*
204 |* Tastaturereignisse bearbeiten
205 |*
206 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
207 |* sal_False.
208 |*
209 \************************************************************************/
210 
211 sal_Bool FuConstructArc::KeyInput(const KeyEvent& rKEvt)
212 {
213 	sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
214 	return(bReturn);
215 }
216 
217 /*************************************************************************
218 |*
219 |* Function aktivieren
220 |*
221 \************************************************************************/
222 
223 void FuConstructArc::Activate()
224 {
225 	SdrObjKind aObjKind;
226 
227 	switch( nSlotId )
228 	{
229 		case SID_DRAW_ARC	   :
230 		case SID_DRAW_CIRCLEARC:
231 		{
232 			aObjKind = OBJ_CARC;
233 		}
234 		break;
235 
236 		case SID_DRAW_PIE			  :
237 		case SID_DRAW_PIE_NOFILL	  :
238 		case SID_DRAW_CIRCLEPIE 	  :
239 		case SID_DRAW_CIRCLEPIE_NOFILL:
240 		{
241 			aObjKind = OBJ_SECT;
242 		}
243 		break;
244 
245 		case SID_DRAW_ELLIPSECUT	   :
246 		case SID_DRAW_ELLIPSECUT_NOFILL:
247 		case SID_DRAW_CIRCLECUT 	   :
248 		case SID_DRAW_CIRCLECUT_NOFILL :
249 		{
250 			aObjKind = OBJ_CCUT;
251 		}
252 		break;
253 
254 		default:
255 		{
256 			aObjKind = OBJ_CARC;
257 		}
258 		break;
259 	}
260 
261 	mpView->SetCurrentObj((sal_uInt16)aObjKind);
262 
263 	FuConstruct::Activate();
264 //	FuDraw::Activate();
265 }
266 
267 /*************************************************************************
268 |*
269 |* Function deaktivieren
270 |*
271 \************************************************************************/
272 
273 void FuConstructArc::Deactivate()
274 {
275 	FuConstruct::Deactivate();
276 //	FuDraw::Deactivate();
277 }
278 
279 // #97016#
280 SdrObject* FuConstructArc::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
281 {
282 	// case SID_DRAW_ARC:
283 	// case SID_DRAW_CIRCLEARC:
284 	// case SID_DRAW_PIE:
285 	// case SID_DRAW_PIE_NOFILL:
286 	// case SID_DRAW_CIRCLEPIE:
287 	// case SID_DRAW_CIRCLEPIE_NOFILL:
288 	// case SID_DRAW_ELLIPSECUT:
289 	// case SID_DRAW_ELLIPSECUT_NOFILL:
290 	// case SID_DRAW_CIRCLECUT:
291 	// case SID_DRAW_CIRCLECUT_NOFILL:
292 
293 	SdrObject* pObj = SdrObjFactory::MakeNewObject(
294 		mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
295 		0L, mpDoc);
296 
297 	if(pObj)
298 	{
299 		if(pObj->ISA(SdrCircObj))
300 		{
301 			Rectangle aRect(rRectangle);
302 
303 			if(SID_DRAW_ARC == nID ||
304 				SID_DRAW_CIRCLEARC == nID ||
305 				SID_DRAW_CIRCLEPIE == nID ||
306 				SID_DRAW_CIRCLEPIE_NOFILL == nID ||
307 				SID_DRAW_CIRCLECUT == nID ||
308 				SID_DRAW_CIRCLECUT_NOFILL == nID)
309 			{
310 				// force quadratic
311 				ImpForceQuadratic(aRect);
312 			}
313 
314 			pObj->SetLogicRect(aRect);
315 
316 			SfxItemSet aAttr(mpDoc->GetPool());
317 			aAttr.Put(SdrCircStartAngleItem(9000));
318 			aAttr.Put(SdrCircEndAngleItem(0));
319 
320 			if(SID_DRAW_PIE_NOFILL == nID ||
321 				SID_DRAW_CIRCLEPIE_NOFILL == nID ||
322 				SID_DRAW_ELLIPSECUT_NOFILL == nID ||
323 				SID_DRAW_CIRCLECUT_NOFILL == nID)
324 			{
325 				aAttr.Put(XFillStyleItem(XFILL_NONE));
326 			}
327 
328 			pObj->SetMergedItemSet(aAttr);
329 		}
330 		else
331 		{
332 			DBG_ERROR("Object is NO circle object");
333 		}
334 	}
335 
336 	return pObj;
337 }
338 
339 } // end of namespace sd
340