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"
47 #include "viewdata.hxx"
49 #include "drawview.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
)
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)
74 bRet
= pDraw
->MouseButtonDown( rMEvt
);
76 UpdateStatusPosSize();
80 // bei rechter Taste Draw-Aktion abbrechen
82 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
83 if ( pDrView
&& !rMEvt
.IsLeft() && !bRet
)
91 BOOL
ScGridWindow::DrawMouseButtonUp(const MouseEvent
& rMEvt
)
93 ScViewFunc
* pView
= pViewData
->GetView();
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();
105 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
108 BOOL bReplaceAll
= TRUE
;
109 pDrView
->SetAttrToMarked(*pDrawBrush
, bReplaceAll
);
112 if ( !pView
->IsPaintBrushLocked() )
113 pView
->ResetBrushDocument(); // end paint brush mode if not locked
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
);
128 UpdateStatusPosSize();
133 SetPointer( Pointer( POINTER_ARROW
) );
138 void ScGridWindow::DrawEndAction()
140 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
141 if ( pDrView
&& pDrView
->IsAction() )
142 pDrView
->BrkAction();
144 FuPoor
* pDraw
= pViewData
->GetView()->GetDrawFuncPtr();
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() )
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
;
180 BOOL bNewMarked
= pDrView
->AreObjectsMarked();
181 if ( !pViewData
->GetView()->IsDrawSelMode() )
184 pViewData
->GetViewShell()->SetDrawShell( FALSE
);
187 rKEvt
.GetKeyCode().GetCode() == KEY_DELETE
)
188 bUsed
= FALSE
; // nichts geloescht
191 UpdateStatusPosSize(); // #108137# for moving/resizing etc. by keyboard
199 void ScGridWindow::DrawRedraw( ScOutputData
& rOutputData
, ScUpdateMode eMode
, ULONG nLayer
)
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();
215 pDrView
->setHideOle(!bDrawOle
);
216 pDrView
->setHideChart(!bDrawChart
);
217 pDrView
->setHideDraw(!bDrawDraw
);
220 if(SC_UPDATE_CHANGED
== eMode
)
222 rOutputData
.DrawingSingle((sal_uInt16
)nLayer
);
226 rOutputData
.DrawSelectiveObjects((sal_uInt16
)nLayer
);
231 void ScGridWindow::DrawSdrGrid( const Rectangle
& rDrawingRect
, OutputDevice
* pContentDev
)
235 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
236 if ( pDrView
&& pDrView
->IsGridVisible() )
238 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
239 DBG_ASSERT(pPV
, "keine PageView");
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
)
263 pDrView
->GetScale( aScaleX
, aScaleY
);
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(),
276 aDrawMode
.SetScaleX(aScaleX
);
277 aDrawMode
.SetScaleY(aScaleY
);
279 aDrawMode
.SetOrigin(Point());
280 Point aStartPos
= pViewData
->GetPixPos(eWhich
);
283 // RTL uses negative positions for drawing objects
284 aStartPos
.X() = -aStartPos
.X() + GetOutputSizePixel().Width() - 1;
286 aDrawMode
.SetOrigin( PixelToLogic( aStartPos
, aDrawMode
) );
291 //BOOL ScGridWindow::DrawBeforeScroll()
293 // ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
295 // BOOL bXor = FALSE;
298 // bXor=pDrView->IsShownXorVisible(this);
299 // if (bXor) pDrView->HideShownXor(this);
304 void ScGridWindow::DrawAfterScroll(/*BOOL bVal*/)
306 Update(); // immer, damit das Verhalten mit/ohne DrawingLayer gleich ist
308 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
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();
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();
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();
354 OutlinerView
* pOlView
= pDrView
->GetTextEditOutlinerView();
355 if (pOlView
&& pOlView
->GetWindow() == this)
356 return pDrView
->GetTextEditObject();
362 void ScGridWindow::UpdateStatusPosSize()
364 ScDrawView
* pDrView
= pViewData
->GetView()->GetScDrawView();
366 return; // shouldn't be called in that case
368 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
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
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() ) ) );
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();
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();
441 pDrView
->MarkDropObj(pObj
);