Update ooo320-m1
[ooovba.git] / sc / source / ui / view / gridwin3.cxx
blob0d5b97ebc07d54943630efcffa5ea61672e0984e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gridwin3.cxx,v $
10 * $Revision: 1.20.126.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "scitems.hxx"
35 #include <svx/eeitem.hxx>
37 #include <svx/svdoutl.hxx>
38 #include <svx/svdotext.hxx>
39 #include <svx/svdpagv.hxx>
40 #include <svx/sizeitem.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <svtools/ptitem.hxx>
44 #include "tabvwsh.hxx"
45 #include "gridwin.hxx"
46 #include "dbfunc.hxx"
47 #include "viewdata.hxx"
48 #include "output.hxx"
49 #include "drawview.hxx"
50 #include "fupoor.hxx"
52 #include "drawutil.hxx"
53 #include "document.hxx"
54 #include "drwlayer.hxx"
55 #include <vcl/svapp.hxx>
57 // -----------------------------------------------------------------------
59 BOOL ScGridWindow::DrawMouseButtonDown(const MouseEvent& rMEvt)
61 BOOL bRet = FALSE;
62 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
63 if (pDraw && !pViewData->IsRefMode())
65 pDraw->SetWindow( this );
66 Point aLogicPos = PixelToLogic(rMEvt.GetPosPixel());
67 if ( pDraw->IsDetectiveHit( aLogicPos ) )
69 // auf Detektiv-Pfeilen gar nichts (Doppelklick wird bei ButtonUp ausgewertet)
70 bRet = TRUE;
72 else
74 bRet = pDraw->MouseButtonDown( rMEvt );
75 if ( bRet )
76 UpdateStatusPosSize();
80 // bei rechter Taste Draw-Aktion abbrechen
82 ScDrawView* pDrView = pViewData->GetScDrawView();
83 if ( pDrView && !rMEvt.IsLeft() && !bRet )
85 pDrView->BrkAction();
86 bRet = TRUE;
88 return bRet;
91 BOOL ScGridWindow::DrawMouseButtonUp(const MouseEvent& rMEvt)
93 ScViewFunc* pView = pViewData->GetView();
94 BOOL bRet = FALSE;
95 FuPoor* pDraw = pView->GetDrawFuncPtr();
96 if (pDraw && !pViewData->IsRefMode())
98 pDraw->SetWindow( this );
99 bRet = pDraw->MouseButtonUp( rMEvt );
101 // execute "format paint brush" for drawing objects
102 SfxItemSet* pDrawBrush = pView->GetDrawBrushSet();
103 if ( pDrawBrush )
105 ScDrawView* pDrView = pViewData->GetScDrawView();
106 if ( pDrView )
108 BOOL bReplaceAll = TRUE;
109 pDrView->SetAttrToMarked(*pDrawBrush, bReplaceAll);
112 if ( !pView->IsPaintBrushLocked() )
113 pView->ResetBrushDocument(); // end paint brush mode if not locked
117 return bRet;
120 BOOL ScGridWindow::DrawMouseMove(const MouseEvent& rMEvt)
122 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
123 if (pDraw && !pViewData->IsRefMode())
125 pDraw->SetWindow( this );
126 BOOL bRet = pDraw->MouseMove( rMEvt );
127 if ( bRet )
128 UpdateStatusPosSize();
129 return bRet;
131 else
133 SetPointer( Pointer( POINTER_ARROW ) );
134 return FALSE;
138 void ScGridWindow::DrawEndAction()
140 ScDrawView* pDrView = pViewData->GetScDrawView();
141 if ( pDrView && pDrView->IsAction() )
142 pDrView->BrkAction();
144 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
145 if (pDraw)
146 pDraw->StopDragTimer();
148 // ReleaseMouse beim Aufruf
151 BOOL ScGridWindow::DrawCommand(const CommandEvent& rCEvt)
153 ScDrawView* pDrView = pViewData->GetScDrawView();
154 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
155 if (pDrView && pDraw && !pViewData->IsRefMode())
157 pDraw->SetWindow( this );
158 BYTE nUsed = pDraw->Command( rCEvt );
159 if( nUsed == SC_CMD_USED )
160 nButtonDown = 0; // MouseButtonUp wird verschluckt...
161 if( nUsed || pDrView->IsAction() )
162 return TRUE;
165 return FALSE;
168 BOOL ScGridWindow::DrawKeyInput(const KeyEvent& rKEvt)
170 ScDrawView* pDrView = pViewData->GetScDrawView();
171 FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
172 if (pDrView && pDraw && !pViewData->IsRefMode())
174 pDraw->SetWindow( this );
175 BOOL bOldMarked = pDrView->AreObjectsMarked();
176 if (pDraw->KeyInput( rKEvt ))
178 BOOL bLeaveDraw = FALSE;
179 BOOL bUsed = TRUE;
180 BOOL bNewMarked = pDrView->AreObjectsMarked();
181 if ( !pViewData->GetView()->IsDrawSelMode() )
182 if ( !bNewMarked )
184 pViewData->GetViewShell()->SetDrawShell( FALSE );
185 bLeaveDraw = TRUE;
186 if ( !bOldMarked &&
187 rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
188 bUsed = FALSE; // nichts geloescht
190 if (!bLeaveDraw)
191 UpdateStatusPosSize(); // #108137# for moving/resizing etc. by keyboard
192 return bUsed;
196 return FALSE;
199 void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, ULONG nLayer )
201 // #109985#
202 const ScViewOptions& rOpts = pViewData->GetOptions();
204 // use new flags at SdrPaintView for hiding objects
205 const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
206 const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
207 const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
209 if(bDrawOle || bDrawChart || bDrawDraw)
211 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
213 if(pDrView)
215 pDrView->setHideOle(!bDrawOle);
216 pDrView->setHideChart(!bDrawChart);
217 pDrView->setHideDraw(!bDrawDraw);
220 if(SC_UPDATE_CHANGED == eMode)
222 rOutputData.DrawingSingle((sal_uInt16)nLayer);
224 else
226 rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
231 void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
233 // Draw-Gitterlinien
235 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
236 if ( pDrView && pDrView->IsGridVisible() )
238 SdrPageView* pPV = pDrView->GetSdrPageView();
239 DBG_ASSERT(pPV, "keine PageView");
240 if (pPV)
242 pContentDev->SetLineColor(COL_GRAY);
244 pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
249 MapMode ScGridWindow::GetDrawMapMode( BOOL bForce )
251 ScDocument* pDoc = pViewData->GetDocument();
252 SCTAB nTab = pViewData->GetTabNo();
253 BOOL bNegativePage = pDoc->IsNegativePage( nTab );
255 MapMode aDrawMode = pViewData->GetLogicMode();
257 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
258 if ( pDrView || bForce )
260 Fraction aScaleX;
261 Fraction aScaleY;
262 if (pDrView)
263 pDrView->GetScale( aScaleX, aScaleY );
264 else
266 SCCOL nEndCol = 0;
267 SCROW nEndRow = 0;
268 pDoc->GetTableArea( nTab, nEndCol, nEndRow );
269 if (nEndCol<20) nEndCol = 20;
270 if (nEndRow<20) nEndRow = 20;
271 ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
272 pViewData->GetZoomX(),pViewData->GetZoomY(),
273 pViewData->GetPPTX(),pViewData->GetPPTY(),
274 aScaleX,aScaleY );
276 aDrawMode.SetScaleX(aScaleX);
277 aDrawMode.SetScaleY(aScaleY);
279 aDrawMode.SetOrigin(Point());
280 Point aStartPos = pViewData->GetPixPos(eWhich);
281 if ( bNegativePage )
283 // RTL uses negative positions for drawing objects
284 aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
286 aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
288 return aDrawMode;
291 //BOOL ScGridWindow::DrawBeforeScroll()
293 // ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
295 // BOOL bXor = FALSE;
296 // if (pDrView)
297 // {
298 // bXor=pDrView->IsShownXorVisible(this);
299 // if (bXor) pDrView->HideShownXor(this);
300 // }
301 // return bXor;
304 void ScGridWindow::DrawAfterScroll(/*BOOL bVal*/)
306 Update(); // immer, damit das Verhalten mit/ohne DrawingLayer gleich ist
308 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
309 if (pDrView)
311 //if (bVal)
312 // pDrView->ShowShownXor(this);
314 OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
315 if (pOlView && pOlView->GetWindow() == this)
316 pOlView->ShowCursor(FALSE); // ist beim Scrollen weggekommen
320 //void ScGridWindow::DrawMarks()
322 // ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
323 // if (pDrView)
324 // pDrView->DrawMarks(this);
327 //BOOL ScGridWindow::NeedDrawMarks()
329 // ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
330 // return pDrView && pDrView->IsMarkHdlShown() && pDrView->AreObjectsMarked();
333 void ScGridWindow::CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress)
335 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
336 if (pDrView)
338 const ScViewOptions& rOpts = pViewData->GetOptions();
339 if(rOpts.GetOption( VOPT_ANCHOR ))
341 BOOL bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
342 Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, TRUE );
343 aPos = PixelToLogic(aPos);
344 rHdl.AddHdl(new SdrHdl(aPos, bNegativePage ? HDL_ANCHOR_TR : HDL_ANCHOR));
349 SdrObject* ScGridWindow::GetEditObject()
351 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
352 if (pDrView)
354 OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
355 if (pOlView && pOlView->GetWindow() == this)
356 return pDrView->GetTextEditObject();
359 return NULL;
362 void ScGridWindow::UpdateStatusPosSize()
364 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
365 if (!pDrView)
366 return; // shouldn't be called in that case
368 SdrPageView* pPV = pDrView->GetSdrPageView();
369 if (!pPV)
370 return; // shouldn't be called in that case either
372 SfxItemSet aSet(pViewData->GetViewShell()->GetPool(), SID_ATTR_POSITION, SID_ATTR_SIZE);
374 // Fill items for position and size:
375 // #108137# show action rectangle during action,
376 // position and size of selected object(s) if something is selected,
377 // mouse position otherwise
379 BOOL bActionItem = FALSE;
380 if ( pDrView->IsAction() ) // action rectangle
382 Rectangle aRect;
383 pDrView->TakeActionRect( aRect );
384 if ( !aRect.IsEmpty() )
386 pPV->LogicToPagePos(aRect);
387 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
388 aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
389 Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
390 bActionItem = TRUE;
393 if ( !bActionItem )
395 if ( pDrView->AreObjectsMarked() ) // selected objects
397 Rectangle aRect = pDrView->GetAllMarkedRect();
398 pPV->LogicToPagePos(aRect);
399 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
400 aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
401 Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
403 else // mouse position
405 Point aPos = PixelToLogic(aCurMousePos);
406 pPV->LogicToPagePos(aPos);
407 aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
408 aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
412 pViewData->GetBindings().SetState(aSet);
415 BOOL ScGridWindow::DrawHasMarkedObj()
417 ScDrawView* p = pViewData->GetScDrawView();
418 return p ? p->AreObjectsMarked() : FALSE;
421 //void ScGridWindow::DrawStartTimer()
423 //ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
424 //if (pDrView)
426 /* jetzt in DrawMarks
427 USHORT nWinNum = pDrView->FindWin(this);
428 if (nWinNum!=SDRVIEWWIN_NOTFOUND)
429 pDrView->AfterInitRedraw(nWinNum);
432 // pDrView->PostPaint();
433 // pDrView->RestartAfterPaintTimer();
437 void ScGridWindow::DrawMarkDropObj( SdrObject* pObj )
439 ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
440 if (pDrView)
441 pDrView->MarkDropObj(pObj);