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