GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / view / gridwin3.cxx
blob5aab83453ebba5cddd450ccdc538268d9d180c18
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 .
21 #include "scitems.hxx"
22 #include <editeng/eeitem.hxx>
24 #include <svx/svdoutl.hxx>
25 #include <svx/svdotext.hxx>
26 #include <svx/svdpagv.hxx>
27 #include <editeng/sizeitem.hxx>
28 #include <sfx2/bindings.hxx>
29 #include <svl/ptitem.hxx>
31 #include "tabvwsh.hxx"
32 #include "gridwin.hxx"
33 #include "dbfunc.hxx"
34 #include "viewdata.hxx"
35 #include "output.hxx"
36 #include "drawview.hxx"
37 #include "fupoor.hxx"
39 #include "drawutil.hxx"
40 #include "document.hxx"
41 #include "drwlayer.hxx"
42 #include <vcl/svapp.hxx>
43 #include "userdat.hxx"
44 #include "unitconv.hxx"
45 #include <svx/svdpage.hxx>
46 // -----------------------------------------------------------------------
48 bool ScGridWindow::DrawMouseButtonDown(const MouseEvent& rMEvt)
50 bool bRet = false;
51 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
52 if (pDraw && !pViewData->IsRefMode())
54 pDraw->SetWindow( this );
55 Point aLogicPos = PixelToLogic(rMEvt.GetPosPixel());
56 if ( pDraw->IsDetectiveHit( aLogicPos ) )
58 // auf Detektiv-Pfeilen gar nichts (Doppelklick wird bei ButtonUp ausgewertet)
59 bRet = true;
61 else
63 bRet = pDraw->MouseButtonDown( rMEvt );
64 if ( bRet )
65 UpdateStatusPosSize();
69 // bei rechter Taste Draw-Aktion abbrechen
71 ScDrawView* pDrView = pViewData->GetScDrawView();
72 if ( pDrView && !rMEvt.IsLeft() && !bRet )
74 pDrView->BrkAction();
75 bRet = true;
77 return bRet;
80 bool ScGridWindow::DrawMouseButtonUp(const MouseEvent& rMEvt)
82 ScViewFunc* pView = pViewData->GetView();
83 bool bRet = false;
84 FuPoor* pDraw = pView->GetDrawFuncPtr();
85 if (pDraw && !pViewData->IsRefMode())
87 pDraw->SetWindow( this );
88 bRet = pDraw->MouseButtonUp( rMEvt );
90 // execute "format paint brush" for drawing objects
91 SfxItemSet* pDrawBrush = pView->GetDrawBrushSet();
92 if ( pDrawBrush )
94 ScDrawView* pDrView = pViewData->GetScDrawView();
95 if ( pDrView )
97 bool bReplaceAll = true;
98 pDrView->SetAttrToMarked(*pDrawBrush, bReplaceAll);
101 if ( !pView->IsPaintBrushLocked() )
102 pView->ResetBrushDocument(); // end paint brush mode if not locked
106 return bRet;
109 bool ScGridWindow::DrawMouseMove(const MouseEvent& rMEvt)
111 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
112 if (pDraw && !pViewData->IsRefMode())
114 pDraw->SetWindow( this );
115 bool bRet = pDraw->MouseMove( rMEvt );
116 if ( bRet )
117 UpdateStatusPosSize();
118 return bRet;
120 else
122 SetPointer( Pointer( POINTER_ARROW ) );
123 return false;
127 void ScGridWindow::DrawEndAction()
129 ScDrawView* pDrView = pViewData->GetScDrawView();
130 if ( pDrView && pDrView->IsAction() )
131 pDrView->BrkAction();
133 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
134 if (pDraw)
135 pDraw->StopDragTimer();
137 // ReleaseMouse beim Aufruf
140 bool ScGridWindow::DrawCommand(const CommandEvent& rCEvt)
142 ScDrawView* pDrView = pViewData->GetScDrawView();
143 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
144 if (pDrView && pDraw && !pViewData->IsRefMode())
146 pDraw->SetWindow( this );
147 sal_uInt8 nUsed = pDraw->Command( rCEvt );
148 if( nUsed == SC_CMD_USED )
149 nButtonDown = 0; // MouseButtonUp wird verschluckt...
150 if( nUsed || pDrView->IsAction() )
151 return true;
154 return false;
157 bool ScGridWindow::DrawKeyInput(const KeyEvent& rKEvt)
159 ScDrawView* pDrView = pViewData->GetScDrawView();
160 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
161 if (pDrView && pDraw && !pViewData->IsRefMode())
163 pDraw->SetWindow( this );
164 bool bOldMarked = pDrView->AreObjectsMarked();
165 if (pDraw->KeyInput( rKEvt ))
167 bool bLeaveDraw = false;
168 bool bUsed = true;
169 bool bNewMarked = pDrView->AreObjectsMarked();
170 if ( !pViewData->GetView()->IsDrawSelMode() )
171 if ( !bNewMarked )
173 pViewData->GetViewShell()->SetDrawShell( false );
174 bLeaveDraw = true;
175 if ( !bOldMarked &&
176 rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
177 bUsed = false; // nichts geloescht
179 if (!bLeaveDraw)
180 UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
181 return bUsed;
185 return false;
188 void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer )
190 // #109985#
191 const ScViewOptions& rOpts = pViewData->GetOptions();
193 // use new flags at SdrPaintView for hiding objects
194 const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
195 const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
196 const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
198 if(bDrawOle || bDrawChart || bDrawDraw)
200 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
202 if(pDrView)
204 pDrView->setHideOle(!bDrawOle);
205 pDrView->setHideChart(!bDrawChart);
206 pDrView->setHideDraw(!bDrawDraw);
207 pDrView->setHideFormControl(!bDrawDraw);
210 if(SC_UPDATE_CHANGED == eMode)
212 rOutputData.DrawingSingle((sal_uInt16)nLayer);
214 else
216 rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
221 void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
223 // Draw-Gitterlinien
225 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
226 if ( pDrView && pDrView->IsGridVisible() )
228 SdrPageView* pPV = pDrView->GetSdrPageView();
229 OSL_ENSURE(pPV, "keine PageView");
230 if (pPV)
232 pContentDev->SetLineColor(COL_GRAY);
234 pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
239 MapMode ScGridWindow::GetDrawMapMode( bool bForce )
241 ScDocument* pDoc = pViewData->GetDocument();
242 SCTAB nTab = pViewData->GetTabNo();
243 sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
245 MapMode aDrawMode = pViewData->GetLogicMode();
247 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
248 if ( pDrView || bForce )
250 Fraction aScaleX;
251 Fraction aScaleY;
252 if (pDrView)
253 pDrView->GetScale( aScaleX, aScaleY );
254 else
256 SCCOL nEndCol = 0;
257 SCROW nEndRow = 0;
258 pDoc->GetTableArea( nTab, nEndCol, nEndRow );
259 if (nEndCol<20) nEndCol = 20;
260 if (nEndRow<20) nEndRow = 1000;
261 ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
262 pViewData->GetZoomX(),pViewData->GetZoomY(),
263 pViewData->GetPPTX(),pViewData->GetPPTY(),
264 aScaleX,aScaleY );
266 aDrawMode.SetScaleX(aScaleX);
267 aDrawMode.SetScaleY(aScaleY);
269 aDrawMode.SetOrigin(Point());
270 Point aStartPos = pViewData->GetPixPos(eWhich);
271 if ( bNegativePage )
273 // RTL uses negative positions for drawing objects
274 aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
276 aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
278 return aDrawMode;
281 void ScGridWindow::DrawAfterScroll()
283 Update(); // immer, damit das Verhalten mit/ohne DrawingLayer gleich ist
285 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
286 if (pDrView)
288 OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
289 if (pOlView && pOlView->GetWindow() == this)
290 pOlView->ShowCursor(false); // ist beim Scrollen weggekommen
294 void ScGridWindow::CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress)
296 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
297 if (pDrView)
299 const ScViewOptions& rOpts = pViewData->GetOptions();
300 if(rOpts.GetOption( VOPT_ANCHOR ))
302 sal_Bool bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
303 Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, sal_True );
304 aPos = PixelToLogic(aPos);
305 rHdl.AddHdl(new SdrHdl(aPos, bNegativePage ? HDL_ANCHOR_TR : HDL_ANCHOR));
310 SdrObject* ScGridWindow::GetEditObject()
312 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
313 if (pDrView)
315 OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
316 if (pOlView && pOlView->GetWindow() == this)
317 return pDrView->GetTextEditObject();
320 return NULL;
323 void ScGridWindow::UpdateStatusPosSize()
325 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
326 if (!pDrView)
327 return; // shouldn't be called in that case
329 SdrPageView* pPV = pDrView->GetSdrPageView();
330 if (!pPV)
331 return; // shouldn't be called in that case either
333 SfxItemSet aSet(pViewData->GetViewShell()->GetPool(), SID_ATTR_POSITION, SID_ATTR_SIZE);
335 // Fill items for position and size:
336 // show action rectangle during action,
337 // position and size of selected object(s) if something is selected,
338 // mouse position otherwise
340 sal_Bool bActionItem = false;
341 if ( pDrView->IsAction() ) // action rectangle
343 Rectangle aRect;
344 pDrView->TakeActionRect( aRect );
345 if ( !aRect.IsEmpty() )
347 // mouse position will have been adjusted for offset
348 // at current position and zoom, restore that adjustment here
349 // so status shows correct value
350 aRect -= pDrView->GetGridOffset();
351 pPV->LogicToPagePos(aRect);
352 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
353 aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
354 Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
355 bActionItem = sal_True;
358 if ( !bActionItem )
360 if ( pDrView->AreObjectsMarked() ) // selected objects
362 Rectangle aRect = pDrView->GetAllMarkedRect();
363 // mouse position will have been adjusted for offset
364 // at current position and zoom, restore that adjustment here
365 // so status shows correct value
366 aRect -= pDrView->GetGridOffset();
367 pPV->LogicToPagePos(aRect);
368 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
369 aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
370 Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
372 else // mouse position
374 Point aPos = PixelToLogic(aCurMousePos);
375 pPV->LogicToPagePos(aPos);
376 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
377 aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
381 pViewData->GetBindings().SetState(aSet);
384 bool ScGridWindow::DrawHasMarkedObj()
386 ScDrawView* p = pViewData->GetScDrawView();
387 return p ? p->AreObjectsMarked() : false;
390 void ScGridWindow::DrawMarkDropObj( SdrObject* pObj )
392 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
393 if (pDrView)
394 pDrView->MarkDropObj(pObj);
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */