xref: /aoo41x/main/sc/source/ui/view/gridwin3.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include "scitems.hxx"
32 #include <editeng/eeitem.hxx>
33 
34 #include <svx/svdoutl.hxx>
35 #include <svx/svdotext.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <editeng/sizeitem.hxx>
38 #include <sfx2/bindings.hxx>
39 #include <svl/ptitem.hxx>
40 
41 #include "tabvwsh.hxx"
42 #include "gridwin.hxx"
43 #include "dbfunc.hxx"
44 #include "viewdata.hxx"
45 #include "output.hxx"
46 #include "drawview.hxx"
47 #include "fupoor.hxx"
48 
49 #include "drawutil.hxx"
50 #include "document.hxx"
51 #include "drwlayer.hxx"
52 #include <vcl/svapp.hxx>
53 
54 // -----------------------------------------------------------------------
55 
56 sal_Bool ScGridWindow::DrawMouseButtonDown(const MouseEvent& rMEvt)
57 {
58 	sal_Bool bRet = sal_False;
59 	FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
60 	if (pDraw && !pViewData->IsRefMode())
61 	{
62 		pDraw->SetWindow( this );
63 		Point aLogicPos = PixelToLogic(rMEvt.GetPosPixel());
64 		if ( pDraw->IsDetectiveHit( aLogicPos ) )
65 		{
66 			//	auf Detektiv-Pfeilen gar nichts (Doppelklick wird bei ButtonUp ausgewertet)
67 			bRet = sal_True;
68 		}
69 		else
70 		{
71 			bRet = pDraw->MouseButtonDown( rMEvt );
72 			if ( bRet )
73 				UpdateStatusPosSize();
74 		}
75 	}
76 
77 	//	bei rechter Taste Draw-Aktion abbrechen
78 
79 	ScDrawView* pDrView = pViewData->GetScDrawView();
80 	if ( pDrView && !rMEvt.IsLeft() && !bRet )
81 	{
82 		pDrView->BrkAction();
83 		bRet = sal_True;
84 	}
85 	return bRet;
86 }
87 
88 sal_Bool ScGridWindow::DrawMouseButtonUp(const MouseEvent& rMEvt)
89 {
90     ScViewFunc* pView = pViewData->GetView();
91 	sal_Bool bRet = sal_False;
92 	FuPoor* pDraw = pView->GetDrawFuncPtr();
93 	if (pDraw && !pViewData->IsRefMode())
94 	{
95 		pDraw->SetWindow( this );
96 		bRet = pDraw->MouseButtonUp( rMEvt );
97 
98         // execute "format paint brush" for drawing objects
99         SfxItemSet* pDrawBrush = pView->GetDrawBrushSet();
100         if ( pDrawBrush )
101         {
102             ScDrawView* pDrView = pViewData->GetScDrawView();
103             if ( pDrView )
104             {
105                 sal_Bool bReplaceAll = sal_True;
106 	            pDrView->SetAttrToMarked(*pDrawBrush, bReplaceAll);
107             }
108 
109             if ( !pView->IsPaintBrushLocked() )
110                 pView->ResetBrushDocument();        // end paint brush mode if not locked
111         }
112 	}
113 
114 	return bRet;
115 }
116 
117 sal_Bool ScGridWindow::DrawMouseMove(const MouseEvent& rMEvt)
118 {
119 	FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
120 	if (pDraw && !pViewData->IsRefMode())
121 	{
122 		pDraw->SetWindow( this );
123 		sal_Bool bRet = pDraw->MouseMove( rMEvt );
124 		if ( bRet )
125 			UpdateStatusPosSize();
126 		return bRet;
127 	}
128 	else
129 	{
130 		SetPointer( Pointer( POINTER_ARROW ) );
131 		return sal_False;
132 	}
133 }
134 
135 void ScGridWindow::DrawEndAction()
136 {
137 	ScDrawView* pDrView = pViewData->GetScDrawView();
138 	if ( pDrView && pDrView->IsAction() )
139 		pDrView->BrkAction();
140 
141 	FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
142 	if (pDraw)
143 		pDraw->StopDragTimer();
144 
145 	//	ReleaseMouse beim Aufruf
146 }
147 
148 sal_Bool ScGridWindow::DrawCommand(const CommandEvent& rCEvt)
149 {
150 	ScDrawView* pDrView = pViewData->GetScDrawView();
151 	FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
152 	if (pDrView && pDraw && !pViewData->IsRefMode())
153 	{
154 		pDraw->SetWindow( this );
155 		sal_uInt8 nUsed = pDraw->Command( rCEvt );
156 		if( nUsed == SC_CMD_USED )
157 			nButtonDown = 0;					// MouseButtonUp wird verschluckt...
158 		if( nUsed || pDrView->IsAction() )
159 			return sal_True;
160 	}
161 
162 	return sal_False;
163 }
164 
165 sal_Bool ScGridWindow::DrawKeyInput(const KeyEvent& rKEvt)
166 {
167 	ScDrawView* pDrView = pViewData->GetScDrawView();
168 	FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
169 	if (pDrView && pDraw && !pViewData->IsRefMode())
170 	{
171 		pDraw->SetWindow( this );
172 		sal_Bool bOldMarked = pDrView->AreObjectsMarked();
173 		if (pDraw->KeyInput( rKEvt ))
174 		{
175 			sal_Bool bLeaveDraw = sal_False;
176 			sal_Bool bUsed = sal_True;
177 			sal_Bool bNewMarked = pDrView->AreObjectsMarked();
178 			if ( !pViewData->GetView()->IsDrawSelMode() )
179 				if ( !bNewMarked )
180 				{
181 					pViewData->GetViewShell()->SetDrawShell( sal_False );
182 					bLeaveDraw = sal_True;
183 					if ( !bOldMarked &&
184 						rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
185 						bUsed = sal_False;					// nichts geloescht
186 				}
187 			if (!bLeaveDraw)
188 				UpdateStatusPosSize();		// #108137# for moving/resizing etc. by keyboard
189 			return bUsed;
190 		}
191 	}
192 
193 	return sal_False;
194 }
195 
196 void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer )
197 {
198 	// #109985#
199 	const ScViewOptions& rOpts = pViewData->GetOptions();
200 
201     // use new flags at SdrPaintView for hiding objects
202     const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
203     const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
204     const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
205 
206     if(bDrawOle || bDrawChart || bDrawDraw)
207     {
208         ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
209 
210         if(pDrView)
211         {
212             pDrView->setHideOle(!bDrawOle);
213             pDrView->setHideChart(!bDrawChart);
214             pDrView->setHideDraw(!bDrawDraw);
215             pDrView->setHideFormControl(!bDrawDraw);
216         }
217 
218 		if(SC_UPDATE_CHANGED == eMode)
219 		{
220 			rOutputData.DrawingSingle((sal_uInt16)nLayer);
221 		}
222 		else
223 		{
224 			rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
225 		}
226     }
227 }
228 
229 void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
230 {
231 	//	Draw-Gitterlinien
232 
233 	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
234 	if ( pDrView && pDrView->IsGridVisible() )
235 	{
236 		SdrPageView* pPV = pDrView->GetSdrPageView();
237 		DBG_ASSERT(pPV, "keine PageView");
238 		if (pPV)
239 		{
240             pContentDev->SetLineColor(COL_GRAY);
241 
242             pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
243 		}
244 	}
245 }
246 
247 MapMode ScGridWindow::GetDrawMapMode( sal_Bool bForce )
248 {
249 	ScDocument* pDoc = pViewData->GetDocument();
250     SCTAB nTab = pViewData->GetTabNo();
251 	sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
252 
253 	MapMode aDrawMode = pViewData->GetLogicMode();
254 
255 	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
256 	if ( pDrView || bForce )
257 	{
258 		Fraction aScaleX;
259 		Fraction aScaleY;
260 		if (pDrView)
261 			pDrView->GetScale( aScaleX, aScaleY );
262 		else
263 		{
264 			SCCOL nEndCol = 0;
265 			SCROW nEndRow = 0;
266 			pDoc->GetTableArea( nTab, nEndCol, nEndRow );
267 			if (nEndCol<20) nEndCol = 20;
268             if (nEndRow<20) nEndRow = 20;
269 			ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
270 									pViewData->GetZoomX(),pViewData->GetZoomY(),
271 									pViewData->GetPPTX(),pViewData->GetPPTY(),
272 									aScaleX,aScaleY );
273 		}
274 		aDrawMode.SetScaleX(aScaleX);
275 		aDrawMode.SetScaleY(aScaleY);
276 	}
277 	aDrawMode.SetOrigin(Point());
278 	Point aStartPos = pViewData->GetPixPos(eWhich);
279 	if ( bNegativePage )
280 	{
281 		//	RTL uses negative positions for drawing objects
282 		aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
283 	}
284 	aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
285 
286 	return aDrawMode;
287 }
288 
289 //sal_Bool ScGridWindow::DrawBeforeScroll()
290 //{
291 //	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
292 //
293 //	sal_Bool bXor = sal_False;
294 //	if (pDrView)
295 //	{
296 //	    bXor=pDrView->IsShownXorVisible(this);
297 //	    if (bXor) pDrView->HideShownXor(this);
298 //	}
299 //	return bXor;
300 //}
301 
302 void ScGridWindow::DrawAfterScroll(/*sal_Bool bVal*/)
303 {
304 	Update();		// immer, damit das Verhalten mit/ohne DrawingLayer gleich ist
305 
306 	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
307 	if (pDrView)
308 	{
309 	    //if (bVal)
310     	//	pDrView->ShowShownXor(this);
311 
312 		OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
313 		if (pOlView && pOlView->GetWindow() == this)
314 			pOlView->ShowCursor(sal_False);					// ist beim Scrollen weggekommen
315     }
316 }
317 
318 //void ScGridWindow::DrawMarks()
319 //{
320 //	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
321 //	if (pDrView)
322 //		pDrView->DrawMarks(this);
323 //}
324 
325 //sal_Bool ScGridWindow::NeedDrawMarks()
326 //{
327 //	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
328 //	return pDrView && pDrView->IsMarkHdlShown() && pDrView->AreObjectsMarked();
329 //}
330 
331 void ScGridWindow::CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress)
332 {
333 	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
334 	if (pDrView)
335 	{
336 		const ScViewOptions& rOpts = pViewData->GetOptions();
337 		if(rOpts.GetOption( VOPT_ANCHOR ))
338 		{
339 			sal_Bool bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
340 			Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, sal_True );
341 			aPos = PixelToLogic(aPos);
342 			rHdl.AddHdl(new SdrHdl(aPos, bNegativePage ? HDL_ANCHOR_TR : HDL_ANCHOR));
343 		}
344 	}
345 }
346 
347 SdrObject* ScGridWindow::GetEditObject()
348 {
349 	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
350 	if (pDrView)
351 	{
352 		OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
353 		if (pOlView && pOlView->GetWindow() == this)
354 			return pDrView->GetTextEditObject();
355 	}
356 
357 	return NULL;
358 }
359 
360 void ScGridWindow::UpdateStatusPosSize()
361 {
362 	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
363 	if (!pDrView)
364 		return;			// shouldn't be called in that case
365 
366     SdrPageView* pPV = pDrView->GetSdrPageView();
367     if (!pPV)
368         return;         // shouldn't be called in that case either
369 
370 	SfxItemSet aSet(pViewData->GetViewShell()->GetPool(), SID_ATTR_POSITION, SID_ATTR_SIZE);
371 
372 	//	Fill items for position and size:
373 	//	#108137# show action rectangle during action,
374 	//	position and size of selected object(s) if something is selected,
375 	//	mouse position otherwise
376 
377 	sal_Bool bActionItem = sal_False;
378 	if ( pDrView->IsAction() )				// action rectangle
379 	{
380 		Rectangle aRect;
381 		pDrView->TakeActionRect( aRect );
382 		if ( !aRect.IsEmpty() )
383 		{
384 			pPV->LogicToPagePos(aRect);
385 			aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
386 			aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
387 					Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
388 			bActionItem = sal_True;
389 		}
390 	}
391 	if ( !bActionItem )
392 	{
393 		if ( pDrView->AreObjectsMarked() )		// selected objects
394 		{
395 			Rectangle aRect = pDrView->GetAllMarkedRect();
396 			pPV->LogicToPagePos(aRect);
397 			aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
398 			aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
399 					Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
400 		}
401 		else								// mouse position
402 		{
403 			Point aPos = PixelToLogic(aCurMousePos);
404 			pPV->LogicToPagePos(aPos);
405 			aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
406 			aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
407 		}
408 	}
409 
410 	pViewData->GetBindings().SetState(aSet);
411 }
412 
413 sal_Bool ScGridWindow::DrawHasMarkedObj()
414 {
415 	ScDrawView* p = pViewData->GetScDrawView();
416 	return p ? p->AreObjectsMarked() : sal_False;
417 }
418 
419 //void ScGridWindow::DrawStartTimer()
420 //{
421 	//ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
422 	//if (pDrView)
423 	//{
424 		/* jetzt in DrawMarks
425 		sal_uInt16 nWinNum = pDrView->FindWin(this);
426 	    if (nWinNum!=SDRVIEWWIN_NOTFOUND)
427 	        pDrView->AfterInitRedraw(nWinNum);
428         */
429 
430 		// pDrView->PostPaint();
431 		// pDrView->RestartAfterPaintTimer();
432 	//}
433 //}
434 
435 void ScGridWindow::DrawMarkDropObj( SdrObject* pObj )
436 {
437 	ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
438 	if (pDrView)
439 		pDrView->MarkDropObj(pObj);
440 }
441 
442 
443 
444