LibreOffice Module sc (master)  1
fupoor.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 <editeng/outliner.hxx>
21 #include <svx/svditer.hxx>
22 #include <svx/svdobj.hxx>
23 #include <svx/svdpagv.hxx>
24 #include <svx/svxids.hrc>
25 
26 #include <fupoor.hxx>
27 #include <tabvwsh.hxx>
28 #include <drawview.hxx>
29 #include <detfunc.hxx>
30 #include <document.hxx>
31 #include <vcl/commandevent.hxx>
32 #include <vcl/svapp.hxx>
33 #include <svx/sdrhittesthelper.hxx>
34 
36  SdrModel* pDoc, const SfxRequest& rReq) :
37  pView(pViewP),
38  rViewShell(rViewSh),
39  pWindow(pWin),
40  pDrDoc(pDoc),
41  aSfxRequest(rReq),
42  bIsInDragMode(false),
43  // remember MouseButton state
44  mnCode(0)
45 {
46  aScrollTimer.SetInvokeHandler( LINK(this, FuPoor, ScrollHdl) );
48 
49  aDragTimer.SetInvokeHandler( LINK(this, FuPoor, DragTimerHdl) );
51 }
52 
54 {
55  aDragTimer.Stop();
57 }
58 
60 {
61 }
62 
64 {
65  aDragTimer.Stop();
67 }
68 
69 // Scroll when reached the window border; is called from MouseMove
70 void FuPoor::ForceScroll(const Point& aPixPos)
71 {
73 
74  Size aSize = pWindow->GetSizePixel();
75  SCCOL dx = 0;
76  SCROW dy = 0;
77 
78  if ( aPixPos.X() <= 0 ) dx = -1;
79  if ( aPixPos.X() >= aSize.Width() ) dx = 1;
80  if ( aPixPos.Y() <= 0 ) dy = -1;
81  if ( aPixPos.Y() >= aSize.Height() ) dy = 1;
82 
83  ScViewData& rViewData = rViewShell.GetViewData();
84  if ( rViewData.GetDocument().IsNegativePage( rViewData.GetTabNo() ) )
85  dx = -dx;
86 
87  ScSplitPos eWhich = rViewData.GetActivePart();
88  if ( dx > 0 && rViewData.GetHSplitMode() == SC_SPLIT_FIX && WhichH(eWhich) == SC_SPLIT_LEFT )
89  {
92  dx = 0;
93  }
94  if ( dy > 0 && rViewData.GetVSplitMode() == SC_SPLIT_FIX && WhichV(eWhich) == SC_SPLIT_TOP )
95  {
98  dy = 0;
99  }
100 
101  if ( dx != 0 || dy != 0 )
102  {
103  rViewShell.ScrollLines(2*dx, 4*dy);
105  }
106 }
107 
108 // Timer handler for window scrolling
109 IMPL_LINK_NOARG(FuPoor, ScrollHdl, Timer *, void)
110 {
111  Point aPosPixel = pWindow->GetPointerPosPixel();
112 
113  // use remembered MouseButton state to create correct
114  // MouseEvents for this artificial MouseMove.
115  MouseMove(MouseEvent(aPosPixel, 1, MouseEventModifiers::NONE, GetMouseButtonCode()));
116 }
117 
119 {
120  // remember button state for creation of own MouseEvents
122 
123  return false;
124 }
125 
127 {
128  // remember button state for creation of own MouseEvents
130 
131  return false;
132 }
133 
134 // If we handle a KeyEvent, then the return value is sal_True else FALSE.
135 bool FuPoor::KeyInput(const KeyEvent& /* rKEvt */)
136 {
137  return false;
138 }
139 
141 {
142  if ( CommandEventId::StartDrag == rCEvt.GetCommand() )
143  {
144  // Only if a selection is in Outliner, then Command is allowed
145  // to return sal_True
146 
148 
149  if ( pOutView )
150  return pOutView->HasSelection() ? (pView->Command(rCEvt,pWindow) ? 1 : 0) : SC_CMD_NONE;
151  else
152  return pView->Command(rCEvt,pWindow) ? 1 : 0;
153  }
154  else
155  return pView->Command(rCEvt,pWindow) ? 1 : 0;
156 }
157 
158 // Timer-Handler for Drag&Drop
159 IMPL_LINK_NOARG(FuPoor, DragTimerHdl, Timer *, void)
160 {
161  // Calling ExecuteDrag (and that associated reschedule) directly from
162  // the Timer, will confuse the VCL-Timer-Management, if (e.g during Drop)
163  // a new timer is started (e.g ComeBack-Timer of DrawView for
164  // Solid Handles / ModelHasChanged) - the new timer will end with a delay
165  // of the duration of the Drag&Drop.
166  // Therefore Drag&Drop from own event:
167 
168  Application::PostUserEvent( LINK( this, FuPoor, DragHdl ) );
169 }
170 
171 IMPL_LINK_NOARG(FuPoor, DragHdl, void*, void)
172 {
173  SdrHdl* pHdl = pView->PickHandle(aMDPos);
174 
175  if ( pHdl==nullptr && pView->IsMarkedHit(aMDPos) )
176  {
177  pWindow->ReleaseMouse();
178  bIsInDragMode = true;
179  rViewShell.GetScDrawView()->BeginDrag(pWindow, aMDPos);
180  }
181 }
182 
183 // Detective-line
184 bool FuPoor::IsDetectiveHit( const Point& rLogicPos )
185 {
186  SdrPageView* pPV = pView->GetSdrPageView();
187  if (!pPV)
188  return false;
189 
190  bool bFound = false;
191  SdrObjListIter aIter( pPV->GetObjList(), SdrIterMode::Flat );
192  SdrObject* pObject = aIter.Next();
193  while (pObject && !bFound)
194  {
195  if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
196  {
197  sal_uInt16 nHitLog = static_cast<sal_uInt16>(pWindow->PixelToLogic(
198  Size(pView->GetHitTolerancePixel(),0)).Width());
199  if(SdrObjectPrimitiveHit(*pObject, rLogicPos, nHitLog, *pPV, nullptr, false))
200  {
201  bFound = true;
202  }
203  }
204 
205  pObject = aIter.Next();
206  }
207  return bFound;
208 }
209 
211 {
212  if (aDragTimer.IsActive() )
213  aDragTimer.Stop();
214 }
215 
216 // Create default drawing objects via keyboard
217 SdrObjectUniquePtr FuPoor::CreateDefaultObject(const sal_uInt16 /* nID */, const tools::Rectangle& /* rRectangle */)
218 {
219  // empty base implementation
220  return nullptr;
221 }
222 
224 {
225  if(rRect.GetWidth() > rRect.GetHeight())
226  {
227  rRect = tools::Rectangle(
228  Point(rRect.Left() + ((rRect.GetWidth() - rRect.GetHeight()) / 2), rRect.Top()),
229  Size(rRect.GetHeight(), rRect.GetHeight()));
230  }
231  else
232  {
233  rRect = tools::Rectangle(
234  Point(rRect.Left(), rRect.Top() + ((rRect.GetHeight() - rRect.GetWidth()) / 2)),
235  Size(rRect.GetWidth(), rRect.GetWidth()));
236  }
237 }
238 
239 // #i33136# fdo#88339
241 {
242  // Detect whether we're moving an object or resizing.
243  if (pView->IsDragObj())
244  {
245  const SdrHdl* pHdl = pView->GetDragStat().GetHdl();
246  if (!pHdl || (!pHdl->IsCornerHdl() && !pHdl->IsVertexHdl()))
247  {
248  return false;
249  }
250  }
251 
252  // Detect image/media and resize proportionally, but don't constrain movement by default
253  if (pView->AreObjectsMarked())
254  {
255  const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
256  if (rMarkList.GetMarkCount() == 1)
257  {
258  sal_uInt16 aObjIdentifier = rMarkList.GetMark(0)->GetMarkedSdrObj()->GetObjIdentifier();
259  bool bIsMediaSelected = aObjIdentifier == OBJ_GRAF ||
260  aObjIdentifier == OBJ_MEDIA ||
261  aObjIdentifier == OBJ_OLE2;
262 
263  SdrHdl* pHdl = pView->PickHandle(aMDPos);
264  // Resize proportionally when media is selected and the user drags on a corner
265  if (pHdl)
266  return bIsMediaSelected && pHdl->IsCornerHdl();
267  return bIsMediaSelected;
268  }
269  }
270  else if (aSfxRequest.GetSlot() == SID_DRAW_XPOLYGON
271  || aSfxRequest.GetSlot() == SID_DRAW_XPOLYGON_NOFILL
272  || aSfxRequest.GetSlot() == SID_DRAW_XLINE)
273  return true;
274 
275  return false;
276 }
277 
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OBJ_GRAF
size_t GetMarkCount() const
ScVSplitPos WhichV(ScSplitPos ePos)
Definition: viewdata.hxx:710
OBJ_OLE2
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:1002
virtual bool MouseButtonUp(const MouseEvent &rMEvt)
Definition: fupoor.cxx:118
bool AreObjectsMarked() const
const SdrDragStat & GetDragStat() const
ScHSplitPos WhichH(ScSplitPos ePos)
Definition: viewdata.hxx:704
static bool IsNonAlienArrow(const SdrObject *pObject)
Definition: detfunc.cxx:430
virtual Size GetSizePixel() const
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
virtual bool doConstructOrthogonal() const
Definition: fupoor.cxx:240
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
tools::Long GetWidth() const
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
SdrMark * GetMark(size_t nNum) const
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
FuPoor(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, const SfxRequest &rReq)
Definition: fupoor.cxx:35
#define SELENG_DRAGDROP_TIMEOUT
EmbeddedObjectRef * pObject
SC_DLLPUBLIC void ScrollLines(tools::Long nDeltaX, tools::Long nDeltaY)
Definition: tabview.cxx:1313
ScSplitPos
Definition: viewdata.hxx:45
bool IsActive() const
virtual bool MouseButtonDown(const MouseEvent &rMEvt)
Definition: fupoor.cxx:126
const SdrHdl * GetHdl() const
OBJ_MEDIA
sal_uInt16 GetButtons() const
tools::Long Left() const
IMPL_LINK_NOARG(FuPoor, ScrollHdl, Timer *, void)
Definition: fupoor.cxx:109
void SetMouseButtonCode(sal_uInt16 nNew)
Definition: fupoor.hxx:71
#define SELENG_AUTOREPEAT_INTERVAL
SdrObject * SdrObjectPrimitiveHit(const SdrObject &rObject, const Point &rPnt, sal_uInt16 nTol, const SdrPageView &rSdrPageView, const SdrLayerIDSet *pVisiLayer, bool bTextOnly, drawinglayer::primitive2d::Primitive2DContainer *pHitContainer)
bool IsDetectiveHit(const Point &rLogicPos)
Definition: fupoor.cxx:184
void ActivatePart(ScSplitPos eWhich)
Definition: tabview3.cxx:2868
ScTabViewShell & rViewShell
Definition: fupoor.hxx:44
Timer aDragTimer
Definition: fupoor.hxx:54
bool HasSelection() const
void ForceScroll(const Point &aPixPos)
Definition: fupoor.cxx:70
ScSplitMode GetHSplitMode() const
Definition: viewdata.hxx:416
virtual bool KeyInput(const KeyEvent &rKEvt)
Definition: fupoor.cxx:135
ScViewData & GetViewData()
Definition: tabview.hxx:332
SdrObjList * GetObjList() const
SdrObject * GetMarkedSdrObj() const
virtual sal_uInt16 GetObjIdentifier() const
sal_Int16 SCCOL
Definition: types.hxx:22
const SdrMarkList & GetMarkedObjectList() const
tools::Long Width() const
CommandEventId GetCommand() const
SdrHdl * PickHandle(const Point &rPnt) const
virtual void Start() override
virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle &rRectangle)
Definition: fupoor.cxx:217
const OutlinerView * GetTextEditOutlinerView() const
SfxRequest aSfxRequest
Definition: fupoor.hxx:48
Timer aScrollTimer
Definition: fupoor.hxx:50
tools::Long Top() const
void SetTimeout(sal_uInt64 nTimeoutMs)
Base class for all functions.
Definition: fupoor.hxx:40
Point aMDPos
Definition: fupoor.hxx:58
Point PixelToLogic(const Point &rDevicePt) const
sal_Int32 SCROW
Definition: types.hxx:18
sal_uInt16 GetSlot() const
sal_uInt8 Command(const CommandEvent &rCEvt)
Definition: fupoor.cxx:140
void Stop()
virtual ~FuPoor()
Definition: fupoor.cxx:53
void StopDragTimer()
Definition: fupoor.cxx:210
unsigned char sal_uInt8
virtual bool Command(const CommandEvent &rCEvt, vcl::Window *pWin) override
bool IsVertexHdl() const
ScDrawView * pView
Definition: fupoor.hxx:43
sal_uInt16 GetHitTolerancePixel() const
tools::Long Height() const
void SetInvokeHandler(const Link< Timer *, void > &rLink)
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
SdrPageView * GetSdrPageView() const
static void ImpForceQuadratic(tools::Rectangle &rRect)
Definition: fupoor.cxx:223
tools::Long GetHeight() const
bool IsDragObj() const
bool IsCornerHdl() const
virtual void Activate()
Definition: fupoor.cxx:59
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:45
ScSplitMode GetVSplitMode() const
Definition: viewdata.hxx:417
#define SC_CMD_NONE
Definition: fupoor.hxx:36
virtual void Deactivate()
Definition: fupoor.cxx:63