xref: /trunk/main/sc/source/ui/view/drawview.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svx/svditer.hxx>
32cdf0e10cSrcweir #include <svx/svdograf.hxx>
33cdf0e10cSrcweir #include <svx/svdomedia.hxx>
34cdf0e10cSrcweir #include <svx/svdogrp.hxx>
35cdf0e10cSrcweir #include <svx/svdoole2.hxx>
36cdf0e10cSrcweir #include <svx/svdouno.hxx>
37cdf0e10cSrcweir #include <svx/svdpage.hxx>
38cdf0e10cSrcweir #include <svx/svdundo.hxx>
39cdf0e10cSrcweir #include <svx/svdocapt.hxx>
40cdf0e10cSrcweir #include <editeng/outlobj.hxx>
41cdf0e10cSrcweir #include <editeng/writingmodeitem.hxx>
42cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx>
43cdf0e10cSrcweir #include <sfx2/bindings.hxx>
44cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
4514af77b6SArmin Le Grand #include <svx/sdrundomanager.hxx>
4652f1c2eeSArmin Le Grand #include <svx/xbtmpit.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include "drawview.hxx"
49cdf0e10cSrcweir #include "global.hxx"
50cdf0e10cSrcweir #include "viewdata.hxx"
51cdf0e10cSrcweir #include "document.hxx"
52cdf0e10cSrcweir #include "drawutil.hxx"
53cdf0e10cSrcweir #include "futext.hxx"
54cdf0e10cSrcweir #include "globstr.hrc"
55cdf0e10cSrcweir #include "tabvwsh.hxx"
56cdf0e10cSrcweir #include "client.hxx"
57cdf0e10cSrcweir #include "scmod.hxx"
58cdf0e10cSrcweir #include "drwlayer.hxx"
59cdf0e10cSrcweir #include "docsh.hxx"
60cdf0e10cSrcweir #include "viewuno.hxx"
61cdf0e10cSrcweir #include "userdat.hxx"
62cdf0e10cSrcweir #include "postit.hxx"
63cdf0e10cSrcweir #include "undocell.hxx"
6414af77b6SArmin Le Grand #include "document.hxx"
65cdf0e10cSrcweir 
66cdf0e10cSrcweir #include "sc.hrc"
67cdf0e10cSrcweir 
68cdf0e10cSrcweir using namespace com::sun::star;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir // -----------------------------------------------------------------------
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #define SC_HANDLESIZE_BIG       9
73cdf0e10cSrcweir #define SC_HANDLESIZE_SMALL     7
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // -----------------------------------------------------------------------
76cdf0e10cSrcweir 
77cdf0e10cSrcweir #ifdef _MSC_VER
78cdf0e10cSrcweir #pragma optimize ( "", off )
79cdf0e10cSrcweir #endif
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
Construct()82cdf0e10cSrcweir void ScDrawView::Construct()
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     EnableExtendedKeyInputDispatcher(sal_False);
85cdf0e10cSrcweir     EnableExtendedMouseEventDispatcher(sal_False);
86cdf0e10cSrcweir     EnableExtendedCommandEventDispatcher(sal_False);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     SetFrameDragSingles(sal_True);
89cdf0e10cSrcweir //  SetSolidMarkHdl(sal_True);              // einstellbar -> UpdateUserViewOptions
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     SetMinMoveDistancePixel( 2 );
92cdf0e10cSrcweir     SetHitTolerancePixel( 2 );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     if (pViewData)
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         SCTAB nViewTab = pViewData->GetTabNo();
97cdf0e10cSrcweir         ShowSdrPage(GetModel()->GetPage(nViewTab));
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         sal_Bool bEx = pViewData->GetViewShell()->IsDrawSelMode();
100cdf0e10cSrcweir         sal_Bool bProt = pDoc->IsTabProtected( nViewTab ) ||
101cdf0e10cSrcweir                      pViewData->GetSfxDocShell()->IsReadOnly();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         SdrLayer* pLayer;
104cdf0e10cSrcweir         SdrLayerAdmin& rAdmin = GetModel()->GetLayerAdmin();
105cdf0e10cSrcweir         pLayer = rAdmin.GetLayerPerID(SC_LAYER_BACK);
106cdf0e10cSrcweir         if (pLayer)
107cdf0e10cSrcweir             SetLayerLocked( pLayer->GetName(), bProt || !bEx );
108cdf0e10cSrcweir         pLayer = rAdmin.GetLayerPerID(SC_LAYER_INTERN);
109cdf0e10cSrcweir         if (pLayer)
110cdf0e10cSrcweir             SetLayerLocked( pLayer->GetName(), sal_True );
111cdf0e10cSrcweir         pLayer = rAdmin.GetLayerPerID(SC_LAYER_FRONT);
112cdf0e10cSrcweir         if (pLayer)
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir             SetLayerLocked( pLayer->GetName(), bProt );
115cdf0e10cSrcweir             SetActiveLayer( pLayer->GetName() );        // FRONT als aktiven Layer setzen
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir         pLayer = rAdmin.GetLayerPerID(SC_LAYER_CONTROLS);
118cdf0e10cSrcweir         if (pLayer)
119cdf0e10cSrcweir             SetLayerLocked( pLayer->GetName(), bProt );
120cdf0e10cSrcweir         pLayer = rAdmin.GetLayerPerID(SC_LAYER_HIDDEN);
121cdf0e10cSrcweir         if (pLayer)
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             SetLayerLocked( pLayer->GetName(), bProt );
124cdf0e10cSrcweir             SetLayerVisible( pLayer->GetName(), sal_False);
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         SetSwapAsynchron(sal_True);
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir     else
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         ShowSdrPage(GetModel()->GetPage(nTab));
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     UpdateUserViewOptions();
135cdf0e10cSrcweir     RecalcScale();
136cdf0e10cSrcweir     UpdateWorkArea();
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     bInConstruct = sal_False;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
ImplClearCalcDropMarker()141cdf0e10cSrcweir void ScDrawView::ImplClearCalcDropMarker()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     if(pDropMarker)
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         delete pDropMarker;
146cdf0e10cSrcweir         pDropMarker = 0L;
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
~ScDrawView()150cdf0e10cSrcweir __EXPORT ScDrawView::~ScDrawView()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     ImplClearCalcDropMarker();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
AddCustomHdl()155cdf0e10cSrcweir void ScDrawView::AddCustomHdl()
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     const SdrMarkList &rMrkList = GetMarkedObjectList();
160cdf0e10cSrcweir     sal_uInt32 nCount = rMrkList.GetMarkCount();
161cdf0e10cSrcweir     for(sal_uInt32 nPos=0; nPos<nCount; nPos++ )
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         const SdrObject* pObj = rMrkList.GetMark(nPos)->GetMarkedSdrObj();
164cdf0e10cSrcweir         if(ScDrawLayer::GetAnchor(pObj) == SCA_CELL)
165cdf0e10cSrcweir         {
166cdf0e10cSrcweir             const sal_Int32 nDelta = 1;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir             Rectangle aBoundRect = pObj->GetCurrentBoundRect();
169cdf0e10cSrcweir             Point aPos;
170cdf0e10cSrcweir             if (bNegativePage)
171cdf0e10cSrcweir             {
172cdf0e10cSrcweir                 aPos = aBoundRect.TopRight();
173cdf0e10cSrcweir                 aPos.X() = -aPos.X();           // so the loop below is the same
174cdf0e10cSrcweir             }
175cdf0e10cSrcweir             else
176cdf0e10cSrcweir                 aPos = aBoundRect.TopLeft();
177cdf0e10cSrcweir             long nPosX = (long) (aPos.X() / HMM_PER_TWIPS) + nDelta;
178cdf0e10cSrcweir             long nPosY = (long) (aPos.Y() / HMM_PER_TWIPS) + nDelta;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir             SCCOL nCol;
181cdf0e10cSrcweir             sal_Int32 nWidth = 0;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir             for(nCol=0; nCol<=MAXCOL && nWidth<=nPosX; nCol++)
184cdf0e10cSrcweir                 nWidth += pDoc->GetColWidth(nCol,nTab);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir             if(nCol > 0)
187cdf0e10cSrcweir                 --nCol;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir             SCROW nRow = nPosY <= 0 ? 0 : pDoc->GetRowForHeight( nTab,
190cdf0e10cSrcweir                     (sal_uLong) nPosY);
191cdf0e10cSrcweir             if(nRow > 0)
192cdf0e10cSrcweir                 --nRow;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir             ScTabView* pView = pViewData->GetView();
195cdf0e10cSrcweir             ScAddress aScAddress(nCol, nRow, nTab);
196cdf0e10cSrcweir             pView->CreateAnchorHandles(aHdl, aScAddress);
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
InvalidateAttribs()201cdf0e10cSrcweir void ScDrawView::InvalidateAttribs()
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     if (!pViewData) return;
204cdf0e10cSrcweir     SfxBindings& rBindings = pViewData->GetBindings();
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         // echte Statuswerte:
207cdf0e10cSrcweir     rBindings.InvalidateAll( sal_True );
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
InvalidateDrawTextAttrs()210cdf0e10cSrcweir void ScDrawView::InvalidateDrawTextAttrs()
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     if (!pViewData) return;
213cdf0e10cSrcweir     SfxBindings& rBindings = pViewData->GetBindings();
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     //  cjk/ctl font items have no configured slots,
216cdf0e10cSrcweir     //  need no invalidate
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_CHAR_FONT );
219cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
220cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
221cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
222cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
223cdf0e10cSrcweir     rBindings.Invalidate( SID_ULINE_VAL_NONE );
224cdf0e10cSrcweir     rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
225cdf0e10cSrcweir     rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
226cdf0e10cSrcweir     rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
227cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_CHAR_OVERLINE );
228cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
229766ce4d0SZheng Fan     rBindings.Invalidate( SID_ATTR_PARA_ADJUST_LEFT );
230766ce4d0SZheng Fan     rBindings.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT );
231766ce4d0SZheng Fan     rBindings.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK );
232766ce4d0SZheng Fan     rBindings.Invalidate( SID_ATTR_PARA_ADJUST_CENTER);
233cdf0e10cSrcweir     rBindings.Invalidate( SID_ALIGNLEFT );
234cdf0e10cSrcweir     rBindings.Invalidate( SID_ALIGNCENTERHOR );
235cdf0e10cSrcweir     rBindings.Invalidate( SID_ALIGNRIGHT );
236cdf0e10cSrcweir     rBindings.Invalidate( SID_ALIGNBLOCK );
237cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_10 );
238cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_15 );
239cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_20 );
240cdf0e10cSrcweir     rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
241cdf0e10cSrcweir     rBindings.Invalidate( SID_SET_SUB_SCRIPT );
242512ec161SZheng Fan     rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
243512ec161SZheng Fan     rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
244512ec161SZheng Fan     rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
245cdf0e10cSrcweir     rBindings.Invalidate( SID_TEXTDIRECTION_LEFT_TO_RIGHT );
246cdf0e10cSrcweir     rBindings.Invalidate( SID_TEXTDIRECTION_TOP_TO_BOTTOM );
247cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
248cdf0e10cSrcweir     rBindings.Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
249cdf0e10cSrcweir     // pseudo slots for Format menu
250cdf0e10cSrcweir     rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
251cdf0e10cSrcweir     rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
252cdf0e10cSrcweir     rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
253cdf0e10cSrcweir     rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir //void ScDrawView::DrawMarks( OutputDevice* pOut ) const
257cdf0e10cSrcweir //{
258cdf0e10cSrcweir //  DBG_ASSERT(pOut, "ScDrawView::DrawMarks: No OutputDevice (!)");
259cdf0e10cSrcweir //  SdrPaintWindow* pPaintWindow = FindPaintWindow(*pOut);
260cdf0e10cSrcweir //
261cdf0e10cSrcweir //  if(pPaintWindow)
262cdf0e10cSrcweir //  {
263cdf0e10cSrcweir //      if(pPaintWindow->isXorVisible())
264cdf0e10cSrcweir //      {
265cdf0e10cSrcweir //          ToggleShownXor(pOut, 0L);
266cdf0e10cSrcweir //      }
267cdf0e10cSrcweir //  }
268cdf0e10cSrcweir //}
269cdf0e10cSrcweir 
SetMarkedToLayer(sal_uInt8 nLayerNo)270cdf0e10cSrcweir void ScDrawView::SetMarkedToLayer( sal_uInt8 nLayerNo )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     if (AreObjectsMarked())
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         //  #i11702# use SdrUndoObjectLayerChange for undo
275cdf0e10cSrcweir         //  STR_UNDO_SELATTR is "Attributes" - should use a different text later
276cdf0e10cSrcweir         BegUndo( ScGlobal::GetRscString( STR_UNDO_SELATTR ) );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir         const SdrMarkList& rMark = GetMarkedObjectList();
279cdf0e10cSrcweir         sal_uLong nCount = rMark.GetMarkCount();
280cdf0e10cSrcweir         for (sal_uLong i=0; i<nCount; i++)
281cdf0e10cSrcweir         {
282cdf0e10cSrcweir             SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
283cdf0e10cSrcweir             if ( !pObj->ISA(SdrUnoObj) && (pObj->GetLayer() != SC_LAYER_INTERN) )
284cdf0e10cSrcweir             {
285cdf0e10cSrcweir                 AddUndo( new SdrUndoObjectLayerChange( *pObj, pObj->GetLayer(), (SdrLayerID)nLayerNo) );
286cdf0e10cSrcweir                 pObj->SetLayer( nLayerNo );
287cdf0e10cSrcweir             }
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         EndUndo();
291cdf0e10cSrcweir 
292cdf0e10cSrcweir         //  repaint is done in SetLayer
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         pViewData->GetDocShell()->SetDrawModified();
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         //  #84073# check mark list now instead of later in a timer
297cdf0e10cSrcweir         CheckMarked();
298cdf0e10cSrcweir         MarkListHasChanged();
299cdf0e10cSrcweir     }
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
HasMarkedControl() const302cdf0e10cSrcweir bool ScDrawView::HasMarkedControl() const
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     SdrObjListIter aIter( GetMarkedObjectList() );
305cdf0e10cSrcweir     for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
306cdf0e10cSrcweir         if( pObj->ISA( SdrUnoObj ) )
307cdf0e10cSrcweir             return true;
308cdf0e10cSrcweir     return false;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
HasMarkedInternal() const311cdf0e10cSrcweir bool ScDrawView::HasMarkedInternal() const
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     // internal objects should not be inside a group, but who knows...
314cdf0e10cSrcweir     SdrObjListIter aIter( GetMarkedObjectList() );
315cdf0e10cSrcweir     for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
316cdf0e10cSrcweir         if( pObj->GetLayer() == SC_LAYER_INTERN )
317cdf0e10cSrcweir             return true;
318cdf0e10cSrcweir     return false;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
UpdateWorkArea()321cdf0e10cSrcweir void ScDrawView::UpdateWorkArea()
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     SdrPage* pPage = GetModel()->GetPage(static_cast<sal_uInt16>(nTab));
324cdf0e10cSrcweir     if (pPage)
325cdf0e10cSrcweir     {
326cdf0e10cSrcweir         Point aPos;
327cdf0e10cSrcweir         Size aPageSize( pPage->GetSize() );
328cdf0e10cSrcweir         Rectangle aNewArea( aPos, aPageSize );
329cdf0e10cSrcweir         if ( aPageSize.Width() < 0 )
330cdf0e10cSrcweir         {
331cdf0e10cSrcweir             //  RTL: from max.negative (left) to zero (right)
332cdf0e10cSrcweir             aNewArea.Right() = 0;
333cdf0e10cSrcweir             aNewArea.Left() = aPageSize.Width() + 1;
334cdf0e10cSrcweir         }
335cdf0e10cSrcweir         SetWorkArea( aNewArea );
336cdf0e10cSrcweir     }
337cdf0e10cSrcweir     else
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         DBG_ERROR("Page nicht gefunden");
340cdf0e10cSrcweir     }
341cdf0e10cSrcweir }
342cdf0e10cSrcweir 
DoCut()343cdf0e10cSrcweir void ScDrawView::DoCut()
344cdf0e10cSrcweir {
345cdf0e10cSrcweir     DoCopy();
346cdf0e10cSrcweir     BegUndo( ScGlobal::GetRscString( STR_UNDO_CUT ) );
347cdf0e10cSrcweir     DeleteMarked();     // auf dieser View - von der 505f Umstellung nicht betroffen
348cdf0e10cSrcweir     EndUndo();
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
GetScale(Fraction & rFractX,Fraction & rFractY) const351cdf0e10cSrcweir void ScDrawView::GetScale( Fraction& rFractX, Fraction& rFractY ) const
352cdf0e10cSrcweir {
353cdf0e10cSrcweir     rFractX = aScaleX;
354cdf0e10cSrcweir     rFractY = aScaleY;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
RecalcScale()357cdf0e10cSrcweir void ScDrawView::RecalcScale()
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     double nPPTX;
360cdf0e10cSrcweir     double nPPTY;
361cdf0e10cSrcweir     Fraction aZoomX(1,1);
362cdf0e10cSrcweir     Fraction aZoomY(1,1);
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     if (pViewData)
365cdf0e10cSrcweir     {
366cdf0e10cSrcweir         nTab = pViewData->GetTabNo();
367cdf0e10cSrcweir         nPPTX = pViewData->GetPPTX();
368cdf0e10cSrcweir         nPPTY = pViewData->GetPPTY();
369cdf0e10cSrcweir         aZoomX = pViewData->GetZoomX();
370cdf0e10cSrcweir         aZoomY = pViewData->GetZoomY();
371cdf0e10cSrcweir     }
372cdf0e10cSrcweir     else
373cdf0e10cSrcweir     {
374cdf0e10cSrcweir         Point aLogic = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
375cdf0e10cSrcweir         nPPTX = aLogic.X() / 1000.0;
376cdf0e10cSrcweir         nPPTY = aLogic.Y() / 1000.0;
377cdf0e10cSrcweir                                             //! Zoom uebergeben ???
378cdf0e10cSrcweir     }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     SCCOL nEndCol = 0;
381cdf0e10cSrcweir     SCROW nEndRow = 0;
382cdf0e10cSrcweir     pDoc->GetTableArea( nTab, nEndCol, nEndRow );
383cdf0e10cSrcweir     if (nEndCol<20)
384cdf0e10cSrcweir         nEndCol = 20;
385cdf0e10cSrcweir     if (nEndRow<20)
386cdf0e10cSrcweir         nEndRow = 20;   // #i116848# instead of a large row number for an empty sheet, heights are multiplied in CalcScale
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, pDev,aZoomX,aZoomY,nPPTX,nPPTY,
389cdf0e10cSrcweir                             aScaleX,aScaleY );
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
DoConnect(SdrOle2Obj * pOleObj)392cdf0e10cSrcweir void ScDrawView::DoConnect(SdrOle2Obj* pOleObj)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir     if ( pViewData )
395cdf0e10cSrcweir         pViewData->GetViewShell()->ConnectObject( pOleObj );
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
MarkListHasChanged()398cdf0e10cSrcweir void ScDrawView::MarkListHasChanged()
399cdf0e10cSrcweir {
400cdf0e10cSrcweir     FmFormView::MarkListHasChanged();
401cdf0e10cSrcweir 
402cdf0e10cSrcweir     UpdateBrowser();
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     ScTabViewShell* pViewSh = pViewData->GetViewShell();
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     // #i110829# remove the cell selection only if drawing objects are selected
407cdf0e10cSrcweir     if ( !bInConstruct && GetMarkedObjectList().GetMarkCount() )
408cdf0e10cSrcweir     {
409cdf0e10cSrcweir         pViewSh->Unmark();      // remove cell selection
410cdf0e10cSrcweir 
411cdf0e10cSrcweir         //  #65379# end cell edit mode if drawing objects are selected
412cdf0e10cSrcweir         SC_MOD()->InputEnterHandler();
413cdf0e10cSrcweir     }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir     //  IP deaktivieren
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     ScModule* pScMod = SC_MOD();
418cdf0e10cSrcweir     bool bUnoRefDialog = pScMod->IsRefDialogOpen() && pScMod->GetCurRefDlgId() == WID_SIMPLE_REF;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir     ScClient* pClient = (ScClient*) pViewSh->GetIPClient();
421cdf0e10cSrcweir     if ( pClient && pClient->IsObjectInPlaceActive() && !bUnoRefDialog )
422cdf0e10cSrcweir     {
423cdf0e10cSrcweir         //  #41730# beim ViewShell::Activate aus dem Reset2Open nicht die Handles anzeigen
424cdf0e10cSrcweir         //HMHbDisableHdl = sal_True;
425cdf0e10cSrcweir         pClient->DeactivateObject();
426cdf0e10cSrcweir         //HMHbDisableHdl = sal_False;
427cdf0e10cSrcweir         //  Image-Ole wieder durch Grafik ersetzen passiert jetzt in ScClient::UIActivate
428cdf0e10cSrcweir     }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     //  Ole-Objekt selektiert?
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     SdrOle2Obj* pOle2Obj = NULL;
433cdf0e10cSrcweir     SdrGrafObj* pGrafObj = NULL;
434cdf0e10cSrcweir     SdrMediaObj* pMediaObj = NULL;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     const SdrMarkList& rMarkList = GetMarkedObjectList();
437cdf0e10cSrcweir     sal_uLong nMarkCount = rMarkList.GetMarkCount();
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     if ( nMarkCount == 0 && !pViewData->GetViewShell()->IsDrawSelMode() && !bInConstruct )
440cdf0e10cSrcweir     {
441cdf0e10cSrcweir         //  relock layers that may have been unlocked before
442cdf0e10cSrcweir         LockBackgroundLayer();
443cdf0e10cSrcweir         LockInternalLayer();
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     sal_Bool bSubShellSet = sal_False;
447cdf0e10cSrcweir     if (nMarkCount == 1)
448cdf0e10cSrcweir     {
449cdf0e10cSrcweir         SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
450cdf0e10cSrcweir         if (pObj->GetObjIdentifier() == OBJ_OLE2)
451cdf0e10cSrcweir         {
452cdf0e10cSrcweir             pOle2Obj = (SdrOle2Obj*) pObj;
453cdf0e10cSrcweir             if (!pDoc->IsChart(pObj) )
454cdf0e10cSrcweir                 pViewSh->SetOleObjectShell(sal_True);
455cdf0e10cSrcweir             else
456cdf0e10cSrcweir                 pViewSh->SetChartShell(sal_True);
457cdf0e10cSrcweir             bSubShellSet = sal_True;
458cdf0e10cSrcweir         }
459cdf0e10cSrcweir         else if (pObj->GetObjIdentifier() == OBJ_GRAF)
460cdf0e10cSrcweir         {
461cdf0e10cSrcweir             pGrafObj = (SdrGrafObj*) pObj;
462cdf0e10cSrcweir             pViewSh->SetGraphicShell(sal_True);
463cdf0e10cSrcweir             bSubShellSet = sal_True;
464cdf0e10cSrcweir         }
465cdf0e10cSrcweir         else if (pObj->GetObjIdentifier() == OBJ_MEDIA)
466cdf0e10cSrcweir         {
467cdf0e10cSrcweir             pMediaObj = (SdrMediaObj*) pObj;
468cdf0e10cSrcweir             pViewSh->SetMediaShell(sal_True);
469cdf0e10cSrcweir             bSubShellSet = sal_True;
470cdf0e10cSrcweir         }
471cdf0e10cSrcweir         else if (pObj->GetObjIdentifier() != OBJ_TEXT   // Verhindern, das beim Anlegen
472cdf0e10cSrcweir                     || !pViewSh->IsDrawTextShell())     // eines TextObjekts auf die
473cdf0e10cSrcweir         {                                               // DrawShell umgeschaltet wird.
474cdf0e10cSrcweir             pViewSh->SetDrawShell(sal_True);                //@#70206#
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     if ( nMarkCount && !bSubShellSet )
479cdf0e10cSrcweir     {
480cdf0e10cSrcweir         sal_Bool bOnlyControls = sal_True;
481cdf0e10cSrcweir         sal_Bool bOnlyGraf     = sal_True;
482cdf0e10cSrcweir         for (sal_uLong i=0; i<nMarkCount; i++)
483cdf0e10cSrcweir         {
484cdf0e10cSrcweir             SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
485cdf0e10cSrcweir             if ( pObj->ISA( SdrObjGroup ) )
486cdf0e10cSrcweir             {
487cdf0e10cSrcweir                 const SdrObjList *pLst = ((SdrObjGroup*)pObj)->GetSubList();
488cdf0e10cSrcweir                 sal_uLong nListCount = pLst->GetObjCount();
489cdf0e10cSrcweir                 if ( nListCount == 0 )
490cdf0e10cSrcweir                 {
491cdf0e10cSrcweir                     //  #104156# An empty group (may occur during Undo) is no control or graphics object.
492cdf0e10cSrcweir                     //  Creating the form shell during undo would lead to problems with the undo manager.
493cdf0e10cSrcweir                     bOnlyControls = sal_False;
494cdf0e10cSrcweir                     bOnlyGraf = sal_False;
495cdf0e10cSrcweir                 }
496cdf0e10cSrcweir                 for ( sal_uInt16 j = 0; j < nListCount; ++j )
497cdf0e10cSrcweir                 {
498cdf0e10cSrcweir                     SdrObject *pSubObj = pLst->GetObj( j );
499cdf0e10cSrcweir 
500cdf0e10cSrcweir                     if (!pSubObj->ISA(SdrUnoObj))
501cdf0e10cSrcweir                         bOnlyControls = sal_False;
502cdf0e10cSrcweir                     if (pSubObj->GetObjIdentifier() != OBJ_GRAF)
503cdf0e10cSrcweir                         bOnlyGraf = sal_False;
504cdf0e10cSrcweir 
505cdf0e10cSrcweir                     if ( !bOnlyControls && !bOnlyGraf ) break;
506cdf0e10cSrcweir                 }
507cdf0e10cSrcweir             }
508cdf0e10cSrcweir             else
509cdf0e10cSrcweir             {
510cdf0e10cSrcweir                 if (!pObj->ISA(SdrUnoObj))
511cdf0e10cSrcweir                     bOnlyControls = sal_False;
512cdf0e10cSrcweir                 if (pObj->GetObjIdentifier() != OBJ_GRAF)
513cdf0e10cSrcweir                     bOnlyGraf = sal_False;
514cdf0e10cSrcweir             }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir             if ( !bOnlyControls && !bOnlyGraf ) break;
517cdf0e10cSrcweir         }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir         if(bOnlyControls)
520cdf0e10cSrcweir         {
521cdf0e10cSrcweir             pViewSh->SetDrawFormShell(sal_True);            // jetzt UNO-Controls
522cdf0e10cSrcweir         }
523cdf0e10cSrcweir         else if(bOnlyGraf)
524cdf0e10cSrcweir         {
525cdf0e10cSrcweir             pViewSh->SetGraphicShell(sal_True);
526cdf0e10cSrcweir         }
527cdf0e10cSrcweir         else if(nMarkCount>1)
528cdf0e10cSrcweir         {
529cdf0e10cSrcweir             pViewSh->SetDrawShell(sal_True);
530cdf0e10cSrcweir         }
531cdf0e10cSrcweir     }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 
534cdf0e10cSrcweir 
535cdf0e10cSrcweir     //  Verben anpassen
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     SfxViewFrame* pViewFrame = pViewSh->GetViewFrame();
538cdf0e10cSrcweir     sal_Bool bOle = pViewSh->GetViewFrame()->GetFrame().IsInPlace();
539cdf0e10cSrcweir     uno::Sequence< embed::VerbDescriptor > aVerbs;
540cdf0e10cSrcweir     if ( pOle2Obj && !bOle )
541cdf0e10cSrcweir     {
542cdf0e10cSrcweir         uno::Reference < embed::XEmbeddedObject > xObj = pOle2Obj->GetObjRef();
543cdf0e10cSrcweir         DBG_ASSERT( xObj.is(), "SdrOle2Obj ohne ObjRef" );
544cdf0e10cSrcweir         if (xObj.is())
545cdf0e10cSrcweir             aVerbs = xObj->getSupportedVerbs();
546cdf0e10cSrcweir     }
547cdf0e10cSrcweir     pViewSh->SetVerbs( aVerbs );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     //  Image-Map Editor
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     if ( pOle2Obj )
552cdf0e10cSrcweir         UpdateIMap( pOle2Obj );
553cdf0e10cSrcweir     else if ( pGrafObj )
554cdf0e10cSrcweir         UpdateIMap( pGrafObj );
555cdf0e10cSrcweir 
556cdf0e10cSrcweir     InvalidateAttribs();                // nach dem IMap-Editor Update
557cdf0e10cSrcweir     InvalidateDrawTextAttrs();
558cdf0e10cSrcweir 
559cdf0e10cSrcweir     for(sal_uInt32 a(0L); a < PaintWindowCount(); a++)
560cdf0e10cSrcweir     {
561cdf0e10cSrcweir         SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
562cdf0e10cSrcweir         OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
563cdf0e10cSrcweir 
564cdf0e10cSrcweir         if(OUTDEV_WINDOW == rOutDev.GetOutDevType())
565cdf0e10cSrcweir         {
566cdf0e10cSrcweir             ((Window&)rOutDev).Update();
567cdf0e10cSrcweir         }
568cdf0e10cSrcweir     }
569cdf0e10cSrcweir 
570cdf0e10cSrcweir     //  uno object for view returns drawing objects as selection,
571cdf0e10cSrcweir     //  so it must notify its SelectionChangeListeners
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     if (pViewFrame)
574cdf0e10cSrcweir     {
575cdf0e10cSrcweir         SfxFrame& rFrame = pViewFrame->GetFrame();
576cdf0e10cSrcweir         uno::Reference<frame::XController> xController = rFrame.GetController();
577cdf0e10cSrcweir         if (xController.is())
578cdf0e10cSrcweir         {
579cdf0e10cSrcweir             ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController );
580cdf0e10cSrcweir             if (pImp)
581cdf0e10cSrcweir                 pImp->SelectionChanged();
582cdf0e10cSrcweir         }
583cdf0e10cSrcweir     }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir     //  update selection transfer object
586cdf0e10cSrcweir 
587cdf0e10cSrcweir     pViewSh->CheckSelectionTransfer();
588cdf0e10cSrcweir 
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
SdrBeginTextEdit(SdrObject * pObj,SdrPageView * pPV,::Window * pWinL,sal_Bool bIsNewObj,SdrOutliner * pGivenOutliner,OutlinerView * pGivenOutlinerView,sal_Bool bDontDeleteOutliner,sal_Bool bOnlyOneView,sal_Bool bGrabFocus)591edf077abSOliver-Rainer Wittmann sal_Bool ScDrawView::SdrBeginTextEdit(
592edf077abSOliver-Rainer Wittmann     SdrObject* pObj,
593edf077abSOliver-Rainer Wittmann     SdrPageView* pPV,
594edf077abSOliver-Rainer Wittmann     ::Window* pWinL,
595edf077abSOliver-Rainer Wittmann     sal_Bool bIsNewObj,
596edf077abSOliver-Rainer Wittmann     SdrOutliner* pGivenOutliner,
597edf077abSOliver-Rainer Wittmann     OutlinerView* pGivenOutlinerView,
598edf077abSOliver-Rainer Wittmann     sal_Bool bDontDeleteOutliner,
599edf077abSOliver-Rainer Wittmann     sal_Bool bOnlyOneView,
600edf077abSOliver-Rainer Wittmann     sal_Bool bGrabFocus )
601edf077abSOliver-Rainer Wittmann {
602edf077abSOliver-Rainer Wittmann     const sal_Bool bRet = FmFormView::SdrBeginTextEdit(
603edf077abSOliver-Rainer Wittmann         pObj, pPV, pWinL, bIsNewObj,
604edf077abSOliver-Rainer Wittmann         pGivenOutliner, pGivenOutlinerView, bDontDeleteOutliner,
605edf077abSOliver-Rainer Wittmann         bOnlyOneView, bGrabFocus );
606edf077abSOliver-Rainer Wittmann 
607edf077abSOliver-Rainer Wittmann     ScTabViewShell* pViewSh = pViewData->GetViewShell();
608edf077abSOliver-Rainer Wittmann     if ( pViewSh->GetViewFrame() )
609edf077abSOliver-Rainer Wittmann     {
610edf077abSOliver-Rainer Wittmann         SfxFrame& rFrame = pViewSh->GetViewFrame()->GetFrame();
611edf077abSOliver-Rainer Wittmann         uno::Reference< frame::XController > xController = rFrame.GetController();
612edf077abSOliver-Rainer Wittmann         if (xController.is())
613edf077abSOliver-Rainer Wittmann         {
614edf077abSOliver-Rainer Wittmann             ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController );
615edf077abSOliver-Rainer Wittmann             if (pImp)
616edf077abSOliver-Rainer Wittmann                 pImp->SelectionChanged();
617edf077abSOliver-Rainer Wittmann         }
618edf077abSOliver-Rainer Wittmann     }
619edf077abSOliver-Rainer Wittmann 
620edf077abSOliver-Rainer Wittmann     return bRet;
621edf077abSOliver-Rainer Wittmann }
622edf077abSOliver-Rainer Wittmann 
623edf077abSOliver-Rainer Wittmann 
SdrEndTextEdit(sal_Bool bDontDeleteReally)624edf077abSOliver-Rainer Wittmann SdrEndTextEditKind ScDrawView::SdrEndTextEdit( sal_Bool bDontDeleteReally )
625edf077abSOliver-Rainer Wittmann {
626edf077abSOliver-Rainer Wittmann     const SdrEndTextEditKind eRet = FmFormView::SdrEndTextEdit( bDontDeleteReally );
627edf077abSOliver-Rainer Wittmann 
628edf077abSOliver-Rainer Wittmann     ScTabViewShell* pViewSh = pViewData->GetViewShell();
629edf077abSOliver-Rainer Wittmann     if ( pViewSh->GetViewFrame() )
630edf077abSOliver-Rainer Wittmann     {
631edf077abSOliver-Rainer Wittmann         SfxFrame& rFrame = pViewSh->GetViewFrame()->GetFrame();
632edf077abSOliver-Rainer Wittmann         uno::Reference< frame::XController > xController = rFrame.GetController();
633edf077abSOliver-Rainer Wittmann         if (xController.is())
634edf077abSOliver-Rainer Wittmann         {
635edf077abSOliver-Rainer Wittmann             ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController );
636edf077abSOliver-Rainer Wittmann             if (pImp)
637edf077abSOliver-Rainer Wittmann                 pImp->SelectionChanged();
638edf077abSOliver-Rainer Wittmann         }
639edf077abSOliver-Rainer Wittmann     }
640edf077abSOliver-Rainer Wittmann 
641edf077abSOliver-Rainer Wittmann     return eRet;
642edf077abSOliver-Rainer Wittmann }
643edf077abSOliver-Rainer Wittmann 
644edf077abSOliver-Rainer Wittmann 
ModelHasChanged()645cdf0e10cSrcweir void __EXPORT ScDrawView::ModelHasChanged()
646cdf0e10cSrcweir {
647cdf0e10cSrcweir     SdrObject* pEditObj = GetTextEditObject();
648cdf0e10cSrcweir     if ( pEditObj && !pEditObj->IsInserted() && pViewData )
649cdf0e10cSrcweir     {
650cdf0e10cSrcweir         //  #111700# SdrObjEditView::ModelHasChanged will end text edit in this case,
651cdf0e10cSrcweir         //  so make sure the EditEngine's undo manager is no longer used.
652cdf0e10cSrcweir         pViewData->GetViewShell()->SetDrawTextUndo(NULL);
653cdf0e10cSrcweir         SetCreateMode();    // don't leave FuText in a funny state
654cdf0e10cSrcweir     }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir     FmFormView::ModelHasChanged();
657cdf0e10cSrcweir }
658cdf0e10cSrcweir 
UpdateUserViewOptions()659cdf0e10cSrcweir void __EXPORT ScDrawView::UpdateUserViewOptions()
660cdf0e10cSrcweir {
661cdf0e10cSrcweir     if (pViewData)
662cdf0e10cSrcweir     {
663cdf0e10cSrcweir         const ScViewOptions&    rOpt = pViewData->GetOptions();
664cdf0e10cSrcweir         const ScGridOptions&    rGrid = rOpt.GetGridOptions();
665cdf0e10cSrcweir 
666cdf0e10cSrcweir         sal_Bool bBigHdl = rOpt.GetOption( VOPT_BIGHANDLES );
667cdf0e10cSrcweir 
668cdf0e10cSrcweir         SetDragStripes( rOpt.GetOption( VOPT_HELPLINES ) );
669cdf0e10cSrcweir         SetSolidMarkHdl( rOpt.GetOption( VOPT_SOLIDHANDLES ) );
670cdf0e10cSrcweir         SetMarkHdlSizePixel( bBigHdl ? SC_HANDLESIZE_BIG : SC_HANDLESIZE_SMALL );
671cdf0e10cSrcweir 
672cdf0e10cSrcweir         SetGridVisible( rGrid.GetGridVisible() );
673cdf0e10cSrcweir         SetSnapEnabled( rGrid.GetUseGridSnap() );
674cdf0e10cSrcweir         SetGridSnap( rGrid.GetUseGridSnap() );
675cdf0e10cSrcweir 
676cdf0e10cSrcweir         //  Snap from grid options is no longer used
677cdf0e10cSrcweir //      SetSnapGrid( Size( rGrid.GetFldSnapX(), rGrid.GetFldSnapY() ) );
678cdf0e10cSrcweir 
679cdf0e10cSrcweir         Fraction aFractX( rGrid.GetFldDrawX(), rGrid.GetFldDivisionX() + 1 );
680cdf0e10cSrcweir         Fraction aFractY( rGrid.GetFldDrawY(), rGrid.GetFldDivisionY() + 1 );
681cdf0e10cSrcweir         SetSnapGridWidth( aFractX, aFractY );
682cdf0e10cSrcweir 
683cdf0e10cSrcweir         SetGridCoarse( Size( rGrid.GetFldDrawX(), rGrid.GetFldDrawY() ) );
684cdf0e10cSrcweir         SetGridFine( Size( rGrid.GetFldDrawX() / (rGrid.GetFldDivisionX() + 1),
685cdf0e10cSrcweir                            rGrid.GetFldDrawY() / (rGrid.GetFldDivisionY() + 1) ) );
686cdf0e10cSrcweir     }
687cdf0e10cSrcweir }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir #ifdef _MSC_VER
690cdf0e10cSrcweir #pragma optimize ( "", on )
691cdf0e10cSrcweir #endif
692cdf0e10cSrcweir 
GetObjectByName(const String & rName)6930deba7fbSSteve Yin SdrObject* ScDrawView::GetObjectByName(const String& rName)
6940deba7fbSSteve Yin {
6950deba7fbSSteve Yin     SfxObjectShell* pShell = pDoc->GetDocumentShell();
6960deba7fbSSteve Yin     if (pShell)
6970deba7fbSSteve Yin     {
6980deba7fbSSteve Yin         SdrModel* pDrawLayer = GetModel();
6990deba7fbSSteve Yin         sal_uInt16 nTabCount = pDoc->GetTableCount();
7000deba7fbSSteve Yin         for (sal_uInt16 i=0; i<nTabCount; i++)
7010deba7fbSSteve Yin         {
7020deba7fbSSteve Yin             SdrPage* pPage = pDrawLayer->GetPage(i);
7030deba7fbSSteve Yin             DBG_ASSERT(pPage,"Page ?");
7040deba7fbSSteve Yin             if (pPage)
7050deba7fbSSteve Yin             {
7060deba7fbSSteve Yin                 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
7070deba7fbSSteve Yin                 SdrObject* pObject = aIter.Next();
7080deba7fbSSteve Yin                 while (pObject)
7090deba7fbSSteve Yin                 {
7100deba7fbSSteve Yin                     if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
7110deba7fbSSteve Yin                     {
7120deba7fbSSteve Yin                         return pObject;
7130deba7fbSSteve Yin                     }
7140deba7fbSSteve Yin                     pObject = aIter.Next();
7150deba7fbSSteve Yin                 }
7160deba7fbSSteve Yin             }
7170deba7fbSSteve Yin         }
7180deba7fbSSteve Yin     }
7190deba7fbSSteve Yin     return 0;
7200deba7fbSSteve Yin }
7210deba7fbSSteve Yin //Solution: realize multi-selection of objects
7220deba7fbSSteve Yin //==================================================
SelectCurrentViewObject(const String & rName)7230deba7fbSSteve Yin sal_Bool ScDrawView::SelectCurrentViewObject( const String& rName )
7240deba7fbSSteve Yin {
7250deba7fbSSteve Yin     sal_uInt16 nObjectTab = 0;
7260deba7fbSSteve Yin     SdrObject* pFound = NULL;
7270deba7fbSSteve Yin        sal_Bool bUnMark=sal_False;
7280deba7fbSSteve Yin     SfxObjectShell* pShell = pDoc->GetDocumentShell();
7290deba7fbSSteve Yin     if (pShell)
7300deba7fbSSteve Yin     {
7310deba7fbSSteve Yin         SdrModel* pDrawLayer = GetModel();
7320deba7fbSSteve Yin         sal_uInt16 nTabCount = pDoc->GetTableCount();
7330deba7fbSSteve Yin         for (sal_uInt16 i=0; i<nTabCount && !pFound; i++)
7340deba7fbSSteve Yin         {
7350deba7fbSSteve Yin             SdrPage* pPage = pDrawLayer->GetPage(i);
7360deba7fbSSteve Yin             DBG_ASSERT(pPage,"Page ?");
7370deba7fbSSteve Yin             if (pPage)
7380deba7fbSSteve Yin             {
7390deba7fbSSteve Yin                 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
7400deba7fbSSteve Yin                 SdrObject* pObject = aIter.Next();
7410deba7fbSSteve Yin                 while (pObject && !pFound)
7420deba7fbSSteve Yin                 {
7430deba7fbSSteve Yin                     if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
7440deba7fbSSteve Yin                     {
7450deba7fbSSteve Yin                         pFound = pObject;
7460deba7fbSSteve Yin                         nObjectTab = i;
7470deba7fbSSteve Yin                     }
7480deba7fbSSteve Yin                     pObject = aIter.Next();
7490deba7fbSSteve Yin                 }
7500deba7fbSSteve Yin             }
7510deba7fbSSteve Yin         }
7520deba7fbSSteve Yin     }
7530deba7fbSSteve Yin     if ( pFound )
7540deba7fbSSteve Yin     {
7550deba7fbSSteve Yin         ScTabView* pView = pViewData->GetView();
7560deba7fbSSteve Yin         if ( nObjectTab != nTab )                               // Tabelle umschalten
7570deba7fbSSteve Yin             pView->SetTabNo( nObjectTab );
7580deba7fbSSteve Yin         DBG_ASSERT( nTab == nObjectTab, "Tabellen umschalten hat nicht geklappt" );
7590deba7fbSSteve Yin         pView->ScrollToObject( pFound );
7600deba7fbSSteve Yin         if ( pFound->GetLayer() == SC_LAYER_BACK &&
7610deba7fbSSteve Yin                 !pViewData->GetViewShell()->IsDrawSelMode() &&
7620deba7fbSSteve Yin                 !pDoc->IsTabProtected( nTab ) &&
7630deba7fbSSteve Yin                 !pViewData->GetSfxDocShell()->IsReadOnly() )
7640deba7fbSSteve Yin         {
7650deba7fbSSteve Yin             SdrLayer* pLayer = GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_BACK);
7660deba7fbSSteve Yin             if (pLayer)
7670deba7fbSSteve Yin                 SetLayerLocked( pLayer->GetName(), sal_False );
7680deba7fbSSteve Yin         }
7690deba7fbSSteve Yin         SdrPageView* pPV = GetSdrPageView();
7700deba7fbSSteve Yin               bUnMark = IsObjMarked(pFound);
7710deba7fbSSteve Yin            MarkObj( pFound, pPV, bUnMark);
7720deba7fbSSteve Yin     }
7730deba7fbSSteve Yin     return ( bUnMark );
7740deba7fbSSteve Yin }
SelectObject(const String & rName)775cdf0e10cSrcweir sal_Bool ScDrawView::SelectObject( const String& rName )
776cdf0e10cSrcweir {
777cdf0e10cSrcweir     UnmarkAll();
778cdf0e10cSrcweir 
779cdf0e10cSrcweir     SCTAB nObjectTab = 0;
780cdf0e10cSrcweir     SdrObject* pFound = NULL;
781cdf0e10cSrcweir 
782cdf0e10cSrcweir     SfxObjectShell* pShell = pDoc->GetDocumentShell();
783cdf0e10cSrcweir     if (pShell)
784cdf0e10cSrcweir     {
785cdf0e10cSrcweir         SdrModel* pDrawLayer = GetModel();
786cdf0e10cSrcweir         SCTAB nTabCount = pDoc->GetTableCount();
787cdf0e10cSrcweir         for (SCTAB i=0; i<nTabCount && !pFound; i++)
788cdf0e10cSrcweir         {
789cdf0e10cSrcweir             SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
790cdf0e10cSrcweir             DBG_ASSERT(pPage,"Page ?");
791cdf0e10cSrcweir             if (pPage)
792cdf0e10cSrcweir             {
793cdf0e10cSrcweir                 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
794cdf0e10cSrcweir                 SdrObject* pObject = aIter.Next();
795cdf0e10cSrcweir                 while (pObject && !pFound)
796cdf0e10cSrcweir                 {
797cdf0e10cSrcweir                     if ( ScDrawLayer::GetVisibleName( pObject ) == rName )
798cdf0e10cSrcweir                     {
799cdf0e10cSrcweir                         pFound = pObject;
800cdf0e10cSrcweir                         nObjectTab = i;
801cdf0e10cSrcweir                     }
802cdf0e10cSrcweir                     pObject = aIter.Next();
803cdf0e10cSrcweir                 }
804cdf0e10cSrcweir             }
805cdf0e10cSrcweir         }
806cdf0e10cSrcweir     }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir     if ( pFound )
809cdf0e10cSrcweir     {
810cdf0e10cSrcweir         ScTabView* pView = pViewData->GetView();
811cdf0e10cSrcweir         if ( nObjectTab != nTab )                               // Tabelle umschalten
812cdf0e10cSrcweir             pView->SetTabNo( nObjectTab );
813cdf0e10cSrcweir 
814cdf0e10cSrcweir         DBG_ASSERT( nTab == nObjectTab, "Tabellen umschalten hat nicht geklappt" );
815cdf0e10cSrcweir 
816cdf0e10cSrcweir         pView->ScrollToObject( pFound );
817cdf0e10cSrcweir 
818cdf0e10cSrcweir         /*  #61585# To select an object on the background layer, the layer has to
819cdf0e10cSrcweir             be unlocked even if exclusive drawing selection mode is not active
820cdf0e10cSrcweir             (this is reversed in MarkListHasChanged when nothing is selected) */
821cdf0e10cSrcweir         if ( pFound->GetLayer() == SC_LAYER_BACK &&
822cdf0e10cSrcweir                 !pViewData->GetViewShell()->IsDrawSelMode() &&
823cdf0e10cSrcweir                 !pDoc->IsTabProtected( nTab ) &&
824cdf0e10cSrcweir                 !pViewData->GetSfxDocShell()->IsReadOnly() )
825cdf0e10cSrcweir         {
826cdf0e10cSrcweir             UnlockBackgroundLayer();
827cdf0e10cSrcweir         }
828cdf0e10cSrcweir 
829cdf0e10cSrcweir         SdrPageView* pPV = GetSdrPageView();
830cdf0e10cSrcweir         MarkObj( pFound, pPV );
831cdf0e10cSrcweir     }
832cdf0e10cSrcweir 
833cdf0e10cSrcweir     return ( pFound != NULL );
834cdf0e10cSrcweir }
835cdf0e10cSrcweir 
8360deba7fbSSteve Yin //Solution: If  object  is marked , return true , else return false .
8370deba7fbSSteve Yin //==================================================
GetObjectIsMarked(SdrObject * pObject)8380deba7fbSSteve Yin sal_Bool ScDrawView::GetObjectIsMarked(  SdrObject* pObject  )
8390deba7fbSSteve Yin {
8400deba7fbSSteve Yin        sal_Bool bisMarked =false;
8410deba7fbSSteve Yin     if (pObject )
8420deba7fbSSteve Yin     {
8430deba7fbSSteve Yin           bisMarked = IsObjMarked(pObject);
8440deba7fbSSteve Yin     }
8450deba7fbSSteve Yin     return  bisMarked;
8460deba7fbSSteve Yin }
847cdf0e10cSrcweir //UNUSED2008-05  String ScDrawView::GetSelectedChartName() const
848cdf0e10cSrcweir //UNUSED2008-05  {
849cdf0e10cSrcweir //UNUSED2008-05      //  used for modifying a chart's data area - PersistName must always be used
850cdf0e10cSrcweir //UNUSED2008-05      //  (as in ScDocument::FindChartData and UpdateChartArea)
851cdf0e10cSrcweir //UNUSED2008-05
852cdf0e10cSrcweir //UNUSED2008-05      const SdrMarkList& rMarkList = GetMarkedObjectList();
853cdf0e10cSrcweir //UNUSED2008-05      if (rMarkList.GetMarkCount() == 1)
854cdf0e10cSrcweir //UNUSED2008-05      {
855cdf0e10cSrcweir //UNUSED2008-05          SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
856cdf0e10cSrcweir //UNUSED2008-05          if (pObj->GetObjIdentifier() == OBJ_OLE2)
857cdf0e10cSrcweir //UNUSED2008-05              if ( pDoc->IsChart(pObj) )
858cdf0e10cSrcweir //UNUSED2008-05                  return static_cast<SdrOle2Obj*>(pObj)->GetPersistName();
859cdf0e10cSrcweir //UNUSED2008-05      }
860cdf0e10cSrcweir //UNUSED2008-05
861cdf0e10cSrcweir //UNUSED2008-05      return EMPTY_STRING;        // nichts gefunden
862cdf0e10cSrcweir //UNUSED2008-05  }
863cdf0e10cSrcweir 
InsertObjectSafe(SdrObject * pObj,SdrPageView & rPV,sal_uLong nOptions)864cdf0e10cSrcweir FASTBOOL ScDrawView::InsertObjectSafe(SdrObject* pObj, SdrPageView& rPV, sal_uLong nOptions)
865cdf0e10cSrcweir {
866cdf0e10cSrcweir     //  Markierung nicht aendern, wenn Ole-Objekt aktiv
867cdf0e10cSrcweir     //  (bei Drop aus Ole-Objekt wuerde sonst mitten im ExecuteDrag deaktiviert!)
868cdf0e10cSrcweir 
869cdf0e10cSrcweir     if (pViewData)
870cdf0e10cSrcweir     {
871cdf0e10cSrcweir         SfxInPlaceClient* pClient = pViewData->GetViewShell()->GetIPClient();
872cdf0e10cSrcweir         if ( pClient && pClient->IsObjectInPlaceActive() )
873cdf0e10cSrcweir             nOptions |= SDRINSERT_DONTMARK;
874cdf0e10cSrcweir     }
875cdf0e10cSrcweir 
876cdf0e10cSrcweir     return InsertObjectAtView( pObj, rPV, nOptions );
877cdf0e10cSrcweir }
878cdf0e10cSrcweir 
GetMarkedNoteCaption(ScDrawObjData ** ppCaptData)879cdf0e10cSrcweir SdrObject* ScDrawView::GetMarkedNoteCaption( ScDrawObjData** ppCaptData )
880cdf0e10cSrcweir {
881cdf0e10cSrcweir     const SdrMarkList& rMarkList = GetMarkedObjectList();
882cdf0e10cSrcweir     if( pViewData && (rMarkList.GetMarkCount() == 1) )
883cdf0e10cSrcweir     {
884cdf0e10cSrcweir         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
885cdf0e10cSrcweir         if( ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, pViewData->GetTabNo() ) )
886cdf0e10cSrcweir         {
887cdf0e10cSrcweir             if( ppCaptData ) *ppCaptData = pCaptData;
888cdf0e10cSrcweir             return pObj;
889cdf0e10cSrcweir         }
890cdf0e10cSrcweir     }
891cdf0e10cSrcweir     return 0;
892cdf0e10cSrcweir }
893cdf0e10cSrcweir 
LockCalcLayer(SdrLayerID nLayer,bool bLock)894cdf0e10cSrcweir void ScDrawView::LockCalcLayer( SdrLayerID nLayer, bool bLock )
895cdf0e10cSrcweir {
896cdf0e10cSrcweir     SdrLayer* pLockLayer = GetModel()->GetLayerAdmin().GetLayerPerID( nLayer );
897cdf0e10cSrcweir     if( pLockLayer && (IsLayerLocked( pLockLayer->GetName() ) != bLock) )
898cdf0e10cSrcweir         SetLayerLocked( pLockLayer->GetName(), bLock );
899cdf0e10cSrcweir }
900cdf0e10cSrcweir 
MakeVisible(const Rectangle & rRect,Window & rWin)901cdf0e10cSrcweir void __EXPORT ScDrawView::MakeVisible( const Rectangle& rRect, Window& rWin )
902cdf0e10cSrcweir {
903cdf0e10cSrcweir     //! rWin richtig auswerten
904cdf0e10cSrcweir     //! ggf Zoom aendern
905cdf0e10cSrcweir 
906cdf0e10cSrcweir     if ( pViewData && pViewData->GetActiveWin() == &rWin )
907cdf0e10cSrcweir         pViewData->GetView()->MakeVisible( rRect );
908cdf0e10cSrcweir }
909cdf0e10cSrcweir 
DeleteMarked()910cdf0e10cSrcweir void ScDrawView::DeleteMarked()
911cdf0e10cSrcweir {
912cdf0e10cSrcweir     // try to delete a note caption object with its cell note in the Calc document
913cdf0e10cSrcweir     ScDrawObjData* pCaptData = 0;
914cdf0e10cSrcweir     if( SdrObject* pCaptObj = GetMarkedNoteCaption( &pCaptData ) )
915cdf0e10cSrcweir     {
916cdf0e10cSrcweir         (void)pCaptObj; // prevent 'unused variable' compiler warning in pro builds
917cdf0e10cSrcweir         ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
918cdf0e10cSrcweir         ScDocShell* pDocShell = pViewData ? pViewData->GetDocShell() : 0;
919cdf0e10cSrcweir         ::svl::IUndoManager* pUndoMgr = pDocShell ? pDocShell->GetUndoManager() : 0;
920cdf0e10cSrcweir         bool bUndo = pDrawLayer && pDocShell && pUndoMgr && pDoc->IsUndoEnabled();
921cdf0e10cSrcweir 
922cdf0e10cSrcweir         // remove the cell note from document, we are its owner now
923cdf0e10cSrcweir         ScPostIt* pNote = pDoc->ReleaseNote( pCaptData->maStart );
924cdf0e10cSrcweir         DBG_ASSERT( pNote, "ScDrawView::DeleteMarked - cell note missing in document" );
925cdf0e10cSrcweir         if( pNote )
926cdf0e10cSrcweir         {
927cdf0e10cSrcweir             // rescue note data for undo (with pointer to caption object)
928cdf0e10cSrcweir             ScNoteData aNoteData = pNote->GetNoteData();
929cdf0e10cSrcweir             DBG_ASSERT( aNoteData.mpCaption == pCaptObj, "ScDrawView::DeleteMarked - caption object does not match" );
930cdf0e10cSrcweir             // collect the drawing undo action created while deleting the note
931cdf0e10cSrcweir             if( bUndo )
932a840a559SArmin Le Grand                 pDrawLayer->BeginCalcUndo(false);
933cdf0e10cSrcweir             // delete the note (already removed from document above)
934cdf0e10cSrcweir             delete pNote;
935cdf0e10cSrcweir             // add the undo action for the note
936cdf0e10cSrcweir             if( bUndo )
937cdf0e10cSrcweir                 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, pCaptData->maStart, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
938cdf0e10cSrcweir             // repaint the cell to get rid of the note marker
939cdf0e10cSrcweir             if( pDocShell )
940cdf0e10cSrcweir                 pDocShell->PostPaintCell( pCaptData->maStart );
941cdf0e10cSrcweir             // done, return now to skip call of FmFormView::DeleteMarked()
942cdf0e10cSrcweir             return;
943cdf0e10cSrcweir         }
944cdf0e10cSrcweir     }
945cdf0e10cSrcweir 
946cdf0e10cSrcweir     FmFormView::DeleteMarked();
947cdf0e10cSrcweir }
948cdf0e10cSrcweir 
ScEndTextEdit()949cdf0e10cSrcweir SdrEndTextEditKind ScDrawView::ScEndTextEdit()
950cdf0e10cSrcweir {
951cdf0e10cSrcweir     sal_Bool bIsTextEdit = IsTextEdit();
952cdf0e10cSrcweir     SdrEndTextEditKind eKind = SdrEndTextEdit();
953cdf0e10cSrcweir 
954cdf0e10cSrcweir     if ( bIsTextEdit && pViewData )
955cdf0e10cSrcweir         pViewData->GetViewShell()->SetDrawTextUndo(NULL);   // "normaler" Undo-Manager
956cdf0e10cSrcweir 
957cdf0e10cSrcweir     return eKind;
958cdf0e10cSrcweir }
959cdf0e10cSrcweir 
MarkDropObj(SdrObject * pObj)960cdf0e10cSrcweir void ScDrawView::MarkDropObj( SdrObject* pObj )
961cdf0e10cSrcweir {
962cdf0e10cSrcweir     if ( pDropMarkObj != pObj )
963cdf0e10cSrcweir     {
964cdf0e10cSrcweir         pDropMarkObj = pObj;
965cdf0e10cSrcweir         ImplClearCalcDropMarker();
966cdf0e10cSrcweir 
967cdf0e10cSrcweir         if(pDropMarkObj)
968cdf0e10cSrcweir         {
969cdf0e10cSrcweir             pDropMarker = new SdrDropMarkerOverlay(*this, *pDropMarkObj);
970cdf0e10cSrcweir         }
971cdf0e10cSrcweir     }
972cdf0e10cSrcweir }
973cdf0e10cSrcweir 
97414af77b6SArmin Le Grand // support enhanced text edit for draw objects
getSdrUndoManagerForEnhancedTextEdit() const97514af77b6SArmin Le Grand SdrUndoManager* ScDrawView::getSdrUndoManagerForEnhancedTextEdit() const
97614af77b6SArmin Le Grand {
97714af77b6SArmin Le Grand     return pDoc ? dynamic_cast< SdrUndoManager* >(pDoc->GetUndoManager()) : 0;
97814af77b6SArmin Le Grand }
97914af77b6SArmin Le Grand 
98052f1c2eeSArmin Le Grand // #123922# helper to apply a Graphic to an existing SdrObject
ApplyGraphicToObject(SdrObject & rHitObject,const Graphic & rGraphic,const String & rBeginUndoText,const String & rFile,const String & rFilter)98152f1c2eeSArmin Le Grand SdrObject* ScDrawView::ApplyGraphicToObject(
98252f1c2eeSArmin Le Grand     SdrObject& rHitObject,
98352f1c2eeSArmin Le Grand     const Graphic& rGraphic,
98452f1c2eeSArmin Le Grand     const String& rBeginUndoText,
98552f1c2eeSArmin Le Grand     const String& rFile,
98652f1c2eeSArmin Le Grand     const String& rFilter)
98752f1c2eeSArmin Le Grand {
98852f1c2eeSArmin Le Grand     if(dynamic_cast< SdrGrafObj* >(&rHitObject))
98952f1c2eeSArmin Le Grand     {
99052f1c2eeSArmin Le Grand         SdrGrafObj* pNewGrafObj = (SdrGrafObj*)rHitObject.Clone();
99152f1c2eeSArmin Le Grand 
99252f1c2eeSArmin Le Grand         pNewGrafObj->SetGraphic(rGraphic);
99352f1c2eeSArmin Le Grand         BegUndo(rBeginUndoText);
99452f1c2eeSArmin Le Grand         ReplaceObjectAtView(&rHitObject, *GetSdrPageView(), pNewGrafObj);
99552f1c2eeSArmin Le Grand 
99652f1c2eeSArmin Le Grand         // set in all cases - the Clone() will have copied an existing link (!)
99752f1c2eeSArmin Le Grand         pNewGrafObj->SetGraphicLink( rFile, rFilter );
99852f1c2eeSArmin Le Grand 
99952f1c2eeSArmin Le Grand         EndUndo();
100052f1c2eeSArmin Le Grand         return pNewGrafObj;
100152f1c2eeSArmin Le Grand     }
100252f1c2eeSArmin Le Grand     else if(rHitObject.IsClosedObj() && !dynamic_cast< SdrOle2Obj* >(&rHitObject))
100352f1c2eeSArmin Le Grand     {
100452f1c2eeSArmin Le Grand         AddUndo(new SdrUndoAttrObj(rHitObject));
100552f1c2eeSArmin Le Grand 
100652f1c2eeSArmin Le Grand         SfxItemSet aSet(GetModel()->GetItemPool(), XATTR_FILLSTYLE, XATTR_FILLBITMAP);
100752f1c2eeSArmin Le Grand 
100852f1c2eeSArmin Le Grand         aSet.Put(XFillStyleItem(XFILL_BITMAP));
100952f1c2eeSArmin Le Grand         aSet.Put(XFillBitmapItem(String(), rGraphic));
101052f1c2eeSArmin Le Grand         rHitObject.SetMergedItemSetAndBroadcast(aSet);
101152f1c2eeSArmin Le Grand         return &rHitObject;
101252f1c2eeSArmin Le Grand     }
101352f1c2eeSArmin Le Grand 
1014*4d40bd34SHerbert Dürr     return NULL;
101552f1c2eeSArmin Le Grand }
101652f1c2eeSArmin Le Grand 
101714af77b6SArmin Le Grand // eof
1018