LibreOffice Module sc (master)  1
gridwin3.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 <svx/svdpagv.hxx>
21 #include <svx/svxids.hrc>
22 #include <editeng/sizeitem.hxx>
23 #include <sfx2/bindings.hxx>
24 #include <svl/ptitem.hxx>
25 
26 #include <tabvwsh.hxx>
27 #include <gridwin.hxx>
28 #include <dbfunc.hxx>
29 #include <viewdata.hxx>
30 #include <output.hxx>
31 #include <drawview.hxx>
32 #include <fupoor.hxx>
33 
34 #include <drawutil.hxx>
35 #include <document.hxx>
36 #include <comphelper/lok.hxx>
37 
39 {
40  bool bRet = false;
41  FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
42  if (pDraw && !pViewData->IsRefMode())
43  {
44  MapMode aDrawMode = GetDrawMapMode();
45  MapMode aOldMode = GetMapMode();
46  if ( comphelper::LibreOfficeKit::isActive() && aOldMode != aDrawMode )
47  SetMapMode( aDrawMode );
48 
49  pDraw->SetWindow( this );
50  Point aLogicPos = PixelToLogic(rMEvt.GetPosPixel());
51  if ( pDraw->IsDetectiveHit( aLogicPos ) )
52  {
53  // nothing on detective arrows (double click is evaluated on ButtonUp)
54  bRet = true;
55  }
56  else
57  {
58  bRet = pDraw->MouseButtonDown( rMEvt );
59  if ( bRet )
61  }
62 
63  if ( comphelper::LibreOfficeKit::isActive() && aOldMode != aDrawMode )
64  SetMapMode( aOldMode );
65  }
66 
67  // cancel draw with right key
68  ScDrawView* pDrView = pViewData->GetScDrawView();
69  if ( pDrView && !rMEvt.IsLeft() && !bRet )
70  {
71  pDrView->BrkAction();
72  bRet = true;
73  }
74  return bRet;
75 }
76 
78 {
79  ScViewFunc* pView = pViewData->GetView();
80  bool bRet = false;
81  FuPoor* pDraw = pView->GetDrawFuncPtr();
82  if (pDraw && !pViewData->IsRefMode())
83  {
84  MapMode aDrawMode = GetDrawMapMode();
85  MapMode aOldMode = GetMapMode();
86  if ( comphelper::LibreOfficeKit::isActive() && aOldMode != aDrawMode )
87  SetMapMode( aDrawMode );
88 
89  pDraw->SetWindow( this );
90  bRet = pDraw->MouseButtonUp( rMEvt );
91 
92  // execute "format paint brush" for drawing objects
93  SfxItemSet* pDrawBrush = pView->GetDrawBrushSet();
94  if ( pDrawBrush )
95  {
96  ScDrawView* pDrView = pViewData->GetScDrawView();
97  if ( pDrView )
98  {
99  pDrView->SetAttrToMarked(*pDrawBrush, true/*bReplaceAll*/);
100  }
101 
102  if ( !pView->IsPaintBrushLocked() )
103  pView->ResetBrushDocument(); // end paint brush mode if not locked
104  }
105 
106  if ( comphelper::LibreOfficeKit::isActive() && aOldMode != aDrawMode )
107  SetMapMode( aOldMode );
108  }
109 
110  return bRet;
111 }
112 
114 {
115  FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
116  if (pDraw && !pViewData->IsRefMode())
117  {
118  MapMode aDrawMode = GetDrawMapMode();
119  MapMode aOldMode = GetMapMode();
120  if ( comphelper::LibreOfficeKit::isActive() && aOldMode != aDrawMode )
121  SetMapMode( aDrawMode );
122 
123  pDraw->SetWindow( this );
124  bool bRet = pDraw->MouseMove( rMEvt );
125  if ( bRet )
127 
128  if ( comphelper::LibreOfficeKit::isActive() && aOldMode != aDrawMode )
129  SetMapMode( aOldMode );
130 
131  return bRet;
132  }
133  else
134  {
135  SetPointer( PointerStyle::Arrow );
136  return false;
137  }
138 }
139 
141 {
142  ScDrawView* pDrView = pViewData->GetScDrawView();
143  if ( pDrView && pDrView->IsAction() )
144  pDrView->BrkAction();
145 
146  FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
147  if (pDraw)
148  pDraw->StopDragTimer();
149 
150  // ReleaseMouse on call
151 }
152 
154 {
155  ScDrawView* pDrView = pViewData->GetScDrawView();
156  FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
157  if (pDrView && pDraw && !pViewData->IsRefMode())
158  {
159  pDraw->SetWindow( this );
160  sal_uInt8 nUsed = pDraw->Command( rCEvt );
161  if( nUsed == SC_CMD_USED )
162  nButtonDown = 0; // MouseButtonUp is swallowed...
163  if( nUsed || pDrView->IsAction() )
164  return true;
165  }
166 
167  return false;
168 }
169 
171 {
172  ScDrawView* pDrView = pViewData->GetScDrawView();
173  FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
174  if (pDrView && pDraw && !pViewData->IsRefMode())
175  {
176  pDraw->SetWindow( this );
177  bool bOldMarked = pDrView->AreObjectsMarked();
178  if (pDraw->KeyInput( rKEvt ))
179  {
180  bool bLeaveDraw = false;
181  bool bUsed = true;
182  bool bNewMarked = pDrView->AreObjectsMarked();
183  if ( !pViewData->GetView()->IsDrawSelMode() )
184  if ( !bNewMarked )
185  {
186  pViewData->GetViewShell()->SetDrawShell( false );
187  bLeaveDraw = true;
188  if ( !bOldMarked &&
189  rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
190  bUsed = false; // nothing deleted
191  if(bOldMarked)
192  GetFocus();
193  }
194  if (!bLeaveDraw)
195  UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
196  return bUsed;
197  }
198  }
199 
200  return false;
201 }
202 
204 {
205  const ScViewOptions& rOpts = pViewData->GetOptions();
206 
207  // use new flags at SdrPaintView for hiding objects
208  const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
209  const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
210  const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
211 
212  if(bDrawOle || bDrawChart || bDrawDraw)
213  {
214  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
215 
216  if(pDrView)
217  {
218  pDrView->setHideOle(!bDrawOle);
219  pDrView->setHideChart(!bDrawChart);
220  pDrView->setHideDraw(!bDrawDraw);
221  pDrView->setHideFormControl(!bDrawDraw);
222  }
223 
224  rOutputData.DrawSelectiveObjects(nLayer);
225  }
226 }
227 
228 void ScGridWindow::DrawSdrGrid( const tools::Rectangle& rDrawingRect, OutputDevice* pContentDev )
229 {
230  // Draw grid lines
231 
232  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
233  if ( pDrView && pDrView->IsGridVisible() )
234  {
235  SdrPageView* pPV = pDrView->GetSdrPageView();
236  OSL_ENSURE(pPV, "PageView not available");
237  if (pPV)
238  {
239  pContentDev->SetLineColor(COL_GRAY);
240 
241  pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
242  }
243  }
244 }
245 
247 {
248  ScDocument* pDoc = pViewData->GetDocument();
249 
250  // FIXME this shouldn't be necessary once we change the entire Calc to
251  // work in the logic coordinates (ideally 100ths of mm - so that it is
252  // the same as editeng and drawinglayer), and get rid of all the
253  // SetMapMode's and other unnecessary fun we have with pixels
255  {
256  return pViewData->GetLogicMode();
257  }
258 
259  SCTAB nTab = pViewData->GetTabNo();
260  bool bNegativePage = pDoc->IsNegativePage( nTab );
261 
262  MapMode aDrawMode = pViewData->GetLogicMode();
263 
264  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
265  if ( pDrView || bForce )
266  {
267  Fraction aScaleX;
268  Fraction aScaleY;
269  if (pDrView)
270  pDrView->GetScale( aScaleX, aScaleY );
271  else
272  {
273  SCCOL nEndCol = 0;
274  SCROW nEndRow = 0;
275  pDoc->GetTableArea( nTab, nEndCol, nEndRow );
276  if (nEndCol<20) nEndCol = 20;
277  if (nEndRow<20) nEndRow = 1000;
278  ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
281  aScaleX,aScaleY );
282  }
283  aDrawMode.SetScaleX(aScaleX);
284  aDrawMode.SetScaleY(aScaleY);
285  }
286  aDrawMode.SetOrigin(Point());
287  Point aStartPos = pViewData->GetPixPos(eWhich);
288  if ( bNegativePage )
289  {
290  // RTL uses negative positions for drawing objects
291  aStartPos.setX( -aStartPos.X() + GetOutputSizePixel().Width() - 1 );
292  }
293  aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
294 
295  return aDrawMode;
296 }
297 
299 {
300  PaintImmediately(); // always, so the behaviour with and without DrawingLayer is the same
301 
302  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
303  if (pDrView)
304  {
305  OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
306  if (pOlView && pOlView->GetWindow() == this)
307  pOlView->ShowCursor(false); // was removed at scrolling
308  }
309 }
310 
312 {
313  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
314  if (pDrView)
315  {
316  const ScViewOptions& rOpts = pViewData->GetOptions();
317  if(rOpts.GetOption( VOPT_ANCHOR ))
318  {
319  bool bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
320  Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, true );
321  aPos = PixelToLogic(aPos);
322  rHdl.AddHdl(std::make_unique<SdrHdl>(aPos, bNegativePage ? SdrHdlKind::Anchor_TR : SdrHdlKind::Anchor));
323  }
324  }
325 }
326 
328 {
329  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
330  if (!pDrView)
331  return; // shouldn't be called in that case
332 
333  SdrPageView* pPV = pDrView->GetSdrPageView();
334  if (!pPV)
335  return; // shouldn't be called in that case either
336 
338 
339  // Fill items for position and size:
340  // show action rectangle during action,
341  // position and size of selected object(s) if something is selected,
342  // mouse position otherwise
343 
344  bool bActionItem = false;
345  if ( pDrView->IsAction() ) // action rectangle
346  {
347  tools::Rectangle aRect;
348  pDrView->TakeActionRect( aRect );
349  if ( !aRect.IsEmpty() )
350  {
351  pPV->LogicToPagePos(aRect);
352  aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
353  aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
354  Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
355  bActionItem = true;
356  }
357  }
358  if ( !bActionItem )
359  {
360  if ( pDrView->AreObjectsMarked() ) // selected objects
361  {
362  tools::Rectangle aRect = pDrView->GetAllMarkedRect();
363  pPV->LogicToPagePos(aRect);
364  aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
365  aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
366  Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
367  }
368  else // mouse position
369  {
371  pPV->LogicToPagePos(aPos);
372  aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
373  aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
374  }
375  }
376 
377  pViewData->GetBindings().SetState(aSet);
378 }
379 
381 {
383  return p && p->AreObjectsMarked();
384 }
385 
387 {
388  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
389  if (pDrView)
390  pDrView->MarkDropObj(pObj);
391 }
392 
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
ScDBFunc * GetView() const
Definition: viewdata.hxx:356
long Width() const
void ResetBrushDocument()
Definition: tabview5.cxx:641
bool IsDrawSelMode() const
Definition: tabview.hxx:315
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:1002
static void CalcScale(const ScDocument *pDoc, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const OutputDevice *pDev, const Fraction &rZoomX, const Fraction &rZoomY, double nPPTX, double nPPTY, Fraction &rScaleX, Fraction &rScaleY)
Definition: drawutil.cxx:27
MapMode GetDrawMapMode(bool bForce=false)
MapMode for the drawinglayer objects.
Definition: gridwin3.cxx:246
SCROW Row() const
Definition: address.hxx:262
void SetState(const SfxItemSet &rSet)
const Fraction & GetZoomX() const
Definition: viewdata.hxx:459
virtual bool MouseButtonUp(const MouseEvent &rMEvt)
Definition: fupoor.cxx:118
bool AreObjectsMarked() const
void ShowCursor(bool bGotoCursor=true, bool bActivate=false)
#define SC_CMD_USED
Definition: fupoor.hxx:37
bool DrawMouseMove(const MouseEvent &rMEvt)
Definition: gridwin3.cxx:113
void UpdateStatusPosSize()
Definition: gridwin3.cxx:327
void DrawSelectiveObjects(SdrLayerID nLayer)
Definition: output3.cxx:166
bool DrawKeyInput(const KeyEvent &rKEvt)
Definition: gridwin3.cxx:170
virtual void GetFocus() override
Definition: gridwin.cxx:4764
double GetPPTX() const
Definition: viewdata.hxx:468
const MapMode & GetMapMode() const
constexpr::Color COL_GRAY(0x80, 0x80, 0x80)
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
sal_uInt16 GetCode() const
void PaintImmediately()
ScViewData * pViewData
Definition: gridwin.hxx:149
void SetMapMode()
bool IsEmpty() const
virtual bool MouseButtonDown(const MouseEvent &rMEvt)
Definition: fupoor.cxx:126
void SetAttrToMarked(const SfxItemSet &rAttr, bool bReplaceAll)
long Right() const
void LogicToPagePos(Point &rPnt) const
void DrawSdrGrid(const tools::Rectangle &rDrawingRect, OutputDevice *pContentDev)
Definition: gridwin3.cxx:228
sal_uInt16 nButtonDown
Definition: gridwin.hxx:166
bool IsGridVisible() const
void SetWindow(vcl::Window *pWin)
Definition: fupoor.hxx:89
Point aCurMousePos
Definition: gridwin.hxx:194
bool IsDetectiveHit(const Point &rLogicPos)
Definition: fupoor.cxx:184
bool IsPaintBrushLocked() const
Definition: tabview.hxx:587
long Top() const
ScDocument * GetDocument() const
Definition: viewdata.cxx:859
void GetScale(Fraction &rFractX, Fraction &rFractY) const
Definition: drawview.cxx:290
void MarkDropObj(SdrObject *pObj)
Definition: drawview.cxx:903
const Fraction & GetZoomY() const
Definition: viewdata.hxx:460
virtual bool KeyInput(const KeyEvent &rKEvt)
Definition: fupoor.cxx:135
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3081
void setHideOle(bool bNew)
SfxItemPool & GetPool() const
void DrawEndAction()
Definition: gridwin3.cxx:140
Point GetPixPos(ScSplitPos eWhich) const
Definition: viewdata.hxx:634
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
void SetLineColor()
void SetScaleX(const Fraction &rScaleX)
Point GetScrPos(SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich, bool bAllowNeg=false, SCTAB nForTab=-1) const
Definition: viewdata.cxx:2319
SfxBindings & GetBindings()
Definition: viewdata.cxx:3041
sal_Int16 SCCOL
Definition: types.hxx:22
void SetOrigin(const Point &rOrigin)
void SetDrawShell(bool bActive)
Definition: tabvwsh4.cxx:596
long Bottom() const
void CreateAnchorHandle(SdrHdlList &rHdl, const ScAddress &rAddress)
Definition: gridwin3.cxx:311
bool GetOption(ScViewOption eOpt) const
Definition: viewopti.hxx:88
void SetScaleY(const Fraction &rScaleY)
const OutlinerView * GetTextEditOutlinerView() const
Size GetOutputSizePixel() const
Base class for all functions.
Definition: fupoor.hxx:40
const tools::Rectangle & GetAllMarkedRect() const
ScSplitPos eWhich
Definition: gridwin.hxx:150
SCCOL Col() const
Definition: address.hxx:267
Point PixelToLogic(const Point &rDevicePt) const
virtual bool IsAction() const override
void DrawPageViewGrid(OutputDevice &rOut, const tools::Rectangle &rRect, Color aColor=COL_BLACK)
SfxItemSet * GetDrawBrushSet() const
Definition: tabview.hxx:586
void SetPointer(PointerStyle)
void DrawRedraw(ScOutputData &rOutputData, SdrLayerID nLayer)
Definition: gridwin3.cxx:203
bool DrawMouseButtonDown(const MouseEvent &rMEvt)
Definition: gridwin3.cxx:38
sal_Int32 SCROW
Definition: types.hxx:18
const vcl::KeyCode & GetKeyCode() const
double GetPPTY() const
Definition: viewdata.hxx:469
sal_uInt8 Command(const CommandEvent &rCEvt)
Definition: fupoor.cxx:140
void StopDragTimer()
Definition: fupoor.cxx:210
bool DrawCommand(const CommandEvent &rCEvt)
Definition: gridwin3.cxx:153
ScDrawView * GetScDrawView()
Definition: tabview.hxx:340
void DrawMarkDropObj(SdrObject *pObj)
Definition: gridwin3.cxx:386
unsigned char sal_uInt8
bool IsLeft() const
SC_DLLPUBLIC bool GetTableArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow) const
Definition: document.cxx:1029
FuPoor * GetDrawFuncPtr()
Definition: tabview.hxx:320
void setHideFormControl(bool bNew)
bool DrawHasMarkedObj()
Definition: gridwin3.cxx:380
bool DrawMouseButtonUp(const MouseEvent &rMEvt)
Definition: gridwin3.cxx:77
virtual bool MouseMove(const MouseEvent &)
Definition: fupoor.hxx:76
const ScViewOptions & GetOptions() const
Definition: viewdata.hxx:537
vcl::Window * GetWindow() const
void * p
const Point & GetPosPixel() const
long Left() const
SdrPageView * GetSdrPageView() const
void setHideDraw(bool bNew)
virtual void TakeActionRect(tools::Rectangle &rRect) const override
void setHideChart(bool bNew)
void DrawAfterScroll()
Definition: gridwin3.cxx:298
constexpr sal_uInt16 KEY_DELETE
const MapMode & GetLogicMode(ScSplitPos eWhich)
Definition: viewdata.cxx:2927
virtual void BrkAction() override
bool IsRefMode() const
Definition: viewdata.hxx:513
ScVObjMode GetObjMode(ScVObjType eObj) const
Definition: viewopti.hxx:91
void AddHdl(std::unique_ptr< SdrHdl > pHdl)
sal_Int16 SCTAB
Definition: types.hxx:23