xref: /aoo42x/main/sc/source/ui/drawfunc/fuconpol.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_sc.hxx"
30 
31 #include "fuconpol.hxx"
32 #include "tabvwsh.hxx"
33 #include "sc.hrc"
34 #include "drawview.hxx"
35 
36 // #98185# Create default drawing objects via keyboard
37 #include <svx/svdopath.hxx>
38 #include <basegfx/polygon/b2dpolygon.hxx>
39 #include <basegfx/point/b2dpoint.hxx>
40 
41 //	Pixelabstand zum Schliessen von Freihand-Zeichnungen
42 #ifndef CLOSE_PIXDIST
43 #define CLOSE_PIXDIST 5
44 #endif
45 
46 //------------------------------------------------------------------------
47 
48 /*************************************************************************
49 |*
50 |* Konstruktor
51 |*
52 \************************************************************************/
53 
54 FuConstPolygon::FuConstPolygon(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
55 				   SdrModel* pDoc, SfxRequest& rReq)
56     : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
57 {
58 }
59 
60 /*************************************************************************
61 |*
62 |* Destruktor
63 |*
64 \************************************************************************/
65 
66 FuConstPolygon::~FuConstPolygon()
67 {
68 }
69 
70 /*************************************************************************
71 |*
72 |* MouseButtonDown-event
73 |*
74 \************************************************************************/
75 
76 sal_Bool __EXPORT FuConstPolygon::MouseButtonDown(const MouseEvent& rMEvt)
77 {
78 	// #95491# remember button state for creation of own MouseEvents
79 	SetMouseButtonCode(rMEvt.GetButtons());
80 
81 	sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
82 
83 	SdrViewEvent aVEvt;
84     (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
85 	if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT)
86 	{
87 		// Texteingabe hier nicht zulassen
88 		aVEvt.eEvent = SDREVENT_BEGDRAGOBJ;
89 		pView->EnableExtendedMouseEventDispatcher(sal_False);
90 	}
91 	else
92 	{
93 		pView->EnableExtendedMouseEventDispatcher(sal_True);
94 	}
95 
96 	if ( pView->MouseButtonDown(rMEvt, pWindow) )
97 		bReturn = sal_True;
98 
99 	return bReturn;
100 }
101 
102 /*************************************************************************
103 |*
104 |* MouseMove-event
105 |*
106 \************************************************************************/
107 
108 sal_Bool __EXPORT FuConstPolygon::MouseMove(const MouseEvent& rMEvt)
109 {
110 	pView->MouseMove(rMEvt, pWindow);
111 	sal_Bool bReturn = FuConstruct::MouseMove(rMEvt);
112 	return bReturn;
113 }
114 
115 /*************************************************************************
116 |*
117 |* MouseButtonUp-event
118 |*
119 \************************************************************************/
120 
121 sal_Bool __EXPORT FuConstPolygon::MouseButtonUp(const MouseEvent& rMEvt)
122 {
123 	// #95491# remember button state for creation of own MouseEvents
124 	SetMouseButtonCode(rMEvt.GetButtons());
125 
126 	sal_Bool bReturn = sal_False;
127 	sal_Bool bSimple = sal_False;
128 
129 	SdrViewEvent aVEvt;
130     (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt);
131 
132 	pView->MouseButtonUp(rMEvt, pWindow);
133 
134 	if (aVEvt.eEvent == SDREVENT_ENDCREATE)
135 	{
136 		bReturn = sal_True;
137 		bSimple = sal_True;			// Doppelklick nicht weiterreichen
138 	}
139 
140 	sal_Bool bParent;
141 	if (bSimple)
142 		bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
143 	else
144 		bParent = FuConstruct::MouseButtonUp(rMEvt);
145 
146 	return (bParent || bReturn);
147 }
148 
149 /*************************************************************************
150 |*
151 |* Tastaturereignisse bearbeiten
152 |*
153 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
154 |* FALSE.
155 |*
156 \************************************************************************/
157 
158 sal_Bool __EXPORT FuConstPolygon::KeyInput(const KeyEvent& rKEvt)
159 {
160 	sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
161 
162 	return(bReturn);
163 }
164 
165 /*************************************************************************
166 |*
167 |* Function aktivieren
168 |*
169 \************************************************************************/
170 
171 void FuConstPolygon::Activate()
172 {
173 	pView->EnableExtendedMouseEventDispatcher(sal_True);
174 
175 	SdrObjKind eKind;
176 
177 	switch (GetSlotID())
178 	{
179 		case SID_DRAW_POLYGON_NOFILL:
180 		case SID_DRAW_XPOLYGON_NOFILL:
181 		{
182 			eKind = OBJ_PLIN;
183 		}
184 		break;
185 
186 		case SID_DRAW_POLYGON:
187 		case SID_DRAW_XPOLYGON:
188 		{
189 			eKind = OBJ_POLY;
190 		}
191 		break;
192 
193 		case SID_DRAW_BEZIER_NOFILL:
194 		{
195 			eKind = OBJ_PATHLINE;
196 		}
197 		break;
198 
199 		case SID_DRAW_BEZIER_FILL:
200 		{
201 			eKind = OBJ_PATHFILL;
202 		}
203 		break;
204 
205 		case SID_DRAW_FREELINE_NOFILL:
206 		{
207 			eKind = OBJ_FREELINE;
208 		}
209 		break;
210 
211 		case SID_DRAW_FREELINE:
212 		{
213 			eKind = OBJ_FREEFILL;
214 		}
215 		break;
216 
217 		default:
218 		{
219 			eKind = OBJ_PATHLINE;
220 		}
221 		break;
222 	}
223 
224     pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(eKind));
225 
226 	pView->SetEditMode(SDREDITMODE_CREATE);
227 
228 	FuConstruct::Activate();
229 
230 	aNewPointer = Pointer( POINTER_DRAW_POLYGON );
231 	aOldPointer = pWindow->GetPointer();
232 	pViewShell->SetActivePointer( aNewPointer );
233 }
234 
235 /*************************************************************************
236 |*
237 |* Function deaktivieren
238 |*
239 \************************************************************************/
240 
241 void FuConstPolygon::Deactivate()
242 {
243 	pView->SetEditMode(SDREDITMODE_EDIT);
244 
245 	pView->EnableExtendedMouseEventDispatcher(sal_False);
246 
247 	FuConstruct::Deactivate();
248 
249 	pViewShell->SetActivePointer( aOldPointer );
250 }
251 
252 // #98185# Create default drawing objects via keyboard
253 SdrObject* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
254 {
255 	// case SID_DRAW_POLYGON:
256 	// case SID_DRAW_POLYGON_NOFILL:
257 	// case SID_DRAW_BEZIER_NOFILL:
258 	// case SID_DRAW_FREELINE_NOFILL:
259 
260 	SdrObject* pObj = SdrObjFactory::MakeNewObject(
261 		pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
262 		0L, pDrDoc);
263 
264 	if(pObj)
265 	{
266 		if(pObj->ISA(SdrPathObj))
267 		{
268 			basegfx::B2DPolyPolygon aPoly;
269 
270 			switch(nID)
271 			{
272 				case SID_DRAW_BEZIER_NOFILL:
273 				{
274 					basegfx::B2DPolygon aInnerPoly;
275 
276 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
277 
278 					const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
279 					aInnerPoly.appendBezierSegment(
280 						aCenterBottom,
281 						aCenterBottom,
282 						basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
283 
284 					const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
285 					aInnerPoly.appendBezierSegment(
286 						aCenterTop,
287 						aCenterTop,
288 						basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
289 
290 					aPoly.append(aInnerPoly);
291 					break;
292 				}
293 				case SID_DRAW_FREELINE_NOFILL:
294 				{
295 					basegfx::B2DPolygon aInnerPoly;
296 
297 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
298 
299 					aInnerPoly.appendBezierSegment(
300 						basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
301 						basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
302 						basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
303 
304 					aInnerPoly.appendBezierSegment(
305 						basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
306 						basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
307 						basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
308 
309 					aPoly.append(aInnerPoly);
310 					break;
311 				}
312 				case SID_DRAW_POLYGON:
313 				case SID_DRAW_POLYGON_NOFILL:
314 				{
315 					basegfx::B2DPolygon aInnerPoly;
316 					const sal_Int32 nWdt(rRectangle.GetWidth());
317 					const sal_Int32 nHgt(rRectangle.GetHeight());
318 
319 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
320 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
321 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
322 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
323 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
324 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
325 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
326 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
327 
328 					if(SID_DRAW_POLYGON_NOFILL == nID)
329 					{
330 						aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
331 					}
332 					else
333 					{
334 						aInnerPoly.setClosed(true);
335 					}
336 
337 					aPoly.append(aInnerPoly);
338 					break;
339 				}
340 			}
341 
342 			((SdrPathObj*)pObj)->SetPathPoly(aPoly);
343 		}
344 		else
345 		{
346 			DBG_ERROR("Object is NO path object");
347 		}
348 
349 		pObj->SetLogicRect(rRectangle);
350 	}
351 
352 	return pObj;
353 }
354 
355 // eof
356