Update ooo320-m1
[ooovba.git] / sc / source / ui / drawfunc / fuconpol.cxx
blobe0460566e67957a0e7ba01695c29abe37b6b463a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuconpol.cxx,v $
10 * $Revision: 1.9.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "fuconpol.hxx"
35 #include "tabvwsh.hxx"
36 #include "sc.hrc"
37 #include "drawview.hxx"
39 // #98185# Create default drawing objects via keyboard
40 #include <svx/svdopath.hxx>
41 #include <basegfx/polygon/b2dpolygon.hxx>
42 #include <basegfx/point/b2dpoint.hxx>
44 // Pixelabstand zum Schliessen von Freihand-Zeichnungen
45 #ifndef CLOSE_PIXDIST
46 #define CLOSE_PIXDIST 5
47 #endif
49 //------------------------------------------------------------------------
51 /*************************************************************************
53 |* Konstruktor
55 \************************************************************************/
57 FuConstPolygon::FuConstPolygon(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
58 SdrModel* pDoc, SfxRequest& rReq)
59 : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
63 /*************************************************************************
65 |* Destruktor
67 \************************************************************************/
69 FuConstPolygon::~FuConstPolygon()
73 /*************************************************************************
75 |* MouseButtonDown-event
77 \************************************************************************/
79 BOOL __EXPORT FuConstPolygon::MouseButtonDown(const MouseEvent& rMEvt)
81 // #95491# remember button state for creation of own MouseEvents
82 SetMouseButtonCode(rMEvt.GetButtons());
84 BOOL bReturn = FuConstruct::MouseButtonDown(rMEvt);
86 SdrViewEvent aVEvt;
87 (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
88 if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT)
90 // Texteingabe hier nicht zulassen
91 aVEvt.eEvent = SDREVENT_BEGDRAGOBJ;
92 pView->EnableExtendedMouseEventDispatcher(FALSE);
94 else
96 pView->EnableExtendedMouseEventDispatcher(TRUE);
99 if ( pView->MouseButtonDown(rMEvt, pWindow) )
100 bReturn = TRUE;
102 return bReturn;
105 /*************************************************************************
107 |* MouseMove-event
109 \************************************************************************/
111 BOOL __EXPORT FuConstPolygon::MouseMove(const MouseEvent& rMEvt)
113 pView->MouseMove(rMEvt, pWindow);
114 BOOL bReturn = FuConstruct::MouseMove(rMEvt);
115 return bReturn;
118 /*************************************************************************
120 |* MouseButtonUp-event
122 \************************************************************************/
124 BOOL __EXPORT FuConstPolygon::MouseButtonUp(const MouseEvent& rMEvt)
126 // #95491# remember button state for creation of own MouseEvents
127 SetMouseButtonCode(rMEvt.GetButtons());
129 BOOL bReturn = FALSE;
130 BOOL bSimple = FALSE;
132 SdrViewEvent aVEvt;
133 (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt);
135 pView->MouseButtonUp(rMEvt, pWindow);
137 if (aVEvt.eEvent == SDREVENT_ENDCREATE)
139 bReturn = TRUE;
140 bSimple = TRUE; // Doppelklick nicht weiterreichen
143 BOOL bParent;
144 if (bSimple)
145 bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
146 else
147 bParent = FuConstruct::MouseButtonUp(rMEvt);
149 return (bParent || bReturn);
152 /*************************************************************************
154 |* Tastaturereignisse bearbeiten
156 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
157 |* FALSE.
159 \************************************************************************/
161 BOOL __EXPORT FuConstPolygon::KeyInput(const KeyEvent& rKEvt)
163 BOOL bReturn = FuConstruct::KeyInput(rKEvt);
165 return(bReturn);
168 /*************************************************************************
170 |* Function aktivieren
172 \************************************************************************/
174 void FuConstPolygon::Activate()
176 pView->EnableExtendedMouseEventDispatcher(TRUE);
178 SdrObjKind eKind;
180 switch (GetSlotID())
182 case SID_DRAW_POLYGON_NOFILL:
183 case SID_DRAW_XPOLYGON_NOFILL:
185 eKind = OBJ_PLIN;
187 break;
189 case SID_DRAW_POLYGON:
190 case SID_DRAW_XPOLYGON:
192 eKind = OBJ_POLY;
194 break;
196 case SID_DRAW_BEZIER_NOFILL:
198 eKind = OBJ_PATHLINE;
200 break;
202 case SID_DRAW_BEZIER_FILL:
204 eKind = OBJ_PATHFILL;
206 break;
208 case SID_DRAW_FREELINE_NOFILL:
210 eKind = OBJ_FREELINE;
212 break;
214 case SID_DRAW_FREELINE:
216 eKind = OBJ_FREEFILL;
218 break;
220 default:
222 eKind = OBJ_PATHLINE;
224 break;
227 pView->SetCurrentObj(sal::static_int_cast<UINT16>(eKind));
229 pView->SetEditMode(SDREDITMODE_CREATE);
231 FuConstruct::Activate();
233 aNewPointer = Pointer( POINTER_DRAW_POLYGON );
234 aOldPointer = pWindow->GetPointer();
235 pViewShell->SetActivePointer( aNewPointer );
238 /*************************************************************************
240 |* Function deaktivieren
242 \************************************************************************/
244 void FuConstPolygon::Deactivate()
246 pView->SetEditMode(SDREDITMODE_EDIT);
248 pView->EnableExtendedMouseEventDispatcher(FALSE);
250 FuConstruct::Deactivate();
252 pViewShell->SetActivePointer( aOldPointer );
255 // #98185# Create default drawing objects via keyboard
256 SdrObject* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
258 // case SID_DRAW_POLYGON:
259 // case SID_DRAW_POLYGON_NOFILL:
260 // case SID_DRAW_BEZIER_NOFILL:
261 // case SID_DRAW_FREELINE_NOFILL:
263 SdrObject* pObj = SdrObjFactory::MakeNewObject(
264 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
265 0L, pDrDoc);
267 if(pObj)
269 if(pObj->ISA(SdrPathObj))
271 basegfx::B2DPolyPolygon aPoly;
273 switch(nID)
275 case SID_DRAW_BEZIER_NOFILL:
277 basegfx::B2DPolygon aInnerPoly;
279 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
281 const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
282 aInnerPoly.appendBezierSegment(
283 aCenterBottom,
284 aCenterBottom,
285 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
287 const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
288 aInnerPoly.appendBezierSegment(
289 aCenterTop,
290 aCenterTop,
291 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
293 aPoly.append(aInnerPoly);
294 break;
296 case SID_DRAW_FREELINE_NOFILL:
298 basegfx::B2DPolygon aInnerPoly;
300 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
302 aInnerPoly.appendBezierSegment(
303 basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
304 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
305 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
307 aInnerPoly.appendBezierSegment(
308 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
309 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
310 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
312 aPoly.append(aInnerPoly);
313 break;
315 case SID_DRAW_POLYGON:
316 case SID_DRAW_POLYGON_NOFILL:
318 basegfx::B2DPolygon aInnerPoly;
319 const sal_Int32 nWdt(rRectangle.GetWidth());
320 const sal_Int32 nHgt(rRectangle.GetHeight());
322 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
323 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
324 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
325 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
326 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
327 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
328 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
329 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
331 if(SID_DRAW_POLYGON_NOFILL == nID)
333 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
335 else
337 aInnerPoly.setClosed(true);
340 aPoly.append(aInnerPoly);
341 break;
345 ((SdrPathObj*)pObj)->SetPathPoly(aPoly);
347 else
349 DBG_ERROR("Object is NO path object");
352 pObj->SetLogicRect(rRectangle);
355 return pObj;
358 // eof