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 "scitems.hxx"
21 #include <editeng/eeitem.hxx>
23 #include <svx/svdoutl.hxx>
24 #include <svx/svdotext.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <editeng/sizeitem.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <svl/ptitem.hxx>
30 #include "tabvwsh.hxx"
31 #include "gridwin.hxx"
33 #include "viewdata.hxx"
35 #include "drawview.hxx"
38 #include "drawutil.hxx"
39 #include "document.hxx"
40 #include "drwlayer.hxx"
41 #include <vcl/svapp.hxx>
42 #include "userdat.hxx"
43 #include "unitconv.hxx"
44 #include <svx/svdpage.hxx>
45 #include <comphelper/lok.hxx>
47 bool ScGridWindow::DrawMouseButtonDown(const MouseEvent
& rMEvt
)
50 FuPoor
* pDraw
= pViewData
->GetView()->GetDrawFuncPtr();
51 if (pDraw
&& !pViewData
->IsRefMode())
53 pDraw
->SetWindow( this );
54 Point aLogicPos
= PixelToLogic(rMEvt
.GetPosPixel());
55 if ( pDraw
->IsDetectiveHit( aLogicPos
) )
57 // nothing on detective arrows (double click is evaluated on ButtonUp)
62 bRet
= pDraw
->MouseButtonDown( rMEvt
);
64 UpdateStatusPosSize();
68 // cancel draw with right key
69 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
70 if ( pDrView
&& !rMEvt
.IsLeft() && !bRet
)
78 bool ScGridWindow::DrawMouseButtonUp(const MouseEvent
& rMEvt
)
80 ScViewFunc
* pView
= pViewData
->GetView();
82 FuPoor
* pDraw
= pView
->GetDrawFuncPtr();
83 if (pDraw
&& !pViewData
->IsRefMode())
85 pDraw
->SetWindow( this );
86 bRet
= pDraw
->MouseButtonUp( rMEvt
);
88 // execute "format paint brush" for drawing objects
89 SfxItemSet
* pDrawBrush
= pView
->GetDrawBrushSet();
92 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
95 bool bReplaceAll
= true;
96 pDrView
->SetAttrToMarked(*pDrawBrush
, bReplaceAll
);
99 if ( !pView
->IsPaintBrushLocked() )
100 pView
->ResetBrushDocument(); // end paint brush mode if not locked
107 bool ScGridWindow::DrawMouseMove(const MouseEvent
& rMEvt
)
109 FuPoor
* pDraw
= pViewData
->GetView()->GetDrawFuncPtr();
110 if (pDraw
&& !pViewData
->IsRefMode())
112 pDraw
->SetWindow( this );
113 bool bRet
= pDraw
->MouseMove( rMEvt
);
115 UpdateStatusPosSize();
120 SetPointer( Pointer( PointerStyle::Arrow
) );
125 void ScGridWindow::DrawEndAction()
127 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
128 if ( pDrView
&& pDrView
->IsAction() )
129 pDrView
->BrkAction();
131 FuPoor
* pDraw
= pViewData
->GetView()->GetDrawFuncPtr();
133 pDraw
->StopDragTimer();
135 // ReleaseMouse on call
138 bool ScGridWindow::DrawCommand(const CommandEvent
& rCEvt
)
140 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
141 FuPoor
* pDraw
= pViewData
->GetView()->GetDrawFuncPtr();
142 if (pDrView
&& pDraw
&& !pViewData
->IsRefMode())
144 pDraw
->SetWindow( this );
145 sal_uInt8 nUsed
= pDraw
->Command( rCEvt
);
146 if( nUsed
== SC_CMD_USED
)
147 nButtonDown
= 0; // MouseButtonUp is swallowed...
148 if( nUsed
|| pDrView
->IsAction() )
155 bool ScGridWindow::DrawKeyInput(const KeyEvent
& rKEvt
)
157 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
158 FuPoor
* pDraw
= pViewData
->GetView()->GetDrawFuncPtr();
159 if (pDrView
&& pDraw
&& !pViewData
->IsRefMode())
161 pDraw
->SetWindow( this );
162 bool bOldMarked
= pDrView
->AreObjectsMarked();
163 if (pDraw
->KeyInput( rKEvt
))
165 bool bLeaveDraw
= false;
167 bool bNewMarked
= pDrView
->AreObjectsMarked();
168 if ( !pViewData
->GetView()->IsDrawSelMode() )
171 pViewData
->GetViewShell()->SetDrawShell( false );
174 rKEvt
.GetKeyCode().GetCode() == KEY_DELETE
)
175 bUsed
= false; // nothing deleted
180 UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
188 void ScGridWindow::DrawRedraw( ScOutputData
& rOutputData
, ScUpdateMode eMode
, sal_uLong nLayer
)
190 const ScViewOptions
& rOpts
= pViewData
->GetOptions();
192 // use new flags at SdrPaintView for hiding objects
193 const bool bDrawOle(VOBJ_MODE_SHOW
== rOpts
.GetObjMode(VOBJ_TYPE_OLE
));
194 const bool bDrawChart(VOBJ_MODE_SHOW
== rOpts
.GetObjMode(VOBJ_TYPE_CHART
));
195 const bool bDrawDraw(VOBJ_MODE_SHOW
== rOpts
.GetObjMode(VOBJ_TYPE_DRAW
));
197 if(bDrawOle
|| bDrawChart
|| bDrawDraw
)
199 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
203 pDrView
->setHideOle(!bDrawOle
);
204 pDrView
->setHideChart(!bDrawChart
);
205 pDrView
->setHideDraw(!bDrawDraw
);
206 pDrView
->setHideFormControl(!bDrawDraw
);
209 if(SC_UPDATE_CHANGED
== eMode
)
211 rOutputData
.DrawingSingle((sal_uInt16
)nLayer
);
215 rOutputData
.DrawSelectiveObjects((sal_uInt16
)nLayer
);
220 void ScGridWindow::DrawSdrGrid( const Rectangle
& rDrawingRect
, OutputDevice
* pContentDev
)
224 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
225 if ( pDrView
&& pDrView
->IsGridVisible() )
227 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
228 OSL_ENSURE(pPV
, "PageView not available");
231 pContentDev
->SetLineColor(COL_GRAY
);
233 pPV
->DrawPageViewGrid( *pContentDev
, rDrawingRect
);
238 MapMode
ScGridWindow::GetDrawMapMode( bool bForce
)
240 ScDocument
* pDoc
= pViewData
->GetDocument();
242 // FIXME this shouldn't be necessary once we change the entire Calc to
243 // work in the logic coordinates (ideally 100ths of mm - so that it is
244 // the same as editeng and drawinglayer), and get rid of all the
245 // SetMapMode's and other unnecessary fun we have with pixels
246 if (comphelper::LibreOfficeKit::isActive())
248 return pViewData
->GetLogicMode();
251 SCTAB nTab
= pViewData
->GetTabNo();
252 bool bNegativePage
= pDoc
->IsNegativePage( nTab
);
254 MapMode aDrawMode
= pViewData
->GetLogicMode();
256 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
257 if ( pDrView
|| bForce
)
262 pDrView
->GetScale( aScaleX
, aScaleY
);
267 pDoc
->GetTableArea( nTab
, nEndCol
, nEndRow
);
268 if (nEndCol
<20) nEndCol
= 20;
269 if (nEndRow
<20) nEndRow
= 1000;
270 ScDrawUtil::CalcScale( pDoc
, nTab
, 0,0, nEndCol
,nEndRow
, this,
271 pViewData
->GetZoomX(),pViewData
->GetZoomY(),
272 pViewData
->GetPPTX(),pViewData
->GetPPTY(),
275 aDrawMode
.SetScaleX(aScaleX
);
276 aDrawMode
.SetScaleY(aScaleY
);
278 aDrawMode
.SetOrigin(Point());
279 Point aStartPos
= pViewData
->GetPixPos(eWhich
);
282 // RTL uses negative positions for drawing objects
283 aStartPos
.X() = -aStartPos
.X() + GetOutputSizePixel().Width() - 1;
285 aDrawMode
.SetOrigin( PixelToLogic( aStartPos
, aDrawMode
) );
290 void ScGridWindow::DrawAfterScroll()
292 Update(); // always, so the behaviour with and without DrawingLayer is the same
294 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
297 OutlinerView
* pOlView
= pDrView
->GetTextEditOutlinerView();
298 if (pOlView
&& pOlView
->GetWindow() == this)
299 pOlView
->ShowCursor(false); // was removed at scrolling
303 void ScGridWindow::CreateAnchorHandle(SdrHdlList
& rHdl
, const ScAddress
& rAddress
)
305 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
308 const ScViewOptions
& rOpts
= pViewData
->GetOptions();
309 if(rOpts
.GetOption( VOPT_ANCHOR
))
311 bool bNegativePage
= pViewData
->GetDocument()->IsNegativePage( pViewData
->GetTabNo() );
312 Point aPos
= pViewData
->GetScrPos( rAddress
.Col(), rAddress
.Row(), eWhich
, true );
313 aPos
= PixelToLogic(aPos
);
314 rHdl
.AddHdl(new SdrHdl(aPos
, bNegativePage
? HDL_ANCHOR_TR
: HDL_ANCHOR
));
319 SdrObject
* ScGridWindow::GetEditObject()
321 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
324 OutlinerView
* pOlView
= pDrView
->GetTextEditOutlinerView();
325 if (pOlView
&& pOlView
->GetWindow() == this)
326 return pDrView
->GetTextEditObject();
332 void ScGridWindow::UpdateStatusPosSize()
334 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
336 return; // shouldn't be called in that case
338 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
340 return; // shouldn't be called in that case either
342 SfxItemSet
aSet(pViewData
->GetViewShell()->GetPool(), SID_ATTR_POSITION
, SID_ATTR_SIZE
);
344 // Fill items for position and size:
345 // show action rectangle during action,
346 // position and size of selected object(s) if something is selected,
347 // mouse position otherwise
349 bool bActionItem
= false;
350 if ( pDrView
->IsAction() ) // action rectangle
353 pDrView
->TakeActionRect( aRect
);
354 if ( !aRect
.IsEmpty() )
356 // mouse position will have been adjusted for offset
357 // at current position and zoom, restore that adjustment here
358 // so status shows correct value
359 aRect
-= pDrView
->GetGridOffset();
360 pPV
->LogicToPagePos(aRect
);
361 aSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aRect
.TopLeft() ) );
362 aSet
.Put( SvxSizeItem( SID_ATTR_SIZE
,
363 Size( aRect
.Right() - aRect
.Left(), aRect
.Bottom() - aRect
.Top() ) ) );
369 if ( pDrView
->AreObjectsMarked() ) // selected objects
371 Rectangle aRect
= pDrView
->GetAllMarkedRect();
372 // mouse position will have been adjusted for offset
373 // at current position and zoom, restore that adjustment here
374 // so status shows correct value
375 aRect
-= pDrView
->GetGridOffset();
376 pPV
->LogicToPagePos(aRect
);
377 aSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aRect
.TopLeft() ) );
378 aSet
.Put( SvxSizeItem( SID_ATTR_SIZE
,
379 Size( aRect
.Right() - aRect
.Left(), aRect
.Bottom() - aRect
.Top() ) ) );
381 else // mouse position
383 Point aPos
= PixelToLogic(aCurMousePos
);
384 pPV
->LogicToPagePos(aPos
);
385 aSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aPos
) );
386 aSet
.Put( SvxSizeItem( SID_ATTR_SIZE
, Size( 0, 0 ) ) );
390 pViewData
->GetBindings().SetState(aSet
);
393 bool ScGridWindow::DrawHasMarkedObj()
395 ScDrawView
* p
= pViewData
->GetScDrawView();
396 return p
&& p
->AreObjectsMarked();
399 void ScGridWindow::DrawMarkDropObj( SdrObject
* pObj
)
401 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
403 pDrView
->MarkDropObj(pObj
);
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */