tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / drawfunc / fuconpol.cxx
blob7290b5186ad79fcb57101dce563c29cc0f89549b
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 <drawview.hxx>
24 // Create default drawing objects via keyboard
25 #include <svx/svdopath.hxx>
26 #include <svx/svxids.hrc>
27 #include <osl/diagnose.h>
28 #include <basegfx/polygon/b2dpolygon.hxx>
29 #include <basegfx/point/b2dpoint.hxx>
31 FuConstPolygon::FuConstPolygon(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP,
32 SdrModel* pDoc, const SfxRequest& rReq)
33 : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
37 FuConstPolygon::~FuConstPolygon()
41 bool FuConstPolygon::MouseButtonDown(const MouseEvent& rMEvt)
43 // remember button state for creation of own MouseEvents
44 SetMouseButtonCode(rMEvt.GetButtons());
46 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
48 SdrViewEvent aVEvt;
49 (void)pView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
50 if (aVEvt.meEvent == SdrEventKind::BeginTextEdit)
52 // Text input not allowed here
53 aVEvt.meEvent = SdrEventKind::BeginDragObj;
54 pView->EnableExtendedMouseEventDispatcher(false);
56 else
58 pView->EnableExtendedMouseEventDispatcher(true);
61 if ( pView->MouseButtonDown(rMEvt, pWindow->GetOutDev()) )
62 bReturn = true;
64 return bReturn;
67 bool FuConstPolygon::MouseMove(const MouseEvent& rMEvt)
69 pView->MouseMove(rMEvt, pWindow->GetOutDev());
70 return FuConstruct::MouseMove(rMEvt);
73 bool FuConstPolygon::MouseButtonUp(const MouseEvent& rMEvt)
75 // remember button state for creation of own MouseEvents
76 SetMouseButtonCode(rMEvt.GetButtons());
78 bool bReturn = false;
79 bool bSimple = false;
81 SdrViewEvent aVEvt;
82 (void)pView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONUP, aVEvt);
84 pView->MouseButtonUp(rMEvt, pWindow->GetOutDev());
86 if (aVEvt.meEvent == SdrEventKind::EndCreate)
88 bReturn = true;
89 bSimple = true; // Do not pass on double-click
92 bool bParent;
93 if (bSimple)
94 bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
95 else
96 bParent = FuConstruct::MouseButtonUp(rMEvt);
98 return (bParent || bReturn);
101 void FuConstPolygon::Activate()
103 pView->EnableExtendedMouseEventDispatcher(true);
105 SdrObjKind eKind;
107 switch (GetSlotID())
109 case SID_DRAW_POLYGON_NOFILL:
110 case SID_DRAW_XPOLYGON_NOFILL:
112 eKind = SdrObjKind::PolyLine;
114 break;
116 case SID_DRAW_POLYGON:
117 case SID_DRAW_XPOLYGON:
119 eKind = SdrObjKind::Polygon;
121 break;
123 case SID_DRAW_BEZIER_NOFILL:
125 eKind = SdrObjKind::PathLine;
127 break;
129 case SID_DRAW_BEZIER_FILL:
131 eKind = SdrObjKind::PathFill;
133 break;
135 case SID_DRAW_FREELINE_NOFILL:
137 eKind = SdrObjKind::FreehandLine;
139 break;
141 case SID_DRAW_FREELINE:
143 eKind = SdrObjKind::FreehandFill;
145 break;
147 default:
149 eKind = SdrObjKind::PathLine;
151 break;
154 pView->SetCurrentObj(eKind);
156 pView->SetEditMode(SdrViewEditMode::Create);
158 FuConstruct::Activate();
160 aNewPointer = PointerStyle::DrawPolygon;
161 aOldPointer = pWindow->GetPointer();
162 rViewShell.SetActivePointer( aNewPointer );
165 void FuConstPolygon::Deactivate()
167 pView->SetEditMode(SdrViewEditMode::Edit);
169 pView->EnableExtendedMouseEventDispatcher(false);
171 FuConstruct::Deactivate();
173 rViewShell.SetActivePointer( aOldPointer );
176 // Create default drawing objects via keyboard
177 rtl::Reference<SdrObject> FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle& rRectangle)
179 // case SID_DRAW_XPOLYGON:
180 // case SID_DRAW_XPOLYGON_NOFILL:
181 // case SID_DRAW_POLYGON:
182 // case SID_DRAW_POLYGON_NOFILL:
183 // case SID_DRAW_BEZIER_FILL:
184 // case SID_DRAW_BEZIER_NOFILL:
185 // case SID_DRAW_FREELINE:
186 // case SID_DRAW_FREELINE_NOFILL:
188 rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject(
189 *pDrDoc,
190 pView->GetCurrentObjInventor(),
191 pView->GetCurrentObjIdentifier()));
193 if(pObj)
195 if(dynamic_cast<const SdrPathObj*>( pObj.get() ) != nullptr)
197 basegfx::B2DPolyPolygon aPoly;
199 switch(nID)
201 case SID_DRAW_BEZIER_FILL:
202 case SID_DRAW_BEZIER_NOFILL:
204 basegfx::B2DPolygon aInnerPoly;
206 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
208 const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
209 aInnerPoly.appendBezierSegment(
210 aCenterBottom,
211 aCenterBottom,
212 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
214 const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
215 aInnerPoly.appendBezierSegment(
216 aCenterTop,
217 aCenterTop,
218 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
220 aPoly.append(aInnerPoly);
221 break;
223 case SID_DRAW_FREELINE:
224 case SID_DRAW_FREELINE_NOFILL:
226 basegfx::B2DPolygon aInnerPoly;
228 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
230 aInnerPoly.appendBezierSegment(
231 basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
232 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
233 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
235 aInnerPoly.appendBezierSegment(
236 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
237 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
238 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
240 aPoly.append(aInnerPoly);
241 break;
243 case SID_DRAW_XPOLYGON:
244 case SID_DRAW_XPOLYGON_NOFILL:
245 case SID_DRAW_POLYGON:
246 case SID_DRAW_POLYGON_NOFILL:
248 basegfx::B2DPolygon aInnerPoly;
249 const sal_Int32 nWdt(rRectangle.GetWidth());
250 const sal_Int32 nHgt(rRectangle.GetHeight());
252 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
253 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
254 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
255 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
256 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
257 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
258 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
259 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
261 if(SID_DRAW_POLYGON_NOFILL == nID)
263 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
265 else
267 aInnerPoly.setClosed(true);
270 aPoly.append(aInnerPoly);
271 break;
275 static_cast<SdrPathObj*>(pObj.get())->SetPathPoly(aPoly);
277 else
279 OSL_FAIL("Object is NO path object");
282 pObj->SetLogicRect(rRectangle);
285 return pObj;
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */