fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / gridwin3.cxx
blobb1e7b6fa78055ff9d914db89ad8f1897c4b08fc7
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 "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"
32 #include "dbfunc.hxx"
33 #include "viewdata.hxx"
34 #include "output.hxx"
35 #include "drawview.hxx"
36 #include "fupoor.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>
46 bool ScGridWindow::DrawMouseButtonDown(const MouseEvent& rMEvt)
48 bool bRet = false;
49 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
50 if (pDraw && !pViewData->IsRefMode())
52 pDraw->SetWindow( this );
53 Point aLogicPos = PixelToLogic(rMEvt.GetPosPixel());
54 if ( pDraw->IsDetectiveHit( aLogicPos ) )
56 // auf Detektiv-Pfeilen gar nichts (Doppelklick wird bei ButtonUp ausgewertet)
57 bRet = true;
59 else
61 bRet = pDraw->MouseButtonDown( rMEvt );
62 if ( bRet )
63 UpdateStatusPosSize();
67 // cancel draw with right key
68 ScDrawView* pDrView = pViewData->GetScDrawView();
69 if ( pDrView && !rMEvt.IsLeft() && !bRet )
71 pDrView->BrkAction();
72 bRet = true;
74 return bRet;
77 bool ScGridWindow::DrawMouseButtonUp(const MouseEvent& rMEvt)
79 ScViewFunc* pView = pViewData->GetView();
80 bool bRet = false;
81 FuPoor* pDraw = pView->GetDrawFuncPtr();
82 if (pDraw && !pViewData->IsRefMode())
84 pDraw->SetWindow( this );
85 bRet = pDraw->MouseButtonUp( rMEvt );
87 // execute "format paint brush" for drawing objects
88 SfxItemSet* pDrawBrush = pView->GetDrawBrushSet();
89 if ( pDrawBrush )
91 ScDrawView* pDrView = pViewData->GetScDrawView();
92 if ( pDrView )
94 bool bReplaceAll = true;
95 pDrView->SetAttrToMarked(*pDrawBrush, bReplaceAll);
98 if ( !pView->IsPaintBrushLocked() )
99 pView->ResetBrushDocument(); // end paint brush mode if not locked
103 return bRet;
106 bool ScGridWindow::DrawMouseMove(const MouseEvent& rMEvt)
108 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
109 if (pDraw && !pViewData->IsRefMode())
111 pDraw->SetWindow( this );
112 bool bRet = pDraw->MouseMove( rMEvt );
113 if ( bRet )
114 UpdateStatusPosSize();
115 return bRet;
117 else
119 SetPointer( Pointer( PointerStyle::Arrow ) );
120 return false;
124 void ScGridWindow::DrawEndAction()
126 ScDrawView* pDrView = pViewData->GetScDrawView();
127 if ( pDrView && pDrView->IsAction() )
128 pDrView->BrkAction();
130 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
131 if (pDraw)
132 pDraw->StopDragTimer();
134 // ReleaseMouse beim Aufruf
137 bool ScGridWindow::DrawCommand(const CommandEvent& rCEvt)
139 ScDrawView* pDrView = pViewData->GetScDrawView();
140 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
141 if (pDrView && pDraw && !pViewData->IsRefMode())
143 pDraw->SetWindow( this );
144 sal_uInt8 nUsed = pDraw->Command( rCEvt );
145 if( nUsed == SC_CMD_USED )
146 nButtonDown = 0; // MouseButtonUp wird verschluckt...
147 if( nUsed || pDrView->IsAction() )
148 return true;
151 return false;
154 bool ScGridWindow::DrawKeyInput(const KeyEvent& rKEvt)
156 ScDrawView* pDrView = pViewData->GetScDrawView();
157 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
158 if (pDrView && pDraw && !pViewData->IsRefMode())
160 pDraw->SetWindow( this );
161 bool bOldMarked = pDrView->AreObjectsMarked();
162 if (pDraw->KeyInput( rKEvt ))
164 bool bLeaveDraw = false;
165 bool bUsed = true;
166 bool bNewMarked = pDrView->AreObjectsMarked();
167 if ( !pViewData->GetView()->IsDrawSelMode() )
168 if ( !bNewMarked )
170 pViewData->GetViewShell()->SetDrawShell( false );
171 bLeaveDraw = true;
172 if ( !bOldMarked &&
173 rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
174 bUsed = false; // nothing deleted
175 if(bOldMarked)
176 GetFocus();
178 if (!bLeaveDraw)
179 UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
180 return bUsed;
184 return false;
187 void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer )
189 // #109985#
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();
201 if(pDrView)
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);
213 else
215 rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
220 void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
222 // Draw grid lines
224 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
225 if ( pDrView && pDrView->IsGridVisible() )
227 SdrPageView* pPV = pDrView->GetSdrPageView();
228 OSL_ENSURE(pPV, "PageView not available");
229 if (pPV)
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 unneccessary fun we have with pixels
246 if (pDoc->GetDrawLayer() && pDoc->GetDrawLayer()->isTiledRendering())
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 )
259 Fraction aScaleX;
260 Fraction aScaleY;
261 if (pDrView)
262 pDrView->GetScale( aScaleX, aScaleY );
263 else
265 SCCOL nEndCol = 0;
266 SCROW nEndRow = 0;
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(),
273 aScaleX,aScaleY );
275 aDrawMode.SetScaleX(aScaleX);
276 aDrawMode.SetScaleY(aScaleY);
278 aDrawMode.SetOrigin(Point());
279 Point aStartPos = pViewData->GetPixPos(eWhich);
280 if ( bNegativePage )
282 // RTL uses negative positions for drawing objects
283 aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
285 aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
287 return aDrawMode;
290 void ScGridWindow::DrawAfterScroll()
292 Update(); // always, so the the behaviour with and without DrawingLayer is the same
294 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
295 if (pDrView)
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();
306 if (pDrView)
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();
322 if (pDrView)
324 OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
325 if (pOlView && pOlView->GetWindow() == this)
326 return pDrView->GetTextEditObject();
329 return NULL;
332 void ScGridWindow::UpdateStatusPosSize()
334 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
335 if (!pDrView)
336 return; // shouldn't be called in that case
338 SdrPageView* pPV = pDrView->GetSdrPageView();
339 if (!pPV)
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
352 Rectangle aRect;
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() ) ) );
364 bActionItem = true;
367 if ( !bActionItem )
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();
402 if (pDrView)
403 pDrView->MarkDropObj(pObj);
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */