Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / sc / source / ui / drawfunc / fuconpol.cxx
blob12183dd164bfc52d4206fa286febe5d6661af391
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 bool FuConstPolygon::MouseButtonDown(const MouseEvent& rMEvt)
61 // remember button state for creation of own MouseEvents
62 SetMouseButtonCode(rMEvt.GetButtons());
64 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(true);
79 if ( pView->MouseButtonDown(rMEvt, pWindow) )
80 bReturn = true;
82 return bReturn;
85 /*************************************************************************
87 |* MouseMove-event
89 \************************************************************************/
91 bool FuConstPolygon::MouseMove(const MouseEvent& rMEvt)
93 pView->MouseMove(rMEvt, pWindow);
94 return FuConstruct::MouseMove(rMEvt);
97 /*************************************************************************
99 |* MouseButtonUp-event
101 \************************************************************************/
103 bool FuConstPolygon::MouseButtonUp(const MouseEvent& rMEvt)
105 // remember button state for creation of own MouseEvents
106 SetMouseButtonCode(rMEvt.GetButtons());
108 bool bReturn = false;
109 bool bSimple = false;
111 SdrViewEvent aVEvt;
112 (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt);
114 pView->MouseButtonUp(rMEvt, pWindow);
116 if (aVEvt.eEvent == SDREVENT_ENDCREATE)
118 bReturn = true;
119 bSimple = true; // Doppelklick nicht weiterreichen
122 bool bParent;
123 if (bSimple)
124 bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
125 else
126 bParent = FuConstruct::MouseButtonUp(rMEvt);
128 return (bParent || bReturn);
131 /*************************************************************************
133 |* Tastaturereignisse bearbeiten
135 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
136 |* FALSE.
138 \************************************************************************/
140 bool FuConstPolygon::KeyInput(const KeyEvent& rKEvt)
142 return FuConstruct::KeyInput(rKEvt);
145 /*************************************************************************
147 |* Function aktivieren
149 \************************************************************************/
151 void FuConstPolygon::Activate()
153 pView->EnableExtendedMouseEventDispatcher(true);
155 SdrObjKind eKind;
157 switch (GetSlotID())
159 case SID_DRAW_POLYGON_NOFILL:
160 case SID_DRAW_XPOLYGON_NOFILL:
162 eKind = OBJ_PLIN;
164 break;
166 case SID_DRAW_POLYGON:
167 case SID_DRAW_XPOLYGON:
169 eKind = OBJ_POLY;
171 break;
173 case SID_DRAW_BEZIER_NOFILL:
175 eKind = OBJ_PATHLINE;
177 break;
179 case SID_DRAW_BEZIER_FILL:
181 eKind = OBJ_PATHFILL;
183 break;
185 case SID_DRAW_FREELINE_NOFILL:
187 eKind = OBJ_FREELINE;
189 break;
191 case SID_DRAW_FREELINE:
193 eKind = OBJ_FREEFILL;
195 break;
197 default:
199 eKind = OBJ_PATHLINE;
201 break;
204 pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(eKind));
206 pView->SetEditMode(SDREDITMODE_CREATE);
208 FuConstruct::Activate();
210 aNewPointer = Pointer( POINTER_DRAW_POLYGON );
211 aOldPointer = pWindow->GetPointer();
212 pViewShell->SetActivePointer( aNewPointer );
215 /*************************************************************************
217 |* Function deaktivieren
219 \************************************************************************/
221 void FuConstPolygon::Deactivate()
223 pView->SetEditMode(SDREDITMODE_EDIT);
225 pView->EnableExtendedMouseEventDispatcher(false);
227 FuConstruct::Deactivate();
229 pViewShell->SetActivePointer( aOldPointer );
232 // Create default drawing objects via keyboard
233 SdrObject* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
235 // case SID_DRAW_POLYGON:
236 // case SID_DRAW_POLYGON_NOFILL:
237 // case SID_DRAW_BEZIER_NOFILL:
238 // case SID_DRAW_FREELINE_NOFILL:
240 SdrObject* pObj = SdrObjFactory::MakeNewObject(
241 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
242 0L, pDrDoc);
244 if(pObj)
246 if(pObj->ISA(SdrPathObj))
248 basegfx::B2DPolyPolygon aPoly;
250 switch(nID)
252 case SID_DRAW_BEZIER_NOFILL:
254 basegfx::B2DPolygon aInnerPoly;
256 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
258 const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
259 aInnerPoly.appendBezierSegment(
260 aCenterBottom,
261 aCenterBottom,
262 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
264 const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
265 aInnerPoly.appendBezierSegment(
266 aCenterTop,
267 aCenterTop,
268 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
270 aPoly.append(aInnerPoly);
271 break;
273 case SID_DRAW_FREELINE_NOFILL:
275 basegfx::B2DPolygon aInnerPoly;
277 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
279 aInnerPoly.appendBezierSegment(
280 basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
281 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
282 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
284 aInnerPoly.appendBezierSegment(
285 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
286 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
287 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
289 aPoly.append(aInnerPoly);
290 break;
292 case SID_DRAW_POLYGON:
293 case SID_DRAW_POLYGON_NOFILL:
295 basegfx::B2DPolygon aInnerPoly;
296 const sal_Int32 nWdt(rRectangle.GetWidth());
297 const sal_Int32 nHgt(rRectangle.GetHeight());
299 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
300 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
301 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
302 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
303 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
304 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
305 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
306 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
308 if(SID_DRAW_POLYGON_NOFILL == nID)
310 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
312 else
314 aInnerPoly.setClosed(true);
317 aPoly.append(aInnerPoly);
318 break;
322 ((SdrPathObj*)pObj)->SetPathPoly(aPoly);
324 else
326 OSL_FAIL("Object is NO path object");
329 pObj->SetLogicRect(rRectangle);
332 return pObj;
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */