LibreOffice Module sc (master)  1
fuconstr.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/outlobj.hxx>
21 #include <svx/svdotext.hxx>
22 #include <svx/svdouno.hxx>
23 #include <svx/svxids.hrc>
24 #include <sfx2/dispatch.hxx>
25 
26 #include <fuconstr.hxx>
27 #include <fudraw.hxx>
28 #include <tabvwsh.hxx>
29 #include <futext.hxx>
30 #include <drawview.hxx>
31 
32 // maximal permitted mouse movement to start Drag&Drop
34 #define SC_MAXDRAGMOVE 3
35 
37  SdrModel* pDoc, const SfxRequest& rReq)
38  : FuDraw(rViewSh, pWin, pViewP, pDoc, rReq)
39 {
40 }
41 
43 {
44 }
45 
47 {
48  // remember button state for creation of own MouseEvents
50 
51  bool bReturn = FuDraw::MouseButtonDown(rMEvt);
52 
53  if ( pView->IsAction() )
54  {
55  if ( rMEvt.IsRight() )
56  pView->BckAction();
57  return true;
58  }
59 
60  aDragTimer.Start();
61 
62  aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
63 
64  if ( rMEvt.IsLeft() )
65  {
67 
68  SdrHdl* pHdl = pView->PickHandle(aMDPos);
69 
70  if ( pHdl != nullptr || pView->IsMarkedHit(aMDPos) )
71  {
72  pView->BegDragObj(aMDPos, nullptr, pHdl, 1);
73  bReturn = true;
74  }
75  else if ( pView->AreObjectsMarked() )
76  {
77  pView->UnmarkAll();
78  bReturn = true;
79  }
80  }
81 
82  bIsInDragMode = false;
83 
84  return bReturn;
85 }
86 
88 {
89  FuDraw::MouseMove(rMEvt);
90 
91  if (aDragTimer.IsActive() )
92  {
93  Point aOldPixel = pWindow->LogicToPixel( aMDPos );
94  Point aNewPixel = rMEvt.GetPosPixel();
95  if ( std::abs( aOldPixel.X() - aNewPixel.X() ) > SC_MAXDRAGMOVE ||
96  std::abs( aOldPixel.Y() - aNewPixel.Y() ) > SC_MAXDRAGMOVE )
97  aDragTimer.Stop();
98  }
99 
100  Point aPix(rMEvt.GetPosPixel());
101  Point aPnt( pWindow->PixelToLogic(aPix) );
102 
103  if ( pView->IsAction() )
104  {
105  ForceScroll(aPix);
106  pView->MovAction(aPnt);
107  }
108  else
109  {
110  SdrHdl* pHdl=pView->PickHandle(aPnt);
111 
112  if ( pHdl != nullptr )
113  {
115  }
116  else if ( pView->IsMarkedHit(aPnt) )
117  {
118  rViewShell.SetActivePointer(PointerStyle::Move);
119  }
120  else
121  {
123  }
124  }
125  return true;
126 }
127 
129 {
130  // remember button state for creation of own MouseEvents
132 
133  bool bReturn = SimpleMouseButtonUp( rMEvt );
134 
135  // Double-click on text object? (->fusel)
136 
137  sal_uInt16 nClicks = rMEvt.GetClicks();
138  if ( nClicks == 2 && rMEvt.IsLeft() )
139  {
140  if ( pView->AreObjectsMarked() )
141  {
142  const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
143  if (rMarkList.GetMarkCount() == 1)
144  {
145  SdrMark* pMark = rMarkList.GetMark(0);
146  SdrObject* pObj = pMark->GetMarkedSdrObj();
147 
148  // if Uno-Controls no text mode
149  if ( dynamic_cast<const SdrTextObj*>( pObj) != nullptr && dynamic_cast<const SdrUnoObj*>( pObj) == nullptr )
150  {
152  bool bVertical = ( pOPO && pOPO->IsVertical() );
153  sal_uInt16 nTextSlotId = bVertical ? SID_DRAW_TEXT_VERTICAL : SID_DRAW_TEXT;
154 
156  Execute(nTextSlotId, SfxCallMode::SLOT | SfxCallMode::RECORD);
157 
158  // Get the created FuText now and change into EditMode
160  if ( pPoor && pPoor->GetSlotID() == nTextSlotId ) // has no RTTI
161  {
162  FuText* pText = static_cast<FuText*>(pPoor);
163  Point aMousePixel = rMEvt.GetPosPixel();
164  pText->SetInEditMode( pObj, &aMousePixel );
165  }
166  bReturn = true;
167  }
168  }
169  }
170  }
171 
172  FuDraw::MouseButtonUp(rMEvt);
173 
174  return bReturn;
175 }
176 
177 // SimpleMouseButtonUp - no test on double-click
178 
180 {
181  bool bReturn = true;
182 
183  if (aDragTimer.IsActive() )
184  {
185  aDragTimer.Stop();
186  }
187 
188  Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
189 
190  if ( pView->IsDragObj() )
191  pView->EndDragObj( rMEvt.IsMod1() );
192 
193  else if ( pView->IsMarkObj() )
194  pView->EndMarkObj();
195 
196  else bReturn = false;
197 
198  if ( !pView->IsAction() )
199  {
201 
202  if ( !pView->AreObjectsMarked() && rMEvt.GetClicks() < 2 )
203  {
204  pView->MarkObj(aPnt, -2, false, rMEvt.IsMod1());
205 
207  if ( pView->AreObjectsMarked() )
208  rDisp.Execute(SID_OBJECT_SELECT, SfxCallMode::SLOT | SfxCallMode::RECORD);
209  else
210  rDisp.Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
211  }
212  }
213 
214  return bReturn;
215 }
216 
217 // If we handle a KeyEvent, then the return value is sal_True else FALSE.
218 bool FuConstruct::KeyInput(const KeyEvent& rKEvt)
219 {
220  bool bReturn = false;
221 
222  switch ( rKEvt.GetKeyCode().GetCode() )
223  {
224  case KEY_ESCAPE:
225  if ( pView->IsAction() )
226  {
227  pView->BrkAction();
229  bReturn = true;
230  }
231  else // end drawing mode
232  {
234  Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
235  }
236  break;
237 
238  case KEY_DELETE:
239  pView->DeleteMarked();
240  bReturn = true;
241  break;
242  }
243 
244  if ( !bReturn )
245  {
246  bReturn = FuDraw::KeyInput(rKEvt);
247  }
248 
249  return bReturn;
250 }
251 
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDBFunc * GetView() const
Definition: viewdata.hxx:356
void CaptureMouse()
size_t GetMarkCount() const
bool bIsInDragMode
Definition: fupoor.hxx:57
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: fudraw.cxx:172
FuConstruct(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, const SfxRequest &rReq)
Definition: fuconstr.cxx:36
bool IsVertical() const
bool AreObjectsMarked() const
bool EndDragObj(bool bCopy=false)
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:87
sal_uInt16 GetCode() const
SdrMark * GetMark(size_t nNum) const
Base class for all Drawmodule specific functions.
Definition: fudraw.hxx:28
virtual ~FuConstruct() override
Definition: fuconstr.cxx:42
virtual PointerStyle GetPointer() const
bool IsActive() const
sal_uInt16 GetClicks() const
virtual void MovAction(const Point &rPnt) override
virtual void DeleteMarked() override
Definition: drawview.cxx:854
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:128
sal_uInt16 GetButtons() const
void SetMouseButtonCode(sal_uInt16 nNew)
Definition: fupoor.hxx:71
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: fudraw.cxx:119
ScTabViewShell & rViewShell
Definition: fupoor.hxx:44
bool IsMarkedHit(const Point &rPnt, short nTol=-2) const
Timer aDragTimer
Definition: fupoor.hxx:54
void UnmarkAll()
void ForceScroll(const Point &aPixPos)
Definition: fupoor.cxx:70
ScViewData & GetViewData()
Definition: tabview.hxx:332
sal_uInt16 GetSlotID() const
Definition: fupoor.hxx:91
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:46
Base class for Text functions.
Definition: futext.hxx:28
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: fuconstr.cxx:218
SdrObject * GetMarkedSdrObj() const
bool IsMarkObj() const
void SetActivePointer(PointerStyle nPointer)
Definition: tabview.cxx:891
const SdrMarkList & GetMarkedObjectList() const
SdrHdl * PickHandle(const Point &rPnt) const
virtual void Start() override
SfxRequest aSfxRequest
Definition: fupoor.hxx:48
Base class for all functions.
Definition: fupoor.hxx:40
Point aMDPos
Definition: fupoor.hxx:58
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
void ReleaseMouse()
virtual bool IsAction() const override
bool SimpleMouseButtonUp(const MouseEvent &rMEvt)
Definition: fuconstr.cxx:179
const vcl::KeyCode & GetKeyCode() const
sal_uInt16 GetSlot() const
bool EndMarkObj()
void Stop()
constexpr sal_uInt16 KEY_ESCAPE
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fudraw.cxx:110
bool IsLeft() const
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3047
FuPoor * GetDrawFuncPtr()
Definition: tabview.hxx:320
ScDrawView * pView
Definition: fupoor.hxx:43
const Point & GetPosPixel() const
PointerStyle aNewPointer
Definition: fudraw.hxx:31
bool IsDragObj() const
void SetInEditMode(SdrObject *pObj=nullptr, const Point *pMousePixel=nullptr, bool bCursorToEnd=false, const KeyEvent *pInitialKey=nullptr)
Definition: futext.cxx:533
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
#define SC_MAXDRAGMOVE
fusel,fuconstr,futext - combine them!
Definition: fuconstr.cxx:34
bool IsRight() const
constexpr sal_uInt16 KEY_DELETE
virtual bool BegDragObj(const Point &rPnt, OutputDevice *pOut, SdrHdl *pHdl, short nMinMov=-3, SdrDragMethod *pForcedMeth=nullptr) override
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
virtual void BrkAction() override
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fudraw.cxx:129
virtual void BckAction() override
virtual OutlinerParaObject * GetOutlinerParaObject() const
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:45
bool IsMod1() const