Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / drawfunc / fuconpol.cxx
blob62dbcf3690437a66609208b8230045d8794c7985
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 .
21 #include "fuconpol.hxx"
22 #include "tabvwsh.hxx"
23 #include "sc.hrc"
24 #include "drawview.hxx"
26 // Create default drawing objects via keyboard
27 #include <svx/svdopath.hxx>
28 #include <basegfx/polygon/b2dpolygon.hxx>
29 #include <basegfx/point/b2dpoint.hxx>
31 /*************************************************************************
33 |* Konstruktor
35 \************************************************************************/
37 FuConstPolygon::FuConstPolygon(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
38 SdrModel* pDoc, SfxRequest& rReq)
39 : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
43 /*************************************************************************
45 |* Destruktor
47 \************************************************************************/
49 FuConstPolygon::~FuConstPolygon()
53 /*************************************************************************
55 |* MouseButtonDown-event
57 \************************************************************************/
59 sal_Bool FuConstPolygon::MouseButtonDown(const MouseEvent& rMEvt)
61 // remember button state for creation of own MouseEvents
62 SetMouseButtonCode(rMEvt.GetButtons());
64 sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
66 SdrViewEvent aVEvt;
67 (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
68 if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT)
70 // Texteingabe hier nicht zulassen
71 aVEvt.eEvent = SDREVENT_BEGDRAGOBJ;
72 pView->EnableExtendedMouseEventDispatcher(false);
74 else
76 pView->EnableExtendedMouseEventDispatcher(sal_True);
79 if ( pView->MouseButtonDown(rMEvt, pWindow) )
80 bReturn = sal_True;
82 return bReturn;
85 /*************************************************************************
87 |* MouseMove-event
89 \************************************************************************/
91 sal_Bool FuConstPolygon::MouseMove(const MouseEvent& rMEvt)
93 pView->MouseMove(rMEvt, pWindow);
94 sal_Bool bReturn = FuConstruct::MouseMove(rMEvt);
95 return bReturn;
98 /*************************************************************************
100 |* MouseButtonUp-event
102 \************************************************************************/
104 sal_Bool FuConstPolygon::MouseButtonUp(const MouseEvent& rMEvt)
106 // remember button state for creation of own MouseEvents
107 SetMouseButtonCode(rMEvt.GetButtons());
109 sal_Bool bReturn = false;
110 sal_Bool bSimple = false;
112 SdrViewEvent aVEvt;
113 (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt);
115 pView->MouseButtonUp(rMEvt, pWindow);
117 if (aVEvt.eEvent == SDREVENT_ENDCREATE)
119 bReturn = sal_True;
120 bSimple = sal_True; // Doppelklick nicht weiterreichen
123 sal_Bool bParent;
124 if (bSimple)
125 bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
126 else
127 bParent = FuConstruct::MouseButtonUp(rMEvt);
129 return (bParent || bReturn);
132 /*************************************************************************
134 |* Tastaturereignisse bearbeiten
136 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
137 |* FALSE.
139 \************************************************************************/
141 sal_Bool FuConstPolygon::KeyInput(const KeyEvent& rKEvt)
143 sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
145 return(bReturn);
148 /*************************************************************************
150 |* Function aktivieren
152 \************************************************************************/
154 void FuConstPolygon::Activate()
156 pView->EnableExtendedMouseEventDispatcher(sal_True);
158 SdrObjKind eKind;
160 switch (GetSlotID())
162 case SID_DRAW_POLYGON_NOFILL:
163 case SID_DRAW_XPOLYGON_NOFILL:
165 eKind = OBJ_PLIN;
167 break;
169 case SID_DRAW_POLYGON:
170 case SID_DRAW_XPOLYGON:
172 eKind = OBJ_POLY;
174 break;
176 case SID_DRAW_BEZIER_NOFILL:
178 eKind = OBJ_PATHLINE;
180 break;
182 case SID_DRAW_BEZIER_FILL:
184 eKind = OBJ_PATHFILL;
186 break;
188 case SID_DRAW_FREELINE_NOFILL:
190 eKind = OBJ_FREELINE;
192 break;
194 case SID_DRAW_FREELINE:
196 eKind = OBJ_FREEFILL;
198 break;
200 default:
202 eKind = OBJ_PATHLINE;
204 break;
207 pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(eKind));
209 pView->SetEditMode(SDREDITMODE_CREATE);
211 FuConstruct::Activate();
213 aNewPointer = Pointer( POINTER_DRAW_POLYGON );
214 aOldPointer = pWindow->GetPointer();
215 pViewShell->SetActivePointer( aNewPointer );
218 /*************************************************************************
220 |* Function deaktivieren
222 \************************************************************************/
224 void FuConstPolygon::Deactivate()
226 pView->SetEditMode(SDREDITMODE_EDIT);
228 pView->EnableExtendedMouseEventDispatcher(false);
230 FuConstruct::Deactivate();
232 pViewShell->SetActivePointer( aOldPointer );
235 // Create default drawing objects via keyboard
236 SdrObject* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
238 // case SID_DRAW_POLYGON:
239 // case SID_DRAW_POLYGON_NOFILL:
240 // case SID_DRAW_BEZIER_NOFILL:
241 // case SID_DRAW_FREELINE_NOFILL:
243 SdrObject* pObj = SdrObjFactory::MakeNewObject(
244 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
245 0L, pDrDoc);
247 if(pObj)
249 if(pObj->ISA(SdrPathObj))
251 basegfx::B2DPolyPolygon aPoly;
253 switch(nID)
255 case SID_DRAW_BEZIER_NOFILL:
257 basegfx::B2DPolygon aInnerPoly;
259 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
261 const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
262 aInnerPoly.appendBezierSegment(
263 aCenterBottom,
264 aCenterBottom,
265 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
267 const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
268 aInnerPoly.appendBezierSegment(
269 aCenterTop,
270 aCenterTop,
271 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
273 aPoly.append(aInnerPoly);
274 break;
276 case SID_DRAW_FREELINE_NOFILL:
278 basegfx::B2DPolygon aInnerPoly;
280 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
282 aInnerPoly.appendBezierSegment(
283 basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
284 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
285 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
287 aInnerPoly.appendBezierSegment(
288 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
289 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
290 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
292 aPoly.append(aInnerPoly);
293 break;
295 case SID_DRAW_POLYGON:
296 case SID_DRAW_POLYGON_NOFILL:
298 basegfx::B2DPolygon aInnerPoly;
299 const sal_Int32 nWdt(rRectangle.GetWidth());
300 const sal_Int32 nHgt(rRectangle.GetHeight());
302 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
303 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
304 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
305 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
306 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
307 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
308 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
309 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
311 if(SID_DRAW_POLYGON_NOFILL == nID)
313 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
315 else
317 aInnerPoly.setClosed(true);
320 aPoly.append(aInnerPoly);
321 break;
325 ((SdrPathObj*)pObj)->SetPathPoly(aPoly);
327 else
329 OSL_FAIL("Object is NO path object");
332 pObj->SetLogicRect(rRectangle);
335 return pObj;
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */