1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
);
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);
58 pView
->EnableExtendedMouseEventDispatcher(true);
61 if ( pView
->MouseButtonDown(rMEvt
, pWindow
->GetOutDev()) )
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());
82 (void)pView
->PickAnything(rMEvt
, SdrMouseEventKind::BUTTONUP
, aVEvt
);
84 pView
->MouseButtonUp(rMEvt
, pWindow
->GetOutDev());
86 if (aVEvt
.meEvent
== SdrEventKind::EndCreate
)
89 bSimple
= true; // Do not pass on double-click
94 bParent
= FuConstruct::SimpleMouseButtonUp(rMEvt
);
96 bParent
= FuConstruct::MouseButtonUp(rMEvt
);
98 return (bParent
|| bReturn
);
101 void FuConstPolygon::Activate()
103 pView
->EnableExtendedMouseEventDispatcher(true);
109 case SID_DRAW_POLYGON_NOFILL
:
110 case SID_DRAW_XPOLYGON_NOFILL
:
112 eKind
= SdrObjKind::PolyLine
;
116 case SID_DRAW_POLYGON
:
117 case SID_DRAW_XPOLYGON
:
119 eKind
= SdrObjKind::Polygon
;
123 case SID_DRAW_BEZIER_NOFILL
:
125 eKind
= SdrObjKind::PathLine
;
129 case SID_DRAW_BEZIER_FILL
:
131 eKind
= SdrObjKind::PathFill
;
135 case SID_DRAW_FREELINE_NOFILL
:
137 eKind
= SdrObjKind::FreehandLine
;
141 case SID_DRAW_FREELINE
:
143 eKind
= SdrObjKind::FreehandFill
;
149 eKind
= SdrObjKind::PathLine
;
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(
190 pView
->GetCurrentObjInventor(),
191 pView
->GetCurrentObjIdentifier()));
195 if(dynamic_cast<const SdrPathObj
*>( pObj
.get() ) != nullptr)
197 basegfx::B2DPolyPolygon aPoly
;
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(
212 basegfx::B2DPoint(rRectangle
.Center().X(), rRectangle
.Center().Y()));
214 const basegfx::B2DPoint
aCenterTop(rRectangle
.Center().X(), rRectangle
.Top());
215 aInnerPoly
.appendBezierSegment(
218 basegfx::B2DPoint(rRectangle
.Right(), rRectangle
.Top()));
220 aPoly
.append(aInnerPoly
);
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
);
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()));
267 aInnerPoly
.setClosed(true);
270 aPoly
.append(aInnerPoly
);
275 static_cast<SdrPathObj
*>(pObj
.get())->SetPathPoly(aPoly
);
279 OSL_FAIL("Object is NO path object");
282 pObj
->SetLogicRect(rRectangle
);
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */