1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 #include <tabvwsh.hxx>
28 #include <gridwin.hxx>
30 #include <viewdata.hxx>
32 #include <drawview.hxx>
35 #include <drawutil.hxx>
36 #include <document.hxx>
37 #include <comphelper/lok.hxx>
39 bool ScGridWindow::DrawMouseButtonDown(const MouseEvent
& rMEvt
)
42 FuPoor
* pDraw
= mrViewData
.GetView()->GetDrawFuncPtr();
43 if (pDraw
&& !mrViewData
.IsRefMode())
45 MapMode aDrawMode
= GetDrawMapMode();
46 MapMode aOldMode
= GetMapMode();
47 if ( comphelper::LibreOfficeKit::isActive() && aOldMode
!= aDrawMode
)
48 SetMapMode( aDrawMode
);
50 pDraw
->SetWindow( this );
51 Point aLogicPos
= PixelToLogic(rMEvt
.GetPosPixel());
52 if ( pDraw
->IsDetectiveHit( aLogicPos
) )
54 // nothing on detective arrows (double click is evaluated on ButtonUp)
59 bRet
= pDraw
->MouseButtonDown( rMEvt
);
61 UpdateStatusPosSize();
64 if ( comphelper::LibreOfficeKit::isActive() && aOldMode
!= aDrawMode
)
65 SetMapMode( aOldMode
);
68 // cancel draw with right key
69 ScDrawView
* pDrView
= mrViewData
.GetScDrawView();
70 if ( pDrView
&& !rMEvt
.IsLeft() && !bRet
)
78 bool ScGridWindow::DrawMouseButtonUp(const MouseEvent
& rMEvt
)
80 ScViewFunc
* pView
= mrViewData
.GetView();
82 FuPoor
* pDraw
= pView
->GetDrawFuncPtr();
83 if (pDraw
&& !mrViewData
.IsRefMode())
85 MapMode aDrawMode
= GetDrawMapMode();
86 MapMode aOldMode
= GetMapMode();
87 if ( comphelper::LibreOfficeKit::isActive() && aOldMode
!= aDrawMode
)
88 SetMapMode( aDrawMode
);
90 pDraw
->SetWindow( this );
91 bRet
= pDraw
->MouseButtonUp( rMEvt
);
93 // execute "format paint brush" for drawing objects
94 SfxItemSet
* pDrawBrush
= pView
->GetDrawBrushSet();
97 ScDrawView
* pDrView
= mrViewData
.GetScDrawView();
100 pDrView
->SetAttrToMarked(*pDrawBrush
, true/*bReplaceAll*/);
103 if ( !pView
->IsPaintBrushLocked() )
104 pView
->ResetBrushDocument(); // end paint brush mode if not locked
107 if ( comphelper::LibreOfficeKit::isActive() && aOldMode
!= aDrawMode
)
108 SetMapMode( aOldMode
);
114 bool ScGridWindow::DrawMouseMove(const MouseEvent
& rMEvt
)
116 FuPoor
* pDraw
= mrViewData
.GetView()->GetDrawFuncPtr();
117 if (pDraw
&& !mrViewData
.IsRefMode())
119 MapMode aDrawMode
= GetDrawMapMode();
120 MapMode aOldMode
= GetMapMode();
121 if ( comphelper::LibreOfficeKit::isActive() && aOldMode
!= aDrawMode
)
122 SetMapMode( aDrawMode
);
124 pDraw
->SetWindow( this );
125 bool bRet
= pDraw
->MouseMove( rMEvt
);
127 UpdateStatusPosSize();
129 if ( comphelper::LibreOfficeKit::isActive() && aOldMode
!= aDrawMode
)
130 SetMapMode( aOldMode
);
136 SetPointer( PointerStyle::Arrow
);
141 void ScGridWindow::DrawEndAction()
143 ScDrawView
* pDrView
= mrViewData
.GetScDrawView();
144 if ( pDrView
&& pDrView
->IsAction() )
145 pDrView
->BrkAction();
147 FuPoor
* pDraw
= mrViewData
.GetView()->GetDrawFuncPtr();
149 pDraw
->StopDragTimer();
151 // ReleaseMouse on call
154 bool ScGridWindow::DrawCommand(const CommandEvent
& rCEvt
)
156 ScDrawView
* pDrView
= mrViewData
.GetScDrawView();
157 FuPoor
* pDraw
= mrViewData
.GetView()->GetDrawFuncPtr();
158 if (pDrView
&& pDraw
&& !mrViewData
.IsRefMode())
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() )
171 bool ScGridWindow::DrawKeyInput(const KeyEvent
& rKEvt
, vcl::Window
* pWin
)
173 ScDrawView
* pDrView
= mrViewData
.GetScDrawView();
174 FuPoor
* pDraw
= mrViewData
.GetView()->GetDrawFuncPtr();
177 if (pDrView
&& pDrView
->KeyInput(rKEvt
, pWin
))
180 if (pDrView
&& pDraw
&& !mrViewData
.IsRefMode())
182 pDraw
->SetWindow( this );
183 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
184 bool bOldMarked
= rMarkList
.GetMarkCount() != 0;
185 if (pDraw
->KeyInput( rKEvt
))
187 bool bLeaveDraw
= false;
189 bool bNewMarked
= rMarkList
.GetMarkCount() != 0;
190 if ( !mrViewData
.GetView()->IsDrawSelMode() )
193 mrViewData
.GetViewShell()->SetDrawShell( false );
196 rKEvt
.GetKeyCode().GetCode() == KEY_DELETE
)
197 bUsed
= false; // nothing deleted
202 UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
210 void ScGridWindow::DrawRedraw( ScOutputData
& rOutputData
, SdrLayerID nLayer
)
212 const ScViewOptions
& rOpts
= mrViewData
.GetOptions();
214 // use new flags at SdrPaintView for hiding objects
215 const bool bDrawOle(VOBJ_MODE_SHOW
== rOpts
.GetObjMode(VOBJ_TYPE_OLE
));
216 const bool bDrawChart(VOBJ_MODE_SHOW
== rOpts
.GetObjMode(VOBJ_TYPE_CHART
));
217 const bool bDrawDraw(VOBJ_MODE_SHOW
== rOpts
.GetObjMode(VOBJ_TYPE_DRAW
));
219 if(!(bDrawOle
|| bDrawChart
|| bDrawDraw
))
222 ScDrawView
* pDrView
= mrViewData
.GetView()->GetScDrawView();
226 pDrView
->setHideOle(!bDrawOle
);
227 pDrView
->setHideChart(!bDrawChart
);
228 pDrView
->setHideDraw(!bDrawDraw
);
229 pDrView
->setHideFormControl(!bDrawDraw
);
232 rOutputData
.DrawSelectiveObjects(nLayer
);
235 void ScGridWindow::DrawSdrGrid( const tools::Rectangle
& rDrawingRect
, OutputDevice
* pContentDev
)
239 ScDrawView
* pDrView
= mrViewData
.GetView()->GetScDrawView();
240 if ( pDrView
&& pDrView
->IsGridVisible() )
242 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
243 OSL_ENSURE(pPV
, "PageView not available");
246 pContentDev
->SetLineColor(COL_GRAY
);
248 pPV
->DrawPageViewGrid( *pContentDev
, rDrawingRect
);
253 MapMode
ScGridWindow::GetDrawMapMode( bool bForce
)
255 ScDocument
& rDoc
= mrViewData
.GetDocument();
257 // FIXME this shouldn't be necessary once we change the entire Calc to
258 // work in the logic coordinates (ideally 100ths of mm - so that it is
259 // the same as editeng and drawinglayer), and get rid of all the
260 // SetMapMode's and other unnecessary fun we have with pixels
261 if (comphelper::LibreOfficeKit::isActive())
263 return mrViewData
.GetLogicMode();
266 SCTAB nTab
= mrViewData
.GetTabNo();
267 bool bNegativePage
= rDoc
.IsNegativePage( nTab
);
269 MapMode aDrawMode
= mrViewData
.GetLogicMode();
271 ScDrawView
* pDrView
= mrViewData
.GetView()->GetScDrawView();
272 if ( pDrView
|| bForce
)
277 pDrView
->GetScale( aScaleX
, aScaleY
);
282 rDoc
.GetTableArea( nTab
, nEndCol
, nEndRow
);
283 if (nEndCol
<20) nEndCol
= 20;
284 if (nEndRow
<20) nEndRow
= 1000;
285 ScDrawUtil::CalcScale( rDoc
, nTab
, 0,0, nEndCol
,nEndRow
, GetOutDev(),
286 mrViewData
.GetZoomX(),mrViewData
.GetZoomY(),
287 mrViewData
.GetPPTX(),mrViewData
.GetPPTY(),
290 aDrawMode
.SetScaleX(aScaleX
);
291 aDrawMode
.SetScaleY(aScaleY
);
293 aDrawMode
.SetOrigin(Point());
294 Point aStartPos
= mrViewData
.GetPixPos(eWhich
);
297 // RTL uses negative positions for drawing objects
298 aStartPos
.setX( -aStartPos
.X() + GetOutputSizePixel().Width() - 1 );
300 aDrawMode
.SetOrigin( PixelToLogic( aStartPos
, aDrawMode
) );
305 void ScGridWindow::DrawAfterScroll()
307 PaintImmediately(); // always, so the behaviour with and without DrawingLayer is the same
309 ScDrawView
* pDrView
= mrViewData
.GetView()->GetScDrawView();
312 OutlinerView
* pOlView
= pDrView
->GetTextEditOutlinerView();
313 if (pOlView
&& pOlView
->GetWindow() == this)
314 pOlView
->ShowCursor(false); // was removed at scrolling
318 void ScGridWindow::CreateAnchorHandle(SdrHdlList
& rHdl
, const ScAddress
& rAddress
)
320 ScDrawView
* pDrView
= mrViewData
.GetView()->GetScDrawView();
323 const ScViewOptions
& rOpts
= mrViewData
.GetOptions();
324 if(rOpts
.GetOption( VOPT_ANCHOR
))
326 bool bNegativePage
= mrViewData
.GetDocument().IsNegativePage( mrViewData
.GetTabNo() );
327 Point aPos
= mrViewData
.GetScrPos( rAddress
.Col(), rAddress
.Row(), eWhich
, true );
328 aPos
= PixelToLogic(aPos
);
329 rHdl
.AddHdl(std::make_unique
<SdrHdl
>(aPos
, bNegativePage
? SdrHdlKind::Anchor_TR
: SdrHdlKind::Anchor
));
334 void ScGridWindow::UpdateStatusPosSize()
336 ScDrawView
* pDrView
= mrViewData
.GetView()->GetScDrawView();
338 return; // shouldn't be called in that case
340 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
342 return; // shouldn't be called in that case either
344 SfxItemSetFixed
<SID_ATTR_POSITION
, SID_ATTR_SIZE
> aSet(mrViewData
.GetViewShell()->GetPool());
346 // Fill items for position and size:
347 // show action rectangle during action,
348 // position and size of selected object(s) if something is selected,
349 // mouse position otherwise
351 bool bActionItem
= false;
352 if ( pDrView
->IsAction() ) // action rectangle
354 tools::Rectangle aRect
;
355 pDrView
->TakeActionRect( aRect
);
356 if ( !aRect
.IsEmpty() )
358 pPV
->LogicToPagePos(aRect
);
359 aSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aRect
.TopLeft() ) );
360 aSet
.Put( SvxSizeItem( SID_ATTR_SIZE
,
361 Size( aRect
.Right() - aRect
.Left(), aRect
.Bottom() - aRect
.Top() ) ) );
367 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
368 if ( rMarkList
.GetMarkCount() != 0 ) // selected objects
370 tools::Rectangle aRect
= pDrView
->GetAllMarkedRect();
371 pPV
->LogicToPagePos(aRect
);
372 aSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aRect
.TopLeft() ) );
373 aSet
.Put( SvxSizeItem( SID_ATTR_SIZE
,
374 Size( aRect
.Right() - aRect
.Left(), aRect
.Bottom() - aRect
.Top() ) ) );
376 else // mouse position
378 Point aPos
= PixelToLogic(aCurMousePos
);
379 pPV
->LogicToPagePos(aPos
);
380 aSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aPos
) );
381 aSet
.Put( SvxSizeItem( SID_ATTR_SIZE
, Size( 0, 0 ) ) );
385 mrViewData
.GetBindings().SetState(aSet
);
388 bool ScGridWindow::DrawHasMarkedObj()
390 ScDrawView
* p
= mrViewData
.GetScDrawView();
391 return p
&& p
->GetMarkedObjectList().GetMarkCount() != 0;
394 void ScGridWindow::DrawMarkDropObj( SdrObject
* pObj
)
396 ScDrawView
* pDrView
= mrViewData
.GetView()->GetScDrawView();
398 pDrView
->MarkDropObj(pObj
);
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */