tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / view / gridwin3.cxx
blobc0aa97ded4c6fe9ecc3d5c773f912c2015422455
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 #include <dbfunc.hxx>
30 #include <viewdata.hxx>
31 #include <output.hxx>
32 #include <drawview.hxx>
33 #include <fupoor.hxx>
35 #include <drawutil.hxx>
36 #include <document.hxx>
37 #include <comphelper/lok.hxx>
39 bool ScGridWindow::DrawMouseButtonDown(const MouseEvent& rMEvt)
41 bool bRet = false;
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)
55 bRet = true;
57 else
59 bRet = pDraw->MouseButtonDown( rMEvt );
60 if ( bRet )
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 )
72 pDrView->BrkAction();
73 bRet = true;
75 return bRet;
78 bool ScGridWindow::DrawMouseButtonUp(const MouseEvent& rMEvt)
80 ScViewFunc* pView = mrViewData.GetView();
81 bool bRet = false;
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();
95 if ( pDrawBrush )
97 ScDrawView* pDrView = mrViewData.GetScDrawView();
98 if ( pDrView )
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 );
111 return bRet;
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 );
126 if ( bRet )
127 UpdateStatusPosSize();
129 if ( comphelper::LibreOfficeKit::isActive() && aOldMode != aDrawMode )
130 SetMapMode( aOldMode );
132 return bRet;
134 else
136 SetPointer( PointerStyle::Arrow );
137 return false;
141 void ScGridWindow::DrawEndAction()
143 ScDrawView* pDrView = mrViewData.GetScDrawView();
144 if ( pDrView && pDrView->IsAction() )
145 pDrView->BrkAction();
147 FuPoor* pDraw = mrViewData.GetView()->GetDrawFuncPtr();
148 if (pDraw)
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() )
165 return true;
168 return false;
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))
178 return true;
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;
188 bool bUsed = true;
189 bool bNewMarked = rMarkList.GetMarkCount() != 0;
190 if ( !mrViewData.GetView()->IsDrawSelMode() )
191 if ( !bNewMarked )
193 mrViewData.GetViewShell()->SetDrawShell( false );
194 bLeaveDraw = true;
195 if ( !bOldMarked &&
196 rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
197 bUsed = false; // nothing deleted
198 if(bOldMarked)
199 GetFocus();
201 if (!bLeaveDraw)
202 UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
203 return bUsed;
207 return false;
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))
220 return;
222 ScDrawView* pDrView = mrViewData.GetView()->GetScDrawView();
224 if(pDrView)
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 )
237 // Draw grid lines
239 ScDrawView* pDrView = mrViewData.GetView()->GetScDrawView();
240 if ( pDrView && pDrView->IsGridVisible() )
242 SdrPageView* pPV = pDrView->GetSdrPageView();
243 OSL_ENSURE(pPV, "PageView not available");
244 if (pPV)
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 )
274 Fraction aScaleX;
275 Fraction aScaleY;
276 if (pDrView)
277 pDrView->GetScale( aScaleX, aScaleY );
278 else
280 SCCOL nEndCol = 0;
281 SCROW nEndRow = 0;
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(),
288 aScaleX,aScaleY );
290 aDrawMode.SetScaleX(aScaleX);
291 aDrawMode.SetScaleY(aScaleY);
293 aDrawMode.SetOrigin(Point());
294 Point aStartPos = mrViewData.GetPixPos(eWhich);
295 if ( bNegativePage )
297 // RTL uses negative positions for drawing objects
298 aStartPos.setX( -aStartPos.X() + GetOutputSizePixel().Width() - 1 );
300 aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
302 return aDrawMode;
305 void ScGridWindow::DrawAfterScroll()
307 PaintImmediately(); // always, so the behaviour with and without DrawingLayer is the same
309 ScDrawView* pDrView = mrViewData.GetView()->GetScDrawView();
310 if (pDrView)
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();
321 if (pDrView)
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();
337 if (!pDrView)
338 return; // shouldn't be called in that case
340 SdrPageView* pPV = pDrView->GetSdrPageView();
341 if (!pPV)
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() ) ) );
362 bActionItem = true;
365 if ( !bActionItem )
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();
397 if (pDrView)
398 pDrView->MarkDropObj(pObj);
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */