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