xref: /trunk/main/sc/source/core/data/drwlayer.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 #include <com/sun/star/uno/Reference.hxx>
27cdf0e10cSrcweir #include <com/sun/star/chart/XChartDocument.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedObject.hpp>
29cdf0e10cSrcweir #include <com/sun/star/embed/XVisualObject.hpp>
30cdf0e10cSrcweir #include <com/sun/star/embed/XClassifiedObject.hpp>
31cdf0e10cSrcweir #include <com/sun/star/embed/XComponentSupplier.hpp>
32cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
33cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
34cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
35cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "scitems.hxx"
40cdf0e10cSrcweir #include <editeng/eeitem.hxx>
41cdf0e10cSrcweir #include <editeng/frmdiritem.hxx>
42cdf0e10cSrcweir #include <sot/exchange.hxx>
43cdf0e10cSrcweir #include <svx/objfac3d.hxx>
44cdf0e10cSrcweir #include <svx/xtable.hxx>
45cdf0e10cSrcweir #include <svx/svdoutl.hxx>
46cdf0e10cSrcweir #include <svx/svditer.hxx>
47cdf0e10cSrcweir #include <svx/svdocapt.hxx>
48cdf0e10cSrcweir #include <svx/svdocirc.hxx>
49cdf0e10cSrcweir #include <svx/svdoedge.hxx>
50cdf0e10cSrcweir #include <svx/svdograf.hxx>
51cdf0e10cSrcweir #include <svx/svdoole2.hxx>
52cdf0e10cSrcweir #include <svx/svdundo.hxx>
53cdf0e10cSrcweir #include <editeng/unolingu.hxx>
54cdf0e10cSrcweir #include <svx/drawitem.hxx>
55cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
56cdf0e10cSrcweir #include <editeng/scriptspaceitem.hxx>
57cdf0e10cSrcweir #include <svx/shapepropertynotifier.hxx>
58cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
59cdf0e10cSrcweir #include <sfx2/docfile.hxx>
60cdf0e10cSrcweir #include <sot/storage.hxx>
61cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
62cdf0e10cSrcweir #include <svl/itempool.hxx>
63cdf0e10cSrcweir #include <vcl/virdev.hxx>
64cdf0e10cSrcweir #include <vcl/svapp.hxx>
65cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
66cdf0e10cSrcweir 
67cdf0e10cSrcweir #include "drwlayer.hxx"
68cdf0e10cSrcweir #include "drawpage.hxx"
69cdf0e10cSrcweir #include "global.hxx"
70cdf0e10cSrcweir #include "document.hxx"
71cdf0e10cSrcweir #include "rechead.hxx"
72cdf0e10cSrcweir #include "userdat.hxx"
73cdf0e10cSrcweir #include "markdata.hxx"
74cdf0e10cSrcweir #include "globstr.hrc"
75cdf0e10cSrcweir #include "scmod.hxx"
76cdf0e10cSrcweir #include "chartarr.hxx"
77cdf0e10cSrcweir #include "postit.hxx"
78cdf0e10cSrcweir #include "attrib.hxx"
79cdf0e10cSrcweir #include "charthelper.hxx"
80cdf0e10cSrcweir 
81cdf0e10cSrcweir #define DET_ARROW_OFFSET    1000
82cdf0e10cSrcweir 
83cdf0e10cSrcweir //  Abstand zur naechsten Zelle beim Loeschen (bShrink), damit der Anker
84cdf0e10cSrcweir //  immer an der richtigen Zelle angezeigt wird
85cdf0e10cSrcweir //#define SHRINK_DIST       3
86cdf0e10cSrcweir //  und noch etwas mehr, damit das Objekt auch sichtbar in der Zelle liegt
87cdf0e10cSrcweir #define SHRINK_DIST     25
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #define SHRINK_DIST_TWIPS   15
90cdf0e10cSrcweir 
91cdf0e10cSrcweir using namespace ::com::sun::star;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
94cdf0e10cSrcweir 
95cdf0e10cSrcweir TYPEINIT1(ScTabDeletedHint, SfxHint);
96cdf0e10cSrcweir TYPEINIT1(ScTabSizeChangedHint, SfxHint);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir static ScDrawObjFactory* pFac = NULL;
99cdf0e10cSrcweir static E3dObjFactory* pF3d = NULL;
100cdf0e10cSrcweir static sal_uInt16 nInst = 0;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir SfxObjectShell* ScDrawLayer::pGlobalDrawPersist = NULL;
103cdf0e10cSrcweir //REMOVE    SvPersist* ScDrawLayer::pGlobalDrawPersist = NULL;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir sal_Bool bDrawIsInUndo = sal_False;         //! Member
106cdf0e10cSrcweir 
107cdf0e10cSrcweir // -----------------------------------------------------------------------
108cdf0e10cSrcweir 
ScUndoObjData(SdrObject * pObjP,const ScAddress & rOS,const ScAddress & rOE,const ScAddress & rNS,const ScAddress & rNE)109cdf0e10cSrcweir ScUndoObjData::ScUndoObjData( SdrObject* pObjP, const ScAddress& rOS, const ScAddress& rOE,
110cdf0e10cSrcweir                                                const ScAddress& rNS, const ScAddress& rNE ) :
111cdf0e10cSrcweir     SdrUndoObj( *pObjP ),
112cdf0e10cSrcweir     aOldStt( rOS ),
113cdf0e10cSrcweir     aOldEnd( rOE ),
114cdf0e10cSrcweir     aNewStt( rNS ),
115cdf0e10cSrcweir     aNewEnd( rNE )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
~ScUndoObjData()119cdf0e10cSrcweir __EXPORT ScUndoObjData::~ScUndoObjData()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
Undo()123cdf0e10cSrcweir void ScUndoObjData::Undo()
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     ScDrawObjData* pData = ScDrawLayer::GetObjData( pObj );
126cdf0e10cSrcweir     DBG_ASSERT(pData,"ScUndoObjData: Daten nicht da");
127cdf0e10cSrcweir     if (pData)
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         pData->maStart = aOldStt;
130cdf0e10cSrcweir         pData->maEnd = aOldEnd;
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
Redo()134cdf0e10cSrcweir void __EXPORT ScUndoObjData::Redo()
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     ScDrawObjData* pData = ScDrawLayer::GetObjData( pObj );
137cdf0e10cSrcweir     DBG_ASSERT(pData,"ScUndoObjData: Daten nicht da");
138cdf0e10cSrcweir     if (pData)
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         pData->maStart = aNewStt;
141cdf0e10cSrcweir         pData->maEnd = aNewEnd;
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir // -----------------------------------------------------------------------
146cdf0e10cSrcweir 
ScTabDeletedHint(SCTAB nTabNo)147cdf0e10cSrcweir ScTabDeletedHint::ScTabDeletedHint( SCTAB nTabNo ) :
148cdf0e10cSrcweir     nTab( nTabNo )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
~ScTabDeletedHint()152cdf0e10cSrcweir __EXPORT ScTabDeletedHint::~ScTabDeletedHint()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
ScTabSizeChangedHint(SCTAB nTabNo)156cdf0e10cSrcweir ScTabSizeChangedHint::ScTabSizeChangedHint( SCTAB nTabNo ) :
157cdf0e10cSrcweir     nTab( nTabNo )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
~ScTabSizeChangedHint()161cdf0e10cSrcweir __EXPORT ScTabSizeChangedHint::~ScTabSizeChangedHint()
162cdf0e10cSrcweir {
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir // -----------------------------------------------------------------------
166cdf0e10cSrcweir 
167cdf0e10cSrcweir #define MAXMM   10000000
168cdf0e10cSrcweir 
TwipsToMM(long & nVal)169cdf0e10cSrcweir inline void TwipsToMM( long& nVal )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     nVal = (long) ( nVal * HMM_PER_TWIPS );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
ReverseTwipsToMM(long & nVal)174cdf0e10cSrcweir inline void ReverseTwipsToMM( long& nVal )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     //  reverse the effect of TwipsToMM - round up here (add 1)
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     nVal = ((long) ( nVal / HMM_PER_TWIPS )) + 1;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
lcl_TwipsToMM(Point & rPoint)181cdf0e10cSrcweir void lcl_TwipsToMM( Point& rPoint )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     TwipsToMM( rPoint.X() );
184cdf0e10cSrcweir     TwipsToMM( rPoint.Y() );
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
lcl_ReverseTwipsToMM(Point & rPoint)187cdf0e10cSrcweir void lcl_ReverseTwipsToMM( Point& rPoint )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     ReverseTwipsToMM( rPoint.X() );
190cdf0e10cSrcweir     ReverseTwipsToMM( rPoint.Y() );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
lcl_ReverseTwipsToMM(Rectangle & rRect)193cdf0e10cSrcweir void lcl_ReverseTwipsToMM( Rectangle& rRect )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     ReverseTwipsToMM( rRect.Left() );
196cdf0e10cSrcweir     ReverseTwipsToMM( rRect.Right() );
197cdf0e10cSrcweir     ReverseTwipsToMM( rRect.Top() );
198cdf0e10cSrcweir     ReverseTwipsToMM( rRect.Bottom() );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // -----------------------------------------------------------------------
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 
ScDrawLayer(ScDocument * pDocument,const String & rName)204cdf0e10cSrcweir ScDrawLayer::ScDrawLayer( ScDocument* pDocument, const String& rName ) :
205cdf0e10cSrcweir     FmFormModel( SvtPathOptions().GetPalettePath(),
206cdf0e10cSrcweir                  NULL,                          // SfxItemPool* Pool
207cdf0e10cSrcweir                  pGlobalDrawPersist ?
208cdf0e10cSrcweir                     pGlobalDrawPersist :
209c7be74b1SArmin Le Grand                     ( pDocument ? pDocument->GetDocumentShell() : NULL )),
210cdf0e10cSrcweir     aName( rName ),
211cdf0e10cSrcweir     pDoc( pDocument ),
212cdf0e10cSrcweir     pUndoGroup( NULL ),
213cdf0e10cSrcweir     bRecording( sal_False ),
214cdf0e10cSrcweir     bAdjustEnabled( sal_True ),
215577c0052SWang Lei     bHyphenatorSet( sal_False ),
216577c0052SWang Lei         mbUndoAllowed( sal_True )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     pGlobalDrawPersist = NULL;          // nur einmal benutzen
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     SfxObjectShell* pObjSh = pDocument ? pDocument->GetDocumentShell() : NULL;
221cdf0e10cSrcweir     if ( pObjSh )
222cdf0e10cSrcweir     {
223cdf0e10cSrcweir         SetObjectShell( pObjSh );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         // set color table
226c7be74b1SArmin Le Grand         const SvxColorTableItem* pColItem = static_cast< const SvxColorTableItem* >(pObjSh->GetItem( SID_COLOR_TABLE ));
227c7be74b1SArmin Le Grand         XColorListSharedPtr aXCol = pColItem ? pColItem->GetColorTable() : XColorList::GetStdColorList();
228c7be74b1SArmin Le Grand         SetColorTableAtSdrModel( aXCol );
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir     else
231c7be74b1SArmin Le Grand         SetColorTableAtSdrModel( XColorList::GetStdColorList() );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     SetSwapGraphics(sal_True);
234cdf0e10cSrcweir //  SetSwapAsynchron(sal_True);     // an der View
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     SetScaleUnit(MAP_100TH_MM);
237cdf0e10cSrcweir     SfxItemPool& rPool = GetItemPool();
238cdf0e10cSrcweir     rPool.SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
239cdf0e10cSrcweir     SvxFrameDirectionItem aModeItem( FRMDIR_ENVIRONMENT, EE_PARA_WRITINGDIR );
240cdf0e10cSrcweir     rPool.SetPoolDefaultItem( aModeItem );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     // #i33700#
243cdf0e10cSrcweir     // Set shadow distance defaults as PoolDefaultItems. Details see bug.
244cdf0e10cSrcweir     rPool.SetPoolDefaultItem(SdrShadowXDistItem(300));
245cdf0e10cSrcweir     rPool.SetPoolDefaultItem(SdrShadowYDistItem(300));
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     // #111216# default for script spacing depends on locale, see SdDrawDocument ctor in sd
248cdf0e10cSrcweir     LanguageType eOfficeLanguage = Application::GetSettings().GetLanguage();
249cdf0e10cSrcweir     if ( eOfficeLanguage == LANGUAGE_KOREAN || eOfficeLanguage == LANGUAGE_KOREAN_JOHAB ||
250cdf0e10cSrcweir          eOfficeLanguage == LANGUAGE_JAPANESE )
251cdf0e10cSrcweir     {
252cdf0e10cSrcweir         // secondary is edit engine pool
253cdf0e10cSrcweir         rPool.GetSecondaryPool()->SetPoolDefaultItem( SvxScriptSpaceItem( sal_False, EE_PARA_ASIANCJKSPACING ) );
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     rPool.FreezeIdRanges();                         // the pool is also used directly
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     SdrLayerAdmin& rAdmin = GetLayerAdmin();
259cdf0e10cSrcweir     rAdmin.NewLayer(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("vorne")),    SC_LAYER_FRONT);
260cdf0e10cSrcweir     rAdmin.NewLayer(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("hinten")),   SC_LAYER_BACK);
261cdf0e10cSrcweir     rAdmin.NewLayer(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("intern")),   SC_LAYER_INTERN);
262cdf0e10cSrcweir     rAdmin.NewLayer(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Controls")), SC_LAYER_CONTROLS);
263cdf0e10cSrcweir     rAdmin.NewLayer(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("hidden")),   SC_LAYER_HIDDEN);
264cdf0e10cSrcweir     // "Controls" is new - must also be created when loading
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     //  Link fuer URL-Fields setzen
267cdf0e10cSrcweir     ScModule* pScMod = SC_MOD();
268cdf0e10cSrcweir     Outliner& rOutliner = GetDrawOutliner();
269cdf0e10cSrcweir     rOutliner.SetCalcFieldValueHdl( LINK( pScMod, ScModule, CalcFieldValueHdl ) );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     Outliner& rHitOutliner = GetHitTestOutliner();
272cdf0e10cSrcweir     rHitOutliner.SetCalcFieldValueHdl( LINK( pScMod, ScModule, CalcFieldValueHdl ) );
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     // #95129# SJ: set FontHeight pool defaults without changing static SdrEngineDefaults
275cdf0e10cSrcweir     SfxItemPool* pOutlinerPool = rOutliner.GetEditTextObjectPool();
276cdf0e10cSrcweir     if ( pOutlinerPool )
277*15be5a03STsutomu Uchino     {
278cdf0e10cSrcweir         pItemPool->SetPoolDefaultItem(SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ));           // 12Pt
279*15be5a03STsutomu Uchino         pItemPool->SetPoolDefaultItem(SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT_CJK ));           // 12Pt
280*15be5a03STsutomu Uchino     }
281cdf0e10cSrcweir     SfxItemPool* pHitOutlinerPool = rHitOutliner.GetEditTextObjectPool();
282cdf0e10cSrcweir     if ( pHitOutlinerPool )
283*15be5a03STsutomu Uchino     {
284cdf0e10cSrcweir         pHitOutlinerPool->SetPoolDefaultItem(SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ));    // 12Pt
285*15be5a03STsutomu Uchino         pHitOutlinerPool->SetPoolDefaultItem(SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT_CJK ));    // 12Pt
286*15be5a03STsutomu Uchino     }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     // initial undo mode as in Calc document
289cdf0e10cSrcweir     if( pDoc )
290cdf0e10cSrcweir         EnableUndo( pDoc->IsUndoEnabled() );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     //  URL-Buttons haben keinen Handler mehr, machen alles selber
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     if( !nInst++ )
295cdf0e10cSrcweir     {
296cdf0e10cSrcweir         pFac = new ScDrawObjFactory;
297cdf0e10cSrcweir         pF3d = new E3dObjFactory;
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
~ScDrawLayer()301cdf0e10cSrcweir __EXPORT ScDrawLayer::~ScDrawLayer()
302cdf0e10cSrcweir {
303cdf0e10cSrcweir     Broadcast(SdrHint(HINT_MODELCLEARED));
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     // #116168#
306cdf0e10cSrcweir     //Clear();
307cdf0e10cSrcweir     ClearModel(sal_True);
308cdf0e10cSrcweir 
309cdf0e10cSrcweir     delete pUndoGroup;
310cdf0e10cSrcweir     if( !--nInst )
311cdf0e10cSrcweir     {
312cdf0e10cSrcweir         delete pFac, pFac = NULL;
313cdf0e10cSrcweir         delete pF3d, pF3d = NULL;
314cdf0e10cSrcweir     }
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
UseHyphenator()317cdf0e10cSrcweir void ScDrawLayer::UseHyphenator()
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     if (!bHyphenatorSet)
320cdf0e10cSrcweir     {
321cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::linguistic2::XHyphenator >
322cdf0e10cSrcweir                                     xHyphenator = LinguMgr::GetHyphenator();
323cdf0e10cSrcweir 
324cdf0e10cSrcweir         GetDrawOutliner().SetHyphenator( xHyphenator );
325cdf0e10cSrcweir         GetHitTestOutliner().SetHyphenator( xHyphenator );
326cdf0e10cSrcweir 
327cdf0e10cSrcweir         bHyphenatorSet = sal_True;
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
AllocPage(FASTBOOL bMasterPage)331cdf0e10cSrcweir SdrPage* __EXPORT ScDrawLayer::AllocPage(FASTBOOL bMasterPage)
332cdf0e10cSrcweir {
333cdf0e10cSrcweir     //  don't create basic until it is needed
334cdf0e10cSrcweir     StarBASIC* pBasic = NULL;
335cdf0e10cSrcweir     ScDrawPage* pPage = new ScDrawPage( *this, pBasic, sal::static_int_cast<sal_Bool>(bMasterPage) );
336cdf0e10cSrcweir     return pPage;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
HasObjects() const339cdf0e10cSrcweir sal_Bool ScDrawLayer::HasObjects() const
340cdf0e10cSrcweir {
341cdf0e10cSrcweir     sal_Bool bFound = sal_False;
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     sal_uInt16 nCount = GetPageCount();
344cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nCount && !bFound; i++)
345cdf0e10cSrcweir         if (GetPage(i)->GetObjCount())
346cdf0e10cSrcweir             bFound = sal_True;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     return bFound;
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
UpdateBasic()351cdf0e10cSrcweir void ScDrawLayer::UpdateBasic()
352cdf0e10cSrcweir {
353cdf0e10cSrcweir     //  don't create basic until it is needed
354cdf0e10cSrcweir     //! remove this method?
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
AllocModel() const357cdf0e10cSrcweir SdrModel* __EXPORT ScDrawLayer::AllocModel() const
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     //  #103849# Allocated model (for clipboard etc) must not have a pointer
360cdf0e10cSrcweir     //  to the original model's document, pass NULL as document:
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     return new ScDrawLayer( NULL, aName );
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
GetCurDocViewWin()365cdf0e10cSrcweir Window* __EXPORT ScDrawLayer::GetCurDocViewWin()
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::GetCurDocViewWin without document" );
368cdf0e10cSrcweir     if ( !pDoc )
369cdf0e10cSrcweir         return NULL;
370cdf0e10cSrcweir 
371cdf0e10cSrcweir     SfxViewShell* pViewSh = SfxViewShell::Current();
372cdf0e10cSrcweir     SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     if (pViewSh && pViewSh->GetObjectShell() == pObjSh)
375cdf0e10cSrcweir         return pViewSh->GetWindow();
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     return NULL;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir 
ScAddPage(SCTAB nTab)380cdf0e10cSrcweir sal_Bool ScDrawLayer::ScAddPage( SCTAB nTab )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir     if (bDrawIsInUndo)
383cdf0e10cSrcweir         return sal_False;   // not inserted
384cdf0e10cSrcweir 
385cdf0e10cSrcweir     ScDrawPage* pPage = (ScDrawPage*)AllocPage( sal_False );
386cdf0e10cSrcweir     InsertPage(pPage, static_cast<sal_uInt16>(nTab));
387cdf0e10cSrcweir     if (bRecording)
388577c0052SWang Lei             AddCalcUndo< SdrUndoNewPage >(*pPage);
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     return sal_True;        // inserted
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
ScRemovePage(SCTAB nTab)393cdf0e10cSrcweir void ScDrawLayer::ScRemovePage( SCTAB nTab )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir     if (bDrawIsInUndo)
396cdf0e10cSrcweir         return;
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     Broadcast( ScTabDeletedHint( nTab ) );
399cdf0e10cSrcweir     if (bRecording)
400cdf0e10cSrcweir     {
401cdf0e10cSrcweir         SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
402577c0052SWang Lei         AddCalcUndo< SdrUndoDelPage >(*pPage);      // Undo-Action wird Owner der Page
403cdf0e10cSrcweir         RemovePage( static_cast<sal_uInt16>(nTab) );                            // nur austragen, nicht loeschen
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir     else
406cdf0e10cSrcweir         DeletePage( static_cast<sal_uInt16>(nTab) );                            // einfach weg damit
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
ScRenamePage(SCTAB nTab,const String & rNewName)409cdf0e10cSrcweir void ScDrawLayer::ScRenamePage( SCTAB nTab, const String& rNewName )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir     ScDrawPage* pPage = (ScDrawPage*) GetPage(static_cast<sal_uInt16>(nTab));
412cdf0e10cSrcweir     if (pPage)
413cdf0e10cSrcweir         pPage->SetName(rNewName);
414cdf0e10cSrcweir }
415cdf0e10cSrcweir 
ScMovePage(sal_uInt16 nOldPos,sal_uInt16 nNewPos)416cdf0e10cSrcweir void ScDrawLayer::ScMovePage( sal_uInt16 nOldPos, sal_uInt16 nNewPos )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir     MovePage( nOldPos, nNewPos );
419cdf0e10cSrcweir }
420cdf0e10cSrcweir 
ScCopyPage(sal_uInt16 nOldPos,sal_uInt16 nNewPos,sal_Bool bAlloc)421cdf0e10cSrcweir void ScDrawLayer::ScCopyPage( sal_uInt16 nOldPos, sal_uInt16 nNewPos, sal_Bool bAlloc )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir     //! remove argument bAlloc (always sal_False)
424cdf0e10cSrcweir 
425cdf0e10cSrcweir     if (bDrawIsInUndo)
426cdf0e10cSrcweir         return;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     SdrPage* pOldPage = GetPage(nOldPos);
429cdf0e10cSrcweir     SdrPage* pNewPage = bAlloc ? AllocPage(sal_False) : GetPage(nNewPos);
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     // kopieren
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     if (pOldPage && pNewPage)
434cdf0e10cSrcweir     {
435cdf0e10cSrcweir         SdrObjListIter aIter( *pOldPage, IM_FLAT );
436cdf0e10cSrcweir         SdrObject* pOldObject = aIter.Next();
437cdf0e10cSrcweir         while (pOldObject)
438cdf0e10cSrcweir         {
439cdf0e10cSrcweir             // #i112034# do not copy internal objects (detective) and note captions
440cdf0e10cSrcweir             if ( pOldObject->GetLayer() != SC_LAYER_INTERN && !IsNoteCaption( pOldObject ) )
441cdf0e10cSrcweir             {
442cdf0e10cSrcweir                 // #116235#
443cdf0e10cSrcweir                 SdrObject* pNewObject = pOldObject->Clone();
444cdf0e10cSrcweir                 //SdrObject* pNewObject = pOldObject->Clone( pNewPage, this );
445cdf0e10cSrcweir                 pNewObject->SetModel(this);
446cdf0e10cSrcweir                 pNewObject->SetPage(pNewPage);
447cdf0e10cSrcweir 
448cdf0e10cSrcweir                 pNewObject->NbcMove(Size(0,0));
449cdf0e10cSrcweir                 pNewPage->InsertObject( pNewObject );
450cdf0e10cSrcweir                 if (bRecording)
451577c0052SWang Lei                     AddCalcUndo< SdrUndoInsertObj >( *pNewObject );
452cdf0e10cSrcweir             }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir             pOldObject = aIter.Next();
455cdf0e10cSrcweir         }
456cdf0e10cSrcweir     }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     if (bAlloc)
459cdf0e10cSrcweir         InsertPage(pNewPage, nNewPos);
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
IsInBlock(const ScAddress & rPos,SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2)462cdf0e10cSrcweir inline sal_Bool IsInBlock( const ScAddress& rPos, SCCOL nCol1,SCROW nRow1, SCCOL nCol2,SCROW nRow2 )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir     return rPos.Col() >= nCol1 && rPos.Col() <= nCol2 &&
465cdf0e10cSrcweir            rPos.Row() >= nRow1 && rPos.Row() <= nRow2;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
MoveCells(SCTAB nTab,SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2,SCsCOL nDx,SCsROW nDy,bool bUpdateNoteCaptionPos)468cdf0e10cSrcweir void ScDrawLayer::MoveCells( SCTAB nTab, SCCOL nCol1,SCROW nRow1, SCCOL nCol2,SCROW nRow2,
469cdf0e10cSrcweir                                 SCsCOL nDx,SCsROW nDy, bool bUpdateNoteCaptionPos )
470cdf0e10cSrcweir {
471cdf0e10cSrcweir     SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
472cdf0e10cSrcweir     DBG_ASSERT(pPage,"Page nicht gefunden");
473cdf0e10cSrcweir     if (!pPage)
474cdf0e10cSrcweir         return;
475cdf0e10cSrcweir 
476cdf0e10cSrcweir     sal_Bool bNegativePage = pDoc && pDoc->IsNegativePage( nTab );
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     sal_uLong nCount = pPage->GetObjCount();
479cdf0e10cSrcweir     for ( sal_uLong i = 0; i < nCount; i++ )
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         SdrObject* pObj = pPage->GetObj( i );
482cdf0e10cSrcweir         ScDrawObjData* pData = GetObjDataTab( pObj, nTab );
483cdf0e10cSrcweir         if( pData )
484cdf0e10cSrcweir         {
485cdf0e10cSrcweir             const ScAddress aOldStt = pData->maStart;
486cdf0e10cSrcweir             const ScAddress aOldEnd = pData->maEnd;
487cdf0e10cSrcweir             sal_Bool bChange = sal_False;
488cdf0e10cSrcweir             if ( aOldStt.IsValid() && IsInBlock( aOldStt, nCol1,nRow1, nCol2,nRow2 ) )
489cdf0e10cSrcweir             {
490cdf0e10cSrcweir                 pData->maStart.IncCol( nDx );
491cdf0e10cSrcweir                 pData->maStart.IncRow( nDy );
492cdf0e10cSrcweir                 bChange = sal_True;
493cdf0e10cSrcweir             }
494cdf0e10cSrcweir             if ( aOldEnd.IsValid() && IsInBlock( aOldEnd, nCol1,nRow1, nCol2,nRow2 ) )
495cdf0e10cSrcweir             {
496cdf0e10cSrcweir                 pData->maEnd.IncCol( nDx );
497cdf0e10cSrcweir                 pData->maEnd.IncRow( nDy );
498cdf0e10cSrcweir                 bChange = sal_True;
499cdf0e10cSrcweir             }
500cdf0e10cSrcweir             if (bChange)
501cdf0e10cSrcweir             {
502cdf0e10cSrcweir                 if ( pObj->ISA( SdrRectObj ) && pData->maStart.IsValid() && pData->maEnd.IsValid() )
503cdf0e10cSrcweir                     pData->maStart.PutInOrder( pData->maEnd );
504577c0052SWang Lei                 AddCalcUndo< ScUndoObjData >( pObj, aOldStt, aOldEnd, pData->maStart, pData->maEnd );
505cdf0e10cSrcweir                 RecalcPos( pObj, *pData, bNegativePage, bUpdateNoteCaptionPos );
506cdf0e10cSrcweir             }
507cdf0e10cSrcweir         }
508cdf0e10cSrcweir     }
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
SetPageSize(sal_uInt16 nPageNo,const Size & rSize,bool bUpdateNoteCaptionPos)511cdf0e10cSrcweir void ScDrawLayer::SetPageSize( sal_uInt16 nPageNo, const Size& rSize, bool bUpdateNoteCaptionPos )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir     SdrPage* pPage = GetPage(nPageNo);
514cdf0e10cSrcweir     if (pPage)
515cdf0e10cSrcweir     {
516cdf0e10cSrcweir         if ( rSize != pPage->GetSize() )
517cdf0e10cSrcweir         {
518cdf0e10cSrcweir             pPage->SetSize( rSize );
519cdf0e10cSrcweir             Broadcast( ScTabSizeChangedHint( static_cast<SCTAB>(nPageNo) ) );   // SetWorkArea() an den Views
520cdf0e10cSrcweir         }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir         // Detektivlinien umsetzen (an neue Hoehen/Breiten anpassen)
523cdf0e10cSrcweir         //  auch wenn Groesse gleich geblieben ist
524cdf0e10cSrcweir         //  (einzelne Zeilen/Spalten koennen geaendert sein)
525cdf0e10cSrcweir 
526cdf0e10cSrcweir         sal_Bool bNegativePage = pDoc && pDoc->IsNegativePage( static_cast<SCTAB>(nPageNo) );
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         sal_uLong nCount = pPage->GetObjCount();
529cdf0e10cSrcweir         for ( sal_uLong i = 0; i < nCount; i++ )
530cdf0e10cSrcweir         {
531cdf0e10cSrcweir             SdrObject* pObj = pPage->GetObj( i );
532cdf0e10cSrcweir             ScDrawObjData* pData = GetObjDataTab( pObj, static_cast<SCTAB>(nPageNo) );
533cdf0e10cSrcweir             if( pData )
534cdf0e10cSrcweir                 RecalcPos( pObj, *pData, bNegativePage, bUpdateNoteCaptionPos );
535cdf0e10cSrcweir         }
536cdf0e10cSrcweir     }
537cdf0e10cSrcweir }
538cdf0e10cSrcweir 
RecalcPos(SdrObject * pObj,const ScDrawObjData & rData,bool bNegativePage,bool bUpdateNoteCaptionPos)539cdf0e10cSrcweir void ScDrawLayer::RecalcPos( SdrObject* pObj, const ScDrawObjData& rData, bool bNegativePage, bool bUpdateNoteCaptionPos )
540cdf0e10cSrcweir {
541cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::RecalcPos - missing document" );
542cdf0e10cSrcweir     if( !pDoc )
543cdf0e10cSrcweir         return;
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     if( rData.mbNote )
546cdf0e10cSrcweir     {
547cdf0e10cSrcweir         DBG_ASSERT( rData.maStart.IsValid(), "ScDrawLayer::RecalcPos - invalid position for cell note" );
548cdf0e10cSrcweir         /*  #i109372# On insert/remove rows/columns/cells: Updating the caption
549cdf0e10cSrcweir             position must not be done, if the cell containing the note has not
550cdf0e10cSrcweir             been moved yet in the document. The calling code now passes an
551cdf0e10cSrcweir             additional boolean stating if the cells are already moved. */
552cdf0e10cSrcweir         if( bUpdateNoteCaptionPos )
553cdf0e10cSrcweir             /*  When inside an undo action, there may be pending note captions
554cdf0e10cSrcweir                 where cell note is already deleted (thus document cannot find
555cdf0e10cSrcweir                 the note object anymore). The caption will be deleted later
556cdf0e10cSrcweir                 with drawing undo. */
557cdf0e10cSrcweir             if( ScPostIt* pNote = pDoc->GetNote( rData.maStart ) )
558cdf0e10cSrcweir                 pNote->UpdateCaptionPos( rData.maStart );
559cdf0e10cSrcweir         return;
560cdf0e10cSrcweir     }
561cdf0e10cSrcweir 
562cdf0e10cSrcweir     bool bValid1 = rData.maStart.IsValid();
563cdf0e10cSrcweir     SCCOL nCol1 = rData.maStart.Col();
564cdf0e10cSrcweir     SCROW nRow1 = rData.maStart.Row();
565cdf0e10cSrcweir     SCTAB nTab1 = rData.maStart.Tab();
566cdf0e10cSrcweir     bool bValid2 = rData.maEnd.IsValid();
567cdf0e10cSrcweir     SCCOL nCol2 = rData.maEnd.Col();
568cdf0e10cSrcweir     SCROW nRow2 = rData.maEnd.Row();
569cdf0e10cSrcweir     SCTAB nTab2 = rData.maEnd.Tab();
570cdf0e10cSrcweir 
571cdf0e10cSrcweir     // validation circle
572cdf0e10cSrcweir     bool bCircle = pObj->ISA( SdrCircObj );
573cdf0e10cSrcweir     // detective arrow
574cdf0e10cSrcweir     bool bArrow = pObj->IsPolyObj() && (pObj->GetPointCount() == 2);
575cdf0e10cSrcweir 
576cdf0e10cSrcweir     if( bCircle )
577cdf0e10cSrcweir     {
578cdf0e10cSrcweir         Point aPos( pDoc->GetColOffset( nCol1, nTab1 ), pDoc->GetRowOffset( nRow1, nTab1 ) );
579cdf0e10cSrcweir         TwipsToMM( aPos.X() );
580cdf0e10cSrcweir         TwipsToMM( aPos.Y() );
581cdf0e10cSrcweir 
582cdf0e10cSrcweir         //  Berechnung und Werte wie in detfunc.cxx
583cdf0e10cSrcweir 
584cdf0e10cSrcweir         Size aSize( (long)(pDoc->GetColWidth( nCol1, nTab1 ) * HMM_PER_TWIPS),
585cdf0e10cSrcweir                     (long)(pDoc->GetRowHeight( nRow1, nTab1 ) * HMM_PER_TWIPS) );
586cdf0e10cSrcweir         Rectangle aRect( aPos, aSize );
587cdf0e10cSrcweir         aRect.Left()    -= 250;
588cdf0e10cSrcweir         aRect.Right()   += 250;
589cdf0e10cSrcweir         aRect.Top()     -= 70;
590cdf0e10cSrcweir         aRect.Bottom()  += 70;
591cdf0e10cSrcweir         if ( bNegativePage )
592cdf0e10cSrcweir             MirrorRectRTL( aRect );
593cdf0e10cSrcweir 
594cdf0e10cSrcweir         if ( pObj->GetLogicRect() != aRect )
595cdf0e10cSrcweir         {
596cdf0e10cSrcweir             if (bRecording)
597577c0052SWang Lei                         AddCalcUndo<SdrUndoGeoObj>( *pObj );
598cdf0e10cSrcweir             pObj->SetLogicRect(aRect);
599cdf0e10cSrcweir         }
600cdf0e10cSrcweir     }
601cdf0e10cSrcweir     else if( bArrow )
602cdf0e10cSrcweir     {
603cdf0e10cSrcweir         //! nicht mehrere Undos fuer ein Objekt erzeugen (hinteres kann dann weggelassen werden)
604cdf0e10cSrcweir 
605cdf0e10cSrcweir         SCCOL nLastCol;
606cdf0e10cSrcweir         SCROW nLastRow;
607cdf0e10cSrcweir         if( bValid1 )
608cdf0e10cSrcweir         {
609cdf0e10cSrcweir             Point aPos( pDoc->GetColOffset( nCol1, nTab1 ), pDoc->GetRowOffset( nRow1, nTab1 ) );
610cdf0e10cSrcweir             if (!pDoc->ColHidden(nCol1, nTab1, nLastCol))
611cdf0e10cSrcweir                 aPos.X() += pDoc->GetColWidth( nCol1, nTab1 ) / 4;
612cdf0e10cSrcweir             if (!pDoc->RowHidden(nRow1, nTab1, nLastRow))
613cdf0e10cSrcweir                 aPos.Y() += pDoc->GetRowHeight( nRow1, nTab1 ) / 2;
614cdf0e10cSrcweir             TwipsToMM( aPos.X() );
615cdf0e10cSrcweir             TwipsToMM( aPos.Y() );
616cdf0e10cSrcweir             Point aStartPos = aPos;
617cdf0e10cSrcweir             if ( bNegativePage )
618cdf0e10cSrcweir                 aStartPos.X() = -aStartPos.X();     // don't modify aPos - used below
619cdf0e10cSrcweir             if ( pObj->GetPoint( 0 ) != aStartPos )
620cdf0e10cSrcweir             {
621cdf0e10cSrcweir                 if (bRecording)
622577c0052SWang Lei                             AddCalcUndo< SdrUndoGeoObj> ( *pObj );
623cdf0e10cSrcweir                 pObj->SetPoint( aStartPos, 0 );
624cdf0e10cSrcweir             }
625cdf0e10cSrcweir 
626cdf0e10cSrcweir             if( !bValid2 )
627cdf0e10cSrcweir             {
628cdf0e10cSrcweir                 Point aEndPos( aPos.X() + DET_ARROW_OFFSET, aPos.Y() - DET_ARROW_OFFSET );
629cdf0e10cSrcweir                 if (aEndPos.Y() < 0)
630cdf0e10cSrcweir                     aEndPos.Y() += (2 * DET_ARROW_OFFSET);
631cdf0e10cSrcweir                 if ( bNegativePage )
632cdf0e10cSrcweir                     aEndPos.X() = -aEndPos.X();
633cdf0e10cSrcweir                 if ( pObj->GetPoint( 1 ) != aEndPos )
634cdf0e10cSrcweir                 {
635cdf0e10cSrcweir                     if (bRecording)
636577c0052SWang Lei                                 AddCalcUndo< SdrUndoGeoObj >( *pObj );
637cdf0e10cSrcweir                     pObj->SetPoint( aEndPos, 1 );
638cdf0e10cSrcweir                 }
639cdf0e10cSrcweir             }
640cdf0e10cSrcweir         }
641cdf0e10cSrcweir         if( bValid2 )
642cdf0e10cSrcweir         {
643cdf0e10cSrcweir             Point aPos( pDoc->GetColOffset( nCol2, nTab2 ), pDoc->GetRowOffset( nRow2, nTab2 ) );
644cdf0e10cSrcweir             if (!pDoc->ColHidden(nCol2, nTab2, nLastCol))
645cdf0e10cSrcweir                 aPos.X() += pDoc->GetColWidth( nCol2, nTab2 ) / 4;
646cdf0e10cSrcweir             if (!pDoc->RowHidden(nRow2, nTab2, nLastRow))
647cdf0e10cSrcweir                 aPos.Y() += pDoc->GetRowHeight( nRow2, nTab2 ) / 2;
648cdf0e10cSrcweir             TwipsToMM( aPos.X() );
649cdf0e10cSrcweir             TwipsToMM( aPos.Y() );
650cdf0e10cSrcweir             Point aEndPos = aPos;
651cdf0e10cSrcweir             if ( bNegativePage )
652cdf0e10cSrcweir                 aEndPos.X() = -aEndPos.X();         // don't modify aPos - used below
653cdf0e10cSrcweir             if ( pObj->GetPoint( 1 ) != aEndPos )
654cdf0e10cSrcweir             {
655cdf0e10cSrcweir                 if (bRecording)
656577c0052SWang Lei                             AddCalcUndo< SdrUndoGeoObj> ( *pObj  );
657cdf0e10cSrcweir                 pObj->SetPoint( aEndPos, 1 );
658cdf0e10cSrcweir             }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir             if( !bValid1 )
661cdf0e10cSrcweir             {
662cdf0e10cSrcweir                 Point aStartPos( aPos.X() - DET_ARROW_OFFSET, aPos.Y() - DET_ARROW_OFFSET );
663cdf0e10cSrcweir                 if (aStartPos.X() < 0)
664cdf0e10cSrcweir                     aStartPos.X() += (2 * DET_ARROW_OFFSET);
665cdf0e10cSrcweir                 if (aStartPos.Y() < 0)
666cdf0e10cSrcweir                     aStartPos.Y() += (2 * DET_ARROW_OFFSET);
667cdf0e10cSrcweir                 if ( bNegativePage )
668cdf0e10cSrcweir                     aStartPos.X() = -aStartPos.X();
669cdf0e10cSrcweir                 if ( pObj->GetPoint( 0 ) != aStartPos )
670cdf0e10cSrcweir                 {
671cdf0e10cSrcweir                     if (bRecording)
672577c0052SWang Lei                                     AddCalcUndo< SdrUndoGeoObj >( *pObj );
673cdf0e10cSrcweir                     pObj->SetPoint( aStartPos, 0 );
674cdf0e10cSrcweir                 }
675cdf0e10cSrcweir             }
676cdf0e10cSrcweir         }
677cdf0e10cSrcweir     }
678cdf0e10cSrcweir     else                                // Referenz-Rahmen
679cdf0e10cSrcweir     {
680cdf0e10cSrcweir         DBG_ASSERT( bValid1, "ScDrawLayer::RecalcPos - invalid start position" );
681cdf0e10cSrcweir         Point aPos( pDoc->GetColOffset( nCol1, nTab1 ), pDoc->GetRowOffset( nRow1, nTab1 ) );
682cdf0e10cSrcweir         TwipsToMM( aPos.X() );
683cdf0e10cSrcweir         TwipsToMM( aPos.Y() );
684cdf0e10cSrcweir 
685cdf0e10cSrcweir         if( bValid2 )
686cdf0e10cSrcweir         {
687cdf0e10cSrcweir             Point aEnd( pDoc->GetColOffset( nCol2 + 1, nTab2 ), pDoc->GetRowOffset( nRow2 + 1, nTab2 ) );
688cdf0e10cSrcweir             TwipsToMM( aEnd.X() );
689cdf0e10cSrcweir             TwipsToMM( aEnd.Y() );
690cdf0e10cSrcweir 
691cdf0e10cSrcweir             Rectangle aNew( aPos, aEnd );
692cdf0e10cSrcweir             if ( bNegativePage )
693cdf0e10cSrcweir                 MirrorRectRTL( aNew );
694cdf0e10cSrcweir             if ( pObj->GetLogicRect() != aNew )
695cdf0e10cSrcweir             {
696cdf0e10cSrcweir                 if (bRecording)
697577c0052SWang Lei                             AddCalcUndo< SdrUndoGeoObj >( *pObj );
698cdf0e10cSrcweir                 pObj->SetLogicRect(aNew);
699cdf0e10cSrcweir             }
700cdf0e10cSrcweir         }
701cdf0e10cSrcweir         else
702cdf0e10cSrcweir         {
703cdf0e10cSrcweir             if ( bNegativePage )
704cdf0e10cSrcweir                 aPos.X() = -aPos.X();
705cdf0e10cSrcweir             if ( pObj->GetRelativePos() != aPos )
706cdf0e10cSrcweir             {
707cdf0e10cSrcweir                 if (bRecording)
708577c0052SWang Lei                             AddCalcUndo< SdrUndoGeoObj >( *pObj );
709cdf0e10cSrcweir                 pObj->SetRelativePos( aPos );
710cdf0e10cSrcweir             }
711cdf0e10cSrcweir         }
712cdf0e10cSrcweir     }
713cdf0e10cSrcweir }
714cdf0e10cSrcweir 
GetPrintArea(ScRange & rRange,sal_Bool bSetHor,sal_Bool bSetVer) const715cdf0e10cSrcweir sal_Bool ScDrawLayer::GetPrintArea( ScRange& rRange, sal_Bool bSetHor, sal_Bool bSetVer ) const
716cdf0e10cSrcweir {
717cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::GetPrintArea without document" );
718cdf0e10cSrcweir     if ( !pDoc )
719cdf0e10cSrcweir         return sal_False;
720cdf0e10cSrcweir 
721cdf0e10cSrcweir     SCTAB nTab = rRange.aStart.Tab();
722cdf0e10cSrcweir     DBG_ASSERT( rRange.aEnd.Tab() == nTab, "GetPrintArea: Tab unterschiedlich" );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
725cdf0e10cSrcweir 
726cdf0e10cSrcweir     sal_Bool bAny = sal_False;
727cdf0e10cSrcweir     long nEndX = 0;
728cdf0e10cSrcweir     long nEndY = 0;
729cdf0e10cSrcweir     long nStartX = LONG_MAX;
730cdf0e10cSrcweir     long nStartY = LONG_MAX;
731cdf0e10cSrcweir 
732cdf0e10cSrcweir     // Grenzen ausrechnen
733cdf0e10cSrcweir 
734cdf0e10cSrcweir     if (!bSetHor)
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         nStartX = 0;
737cdf0e10cSrcweir         SCCOL nStartCol = rRange.aStart.Col();
738cdf0e10cSrcweir             SCCOL i;
739cdf0e10cSrcweir         for (i=0; i<nStartCol; i++)
740cdf0e10cSrcweir             nStartX +=pDoc->GetColWidth(i,nTab);
741cdf0e10cSrcweir         nEndX = nStartX;
742cdf0e10cSrcweir         SCCOL nEndCol = rRange.aEnd.Col();
743cdf0e10cSrcweir         for (i=nStartCol; i<=nEndCol; i++)
744cdf0e10cSrcweir             nEndX += pDoc->GetColWidth(i,nTab);
745cdf0e10cSrcweir         nStartX = (long)(nStartX * HMM_PER_TWIPS);
746cdf0e10cSrcweir         nEndX   = (long)(nEndX   * HMM_PER_TWIPS);
747cdf0e10cSrcweir     }
748cdf0e10cSrcweir     if (!bSetVer)
749cdf0e10cSrcweir     {
750cdf0e10cSrcweir         nStartY = pDoc->GetRowHeight( 0, rRange.aStart.Row()-1, nTab);
751cdf0e10cSrcweir         nEndY = nStartY + pDoc->GetRowHeight( rRange.aStart.Row(),
752cdf0e10cSrcweir                 rRange.aEnd.Row(), nTab);
753cdf0e10cSrcweir         nStartY = (long)(nStartY * HMM_PER_TWIPS);
754cdf0e10cSrcweir         nEndY   = (long)(nEndY   * HMM_PER_TWIPS);
755cdf0e10cSrcweir     }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir     if ( bNegativePage )
758cdf0e10cSrcweir     {
759cdf0e10cSrcweir         nStartX = -nStartX;     // positions are negative, swap start/end so the same comparisons work
760cdf0e10cSrcweir         nEndX   = -nEndX;
761cdf0e10cSrcweir         ::std::swap( nStartX, nEndX );
762cdf0e10cSrcweir     }
763cdf0e10cSrcweir 
764cdf0e10cSrcweir     const SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
765cdf0e10cSrcweir     DBG_ASSERT(pPage,"Page nicht gefunden");
766cdf0e10cSrcweir     if (pPage)
767cdf0e10cSrcweir     {
768cdf0e10cSrcweir         SdrObjListIter aIter( *pPage, IM_FLAT );
769cdf0e10cSrcweir         SdrObject* pObject = aIter.Next();
770cdf0e10cSrcweir         while (pObject)
771cdf0e10cSrcweir         {
772cdf0e10cSrcweir                             //! Flags (ausgeblendet?) testen
773cdf0e10cSrcweir 
774cdf0e10cSrcweir             Rectangle aObjRect = pObject->GetCurrentBoundRect();
775cdf0e10cSrcweir             sal_Bool bFit = sal_True;
776cdf0e10cSrcweir             if ( !bSetHor && ( aObjRect.Right() < nStartX || aObjRect.Left() > nEndX ) )
777cdf0e10cSrcweir                 bFit = sal_False;
778cdf0e10cSrcweir             if ( !bSetVer && ( aObjRect.Bottom() < nStartY || aObjRect.Top() > nEndY ) )
779cdf0e10cSrcweir                 bFit = sal_False;
780cdf0e10cSrcweir             // #i104716# don't include hidden note objects
781cdf0e10cSrcweir             if ( bFit && pObject->GetLayer() != SC_LAYER_HIDDEN )
782cdf0e10cSrcweir             {
783cdf0e10cSrcweir                 if (bSetHor)
784cdf0e10cSrcweir                 {
785cdf0e10cSrcweir                     if (aObjRect.Left() < nStartX) nStartX = aObjRect.Left();
786cdf0e10cSrcweir                     if (aObjRect.Right()  > nEndX) nEndX = aObjRect.Right();
787cdf0e10cSrcweir                 }
788cdf0e10cSrcweir                 if (bSetVer)
789cdf0e10cSrcweir                 {
790cdf0e10cSrcweir                     if (aObjRect.Top()  < nStartY) nStartY = aObjRect.Top();
791cdf0e10cSrcweir                     if (aObjRect.Bottom() > nEndY) nEndY = aObjRect.Bottom();
792cdf0e10cSrcweir                 }
793cdf0e10cSrcweir                 bAny = sal_True;
794cdf0e10cSrcweir             }
795cdf0e10cSrcweir 
796cdf0e10cSrcweir             pObject = aIter.Next();
797cdf0e10cSrcweir         }
798cdf0e10cSrcweir     }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     if ( bNegativePage )
801cdf0e10cSrcweir     {
802cdf0e10cSrcweir         nStartX = -nStartX;     // reverse transformation, so the same cell address calculation works
803cdf0e10cSrcweir         nEndX   = -nEndX;
804cdf0e10cSrcweir         ::std::swap( nStartX, nEndX );
805cdf0e10cSrcweir     }
806cdf0e10cSrcweir 
807cdf0e10cSrcweir     if (bAny)
808cdf0e10cSrcweir     {
809cdf0e10cSrcweir         DBG_ASSERT( nStartX<=nEndX && nStartY<=nEndY, "Start/End falsch in ScDrawLayer::GetPrintArea" );
810cdf0e10cSrcweir 
811cdf0e10cSrcweir         if (bSetHor)
812cdf0e10cSrcweir         {
813cdf0e10cSrcweir             nStartX = (long) (nStartX / HMM_PER_TWIPS);
814cdf0e10cSrcweir             nEndX = (long) (nEndX / HMM_PER_TWIPS);
815cdf0e10cSrcweir             long nWidth;
816cdf0e10cSrcweir             SCCOL i;
817cdf0e10cSrcweir 
818cdf0e10cSrcweir             nWidth = 0;
819cdf0e10cSrcweir             for (i=0; i<=MAXCOL && nWidth<=nStartX; i++)
820cdf0e10cSrcweir                 nWidth += pDoc->GetColWidth(i,nTab);
821cdf0e10cSrcweir             rRange.aStart.SetCol( i>0 ? (i-1) : 0 );
822cdf0e10cSrcweir 
823cdf0e10cSrcweir             nWidth = 0;
824cdf0e10cSrcweir             for (i=0; i<=MAXCOL && nWidth<=nEndX; i++)          //! bei Start anfangen
825cdf0e10cSrcweir                 nWidth += pDoc->GetColWidth(i,nTab);
826cdf0e10cSrcweir             rRange.aEnd.SetCol( i>0 ? (i-1) : 0 );
827cdf0e10cSrcweir         }
828cdf0e10cSrcweir 
829cdf0e10cSrcweir         if (bSetVer)
830cdf0e10cSrcweir         {
831cdf0e10cSrcweir             nStartY = (long) (nStartY / HMM_PER_TWIPS);
832cdf0e10cSrcweir             nEndY = (long) (nEndY / HMM_PER_TWIPS);
833cdf0e10cSrcweir             SCROW nRow = pDoc->GetRowForHeight( nTab, nStartY);
834cdf0e10cSrcweir             rRange.aStart.SetRow( nRow>0 ? (nRow-1) : 0);
835cdf0e10cSrcweir             nRow = pDoc->GetRowForHeight( nTab, nEndY);
836cdf0e10cSrcweir             rRange.aEnd.SetRow( nRow == MAXROW ? MAXROW :
837cdf0e10cSrcweir                     (nRow>0 ? (nRow-1) : 0));
838cdf0e10cSrcweir         }
839cdf0e10cSrcweir     }
840cdf0e10cSrcweir     else
841cdf0e10cSrcweir     {
842cdf0e10cSrcweir         if (bSetHor)
843cdf0e10cSrcweir         {
844cdf0e10cSrcweir             rRange.aStart.SetCol(0);
845cdf0e10cSrcweir             rRange.aEnd.SetCol(0);
846cdf0e10cSrcweir         }
847cdf0e10cSrcweir         if (bSetVer)
848cdf0e10cSrcweir         {
849cdf0e10cSrcweir             rRange.aStart.SetRow(0);
850cdf0e10cSrcweir             rRange.aEnd.SetRow(0);
851cdf0e10cSrcweir         }
852cdf0e10cSrcweir     }
853cdf0e10cSrcweir     return bAny;
854cdf0e10cSrcweir }
855cdf0e10cSrcweir 
AddCalcUndo(SdrUndoAction * pUndo)856cdf0e10cSrcweir void ScDrawLayer::AddCalcUndo( SdrUndoAction* pUndo )
857cdf0e10cSrcweir {
858cdf0e10cSrcweir     if (bRecording)
859cdf0e10cSrcweir     {
860cdf0e10cSrcweir         if (!pUndoGroup)
861cdf0e10cSrcweir             pUndoGroup = new SdrUndoGroup(*this);
862cdf0e10cSrcweir 
863cdf0e10cSrcweir         pUndoGroup->AddAction( pUndo );
864cdf0e10cSrcweir     }
865cdf0e10cSrcweir     else
866cdf0e10cSrcweir         delete pUndo;
867cdf0e10cSrcweir }
868cdf0e10cSrcweir 
BeginCalcUndo(bool bDisableTextEditUsesCommonUndoManager)869a840a559SArmin Le Grand void ScDrawLayer::BeginCalcUndo(bool bDisableTextEditUsesCommonUndoManager)
870cdf0e10cSrcweir {
871cdf0e10cSrcweir //! DBG_ASSERT( !bRecording, "BeginCalcUndo ohne GetCalcUndo" );
872a840a559SArmin Le Grand     SetDisableTextEditUsesCommonUndoManager(bDisableTextEditUsesCommonUndoManager);
873cdf0e10cSrcweir     DELETEZ(pUndoGroup);
874cdf0e10cSrcweir     bRecording = sal_True;
875cdf0e10cSrcweir }
876cdf0e10cSrcweir 
GetCalcUndo()877cdf0e10cSrcweir SdrUndoGroup* ScDrawLayer::GetCalcUndo()
878cdf0e10cSrcweir {
879cdf0e10cSrcweir //! DBG_ASSERT( bRecording, "GetCalcUndo ohne BeginCalcUndo" );
880cdf0e10cSrcweir 
881cdf0e10cSrcweir     SdrUndoGroup* pRet = pUndoGroup;
882cdf0e10cSrcweir     pUndoGroup = NULL;
883cdf0e10cSrcweir     bRecording = sal_False;
884a840a559SArmin Le Grand     SetDisableTextEditUsesCommonUndoManager(false);
885cdf0e10cSrcweir     return pRet;
886cdf0e10cSrcweir }
887cdf0e10cSrcweir 
888cdf0e10cSrcweir //  MoveAreaTwips: all measures are kept in twips
MoveAreaTwips(SCTAB nTab,const Rectangle & rArea,const Point & rMove,const Point & rTopLeft)889cdf0e10cSrcweir void ScDrawLayer::MoveAreaTwips( SCTAB nTab, const Rectangle& rArea,
890cdf0e10cSrcweir         const Point& rMove, const Point& rTopLeft )
891cdf0e10cSrcweir {
892cdf0e10cSrcweir     if (!rMove.X() && !rMove.Y())
893cdf0e10cSrcweir         return;                                     // nix
894cdf0e10cSrcweir 
895cdf0e10cSrcweir     SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
896cdf0e10cSrcweir     DBG_ASSERT(pPage,"Page nicht gefunden");
897cdf0e10cSrcweir     if (!pPage)
898cdf0e10cSrcweir         return;
899cdf0e10cSrcweir 
900cdf0e10cSrcweir     sal_Bool bNegativePage = pDoc && pDoc->IsNegativePage( nTab );
901cdf0e10cSrcweir 
902cdf0e10cSrcweir     // fuer Shrinking!
903cdf0e10cSrcweir     Rectangle aNew( rArea );
904cdf0e10cSrcweir     sal_Bool bShrink = sal_False;
905cdf0e10cSrcweir     if ( rMove.X() < 0 || rMove.Y() < 0 )       // verkleinern
906cdf0e10cSrcweir     {
907cdf0e10cSrcweir         if ( rTopLeft != rArea.TopLeft() )      // sind gleich beim Verschieben von Zellen
908cdf0e10cSrcweir         {
909cdf0e10cSrcweir             bShrink = sal_True;
910cdf0e10cSrcweir             aNew.Left() = rTopLeft.X();
911cdf0e10cSrcweir             aNew.Top() = rTopLeft.Y();
912cdf0e10cSrcweir         }
913cdf0e10cSrcweir     }
914cdf0e10cSrcweir     SdrObjListIter aIter( *pPage, IM_FLAT );
915cdf0e10cSrcweir     SdrObject* pObject = aIter.Next();
916cdf0e10cSrcweir     while (pObject)
917cdf0e10cSrcweir     {
918cdf0e10cSrcweir         if( GetAnchor( pObject ) == SCA_CELL )
919cdf0e10cSrcweir         {
920cdf0e10cSrcweir             if ( GetObjData( pObject ) )                    // Detektiv-Pfeil ?
921cdf0e10cSrcweir             {
922cdf0e10cSrcweir                 // hier nichts
923cdf0e10cSrcweir             }
924cdf0e10cSrcweir             else if ( pObject->ISA( SdrEdgeObj ) )          // Verbinder?
925cdf0e10cSrcweir             {
926cdf0e10cSrcweir                 //  hier auch nichts
927cdf0e10cSrcweir                 //! nicht verbundene Enden wie bei Linien (s.u.) behandeln?
928cdf0e10cSrcweir             }
929cdf0e10cSrcweir             else if ( pObject->IsPolyObj() && pObject->GetPointCount()==2 )
930cdf0e10cSrcweir             {
931cdf0e10cSrcweir                 for (sal_uInt16 i=0; i<2; i++)
932cdf0e10cSrcweir                 {
933cdf0e10cSrcweir                     sal_Bool bMoved = sal_False;
934cdf0e10cSrcweir                     Point aPoint = pObject->GetPoint(i);
935cdf0e10cSrcweir                     lcl_ReverseTwipsToMM( aPoint );
936cdf0e10cSrcweir                     if (rArea.IsInside(aPoint))
937cdf0e10cSrcweir                     {
938cdf0e10cSrcweir                         aPoint += rMove; bMoved = sal_True;
939cdf0e10cSrcweir                     }
940cdf0e10cSrcweir                     else if (bShrink && aNew.IsInside(aPoint))
941cdf0e10cSrcweir                     {
942cdf0e10cSrcweir                         //  Punkt ist in betroffener Zelle - Test auf geloeschten Bereich
943cdf0e10cSrcweir                         if ( rMove.X() && aPoint.X() >= rArea.Left() + rMove.X() )
944cdf0e10cSrcweir                         {
945cdf0e10cSrcweir                             aPoint.X() = rArea.Left() + rMove.X() - SHRINK_DIST_TWIPS;
946cdf0e10cSrcweir                             if ( aPoint.X() < 0 ) aPoint.X() = 0;
947cdf0e10cSrcweir                             bMoved = sal_True;
948cdf0e10cSrcweir                         }
949cdf0e10cSrcweir                         if ( rMove.Y() && aPoint.Y() >= rArea.Top() + rMove.Y() )
950cdf0e10cSrcweir                         {
951cdf0e10cSrcweir                             aPoint.Y() = rArea.Top() + rMove.Y() - SHRINK_DIST_TWIPS;
952cdf0e10cSrcweir                             if ( aPoint.Y() < 0 ) aPoint.Y() = 0;
953cdf0e10cSrcweir                             bMoved = sal_True;
954cdf0e10cSrcweir                         }
955cdf0e10cSrcweir                     }
956cdf0e10cSrcweir                     if( bMoved )
957cdf0e10cSrcweir                     {
958577c0052SWang Lei                                     AddCalcUndo< SdrUndoGeoObj >( *pObject );
959cdf0e10cSrcweir                         lcl_TwipsToMM( aPoint );
960cdf0e10cSrcweir                         pObject->SetPoint( aPoint, i );
961cdf0e10cSrcweir                     }
962cdf0e10cSrcweir                 }
963cdf0e10cSrcweir             }
964cdf0e10cSrcweir             else
965cdf0e10cSrcweir             {
966cdf0e10cSrcweir                 Rectangle aObjRect = pObject->GetLogicRect();
967cdf0e10cSrcweir                 // aOldMMPos: not converted, millimeters
968cdf0e10cSrcweir                 Point aOldMMPos = bNegativePage ? aObjRect.TopRight() : aObjRect.TopLeft();
969cdf0e10cSrcweir                 lcl_ReverseTwipsToMM( aObjRect );
970cdf0e10cSrcweir                 Point aTopLeft = bNegativePage ? aObjRect.TopRight() : aObjRect.TopLeft();  // logical left
971cdf0e10cSrcweir                 Size aMoveSize;
972cdf0e10cSrcweir                 sal_Bool bDoMove = sal_False;
973cdf0e10cSrcweir                 if (rArea.IsInside(aTopLeft))
974cdf0e10cSrcweir                 {
975cdf0e10cSrcweir                     aMoveSize = Size(rMove.X(),rMove.Y());
976cdf0e10cSrcweir                     bDoMove = sal_True;
977cdf0e10cSrcweir                 }
978cdf0e10cSrcweir                 else if (bShrink && aNew.IsInside(aTopLeft))
979cdf0e10cSrcweir                 {
980cdf0e10cSrcweir                     //  Position ist in betroffener Zelle - Test auf geloeschten Bereich
981cdf0e10cSrcweir                     if ( rMove.X() && aTopLeft.X() >= rArea.Left() + rMove.X() )
982cdf0e10cSrcweir                     {
983cdf0e10cSrcweir                         aMoveSize.Width() = rArea.Left() + rMove.X() - SHRINK_DIST - aTopLeft.X();
984cdf0e10cSrcweir                         bDoMove = sal_True;
985cdf0e10cSrcweir                     }
986cdf0e10cSrcweir                     if ( rMove.Y() && aTopLeft.Y() >= rArea.Top() + rMove.Y() )
987cdf0e10cSrcweir                     {
988cdf0e10cSrcweir                         aMoveSize.Height() = rArea.Top() + rMove.Y() - SHRINK_DIST - aTopLeft.Y();
989cdf0e10cSrcweir                         bDoMove = sal_True;
990cdf0e10cSrcweir                     }
991cdf0e10cSrcweir                 }
992cdf0e10cSrcweir                 if ( bDoMove )
993cdf0e10cSrcweir                 {
994cdf0e10cSrcweir                     if ( bNegativePage )
995cdf0e10cSrcweir                     {
996cdf0e10cSrcweir                         if ( aTopLeft.X() + aMoveSize.Width() > 0 )
997cdf0e10cSrcweir                             aMoveSize.Width() = -aTopLeft.X();
998cdf0e10cSrcweir                     }
999cdf0e10cSrcweir                     else
1000cdf0e10cSrcweir                     {
1001cdf0e10cSrcweir                         if ( aTopLeft.X() + aMoveSize.Width() < 0 )
1002cdf0e10cSrcweir                             aMoveSize.Width() = -aTopLeft.X();
1003cdf0e10cSrcweir                     }
1004cdf0e10cSrcweir                     if ( aTopLeft.Y() + aMoveSize.Height() < 0 )
1005cdf0e10cSrcweir                         aMoveSize.Height() = -aTopLeft.Y();
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir                     //  get corresponding move size in millimeters:
1008cdf0e10cSrcweir                     Point aNewPos( aTopLeft.X() + aMoveSize.Width(), aTopLeft.Y() + aMoveSize.Height() );
1009cdf0e10cSrcweir                     lcl_TwipsToMM( aNewPos );
1010cdf0e10cSrcweir                     aMoveSize = Size( aNewPos.X() - aOldMMPos.X(), aNewPos.Y() - aOldMMPos.Y() );   // millimeters
1011cdf0e10cSrcweir 
1012577c0052SWang Lei                                 AddCalcUndo< SdrUndoMoveObj >( *pObject, aMoveSize );
1013cdf0e10cSrcweir                     pObject->Move( aMoveSize );
1014cdf0e10cSrcweir                 }
1015cdf0e10cSrcweir                 else if ( rArea.IsInside( bNegativePage ? aObjRect.BottomLeft() : aObjRect.BottomRight() ) &&
1016cdf0e10cSrcweir                             !pObject->IsResizeProtect() )
1017cdf0e10cSrcweir                 {
1018cdf0e10cSrcweir                     //  geschuetzte Groessen werden nicht veraendert
1019cdf0e10cSrcweir                     //  (Positionen schon, weil sie ja an der Zelle "verankert" sind)
1020577c0052SWang Lei                             AddCalcUndo< SdrUndoGeoObj >( *pObject );
1021cdf0e10cSrcweir                     long nOldSizeX = aObjRect.Right() - aObjRect.Left() + 1;
1022cdf0e10cSrcweir                     long nOldSizeY = aObjRect.Bottom() - aObjRect.Top() + 1;
1023cdf0e10cSrcweir                     long nLogMoveX = rMove.X() * ( bNegativePage ? -1 : 1 );    // logical direction
1024cdf0e10cSrcweir                     pObject->Resize( aOldMMPos, Fraction( nOldSizeX+nLogMoveX, nOldSizeX ),
1025cdf0e10cSrcweir                                                 Fraction( nOldSizeY+rMove.Y(), nOldSizeY ) );
1026cdf0e10cSrcweir                 }
1027cdf0e10cSrcweir             }
1028cdf0e10cSrcweir         }
1029cdf0e10cSrcweir         pObject = aIter.Next();
1030cdf0e10cSrcweir     }
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir 
MoveArea(SCTAB nTab,SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2,SCsCOL nDx,SCsROW nDy,sal_Bool bInsDel,bool bUpdateNoteCaptionPos)1033cdf0e10cSrcweir void ScDrawLayer::MoveArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1, SCCOL nCol2,SCROW nRow2,
1034cdf0e10cSrcweir                             SCsCOL nDx,SCsROW nDy, sal_Bool bInsDel, bool bUpdateNoteCaptionPos )
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::MoveArea without document" );
1037cdf0e10cSrcweir     if ( !pDoc )
1038cdf0e10cSrcweir         return;
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir     if (!bAdjustEnabled)
1041cdf0e10cSrcweir         return;
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir     Rectangle aRect = pDoc->GetMMRect( nCol1, nRow1, nCol2, nRow2, nTab );
1046cdf0e10cSrcweir     lcl_ReverseTwipsToMM( aRect );
1047cdf0e10cSrcweir     //! use twips directly?
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir     Point aMove;
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir     if (nDx > 0)
1052cdf0e10cSrcweir         for (SCsCOL s=0; s<nDx; s++)
1053cdf0e10cSrcweir             aMove.X() += pDoc->GetColWidth(s+(SCsCOL)nCol1,nTab);
1054cdf0e10cSrcweir     else
1055cdf0e10cSrcweir         for (SCsCOL s=-1; s>=nDx; s--)
1056cdf0e10cSrcweir             aMove.X() -= pDoc->GetColWidth(s+(SCsCOL)nCol1,nTab);
1057cdf0e10cSrcweir     if (nDy > 0)
1058cdf0e10cSrcweir         aMove.Y() += pDoc->GetRowHeight( nRow1, nRow1+nDy-1, nTab);
1059cdf0e10cSrcweir     else
1060cdf0e10cSrcweir         aMove.Y() -= pDoc->GetRowHeight( nRow1+nDy, nRow1-1, nTab);
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir     if ( bNegativePage )
1063cdf0e10cSrcweir         aMove.X() = -aMove.X();
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir     Point aTopLeft = aRect.TopLeft();       // Anfang beim Verkleinern
1066cdf0e10cSrcweir     if (bInsDel)
1067cdf0e10cSrcweir     {
1068cdf0e10cSrcweir         if ( aMove.X() != 0 && nDx < 0 )    // nDx counts cells, sign is independent of RTL
1069cdf0e10cSrcweir             aTopLeft.X() += aMove.X();
1070cdf0e10cSrcweir         if ( aMove.Y() < 0 )
1071cdf0e10cSrcweir             aTopLeft.Y() += aMove.Y();
1072cdf0e10cSrcweir     }
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir     //  drawing objects are now directly included in cut&paste
1075cdf0e10cSrcweir     //  -> only update references when inserting/deleting (or changing widths or heights)
1076cdf0e10cSrcweir     if ( bInsDel )
1077cdf0e10cSrcweir         MoveAreaTwips( nTab, aRect, aMove, aTopLeft );
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir         //
1080cdf0e10cSrcweir         //      Detektiv-Pfeile: Zellpositionen anpassen
1081cdf0e10cSrcweir         //
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir     MoveCells( nTab, nCol1,nRow1, nCol2,nRow2, nDx,nDy, bUpdateNoteCaptionPos );
1084cdf0e10cSrcweir }
1085cdf0e10cSrcweir 
WidthChanged(SCTAB nTab,SCCOL nCol,long nDifTwips)1086cdf0e10cSrcweir void ScDrawLayer::WidthChanged( SCTAB nTab, SCCOL nCol, long nDifTwips )
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::WidthChanged without document" );
1089cdf0e10cSrcweir     if ( !pDoc )
1090cdf0e10cSrcweir         return;
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir     if (!bAdjustEnabled)
1093cdf0e10cSrcweir         return;
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir     Rectangle aRect;
1096cdf0e10cSrcweir     Point aTopLeft;
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir     for (SCCOL i=0; i<nCol; i++)
1099cdf0e10cSrcweir         aRect.Left() += pDoc->GetColWidth(i,nTab);
1100cdf0e10cSrcweir     aTopLeft.X() = aRect.Left();
1101cdf0e10cSrcweir     aRect.Left() += pDoc->GetColWidth(nCol,nTab);
1102cdf0e10cSrcweir 
1103cdf0e10cSrcweir     aRect.Right() = MAXMM;
1104cdf0e10cSrcweir     aRect.Top() = 0;
1105cdf0e10cSrcweir     aRect.Bottom() = MAXMM;
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir     //! aTopLeft ist falsch, wenn mehrere Spalten auf einmal ausgeblendet werden
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
1110cdf0e10cSrcweir     if ( bNegativePage )
1111cdf0e10cSrcweir     {
1112cdf0e10cSrcweir         MirrorRectRTL( aRect );
1113cdf0e10cSrcweir         aTopLeft.X() = -aTopLeft.X();
1114cdf0e10cSrcweir         nDifTwips = -nDifTwips;
1115cdf0e10cSrcweir     }
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir     MoveAreaTwips( nTab, aRect, Point( nDifTwips,0 ), aTopLeft );
1118cdf0e10cSrcweir }
1119cdf0e10cSrcweir 
HeightChanged(SCTAB nTab,SCROW nRow,long nDifTwips)1120cdf0e10cSrcweir void ScDrawLayer::HeightChanged( SCTAB nTab, SCROW nRow, long nDifTwips )
1121cdf0e10cSrcweir {
1122cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::HeightChanged without document" );
1123cdf0e10cSrcweir     if ( !pDoc )
1124cdf0e10cSrcweir         return;
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir     if (!bAdjustEnabled)
1127cdf0e10cSrcweir         return;
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir     SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
1130cdf0e10cSrcweir     DBG_ASSERT(pPage,"Page not found");
1131cdf0e10cSrcweir     if (!pPage)
1132cdf0e10cSrcweir         return;
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir     // for an empty page, there's no need to calculate the row heights
1135cdf0e10cSrcweir     if (!pPage->GetObjCount())
1136cdf0e10cSrcweir         return;
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir     Rectangle aRect;
1139cdf0e10cSrcweir     Point aTopLeft;
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir     aRect.Top() += pDoc->GetRowHeight( 0, nRow-1, nTab);
1142cdf0e10cSrcweir     aTopLeft.Y() = aRect.Top();
1143cdf0e10cSrcweir     aRect.Top() += pDoc->GetRowHeight(nRow, nTab);
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir     aRect.Bottom() = MAXMM;
1146cdf0e10cSrcweir     aRect.Left() = 0;
1147cdf0e10cSrcweir     aRect.Right() = MAXMM;
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir     //! aTopLeft ist falsch, wenn mehrere Zeilen auf einmal ausgeblendet werden
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
1152cdf0e10cSrcweir     if ( bNegativePage )
1153cdf0e10cSrcweir     {
1154cdf0e10cSrcweir         MirrorRectRTL( aRect );
1155cdf0e10cSrcweir         aTopLeft.X() = -aTopLeft.X();
1156cdf0e10cSrcweir     }
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir     MoveAreaTwips( nTab, aRect, Point( 0,nDifTwips ), aTopLeft );
1159cdf0e10cSrcweir }
1160cdf0e10cSrcweir 
HasObjectsInRows(SCTAB nTab,SCROW nStartRow,SCROW nEndRow,bool bIncludeNotes)1161cdf0e10cSrcweir sal_Bool ScDrawLayer::HasObjectsInRows( SCTAB nTab, SCROW nStartRow, SCROW nEndRow, bool bIncludeNotes )
1162cdf0e10cSrcweir {
1163cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::HasObjectsInRows without document" );
1164cdf0e10cSrcweir     if ( !pDoc )
1165cdf0e10cSrcweir         return sal_False;
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir     SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
1168cdf0e10cSrcweir     DBG_ASSERT(pPage,"Page not found");
1169cdf0e10cSrcweir     if (!pPage)
1170cdf0e10cSrcweir         return sal_False;
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir     // for an empty page, there's no need to calculate the row heights
1173cdf0e10cSrcweir     if (!pPage->GetObjCount())
1174cdf0e10cSrcweir         return sal_False;
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir     Rectangle aTestRect;
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir     aTestRect.Top() += pDoc->GetRowHeight( 0, nStartRow-1, nTab);
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir     if (nEndRow==MAXROW)
1181cdf0e10cSrcweir         aTestRect.Bottom() = MAXMM;
1182cdf0e10cSrcweir     else
1183cdf0e10cSrcweir     {
1184cdf0e10cSrcweir         aTestRect.Bottom() = aTestRect.Top();
1185cdf0e10cSrcweir         aTestRect.Bottom() += pDoc->GetRowHeight( nStartRow, nEndRow, nTab);
1186cdf0e10cSrcweir         TwipsToMM( aTestRect.Bottom() );
1187cdf0e10cSrcweir     }
1188cdf0e10cSrcweir 
1189cdf0e10cSrcweir     TwipsToMM( aTestRect.Top() );
1190cdf0e10cSrcweir 
1191cdf0e10cSrcweir     aTestRect.Left()  = 0;
1192cdf0e10cSrcweir     aTestRect.Right() = MAXMM;
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
1195cdf0e10cSrcweir     if ( bNegativePage )
1196cdf0e10cSrcweir         MirrorRectRTL( aTestRect );
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir     sal_Bool bFound = sal_False;
1199cdf0e10cSrcweir 
1200cdf0e10cSrcweir     Rectangle aObjRect;
1201cdf0e10cSrcweir     SdrObjListIter aIter( *pPage );
1202cdf0e10cSrcweir     SdrObject* pObject = aIter.Next();
1203cdf0e10cSrcweir     while ( pObject && !bFound )
1204cdf0e10cSrcweir     {
1205cdf0e10cSrcweir         aObjRect = pObject->GetSnapRect();  //! GetLogicRect ?
1206cdf0e10cSrcweir         // #i116164# note captions are handled separately, don't have to be included for each single row height change
1207cdf0e10cSrcweir         if ( (aTestRect.IsInside(aObjRect.TopLeft()) || aTestRect.IsInside(aObjRect.BottomLeft())) &&
1208cdf0e10cSrcweir              (bIncludeNotes || !IsNoteCaption(pObject)) )
1209cdf0e10cSrcweir             bFound = sal_True;
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir         pObject = aIter.Next();
1212cdf0e10cSrcweir     }
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir     return bFound;
1215cdf0e10cSrcweir }
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir #if 0
1218cdf0e10cSrcweir void ScDrawLayer::DeleteObjects( SCTAB nTab )
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir     SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
1221cdf0e10cSrcweir     DBG_ASSERT(pPage,"Page ?");
1222cdf0e10cSrcweir     if (!pPage)
1223cdf0e10cSrcweir         return;
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir     pPage->RecalcObjOrdNums();
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir     long    nDelCount = 0;
1228cdf0e10cSrcweir     sal_uLong   nObjCount = pPage->GetObjCount();
1229cdf0e10cSrcweir     if (nObjCount)
1230cdf0e10cSrcweir     {
1231cdf0e10cSrcweir         SdrObject** ppObj = new SdrObject*[nObjCount];
1232cdf0e10cSrcweir 
1233cdf0e10cSrcweir         SdrObjListIter aIter( *pPage, IM_FLAT );
1234cdf0e10cSrcweir         SdrObject* pObject = aIter.Next();
1235cdf0e10cSrcweir         while (pObject)
1236cdf0e10cSrcweir         {
1237cdf0e10cSrcweir             //  alle loeschen
1238cdf0e10cSrcweir             ppObj[nDelCount++] = pObject;
1239cdf0e10cSrcweir             pObject = aIter.Next();
1240cdf0e10cSrcweir         }
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir         long i;
1243cdf0e10cSrcweir         if (bRecording)
1244cdf0e10cSrcweir             for (i=1; i<=nDelCount; i++)
1245577c0052SWang Lei                         AddCalcUndo< SdrUndoRemoveObj >( *ppObj[nDelCount-i] );
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir         for (i=1; i<=nDelCount; i++)
1248cdf0e10cSrcweir             pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir         delete[] ppObj;
1251cdf0e10cSrcweir     }
1252cdf0e10cSrcweir }
1253cdf0e10cSrcweir #endif
1254cdf0e10cSrcweir 
DeleteObjectsInArea(SCTAB nTab,SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2)1255cdf0e10cSrcweir void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
1256cdf0e10cSrcweir                                             SCCOL nCol2,SCROW nRow2 )
1257cdf0e10cSrcweir {
1258cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::DeleteObjectsInArea without document" );
1259cdf0e10cSrcweir     if ( !pDoc )
1260cdf0e10cSrcweir         return;
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir     SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
1263cdf0e10cSrcweir     DBG_ASSERT(pPage,"Page ?");
1264cdf0e10cSrcweir     if (!pPage)
1265cdf0e10cSrcweir         return;
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir     pPage->RecalcObjOrdNums();
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir     long    nDelCount = 0;
1270cdf0e10cSrcweir     sal_uLong   nObjCount = pPage->GetObjCount();
1271cdf0e10cSrcweir     if (nObjCount)
1272cdf0e10cSrcweir     {
1273cdf0e10cSrcweir         Rectangle aDelRect = pDoc->GetMMRect( nCol1, nRow1, nCol2, nRow2, nTab );
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir         SdrObject** ppObj = new SdrObject*[nObjCount];
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir         SdrObjListIter aIter( *pPage, IM_FLAT );
1278cdf0e10cSrcweir         SdrObject* pObject = aIter.Next();
1279cdf0e10cSrcweir         while (pObject)
1280cdf0e10cSrcweir         {
1281cdf0e10cSrcweir             // do not delete note caption, they are always handled by the cell note
1282cdf0e10cSrcweir             // TODO: detective objects are still deleted, is this desired?
1283cdf0e10cSrcweir             if (!IsNoteCaption( pObject ))
1284cdf0e10cSrcweir             {
1285cdf0e10cSrcweir                 Rectangle aObjRect = pObject->GetCurrentBoundRect();
1286cdf0e10cSrcweir                 if ( aDelRect.IsInside( aObjRect ) )
1287cdf0e10cSrcweir                     ppObj[nDelCount++] = pObject;
1288cdf0e10cSrcweir             }
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir             pObject = aIter.Next();
1291cdf0e10cSrcweir         }
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir         long i;
1294cdf0e10cSrcweir         if (bRecording)
1295cdf0e10cSrcweir             for (i=1; i<=nDelCount; i++)
1296577c0052SWang Lei                         AddCalcUndo< SdrUndoRemoveObj >( *ppObj[nDelCount-i] );
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir         for (i=1; i<=nDelCount; i++)
1299cdf0e10cSrcweir             pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir         delete[] ppObj;
1302cdf0e10cSrcweir     }
1303cdf0e10cSrcweir }
1304cdf0e10cSrcweir 
DeleteObjectsInSelection(const ScMarkData & rMark)1305cdf0e10cSrcweir void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
1306cdf0e10cSrcweir {
1307cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::DeleteObjectsInSelection without document" );
1308cdf0e10cSrcweir     if ( !pDoc )
1309cdf0e10cSrcweir         return;
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir     if ( !rMark.IsMultiMarked() )
1312cdf0e10cSrcweir         return;
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir     ScRange aMarkRange;
1315cdf0e10cSrcweir     rMark.GetMultiMarkArea( aMarkRange );
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir     SCTAB nTabCount = pDoc->GetTableCount();
1318cdf0e10cSrcweir     for (SCTAB nTab=0; nTab<=nTabCount; nTab++)
1319cdf0e10cSrcweir         if ( rMark.GetTableSelect( nTab ) )
1320cdf0e10cSrcweir         {
1321cdf0e10cSrcweir             SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
1322cdf0e10cSrcweir             if (pPage)
1323cdf0e10cSrcweir             {
1324cdf0e10cSrcweir                 pPage->RecalcObjOrdNums();
1325cdf0e10cSrcweir                 long    nDelCount = 0;
1326cdf0e10cSrcweir                 sal_uLong   nObjCount = pPage->GetObjCount();
1327cdf0e10cSrcweir                 if (nObjCount)
1328cdf0e10cSrcweir                 {
1329cdf0e10cSrcweir                     //  Rechteck um die ganze Selektion
1330cdf0e10cSrcweir                     Rectangle aMarkBound = pDoc->GetMMRect(
1331cdf0e10cSrcweir                                 aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
1332cdf0e10cSrcweir                                 aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab );
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir                     SdrObject** ppObj = new SdrObject*[nObjCount];
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir                     SdrObjListIter aIter( *pPage, IM_FLAT );
1337cdf0e10cSrcweir                     SdrObject* pObject = aIter.Next();
1338cdf0e10cSrcweir                     while (pObject)
1339cdf0e10cSrcweir                     {
1340cdf0e10cSrcweir                         // do not delete note caption, they are always handled by the cell note
1341cdf0e10cSrcweir                         // TODO: detective objects are still deleted, is this desired?
1342cdf0e10cSrcweir                         if (!IsNoteCaption( pObject ))
1343cdf0e10cSrcweir                         {
1344cdf0e10cSrcweir                             Rectangle aObjRect = pObject->GetCurrentBoundRect();
1345cdf0e10cSrcweir                             if ( aMarkBound.IsInside( aObjRect ) )
1346cdf0e10cSrcweir                             {
1347cdf0e10cSrcweir                                 ScRange aRange = pDoc->GetRange( nTab, aObjRect );
1348cdf0e10cSrcweir                                 if (rMark.IsAllMarked(aRange))
1349cdf0e10cSrcweir                                     ppObj[nDelCount++] = pObject;
1350cdf0e10cSrcweir                             }
1351cdf0e10cSrcweir                         }
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir                         pObject = aIter.Next();
1354cdf0e10cSrcweir                     }
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir                     //  Objekte loeschen (rueckwaerts)
1357cdf0e10cSrcweir 
1358cdf0e10cSrcweir                     long i;
1359cdf0e10cSrcweir                     if (bRecording)
1360cdf0e10cSrcweir                         for (i=1; i<=nDelCount; i++)
1361577c0052SWang Lei                                         AddCalcUndo< SdrUndoRemoveObj >( *ppObj[nDelCount-i] );
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir                     for (i=1; i<=nDelCount; i++)
1364cdf0e10cSrcweir                         pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir                     delete[] ppObj;
1367cdf0e10cSrcweir                 }
1368cdf0e10cSrcweir             }
1369cdf0e10cSrcweir             else
1370cdf0e10cSrcweir             {
1371cdf0e10cSrcweir                 DBG_ERROR("pPage?");
1372cdf0e10cSrcweir             }
1373cdf0e10cSrcweir         }
1374cdf0e10cSrcweir }
1375cdf0e10cSrcweir 
CopyToClip(ScDocument * pClipDoc,SCTAB nTab,const Rectangle & rRange)1376cdf0e10cSrcweir void ScDrawLayer::CopyToClip( ScDocument* pClipDoc, SCTAB nTab, const Rectangle& rRange )
1377cdf0e10cSrcweir {
1378cdf0e10cSrcweir     //  copy everything in the specified range into the same page (sheet) in the clipboard doc
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir     SdrPage* pSrcPage = GetPage(static_cast<sal_uInt16>(nTab));
1381cdf0e10cSrcweir     if (pSrcPage)
1382cdf0e10cSrcweir     {
1383cdf0e10cSrcweir         ScDrawLayer* pDestModel = NULL;
1384cdf0e10cSrcweir         SdrPage* pDestPage = NULL;
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir         SdrObjListIter aIter( *pSrcPage, IM_FLAT );
1387cdf0e10cSrcweir         SdrObject* pOldObject = aIter.Next();
1388cdf0e10cSrcweir         while (pOldObject)
1389cdf0e10cSrcweir         {
1390cdf0e10cSrcweir             Rectangle aObjRect = pOldObject->GetCurrentBoundRect();
1391cdf0e10cSrcweir             // do not copy internal objects (detective) and note captions
1392cdf0e10cSrcweir             if ( rRange.IsInside( aObjRect ) && (pOldObject->GetLayer() != SC_LAYER_INTERN) && !IsNoteCaption( pOldObject ) )
1393cdf0e10cSrcweir             {
1394cdf0e10cSrcweir                 if ( !pDestModel )
1395cdf0e10cSrcweir                 {
1396cdf0e10cSrcweir                     pDestModel = pClipDoc->GetDrawLayer();      // does the document already have a drawing layer?
1397cdf0e10cSrcweir                     if ( !pDestModel )
1398cdf0e10cSrcweir                     {
1399cdf0e10cSrcweir                         //  allocate drawing layer in clipboard document only if there are objects to copy
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir                         pClipDoc->InitDrawLayer();                  //! create contiguous pages
1402cdf0e10cSrcweir                         pDestModel = pClipDoc->GetDrawLayer();
1403cdf0e10cSrcweir                     }
1404cdf0e10cSrcweir                     if (pDestModel)
1405cdf0e10cSrcweir                         pDestPage = pDestModel->GetPage( static_cast<sal_uInt16>(nTab) );
1406cdf0e10cSrcweir                 }
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir                 DBG_ASSERT( pDestPage, "no page" );
1409cdf0e10cSrcweir                 if (pDestPage)
1410cdf0e10cSrcweir                 {
1411cdf0e10cSrcweir                     // #116235#
1412cdf0e10cSrcweir                     SdrObject* pNewObject = pOldObject->Clone();
1413cdf0e10cSrcweir                     //SdrObject* pNewObject = pOldObject->Clone( pDestPage, pDestModel );
1414cdf0e10cSrcweir                     pNewObject->SetModel(pDestModel);
1415cdf0e10cSrcweir                     pNewObject->SetPage(pDestPage);
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir                     uno::Reference< chart2::XChartDocument > xOldChart( ScChartHelper::GetChartFromSdrObject( pOldObject ) );
1418cdf0e10cSrcweir                     if(!xOldChart.is())//#i110034# do not move charts as they loose all their data references otherwise
1419cdf0e10cSrcweir                         pNewObject->NbcMove(Size(0,0));
1420cdf0e10cSrcweir                     pDestPage->InsertObject( pNewObject );
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir                     //  no undo needed in clipboard document
1423cdf0e10cSrcweir                     //  charts are not updated
1424cdf0e10cSrcweir                 }
1425cdf0e10cSrcweir             }
1426cdf0e10cSrcweir 
1427cdf0e10cSrcweir             pOldObject = aIter.Next();
1428cdf0e10cSrcweir         }
1429cdf0e10cSrcweir     }
1430cdf0e10cSrcweir }
1431cdf0e10cSrcweir 
lcl_IsAllInRange(const::std::vector<ScRangeList> & rRangesVector,const ScRange & rClipRange)1432cdf0e10cSrcweir sal_Bool lcl_IsAllInRange( const ::std::vector< ScRangeList >& rRangesVector, const ScRange& rClipRange )
1433cdf0e10cSrcweir {
1434cdf0e10cSrcweir     //  check if every range of rRangesVector is completely in rClipRange
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir     ::std::vector< ScRangeList >::const_iterator aIt = rRangesVector.begin();
1437cdf0e10cSrcweir     for( ;aIt!=rRangesVector.end(); ++aIt )
1438cdf0e10cSrcweir     {
1439cdf0e10cSrcweir         const ScRangeList& rRanges = *aIt;
1440cdf0e10cSrcweir         sal_uLong nCount = rRanges.Count();
1441cdf0e10cSrcweir         for (sal_uLong i=0; i<nCount; i++)
1442cdf0e10cSrcweir         {
1443cdf0e10cSrcweir             ScRange aRange = *rRanges.GetObject(i);
1444cdf0e10cSrcweir             if ( !rClipRange.In( aRange ) )
1445cdf0e10cSrcweir             {
1446cdf0e10cSrcweir                 return sal_False;   // at least one range is not valid
1447cdf0e10cSrcweir             }
1448cdf0e10cSrcweir         }
1449cdf0e10cSrcweir     }
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir     return sal_True;            // everything is fine
1452cdf0e10cSrcweir }
1453cdf0e10cSrcweir 
lcl_MoveRanges(::std::vector<ScRangeList> & rRangesVector,const ScRange & rSourceRange,const ScAddress & rDestPos)1454cdf0e10cSrcweir sal_Bool lcl_MoveRanges( ::std::vector< ScRangeList >& rRangesVector, const ScRange& rSourceRange, const ScAddress& rDestPos )
1455cdf0e10cSrcweir {
1456cdf0e10cSrcweir     sal_Bool bChanged = sal_False;
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir     ::std::vector< ScRangeList >::iterator aIt = rRangesVector.begin();
1459cdf0e10cSrcweir     for( ;aIt!=rRangesVector.end(); ++aIt )
1460cdf0e10cSrcweir     {
1461cdf0e10cSrcweir         ScRangeList& rRanges = *aIt;
1462cdf0e10cSrcweir         sal_uLong nCount = rRanges.Count();
1463cdf0e10cSrcweir         for (sal_uLong i=0; i<nCount; i++)
1464cdf0e10cSrcweir         {
1465cdf0e10cSrcweir             ScRange* pRange = rRanges.GetObject(i);
1466cdf0e10cSrcweir             if ( rSourceRange.In( *pRange ) )
1467cdf0e10cSrcweir             {
1468cdf0e10cSrcweir                 SCsCOL nDiffX = rDestPos.Col() - (SCsCOL)rSourceRange.aStart.Col();
1469cdf0e10cSrcweir                 SCsROW nDiffY = rDestPos.Row() - (SCsROW)rSourceRange.aStart.Row();
1470cdf0e10cSrcweir                 SCsTAB nDiffZ = rDestPos.Tab() - (SCsTAB)rSourceRange.aStart.Tab();
1471cdf0e10cSrcweir                 pRange->Move( nDiffX, nDiffY, nDiffZ );
1472cdf0e10cSrcweir                 bChanged = sal_True;
1473cdf0e10cSrcweir             }
1474cdf0e10cSrcweir         }
1475cdf0e10cSrcweir     }
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir     return bChanged;
1478cdf0e10cSrcweir }
1479cdf0e10cSrcweir 
CopyFromClip(ScDrawLayer * pClipModel,SCTAB nSourceTab,const Rectangle & rSourceRange,const ScAddress & rDestPos,const Rectangle & rDestRange)1480cdf0e10cSrcweir void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const Rectangle& rSourceRange,
1481cdf0e10cSrcweir                                     const ScAddress& rDestPos, const Rectangle& rDestRange )
1482cdf0e10cSrcweir {
1483cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::CopyFromClip without document" );
1484cdf0e10cSrcweir     if ( !pDoc )
1485cdf0e10cSrcweir         return;
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir     if (!pClipModel)
1488cdf0e10cSrcweir         return;
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir     if (bDrawIsInUndo)      //! can this happen?
1491cdf0e10cSrcweir     {
1492cdf0e10cSrcweir         DBG_ERROR("CopyFromClip, bDrawIsInUndo");
1493cdf0e10cSrcweir         return;
1494cdf0e10cSrcweir     }
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir     sal_Bool bMirrorObj = ( rSourceRange.Left() < 0 && rSourceRange.Right() < 0 &&
1497cdf0e10cSrcweir                         rDestRange.Left()   > 0 && rDestRange.Right()   > 0 ) ||
1498cdf0e10cSrcweir                       ( rSourceRange.Left() > 0 && rSourceRange.Right() > 0 &&
1499cdf0e10cSrcweir                         rDestRange.Left()   < 0 && rDestRange.Right()   < 0 );
1500cdf0e10cSrcweir     Rectangle aMirroredSource = rSourceRange;
1501cdf0e10cSrcweir     if ( bMirrorObj )
1502cdf0e10cSrcweir         MirrorRectRTL( aMirroredSource );
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir     SCTAB nDestTab = rDestPos.Tab();
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir     SdrPage* pSrcPage = pClipModel->GetPage(static_cast<sal_uInt16>(nSourceTab));
1507cdf0e10cSrcweir     SdrPage* pDestPage = GetPage(static_cast<sal_uInt16>(nDestTab));
1508cdf0e10cSrcweir     DBG_ASSERT( pSrcPage && pDestPage, "draw page missing" );
1509cdf0e10cSrcweir     if ( !pSrcPage || !pDestPage )
1510cdf0e10cSrcweir         return;
1511cdf0e10cSrcweir 
1512cdf0e10cSrcweir     SdrObjListIter aIter( *pSrcPage, IM_FLAT );
1513cdf0e10cSrcweir     SdrObject* pOldObject = aIter.Next();
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir     ScDocument* pClipDoc = pClipModel->GetDocument();
1516cdf0e10cSrcweir     //  a clipboard document and its source share the same document item pool,
1517cdf0e10cSrcweir     //  so the pointers can be compared to see if this is copy&paste within
1518cdf0e10cSrcweir     //  the same document
1519cdf0e10cSrcweir     sal_Bool bSameDoc = pDoc && pClipDoc && pDoc->GetPool() == pClipDoc->GetPool();
1520cdf0e10cSrcweir     sal_Bool bDestClip = pDoc && pDoc->IsClipboard();
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir     //#i110034# charts need correct sheet names for xml range conversion during load
1523cdf0e10cSrcweir     //so the target sheet name is temporarily renamed (if we have any SdrObjects)
1524cdf0e10cSrcweir     String aDestTabName;
1525cdf0e10cSrcweir     sal_Bool bRestoreDestTabName = sal_False;
1526cdf0e10cSrcweir     if( pOldObject && !bSameDoc && !bDestClip )
1527cdf0e10cSrcweir     {
1528cdf0e10cSrcweir         if( pDoc && pClipDoc )
1529cdf0e10cSrcweir         {
1530cdf0e10cSrcweir             String aSourceTabName;
1531cdf0e10cSrcweir             if( pClipDoc->GetName( nSourceTab, aSourceTabName )
1532cdf0e10cSrcweir                 && pDoc->GetName( nDestTab, aDestTabName ) )
1533cdf0e10cSrcweir             {
1534cdf0e10cSrcweir                 if( !(aSourceTabName==aDestTabName) &&
1535cdf0e10cSrcweir                     pDoc->ValidNewTabName(aSourceTabName) )
1536cdf0e10cSrcweir                 {
1537cdf0e10cSrcweir                     bRestoreDestTabName = pDoc->RenameTab( nDestTab, aSourceTabName ); //sal_Bool bUpdateRef = sal_True, sal_Bool bExternalDocument = sal_False
1538cdf0e10cSrcweir                 }
1539cdf0e10cSrcweir             }
1540cdf0e10cSrcweir         }
1541cdf0e10cSrcweir     }
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir     // first mirror, then move
1544cdf0e10cSrcweir     Size aMove( rDestRange.Left() - aMirroredSource.Left(), rDestRange.Top() - aMirroredSource.Top() );
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir     long nDestWidth = rDestRange.GetWidth();
1547cdf0e10cSrcweir     long nDestHeight = rDestRange.GetHeight();
1548cdf0e10cSrcweir     long nSourceWidth = rSourceRange.GetWidth();
1549cdf0e10cSrcweir     long nSourceHeight = rSourceRange.GetHeight();
1550cdf0e10cSrcweir 
1551cdf0e10cSrcweir     long nWidthDiff = nDestWidth - nSourceWidth;
1552cdf0e10cSrcweir     long nHeightDiff = nDestHeight - nSourceHeight;
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir     Fraction aHorFract(1,1);
1555cdf0e10cSrcweir     Fraction aVerFract(1,1);
1556cdf0e10cSrcweir     sal_Bool bResize = sal_False;
1557cdf0e10cSrcweir     // sizes can differ by 1 from twips->1/100mm conversion for equal cell sizes,
1558cdf0e10cSrcweir     // don't resize to empty size when pasting into hidden columns or rows
1559cdf0e10cSrcweir     if ( Abs(nWidthDiff) > 1 && nDestWidth > 1 && nSourceWidth > 1 )
1560cdf0e10cSrcweir     {
1561cdf0e10cSrcweir         aHorFract = Fraction( nDestWidth, nSourceWidth );
1562cdf0e10cSrcweir         bResize = sal_True;
1563cdf0e10cSrcweir     }
1564cdf0e10cSrcweir     if ( Abs(nHeightDiff) > 1 && nDestHeight > 1 && nSourceHeight > 1 )
1565cdf0e10cSrcweir     {
1566cdf0e10cSrcweir         aVerFract = Fraction( nDestHeight, nSourceHeight );
1567cdf0e10cSrcweir         bResize = sal_True;
1568cdf0e10cSrcweir     }
1569cdf0e10cSrcweir     Point aRefPos = rDestRange.TopLeft();       // for resizing (after moving)
1570cdf0e10cSrcweir 
1571cdf0e10cSrcweir     while (pOldObject)
1572cdf0e10cSrcweir     {
1573cdf0e10cSrcweir         Rectangle aObjRect = pOldObject->GetCurrentBoundRect();
1574cdf0e10cSrcweir         // do not copy internal objects (detective) and note captions
1575cdf0e10cSrcweir         if ( rSourceRange.IsInside( aObjRect ) && (pOldObject->GetLayer() != SC_LAYER_INTERN) && !IsNoteCaption( pOldObject ) )
1576cdf0e10cSrcweir         {
1577cdf0e10cSrcweir             // #116235#
1578cdf0e10cSrcweir             SdrObject* pNewObject = pOldObject->Clone();
1579cdf0e10cSrcweir             //SdrObject* pNewObject = pOldObject->Clone( pDestPage, this );
1580cdf0e10cSrcweir             pNewObject->SetModel(this);
1581cdf0e10cSrcweir             pNewObject->SetPage(pDestPage);
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir             if ( bMirrorObj )
1584cdf0e10cSrcweir                 MirrorRTL( pNewObject );        // first mirror, then move
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir             pNewObject->NbcMove( aMove );
1587cdf0e10cSrcweir             if ( bResize )
1588cdf0e10cSrcweir                 pNewObject->NbcResize( aRefPos, aHorFract, aVerFract );
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir             pDestPage->InsertObject( pNewObject );
1591cdf0e10cSrcweir             if (bRecording)
1592577c0052SWang Lei                         AddCalcUndo< SdrUndoInsertObj >( *pNewObject );
1593cdf0e10cSrcweir 
1594cdf0e10cSrcweir             //#i110034# handle chart data references (after InsertObject)
1595cdf0e10cSrcweir 
1596cdf0e10cSrcweir             if ( pNewObject->GetObjIdentifier() == OBJ_OLE2 )
1597cdf0e10cSrcweir             {
1598cdf0e10cSrcweir                 uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pNewObject)->GetObjRef();
1599cdf0e10cSrcweir                 uno::Reference< embed::XClassifiedObject > xClassified( xIPObj, uno::UNO_QUERY );
1600cdf0e10cSrcweir                 SvGlobalName aObjectClassName;
1601cdf0e10cSrcweir                 if ( xClassified.is() )
1602cdf0e10cSrcweir                 {
1603cdf0e10cSrcweir                     try {
1604cdf0e10cSrcweir                         aObjectClassName = SvGlobalName( xClassified->getClassID() );
1605cdf0e10cSrcweir                     } catch( uno::Exception& )
1606cdf0e10cSrcweir                     {
1607cdf0e10cSrcweir                         // TODO: handle error?
1608cdf0e10cSrcweir                     }
1609cdf0e10cSrcweir                 }
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir                 if ( xIPObj.is() && SotExchange::IsChart( aObjectClassName ) )
1612cdf0e10cSrcweir                 {
1613cdf0e10cSrcweir                     uno::Reference< chart2::XChartDocument > xNewChart( ScChartHelper::GetChartFromSdrObject( pNewObject ) );
1614cdf0e10cSrcweir                     if( xNewChart.is() && !xNewChart->hasInternalDataProvider() )
1615cdf0e10cSrcweir                     {
1616cdf0e10cSrcweir                         String aChartName = ((SdrOle2Obj*)pNewObject)->GetPersistName();
1617cdf0e10cSrcweir                         ::std::vector< ScRangeList > aRangesVector;
1618cdf0e10cSrcweir                         pDoc->GetChartRanges( aChartName, aRangesVector, pDoc );
1619cdf0e10cSrcweir                         if( !aRangesVector.empty() )
1620cdf0e10cSrcweir                         {
1621cdf0e10cSrcweir                             sal_Bool bInSourceRange = sal_False;
1622cdf0e10cSrcweir                             ScRange aClipRange;
1623cdf0e10cSrcweir                             if ( pClipDoc )
1624cdf0e10cSrcweir                             {
1625cdf0e10cSrcweir                                 SCCOL nClipStartX;
1626cdf0e10cSrcweir                                 SCROW nClipStartY;
1627cdf0e10cSrcweir                                 SCCOL nClipEndX;
1628cdf0e10cSrcweir                                 SCROW nClipEndY;
1629cdf0e10cSrcweir                                 pClipDoc->GetClipStart( nClipStartX, nClipStartY );
1630cdf0e10cSrcweir                                 pClipDoc->GetClipArea( nClipEndX, nClipEndY, sal_True );
1631cdf0e10cSrcweir                                 nClipEndX = nClipEndX + nClipStartX;
1632cdf0e10cSrcweir                                 nClipEndY += nClipStartY;   // GetClipArea returns the difference
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir                                 SCTAB nClipTab = bRestoreDestTabName ? nDestTab : nSourceTab;
1635cdf0e10cSrcweir                                 aClipRange = ScRange( nClipStartX, nClipStartY, nClipTab,
1636cdf0e10cSrcweir                                                         nClipEndX, nClipEndY, nClipTab );
1637cdf0e10cSrcweir 
1638cdf0e10cSrcweir                                 bInSourceRange = lcl_IsAllInRange( aRangesVector, aClipRange );
1639cdf0e10cSrcweir                             }
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir                             // always lose references when pasting into a clipboard document (transpose)
1642cdf0e10cSrcweir                             if ( ( bInSourceRange || bSameDoc ) && !bDestClip )
1643cdf0e10cSrcweir                             {
1644cdf0e10cSrcweir                                 if ( bInSourceRange )
1645cdf0e10cSrcweir                                 {
1646cdf0e10cSrcweir                                     if ( rDestPos != aClipRange.aStart )
1647cdf0e10cSrcweir                                     {
1648cdf0e10cSrcweir                                         //  update the data ranges to the new (copied) position
1649cdf0e10cSrcweir                                         if ( lcl_MoveRanges( aRangesVector, aClipRange, rDestPos ) )
1650cdf0e10cSrcweir                                             pDoc->SetChartRanges( aChartName, aRangesVector );
1651cdf0e10cSrcweir                                     }
1652cdf0e10cSrcweir                                 }
1653cdf0e10cSrcweir                                 else
1654cdf0e10cSrcweir                                 {
1655cdf0e10cSrcweir                                     //  leave the ranges unchanged
1656cdf0e10cSrcweir                                 }
1657cdf0e10cSrcweir                             }
1658cdf0e10cSrcweir                             else
1659cdf0e10cSrcweir                             {
1660cdf0e10cSrcweir                                 //  pasting into a new document without the complete source data
1661cdf0e10cSrcweir                                 //  -> break connection to source data and switch to own data
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir                                 uno::Reference< chart::XChartDocument > xOldChartDoc( ScChartHelper::GetChartFromSdrObject( pOldObject ), uno::UNO_QUERY );
1664cdf0e10cSrcweir                                 uno::Reference< chart::XChartDocument > xNewChartDoc( xNewChart, uno::UNO_QUERY );
1665cdf0e10cSrcweir                                 if( xOldChartDoc.is() && xNewChartDoc.is() )
1666cdf0e10cSrcweir                                     xNewChartDoc->attachData( xOldChartDoc->getData() );
1667cdf0e10cSrcweir 
1668cdf0e10cSrcweir                                 //  (see ScDocument::UpdateChartListenerCollection, PastingDrawFromOtherDoc)
1669cdf0e10cSrcweir                             }
1670cdf0e10cSrcweir                         }
1671cdf0e10cSrcweir                     }
1672cdf0e10cSrcweir                 }
1673cdf0e10cSrcweir             }
1674cdf0e10cSrcweir         }
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir         pOldObject = aIter.Next();
1677cdf0e10cSrcweir     }
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir     if( bRestoreDestTabName )
1680cdf0e10cSrcweir         pDoc->RenameTab( nDestTab, aDestTabName );
1681cdf0e10cSrcweir }
1682cdf0e10cSrcweir 
MirrorRTL(SdrObject * pObj)1683cdf0e10cSrcweir void ScDrawLayer::MirrorRTL( SdrObject* pObj )
1684cdf0e10cSrcweir {
1685cdf0e10cSrcweir     sal_uInt16 nIdent = pObj->GetObjIdentifier();
1686cdf0e10cSrcweir 
1687cdf0e10cSrcweir     //  don't mirror OLE or graphics, otherwise ask the object
1688cdf0e10cSrcweir     //  if it can be mirrored
1689cdf0e10cSrcweir     sal_Bool bCanMirror = ( nIdent != OBJ_GRAF && nIdent != OBJ_OLE2 );
1690cdf0e10cSrcweir     if (bCanMirror)
1691cdf0e10cSrcweir     {
1692cdf0e10cSrcweir         SdrObjTransformInfoRec aInfo;
1693cdf0e10cSrcweir         pObj->TakeObjInfo( aInfo );
1694cdf0e10cSrcweir         bCanMirror = aInfo.bMirror90Allowed;
1695cdf0e10cSrcweir     }
1696cdf0e10cSrcweir 
1697cdf0e10cSrcweir     if (bCanMirror)
1698cdf0e10cSrcweir     {
1699cdf0e10cSrcweir         Point aRef1( 0, 0 );
1700cdf0e10cSrcweir         Point aRef2( 0, 1 );
1701cdf0e10cSrcweir         if (bRecording)
1702577c0052SWang Lei                     AddCalcUndo< SdrUndoGeoObj >( *pObj );
1703cdf0e10cSrcweir         pObj->Mirror( aRef1, aRef2 );
1704cdf0e10cSrcweir     }
1705cdf0e10cSrcweir     else
1706cdf0e10cSrcweir     {
1707cdf0e10cSrcweir         //  Move instead of mirroring:
1708cdf0e10cSrcweir         //  New start position is negative of old end position
1709cdf0e10cSrcweir         //  -> move by sum of start and end position
1710cdf0e10cSrcweir         Rectangle aObjRect = pObj->GetLogicRect();
1711cdf0e10cSrcweir         Size aMoveSize( -(aObjRect.Left() + aObjRect.Right()), 0 );
1712cdf0e10cSrcweir         if (bRecording)
1713577c0052SWang Lei                     AddCalcUndo< SdrUndoMoveObj >( *pObj, aMoveSize );
1714cdf0e10cSrcweir         pObj->Move( aMoveSize );
1715cdf0e10cSrcweir     }
1716cdf0e10cSrcweir }
1717cdf0e10cSrcweir 
1718cdf0e10cSrcweir // static
MirrorRectRTL(Rectangle & rRect)1719cdf0e10cSrcweir void ScDrawLayer::MirrorRectRTL( Rectangle& rRect )
1720cdf0e10cSrcweir {
1721cdf0e10cSrcweir     //  mirror and swap left/right
1722cdf0e10cSrcweir     long nTemp = rRect.Left();
1723cdf0e10cSrcweir     rRect.Left() = -rRect.Right();
1724cdf0e10cSrcweir     rRect.Right() = -nTemp;
1725cdf0e10cSrcweir }
1726cdf0e10cSrcweir 
GetCellRect(ScDocument & rDoc,const ScAddress & rPos,bool bMergedCell)1727cdf0e10cSrcweir Rectangle ScDrawLayer::GetCellRect( ScDocument& rDoc, const ScAddress& rPos, bool bMergedCell )
1728cdf0e10cSrcweir {
1729cdf0e10cSrcweir     Rectangle aCellRect;
1730cdf0e10cSrcweir     DBG_ASSERT( ValidColRowTab( rPos.Col(), rPos.Row(), rPos.Tab() ), "ScDrawLayer::GetCellRect - invalid cell address" );
1731cdf0e10cSrcweir     if( ValidColRowTab( rPos.Col(), rPos.Row(), rPos.Tab() ) )
1732cdf0e10cSrcweir     {
1733cdf0e10cSrcweir         // find top left position of passed cell address
1734cdf0e10cSrcweir         Point aTopLeft;
1735cdf0e10cSrcweir         for( SCCOL nCol = 0; nCol < rPos.Col(); ++nCol )
1736cdf0e10cSrcweir             aTopLeft.X() += rDoc.GetColWidth( nCol, rPos.Tab() );
1737cdf0e10cSrcweir         if( rPos.Row() > 0 )
1738cdf0e10cSrcweir             aTopLeft.Y() += rDoc.GetRowHeight( 0, rPos.Row() - 1, rPos.Tab() );
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir         // find bottom-right position of passed cell address
1741cdf0e10cSrcweir         ScAddress aEndPos = rPos;
1742cdf0e10cSrcweir         if( bMergedCell )
1743cdf0e10cSrcweir         {
1744cdf0e10cSrcweir             const ScMergeAttr* pMerge = static_cast< const ScMergeAttr* >( rDoc.GetAttr( rPos.Col(), rPos.Row(), rPos.Tab(), ATTR_MERGE ) );
1745cdf0e10cSrcweir             if( pMerge->GetColMerge() > 1 )
1746cdf0e10cSrcweir                 aEndPos.IncCol( pMerge->GetColMerge() - 1 );
1747cdf0e10cSrcweir             if( pMerge->GetRowMerge() > 1 )
1748cdf0e10cSrcweir                 aEndPos.IncRow( pMerge->GetRowMerge() - 1 );
1749cdf0e10cSrcweir         }
1750cdf0e10cSrcweir         Point aBotRight = aTopLeft;
1751cdf0e10cSrcweir         for( SCCOL nCol = rPos.Col(); nCol <= aEndPos.Col(); ++nCol )
1752cdf0e10cSrcweir             aBotRight.X() += rDoc.GetColWidth( nCol, rPos.Tab() );
1753cdf0e10cSrcweir         aBotRight.Y() += rDoc.GetRowHeight( rPos.Row(), aEndPos.Row(), rPos.Tab() );
1754cdf0e10cSrcweir 
1755cdf0e10cSrcweir         // twips -> 1/100 mm
1756cdf0e10cSrcweir         aTopLeft.X() = static_cast< long >( aTopLeft.X() * HMM_PER_TWIPS );
1757cdf0e10cSrcweir         aTopLeft.Y() = static_cast< long >( aTopLeft.Y() * HMM_PER_TWIPS );
1758cdf0e10cSrcweir         aBotRight.X() = static_cast< long >( aBotRight.X() * HMM_PER_TWIPS );
1759cdf0e10cSrcweir         aBotRight.Y() = static_cast< long >( aBotRight.Y() * HMM_PER_TWIPS );
1760cdf0e10cSrcweir 
1761cdf0e10cSrcweir         aCellRect = Rectangle( aTopLeft, aBotRight );
1762cdf0e10cSrcweir         if( rDoc.IsNegativePage( rPos.Tab() ) )
1763cdf0e10cSrcweir             MirrorRectRTL( aCellRect );
1764cdf0e10cSrcweir     }
1765cdf0e10cSrcweir     return aCellRect;
1766cdf0e10cSrcweir }
1767cdf0e10cSrcweir 
1768cdf0e10cSrcweir // static
GetVisibleName(SdrObject * pObj)1769cdf0e10cSrcweir String ScDrawLayer::GetVisibleName( SdrObject* pObj )
1770cdf0e10cSrcweir {
1771cdf0e10cSrcweir     String aName = pObj->GetName();
1772cdf0e10cSrcweir     if ( pObj->GetObjIdentifier() == OBJ_OLE2 )
1773cdf0e10cSrcweir     {
1774cdf0e10cSrcweir         //  #95575# For OLE, the user defined name (GetName) is used
1775cdf0e10cSrcweir         //  if it's not empty (accepting possibly duplicate names),
1776cdf0e10cSrcweir         //  otherwise the persist name is used so every object appears
1777cdf0e10cSrcweir         //  in the Navigator at all.
1778cdf0e10cSrcweir 
1779cdf0e10cSrcweir         if ( !aName.Len() )
1780cdf0e10cSrcweir             aName = static_cast<SdrOle2Obj*>(pObj)->GetPersistName();
1781cdf0e10cSrcweir     }
1782cdf0e10cSrcweir     return aName;
1783cdf0e10cSrcweir }
1784cdf0e10cSrcweir 
IsNamedObject(SdrObject * pObj,const String & rName)1785cdf0e10cSrcweir inline sal_Bool IsNamedObject( SdrObject* pObj, const String& rName )
1786cdf0e10cSrcweir {
1787cdf0e10cSrcweir     //  sal_True if rName is the object's Name or PersistName
1788cdf0e10cSrcweir     //  (used to find a named object)
1789cdf0e10cSrcweir 
1790cdf0e10cSrcweir     return ( pObj->GetName() == rName ||
1791cdf0e10cSrcweir             ( pObj->GetObjIdentifier() == OBJ_OLE2 &&
1792cdf0e10cSrcweir               static_cast<SdrOle2Obj*>(pObj)->GetPersistName() == rName ) );
1793cdf0e10cSrcweir }
1794cdf0e10cSrcweir 
GetNamedObject(const String & rName,sal_uInt16 nId,SCTAB & rFoundTab) const1795cdf0e10cSrcweir SdrObject* ScDrawLayer::GetNamedObject( const String& rName, sal_uInt16 nId, SCTAB& rFoundTab ) const
1796cdf0e10cSrcweir {
1797cdf0e10cSrcweir     sal_uInt16 nTabCount = GetPageCount();
1798cdf0e10cSrcweir     for (sal_uInt16 nTab=0; nTab<nTabCount; nTab++)
1799cdf0e10cSrcweir     {
1800cdf0e10cSrcweir         const SdrPage* pPage = GetPage(nTab);
1801cdf0e10cSrcweir         DBG_ASSERT(pPage,"Page ?");
1802cdf0e10cSrcweir         if (pPage)
1803cdf0e10cSrcweir         {
1804cdf0e10cSrcweir             SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
1805cdf0e10cSrcweir             SdrObject* pObject = aIter.Next();
1806cdf0e10cSrcweir             while (pObject)
1807cdf0e10cSrcweir             {
1808cdf0e10cSrcweir                 if ( nId == 0 || pObject->GetObjIdentifier() == nId )
1809cdf0e10cSrcweir                     if ( IsNamedObject( pObject, rName ) )
1810cdf0e10cSrcweir                     {
1811cdf0e10cSrcweir                         rFoundTab = static_cast<SCTAB>(nTab);
1812cdf0e10cSrcweir                         return pObject;
1813cdf0e10cSrcweir                     }
1814cdf0e10cSrcweir 
1815cdf0e10cSrcweir                 pObject = aIter.Next();
1816cdf0e10cSrcweir             }
1817cdf0e10cSrcweir         }
1818cdf0e10cSrcweir     }
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir     return NULL;
1821cdf0e10cSrcweir }
1822cdf0e10cSrcweir 
GetNewGraphicName(long * pnCounter) const1823cdf0e10cSrcweir String ScDrawLayer::GetNewGraphicName( long* pnCounter ) const
1824cdf0e10cSrcweir {
1825cdf0e10cSrcweir     String aBase = ScGlobal::GetRscString(STR_GRAPHICNAME);
1826cdf0e10cSrcweir     aBase += ' ';
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir     sal_Bool bThere = sal_True;
1829cdf0e10cSrcweir     String aGraphicName;
1830cdf0e10cSrcweir     SCTAB nDummy;
1831cdf0e10cSrcweir     long nId = pnCounter ? *pnCounter : 0;
1832cdf0e10cSrcweir     while (bThere)
1833cdf0e10cSrcweir     {
1834cdf0e10cSrcweir         ++nId;
1835cdf0e10cSrcweir         aGraphicName = aBase;
1836cdf0e10cSrcweir         aGraphicName += String::CreateFromInt32( nId );
1837cdf0e10cSrcweir         bThere = ( GetNamedObject( aGraphicName, 0, nDummy ) != NULL );
1838cdf0e10cSrcweir     }
1839cdf0e10cSrcweir 
1840cdf0e10cSrcweir     if ( pnCounter )
1841cdf0e10cSrcweir         *pnCounter = nId;
1842cdf0e10cSrcweir 
1843cdf0e10cSrcweir     return aGraphicName;
1844cdf0e10cSrcweir }
1845cdf0e10cSrcweir 
EnsureGraphicNames()1846cdf0e10cSrcweir void ScDrawLayer::EnsureGraphicNames()
1847cdf0e10cSrcweir {
1848cdf0e10cSrcweir     //  make sure all graphic objects have names (after Excel import etc.)
1849cdf0e10cSrcweir 
1850cdf0e10cSrcweir     sal_uInt16 nTabCount = GetPageCount();
1851cdf0e10cSrcweir     for (sal_uInt16 nTab=0; nTab<nTabCount; nTab++)
1852cdf0e10cSrcweir     {
1853cdf0e10cSrcweir         SdrPage* pPage = GetPage(nTab);
1854cdf0e10cSrcweir         DBG_ASSERT(pPage,"Page ?");
1855cdf0e10cSrcweir         if (pPage)
1856cdf0e10cSrcweir         {
1857cdf0e10cSrcweir             SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
1858cdf0e10cSrcweir             SdrObject* pObject = aIter.Next();
1859cdf0e10cSrcweir 
1860cdf0e10cSrcweir             /* #101799# The index passed to GetNewGraphicName() will be set to
1861cdf0e10cSrcweir                 the used index in each call. This prevents the repeated search
1862cdf0e10cSrcweir                 for all names from 1 to current index. */
1863cdf0e10cSrcweir             long nCounter = 0;
1864cdf0e10cSrcweir 
1865cdf0e10cSrcweir             while (pObject)
1866cdf0e10cSrcweir             {
1867cdf0e10cSrcweir                 if ( pObject->GetObjIdentifier() == OBJ_GRAF && pObject->GetName().Len() == 0 )
1868cdf0e10cSrcweir                     pObject->SetName( GetNewGraphicName( &nCounter ) );
1869cdf0e10cSrcweir 
1870cdf0e10cSrcweir                 pObject = aIter.Next();
1871cdf0e10cSrcweir             }
1872cdf0e10cSrcweir         }
1873cdf0e10cSrcweir     }
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir 
SetAnchor(SdrObject * pObj,ScAnchorType eType)1876cdf0e10cSrcweir void ScDrawLayer::SetAnchor( SdrObject* pObj, ScAnchorType eType )
1877cdf0e10cSrcweir {
1878cdf0e10cSrcweir     ScAnchorType eOldAnchorType = GetAnchor( pObj );
1879cdf0e10cSrcweir 
1880cdf0e10cSrcweir     // Ein an der Seite verankertes Objekt zeichnet sich durch eine Anker-Pos
1881cdf0e10cSrcweir     // von (0,1) aus. Das ist ein shabby Trick, der aber funktioniert!
1882cdf0e10cSrcweir     Point aAnchor( 0, eType == SCA_PAGE ? 1 : 0 );
1883cdf0e10cSrcweir     pObj->SetAnchorPos( aAnchor );
1884cdf0e10cSrcweir 
1885cdf0e10cSrcweir     if ( eOldAnchorType != eType )
1886cdf0e10cSrcweir         pObj->notifyShapePropertyChange( ::svx::eSpreadsheetAnchor );
1887cdf0e10cSrcweir }
1888cdf0e10cSrcweir 
GetAnchor(const SdrObject * pObj)1889cdf0e10cSrcweir ScAnchorType ScDrawLayer::GetAnchor( const SdrObject* pObj )
1890cdf0e10cSrcweir {
1891cdf0e10cSrcweir     Point aAnchor( pObj->GetAnchorPos() );
1892cdf0e10cSrcweir     return ( aAnchor.Y() != 0 ) ? SCA_PAGE : SCA_CELL;
1893cdf0e10cSrcweir }
1894cdf0e10cSrcweir 
GetObjData(SdrObject * pObj,sal_Bool bCreate)1895cdf0e10cSrcweir ScDrawObjData* ScDrawLayer::GetObjData( SdrObject* pObj, sal_Bool bCreate )     // static
1896cdf0e10cSrcweir {
1897cdf0e10cSrcweir     sal_uInt16 nCount = pObj ? pObj->GetUserDataCount() : 0;
1898cdf0e10cSrcweir     for( sal_uInt16 i = 0; i < nCount; i++ )
1899cdf0e10cSrcweir     {
1900cdf0e10cSrcweir         SdrObjUserData* pData = pObj->GetUserData( i );
1901cdf0e10cSrcweir         if( pData && pData->GetInventor() == SC_DRAWLAYER
1902cdf0e10cSrcweir                     && pData->GetId() == SC_UD_OBJDATA )
1903cdf0e10cSrcweir             return (ScDrawObjData*) pData;
1904cdf0e10cSrcweir     }
1905cdf0e10cSrcweir     if( pObj && bCreate )
1906cdf0e10cSrcweir     {
1907cdf0e10cSrcweir         ScDrawObjData* pData = new ScDrawObjData;
1908cdf0e10cSrcweir         pObj->InsertUserData( pData, 0 );
1909cdf0e10cSrcweir         return pData;
1910cdf0e10cSrcweir     }
1911cdf0e10cSrcweir     return 0;
1912cdf0e10cSrcweir }
1913cdf0e10cSrcweir 
GetObjDataTab(SdrObject * pObj,SCTAB nTab)1914cdf0e10cSrcweir ScDrawObjData* ScDrawLayer::GetObjDataTab( SdrObject* pObj, SCTAB nTab )    // static
1915cdf0e10cSrcweir {
1916cdf0e10cSrcweir     ScDrawObjData* pData = GetObjData( pObj );
1917cdf0e10cSrcweir     if ( pData )
1918cdf0e10cSrcweir     {
1919cdf0e10cSrcweir         if ( pData->maStart.IsValid() )
1920cdf0e10cSrcweir             pData->maStart.SetTab( nTab );
1921cdf0e10cSrcweir         if ( pData->maEnd.IsValid() )
1922cdf0e10cSrcweir             pData->maEnd.SetTab( nTab );
1923cdf0e10cSrcweir     }
1924cdf0e10cSrcweir     return pData;
1925cdf0e10cSrcweir }
1926cdf0e10cSrcweir 
IsNoteCaption(SdrObject * pObj)1927cdf0e10cSrcweir bool ScDrawLayer::IsNoteCaption( SdrObject* pObj )
1928cdf0e10cSrcweir {
1929cdf0e10cSrcweir     ScDrawObjData* pData = pObj ? GetObjData( pObj ) : 0;
1930cdf0e10cSrcweir     return pData && pData->mbNote;
1931cdf0e10cSrcweir }
1932cdf0e10cSrcweir 
GetNoteCaptionData(SdrObject * pObj,SCTAB nTab)1933cdf0e10cSrcweir ScDrawObjData* ScDrawLayer::GetNoteCaptionData( SdrObject* pObj, SCTAB nTab )
1934cdf0e10cSrcweir {
1935cdf0e10cSrcweir     ScDrawObjData* pData = pObj ? GetObjDataTab( pObj, nTab ) : 0;
1936cdf0e10cSrcweir     return (pData && pData->mbNote) ? pData : 0;
1937cdf0e10cSrcweir }
1938cdf0e10cSrcweir 
GetIMapInfo(SdrObject * pObj)1939cdf0e10cSrcweir ScIMapInfo* ScDrawLayer::GetIMapInfo( SdrObject* pObj )             // static
1940cdf0e10cSrcweir {
1941cdf0e10cSrcweir     sal_uInt16 nCount = pObj->GetUserDataCount();
1942cdf0e10cSrcweir     for( sal_uInt16 i = 0; i < nCount; i++ )
1943cdf0e10cSrcweir     {
1944cdf0e10cSrcweir         SdrObjUserData* pData = pObj->GetUserData( i );
1945cdf0e10cSrcweir         if( pData && pData->GetInventor() == SC_DRAWLAYER
1946cdf0e10cSrcweir                     && pData->GetId() == SC_UD_IMAPDATA )
1947cdf0e10cSrcweir             return (ScIMapInfo*) pData;
1948cdf0e10cSrcweir     }
1949cdf0e10cSrcweir     return NULL;
1950cdf0e10cSrcweir }
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir // static:
GetHitIMapObject(SdrObject * pObj,const Point & rWinPoint,const Window & rCmpWnd)1953cdf0e10cSrcweir IMapObject* ScDrawLayer::GetHitIMapObject( SdrObject* pObj,
1954cdf0e10cSrcweir                                           const Point& rWinPoint, const Window& rCmpWnd )
1955cdf0e10cSrcweir {
1956cdf0e10cSrcweir     const MapMode       aMap100( MAP_100TH_MM );
1957cdf0e10cSrcweir     MapMode             aWndMode = rCmpWnd.GetMapMode();
1958cdf0e10cSrcweir     Point               aRelPoint( rCmpWnd.LogicToLogic( rWinPoint, &aWndMode, &aMap100 ) );
1959cdf0e10cSrcweir     Rectangle           aLogRect = rCmpWnd.LogicToLogic( pObj->GetLogicRect(), &aWndMode, &aMap100 );
1960cdf0e10cSrcweir     ScIMapInfo*         pIMapInfo = GetIMapInfo( pObj );
1961cdf0e10cSrcweir     IMapObject*         pIMapObj = NULL;
1962cdf0e10cSrcweir 
1963cdf0e10cSrcweir     if ( pIMapInfo )
1964cdf0e10cSrcweir     {
1965cdf0e10cSrcweir         Size        aGraphSize;
1966cdf0e10cSrcweir         ImageMap&   rImageMap = (ImageMap&) pIMapInfo->GetImageMap();
1967cdf0e10cSrcweir         Graphic     aGraphic;
1968cdf0e10cSrcweir         sal_Bool        bObjSupported = sal_False;
1969cdf0e10cSrcweir 
1970cdf0e10cSrcweir         if ( pObj->ISA( SdrGrafObj )  ) // einfaches Grafik-Objekt
1971cdf0e10cSrcweir         {
1972cdf0e10cSrcweir             const SdrGrafObj*   pGrafObj = (const SdrGrafObj*) pObj;
1973cdf0e10cSrcweir             const GeoStat&      rGeo = pGrafObj->GetGeoStat();
1974cdf0e10cSrcweir             const Graphic&      rGraphic = pGrafObj->GetGraphic();
1975cdf0e10cSrcweir 
1976cdf0e10cSrcweir             // Drehung rueckgaengig
1977cdf0e10cSrcweir             if ( rGeo.nDrehWink )
1978cdf0e10cSrcweir                 RotatePoint( aRelPoint, aLogRect.TopLeft(), -rGeo.nSin, rGeo.nCos );
1979cdf0e10cSrcweir 
1980cdf0e10cSrcweir             // Spiegelung rueckgaengig
1981cdf0e10cSrcweir             if ( ( (const SdrGrafObjGeoData*) pGrafObj->GetGeoData() )->bMirrored )
1982cdf0e10cSrcweir                 aRelPoint.X() = aLogRect.Right() + aLogRect.Left() - aRelPoint.X();
1983cdf0e10cSrcweir 
1984cdf0e10cSrcweir             // ggf. Unshear:
1985cdf0e10cSrcweir             if ( rGeo.nShearWink )
1986cdf0e10cSrcweir                 ShearPoint( aRelPoint, aLogRect.TopLeft(), -rGeo.nTan );
1987cdf0e10cSrcweir 
1988cdf0e10cSrcweir 
1989cdf0e10cSrcweir             if ( rGraphic.GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
1990cdf0e10cSrcweir                 aGraphSize = rCmpWnd.PixelToLogic( rGraphic.GetPrefSize(),
1991cdf0e10cSrcweir                                                          aMap100 );
1992cdf0e10cSrcweir             else
1993cdf0e10cSrcweir                 aGraphSize = OutputDevice::LogicToLogic( rGraphic.GetPrefSize(),
1994cdf0e10cSrcweir                                                          rGraphic.GetPrefMapMode(),
1995cdf0e10cSrcweir                                                          aMap100 );
1996cdf0e10cSrcweir 
1997cdf0e10cSrcweir             bObjSupported = sal_True;
1998cdf0e10cSrcweir         }
1999cdf0e10cSrcweir         else if ( pObj->ISA( SdrOle2Obj ) ) // OLE-Objekt
2000cdf0e10cSrcweir         {
2001cdf0e10cSrcweir             // TODO/LEAN: working with visual area needs running state
2002cdf0e10cSrcweir             aGraphSize = ((SdrOle2Obj*)pObj)->GetOrigObjSize();
2003cdf0e10cSrcweir             bObjSupported = sal_True;
2004cdf0e10cSrcweir         }
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir         // hat alles geklappt, dann HitTest ausfuehren
2007cdf0e10cSrcweir         if ( bObjSupported )
2008cdf0e10cSrcweir         {
2009cdf0e10cSrcweir             // relativen Mauspunkt berechnen
2010cdf0e10cSrcweir             aRelPoint -= aLogRect.TopLeft();
2011cdf0e10cSrcweir             pIMapObj = rImageMap.GetHitIMapObject( aGraphSize, aLogRect.GetSize(), aRelPoint );
2012cdf0e10cSrcweir         }
2013cdf0e10cSrcweir     }
2014cdf0e10cSrcweir 
2015cdf0e10cSrcweir     return pIMapObj;
2016cdf0e10cSrcweir }
2017cdf0e10cSrcweir 
GetMacroInfo(SdrObject * pObj,sal_Bool bCreate)2018cdf0e10cSrcweir ScMacroInfo* ScDrawLayer::GetMacroInfo( SdrObject* pObj, sal_Bool bCreate )             // static
2019cdf0e10cSrcweir {
2020cdf0e10cSrcweir     sal_uInt16 nCount = pObj->GetUserDataCount();
2021cdf0e10cSrcweir     for( sal_uInt16 i = 0; i < nCount; i++ )
2022cdf0e10cSrcweir     {
2023cdf0e10cSrcweir         SdrObjUserData* pData = pObj->GetUserData( i );
2024cdf0e10cSrcweir         if( pData && pData->GetInventor() == SC_DRAWLAYER
2025cdf0e10cSrcweir                     && pData->GetId() == SC_UD_MACRODATA )
2026cdf0e10cSrcweir             return (ScMacroInfo*) pData;
2027cdf0e10cSrcweir     }
2028cdf0e10cSrcweir     if ( bCreate )
2029cdf0e10cSrcweir     {
2030cdf0e10cSrcweir         ScMacroInfo* pData = new ScMacroInfo;
2031cdf0e10cSrcweir         pObj->InsertUserData( pData, 0 );
2032cdf0e10cSrcweir         return pData;
2033cdf0e10cSrcweir     }
2034cdf0e10cSrcweir     return 0;
2035cdf0e10cSrcweir }
GetImageMapForObject(SdrObject * pObj)20360deba7fbSSteve Yin ImageMap* ScDrawLayer::GetImageMapForObject(SdrObject* pObj)
20370deba7fbSSteve Yin {
20380deba7fbSSteve Yin     ScIMapInfo* pIMapInfo = const_cast<ScIMapInfo*>( GetIMapInfo( pObj ) );
20390deba7fbSSteve Yin     if ( pIMapInfo )
20400deba7fbSSteve Yin     {
20410deba7fbSSteve Yin         return const_cast<ImageMap*>( &(pIMapInfo->GetImageMap()) );
20420deba7fbSSteve Yin     }
20430deba7fbSSteve Yin     return NULL;
20440deba7fbSSteve Yin }
2045cdf0e10cSrcweir 
GetHyperlinkCount(SdrObject * pObj)20460deba7fbSSteve Yin sal_Int32 ScDrawLayer::GetHyperlinkCount(SdrObject* pObj)
20470deba7fbSSteve Yin {
20480deba7fbSSteve Yin     sal_Int32 nHLCount = 0;
20490deba7fbSSteve Yin     ScMacroInfo* pMacroInfo = GetMacroInfo(pObj, sal_False);
20500deba7fbSSteve Yin     if (pMacroInfo)
20510deba7fbSSteve Yin         // MT IA2: GetHlink*( doesn|t exist in DEV300 anymore...
20520deba7fbSSteve Yin         nHLCount = 0; // pMacroInfo->GetHlink().getLength() > 0 ? 1 : 0;
20530deba7fbSSteve Yin     return nHLCount;
20540deba7fbSSteve Yin }
SetGlobalDrawPersist(SfxObjectShell * pPersist)2055cdf0e10cSrcweir void ScDrawLayer::SetGlobalDrawPersist(SfxObjectShell* pPersist)            // static
2056cdf0e10cSrcweir {
2057cdf0e10cSrcweir     DBG_ASSERT(!pGlobalDrawPersist,"SetGlobalDrawPersist mehrfach");
2058cdf0e10cSrcweir     pGlobalDrawPersist = pPersist;
2059cdf0e10cSrcweir }
2060cdf0e10cSrcweir 
SetChanged(sal_Bool bFlg)2061cdf0e10cSrcweir void __EXPORT ScDrawLayer::SetChanged( sal_Bool bFlg /* = sal_True */ )
2062cdf0e10cSrcweir {
2063cdf0e10cSrcweir     if ( bFlg && pDoc )
2064cdf0e10cSrcweir         pDoc->SetChartListenerCollectionNeedsUpdate( sal_True );
2065cdf0e10cSrcweir     FmFormModel::SetChanged( bFlg );
2066cdf0e10cSrcweir }
2067cdf0e10cSrcweir 
GetDocumentStream(SdrDocumentStreamInfo & rStreamInfo) const2068cdf0e10cSrcweir SvStream* __EXPORT ScDrawLayer::GetDocumentStream(SdrDocumentStreamInfo& rStreamInfo) const
2069cdf0e10cSrcweir {
2070cdf0e10cSrcweir     DBG_ASSERT( pDoc, "ScDrawLayer::GetDocumentStream without document" );
2071cdf0e10cSrcweir     if ( !pDoc )
2072cdf0e10cSrcweir         return NULL;
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir     uno::Reference< embed::XStorage > xStorage = pDoc->GetDocumentShell() ?
2075cdf0e10cSrcweir                                                         pDoc->GetDocumentShell()->GetStorage() :
2076cdf0e10cSrcweir                                                         NULL;
2077cdf0e10cSrcweir     SvStream*   pRet = NULL;
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir     if( xStorage.is() )
2080cdf0e10cSrcweir     {
2081cdf0e10cSrcweir         if( rStreamInfo.maUserData.Len() &&
2082cdf0e10cSrcweir             ( rStreamInfo.maUserData.GetToken( 0, ':' ) ==
2083cdf0e10cSrcweir               String( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package" ) ) ) )
2084cdf0e10cSrcweir         {
2085cdf0e10cSrcweir             const String aPicturePath( rStreamInfo.maUserData.GetToken( 1, ':' ) );
2086cdf0e10cSrcweir 
2087cdf0e10cSrcweir             // graphic from picture stream in picture storage in XML package
2088cdf0e10cSrcweir             if( aPicturePath.GetTokenCount( '/' ) == 2 )
2089cdf0e10cSrcweir             {
2090cdf0e10cSrcweir                 const String aPictureStreamName( aPicturePath.GetToken( 1, '/' ) );
2091cdf0e10cSrcweir                 const String aPictureStorageName( aPicturePath.GetToken( 0, '/' ) );
2092cdf0e10cSrcweir 
2093cdf0e10cSrcweir                 try {
2094cdf0e10cSrcweir                     if ( xStorage->isStorageElement( aPictureStorageName ) )
2095cdf0e10cSrcweir                     {
2096cdf0e10cSrcweir                         uno::Reference< embed::XStorage > xPictureStorage =
2097cdf0e10cSrcweir                                     xStorage->openStorageElement( aPictureStorageName, embed::ElementModes::READ );
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir                         if( xPictureStorage.is() &&
2100cdf0e10cSrcweir                             xPictureStorage->isStreamElement( aPictureStreamName ) )
2101cdf0e10cSrcweir                         {
2102cdf0e10cSrcweir                             uno::Reference< io::XStream > xStream =
2103cdf0e10cSrcweir                                 xPictureStorage->openStreamElement( aPictureStreamName, embed::ElementModes::READ );
2104cdf0e10cSrcweir                             if ( xStream.is() )
2105cdf0e10cSrcweir                                 pRet = ::utl::UcbStreamHelper::CreateStream( xStream );
2106cdf0e10cSrcweir                         }
2107cdf0e10cSrcweir                     }
2108cdf0e10cSrcweir                 }
2109cdf0e10cSrcweir                 catch( uno::Exception& )
2110cdf0e10cSrcweir                 {
2111cdf0e10cSrcweir                     // TODO: error handling
2112cdf0e10cSrcweir                 }
2113cdf0e10cSrcweir             }
2114cdf0e10cSrcweir         }
2115cdf0e10cSrcweir         // the following code seems to be related to binary format
2116cdf0e10cSrcweir //REMOVE            else
2117cdf0e10cSrcweir //REMOVE            {
2118cdf0e10cSrcweir //REMOVE                pRet = pStor->OpenStream( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STRING_SCSTREAM)),
2119cdf0e10cSrcweir //REMOVE                                          STREAM_READ | STREAM_WRITE | STREAM_TRUNC );
2120cdf0e10cSrcweir //REMOVE
2121cdf0e10cSrcweir //REMOVE                if( pRet )
2122cdf0e10cSrcweir //REMOVE                {
2123cdf0e10cSrcweir //REMOVE                    pRet->SetVersion( pStor->GetVersion() );
2124cdf0e10cSrcweir //REMOVE                    pRet->SetKey( pStor->GetKey() );
2125cdf0e10cSrcweir //REMOVE                }
2126cdf0e10cSrcweir //REMOVE            }
2127cdf0e10cSrcweir 
2128cdf0e10cSrcweir         rStreamInfo.mbDeleteAfterUse = ( pRet != NULL );
2129cdf0e10cSrcweir     }
2130cdf0e10cSrcweir 
2131cdf0e10cSrcweir     return pRet;
2132cdf0e10cSrcweir }
2133cdf0e10cSrcweir 
2134cdf0e10cSrcweir //REMOVE    void ScDrawLayer::ReleasePictureStorage()
2135cdf0e10cSrcweir //REMOVE    {
2136cdf0e10cSrcweir //REMOVE        xPictureStorage.Clear();
2137cdf0e10cSrcweir //REMOVE    }
2138cdf0e10cSrcweir 
GetControlExportLayerId(const SdrObject &) const2139cdf0e10cSrcweir SdrLayerID __EXPORT ScDrawLayer::GetControlExportLayerId( const SdrObject & ) const
2140cdf0e10cSrcweir {
2141cdf0e10cSrcweir     //  Layer fuer Export von Form-Controls in Versionen vor 5.0 - immer SC_LAYER_FRONT
2142cdf0e10cSrcweir     return SC_LAYER_FRONT;
2143cdf0e10cSrcweir }
2144cdf0e10cSrcweir 
createUnoModel()2145cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ScDrawLayer::createUnoModel()
2146cdf0e10cSrcweir {
2147cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xRet;
2148cdf0e10cSrcweir     if( pDoc && pDoc->GetDocumentShell() )
2149cdf0e10cSrcweir         xRet = pDoc->GetDocumentShell()->GetModel();
2150cdf0e10cSrcweir 
2151cdf0e10cSrcweir     return xRet;
2152cdf0e10cSrcweir }
2153