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>
29 
31  SdrModel* pDoc, const SfxRequest& rReq)
32  : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
33 {
34 }
35 
37 {
38 }
39 
41 {
42  // remember button state for creation of own MouseEvents
44 
45  bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
46 
47  SdrViewEvent aVEvt;
48  (void)pView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
49  if (aVEvt.eEvent == SdrEventKind::BeginTextEdit)
50  {
51  // Text input not allowed here
52  aVEvt.eEvent = SdrEventKind::BeginDragObj;
54  }
55  else
56  {
58  }
59 
60  if ( pView->MouseButtonDown(rMEvt, pWindow) )
61  bReturn = true;
62 
63  return bReturn;
64 }
65 
67 {
68  pView->MouseMove(rMEvt, pWindow);
69  return FuConstruct::MouseMove(rMEvt);
70 }
71 
73 {
74  // remember button state for creation of own MouseEvents
76 
77  bool bReturn = false;
78  bool bSimple = false;
79 
80  SdrViewEvent aVEvt;
81  (void)pView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONUP, aVEvt);
82 
83  pView->MouseButtonUp(rMEvt, pWindow);
84 
85  if (aVEvt.eEvent == SdrEventKind::EndCreate)
86  {
87  bReturn = true;
88  bSimple = true; // Do not pass on double-click
89  }
90 
91  bool bParent;
92  if (bSimple)
93  bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
94  else
95  bParent = FuConstruct::MouseButtonUp(rMEvt);
96 
97  return (bParent || bReturn);
98 }
99 
101 {
103 
104  SdrObjKind eKind;
105 
106  switch (GetSlotID())
107  {
108  case SID_DRAW_POLYGON_NOFILL:
109  case SID_DRAW_XPOLYGON_NOFILL:
110  {
111  eKind = OBJ_PLIN;
112  }
113  break;
114 
115  case SID_DRAW_POLYGON:
116  case SID_DRAW_XPOLYGON:
117  {
118  eKind = OBJ_POLY;
119  }
120  break;
121 
122  case SID_DRAW_BEZIER_NOFILL:
123  {
124  eKind = OBJ_PATHLINE;
125  }
126  break;
127 
128  case SID_DRAW_BEZIER_FILL:
129  {
130  eKind = OBJ_PATHFILL;
131  }
132  break;
133 
134  case SID_DRAW_FREELINE_NOFILL:
135  {
136  eKind = OBJ_FREELINE;
137  }
138  break;
139 
140  case SID_DRAW_FREELINE:
141  {
142  eKind = OBJ_FREEFILL;
143  }
144  break;
145 
146  default:
147  {
148  eKind = OBJ_PATHLINE;
149  }
150  break;
151  }
152 
153  pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(eKind));
154 
155  pView->SetEditMode(SdrViewEditMode::Create);
156 
158 
159  aNewPointer = PointerStyle::DrawPolygon;
162 }
163 
165 {
166  pView->SetEditMode(SdrViewEditMode::Edit);
167 
169 
171 
173 }
174 
175 // Create default drawing objects via keyboard
177 {
178  // case SID_DRAW_XPOLYGON:
179  // case SID_DRAW_XPOLYGON_NOFILL:
180  // case SID_DRAW_POLYGON:
181  // case SID_DRAW_POLYGON_NOFILL:
182  // case SID_DRAW_BEZIER_FILL:
183  // case SID_DRAW_BEZIER_NOFILL:
184  // case SID_DRAW_FREELINE:
185  // case SID_DRAW_FREELINE_NOFILL:
186 
188  *pDrDoc,
191 
192  if(pObj)
193  {
194  if(dynamic_cast<const SdrPathObj*>( pObj.get() ) != nullptr)
195  {
197 
198  switch(nID)
199  {
200  case SID_DRAW_BEZIER_FILL:
201  case SID_DRAW_BEZIER_NOFILL:
202  {
203  basegfx::B2DPolygon aInnerPoly;
204 
205  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
206 
207  const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
208  aInnerPoly.appendBezierSegment(
209  aCenterBottom,
210  aCenterBottom,
211  basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
212 
213  const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
214  aInnerPoly.appendBezierSegment(
215  aCenterTop,
216  aCenterTop,
217  basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
218 
219  aPoly.append(aInnerPoly);
220  break;
221  }
222  case SID_DRAW_FREELINE:
223  case SID_DRAW_FREELINE_NOFILL:
224  {
225  basegfx::B2DPolygon aInnerPoly;
226 
227  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
228 
229  aInnerPoly.appendBezierSegment(
230  basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
231  basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
232  basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
233 
234  aInnerPoly.appendBezierSegment(
235  basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
236  basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
237  basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
238 
239  aPoly.append(aInnerPoly);
240  break;
241  }
242  case SID_DRAW_XPOLYGON:
243  case SID_DRAW_XPOLYGON_NOFILL:
244  case SID_DRAW_POLYGON:
245  case SID_DRAW_POLYGON_NOFILL:
246  {
247  basegfx::B2DPolygon aInnerPoly;
248  const sal_Int32 nWdt(rRectangle.GetWidth());
249  const sal_Int32 nHgt(rRectangle.GetHeight());
250 
251  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
252  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
253  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
254  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
255  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
256  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
257  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
258  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
259 
260  if(SID_DRAW_POLYGON_NOFILL == nID)
261  {
262  aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
263  }
264  else
265  {
266  aInnerPoly.setClosed(true);
267  }
268 
269  aPoly.append(aInnerPoly);
270  break;
271  }
272  }
273 
274  static_cast<SdrPathObj*>(pObj.get())->SetPathPoly(aPoly);
275  }
276  else
277  {
278  OSL_FAIL("Object is NO path object");
279  }
280 
281  pObj->SetLogicRect(rRectangle);
282  }
283 
284  return pObj;
285 }
286 
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long GetWidth() const
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
PointerStyle aOldPointer
Definition: fudraw.hxx:32
long GetHeight() const
virtual void Activate() override
Definition: fuconpol.cxx:100
FuConstPolygon(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, const SfxRequest &rReq)
Definition: fuconpol.cxx:30
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:87
virtual ~FuConstPolygon() override
Definition: fuconpol.cxx:36
void appendBezierSegment(const basegfx::B2DPoint &rNextControlPoint, const basegfx::B2DPoint &rPrevControlPoint, const basegfx::B2DPoint &rPoint)
SdrModel * pDrDoc
Definition: fupoor.hxx:46
SdrHitKind PickAnything(const MouseEvent &rMEvt, SdrMouseEventKind nMouseDownOrMoveOrUp, SdrViewEvent &rVEvt) const
OBJ_POLY
void EnableExtendedMouseEventDispatcher(bool bOn)
OBJ_FREEFILL
Draw rectangle.
Definition: fuconstr.hxx:26
OBJ_PLIN
long Right() const
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:128
sal_uInt16 GetButtons() const
void SetMouseButtonCode(sal_uInt16 nNew)
Definition: fupoor.hxx:71
sal_uInt16 GetCurrentObjIdentifier() const
OBJ_PATHLINE
void SetEditMode(SdrViewEditMode eMode)
static SdrObject * MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, sal_uInt16 nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
ScTabViewShell & rViewShell
Definition: fupoor.hxx:44
virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle &rRectangle) override
Definition: fuconpol.cxx:176
long Top() const
sal_uInt16 GetSlotID() const
Definition: fupoor.hxx:91
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:46
PointerStyle GetPointer() const
void SetActivePointer(PointerStyle nPointer)
Definition: tabview.cxx:891
virtual bool MouseButtonUp(const MouseEvent &rMEvt, OutputDevice *pWin) override
SdrEventKind eEvent
long Bottom() const
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconpol.cxx:72
virtual bool MouseButtonDown(const MouseEvent &_rMEvt, OutputDevice *_pWin) override
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: fuconpol.cxx:66
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
OBJ_FREELINE
bool SimpleMouseButtonUp(const MouseEvent &rMEvt)
Definition: fuconstr.cxx:179
void setClosed(bool bNew)
SdrObjKind
void SetCurrentObj(sal_uInt16 nIdent, SdrInventor nInvent=SdrInventor::Default)
ScDrawView * pView
Definition: fupoor.hxx:43
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
long Left() const
PointerStyle aNewPointer
Definition: fudraw.hxx:31
virtual bool MouseMove(const MouseEvent &rMEvt, OutputDevice *pWin) override
virtual void Deactivate() override
Definition: fuconpol.cxx:164
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconpol.cxx:40
virtual void Activate()
Definition: fupoor.cxx:59
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:45
OBJ_PATHFILL
SdrInventor GetCurrentObjInventor() const
Point Center() const
virtual void Deactivate()
Definition: fupoor.cxx:63
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo