xref: /AOO41X/main/sc/source/ui/view/drawview.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 ---------------------------------------------------------------
28 
29 #include <com/sun/star/embed/EmbedStates.hpp>
30 
31 #include <svx/svditer.hxx>
32 #include <svx/svdograf.hxx>
33 #include <svx/svdomedia.hxx>
34 #include <svx/svdogrp.hxx>
35 #include <svx/svdoole2.hxx>
36 #include <svx/svdouno.hxx>
37 #include <svx/svdpage.hxx>
38 #include <svx/svdundo.hxx>
39 #include <svx/svdocapt.hxx>
40 #include <editeng/outlobj.hxx>
41 #include <editeng/writingmodeitem.hxx>
42 #include <svx/sdrpaintwindow.hxx>
43 #include <sfx2/bindings.hxx>
44 #include <sfx2/viewfrm.hxx>
45 
46 #include "drawview.hxx"
47 #include "global.hxx"
48 #include "viewdata.hxx"
49 #include "document.hxx"
50 #include "drawutil.hxx"
51 #include "futext.hxx"
52 #include "globstr.hrc"
53 #include "tabvwsh.hxx"
54 #include "client.hxx"
55 #include "scmod.hxx"
56 #include "drwlayer.hxx"
57 #include "docsh.hxx"
58 #include "viewuno.hxx"
59 #include "userdat.hxx"
60 #include "postit.hxx"
61 #include "undocell.hxx"
62 
63 #include "sc.hrc"
64 
65 using namespace com::sun::star;
66 
67 // -----------------------------------------------------------------------
68 
69 #define SC_HANDLESIZE_BIG       9
70 #define SC_HANDLESIZE_SMALL     7
71 
72 // -----------------------------------------------------------------------
73 
74 #ifdef _MSC_VER
75 #pragma optimize ( "", off )
76 #endif
77 
78 
79 void ScDrawView::Construct()
80 {
81     EnableExtendedKeyInputDispatcher(sal_False);
82     EnableExtendedMouseEventDispatcher(sal_False);
83     EnableExtendedCommandEventDispatcher(sal_False);
84 
85     SetFrameDragSingles(sal_True);
86 //  SetSolidMarkHdl(sal_True);              // einstellbar -> UpdateUserViewOptions
87 
88     SetMinMoveDistancePixel( 2 );
89     SetHitTolerancePixel( 2 );
90 
91     if (pViewData)
92     {
93         SCTAB nViewTab = pViewData->GetTabNo();
94         ShowSdrPage(GetModel()->GetPage(nViewTab));
95 
96         sal_Bool bEx = pViewData->GetViewShell()->IsDrawSelMode();
97         sal_Bool bProt = pDoc->IsTabProtected( nViewTab ) ||
98                      pViewData->GetSfxDocShell()->IsReadOnly();
99 
100         SdrLayer* pLayer;
101         SdrLayerAdmin& rAdmin = GetModel()->GetLayerAdmin();
102         pLayer = rAdmin.GetLayerPerID(SC_LAYER_BACK);
103         if (pLayer)
104             SetLayerLocked( pLayer->GetName(), bProt || !bEx );
105         pLayer = rAdmin.GetLayerPerID(SC_LAYER_INTERN);
106         if (pLayer)
107             SetLayerLocked( pLayer->GetName(), sal_True );
108         pLayer = rAdmin.GetLayerPerID(SC_LAYER_FRONT);
109         if (pLayer)
110         {
111             SetLayerLocked( pLayer->GetName(), bProt );
112             SetActiveLayer( pLayer->GetName() );        // FRONT als aktiven Layer setzen
113         }
114         pLayer = rAdmin.GetLayerPerID(SC_LAYER_CONTROLS);
115         if (pLayer)
116             SetLayerLocked( pLayer->GetName(), bProt );
117         pLayer = rAdmin.GetLayerPerID(SC_LAYER_HIDDEN);
118         if (pLayer)
119         {
120             SetLayerLocked( pLayer->GetName(), bProt );
121             SetLayerVisible( pLayer->GetName(), sal_False);
122         }
123 
124         SetSwapAsynchron(sal_True);
125     }
126     else
127     {
128         ShowSdrPage(GetModel()->GetPage(nTab));
129     }
130 
131     UpdateUserViewOptions();
132     RecalcScale();
133     UpdateWorkArea();
134 
135     bInConstruct = sal_False;
136 }
137 
138 void ScDrawView::ImplClearCalcDropMarker()
139 {
140     if(pDropMarker)
141     {
142         delete pDropMarker;
143         pDropMarker = 0L;
144     }
145 }
146 
147 __EXPORT ScDrawView::~ScDrawView()
148 {
149     ImplClearCalcDropMarker();
150 }
151 
152 void ScDrawView::AddCustomHdl()
153 {
154     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
155 
156     const SdrMarkList &rMrkList = GetMarkedObjectList();
157     sal_uInt32 nCount = rMrkList.GetMarkCount();
158     for(sal_uInt32 nPos=0; nPos<nCount; nPos++ )
159     {
160         const SdrObject* pObj = rMrkList.GetMark(nPos)->GetMarkedSdrObj();
161         if(ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
162         {
163             const sal_Int32 nDelta = 1;
164 
165             Rectangle aBoundRect = pObj->GetCurrentBoundRect();
166             Point aPos;
167             if (bNegativePage)
168             {
169                 aPos = aBoundRect.TopRight();
170                 aPos.X() = -aPos.X();           // so the loop below is the same
171             }
172             else
173                 aPos = aBoundRect.TopLeft();
174             long nPosX = (long) (aPos.X() / HMM_PER_TWIPS) + nDelta;
175             long nPosY = (long) (aPos.Y() / HMM_PER_TWIPS) + nDelta;
176 
177             SCCOL nCol;
178             sal_Int32 nWidth = 0;
179 
180             for(nCol=0; nCol<=MAXCOL && nWidth<=nPosX; nCol++)
181                 nWidth += pDoc->GetColWidth(nCol,nTab);
182 
183             if(nCol > 0)
184                 --nCol;
185 
186             SCROW nRow = nPosY <= 0 ? 0 : pDoc->GetRowForHeight( nTab,
187                     (sal_uLong) nPosY);
188             if(nRow > 0)
189                 --nRow;
190 
191             ScTabView* pView = pViewData->GetView();
192             ScAddress aScAddress(nCol, nRow, nTab);
193             pView->CreateAnchorHandles(aHdl, aScAddress);
194         }
195     }
196 }
197 
198 void ScDrawView::InvalidateAttribs()
199 {
200     if (!pViewData) return;
201     SfxBindings& rBindings = pViewData->GetBindings();
202 
203         // echte Statuswerte:
204     rBindings.InvalidateAll( sal_True );
205 }
206 
207 void ScDrawView::InvalidateDrawTextAttrs()
208 {
209     if (!pViewData) return;
210     SfxBindings& rBindings = pViewData->GetBindings();
211 
212     //  cjk/ctl font items have no configured slots,
213     //  need no invalidate
214 
215     rBindings.Invalidate( SID_ATTR_CHAR_FONT );
216     rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
217     rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
218     rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
219     rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
220     rBindings.Invalidate( SID_ULINE_VAL_NONE );
221     rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
222     rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
223     rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
224     rBindings.Invalidate( SID_ATTR_CHAR_OVERLINE );
225     rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
226     rBindings.Invalidate( SID_ALIGNLEFT );
227     rBindings.Invalidate( SID_ALIGNCENTERHOR );
228     rBindings.Invalidate( SID_ALIGNRIGHT );
229     rBindings.Invalidate( SID_ALIGNBLOCK );
230     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_10 );
231     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_15 );
232     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_20 );
233     rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
234     rBindings.Invalidate( SID_SET_SUB_SCRIPT );
235     rBindings.Invalidate( SID_TEXTDIRECTION_LEFT_TO_RIGHT );
236     rBindings.Invalidate( SID_TEXTDIRECTION_TOP_TO_BOTTOM );
237     rBindings.Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
238     rBindings.Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
239     // pseudo slots for Format menu
240     rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
241     rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
242     rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
243     rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
244 }
245 
246 //void ScDrawView::DrawMarks( OutputDevice* pOut ) const
247 //{
248 //  DBG_ASSERT(pOut, "ScDrawView::DrawMarks: No OutputDevice (!)");
249 //  SdrPaintWindow* pPaintWindow = FindPaintWindow(*pOut);
250 //
251 //  if(pPaintWindow)
252 //  {
253 //      if(pPaintWindow->isXorVisible())
254 //      {
255 //          ToggleShownXor(pOut, 0L);
256 //      }
257 //  }
258 //}
259 
260 void ScDrawView::SetMarkedToLayer( sal_uInt8 nLayerNo )
261 {
262     if (AreObjectsMarked())
263     {
264         //  #i11702# use SdrUndoObjectLayerChange for undo
265         //  STR_UNDO_SELATTR is "Attributes" - should use a different text later
266         BegUndo( ScGlobal::GetRscString( STR_UNDO_SELATTR ) );
267 
268         const SdrMarkList& rMark = GetMarkedObjectList();
269         sal_uLong nCount = rMark.GetMarkCount();
270         for (sal_uLong i=0; i<nCount; i++)
271         {
272             SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
273             if ( !pObj->ISA(SdrUnoObj) && (pObj->GetLayer() != SC_LAYER_INTERN) )
274             {
275                 AddUndo( new SdrUndoObjectLayerChange( *pObj, pObj->GetLayer(), (SdrLayerID)nLayerNo) );
276                 pObj->SetLayer( nLayerNo );
277             }
278         }
279 
280         EndUndo();
281 
282         //  repaint is done in SetLayer
283 
284         pViewData->GetDocShell()->SetDrawModified();
285 
286         //  #84073# check mark list now instead of later in a timer
287         CheckMarked();
288         MarkListHasChanged();
289     }
290 }
291 
292 bool ScDrawView::HasMarkedControl() const
293 {
294     SdrObjListIter aIter( GetMarkedObjectList() );
295     for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
296         if( pObj->ISA( SdrUnoObj ) )
297             return true;
298     return false;
299 }
300 
301 bool ScDrawView::HasMarkedInternal() const
302 {
303     // internal objects should not be inside a group, but who knows...
304     SdrObjListIter aIter( GetMarkedObjectList() );
305     for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
306         if( pObj->GetLayer() == SC_LAYER_INTERN )
307             return true;
308     return false;
309 }
310 
311 void ScDrawView::UpdateWorkArea()
312 {
313     SdrPage* pPage = GetModel()->GetPage(static_cast<sal_uInt16>(nTab));
314     if (pPage)
315     {
316         Point aPos;
317         Size aPageSize( pPage->GetSize() );
318         Rectangle aNewArea( aPos, aPageSize );
319         if ( aPageSize.Width() < 0 )
320         {
321             //  RTL: from max.negative (left) to zero (right)
322             aNewArea.Right() = 0;
323             aNewArea.Left() = aPageSize.Width() + 1;
324         }
325         SetWorkArea( aNewArea );
326     }
327     else
328     {
329         DBG_ERROR("Page nicht gefunden");
330     }
331 }
332 
333 void ScDrawView::DoCut()
334 {
335     DoCopy();
336     BegUndo( ScGlobal::GetRscString( STR_UNDO_CUT ) );
337     DeleteMarked();     // auf dieser View - von der 505f Umstellung nicht betroffen
338     EndUndo();
339 }
340 
341 void ScDrawView::GetScale( Fraction& rFractX, Fraction& rFractY ) const
342 {
343     rFractX = aScaleX;
344     rFractY = aScaleY;
345 }
346 
347 void ScDrawView::RecalcScale()
348 {
349     double nPPTX;
350     double nPPTY;
351     Fraction aZoomX(1,1);
352     Fraction aZoomY(1,1);
353 
354     if (pViewData)
355     {
356         nTab = pViewData->GetTabNo();
357         nPPTX = pViewData->GetPPTX();
358         nPPTY = pViewData->GetPPTY();
359         aZoomX = pViewData->GetZoomX();
360         aZoomY = pViewData->GetZoomY();
361     }
362     else
363     {
364         Point aLogic = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
365         nPPTX = aLogic.X() / 1000.0;
366         nPPTY = aLogic.Y() / 1000.0;
367                                             //! Zoom uebergeben ???
368     }
369 
370     SCCOL nEndCol = 0;
371     SCROW nEndRow = 0;
372     pDoc->GetTableArea( nTab, nEndCol, nEndRow );
373     if (nEndCol<20)
374         nEndCol = 20;
375     if (nEndRow<20)
376         nEndRow = 20;   // #i116848# instead of a large row number for an empty sheet, heights are multiplied in CalcScale
377 
378     ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, pDev,aZoomX,aZoomY,nPPTX,nPPTY,
379                             aScaleX,aScaleY );
380 }
381 
382 void ScDrawView::DoConnect(SdrOle2Obj* pOleObj)
383 {
384     if ( pViewData )
385         pViewData->GetViewShell()->ConnectObject( pOleObj );
386 }
387 
388 void ScDrawView::MarkListHasChanged()
389 {
390     FmFormView::MarkListHasChanged();
391 
392     UpdateBrowser();
393 
394     ScTabViewShell* pViewSh = pViewData->GetViewShell();
395 
396     // #i110829# remove the cell selection only if drawing objects are selected
397     if ( !bInConstruct && GetMarkedObjectList().GetMarkCount() )
398     {
399         pViewSh->Unmark();      // remove cell selection
400 
401         //  #65379# end cell edit mode if drawing objects are selected
402         SC_MOD()->InputEnterHandler();
403     }
404 
405     //  IP deaktivieren
406 
407     ScModule* pScMod = SC_MOD();
408     bool bUnoRefDialog = pScMod->IsRefDialogOpen() && pScMod->GetCurRefDlgId() == WID_SIMPLE_REF;
409 
410     ScClient* pClient = (ScClient*) pViewSh->GetIPClient();
411     if ( pClient && pClient->IsObjectInPlaceActive() && !bUnoRefDialog )
412     {
413         //  #41730# beim ViewShell::Activate aus dem Reset2Open nicht die Handles anzeigen
414         //HMHbDisableHdl = sal_True;
415         pClient->DeactivateObject();
416         //HMHbDisableHdl = sal_False;
417         //  Image-Ole wieder durch Grafik ersetzen passiert jetzt in ScClient::UIActivate
418     }
419 
420     //  Ole-Objekt selektiert?
421 
422     SdrOle2Obj* pOle2Obj = NULL;
423     SdrGrafObj* pGrafObj = NULL;
424     SdrMediaObj* pMediaObj = NULL;
425 
426     const SdrMarkList& rMarkList = GetMarkedObjectList();
427     sal_uLong nMarkCount = rMarkList.GetMarkCount();
428 
429     if ( nMarkCount == 0 && !pViewData->GetViewShell()->IsDrawSelMode() && !bInConstruct )
430     {
431         //  relock layers that may have been unlocked before
432         LockBackgroundLayer();
433         LockInternalLayer();
434     }
435 
436     sal_Bool bSubShellSet = sal_False;
437     if (nMarkCount == 1)
438     {
439         SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
440         if (pObj->GetObjIdentifier() == OBJ_OLE2)
441         {
442             pOle2Obj = (SdrOle2Obj*) pObj;
443             if (!pDoc->IsChart(pObj) )
444                 pViewSh->SetOleObjectShell(sal_True);
445             else
446                 pViewSh->SetChartShell(sal_True);
447             bSubShellSet = sal_True;
448         }
449         else if (pObj->GetObjIdentifier() == OBJ_GRAF)
450         {
451             pGrafObj = (SdrGrafObj*) pObj;
452             pViewSh->SetGraphicShell(sal_True);
453             bSubShellSet = sal_True;
454         }
455         else if (pObj->GetObjIdentifier() == OBJ_MEDIA)
456         {
457             pMediaObj = (SdrMediaObj*) pObj;
458             pViewSh->SetMediaShell(sal_True);
459             bSubShellSet = sal_True;
460         }
461         else if (pObj->GetObjIdentifier() != OBJ_TEXT   // Verhindern, das beim Anlegen
462                     || !pViewSh->IsDrawTextShell())     // eines TextObjekts auf die
463         {                                               // DrawShell umgeschaltet wird.
464             pViewSh->SetDrawShell(sal_True);                //@#70206#
465         }
466     }
467 
468     if ( nMarkCount && !bSubShellSet )
469     {
470         sal_Bool bOnlyControls = sal_True;
471         sal_Bool bOnlyGraf     = sal_True;
472         for (sal_uLong i=0; i<nMarkCount; i++)
473         {
474             SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
475             if ( pObj->ISA( SdrObjGroup ) )
476             {
477                 const SdrObjList *pLst = ((SdrObjGroup*)pObj)->GetSubList();
478                 sal_uLong nListCount = pLst->GetObjCount();
479                 if ( nListCount == 0 )
480                 {
481                     //  #104156# An empty group (may occur during Undo) is no control or graphics object.
482                     //  Creating the form shell during undo would lead to problems with the undo manager.
483                     bOnlyControls = sal_False;
484                     bOnlyGraf = sal_False;
485                 }
486                 for ( sal_uInt16 j = 0; j < nListCount; ++j )
487                 {
488                     SdrObject *pSubObj = pLst->GetObj( j );
489 
490                     if (!pSubObj->ISA(SdrUnoObj))
491                         bOnlyControls = sal_False;
492                     if (pSubObj->GetObjIdentifier() != OBJ_GRAF)
493                         bOnlyGraf = sal_False;
494 
495                     if ( !bOnlyControls && !bOnlyGraf ) break;
496                 }
497             }
498             else
499             {
500                 if (!pObj->ISA(SdrUnoObj))
501                     bOnlyControls = sal_False;
502                 if (pObj->GetObjIdentifier() != OBJ_GRAF)
503                     bOnlyGraf = sal_False;
504             }
505 
506             if ( !bOnlyControls && !bOnlyGraf ) break;
507         }
508 
509         if(bOnlyControls)
510         {
511             pViewSh->SetDrawFormShell(sal_True);            // jetzt UNO-Controls
512         }
513         else if(bOnlyGraf)
514         {
515             pViewSh->SetGraphicShell(sal_True);
516         }
517         else if(nMarkCount>1)
518         {
519             pViewSh->SetDrawShell(sal_True);
520         }
521     }
522 
523 
524 
525     //  Verben anpassen
526 
527     SfxViewFrame* pViewFrame = pViewSh->GetViewFrame();
528     sal_Bool bOle = pViewSh->GetViewFrame()->GetFrame().IsInPlace();
529     uno::Sequence< embed::VerbDescriptor > aVerbs;
530     if ( pOle2Obj && !bOle )
531     {
532         uno::Reference < embed::XEmbeddedObject > xObj = pOle2Obj->GetObjRef();
533         DBG_ASSERT( xObj.is(), "SdrOle2Obj ohne ObjRef" );
534         if (xObj.is())
535             aVerbs = xObj->getSupportedVerbs();
536     }
537     pViewSh->SetVerbs( aVerbs );
538 
539     //  Image-Map Editor
540 
541     if ( pOle2Obj )
542         UpdateIMap( pOle2Obj );
543     else if ( pGrafObj )
544         UpdateIMap( pGrafObj );
545 
546     InvalidateAttribs();                // nach dem IMap-Editor Update
547     InvalidateDrawTextAttrs();
548 
549     for(sal_uInt32 a(0L); a < PaintWindowCount(); a++)
550     {
551         SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
552         OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
553 
554         if(OUTDEV_WINDOW == rOutDev.GetOutDevType())
555         {
556             ((Window&)rOutDev).Update();
557         }
558     }
559 
560     //  uno object for view returns drawing objects as selection,
561     //  so it must notify its SelectionChangeListeners
562 
563     if (pViewFrame)
564     {
565         SfxFrame& rFrame = pViewFrame->GetFrame();
566         uno::Reference<frame::XController> xController = rFrame.GetController();
567         if (xController.is())
568         {
569             ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController );
570             if (pImp)
571                 pImp->SelectionChanged();
572         }
573     }
574 
575     //  update selection transfer object
576 
577     pViewSh->CheckSelectionTransfer();
578 
579 }
580 
581 void __EXPORT ScDrawView::ModelHasChanged()
582 {
583     SdrObject* pEditObj = GetTextEditObject();
584     if ( pEditObj && !pEditObj->IsInserted() && pViewData )
585     {
586         //  #111700# SdrObjEditView::ModelHasChanged will end text edit in this case,
587         //  so make sure the EditEngine's undo manager is no longer used.
588         pViewData->GetViewShell()->SetDrawTextUndo(NULL);
589         SetCreateMode();    // don't leave FuText in a funny state
590     }
591 
592     FmFormView::ModelHasChanged();
593 }
594 
595 void __EXPORT ScDrawView::UpdateUserViewOptions()
596 {
597     if (pViewData)
598     {
599         const ScViewOptions&    rOpt = pViewData->GetOptions();
600         const ScGridOptions&    rGrid = rOpt.GetGridOptions();
601 
602         sal_Bool bBigHdl = rOpt.GetOption( VOPT_BIGHANDLES );
603 
604         SetDragStripes( rOpt.GetOption( VOPT_HELPLINES ) );
605         SetSolidMarkHdl( rOpt.GetOption( VOPT_SOLIDHANDLES ) );
606         SetMarkHdlSizePixel( bBigHdl ? SC_HANDLESIZE_BIG : SC_HANDLESIZE_SMALL );
607 
608         SetGridVisible( rGrid.GetGridVisible() );
609         SetSnapEnabled( rGrid.GetUseGridSnap() );
610         SetGridSnap( rGrid.GetUseGridSnap() );
611 
612         //  Snap from grid options is no longer used
613 //      SetSnapGrid( Size( rGrid.GetFldSnapX(), rGrid.GetFldSnapY() ) );
614 
615         Fraction aFractX( rGrid.GetFldDrawX(), rGrid.GetFldDivisionX() + 1 );
616         Fraction aFractY( rGrid.GetFldDrawY(), rGrid.GetFldDivisionY() + 1 );
617         SetSnapGridWidth( aFractX, aFractY );
618 
619         SetGridCoarse( Size( rGrid.GetFldDrawX(), rGrid.GetFldDrawY() ) );
620         SetGridFine( Size( rGrid.GetFldDrawX() / (rGrid.GetFldDivisionX() + 1),
621                            rGrid.GetFldDrawY() / (rGrid.GetFldDivisionY() + 1) ) );
622     }
623 }
624 
625 #ifdef _MSC_VER
626 #pragma optimize ( "", on )
627 #endif
628 
629 sal_Bool ScDrawView::SelectObject( const String& rName )
630 {
631     UnmarkAll();
632 
633     SCTAB nObjectTab = 0;
634     SdrObject* pFound = NULL;
635 
636     SfxObjectShell* pShell = pDoc->GetDocumentShell();
637     if (pShell)
638     {
639         SdrModel* pDrawLayer = GetModel();
640         SCTAB nTabCount = pDoc->GetTableCount();
641         for (SCTAB i=0; i<nTabCount && !pFound; i++)
642         {
643             SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
644             DBG_ASSERT(pPage,"Page ?");
645             if (pPage)
646             {
647                 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
648                 SdrObject* pObject = aIter.Next();
649                 while (pObject && !pFound)
650                 {
651                     if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
652                     {
653                         pFound = pObject;
654                         nObjectTab = i;
655                     }
656                     pObject = aIter.Next();
657                 }
658             }
659         }
660     }
661 
662     if ( pFound )
663     {
664         ScTabView* pView = pViewData->GetView();
665         if ( nObjectTab != nTab )                               // Tabelle umschalten
666             pView->SetTabNo( nObjectTab );
667 
668         DBG_ASSERT( nTab == nObjectTab, "Tabellen umschalten hat nicht geklappt" );
669 
670         pView->ScrollToObject( pFound );
671 
672         /*  #61585# To select an object on the background layer, the layer has to
673             be unlocked even if exclusive drawing selection mode is not active
674             (this is reversed in MarkListHasChanged when nothing is selected) */
675         if ( pFound->GetLayer() == SC_LAYER_BACK &&
676                 !pViewData->GetViewShell()->IsDrawSelMode() &&
677                 !pDoc->IsTabProtected( nTab ) &&
678                 !pViewData->GetSfxDocShell()->IsReadOnly() )
679         {
680             UnlockBackgroundLayer();
681         }
682 
683         SdrPageView* pPV = GetSdrPageView();
684         MarkObj( pFound, pPV );
685     }
686 
687     return ( pFound != NULL );
688 }
689 
690 //UNUSED2008-05  String ScDrawView::GetSelectedChartName() const
691 //UNUSED2008-05  {
692 //UNUSED2008-05      //  used for modifying a chart's data area - PersistName must always be used
693 //UNUSED2008-05      //  (as in ScDocument::FindChartData and UpdateChartArea)
694 //UNUSED2008-05
695 //UNUSED2008-05      const SdrMarkList& rMarkList = GetMarkedObjectList();
696 //UNUSED2008-05      if (rMarkList.GetMarkCount() == 1)
697 //UNUSED2008-05      {
698 //UNUSED2008-05          SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
699 //UNUSED2008-05          if (pObj->GetObjIdentifier() == OBJ_OLE2)
700 //UNUSED2008-05              if ( pDoc->IsChart(pObj) )
701 //UNUSED2008-05                  return static_cast<SdrOle2Obj*>(pObj)->GetPersistName();
702 //UNUSED2008-05      }
703 //UNUSED2008-05
704 //UNUSED2008-05      return EMPTY_STRING;        // nichts gefunden
705 //UNUSED2008-05  }
706 
707 FASTBOOL ScDrawView::InsertObjectSafe(SdrObject* pObj, SdrPageView& rPV, sal_uLong nOptions)
708 {
709     //  Markierung nicht aendern, wenn Ole-Objekt aktiv
710     //  (bei Drop aus Ole-Objekt wuerde sonst mitten im ExecuteDrag deaktiviert!)
711 
712     if (pViewData)
713     {
714         SfxInPlaceClient* pClient = pViewData->GetViewShell()->GetIPClient();
715         if ( pClient && pClient->IsObjectInPlaceActive() )
716             nOptions |= SDRINSERT_DONTMARK;
717     }
718 
719     return InsertObjectAtView( pObj, rPV, nOptions );
720 }
721 
722 SdrObject* ScDrawView::GetMarkedNoteCaption( ScDrawObjData** ppCaptData )
723 {
724     const SdrMarkList& rMarkList = GetMarkedObjectList();
725     if( pViewData && (rMarkList.GetMarkCount() == 1) )
726     {
727         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
728         if( ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, pViewData->GetTabNo() ) )
729         {
730             if( ppCaptData ) *ppCaptData = pCaptData;
731             return pObj;
732         }
733     }
734     return 0;
735 }
736 
737 void ScDrawView::LockCalcLayer( SdrLayerID nLayer, bool bLock )
738 {
739     SdrLayer* pLockLayer = GetModel()->GetLayerAdmin().GetLayerPerID( nLayer );
740     if( pLockLayer && (IsLayerLocked( pLockLayer->GetName() ) != bLock) )
741         SetLayerLocked( pLockLayer->GetName(), bLock );
742 }
743 
744 void __EXPORT ScDrawView::MakeVisible( const Rectangle& rRect, Window& rWin )
745 {
746     //! rWin richtig auswerten
747     //! ggf Zoom aendern
748 
749     if ( pViewData && pViewData->GetActiveWin() == &rWin )
750         pViewData->GetView()->MakeVisible( rRect );
751 }
752 
753 void ScDrawView::DeleteMarked()
754 {
755     // try to delete a note caption object with its cell note in the Calc document
756     ScDrawObjData* pCaptData = 0;
757     if( SdrObject* pCaptObj = GetMarkedNoteCaption( &pCaptData ) )
758     {
759         (void)pCaptObj; // prevent 'unused variable' compiler warning in pro builds
760         ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
761         ScDocShell* pDocShell = pViewData ? pViewData->GetDocShell() : 0;
762         ::svl::IUndoManager* pUndoMgr = pDocShell ? pDocShell->GetUndoManager() : 0;
763         bool bUndo = pDrawLayer && pDocShell && pUndoMgr && pDoc->IsUndoEnabled();
764 
765         // remove the cell note from document, we are its owner now
766         ScPostIt* pNote = pDoc->ReleaseNote( pCaptData->maStart );
767         DBG_ASSERT( pNote, "ScDrawView::DeleteMarked - cell note missing in document" );
768         if( pNote )
769         {
770             // rescue note data for undo (with pointer to caption object)
771             ScNoteData aNoteData = pNote->GetNoteData();
772             DBG_ASSERT( aNoteData.mpCaption == pCaptObj, "ScDrawView::DeleteMarked - caption object does not match" );
773             // collect the drawing undo action created while deleting the note
774             if( bUndo )
775                 pDrawLayer->BeginCalcUndo();
776             // delete the note (already removed from document above)
777             delete pNote;
778             // add the undo action for the note
779             if( bUndo )
780                 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, pCaptData->maStart, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
781             // repaint the cell to get rid of the note marker
782             if( pDocShell )
783                 pDocShell->PostPaintCell( pCaptData->maStart );
784             // done, return now to skip call of FmFormView::DeleteMarked()
785             return;
786         }
787     }
788 
789     FmFormView::DeleteMarked();
790 }
791 
792 SdrEndTextEditKind ScDrawView::ScEndTextEdit()
793 {
794     sal_Bool bIsTextEdit = IsTextEdit();
795     SdrEndTextEditKind eKind = SdrEndTextEdit();
796 
797     if ( bIsTextEdit && pViewData )
798         pViewData->GetViewShell()->SetDrawTextUndo(NULL);   // "normaler" Undo-Manager
799 
800     return eKind;
801 }
802 
803 void ScDrawView::MarkDropObj( SdrObject* pObj )
804 {
805     if ( pDropMarkObj != pObj )
806     {
807         pDropMarkObj = pObj;
808         ImplClearCalcDropMarker();
809 
810         if(pDropMarkObj)
811         {
812             pDropMarker = new SdrDropMarkerOverlay(*this, *pDropMarkObj);
813         }
814     }
815 }
816 
817 //UNUSED2009-05 void ScDrawView::CaptionTextDirection( sal_uInt16 nSlot )
818 //UNUSED2009-05 {
819 //UNUSED2009-05     if(nSlot != SID_TEXTDIRECTION_LEFT_TO_RIGHT && nSlot != SID_TEXTDIRECTION_TOP_TO_BOTTOM)
820 //UNUSED2009-05         return;
821 //UNUSED2009-05
822 //UNUSED2009-05     SdrObject* pObject  = GetTextEditObject();
823 //UNUSED2009-05     if ( ScDrawLayer::IsNoteCaption( pObject ) )
824 //UNUSED2009-05     {
825 //UNUSED2009-05         if( SdrCaptionObj* pCaption = dynamic_cast< SdrCaptionObj* >( pObject ) )
826 //UNUSED2009-05         {
827 //UNUSED2009-05             SfxItemSet aAttr(pCaption->GetMergedItemSet());
828 //UNUSED2009-05             aAttr.Put( SvxWritingModeItem(
829 //UNUSED2009-05                 nSlot == SID_TEXTDIRECTION_LEFT_TO_RIGHT ?
830 //UNUSED2009-05                     com::sun::star::text::WritingMode_LR_TB : com::sun::star::text::WritingMode_TB_RL,
831 //UNUSED2009-05                     SDRATTR_TEXTDIRECTION ) );
832 //UNUSED2009-05             pCaption->SetMergedItemSet(aAttr);
833 //UNUSED2009-05             FuPoor* pPoor = pViewData->GetView()->GetDrawFuncPtr();
834 //UNUSED2009-05             if ( pPoor )
835 //UNUSED2009-05             {
836 //UNUSED2009-05                 FuText* pText = static_cast<FuText*>(pPoor);
837 //UNUSED2009-05                 pText->StopEditMode(sal_True);
838 //UNUSED2009-05             }
839 //UNUSED2009-05         }
840 //UNUSED2009-05     }
841 //UNUSED2009-05 }
842