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
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 {
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{
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{
144 if ( pDrView && pDrView->IsAction() )
145 pDrView->BrkAction();
146
148 if (pDraw)
149 pDraw->StopDragTimer();
150
151 // ReleaseMouse on call
152}
153
155{
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{
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
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
234void ScGridWindow::DrawSdrGrid( const tools::Rectangle& rDrawingRect, OutputDevice* pContentDev )
235{
236 // Draw grid lines
237
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
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
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{
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{
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{
395 if (pDrView)
396 pDrView->MarkDropObj(pObj);
397}
398
399/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool KeyInput(const KeyEvent &rKEvt, vcl::Window *pWin) override
Base class for all functions.
Definition: fupoor.hxx:40
void StopDragTimer()
Definition: fupoor.cxx:212
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 bool MouseMove(const MouseEvent &)
Definition: fupoor.hxx:75
sal_uInt8 Command(const CommandEvent &rCEvt)
Definition: fupoor.cxx:142
void SetWindow(vcl::Window *pWin)
Definition: fupoor.hxx:88
const vcl::KeyCode & GetKeyCode() const
void SetOrigin(const Point &rOrigin)
void SetScaleY(const Fraction &rScaleY)
void SetScaleX(const Fraction &rScaleX)
const Point & GetPosPixel() const
bool IsLeft() const
vcl::Window * GetWindow() const
void ShowCursor(bool bGotoCursor=true, bool bActivate=false)
void SetLineColor()
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:1006
SC_DLLPUBLIC bool GetTableArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow, bool bCalcHiddens=false) const
Definition: document.cxx:1033
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:29
void MarkDropObj(SdrObject *pObj)
Definition: drawview.cxx:907
void GetScale(Fraction &rFractX, Fraction &rFractY) const
Definition: drawview.cxx:292
bool DrawMouseMove(const MouseEvent &rMEvt)
Definition: gridwin3.cxx:114
void DrawEndAction()
Definition: gridwin3.cxx:141
MapMode GetDrawMapMode(bool bForce=false)
MapMode for the drawinglayer objects.
Definition: gridwin3.cxx:252
Point aCurMousePos
Definition: gridwin.hxx:195
void DrawRedraw(ScOutputData &rOutputData, SdrLayerID nLayer)
Definition: gridwin3.cxx:209
virtual void GetFocus() override
Definition: gridwin.cxx:5060
bool DrawHasMarkedObj()
Definition: gridwin3.cxx:386
bool DrawCommand(const CommandEvent &rCEvt)
Definition: gridwin3.cxx:154
bool DrawMouseButtonDown(const MouseEvent &rMEvt)
Definition: gridwin3.cxx:39
void DrawAfterScroll()
Definition: gridwin3.cxx:304
void UpdateStatusPosSize()
Definition: gridwin3.cxx:333
sal_uInt16 nButtonDown
Definition: gridwin.hxx:167
bool DrawKeyInput(const KeyEvent &rKEvt, vcl::Window *pWin)
Definition: gridwin3.cxx:171
ScViewData & mrViewData
Definition: gridwin.hxx:151
void DrawSdrGrid(const tools::Rectangle &rDrawingRect, OutputDevice *pContentDev)
Definition: gridwin3.cxx:234
bool DrawMouseButtonUp(const MouseEvent &rMEvt)
Definition: gridwin3.cxx:78
ScSplitPos eWhich
Definition: gridwin.hxx:152
void CreateAnchorHandle(SdrHdlList &rHdl, const ScAddress &rAddress)
Definition: gridwin3.cxx:317
void DrawMarkDropObj(SdrObject *pObj)
Definition: gridwin3.cxx:392
void DrawSelectiveObjects(SdrLayerID nLayer)
Definition: output3.cxx:170
void SetDrawShell(bool bActive)
Definition: tabvwsh4.cxx:613
FuPoor * GetDrawFuncPtr()
Definition: tabview.hxx:323
void ResetBrushDocument()
Definition: tabview5.cxx:654
SfxItemSet * GetDrawBrushSet() const
Definition: tabview.hxx:589
ScDrawView * GetScDrawView()
Definition: tabview.hxx:343
bool IsDrawSelMode() const
Definition: tabview.hxx:318
bool IsPaintBrushLocked() const
Definition: tabview.hxx:590
const ScViewOptions & GetOptions() const
Definition: viewdata.hxx:554
const Fraction & GetZoomY() const
Definition: viewdata.hxx:460
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
double GetPPTY() const
Definition: viewdata.hxx:469
const MapMode & GetLogicMode(ScSplitPos eWhich)
Definition: viewdata.cxx:3015
Point GetPixPos(ScSplitPos eWhich) const
Definition: viewdata.hxx:647
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
ScDBFunc * GetView() const
Definition: viewdata.cxx:863
Point GetScrPos(SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich, bool bAllowNeg=false, SCTAB nForTab=-1) const
Definition: viewdata.cxx:2375
const Fraction & GetZoomX() const
Definition: viewdata.hxx:459
bool IsRefMode() const
Definition: viewdata.hxx:530
double GetPPTX() const
Definition: viewdata.hxx:468
SfxBindings & GetBindings()
Definition: viewdata.cxx:3129
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3169
bool GetOption(ScViewOption eOpt) const
Definition: viewopti.hxx:88
ScVObjMode GetObjMode(ScVObjType eObj) const
Definition: viewopti.hxx:91
virtual void BrkAction() override
virtual bool IsAction() const override
virtual void TakeActionRect(tools::Rectangle &rRect) const override
void SetAttrToMarked(const SfxItemSet &rAttr, bool bReplaceAll)
void AddHdl(std::unique_ptr< SdrHdl > pHdl)
bool AreObjectsMarked() const
const tools::Rectangle & GetAllMarkedRect() const
const OutlinerView * GetTextEditOutlinerView() const
void LogicToPagePos(Point &rPnt) const
void DrawPageViewGrid(OutputDevice &rOut, const tools::Rectangle &rRect, Color aColor=COL_BLACK)
void setHideOle(bool bNew)
void setHideFormControl(bool bNew)
void setHideDraw(bool bNew)
SdrPageView * GetSdrPageView() const
void setHideChart(bool bNew)
bool IsGridVisible() const
void SetState(const SfxItemSet &rSet)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemPool & GetPool() const
constexpr tools::Long Top() const
constexpr Point TopLeft() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
constexpr bool IsEmpty() const
sal_uInt16 GetCode() const
void PaintImmediately()
void SetMapMode()
const MapMode & GetMapMode() const
::OutputDevice const * GetOutDev() const
Point PixelToLogic(const Point &rDevicePt) const
Size GetOutputSizePixel() const
void SetPointer(PointerStyle)
constexpr ::Color COL_GRAY(0x80, 0x80, 0x80)
#define SC_CMD_USED
Definition: fupoor.hxx:36
@ VOBJ_MODE_SHOW
Definition: global.hxx:368
void * p
constexpr sal_uInt16 KEY_DELETE
unsigned char sal_uInt8
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
@ VOBJ_TYPE_CHART
Definition: viewopti.hxx:54
@ VOBJ_TYPE_OLE
Definition: viewopti.hxx:53
@ VOBJ_TYPE_DRAW
Definition: viewopti.hxx:55
@ VOPT_ANCHOR
Definition: viewopti.hxx:44