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