xref: /AOO41X/main/sc/source/ui/view/gridwin3.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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                 }
183             if (!bLeaveDraw)
184                 UpdateStatusPosSize();      // #108137# for moving/resizing etc. by keyboard
185             return bUsed;
186         }
187     }
188 
189     return sal_False;
190 }
191 
192 void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer )
193 {
194     // #109985#
195     const ScViewOptions& rOpts = pViewData->GetOptions();
196 
197     // use new flags at SdrPaintView for hiding objects
198     const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
199     const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
200     const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
201 
202     if(bDrawOle || bDrawChart || bDrawDraw)
203     {
204         ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
205 
206         if(pDrView)
207         {
208             pDrView->setHideOle(!bDrawOle);
209             pDrView->setHideChart(!bDrawChart);
210             pDrView->setHideDraw(!bDrawDraw);
211             pDrView->setHideFormControl(!bDrawDraw);
212         }
213 
214         if(SC_UPDATE_CHANGED == eMode)
215         {
216             rOutputData.DrawingSingle((sal_uInt16)nLayer);
217         }
218         else
219         {
220             rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
221         }
222     }
223 }
224 
225 void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
226 {
227     //  Draw-Gitterlinien
228 
229     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
230     if ( pDrView && pDrView->IsGridVisible() )
231     {
232         SdrPageView* pPV = pDrView->GetSdrPageView();
233         DBG_ASSERT(pPV, "keine PageView");
234         if (pPV)
235         {
236             pContentDev->SetLineColor(COL_GRAY);
237 
238             pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
239         }
240     }
241 }
242 
243 MapMode ScGridWindow::GetDrawMapMode( sal_Bool bForce )
244 {
245     ScDocument* pDoc = pViewData->GetDocument();
246     SCTAB nTab = pViewData->GetTabNo();
247     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
248 
249     MapMode aDrawMode = pViewData->GetLogicMode();
250 
251     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
252     if ( pDrView || bForce )
253     {
254         Fraction aScaleX;
255         Fraction aScaleY;
256         if (pDrView)
257             pDrView->GetScale( aScaleX, aScaleY );
258         else
259         {
260             SCCOL nEndCol = 0;
261             SCROW nEndRow = 0;
262             pDoc->GetTableArea( nTab, nEndCol, nEndRow );
263             if (nEndCol<20) nEndCol = 20;
264             if (nEndRow<20) nEndRow = 20;
265             ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
266                                     pViewData->GetZoomX(),pViewData->GetZoomY(),
267                                     pViewData->GetPPTX(),pViewData->GetPPTY(),
268                                     aScaleX,aScaleY );
269         }
270         aDrawMode.SetScaleX(aScaleX);
271         aDrawMode.SetScaleY(aScaleY);
272     }
273     aDrawMode.SetOrigin(Point());
274     Point aStartPos = pViewData->GetPixPos(eWhich);
275     if ( bNegativePage )
276     {
277         //  RTL uses negative positions for drawing objects
278         aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
279     }
280     aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
281 
282     return aDrawMode;
283 }
284 
285 //sal_Bool ScGridWindow::DrawBeforeScroll()
286 //{
287 //  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
288 //
289 //  sal_Bool bXor = sal_False;
290 //  if (pDrView)
291 //  {
292 //      bXor=pDrView->IsShownXorVisible(this);
293 //      if (bXor) pDrView->HideShownXor(this);
294 //  }
295 //  return bXor;
296 //}
297 
298 void ScGridWindow::DrawAfterScroll(/*sal_Bool bVal*/)
299 {
300     Update();       // immer, damit das Verhalten mit/ohne DrawingLayer gleich ist
301 
302     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
303     if (pDrView)
304     {
305         //if (bVal)
306         //  pDrView->ShowShownXor(this);
307 
308         OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
309         if (pOlView && pOlView->GetWindow() == this)
310             pOlView->ShowCursor(sal_False);                 // ist beim Scrollen weggekommen
311     }
312 }
313 
314 //void ScGridWindow::DrawMarks()
315 //{
316 //  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
317 //  if (pDrView)
318 //      pDrView->DrawMarks(this);
319 //}
320 
321 //sal_Bool ScGridWindow::NeedDrawMarks()
322 //{
323 //  ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
324 //  return pDrView && pDrView->IsMarkHdlShown() && pDrView->AreObjectsMarked();
325 //}
326 
327 void ScGridWindow::CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress)
328 {
329     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
330     if (pDrView)
331     {
332         const ScViewOptions& rOpts = pViewData->GetOptions();
333         if(rOpts.GetOption( VOPT_ANCHOR ))
334         {
335             sal_Bool bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
336             Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, sal_True );
337             aPos = PixelToLogic(aPos);
338             rHdl.AddHdl(new SdrHdl(aPos, bNegativePage ? HDL_ANCHOR_TR : HDL_ANCHOR));
339         }
340     }
341 }
342 
343 SdrObject* ScGridWindow::GetEditObject()
344 {
345     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
346     if (pDrView)
347     {
348         OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
349         if (pOlView && pOlView->GetWindow() == this)
350             return pDrView->GetTextEditObject();
351     }
352 
353     return NULL;
354 }
355 
356 void ScGridWindow::UpdateStatusPosSize()
357 {
358     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
359     if (!pDrView)
360         return;         // shouldn't be called in that case
361 
362     SdrPageView* pPV = pDrView->GetSdrPageView();
363     if (!pPV)
364         return;         // shouldn't be called in that case either
365 
366     SfxItemSet aSet(pViewData->GetViewShell()->GetPool(), SID_ATTR_POSITION, SID_ATTR_SIZE);
367 
368     //  Fill items for position and size:
369     //  #108137# show action rectangle during action,
370     //  position and size of selected object(s) if something is selected,
371     //  mouse position otherwise
372 
373     sal_Bool bActionItem = sal_False;
374     if ( pDrView->IsAction() )              // action rectangle
375     {
376         Rectangle aRect;
377         pDrView->TakeActionRect( aRect );
378         if ( !aRect.IsEmpty() )
379         {
380             pPV->LogicToPagePos(aRect);
381             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
382             aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
383                     Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
384             bActionItem = sal_True;
385         }
386     }
387     if ( !bActionItem )
388     {
389         if ( pDrView->AreObjectsMarked() )      // selected objects
390         {
391             Rectangle aRect = pDrView->GetAllMarkedRect();
392             pPV->LogicToPagePos(aRect);
393             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
394             aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
395                     Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
396         }
397         else                                // mouse position
398         {
399             Point aPos = PixelToLogic(aCurMousePos);
400             pPV->LogicToPagePos(aPos);
401             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
402             aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
403         }
404     }
405 
406     pViewData->GetBindings().SetState(aSet);
407 }
408 
409 sal_Bool ScGridWindow::DrawHasMarkedObj()
410 {
411     ScDrawView* p = pViewData->GetScDrawView();
412     return p ? p->AreObjectsMarked() : sal_False;
413 }
414 
415 //void ScGridWindow::DrawStartTimer()
416 //{
417     //ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
418     //if (pDrView)
419     //{
420         /* jetzt in DrawMarks
421         sal_uInt16 nWinNum = pDrView->FindWin(this);
422         if (nWinNum!=SDRVIEWWIN_NOTFOUND)
423             pDrView->AfterInitRedraw(nWinNum);
424         */
425 
426         // pDrView->PostPaint();
427         // pDrView->RestartAfterPaintTimer();
428     //}
429 //}
430 
431 void ScGridWindow::DrawMarkDropObj( SdrObject* pObj )
432 {
433     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
434     if (pDrView)
435         pDrView->MarkDropObj(pObj);
436 }
437 
438 
439 
440