fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / drawfunc / fuconpol.cxx
blob2132b081d9eb3c49e142ecef688e68a1df5b8125
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 .
20 #include "fuconpol.hxx"
21 #include "tabvwsh.hxx"
22 #include "sc.hrc"
23 #include "drawview.hxx"
25 // Create default drawing objects via keyboard
26 #include <svx/svdopath.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <basegfx/point/b2dpoint.hxx>
30 /*************************************************************************
32 |* Konstruktor
34 \************************************************************************/
36 FuConstPolygon::FuConstPolygon(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP,
37 SdrModel* pDoc, SfxRequest& rReq)
38 : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
42 /*************************************************************************
44 |* Destruktor
46 \************************************************************************/
48 FuConstPolygon::~FuConstPolygon()
52 /*************************************************************************
54 |* MouseButtonDown-event
56 \************************************************************************/
58 bool FuConstPolygon::MouseButtonDown(const MouseEvent& rMEvt)
60 // remember button state for creation of own MouseEvents
61 SetMouseButtonCode(rMEvt.GetButtons());
63 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
65 SdrViewEvent aVEvt;
66 (void)pView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
67 if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT)
69 // Texteingabe hier nicht zulassen
70 aVEvt.eEvent = SDREVENT_BEGDRAGOBJ;
71 pView->EnableExtendedMouseEventDispatcher(false);
73 else
75 pView->EnableExtendedMouseEventDispatcher(true);
78 if ( pView->MouseButtonDown(rMEvt, pWindow) )
79 bReturn = true;
81 return bReturn;
84 /*************************************************************************
86 |* MouseMove-event
88 \************************************************************************/
90 bool FuConstPolygon::MouseMove(const MouseEvent& rMEvt)
92 pView->MouseMove(rMEvt, pWindow);
93 return FuConstruct::MouseMove(rMEvt);
96 /*************************************************************************
98 |* MouseButtonUp-event
100 \************************************************************************/
102 bool FuConstPolygon::MouseButtonUp(const MouseEvent& rMEvt)
104 // remember button state for creation of own MouseEvents
105 SetMouseButtonCode(rMEvt.GetButtons());
107 bool bReturn = false;
108 bool bSimple = false;
110 SdrViewEvent aVEvt;
111 (void)pView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONUP, aVEvt);
113 pView->MouseButtonUp(rMEvt, pWindow);
115 if (aVEvt.eEvent == SDREVENT_ENDCREATE)
117 bReturn = true;
118 bSimple = true; // Doppelklick nicht weiterreichen
121 bool bParent;
122 if (bSimple)
123 bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
124 else
125 bParent = FuConstruct::MouseButtonUp(rMEvt);
127 return (bParent || bReturn);
130 /*************************************************************************
132 |* Tastaturereignisse bearbeiten
134 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
135 |* FALSE.
137 \************************************************************************/
139 bool FuConstPolygon::KeyInput(const KeyEvent& rKEvt)
141 return FuConstruct::KeyInput(rKEvt);
144 /*************************************************************************
146 |* Function aktivieren
148 \************************************************************************/
150 void FuConstPolygon::Activate()
152 pView->EnableExtendedMouseEventDispatcher(true);
154 SdrObjKind eKind;
156 switch (GetSlotID())
158 case SID_DRAW_POLYGON_NOFILL:
159 case SID_DRAW_XPOLYGON_NOFILL:
161 eKind = OBJ_PLIN;
163 break;
165 case SID_DRAW_POLYGON:
166 case SID_DRAW_XPOLYGON:
168 eKind = OBJ_POLY;
170 break;
172 case SID_DRAW_BEZIER_NOFILL:
174 eKind = OBJ_PATHLINE;
176 break;
178 case SID_DRAW_BEZIER_FILL:
180 eKind = OBJ_PATHFILL;
182 break;
184 case SID_DRAW_FREELINE_NOFILL:
186 eKind = OBJ_FREELINE;
188 break;
190 case SID_DRAW_FREELINE:
192 eKind = OBJ_FREEFILL;
194 break;
196 default:
198 eKind = OBJ_PATHLINE;
200 break;
203 pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(eKind));
205 pView->SetEditMode(SDREDITMODE_CREATE);
207 FuConstruct::Activate();
209 aNewPointer = Pointer( PointerStyle::DrawPolygon );
210 aOldPointer = pWindow->GetPointer();
211 pViewShell->SetActivePointer( aNewPointer );
214 /*************************************************************************
216 |* Function deaktivieren
218 \************************************************************************/
220 void FuConstPolygon::Deactivate()
222 pView->SetEditMode(SDREDITMODE_EDIT);
224 pView->EnableExtendedMouseEventDispatcher(false);
226 FuConstruct::Deactivate();
228 pViewShell->SetActivePointer( aOldPointer );
231 // Create default drawing objects via keyboard
232 SdrObject* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
234 // case SID_DRAW_POLYGON:
235 // case SID_DRAW_POLYGON_NOFILL:
236 // case SID_DRAW_BEZIER_NOFILL:
237 // case SID_DRAW_FREELINE_NOFILL:
239 SdrObject* pObj = SdrObjFactory::MakeNewObject(
240 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
241 0L, pDrDoc);
243 if(pObj)
245 if(pObj->ISA(SdrPathObj))
247 basegfx::B2DPolyPolygon aPoly;
249 switch(nID)
251 case SID_DRAW_BEZIER_NOFILL:
253 basegfx::B2DPolygon aInnerPoly;
255 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
257 const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
258 aInnerPoly.appendBezierSegment(
259 aCenterBottom,
260 aCenterBottom,
261 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
263 const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
264 aInnerPoly.appendBezierSegment(
265 aCenterTop,
266 aCenterTop,
267 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
269 aPoly.append(aInnerPoly);
270 break;
272 case SID_DRAW_FREELINE_NOFILL:
274 basegfx::B2DPolygon aInnerPoly;
276 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
278 aInnerPoly.appendBezierSegment(
279 basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
280 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
281 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
283 aInnerPoly.appendBezierSegment(
284 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
285 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
286 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
288 aPoly.append(aInnerPoly);
289 break;
291 case SID_DRAW_POLYGON:
292 case SID_DRAW_POLYGON_NOFILL:
294 basegfx::B2DPolygon aInnerPoly;
295 const sal_Int32 nWdt(rRectangle.GetWidth());
296 const sal_Int32 nHgt(rRectangle.GetHeight());
298 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
299 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
300 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
301 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
302 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
303 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
304 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
305 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
307 if(SID_DRAW_POLYGON_NOFILL == nID)
309 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
311 else
313 aInnerPoly.setClosed(true);
316 aPoly.append(aInnerPoly);
317 break;
321 static_cast<SdrPathObj*>(pObj)->SetPathPoly(aPoly);
323 else
325 OSL_FAIL("Object is NO path object");
328 pObj->SetLogicRect(rRectangle);
331 return pObj;
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */