Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / gridwin3.cxx
blob22d9c435527c99fdf56a988f64566ad2af6ef26d
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>
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
178 if(bOldMarked)
179 GetFocus();
181 if (!bLeaveDraw)
182 UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
183 return bUsed;
187 return false;
190 void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer )
192 // #109985#
193 const ScViewOptions& rOpts = pViewData->GetOptions();
195 // use new flags at SdrPaintView for hiding objects
196 const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
197 const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
198 const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
200 if(bDrawOle || bDrawChart || bDrawDraw)
202 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
204 if(pDrView)
206 pDrView->setHideOle(!bDrawOle);
207 pDrView->setHideChart(!bDrawChart);
208 pDrView->setHideDraw(!bDrawDraw);
209 pDrView->setHideFormControl(!bDrawDraw);
212 if(SC_UPDATE_CHANGED == eMode)
214 rOutputData.DrawingSingle((sal_uInt16)nLayer);
216 else
218 rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
223 void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
225 // Draw-Gitterlinien
227 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
228 if ( pDrView && pDrView->IsGridVisible() )
230 SdrPageView* pPV = pDrView->GetSdrPageView();
231 OSL_ENSURE(pPV, "keine PageView");
232 if (pPV)
234 pContentDev->SetLineColor(COL_GRAY);
236 pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
241 MapMode ScGridWindow::GetDrawMapMode( bool bForce )
243 ScDocument* pDoc = pViewData->GetDocument();
244 SCTAB nTab = pViewData->GetTabNo();
245 bool bNegativePage = pDoc->IsNegativePage( nTab );
247 MapMode aDrawMode = pViewData->GetLogicMode();
249 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
250 if ( pDrView || bForce )
252 Fraction aScaleX;
253 Fraction aScaleY;
254 if (pDrView)
255 pDrView->GetScale( aScaleX, aScaleY );
256 else
258 SCCOL nEndCol = 0;
259 SCROW nEndRow = 0;
260 pDoc->GetTableArea( nTab, nEndCol, nEndRow );
261 if (nEndCol<20) nEndCol = 20;
262 if (nEndRow<20) nEndRow = 1000;
263 ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
264 pViewData->GetZoomX(),pViewData->GetZoomY(),
265 pViewData->GetPPTX(),pViewData->GetPPTY(),
266 aScaleX,aScaleY );
268 aDrawMode.SetScaleX(aScaleX);
269 aDrawMode.SetScaleY(aScaleY);
271 aDrawMode.SetOrigin(Point());
272 Point aStartPos = pViewData->GetPixPos(eWhich);
273 if ( bNegativePage )
275 // RTL uses negative positions for drawing objects
276 aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
278 aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
280 return aDrawMode;
283 void ScGridWindow::DrawAfterScroll()
285 Update(); // immer, damit das Verhalten mit/ohne DrawingLayer gleich ist
287 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
288 if (pDrView)
290 OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
291 if (pOlView && pOlView->GetWindow() == this)
292 pOlView->ShowCursor(false); // ist beim Scrollen weggekommen
296 void ScGridWindow::CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress)
298 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
299 if (pDrView)
301 const ScViewOptions& rOpts = pViewData->GetOptions();
302 if(rOpts.GetOption( VOPT_ANCHOR ))
304 bool bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
305 Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, true );
306 aPos = PixelToLogic(aPos);
307 rHdl.AddHdl(new SdrHdl(aPos, bNegativePage ? HDL_ANCHOR_TR : HDL_ANCHOR));
312 SdrObject* ScGridWindow::GetEditObject()
314 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
315 if (pDrView)
317 OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
318 if (pOlView && pOlView->GetWindow() == this)
319 return pDrView->GetTextEditObject();
322 return NULL;
325 void ScGridWindow::UpdateStatusPosSize()
327 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
328 if (!pDrView)
329 return; // shouldn't be called in that case
331 SdrPageView* pPV = pDrView->GetSdrPageView();
332 if (!pPV)
333 return; // shouldn't be called in that case either
335 SfxItemSet aSet(pViewData->GetViewShell()->GetPool(), SID_ATTR_POSITION, SID_ATTR_SIZE);
337 // Fill items for position and size:
338 // show action rectangle during action,
339 // position and size of selected object(s) if something is selected,
340 // mouse position otherwise
342 bool bActionItem = false;
343 if ( pDrView->IsAction() ) // action rectangle
345 Rectangle aRect;
346 pDrView->TakeActionRect( aRect );
347 if ( !aRect.IsEmpty() )
349 // mouse position will have been adjusted for offset
350 // at current position and zoom, restore that adjustment here
351 // so status shows correct value
352 aRect -= pDrView->GetGridOffset();
353 pPV->LogicToPagePos(aRect);
354 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
355 aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
356 Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
357 bActionItem = true;
360 if ( !bActionItem )
362 if ( pDrView->AreObjectsMarked() ) // selected objects
364 Rectangle aRect = pDrView->GetAllMarkedRect();
365 // mouse position will have been adjusted for offset
366 // at current position and zoom, restore that adjustment here
367 // so status shows correct value
368 aRect -= pDrView->GetGridOffset();
369 pPV->LogicToPagePos(aRect);
370 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
371 aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
372 Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
374 else // mouse position
376 Point aPos = PixelToLogic(aCurMousePos);
377 pPV->LogicToPagePos(aPos);
378 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
379 aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
383 pViewData->GetBindings().SetState(aSet);
386 bool ScGridWindow::DrawHasMarkedObj()
388 ScDrawView* p = pViewData->GetScDrawView();
389 return p && p->AreObjectsMarked();
392 void ScGridWindow::DrawMarkDropObj( SdrObject* pObj )
394 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
395 if (pDrView)
396 pDrView->MarkDropObj(pObj);
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */