xref: /AOO41X/main/sc/source/ui/view/gridwin3.cxx (revision 747164b07d386e56c7c70a1509f0411e0c0b4d3b)
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 
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 
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 
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 
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 
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 
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 //IAccessibility2 Implementation 2009-----
183                     if(bOldMarked)
184                         GetFocus();
185 //-----IAccessibility2 Implementation 2009
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