1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuconpol.cxx,v $
10 * $Revision: 1.9.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "fuconpol.hxx"
35 #include "tabvwsh.hxx"
37 #include "drawview.hxx"
39 // #98185# Create default drawing objects via keyboard
40 #include <svx/svdopath.hxx>
41 #include <basegfx/polygon/b2dpolygon.hxx>
42 #include <basegfx/point/b2dpoint.hxx>
44 // Pixelabstand zum Schliessen von Freihand-Zeichnungen
46 #define CLOSE_PIXDIST 5
49 //------------------------------------------------------------------------
51 /*************************************************************************
55 \************************************************************************/
57 FuConstPolygon::FuConstPolygon(ScTabViewShell
* pViewSh
, Window
* pWin
, ScDrawView
* pViewP
,
58 SdrModel
* pDoc
, SfxRequest
& rReq
)
59 : FuConstruct(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
63 /*************************************************************************
67 \************************************************************************/
69 FuConstPolygon::~FuConstPolygon()
73 /*************************************************************************
75 |* MouseButtonDown-event
77 \************************************************************************/
79 BOOL __EXPORT
FuConstPolygon::MouseButtonDown(const MouseEvent
& rMEvt
)
81 // #95491# remember button state for creation of own MouseEvents
82 SetMouseButtonCode(rMEvt
.GetButtons());
84 BOOL bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
87 (void)pView
->PickAnything(rMEvt
, SDRMOUSEBUTTONDOWN
, aVEvt
);
88 if (aVEvt
.eEvent
== SDREVENT_BEGTEXTEDIT
)
90 // Texteingabe hier nicht zulassen
91 aVEvt
.eEvent
= SDREVENT_BEGDRAGOBJ
;
92 pView
->EnableExtendedMouseEventDispatcher(FALSE
);
96 pView
->EnableExtendedMouseEventDispatcher(TRUE
);
99 if ( pView
->MouseButtonDown(rMEvt
, pWindow
) )
105 /*************************************************************************
109 \************************************************************************/
111 BOOL __EXPORT
FuConstPolygon::MouseMove(const MouseEvent
& rMEvt
)
113 pView
->MouseMove(rMEvt
, pWindow
);
114 BOOL bReturn
= FuConstruct::MouseMove(rMEvt
);
118 /*************************************************************************
120 |* MouseButtonUp-event
122 \************************************************************************/
124 BOOL __EXPORT
FuConstPolygon::MouseButtonUp(const MouseEvent
& rMEvt
)
126 // #95491# remember button state for creation of own MouseEvents
127 SetMouseButtonCode(rMEvt
.GetButtons());
129 BOOL bReturn
= FALSE
;
130 BOOL bSimple
= FALSE
;
133 (void)pView
->PickAnything(rMEvt
, SDRMOUSEBUTTONUP
, aVEvt
);
135 pView
->MouseButtonUp(rMEvt
, pWindow
);
137 if (aVEvt
.eEvent
== SDREVENT_ENDCREATE
)
140 bSimple
= TRUE
; // Doppelklick nicht weiterreichen
145 bParent
= FuConstruct::SimpleMouseButtonUp(rMEvt
);
147 bParent
= FuConstruct::MouseButtonUp(rMEvt
);
149 return (bParent
|| bReturn
);
152 /*************************************************************************
154 |* Tastaturereignisse bearbeiten
156 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
159 \************************************************************************/
161 BOOL __EXPORT
FuConstPolygon::KeyInput(const KeyEvent
& rKEvt
)
163 BOOL bReturn
= FuConstruct::KeyInput(rKEvt
);
168 /*************************************************************************
170 |* Function aktivieren
172 \************************************************************************/
174 void FuConstPolygon::Activate()
176 pView
->EnableExtendedMouseEventDispatcher(TRUE
);
182 case SID_DRAW_POLYGON_NOFILL
:
183 case SID_DRAW_XPOLYGON_NOFILL
:
189 case SID_DRAW_POLYGON
:
190 case SID_DRAW_XPOLYGON
:
196 case SID_DRAW_BEZIER_NOFILL
:
198 eKind
= OBJ_PATHLINE
;
202 case SID_DRAW_BEZIER_FILL
:
204 eKind
= OBJ_PATHFILL
;
208 case SID_DRAW_FREELINE_NOFILL
:
210 eKind
= OBJ_FREELINE
;
214 case SID_DRAW_FREELINE
:
216 eKind
= OBJ_FREEFILL
;
222 eKind
= OBJ_PATHLINE
;
227 pView
->SetCurrentObj(sal::static_int_cast
<UINT16
>(eKind
));
229 pView
->SetEditMode(SDREDITMODE_CREATE
);
231 FuConstruct::Activate();
233 aNewPointer
= Pointer( POINTER_DRAW_POLYGON
);
234 aOldPointer
= pWindow
->GetPointer();
235 pViewShell
->SetActivePointer( aNewPointer
);
238 /*************************************************************************
240 |* Function deaktivieren
242 \************************************************************************/
244 void FuConstPolygon::Deactivate()
246 pView
->SetEditMode(SDREDITMODE_EDIT
);
248 pView
->EnableExtendedMouseEventDispatcher(FALSE
);
250 FuConstruct::Deactivate();
252 pViewShell
->SetActivePointer( aOldPointer
);
255 // #98185# Create default drawing objects via keyboard
256 SdrObject
* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID
, const Rectangle
& rRectangle
)
258 // case SID_DRAW_POLYGON:
259 // case SID_DRAW_POLYGON_NOFILL:
260 // case SID_DRAW_BEZIER_NOFILL:
261 // case SID_DRAW_FREELINE_NOFILL:
263 SdrObject
* pObj
= SdrObjFactory::MakeNewObject(
264 pView
->GetCurrentObjInventor(), pView
->GetCurrentObjIdentifier(),
269 if(pObj
->ISA(SdrPathObj
))
271 basegfx::B2DPolyPolygon aPoly
;
275 case SID_DRAW_BEZIER_NOFILL
:
277 basegfx::B2DPolygon aInnerPoly
;
279 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left(), rRectangle
.Bottom()));
281 const basegfx::B2DPoint
aCenterBottom(rRectangle
.Center().X(), rRectangle
.Bottom());
282 aInnerPoly
.appendBezierSegment(
285 basegfx::B2DPoint(rRectangle
.Center().X(), rRectangle
.Center().Y()));
287 const basegfx::B2DPoint
aCenterTop(rRectangle
.Center().X(), rRectangle
.Top());
288 aInnerPoly
.appendBezierSegment(
291 basegfx::B2DPoint(rRectangle
.Right(), rRectangle
.Top()));
293 aPoly
.append(aInnerPoly
);
296 case SID_DRAW_FREELINE_NOFILL
:
298 basegfx::B2DPolygon aInnerPoly
;
300 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left(), rRectangle
.Bottom()));
302 aInnerPoly
.appendBezierSegment(
303 basegfx::B2DPoint(rRectangle
.Left(), rRectangle
.Top()),
304 basegfx::B2DPoint(rRectangle
.Center().X(), rRectangle
.Top()),
305 basegfx::B2DPoint(rRectangle
.Center().X(), rRectangle
.Center().Y()));
307 aInnerPoly
.appendBezierSegment(
308 basegfx::B2DPoint(rRectangle
.Center().X(), rRectangle
.Bottom()),
309 basegfx::B2DPoint(rRectangle
.Right(), rRectangle
.Bottom()),
310 basegfx::B2DPoint(rRectangle
.Right(), rRectangle
.Top()));
312 aPoly
.append(aInnerPoly
);
315 case SID_DRAW_POLYGON
:
316 case SID_DRAW_POLYGON_NOFILL
:
318 basegfx::B2DPolygon aInnerPoly
;
319 const sal_Int32
nWdt(rRectangle
.GetWidth());
320 const sal_Int32
nHgt(rRectangle
.GetHeight());
322 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left(), rRectangle
.Bottom()));
323 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left() + (nWdt
* 30) / 100, rRectangle
.Top() + (nHgt
* 70) / 100));
324 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left(), rRectangle
.Top() + (nHgt
* 15) / 100));
325 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left() + (nWdt
* 65) / 100, rRectangle
.Top()));
326 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left() + nWdt
, rRectangle
.Top() + (nHgt
* 30) / 100));
327 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left() + (nWdt
* 80) / 100, rRectangle
.Top() + (nHgt
* 50) / 100));
328 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Left() + (nWdt
* 80) / 100, rRectangle
.Top() + (nHgt
* 75) / 100));
329 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Bottom(), rRectangle
.Right()));
331 if(SID_DRAW_POLYGON_NOFILL
== nID
)
333 aInnerPoly
.append(basegfx::B2DPoint(rRectangle
.Center().X(), rRectangle
.Bottom()));
337 aInnerPoly
.setClosed(true);
340 aPoly
.append(aInnerPoly
);
345 ((SdrPathObj
*)pObj
)->SetPathPoly(aPoly
);
349 DBG_ERROR("Object is NO path object");
352 pObj
->SetLogicRect(rRectangle
);