LibreOffice Module sc (master)  1
fuconpol.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <fuconpol.hxx>
21 #include <tabvwsh.hxx>
22 #include <drawview.hxx>
23 
24 // Create default drawing objects via keyboard
25 #include <svx/svdopath.hxx>
26 #include <svx/svxids.hrc>
27 #include <osl/diagnose.h>
30 
32  SdrModel* pDoc, const SfxRequest& rReq)
33  : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
34 {
35 }
36 
38 {
39 }
40 
42 {
43  // remember button state for creation of own MouseEvents
45 
46  bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
47 
48  SdrViewEvent aVEvt;
49  (void)pView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
50  if (aVEvt.eEvent == SdrEventKind::BeginTextEdit)
51  {
52  // Text input not allowed here
53  aVEvt.eEvent = SdrEventKind::BeginDragObj;
55  }
56  else
57  {
59  }
60 
61  if ( pView->MouseButtonDown(rMEvt, pWindow) )
62  bReturn = true;
63 
64  return bReturn;
65 }
66 
68 {
69  pView->MouseMove(rMEvt, pWindow);
70  return FuConstruct::MouseMove(rMEvt);
71 }
72 
74 {
75  // remember button state for creation of own MouseEvents
77 
78  bool bReturn = false;
79  bool bSimple = false;
80 
81  SdrViewEvent aVEvt;
82  (void)pView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONUP, aVEvt);
83 
84  pView->MouseButtonUp(rMEvt, pWindow);
85 
86  if (aVEvt.eEvent == SdrEventKind::EndCreate)
87  {
88  bReturn = true;
89  bSimple = true; // Do not pass on double-click
90  }
91 
92  bool bParent;
93  if (bSimple)
94  bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
95  else
96  bParent = FuConstruct::MouseButtonUp(rMEvt);
97 
98  return (bParent || bReturn);
99 }
100 
102 {
104 
105  SdrObjKind eKind;
106 
107  switch (GetSlotID())
108  {
109  case SID_DRAW_POLYGON_NOFILL:
110  case SID_DRAW_XPOLYGON_NOFILL:
111  {
112  eKind = OBJ_PLIN;
113  }
114  break;
115 
116  case SID_DRAW_POLYGON:
117  case SID_DRAW_XPOLYGON:
118  {
119  eKind = OBJ_POLY;
120  }
121  break;
122 
123  case SID_DRAW_BEZIER_NOFILL:
124  {
125  eKind = OBJ_PATHLINE;
126  }
127  break;
128 
129  case SID_DRAW_BEZIER_FILL:
130  {
131  eKind = OBJ_PATHFILL;
132  }
133  break;
134 
135  case SID_DRAW_FREELINE_NOFILL:
136  {
137  eKind = OBJ_FREELINE;
138  }
139  break;
140 
141  case SID_DRAW_FREELINE:
142  {
143  eKind = OBJ_FREEFILL;
144  }
145  break;
146 
147  default:
148  {
149  eKind = OBJ_PATHLINE;
150  }
151  break;
152  }
153 
154  pView->SetCurrentObj(eKind);
155 
156  pView->SetEditMode(SdrViewEditMode::Create);
157 
159 
160  aNewPointer = PointerStyle::DrawPolygon;
163 }
164 
166 {
167  pView->SetEditMode(SdrViewEditMode::Edit);
168 
170 
172 
174 }
175 
176 // Create default drawing objects via keyboard
178 {
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:
187 
189  *pDrDoc,
192 
193  if(pObj)
194  {
195  if(dynamic_cast<const SdrPathObj*>( pObj.get() ) != nullptr)
196  {
198 
199  switch(nID)
200  {
201  case SID_DRAW_BEZIER_FILL:
202  case SID_DRAW_BEZIER_NOFILL:
203  {
204  basegfx::B2DPolygon aInnerPoly;
205 
206  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
207 
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()));
213 
214  const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
215  aInnerPoly.appendBezierSegment(
216  aCenterTop,
217  aCenterTop,
218  basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
219 
220  aPoly.append(aInnerPoly);
221  break;
222  }
223  case SID_DRAW_FREELINE:
224  case SID_DRAW_FREELINE_NOFILL:
225  {
226  basegfx::B2DPolygon aInnerPoly;
227 
228  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
229 
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()));
234 
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()));
239 
240  aPoly.append(aInnerPoly);
241  break;
242  }
243  case SID_DRAW_XPOLYGON:
244  case SID_DRAW_XPOLYGON_NOFILL:
245  case SID_DRAW_POLYGON:
246  case SID_DRAW_POLYGON_NOFILL:
247  {
248  basegfx::B2DPolygon aInnerPoly;
249  const sal_Int32 nWdt(rRectangle.GetWidth());
250  const sal_Int32 nHgt(rRectangle.GetHeight());
251 
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()));
260 
261  if(SID_DRAW_POLYGON_NOFILL == nID)
262  {
263  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
264  }
265  else
266  {
267  aInnerPoly.setClosed(true);
268  }
269 
270  aPoly.append(aInnerPoly);
271  break;
272  }
273  }
274 
275  static_cast<SdrPathObj*>(pObj.get())->SetPathPoly(aPoly);
276  }
277  else
278  {
279  OSL_FAIL("Object is NO path object");
280  }
281 
282  pObj->SetLogicRect(rRectangle);
283  }
284 
285  return pObj;
286 }
287 
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
PointerStyle aOldPointer
Definition: fudraw.hxx:31
virtual void Activate() override
Definition: fuconpol.cxx:101
FuConstPolygon(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, const SfxRequest &rReq)
Definition: fuconpol.cxx:31
virtual SC_DLLPUBLIC bool MouseMove(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:87
OBJ_POLY
virtual ~FuConstPolygon() override
Definition: fuconpol.cxx:37
void appendBezierSegment(const basegfx::B2DPoint &rNextControlPoint, const basegfx::B2DPoint &rPrevControlPoint, const basegfx::B2DPoint &rPoint)
static SdrObject * MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, SdrObjKind nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
tools::Long GetWidth() const
SdrModel * pDrDoc
Definition: fupoor.hxx:45
SdrHitKind PickAnything(const MouseEvent &rMEvt, SdrMouseEventKind nMouseDownOrMoveOrUp, SdrViewEvent &rVEvt) const
void EnableExtendedMouseEventDispatcher(bool bOn)
Draw rectangle.
Definition: fuconstr.hxx:27
SdrObjKind
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:128
sal_uInt16 GetButtons() const
tools::Long Left() const
void SetMouseButtonCode(sal_uInt16 nNew)
Definition: fupoor.hxx:70
tools::Long Bottom() const
void SetEditMode(SdrViewEditMode eMode)
ScTabViewShell & rViewShell
Definition: fupoor.hxx:43
virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle &rRectangle) override
Definition: fuconpol.cxx:177
sal_uInt16 GetSlotID() const
Definition: fupoor.hxx:90
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:46
PointerStyle GetPointer() const
OBJ_PATHFILL
void SetActivePointer(PointerStyle nPointer)
Definition: tabview.cxx:894
virtual bool MouseButtonUp(const MouseEvent &rMEvt, OutputDevice *pWin) override
SdrEventKind eEvent
OBJ_FREEFILL
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconpol.cxx:73
void SetCurrentObj(SdrObjKind nIdent, SdrInventor nInvent=SdrInventor::Default)
OBJ_PLIN
OBJ_FREELINE
virtual bool MouseButtonDown(const MouseEvent &_rMEvt, OutputDevice *_pWin) override
tools::Long Top() const
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: fuconpol.cxx:67
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
bool SimpleMouseButtonUp(const MouseEvent &rMEvt)
Definition: fuconstr.cxx:179
void setClosed(bool bNew)
ScDrawView * pView
Definition: fupoor.hxx:42
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
PointerStyle aNewPointer
Definition: fudraw.hxx:30
tools::Long GetHeight() const
OBJ_PATHLINE
virtual bool MouseMove(const MouseEvent &rMEvt, OutputDevice *pWin) override
virtual void Deactivate() override
Definition: fuconpol.cxx:165
SdrObjKind GetCurrentObjIdentifier() const
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconpol.cxx:41
virtual void Activate()
Definition: fupoor.cxx:59
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:44
tools::Long Right() const
SdrInventor GetCurrentObjInventor() const
Point Center() const
virtual void Deactivate()
Definition: fupoor.cxx:63
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo