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