LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdmodel.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 640 1087 58.9 %
Date: 2014-04-11 Functions: 84 117 71.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <svx/svdmodel.hxx>
      22             : 
      23             : #include <math.h>
      24             : 
      25             : #include <osl/endian.h>
      26             : #include <rtl/strbuf.hxx>
      27             : 
      28             : #include <com/sun/star/lang/XComponent.hpp>
      29             : #include <com/sun/star/document/XStorageBasedDocument.hpp>
      30             : #include <com/sun/star/embed/ElementModes.hpp>
      31             : 
      32             : #include <unotools/ucbstreamhelper.hxx>
      33             : 
      34             : #include <svl/whiter.hxx>
      35             : #include <svx/xit.hxx>
      36             : #include <svx/xbtmpit.hxx>
      37             : #include <svx/xlndsit.hxx>
      38             : #include <svx/xlnedit.hxx>
      39             : #include <svx/xflgrit.hxx>
      40             : #include <svx/xflftrit.hxx>
      41             : #include <svx/xflhtit.hxx>
      42             : #include <svx/xlnstit.hxx>
      43             : 
      44             : #include <editeng/editdata.hxx>
      45             : #include <editeng/editeng.hxx>
      46             : 
      47             : #include <svx/xtable.hxx>
      48             : 
      49             : #include "svx/svditer.hxx"
      50             : #include <svx/svdtrans.hxx>
      51             : #include <svx/svdpage.hxx>
      52             : #include <svx/svdlayer.hxx>
      53             : #include <svx/svdundo.hxx>
      54             : #include <svx/svdpool.hxx>
      55             : #include <svx/svdobj.hxx>
      56             : #include <svx/svdotext.hxx>
      57             : #include <svx/svdetc.hxx>
      58             : #include <svx/svdoutl.hxx>
      59             : #include <svx/svdoole2.hxx>
      60             : #include "svx/svdglob.hxx"
      61             : #include "svx/svdstr.hrc"
      62             : #include "svdoutlinercache.hxx"
      63             : 
      64             : #include "svx/xflclit.hxx"
      65             : #include "svx/xlnclit.hxx"
      66             : 
      67             : #include "officecfg/Office/Common.hxx"
      68             : #include "editeng/fontitem.hxx"
      69             : #include <editeng/colritem.hxx>
      70             : #include <editeng/fhgtitem.hxx>
      71             : #include <svl/style.hxx>
      72             : #include <editeng/numitem.hxx>
      73             : #include <editeng/bulletitem.hxx>
      74             : #include <editeng/outlobj.hxx>
      75             : #include "editeng/forbiddencharacterstable.hxx"
      76             : #include <svl/zforlist.hxx>
      77             : #include <comphelper/servicehelper.hxx>
      78             : #include <comphelper/storagehelper.hxx>
      79             : 
      80             : #include <tools/tenccvt.hxx>
      81             : #include <unotools/syslocale.hxx>
      82             : 
      83             : #include <svx/sdr/properties/properties.hxx>
      84             : #include <editeng/eeitem.hxx>
      85             : #include <svl/itemset.hxx>
      86             : #include <vcl/settings.hxx>
      87             : #include <vcl/svapp.hxx>
      88             : 
      89             : using namespace ::com::sun::star;
      90             : using namespace ::com::sun::star::uno;
      91             : using namespace ::com::sun::star::lang;
      92             : 
      93             : 
      94             : 
      95             : struct SdrModelImpl
      96             : {
      97             :     SfxUndoManager* mpUndoManager;
      98             :     SdrUndoFactory* mpUndoFactory;
      99             : };
     100             : 
     101             : 
     102             : 
     103         651 : TYPEINIT1(SdrModel,SfxBroadcaster);
     104        2481 : void SdrModel::ImpCtor(SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* _pEmbeddedHelper,
     105             :     bool bUseExtColorTable, bool bLoadRefCounts)
     106             : {
     107        2481 :     mpImpl = new SdrModelImpl;
     108        2481 :     mpImpl->mpUndoManager=0;
     109        2481 :     mpImpl->mpUndoFactory=0;
     110        2481 :     mbInDestruction = false;
     111        2481 :     aObjUnit=SdrEngineDefaults::GetMapFraction();
     112        2481 :     eObjUnit=SdrEngineDefaults::GetMapUnit();
     113        2481 :     eUIUnit=FUNIT_MM;
     114        2481 :     aUIScale=Fraction(1,1);
     115        2481 :     nUIUnitKomma=0;
     116        2481 :     bUIOnlyKomma=false;
     117        2481 :     pLayerAdmin=NULL;
     118        2481 :     pItemPool=pPool;
     119        2481 :     bMyPool=false;
     120        2481 :     m_pEmbeddedHelper=_pEmbeddedHelper;
     121        2481 :     pDrawOutliner=NULL;
     122        2481 :     pHitTestOutliner=NULL;
     123        2481 :     pRefOutDev=NULL;
     124        2481 :     nProgressAkt=0;
     125        2481 :     nProgressMax=0;
     126        2481 :     nProgressOfs=0;
     127        2481 :     pDefaultStyleSheet=NULL;
     128        2481 :     mpDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj = 0;
     129        2481 :     pLinkManager=NULL;
     130        2481 :     pUndoStack=NULL;
     131        2481 :     pRedoStack=NULL;
     132        2481 :     nMaxUndoCount=16;
     133        2481 :     pAktUndoGroup=NULL;
     134        2481 :     nUndoLevel=0;
     135        2481 :     mbUndoEnabled=true;
     136        2481 :     nProgressPercent=0;
     137        2481 :     nLoadVersion=0;
     138        2481 :     bExtColorTable=false;
     139        2481 :     mbChanged = false;
     140        2481 :     bInfoChanged=false;
     141        2481 :     bPagNumsDirty=false;
     142        2481 :     bMPgNumsDirty=false;
     143        2481 :     bPageNotValid=false;
     144        2481 :     bSavePortable=false;
     145        2481 :     bSaveCompressed=false;
     146        2481 :     bSaveNative=false;
     147        2481 :     bSwapGraphics=false;
     148        2481 :     nSwapGraphicsMode=SDR_SWAPGRAPHICSMODE_DEFAULT;
     149        2481 :     bSaveOLEPreview=false;
     150        2481 :     bPasteResize=false;
     151        2481 :     bNoBitmapCaching=false;
     152        2481 :     bReadOnly=false;
     153        2481 :     nStreamCompressMode=COMPRESSMODE_NONE;
     154        2481 :     nStreamNumberFormat=NUMBERFORMAT_INT_BIGENDIAN;
     155        2481 :     nDefaultTabulator=0;
     156        2481 :     mpNumberFormatter = NULL;
     157        2481 :     bTransparentTextFrames=false;
     158        2481 :     bStarDrawPreviewMode = false;
     159        2481 :     nStarDrawPreviewMasterPageNum = SDRPAGE_NOTFOUND;
     160        2481 :     mpForbiddenCharactersTable = NULL;
     161        2481 :     mbModelLocked = false;
     162        2481 :     mpOutlinerCache = NULL;
     163        2481 :     mbKernAsianPunctuation = false;
     164        2481 :     mbAddExtLeading = false;
     165        2481 :     mnHandoutPageCount = 0;
     166             : 
     167        2481 :     mbDisableTextEditUsesCommonUndoManager = false;
     168             : 
     169             :     mnCharCompressType =
     170             :         officecfg::Office::Common::AsianLayout::CompressCharacterDistance::
     171        2481 :         get();
     172             : 
     173             : #ifdef OSL_LITENDIAN
     174        2481 :     nStreamNumberFormat=NUMBERFORMAT_INT_LITTLEENDIAN;
     175             : #endif
     176        2481 :     bExtColorTable=bUseExtColorTable;
     177             : 
     178        2481 :     if ( pPool == NULL )
     179             :     {
     180         707 :         pItemPool=new SdrItemPool(0L, bLoadRefCounts);
     181             :         // Outliner doesn't have its own Pool, so use the EditEngine's
     182         707 :         SfxItemPool* pOutlPool=EditEngine::CreatePool( bLoadRefCounts );
     183             :         // OutlinerPool as SecondaryPool of SdrPool
     184         707 :         pItemPool->SetSecondaryPool(pOutlPool);
     185             :         // remember that I created both pools myself
     186         707 :         bMyPool=true;
     187             :     }
     188        2481 :     pItemPool->SetDefaultMetric((SfxMapUnit)eObjUnit);
     189             : 
     190             : // using static SdrEngineDefaults only if default SvxFontHeight item is not available
     191        2481 :     const SfxPoolItem* pPoolItem = pItemPool->GetPoolDefaultItem( EE_CHAR_FONTHEIGHT );
     192        2481 :     if ( pPoolItem )
     193        1774 :         nDefTextHgt = ((SvxFontHeightItem*)pPoolItem)->GetHeight();
     194             :     else
     195         707 :         nDefTextHgt = SdrEngineDefaults::GetFontHeight();
     196             : 
     197        2481 :     pItemPool->SetPoolDefaultItem( SdrTextWordWrapItem( false ) );
     198             : 
     199        2481 :     SetTextDefaults();
     200        2481 :     pLayerAdmin=new SdrLayerAdmin;
     201        2481 :     pLayerAdmin->SetModel(this);
     202        2481 :     ImpSetUIUnit();
     203             : 
     204             :     // can't create DrawOutliner OnDemand, because I can't get the Pool,
     205             :     // then (only from 302 onwards!)
     206        2481 :     pDrawOutliner = SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT, this );
     207        2481 :     ImpSetOutlinerDefaults(pDrawOutliner, true);
     208             : 
     209        2481 :     pHitTestOutliner = SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT, this );
     210        2481 :     ImpSetOutlinerDefaults(pHitTestOutliner, true);
     211             : 
     212        2481 :     ImpCreateTables();
     213        2481 : }
     214             : 
     215           0 : SdrModel::SdrModel():
     216             :     aReadDate( DateTime::EMPTY ),
     217             :     maMaPag(),
     218           0 :     maPages()
     219             : {
     220           0 :     ImpCtor(NULL, NULL, false, LOADREFCOUNTS);
     221           0 : }
     222             : 
     223           0 : SdrModel::SdrModel(SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* pPers, bool bUseExtColorTable, bool bLoadRefCounts):
     224             :     aReadDate( DateTime::EMPTY ),
     225             :     maMaPag(),
     226           0 :     maPages()
     227             : {
     228           0 :     ImpCtor(pPool,pPers,bUseExtColorTable, bLoadRefCounts);
     229           0 : }
     230             : 
     231        2481 : SdrModel::SdrModel(const OUString& rPath, SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* pPers, bool bUseExtColorTable, bool bLoadRefCounts):
     232             :     aReadDate( DateTime::EMPTY ),
     233             :     maMaPag(),
     234             :     maPages(),
     235        2481 :     aTablePath(rPath)
     236             : {
     237        2481 :     ImpCtor(pPool,pPers,bUseExtColorTable, bLoadRefCounts);
     238        2481 : }
     239             : 
     240           0 : SdrModel::SdrModel(const SdrModel& /*rSrcModel*/):
     241             :     SfxBroadcaster(),
     242             :     tools::WeakBase< SdrModel >(),
     243             :     aReadDate( DateTime::EMPTY ),
     244             :     maMaPag(),
     245           0 :     maPages()
     246             : {
     247             :     // not yet implemented
     248             :     OSL_FAIL("SdrModel::CopyCtor() is not yet implemented.");
     249           0 : }
     250             : 
     251        4630 : SdrModel::~SdrModel()
     252             : {
     253             : 
     254        2315 :     mbInDestruction = true;
     255             : 
     256        2315 :     Broadcast(SdrHint(HINT_MODELCLEARED));
     257             : 
     258        2315 :     delete mpOutlinerCache;
     259             : 
     260        2315 :     ClearUndoBuffer();
     261             : #ifdef DBG_UTIL
     262             :     if(pAktUndoGroup)
     263             :     {
     264             :         OStringBuffer aStr("In the Dtor of the SdrModel there is an open Undo left: \"");
     265             :         aStr.append(OUStringToOString(pAktUndoGroup->GetComment(), osl_getThreadTextEncoding()))
     266             :             .append('\"');
     267             :         OSL_FAIL(aStr.getStr());
     268             :     }
     269             : #endif
     270        2315 :     delete pAktUndoGroup;
     271             : 
     272        2315 :     ClearModel(true);
     273             : 
     274        2315 :     delete pLayerAdmin;
     275             : 
     276             :     // Delete DrawOutliner only after deleting ItemPool, because ItemPool
     277             :     // references Items of the DrawOutliner!
     278        2315 :     delete pHitTestOutliner;
     279        2315 :     delete pDrawOutliner;
     280             : 
     281             :     // delete StyleSheetPool, derived classes should not do this since
     282             :     // the DrawingEngine may need it in its destructor
     283        2315 :     if( mxStyleSheetPool.is() )
     284             :     {
     285         111 :         Reference< XComponent > xComponent( dynamic_cast< cppu::OWeakObject* >( mxStyleSheetPool.get() ), UNO_QUERY );
     286         111 :         if( xComponent.is() ) try
     287             :         {
     288         111 :             xComponent->dispose();
     289             :         }
     290           0 :         catch( RuntimeException& )
     291             :         {
     292             :         }
     293         111 :         mxStyleSheetPool.clear();
     294             :     }
     295             : 
     296        2315 :     if (bMyPool)
     297             :     {
     298             :         // delete Pools if they're mine
     299         543 :         SfxItemPool* pOutlPool=pItemPool->GetSecondaryPool();
     300         543 :         SfxItemPool::Free(pItemPool);
     301             :         // OutlinerPool has to be deleted after deleting ItemPool, because
     302             :         // ItemPool contains SetItems that themselves reference Items from OutlinerPool.
     303         543 :         SfxItemPool::Free(pOutlPool);
     304             :     }
     305             : 
     306        2315 :     if( mpForbiddenCharactersTable )
     307        1905 :         mpForbiddenCharactersTable->release();
     308             : 
     309        2315 :     delete mpNumberFormatter;
     310             : 
     311        2315 :     delete mpImpl->mpUndoFactory;
     312        2315 :     delete mpImpl;
     313        2315 : }
     314             : 
     315         151 : bool SdrModel::IsInDestruction() const
     316             : {
     317         151 :     return mbInDestruction;
     318             : }
     319             : 
     320             : // not yet implemented
     321           0 : void SdrModel::operator=(const SdrModel&)
     322             : {
     323             :     OSL_FAIL("SdrModel::operator=() is not yet implemented.");
     324           0 : }
     325             : 
     326           0 : bool SdrModel::operator==(const SdrModel&) const
     327             : {
     328             :     OSL_FAIL("SdrModel::operator==() is not yet implemented");
     329           0 :     return false;
     330             : }
     331             : 
     332        2261 : void SdrModel::SetSwapGraphics( bool bSwap )
     333             : {
     334        2261 :     bSwapGraphics = bSwap;
     335        2261 : }
     336             : 
     337           0 : bool SdrModel::IsReadOnly() const
     338             : {
     339           0 :     return bReadOnly;
     340             : }
     341             : 
     342           0 : void SdrModel::SetReadOnly(bool bYes)
     343             : {
     344           0 :     bReadOnly=bYes;
     345           0 : }
     346             : 
     347             : 
     348             : 
     349        2205 : void SdrModel::SetMaxUndoActionCount(sal_uIntPtr nAnz)
     350             : {
     351        2205 :     if (nAnz<1) nAnz=1;
     352        2205 :     nMaxUndoCount=nAnz;
     353        2205 :     if (pUndoStack!=NULL) {
     354           0 :         while (pUndoStack->size()>nMaxUndoCount) {
     355           0 :             delete pUndoStack->back();
     356           0 :             pUndoStack->pop_back();
     357             :         }
     358             :     }
     359        2205 : }
     360             : 
     361        4520 : void SdrModel::ClearUndoBuffer()
     362             : {
     363        4520 :     if (pUndoStack!=NULL) {
     364           0 :         while (!pUndoStack->empty()) {
     365           0 :             delete pUndoStack->back();
     366           0 :             pUndoStack->pop_back();
     367             :         }
     368           0 :         delete pUndoStack;
     369           0 :         pUndoStack=NULL;
     370             :     }
     371        4520 :     if (pRedoStack!=NULL) {
     372           0 :         while (!pRedoStack->empty()) {
     373           0 :             delete pRedoStack->back();
     374           0 :             pRedoStack->pop_back();
     375             :         }
     376           0 :         delete pRedoStack;
     377           0 :         pRedoStack=NULL;
     378             :     }
     379        4520 : }
     380             : 
     381           0 : bool SdrModel::HasUndoActions() const
     382             : {
     383           0 :     return pUndoStack && !pUndoStack->empty();
     384             : }
     385             : 
     386           0 : bool SdrModel::HasRedoActions() const
     387             : {
     388           0 :     return pRedoStack && !pRedoStack->empty();
     389             : }
     390             : 
     391           0 : bool SdrModel::Undo()
     392             : {
     393           0 :     bool bRet = false;
     394           0 :     if( mpImpl->mpUndoManager )
     395             :     {
     396             :         OSL_FAIL("svx::SdrModel::Undo(), method not supported with application undo manager!");
     397             :     }
     398             :     else
     399             :     {
     400           0 :         SfxUndoAction* pDo = HasUndoActions() ? pUndoStack->front() : NULL;
     401           0 :         if(pDo!=NULL)
     402             :         {
     403           0 :             const bool bWasUndoEnabled = mbUndoEnabled;
     404           0 :             mbUndoEnabled = false;
     405           0 :             pDo->Undo();
     406           0 :             if(pRedoStack==NULL)
     407           0 :                 pRedoStack=new std::deque<SfxUndoAction*>;
     408           0 :             SfxUndoAction* p = pUndoStack->front();
     409           0 :             pUndoStack->pop_front();
     410           0 :             pRedoStack->push_front(p);
     411           0 :             mbUndoEnabled = bWasUndoEnabled;
     412             :         }
     413             :     }
     414           0 :     return bRet;
     415             : }
     416             : 
     417           0 : bool SdrModel::Redo()
     418             : {
     419           0 :     bool bRet = false;
     420           0 :     if( mpImpl->mpUndoManager )
     421             :     {
     422             :         OSL_FAIL("svx::SdrModel::Redo(), method not supported with application undo manager!");
     423             :     }
     424             :     else
     425             :     {
     426           0 :         SfxUndoAction* pDo = HasRedoActions() ? pRedoStack->front() : NULL;
     427           0 :         if(pDo!=NULL)
     428             :         {
     429           0 :             const bool bWasUndoEnabled = mbUndoEnabled;
     430           0 :             mbUndoEnabled = false;
     431           0 :             pDo->Redo();
     432           0 :             if(pUndoStack==NULL)
     433           0 :                 pUndoStack=new std::deque<SfxUndoAction*>;
     434           0 :             SfxUndoAction* p = pRedoStack->front();
     435           0 :             pRedoStack->pop_front();
     436           0 :             pUndoStack->push_front(p);
     437           0 :             mbUndoEnabled = bWasUndoEnabled;
     438             :         }
     439             :     }
     440           0 :     return bRet;
     441             : }
     442             : 
     443           0 : bool SdrModel::Repeat(SfxRepeatTarget& rView)
     444             : {
     445           0 :     bool bRet = false;
     446           0 :     if( mpImpl->mpUndoManager )
     447             :     {
     448             :         OSL_FAIL("svx::SdrModel::Redo(), method not supported with application undo manager!");
     449             :     }
     450             :     else
     451             :     {
     452           0 :         SfxUndoAction* pDo = HasUndoActions() ? pUndoStack->front() : NULL;
     453           0 :         if(pDo!=NULL)
     454             :         {
     455           0 :             if(pDo->CanRepeat(rView))
     456             :             {
     457           0 :                 pDo->Repeat(rView);
     458           0 :                 bRet = true;
     459             :             }
     460             :         }
     461             :     }
     462           0 :     return bRet;
     463             : }
     464             : 
     465        5964 : void SdrModel::ImpPostUndoAction(SdrUndoAction* pUndo)
     466             : {
     467             :     DBG_ASSERT( mpImpl->mpUndoManager == 0, "svx::SdrModel::ImpPostUndoAction(), method not supported with application undo manager!" );
     468        5964 :     if( IsUndoEnabled() )
     469             :     {
     470        5964 :         if (aUndoLink.IsSet())
     471             :         {
     472        5964 :             aUndoLink.Call(pUndo);
     473             :         }
     474             :         else
     475             :         {
     476           0 :             if (pUndoStack==NULL)
     477           0 :                 pUndoStack=new std::deque<SfxUndoAction*>;
     478           0 :             pUndoStack->push_front(pUndo);
     479           0 :             while (pUndoStack->size()>nMaxUndoCount)
     480             :             {
     481           0 :                 delete pUndoStack->back();
     482           0 :                 pUndoStack->pop_back();
     483             :             }
     484           0 :             if (pRedoStack!=NULL)
     485           0 :                 pRedoStack->clear();
     486             :         }
     487             :     }
     488             :     else
     489             :     {
     490           0 :         delete pUndo;
     491             :     }
     492        5964 : }
     493             : 
     494         131 : void SdrModel::BegUndo()
     495             : {
     496         131 :     if( mpImpl->mpUndoManager )
     497             :     {
     498           6 :         const OUString aEmpty;
     499           6 :         mpImpl->mpUndoManager->EnterListAction(aEmpty,aEmpty);
     500           6 :         nUndoLevel++;
     501             :     }
     502         125 :     else if( IsUndoEnabled() )
     503             :     {
     504         125 :         if(pAktUndoGroup==NULL)
     505             :         {
     506         125 :             pAktUndoGroup = new SdrUndoGroup(*this);
     507         125 :             nUndoLevel=1;
     508             :         }
     509             :         else
     510             :         {
     511           0 :             nUndoLevel++;
     512             :         }
     513             :     }
     514         131 : }
     515             : 
     516         551 : void SdrModel::BegUndo(const OUString& rComment)
     517             : {
     518         551 :     if( mpImpl->mpUndoManager )
     519             :     {
     520         430 :         const OUString aEmpty;
     521         430 :         mpImpl->mpUndoManager->EnterListAction( rComment, aEmpty );
     522         430 :         nUndoLevel++;
     523             :     }
     524         121 :     else if( IsUndoEnabled() )
     525             :     {
     526         121 :         BegUndo();
     527         121 :         if (nUndoLevel==1)
     528             :         {
     529         121 :             pAktUndoGroup->SetComment(rComment);
     530             :         }
     531             :     }
     532         551 : }
     533             : 
     534          28 : void SdrModel::BegUndo(const OUString& rComment, const OUString& rObjDescr, SdrRepeatFunc eFunc)
     535             : {
     536          28 :     if( mpImpl->mpUndoManager )
     537             :     {
     538          24 :         OUString aComment(rComment);
     539          24 :         if( !aComment.isEmpty() && !rObjDescr.isEmpty() )
     540             :         {
     541           9 :             aComment = aComment.replaceFirst("%1", rObjDescr);
     542             :         }
     543          48 :         const OUString aEmpty;
     544          24 :         mpImpl->mpUndoManager->EnterListAction( aComment,aEmpty );
     545          48 :         nUndoLevel++;
     546             :     }
     547           4 :     else if( IsUndoEnabled() )
     548             :     {
     549           4 :         BegUndo();
     550           4 :         if (nUndoLevel==1)
     551             :         {
     552           4 :             pAktUndoGroup->SetComment(rComment);
     553           4 :             pAktUndoGroup->SetObjDescription(rObjDescr);
     554           4 :             pAktUndoGroup->SetRepeatFunction(eFunc);
     555             :         }
     556             :     }
     557          28 : }
     558             : 
     559         585 : void SdrModel::EndUndo()
     560             : {
     561             :     DBG_ASSERT(nUndoLevel!=0,"SdrModel::EndUndo(): UndoLevel is already 0!");
     562         585 :     if( mpImpl->mpUndoManager )
     563             :     {
     564         460 :         if( nUndoLevel )
     565             :         {
     566         460 :             nUndoLevel--;
     567         460 :             mpImpl->mpUndoManager->LeaveListAction();
     568             :         }
     569             :     }
     570             :     else
     571             :     {
     572         125 :         if(pAktUndoGroup!=NULL && IsUndoEnabled())
     573             :         {
     574         125 :             nUndoLevel--;
     575         125 :             if(nUndoLevel==0)
     576             :             {
     577         125 :                 if(pAktUndoGroup->GetActionCount()!=0)
     578             :                 {
     579         125 :                     SdrUndoAction* pUndo=pAktUndoGroup;
     580         125 :                     pAktUndoGroup=NULL;
     581         125 :                     ImpPostUndoAction(pUndo);
     582             :                 }
     583             :                 else
     584             :                 {
     585             :                     // was empty
     586           0 :                     delete pAktUndoGroup;
     587           0 :                     pAktUndoGroup=NULL;
     588             :                 }
     589             :             }
     590             :         }
     591             :     }
     592         585 : }
     593             : 
     594           0 : void SdrModel::SetUndoComment(const OUString& rComment)
     595             : {
     596             :     DBG_ASSERT(nUndoLevel!=0,"SdrModel::SetUndoComment(): UndoLevel is already 0!");
     597             : 
     598           0 :     if( mpImpl->mpUndoManager )
     599             :     {
     600             :         OSL_FAIL("svx::SdrModel::SetUndoComment(), method not supported with application undo manager!" );
     601             :     }
     602           0 :     else if( IsUndoEnabled() )
     603             :     {
     604           0 :         if(nUndoLevel==1)
     605             :         {
     606           0 :             pAktUndoGroup->SetComment(rComment);
     607             :         }
     608             :     }
     609           0 : }
     610             : 
     611          17 : void SdrModel::SetUndoComment(const OUString& rComment, const OUString& rObjDescr)
     612             : {
     613             :     DBG_ASSERT(nUndoLevel!=0,"SdrModel::SetUndoComment(): UndoLevel is already 0!");
     614          17 :     if( mpImpl->mpUndoManager )
     615             :     {
     616             :         OSL_FAIL("svx::SdrModel::SetUndoComment(), method not supported with application undo manager!" );
     617             :     }
     618             :     else
     619             :     {
     620           2 :         if (nUndoLevel==1)
     621             :         {
     622           2 :             pAktUndoGroup->SetComment(rComment);
     623           2 :             pAktUndoGroup->SetObjDescription(rObjDescr);
     624             :         }
     625             :     }
     626          17 : }
     627             : 
     628        6666 : void SdrModel::AddUndo(SdrUndoAction* pUndo)
     629             : {
     630        6666 :     if( mpImpl->mpUndoManager )
     631             :     {
     632         682 :         mpImpl->mpUndoManager->AddUndoAction( pUndo );
     633             :     }
     634        5984 :     else if( !IsUndoEnabled() )
     635             :     {
     636           0 :         delete pUndo;
     637             :     }
     638             :     else
     639             :     {
     640        5984 :         if (pAktUndoGroup!=NULL)
     641             :         {
     642         145 :             pAktUndoGroup->AddAction(pUndo);
     643             :         }
     644             :         else
     645             :         {
     646        5839 :             ImpPostUndoAction(pUndo);
     647             :         }
     648             :     }
     649        6666 : }
     650             : 
     651       62036 : void SdrModel::EnableUndo( bool bEnable )
     652             : {
     653       62036 :     if( mpImpl->mpUndoManager )
     654             :     {
     655          46 :         mpImpl->mpUndoManager->EnableUndo( bEnable );
     656             :     }
     657             :     else
     658             :     {
     659       61990 :         mbUndoEnabled = bEnable;
     660             :     }
     661       62036 : }
     662             : 
     663       47835 : bool SdrModel::IsUndoEnabled() const
     664             : {
     665       47835 :     if( mpImpl->mpUndoManager )
     666             :     {
     667         682 :         return mpImpl->mpUndoManager->IsUndoEnabled();
     668             :     }
     669             :     else
     670             :     {
     671       47153 :         return mbUndoEnabled;
     672             :     }
     673             : }
     674             : 
     675        2481 : void SdrModel::ImpCreateTables()
     676             : {
     677       17367 :     for( int i = 0; i < XPROPERTY_LIST_COUNT; i++ )
     678             :     {
     679       14886 :         if( !bExtColorTable || i != XCOLOR_LIST )
     680       25558 :             maProperties[i] = XPropertyList::CreatePropertyList (
     681       12779 :                 (XPropertyListType) i, aTablePath, ""/*TODO?*/ );
     682             :     }
     683        2481 : }
     684             : 
     685        4842 : void SdrModel::ClearModel(bool bCalledFromDestructor)
     686             : {
     687        4842 :     if(bCalledFromDestructor)
     688             :     {
     689        4842 :         mbInDestruction = true;
     690             :     }
     691             : 
     692             :     sal_Int32 i;
     693             :     // delete all drawing pages
     694        4842 :     sal_Int32 nAnz=GetPageCount();
     695        7703 :     for (i=nAnz-1; i>=0; i--)
     696             :     {
     697        2861 :         DeletePage( (sal_uInt16)i );
     698             :     }
     699        4842 :     maPages.clear();
     700        4842 :     PageListChanged();
     701             : 
     702             :     // delete all Masterpages
     703        4842 :     nAnz=GetMasterPageCount();
     704        5176 :     for(i=nAnz-1; i>=0; i--)
     705             :     {
     706         334 :         DeleteMasterPage( (sal_uInt16)i );
     707             :     }
     708        4842 :     maMaPag.clear();
     709        4842 :     MasterPageListChanged();
     710             : 
     711        4842 :     pLayerAdmin->ClearLayer();
     712        4842 : }
     713             : 
     714           0 : SdrModel* SdrModel::AllocModel() const
     715             : {
     716           0 :     SdrModel* pModel=new SdrModel;
     717           0 :     pModel->SetScaleUnit(eObjUnit,aObjUnit);
     718           0 :     return pModel;
     719             : }
     720             : 
     721           0 : SdrPage* SdrModel::AllocPage(bool bMasterPage)
     722             : {
     723           0 :     return new SdrPage(*this,bMasterPage);
     724             : }
     725             : 
     726        2481 : void SdrModel::SetTextDefaults() const
     727             : {
     728        2481 :     SetTextDefaults( pItemPool, nDefTextHgt );
     729        2481 : }
     730             : 
     731        2673 : void SdrModel::SetTextDefaults( SfxItemPool* pItemPool, sal_uIntPtr nDefTextHgt )
     732             : {
     733             :     // set application-language specific dynamic pool language defaults
     734        2673 :     SvxFontItem aSvxFontItem( EE_CHAR_FONTINFO) ;
     735        5346 :     SvxFontItem aSvxFontItemCJK(EE_CHAR_FONTINFO_CJK);
     736        5346 :     SvxFontItem aSvxFontItemCTL(EE_CHAR_FONTINFO_CTL);
     737        2673 :     sal_uInt16 nLanguage(Application::GetSettings().GetLanguageTag().getLanguageType());
     738             : 
     739             :     // get DEFAULTFONT_LATIN_TEXT and set at pool as dynamic default
     740        5346 :     Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_LATIN_TEXT, nLanguage, DEFAULTFONT_FLAGS_ONLYONE, 0));
     741        2673 :     aSvxFontItem.SetFamily(aFont.GetFamily());
     742        2673 :     aSvxFontItem.SetFamilyName(aFont.GetName());
     743        2673 :     aSvxFontItem.SetStyleName(OUString());
     744        2673 :     aSvxFontItem.SetPitch( aFont.GetPitch());
     745        2673 :     aSvxFontItem.SetCharSet( aFont.GetCharSet() );
     746        2673 :     pItemPool->SetPoolDefaultItem(aSvxFontItem);
     747             : 
     748             :     // get DEFAULTFONT_CJK_TEXT and set at pool as dynamic default
     749        5346 :     Font aFontCJK(OutputDevice::GetDefaultFont(DEFAULTFONT_CJK_TEXT, nLanguage, DEFAULTFONT_FLAGS_ONLYONE, 0));
     750        2673 :     aSvxFontItemCJK.SetFamily( aFontCJK.GetFamily());
     751        2673 :     aSvxFontItemCJK.SetFamilyName(aFontCJK.GetName());
     752        2673 :     aSvxFontItemCJK.SetStyleName(OUString());
     753        2673 :     aSvxFontItemCJK.SetPitch( aFontCJK.GetPitch());
     754        2673 :     aSvxFontItemCJK.SetCharSet( aFontCJK.GetCharSet());
     755        2673 :     pItemPool->SetPoolDefaultItem(aSvxFontItemCJK);
     756             : 
     757             :     // get DEFAULTFONT_CTL_TEXT and set at pool as dynamic default
     758        5346 :     Font aFontCTL(OutputDevice::GetDefaultFont(DEFAULTFONT_CTL_TEXT, nLanguage, DEFAULTFONT_FLAGS_ONLYONE, 0));
     759        2673 :     aSvxFontItemCTL.SetFamily(aFontCTL.GetFamily());
     760        2673 :     aSvxFontItemCTL.SetFamilyName(aFontCTL.GetName());
     761        2673 :     aSvxFontItemCTL.SetStyleName(OUString());
     762        2673 :     aSvxFontItemCTL.SetPitch( aFontCTL.GetPitch() );
     763        2673 :     aSvxFontItemCTL.SetCharSet( aFontCTL.GetCharSet());
     764        2673 :     pItemPool->SetPoolDefaultItem(aSvxFontItemCTL);
     765             : 
     766             :     // set dynamic FontHeight defaults
     767        2673 :     pItemPool->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt, 100, EE_CHAR_FONTHEIGHT ) );
     768        2673 :     pItemPool->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt, 100, EE_CHAR_FONTHEIGHT_CJK ) );
     769        2673 :     pItemPool->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt, 100, EE_CHAR_FONTHEIGHT_CTL ) );
     770             : 
     771             :     // set FontColor defaults
     772        5346 :     pItemPool->SetPoolDefaultItem( SvxColorItem(SdrEngineDefaults::GetFontColor(), EE_CHAR_COLOR) );
     773        2673 : }
     774             : 
     775      429229 : SdrOutliner& SdrModel::GetDrawOutliner(const SdrTextObj* pObj) const
     776             : {
     777      429229 :     pDrawOutliner->SetTextObj(pObj);
     778      429229 :     return *pDrawOutliner;
     779             : }
     780             : 
     781         536 : const SdrTextObj* SdrModel::GetFormattingTextObj() const
     782             : {
     783         536 :     if (pDrawOutliner!=NULL) {
     784         536 :         return pDrawOutliner->GetTextObj();
     785             :     }
     786           0 :     return NULL;
     787             : }
     788             : 
     789       21662 : void SdrModel::ImpSetOutlinerDefaults( SdrOutliner* pOutliner, bool bInit )
     790             : {
     791             :     /**************************************************************************
     792             :     * Initialization of the Outliners for drawing text and HitTest
     793             :     **************************************************************************/
     794       21662 :     if( bInit )
     795             :     {
     796        4962 :         pOutliner->EraseVirtualDevice();
     797        4962 :         pOutliner->SetUpdateMode(false);
     798        4962 :         pOutliner->SetEditTextObjectPool(pItemPool);
     799        4962 :         pOutliner->SetDefTab(nDefaultTabulator);
     800             :     }
     801             : 
     802       21662 :     pOutliner->SetRefDevice(GetRefDevice());
     803       21662 :     pOutliner->SetForbiddenCharsTable(GetForbiddenCharsTable());
     804       21662 :     pOutliner->SetAsianCompressionMode( mnCharCompressType );
     805       21662 :     pOutliner->SetKernAsianPunctuation( IsKernAsianPunctuation() );
     806       21662 :     pOutliner->SetAddExtLeading( IsAddExtLeading() );
     807             : 
     808       21662 :     if ( !GetRefDevice() )
     809             :     {
     810       15924 :         MapMode aMapMode(eObjUnit, Point(0,0), aObjUnit, aObjUnit);
     811       15924 :         pOutliner->SetRefMapMode(aMapMode);
     812             :     }
     813       21662 : }
     814             : 
     815        2513 : void SdrModel::SetRefDevice(OutputDevice* pDev)
     816             : {
     817        2513 :     pRefOutDev=pDev;
     818        2513 :     ImpSetOutlinerDefaults( pDrawOutliner );
     819        2513 :     ImpSetOutlinerDefaults( pHitTestOutliner );
     820        2513 :     RefDeviceChanged();
     821        2513 : }
     822             : 
     823        5166 : void SdrModel::ImpReformatAllTextObjects()
     824             : {
     825        5166 :     if( isLocked() )
     826        5208 :         return;
     827             : 
     828        5124 :     sal_uInt16 nAnz=GetMasterPageCount();
     829             :     sal_uInt16 nNum;
     830        5124 :     for (nNum=0; nNum<nAnz; nNum++) {
     831           0 :         GetMasterPage(nNum)->ReformatAllTextObjects();
     832             :     }
     833        5124 :     nAnz=GetPageCount();
     834        7704 :     for (nNum=0; nNum<nAnz; nNum++) {
     835        2580 :         GetPage(nNum)->ReformatAllTextObjects();
     836             :     }
     837             : }
     838             : 
     839             : /*  steps over all available pages and sends notify messages to
     840             :     all edge objects that are connected to other objects so that
     841             :     they may reposition themselves
     842             : */
     843         875 : void SdrModel::ImpReformatAllEdgeObjects()
     844             : {
     845         875 :     if( isLocked() )
     846         875 :         return;
     847             : 
     848         875 :     sal_uInt16 nAnz=GetMasterPageCount();
     849             :     sal_uInt16 nNum;
     850        1125 :     for (nNum=0; nNum<nAnz; nNum++)
     851             :     {
     852         250 :         GetMasterPage(nNum)->ReformatAllEdgeObjects();
     853             :     }
     854         875 :     nAnz=GetPageCount();
     855        2035 :     for (nNum=0; nNum<nAnz; nNum++)
     856             :     {
     857        1160 :         GetPage(nNum)->ReformatAllEdgeObjects();
     858             :     }
     859             : }
     860             : 
     861           3 : uno::Reference<embed::XStorage> SdrModel::GetDocumentStorage() const
     862             : {
     863             :     uno::Reference<document::XStorageBasedDocument> const xSBD(
     864           3 :             const_cast<SdrModel*>(this)->getUnoModel(), uno::UNO_QUERY);
     865           3 :     if (!xSBD.is())
     866             :     {
     867             :         SAL_WARN("svx", "no UNO model");
     868           0 :         return 0;
     869             :     }
     870           3 :     return xSBD->getDocumentStorage();
     871             : }
     872             : 
     873             : uno::Reference<io::XInputStream>
     874           3 : SdrModel::GetDocumentStream( OUString const& rURL,
     875             :                 ::comphelper::LifecycleProxy & rProxy) const
     876             : {
     877           3 :     uno::Reference<embed::XStorage> const xStorage(GetDocumentStorage());
     878           3 :     if (!xStorage.is())
     879             :     {
     880             :         SAL_WARN("svx", "no storage?");
     881           0 :         return 0;
     882             :     }
     883             :     try {
     884             :         uno::Reference<io::XStream> const xStream(
     885             :             ::comphelper::OStorageHelper::GetStreamAtPackageURL(
     886           3 :                 xStorage, rURL, embed::ElementModes::READ, rProxy));
     887           2 :         return (xStream.is()) ? xStream->getInputStream() : 0;
     888             :     }
     889           0 :     catch (container::NoSuchElementException const&)
     890             :     {
     891             :         SAL_INFO("svx", "not found");
     892             :     }
     893           1 :     catch (uno::Exception const& e)
     894             :     {
     895             :         SAL_WARN("svx", "exception: '" << e.Message << "'");
     896             :     }
     897           1 :     return 0;
     898             : }
     899             : 
     900             : // convert template attributes from the string into "hard" attributes
     901           0 : void SdrModel::BurnInStyleSheetAttributes()
     902             : {
     903           0 :     sal_uInt16 nAnz=GetMasterPageCount();
     904             :     sal_uInt16 nNum;
     905           0 :     for (nNum=0; nNum<nAnz; nNum++) {
     906           0 :         GetMasterPage(nNum)->BurnInStyleSheetAttributes();
     907             :     }
     908           0 :     nAnz=GetPageCount();
     909           0 :     for (nNum=0; nNum<nAnz; nNum++) {
     910           0 :         GetPage(nNum)->BurnInStyleSheetAttributes();
     911             :     }
     912           0 : }
     913             : 
     914        2513 : void SdrModel::RefDeviceChanged()
     915             : {
     916        2513 :     Broadcast(SdrHint(HINT_REFDEVICECHG));
     917        2513 :     ImpReformatAllTextObjects();
     918        2513 : }
     919             : 
     920         373 : void SdrModel::SetDefaultFontHeight(sal_uIntPtr nVal)
     921             : {
     922         373 :     if (nVal!=nDefTextHgt) {
     923         217 :         nDefTextHgt=nVal;
     924         217 :         Broadcast(SdrHint(HINT_DEFFONTHGTCHG));
     925         217 :         ImpReformatAllTextObjects();
     926             :     }
     927         373 : }
     928             : 
     929         503 : void SdrModel::SetDefaultTabulator(sal_uInt16 nVal)
     930             : {
     931         503 :     if (nDefaultTabulator!=nVal) {
     932         493 :         nDefaultTabulator=nVal;
     933         493 :         Outliner& rOutliner=GetDrawOutliner();
     934         493 :         rOutliner.SetDefTab(nVal);
     935         493 :         Broadcast(SdrHint(HINT_DEFAULTTABCHG));
     936         493 :         ImpReformatAllTextObjects();
     937             :     }
     938         503 : }
     939             : 
     940        4411 : void SdrModel::ImpSetUIUnit()
     941             : {
     942        4411 :     if(0 == aUIScale.GetNumerator() || 0 == aUIScale.GetDenominator())
     943             :     {
     944           0 :         aUIScale = Fraction(1,1);
     945             :     }
     946             : 
     947             :     // set start values
     948        4411 :     nUIUnitKomma = 0;
     949        4411 :     sal_Int64 nMul(1);
     950        4411 :     sal_Int64 nDiv(1);
     951             : 
     952             :     // normalize on meters resp. inch
     953        4411 :     switch (eObjUnit)
     954             :     {
     955        2637 :         case MAP_100TH_MM   : nUIUnitKomma+=5; break;
     956           0 :         case MAP_10TH_MM    : nUIUnitKomma+=4; break;
     957           0 :         case MAP_MM         : nUIUnitKomma+=3; break;
     958           0 :         case MAP_CM         : nUIUnitKomma+=2; break;
     959           0 :         case MAP_1000TH_INCH: nUIUnitKomma+=3; break;
     960           0 :         case MAP_100TH_INCH : nUIUnitKomma+=2; break;
     961           0 :         case MAP_10TH_INCH  : nUIUnitKomma+=1; break;
     962           0 :         case MAP_INCH       : nUIUnitKomma+=0; break;
     963           0 :         case MAP_POINT      : nDiv=72;     break;          // 1Pt   = 1/72"
     964        1774 :         case MAP_TWIP       : nDiv=144; nUIUnitKomma++; break; // 1Twip = 1/1440"
     965           0 :         case MAP_PIXEL      : break;
     966           0 :         case MAP_SYSFONT    : break;
     967           0 :         case MAP_APPFONT    : break;
     968           0 :         case MAP_RELATIVE   : break;
     969           0 :         default: break;
     970             :     } // switch
     971             : 
     972             :     // 1 mile    =  8 furlong = 63.360" = 1.609.344,0mm
     973             :     // 1 furlong = 10 chains  =  7.920" =   201.168,0mm
     974             :     // 1 chain   =  4 poles   =    792" =    20.116,8mm
     975             :     // 1 pole    =  5 1/2 yd  =    198" =     5.029,2mm
     976             :     // 1 yd      =  3 ft      =     36" =       914,4mm
     977             :     // 1 ft      = 12 "       =      1" =       304,8mm
     978        4411 :     switch (eUIUnit)
     979             :     {
     980           0 :         case FUNIT_NONE   : break;
     981             :         // metric
     982           0 :         case FUNIT_100TH_MM: nUIUnitKomma-=5; break;
     983        4255 :         case FUNIT_MM     : nUIUnitKomma-=3; break;
     984           0 :         case FUNIT_CM     : nUIUnitKomma-=2; break;
     985           0 :         case FUNIT_M      : nUIUnitKomma+=0; break;
     986           0 :         case FUNIT_KM     : nUIUnitKomma+=3; break;
     987             :         // Inch
     988           0 :         case FUNIT_TWIP   : nMul=144; nUIUnitKomma--;  break;  // 1Twip = 1/1440"
     989           0 :         case FUNIT_POINT  : nMul=72;     break;            // 1Pt   = 1/72"
     990           0 :         case FUNIT_PICA   : nMul=6;      break;            // 1Pica = 1/6"
     991         156 :         case FUNIT_INCH   : break;                         // 1"    = 1"
     992           0 :         case FUNIT_FOOT   : nDiv*=12;    break;            // 1Ft   = 12"
     993           0 :         case FUNIT_MILE   : nDiv*=6336; nUIUnitKomma++; break; // 1mile = 63360"
     994             :         // other
     995           0 :         case FUNIT_CUSTOM : break;
     996           0 :         case FUNIT_PERCENT: nUIUnitKomma+=2; break;
     997             :         // TODO: Add code to handle the following if needed (added to remove warning)
     998           0 :         case FUNIT_CHAR   : break;
     999           0 :         case FUNIT_LINE   : break;
    1000           0 :         case FUNIT_PIXEL  : break;
    1001           0 :         case FUNIT_DEGREE : break;
    1002           0 :         case FUNIT_SECOND : break;
    1003           0 :         case FUNIT_MILLISECOND : break;
    1004             :     } // switch
    1005             : 
    1006             :     // check if mapping is from metric to inch and adapt
    1007        4411 :     const bool bMapInch(IsInch(eObjUnit));
    1008        4411 :     const bool bUIMetr(IsMetric(eUIUnit));
    1009             : 
    1010        4411 :     if (bMapInch && bUIMetr)
    1011             :     {
    1012        1774 :         nUIUnitKomma += 4;
    1013        1774 :         nMul *= 254;
    1014             :     }
    1015             : 
    1016             :     // check if mapping is from inch to metric and adapt
    1017        4411 :     const bool bMapMetr(IsMetric(eObjUnit));
    1018        4411 :     const bool bUIInch(IsInch(eUIUnit));
    1019             : 
    1020        4411 :     if (bMapMetr && bUIInch)
    1021             :     {
    1022         156 :         nUIUnitKomma -= 4;
    1023         156 :         nDiv *= 254;
    1024             :     }
    1025             : 
    1026             :     // use temporary fraction for reduction (fallback to 32bit here),
    1027             :     // may need to be changed in the future, too
    1028        4411 :     if(1 != nMul || 1 != nDiv)
    1029             :     {
    1030        1930 :         const Fraction aTemp(static_cast< long >(nMul), static_cast< long >(nDiv));
    1031        1930 :         nMul = aTemp.GetNumerator();
    1032        1930 :         nDiv = aTemp.GetDenominator();
    1033             :     }
    1034             : 
    1035             :     // #i89872# take Unit of Measurement into account
    1036        4411 :     if(1 != aUIScale.GetDenominator() || 1 != aUIScale.GetNumerator())
    1037             :     {
    1038             :         // divide by UIScale
    1039           0 :         nMul *= aUIScale.GetDenominator();
    1040           0 :         nDiv *= aUIScale.GetNumerator();
    1041             :     }
    1042             : 
    1043             :     // shorten trailing zeros for dividend
    1044        8822 :     while(0 == (nMul % 10))
    1045             :     {
    1046           0 :         nUIUnitKomma--;
    1047           0 :         nMul /= 10;
    1048             :     }
    1049             : 
    1050             :     // shorten trailing zeros for divisor
    1051        8822 :     while(0 == (nDiv % 10))
    1052             :     {
    1053           0 :         nUIUnitKomma++;
    1054           0 :         nDiv /= 10;
    1055             :     }
    1056             : 
    1057             :     // end preparations, set member values
    1058        4411 :     aUIUnitFact = Fraction(sal_Int32(nMul), sal_Int32(nDiv));
    1059        4411 :     bUIOnlyKomma = (nMul == nDiv);
    1060        4411 :     TakeUnitStr(eUIUnit, aUIUnitStr);
    1061        4411 : }
    1062             : 
    1063           0 : void SdrModel::SetScaleUnit(MapUnit eMap, const Fraction& rFrac)
    1064             : {
    1065           0 :     if (eObjUnit!=eMap || aObjUnit!=rFrac) {
    1066           0 :         eObjUnit=eMap;
    1067           0 :         aObjUnit=rFrac;
    1068           0 :         pItemPool->SetDefaultMetric((SfxMapUnit)eObjUnit);
    1069           0 :         ImpSetUIUnit();
    1070           0 :         ImpSetOutlinerDefaults( pDrawOutliner );
    1071           0 :         ImpSetOutlinerDefaults( pHitTestOutliner );
    1072           0 :         ImpReformatAllTextObjects();
    1073             :     }
    1074           0 : }
    1075             : 
    1076        2481 : void SdrModel::SetScaleUnit(MapUnit eMap)
    1077             : {
    1078        2481 :     if (eObjUnit!=eMap) {
    1079        1774 :         eObjUnit=eMap;
    1080        1774 :         pItemPool->SetDefaultMetric((SfxMapUnit)eObjUnit);
    1081        1774 :         ImpSetUIUnit();
    1082        1774 :         ImpSetOutlinerDefaults( pDrawOutliner );
    1083        1774 :         ImpSetOutlinerDefaults( pHitTestOutliner );
    1084        1774 :         ImpReformatAllTextObjects();
    1085             :     }
    1086        2481 : }
    1087             : 
    1088         373 : void SdrModel::SetScaleFraction(const Fraction& rFrac)
    1089             : {
    1090         373 :     if (aObjUnit!=rFrac) {
    1091           0 :         aObjUnit=rFrac;
    1092           0 :         ImpSetUIUnit();
    1093           0 :         ImpSetOutlinerDefaults( pDrawOutliner );
    1094           0 :         ImpSetOutlinerDefaults( pHitTestOutliner );
    1095           0 :         ImpReformatAllTextObjects();
    1096             :     }
    1097         373 : }
    1098             : 
    1099           1 : void SdrModel::SetUIUnit(FieldUnit eUnit)
    1100             : {
    1101           1 :     if (eUIUnit!=eUnit) {
    1102           0 :         eUIUnit=eUnit;
    1103           0 :         ImpSetUIUnit();
    1104           0 :         ImpReformatAllTextObjects();
    1105             :     }
    1106           1 : }
    1107             : 
    1108           2 : void SdrModel::SetUIScale(const Fraction& rScale)
    1109             : {
    1110           2 :     if (aUIScale!=rScale) {
    1111           0 :         aUIScale=rScale;
    1112           0 :         ImpSetUIUnit();
    1113           0 :         ImpReformatAllTextObjects();
    1114             :     }
    1115           2 : }
    1116             : 
    1117         156 : void SdrModel::SetUIUnit(FieldUnit eUnit, const Fraction& rScale)
    1118             : {
    1119         156 :     if (eUIUnit!=eUnit || aUIScale!=rScale) {
    1120         156 :         eUIUnit=eUnit;
    1121         156 :         aUIScale=rScale;
    1122         156 :         ImpSetUIUnit();
    1123         156 :         ImpReformatAllTextObjects();
    1124             :     }
    1125         156 : }
    1126             : 
    1127        4432 : void SdrModel::TakeUnitStr(FieldUnit eUnit, OUString& rStr)
    1128             : {
    1129        4432 :     switch(eUnit)
    1130             :     {
    1131             :         default:
    1132             :         case FUNIT_NONE   :
    1133             :         case FUNIT_CUSTOM :
    1134             :         {
    1135           0 :             rStr = "";
    1136           0 :             break;
    1137             :         }
    1138             :         case FUNIT_100TH_MM:
    1139             :         {
    1140           0 :             rStr = "/100mm";
    1141           0 :             break;
    1142             :         }
    1143             :         case FUNIT_MM     :
    1144             :         {
    1145        4276 :             rStr = "mm";
    1146        4276 :             break;
    1147             :         }
    1148             :         case FUNIT_CM     :
    1149             :         {
    1150           0 :             rStr = "cm";
    1151           0 :             break;
    1152             :         }
    1153             :         case FUNIT_M      :
    1154             :         {
    1155           0 :             rStr = "m";
    1156           0 :             break;
    1157             :         }
    1158             :         case FUNIT_KM     :
    1159             :         {
    1160           0 :             rStr ="km";
    1161           0 :             break;
    1162             :         }
    1163             :         case FUNIT_TWIP   :
    1164             :         {
    1165           0 :             rStr = "twip";
    1166           0 :             break;
    1167             :         }
    1168             :         case FUNIT_POINT  :
    1169             :         {
    1170           0 :             rStr = "pt";
    1171           0 :             break;
    1172             :         }
    1173             :         case FUNIT_PICA   :
    1174             :         {
    1175           0 :             rStr = "pica";
    1176           0 :             break;
    1177             :         }
    1178             :         case FUNIT_INCH   :
    1179             :         {
    1180         156 :             rStr = "\"";
    1181         156 :             break;
    1182             :         }
    1183             :         case FUNIT_FOOT   :
    1184             :         {
    1185           0 :             rStr = "ft";
    1186           0 :             break;
    1187             :         }
    1188             :         case FUNIT_MILE   :
    1189             :         {
    1190           0 :             rStr = "mile(s)";
    1191           0 :             break;
    1192             :         }
    1193             :         case FUNIT_PERCENT:
    1194             :         {
    1195           0 :             rStr = "%";
    1196           0 :             break;
    1197             :         }
    1198             :     }
    1199        4432 : }
    1200             : 
    1201          21 : void SdrModel::TakeMetricStr(long nVal, OUString& rStr, bool bNoUnitChars, sal_Int32 nNumDigits) const
    1202             : {
    1203             :     // #i22167#
    1204             :     // change to double precision usage to not lose decimal places
    1205          21 :     const bool bNegative(nVal < 0L);
    1206          21 :     SvtSysLocale aSysLoc;
    1207          21 :     const LocaleDataWrapper& rLoc(aSysLoc.GetLocaleData());
    1208          21 :     double fLocalValue(double(nVal) * double(aUIUnitFact));
    1209             : 
    1210          21 :     if(bNegative)
    1211             :     {
    1212           0 :         fLocalValue = -fLocalValue;
    1213             :     }
    1214             : 
    1215          21 :     if( -1 == nNumDigits )
    1216             :     {
    1217           0 :         nNumDigits = rLoc.getNumDigits();
    1218             :     }
    1219             : 
    1220          21 :     sal_Int32 nKomma(nUIUnitKomma);
    1221             : 
    1222          21 :     if(nKomma > nNumDigits)
    1223             :     {
    1224           0 :         const sal_Int32 nDiff(nKomma - nNumDigits);
    1225           0 :         const double fFactor(pow(10.0, static_cast<const int>(nDiff)));
    1226             : 
    1227           0 :         fLocalValue /= fFactor;
    1228           0 :         nKomma = nNumDigits;
    1229             :     }
    1230          21 :     else if(nKomma < nNumDigits)
    1231             :     {
    1232           0 :         const sal_Int32 nDiff(nNumDigits - nKomma);
    1233           0 :         const double fFactor(pow(10.0, static_cast<const int>(nDiff)));
    1234             : 
    1235           0 :         fLocalValue *= fFactor;
    1236           0 :         nKomma = nNumDigits;
    1237             :     }
    1238             : 
    1239          42 :     OUStringBuffer aBuf;
    1240          21 :     aBuf.append(static_cast<sal_Int32>(fLocalValue + 0.5));
    1241             : 
    1242          21 :     if(nKomma < 0)
    1243             :     {
    1244             :         // negative nKomma (decimal point) means: add zeros
    1245           0 :         sal_Int32 nAnz(-nKomma);
    1246             : 
    1247           0 :         for(sal_Int32 i=0; i<nAnz; i++)
    1248           0 :             aBuf.append('0');
    1249             : 
    1250           0 :         nKomma = 0;
    1251             :     }
    1252             : 
    1253             :     // the second condition needs to be <= since inside this loop
    1254             :     // also the leading zero is inserted.
    1255          21 :     if (nKomma > 0 && aBuf.getLength() <= nKomma)
    1256             :     {
    1257             :         // if necessary, add zeros before the decimal point
    1258          13 :         sal_Int32 nAnz = nKomma - aBuf.getLength();
    1259             : 
    1260          13 :         if(nAnz >= 0 && rLoc.isNumLeadingZero())
    1261          13 :             nAnz++;
    1262             : 
    1263          26 :         for(sal_Int32 i=0; i<nAnz; i++)
    1264          13 :             aBuf.insert(0, '0');
    1265             :     }
    1266             : 
    1267          21 :     sal_Unicode cDec( rLoc.getNumDecimalSep()[0] );
    1268             : 
    1269             :     // insert KommaChar (decimal point character)
    1270          21 :     sal_Int32 nVorKomma = aBuf.getLength() - nKomma;
    1271             : 
    1272          21 :     if(nKomma > 0)
    1273          21 :         aBuf.insert(nVorKomma, cDec);
    1274             : 
    1275          21 :     if(!rLoc.isNumTrailingZeros())
    1276             :     {
    1277             :         // Remove all trailing zeros.
    1278           0 :         while (!aBuf.isEmpty() && aBuf[aBuf.getLength()-1] == '0')
    1279           0 :             aBuf.remove(aBuf.getLength()-1, 1);
    1280             : 
    1281             :         // Remove decimal if it's the last character.
    1282           0 :         if (!aBuf.isEmpty() && aBuf[aBuf.getLength()-1] == cDec)
    1283           0 :             aBuf.remove(aBuf.getLength()-1, 1);
    1284             :     }
    1285             : 
    1286             :     // if necessary, add separators before every third digit
    1287          21 :     if( nVorKomma > 3 )
    1288             :     {
    1289           0 :         OUString aThoSep( rLoc.getNumThousandSep() );
    1290           0 :         if ( !aThoSep.isEmpty() )
    1291             :         {
    1292           0 :             sal_Unicode cTho( aThoSep[0] );
    1293           0 :             sal_Int32 i(nVorKomma - 3);
    1294             : 
    1295           0 :             while(i > 0)
    1296             :             {
    1297           0 :                 aBuf.insert(i, cTho);
    1298           0 :                 i -= 3;
    1299             :             }
    1300           0 :         }
    1301             :     }
    1302             : 
    1303          21 :     if (aBuf.isEmpty())
    1304           0 :         aBuf.append("0");
    1305             : 
    1306          21 :     if(bNegative)
    1307             :     {
    1308           0 :         aBuf.insert(0, "-");
    1309             :     }
    1310             : 
    1311          21 :     if(!bNoUnitChars)
    1312           0 :         aBuf.append(aUIUnitStr);
    1313             : 
    1314          42 :     rStr = aBuf.makeStringAndClear();
    1315          21 : }
    1316             : 
    1317           0 : void SdrModel::TakeWinkStr(long nWink, OUString& rStr, bool bNoDegChar) const
    1318             : {
    1319           0 :     bool bNeg = nWink < 0;
    1320             : 
    1321           0 :     if(bNeg)
    1322           0 :         nWink = -nWink;
    1323             : 
    1324           0 :     OUStringBuffer aBuf;
    1325           0 :     aBuf.append(static_cast<sal_Int32>(nWink));
    1326             : 
    1327           0 :     SvtSysLocale aSysLoc;
    1328           0 :     const LocaleDataWrapper& rLoc = aSysLoc.GetLocaleData();
    1329           0 :     sal_Int32 nAnz = 2;
    1330             : 
    1331           0 :     if(rLoc.isNumLeadingZero())
    1332           0 :         nAnz++;
    1333             : 
    1334           0 :     while(aBuf.getLength() < nAnz)
    1335           0 :         aBuf.insert(0, '0');
    1336             : 
    1337           0 :     aBuf.insert(aBuf.getLength()-2, rLoc.getNumDecimalSep()[0]);
    1338             : 
    1339           0 :     if(bNeg)
    1340           0 :         aBuf.insert(0, '-');
    1341             : 
    1342           0 :     if(!bNoDegChar)
    1343           0 :         aBuf.append(DEGREE_CHAR);
    1344             : 
    1345           0 :     rStr = aBuf.makeStringAndClear();
    1346           0 : }
    1347             : 
    1348           0 : void SdrModel::TakePercentStr(const Fraction& rVal, OUString& rStr, bool bNoPercentChar) const
    1349             : {
    1350           0 :     sal_Int32 nMul(rVal.GetNumerator());
    1351           0 :     sal_Int32 nDiv(rVal.GetDenominator());
    1352           0 :     bool bNeg(nMul < 0);
    1353             : 
    1354           0 :     if(nDiv < 0)
    1355           0 :         bNeg = !bNeg;
    1356             : 
    1357           0 :     if(nMul < 0)
    1358           0 :         nMul = -nMul;
    1359             : 
    1360           0 :     if(nDiv < 0)
    1361           0 :         nDiv = -nDiv;
    1362             : 
    1363           0 :     nMul *= 100;
    1364           0 :     nMul += nDiv/2;
    1365           0 :     nMul /= nDiv;
    1366             : 
    1367           0 :     rStr = OUString::number(nMul);
    1368             : 
    1369           0 :     if(bNeg)
    1370           0 :         rStr = "-" + rStr;
    1371             : 
    1372           0 :     if(!bNoPercentChar)
    1373           0 :         rStr += "%";
    1374           0 : }
    1375             : 
    1376     1683688 : void SdrModel::SetChanged(bool bFlg)
    1377             : {
    1378     1683688 :     mbChanged = bFlg;
    1379     1683688 : }
    1380             : 
    1381          84 : void SdrModel::RecalcPageNums(bool bMaster)
    1382             : {
    1383          84 :     if(bMaster)
    1384             :     {
    1385           2 :         sal_uInt16 nAnz=sal_uInt16(maMaPag.size());
    1386             :         sal_uInt16 i;
    1387          16 :         for (i=0; i<nAnz; i++) {
    1388          14 :             SdrPage* pPg=maMaPag[i];
    1389          14 :             pPg->SetPageNum(i);
    1390             :         }
    1391           2 :         bMPgNumsDirty=false;
    1392             :     }
    1393             :     else
    1394             :     {
    1395          82 :         sal_uInt16 nAnz=sal_uInt16(maPages.size());
    1396             :         sal_uInt16 i;
    1397         329 :         for (i=0; i<nAnz; i++) {
    1398         247 :             SdrPage* pPg=maPages[i];
    1399         247 :             pPg->SetPageNum(i);
    1400             :         }
    1401          82 :         bPagNumsDirty=false;
    1402             :     }
    1403          84 : }
    1404             : 
    1405        3184 : void SdrModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
    1406             : {
    1407        3184 :     sal_uInt16 nAnz=GetPageCount();
    1408        3184 :     if (nPos>nAnz) nPos=nAnz;
    1409        3184 :     maPages.insert(maPages.begin()+nPos,pPage);
    1410        3184 :     PageListChanged();
    1411        3184 :     pPage->SetInserted(true);
    1412        3184 :     pPage->SetPageNum(nPos);
    1413        3184 :     pPage->SetModel(this);
    1414        3184 :     if (nPos<nAnz) bPagNumsDirty=true;
    1415        3184 :     SetChanged();
    1416        3184 :     SdrHint aHint(HINT_PAGEORDERCHG);
    1417        3184 :     aHint.SetPage(pPage);
    1418        3184 :     Broadcast(aHint);
    1419        3184 : }
    1420             : 
    1421        2865 : void SdrModel::DeletePage(sal_uInt16 nPgNum)
    1422             : {
    1423        2865 :     SdrPage* pPg=RemovePage(nPgNum);
    1424        2865 :     delete pPg;
    1425        2865 : }
    1426             : 
    1427        2981 : SdrPage* SdrModel::RemovePage(sal_uInt16 nPgNum)
    1428             : {
    1429        2981 :     SdrPage* pPg=maPages[nPgNum];
    1430        2981 :     maPages.erase(maPages.begin()+nPgNum);
    1431        2981 :     PageListChanged();
    1432        2981 :     if (pPg!=NULL) {
    1433        2981 :         pPg->SetInserted(false);
    1434             :     }
    1435        2981 :     bPagNumsDirty=true;
    1436        2981 :     SetChanged();
    1437        2981 :     SdrHint aHint(HINT_PAGEORDERCHG);
    1438        2981 :     aHint.SetPage(pPg);
    1439        2981 :     Broadcast(aHint);
    1440        2981 :     return pPg;
    1441             : }
    1442             : 
    1443           1 : void SdrModel::MovePage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
    1444             : {
    1445           1 :     SdrPage* pPg=maPages[nPgNum];
    1446           1 :     if (pPg!=NULL) {
    1447           1 :         maPages.erase(maPages.begin()+nPgNum); // shortcut to avoid two broadcasts
    1448           1 :         PageListChanged();
    1449           1 :         pPg->SetInserted(false);
    1450           1 :         InsertPage(pPg,nNewPos);
    1451             :     }
    1452             :     else
    1453           0 :         RemovePage(nPgNum);
    1454           1 : }
    1455             : 
    1456         407 : void SdrModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
    1457             : {
    1458         407 :     sal_uInt16 nAnz=GetMasterPageCount();
    1459         407 :     if (nPos>nAnz) nPos=nAnz;
    1460         407 :     maMaPag.insert(maMaPag.begin()+nPos,pPage);
    1461         407 :     MasterPageListChanged();
    1462         407 :     pPage->SetInserted(true);
    1463         407 :     pPage->SetPageNum(nPos);
    1464         407 :     pPage->SetModel(this);
    1465         407 :     if (nPos<nAnz) {
    1466           2 :         bMPgNumsDirty=true;
    1467             :     }
    1468         407 :     SetChanged();
    1469         407 :     SdrHint aHint(HINT_PAGEORDERCHG);
    1470         407 :     aHint.SetPage(pPage);
    1471         407 :     Broadcast(aHint);
    1472         407 : }
    1473             : 
    1474         336 : void SdrModel::DeleteMasterPage(sal_uInt16 nPgNum)
    1475             : {
    1476         336 :     SdrPage* pPg=RemoveMasterPage(nPgNum);
    1477         336 :     delete pPg;
    1478         336 : }
    1479             : 
    1480         338 : SdrPage* SdrModel::RemoveMasterPage(sal_uInt16 nPgNum)
    1481             : {
    1482         338 :     SdrPage* pRetPg=maMaPag[nPgNum];
    1483         338 :     maMaPag.erase(maMaPag.begin()+nPgNum);
    1484         338 :     MasterPageListChanged();
    1485             : 
    1486         338 :     if(pRetPg)
    1487             :     {
    1488             :         // Now delete the links from the normal drawing pages to the deleted master page.
    1489         338 :         sal_uInt16 nPageAnz(GetPageCount());
    1490             : 
    1491         344 :         for(sal_uInt16 np(0); np < nPageAnz; np++)
    1492             :         {
    1493           6 :             GetPage(np)->TRG_ImpMasterPageRemoved(*pRetPg);
    1494             :         }
    1495             : 
    1496         338 :         pRetPg->SetInserted(false);
    1497             :     }
    1498             : 
    1499         338 :     bMPgNumsDirty=true;
    1500         338 :     SetChanged();
    1501         338 :     SdrHint aHint(HINT_PAGEORDERCHG);
    1502         338 :     aHint.SetPage(pRetPg);
    1503         338 :     Broadcast(aHint);
    1504         338 :     return pRetPg;
    1505             : }
    1506             : 
    1507           0 : void SdrModel::MoveMasterPage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
    1508             : {
    1509           0 :     SdrPage* pPg=maMaPag[nPgNum];
    1510           0 :     maMaPag.erase(maMaPag.begin()+nPgNum);
    1511           0 :     MasterPageListChanged();
    1512           0 :     if (pPg!=NULL) {
    1513           0 :         pPg->SetInserted(false);
    1514           0 :         maMaPag.insert(maMaPag.begin()+nNewPos,pPg);
    1515           0 :         MasterPageListChanged();
    1516             :     }
    1517           0 :     bMPgNumsDirty=true;
    1518           0 :     SetChanged();
    1519           0 :     SdrHint aHint(HINT_PAGEORDERCHG);
    1520           0 :     aHint.SetPage(pPg);
    1521           0 :     Broadcast(aHint);
    1522           0 : }
    1523             : 
    1524             : 
    1525             : 
    1526           0 : void SdrModel::CopyPages(sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum,
    1527             :                          sal_uInt16 nDestPos,
    1528             :                          bool bUndo, bool bMoveNoCopy)
    1529             : {
    1530           0 :     if( bUndo && !IsUndoEnabled() )
    1531           0 :         bUndo = false;
    1532             : 
    1533           0 :     if( bUndo )
    1534           0 :         BegUndo(ImpGetResStr(STR_UndoMergeModel));
    1535             : 
    1536           0 :     sal_uInt16 nPageAnz=GetPageCount();
    1537           0 :     sal_uInt16 nMaxPage=nPageAnz;
    1538             : 
    1539           0 :     if (nMaxPage!=0)
    1540           0 :         nMaxPage--;
    1541           0 :     if (nFirstPageNum>nMaxPage)
    1542           0 :         nFirstPageNum=nMaxPage;
    1543           0 :     if (nLastPageNum>nMaxPage)
    1544           0 :         nLastPageNum =nMaxPage;
    1545           0 :     bool bReverse=nLastPageNum<nFirstPageNum;
    1546           0 :     if (nDestPos>nPageAnz)
    1547           0 :         nDestPos=nPageAnz;
    1548             : 
    1549             :     // at first, save the pointers of the affected pages in an array
    1550           0 :     sal_uInt16 nPageNum=nFirstPageNum;
    1551           0 :     sal_uInt16 nCopyAnz=((!bReverse)?(nLastPageNum-nFirstPageNum):(nFirstPageNum-nLastPageNum))+1;
    1552           0 :     SdrPage** pPagePtrs=new SdrPage*[nCopyAnz];
    1553             :     sal_uInt16 nCopyNum;
    1554           0 :     for(nCopyNum=0; nCopyNum<nCopyAnz; nCopyNum++)
    1555             :     {
    1556           0 :         pPagePtrs[nCopyNum]=GetPage(nPageNum);
    1557           0 :         if (bReverse)
    1558           0 :             nPageNum--;
    1559             :         else
    1560           0 :             nPageNum++;
    1561             :     }
    1562             : 
    1563             :     // now copy the pages
    1564           0 :     sal_uInt16 nDestNum=nDestPos;
    1565           0 :     for (nCopyNum=0; nCopyNum<nCopyAnz; nCopyNum++)
    1566             :     {
    1567           0 :         SdrPage* pPg=pPagePtrs[nCopyNum];
    1568           0 :         sal_uInt16 nPageNum2=pPg->GetPageNum();
    1569           0 :         if (!bMoveNoCopy)
    1570             :         {
    1571           0 :             const SdrPage* pPg1=GetPage(nPageNum2);
    1572           0 :             pPg=pPg1->Clone();
    1573           0 :             InsertPage(pPg,nDestNum);
    1574           0 :             if (bUndo)
    1575           0 :                 AddUndo(GetSdrUndoFactory().CreateUndoCopyPage(*pPg));
    1576           0 :             nDestNum++;
    1577             :         }
    1578             :         else
    1579             :         {
    1580             :             // TODO: Move is untested!
    1581           0 :             if (nDestNum>nPageNum2)
    1582           0 :                 nDestNum--;
    1583             : 
    1584           0 :             if(bUndo)
    1585           0 :                 AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*GetPage(nPageNum2),nPageNum2,nDestNum));
    1586             : 
    1587           0 :             pPg=RemovePage(nPageNum2);
    1588           0 :             InsertPage(pPg,nDestNum);
    1589           0 :             nDestNum++;
    1590             :         }
    1591             : 
    1592           0 :         if(bReverse)
    1593           0 :             nPageNum2--;
    1594             :         else
    1595           0 :             nPageNum2++;
    1596             :     }
    1597             : 
    1598           0 :     delete[] pPagePtrs;
    1599           0 :     if(bUndo)
    1600           0 :         EndUndo();
    1601           0 : }
    1602             : 
    1603           0 : void SdrModel::Merge(SdrModel& rSourceModel,
    1604             :                      sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum,
    1605             :                      sal_uInt16 nDestPos,
    1606             :                      bool bMergeMasterPages, bool bAllMasterPages,
    1607             :                      bool bUndo, bool bTreadSourceAsConst)
    1608             : {
    1609           0 :     if (&rSourceModel==this)
    1610             :     {
    1611           0 :         CopyPages(nFirstPageNum,nLastPageNum,nDestPos,bUndo,!bTreadSourceAsConst);
    1612           0 :         return;
    1613             :     }
    1614             : 
    1615           0 :     if( bUndo && !IsUndoEnabled() )
    1616           0 :         bUndo = false;
    1617             : 
    1618           0 :     if (bUndo)
    1619           0 :         BegUndo(ImpGetResStr(STR_UndoMergeModel));
    1620             : 
    1621           0 :     sal_uInt16 nSrcPageAnz=rSourceModel.GetPageCount();
    1622           0 :     sal_uInt16 nSrcMasterPageAnz=rSourceModel.GetMasterPageCount();
    1623           0 :     sal_uInt16 nDstMasterPageAnz=GetMasterPageCount();
    1624           0 :     bool bInsPages=(nFirstPageNum<nSrcPageAnz || nLastPageNum<nSrcPageAnz);
    1625           0 :     sal_uInt16 nMaxSrcPage=nSrcPageAnz; if (nMaxSrcPage!=0) nMaxSrcPage--;
    1626           0 :     if (nFirstPageNum>nMaxSrcPage) nFirstPageNum=nMaxSrcPage;
    1627           0 :     if (nLastPageNum>nMaxSrcPage)  nLastPageNum =nMaxSrcPage;
    1628           0 :     bool bReverse=nLastPageNum<nFirstPageNum;
    1629             : 
    1630           0 :     sal_uInt16*   pMasterMap=NULL;
    1631           0 :     bool* pMasterNeed=NULL;
    1632           0 :     sal_uInt16    nMasterNeed=0;
    1633           0 :     if (bMergeMasterPages && nSrcMasterPageAnz!=0) {
    1634             :         // determine which MasterPages from rSrcModel we need
    1635           0 :         pMasterMap=new sal_uInt16[nSrcMasterPageAnz];
    1636           0 :         pMasterNeed=new bool[nSrcMasterPageAnz];
    1637           0 :         memset(pMasterMap,0xFF,nSrcMasterPageAnz*sizeof(sal_uInt16));
    1638           0 :         if (bAllMasterPages) {
    1639           0 :             memset(pMasterNeed, true, nSrcMasterPageAnz * sizeof(bool));
    1640             :         } else {
    1641           0 :             memset(pMasterNeed, false, nSrcMasterPageAnz * sizeof(bool));
    1642           0 :             sal_uInt16 nAnf= bReverse ? nLastPageNum : nFirstPageNum;
    1643           0 :             sal_uInt16 nEnd= bReverse ? nFirstPageNum : nLastPageNum;
    1644           0 :             for (sal_uInt16 i=nAnf; i<=nEnd; i++) {
    1645           0 :                 const SdrPage* pPg=rSourceModel.GetPage(i);
    1646           0 :                 if(pPg->TRG_HasMasterPage())
    1647             :                 {
    1648           0 :                     SdrPage& rMasterPage = pPg->TRG_GetMasterPage();
    1649           0 :                     sal_uInt16 nMPgNum(rMasterPage.GetPageNum());
    1650             : 
    1651           0 :                     if(nMPgNum < nSrcMasterPageAnz)
    1652             :                     {
    1653           0 :                         pMasterNeed[nMPgNum] = true;
    1654             :                     }
    1655             :                 }
    1656             :             }
    1657             :         }
    1658             :         // now determine the Mapping of the MasterPages
    1659           0 :         sal_uInt16 nAktMaPagNum=nDstMasterPageAnz;
    1660           0 :         for (sal_uInt16 i=0; i<nSrcMasterPageAnz; i++) {
    1661           0 :             if (pMasterNeed[i]) {
    1662           0 :                 pMasterMap[i]=nAktMaPagNum;
    1663           0 :                 nAktMaPagNum++;
    1664           0 :                 nMasterNeed++;
    1665             :             }
    1666             :         }
    1667             :     }
    1668             : 
    1669             :     // get the MasterPages
    1670           0 :     if (pMasterMap!=NULL && pMasterNeed!=NULL && nMasterNeed!=0) {
    1671           0 :         for (sal_uInt16 i=nSrcMasterPageAnz; i>0;) {
    1672           0 :             i--;
    1673           0 :             if (pMasterNeed[i]) {
    1674           0 :                 SdrPage* pPg=NULL;
    1675           0 :                 if (bTreadSourceAsConst) {
    1676           0 :                     const SdrPage* pPg1=rSourceModel.GetMasterPage(i);
    1677           0 :                     pPg=pPg1->Clone();
    1678             :                 } else {
    1679           0 :                     pPg=rSourceModel.RemoveMasterPage(i);
    1680             :                 }
    1681           0 :                 if (pPg!=NULL) {
    1682             :                     // Now append all of them to the end of the DstModel.
    1683             :                     // Don't use InsertMasterPage(), because everything is
    1684             :                     // inconsistent until all are in.
    1685           0 :                     maMaPag.insert(maMaPag.begin()+nDstMasterPageAnz, pPg);
    1686           0 :                     MasterPageListChanged();
    1687           0 :                     pPg->SetInserted(true);
    1688           0 :                     pPg->SetModel(this);
    1689           0 :                     bMPgNumsDirty=true;
    1690           0 :                     if (bUndo) AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pPg));
    1691             :                 } else {
    1692             :                     OSL_FAIL("SdrModel::Merge(): MasterPage not found in SourceModel.");
    1693             :                 }
    1694             :             }
    1695             :         }
    1696             :     }
    1697             : 
    1698             :     // get the drawing pages
    1699           0 :     if (bInsPages) {
    1700           0 :         sal_uInt16 nSourcePos=nFirstPageNum;
    1701           0 :         sal_uInt16 nMergeCount=sal_uInt16(std::abs((long)((long)nFirstPageNum-nLastPageNum))+1);
    1702           0 :         if (nDestPos>GetPageCount()) nDestPos=GetPageCount();
    1703           0 :         while (nMergeCount>0) {
    1704           0 :             SdrPage* pPg=NULL;
    1705           0 :             if (bTreadSourceAsConst) {
    1706           0 :                 const SdrPage* pPg1=rSourceModel.GetPage(nSourcePos);
    1707           0 :                 pPg=pPg1->Clone();
    1708             :             } else {
    1709           0 :                 pPg=rSourceModel.RemovePage(nSourcePos);
    1710             :             }
    1711           0 :             if (pPg!=NULL) {
    1712           0 :                 InsertPage(pPg,nDestPos);
    1713           0 :                 if (bUndo) AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pPg));
    1714             : 
    1715           0 :                 if(pPg->TRG_HasMasterPage())
    1716             :                 {
    1717           0 :                     SdrPage& rMasterPage = pPg->TRG_GetMasterPage();
    1718           0 :                     sal_uInt16 nMaPgNum(rMasterPage.GetPageNum());
    1719             : 
    1720           0 :                     if (bMergeMasterPages)
    1721             :                     {
    1722           0 :                         sal_uInt16 nNeuNum(0xFFFF);
    1723             : 
    1724           0 :                         if(pMasterMap)
    1725             :                         {
    1726           0 :                             nNeuNum = pMasterMap[nMaPgNum];
    1727             :                         }
    1728             : 
    1729           0 :                         if(nNeuNum != 0xFFFF)
    1730             :                         {
    1731           0 :                             if(bUndo)
    1732             :                             {
    1733           0 :                                 AddUndo(GetSdrUndoFactory().CreateUndoPageChangeMasterPage(*pPg));
    1734             :                             }
    1735             : 
    1736           0 :                             pPg->TRG_SetMasterPage(*GetMasterPage(nNeuNum));
    1737             :                         }
    1738             :                         DBG_ASSERT(nNeuNum!=0xFFFF,"SdrModel::Merge(): Something is crooked with the mapping of the MasterPages.");
    1739             :                     } else {
    1740           0 :                         if (nMaPgNum>=nDstMasterPageAnz) {
    1741             :                             // This is outside of the original area of the MasterPage of the DstModel.
    1742           0 :                             pPg->TRG_ClearMasterPage();
    1743             :                         }
    1744             :                     }
    1745             :                 }
    1746             : 
    1747             :             } else {
    1748             :                 OSL_FAIL("SdrModel::Merge(): Drawing page not found in SourceModel.");
    1749             :             }
    1750           0 :             nDestPos++;
    1751           0 :             if (bReverse) nSourcePos--;
    1752           0 :             else if (bTreadSourceAsConst) nSourcePos++;
    1753           0 :             nMergeCount--;
    1754             :         }
    1755             :     }
    1756             : 
    1757           0 :     delete [] pMasterMap;
    1758           0 :     delete [] pMasterNeed;
    1759             : 
    1760           0 :     bMPgNumsDirty=true;
    1761           0 :     bPagNumsDirty=true;
    1762             : 
    1763           0 :     SetChanged();
    1764             :     // TODO: Missing: merging and mapping of layers
    1765             :     // at the objects as well as at the MasterPageDescriptors
    1766           0 :     if (bUndo) EndUndo();
    1767             : }
    1768             : 
    1769           0 : void SdrModel::SetStarDrawPreviewMode(bool bPreview)
    1770             : {
    1771           0 :     if (!bPreview && bStarDrawPreviewMode && GetPageCount())
    1772             :     {
    1773             :         // Resetting is not allowed, because the Model might not be loaded completely
    1774             :         DBG_ASSERT(false,"SdrModel::SetStarDrawPreviewMode(): Resetting not allowed, because Model might not be complete.");
    1775             :     }
    1776             :     else
    1777             :     {
    1778           0 :         bStarDrawPreviewMode = bPreview;
    1779             :     }
    1780           0 : }
    1781             : 
    1782        3379 : uno::Reference< uno::XInterface > SdrModel::getUnoModel()
    1783             : {
    1784        3379 :     if( !mxUnoModel.is() )
    1785         427 :         mxUnoModel = createUnoModel();
    1786             : 
    1787        3379 :     return mxUnoModel;
    1788             : }
    1789             : 
    1790           0 : void SdrModel::setUnoModel( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xModel )
    1791             : {
    1792           0 :     mxUnoModel = xModel;
    1793           0 : }
    1794             : 
    1795           0 : uno::Reference< uno::XInterface > SdrModel::createUnoModel()
    1796             : {
    1797             :     OSL_FAIL( "SdrModel::createUnoModel() - base implementation should not be called!" );
    1798           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xInt;
    1799           0 :     return xInt;
    1800             : }
    1801             : 
    1802        1871 : void SdrModel::setLock( bool bLock )
    1803             : {
    1804        1871 :     if( mbModelLocked != bLock )
    1805             :     {
    1806             :         // #i120437# need to set first, else ImpReformatAllEdgeObjects will do nothing
    1807        1758 :         mbModelLocked = bLock;
    1808             : 
    1809        1758 :         if( !bLock )
    1810             :         {
    1811         875 :             ImpReformatAllEdgeObjects();
    1812             :         }
    1813             :     }
    1814        1871 : }
    1815             : 
    1816             : 
    1817             : 
    1818        4450 : void SdrModel::MigrateItemSet( const SfxItemSet* pSourceSet, SfxItemSet* pDestSet, SdrModel* pNewModel )
    1819             : {
    1820        4450 :     if( pSourceSet && pDestSet && (pSourceSet != pDestSet ) )
    1821             :     {
    1822        4450 :         if( pNewModel == NULL )
    1823           0 :             pNewModel = this;
    1824             : 
    1825        4450 :         SfxWhichIter aWhichIter(*pSourceSet);
    1826        4450 :         sal_uInt16 nWhich(aWhichIter.FirstWhich());
    1827             :         const SfxPoolItem *pPoolItem;
    1828             : 
    1829      624126 :         while(nWhich)
    1830             :         {
    1831      615226 :             if(SFX_ITEM_SET == pSourceSet->GetItemState(nWhich, false, &pPoolItem))
    1832             :             {
    1833       25779 :                 const SfxPoolItem* pItem = pPoolItem;
    1834             : 
    1835       25779 :                 switch( nWhich )
    1836             :                 {
    1837             :                 case XATTR_FILLBITMAP:
    1838           0 :                     pItem = ((XFillBitmapItem*)pItem)->checkForUniqueItem( pNewModel );
    1839           0 :                     break;
    1840             :                 case XATTR_LINEDASH:
    1841          46 :                     pItem = ((XLineDashItem*)pItem)->checkForUniqueItem( pNewModel );
    1842          46 :                     break;
    1843             :                 case XATTR_LINESTART:
    1844          36 :                     pItem = ((XLineStartItem*)pItem)->checkForUniqueItem( pNewModel );
    1845          36 :                     break;
    1846             :                 case XATTR_LINEEND:
    1847          40 :                     pItem = ((XLineEndItem*)pItem)->checkForUniqueItem( pNewModel );
    1848          40 :                     break;
    1849             :                 case XATTR_FILLGRADIENT:
    1850           1 :                     pItem = ((XFillGradientItem*)pItem)->checkForUniqueItem( pNewModel );
    1851           1 :                     break;
    1852             :                 case XATTR_FILLFLOATTRANSPARENCE:
    1853             :                     // allow all kinds of XFillFloatTransparenceItem to be set
    1854           0 :                     pItem = ((XFillFloatTransparenceItem*)pItem)->checkForUniqueItem( pNewModel );
    1855           0 :                     break;
    1856             :                 case XATTR_FILLHATCH:
    1857           0 :                     pItem = ((XFillHatchItem*)pItem)->checkForUniqueItem( pNewModel );
    1858           0 :                     break;
    1859             :                 }
    1860             : 
    1861             :                 // set item
    1862       25779 :                 if( pItem )
    1863             :                 {
    1864       25779 :                     pDestSet->Put(*pItem);
    1865             : 
    1866             :                     // delete item if it was a generated one
    1867       25779 :                     if( pItem != pPoolItem)
    1868          55 :                         delete (SfxPoolItem*)pItem;
    1869             :                 }
    1870             :             }
    1871      615226 :             nWhich = aWhichIter.NextWhich();
    1872        4450 :         }
    1873             :     }
    1874        4450 : }
    1875             : 
    1876             : 
    1877             : 
    1878        2283 : void SdrModel::SetForbiddenCharsTable( rtl::Reference<SvxForbiddenCharactersTable> xForbiddenChars )
    1879             : {
    1880        2283 :     if( mpForbiddenCharactersTable )
    1881           0 :         mpForbiddenCharactersTable->release();
    1882             : 
    1883        2283 :     mpForbiddenCharactersTable = xForbiddenChars.get();
    1884             : 
    1885        2283 :     if( mpForbiddenCharactersTable )
    1886        1952 :         mpForbiddenCharactersTable->acquire();
    1887             : 
    1888        2283 :     ImpSetOutlinerDefaults( pDrawOutliner );
    1889        2283 :     ImpSetOutlinerDefaults( pHitTestOutliner );
    1890        2283 : }
    1891             : 
    1892       40528 : rtl::Reference<SvxForbiddenCharactersTable> SdrModel::GetForbiddenCharsTable() const
    1893             : {
    1894       40528 :     return mpForbiddenCharactersTable;
    1895             : }
    1896             : 
    1897        2123 : void SdrModel::SetCharCompressType( sal_uInt16 nType )
    1898             : {
    1899        2123 :     if( nType != mnCharCompressType )
    1900             :     {
    1901           7 :         mnCharCompressType = nType;
    1902           7 :         ImpSetOutlinerDefaults( pDrawOutliner );
    1903           7 :         ImpSetOutlinerDefaults( pHitTestOutliner );
    1904             :     }
    1905        2123 : }
    1906             : 
    1907         349 : void SdrModel::SetKernAsianPunctuation( bool bEnabled )
    1908             : {
    1909         349 :     if( mbKernAsianPunctuation != bEnabled )
    1910             :     {
    1911           2 :         mbKernAsianPunctuation = bEnabled;
    1912           2 :         ImpSetOutlinerDefaults( pDrawOutliner );
    1913           2 :         ImpSetOutlinerDefaults( pHitTestOutliner );
    1914             :     }
    1915         349 : }
    1916             : 
    1917        1774 : void SdrModel::SetAddExtLeading( bool bEnabled )
    1918             : {
    1919        1774 :     if( mbAddExtLeading != bEnabled )
    1920             :     {
    1921        1771 :         mbAddExtLeading = bEnabled;
    1922        1771 :         ImpSetOutlinerDefaults( pDrawOutliner );
    1923        1771 :         ImpSetOutlinerDefaults( pHitTestOutliner );
    1924             :     }
    1925        1774 : }
    1926             : 
    1927          13 : void SdrModel::ReformatAllTextObjects()
    1928             : {
    1929          13 :     ImpReformatAllTextObjects();
    1930          13 : }
    1931             : 
    1932       16173 : SdrOutliner* SdrModel::createOutliner( sal_uInt16 nOutlinerMode )
    1933             : {
    1934       16173 :     if( NULL == mpOutlinerCache )
    1935         460 :         mpOutlinerCache = new SdrOutlinerCache(this);
    1936             : 
    1937       16173 :     return mpOutlinerCache->createOutliner( nOutlinerMode );
    1938             : }
    1939             : 
    1940       14855 : void SdrModel::disposeOutliner( SdrOutliner* pOutliner )
    1941             : {
    1942       14855 :     if( mpOutlinerCache )
    1943             :     {
    1944       14855 :         mpOutlinerCache->disposeOutliner( pOutliner );
    1945             :     }
    1946             :     else
    1947             :     {
    1948           0 :         delete pOutliner;
    1949             :     }
    1950       14855 : }
    1951             : 
    1952           0 : SvxNumType SdrModel::GetPageNumType() const
    1953             : {
    1954           0 :     return SVX_ARABIC;
    1955             : }
    1956             : 
    1957        3645 : const SdrPage* SdrModel::GetPage(sal_uInt16 nPgNum) const
    1958             : {
    1959             :     DBG_ASSERT(nPgNum < maPages.size(), "SdrModel::GetPage: Access out of range (!)");
    1960        3645 :     return nPgNum < maPages.size() ? maPages[nPgNum] : NULL;
    1961             : }
    1962             : 
    1963       29985 : SdrPage* SdrModel::GetPage(sal_uInt16 nPgNum)
    1964             : {
    1965             :     DBG_ASSERT(nPgNum < maPages.size(), "SdrModel::GetPage: Access out of range (!)");
    1966       29985 :     return nPgNum < maPages.size() ? maPages[nPgNum] : NULL;
    1967             : }
    1968             : 
    1969       21198 : sal_uInt16 SdrModel::GetPageCount() const
    1970             : {
    1971       21198 :     return sal_uInt16(maPages.size());
    1972             : }
    1973             : 
    1974        9810 : void SdrModel::PageListChanged()
    1975             : {
    1976        9810 : }
    1977             : 
    1978         666 : const SdrPage* SdrModel::GetMasterPage(sal_uInt16 nPgNum) const
    1979             : {
    1980             :     DBG_ASSERT(nPgNum < maMaPag.size(), "SdrModel::GetMasterPage: Access out of range (!)");
    1981         666 :     return maMaPag[nPgNum];
    1982             : }
    1983             : 
    1984        2143 : SdrPage* SdrModel::GetMasterPage(sal_uInt16 nPgNum)
    1985             : {
    1986             :     DBG_ASSERT(nPgNum < maMaPag.size(), "SdrModel::GetMasterPage: Access out of range (!)");
    1987        2143 :     return maMaPag[nPgNum];
    1988             : }
    1989             : 
    1990       12713 : sal_uInt16 SdrModel::GetMasterPageCount() const
    1991             : {
    1992       12713 :     return sal_uInt16(maMaPag.size());
    1993             : }
    1994             : 
    1995        4731 : void SdrModel::MasterPageListChanged()
    1996             : {
    1997        4731 : }
    1998             : 
    1999         264 : void SdrModel::SetSdrUndoManager( SfxUndoManager* pUndoManager )
    2000             : {
    2001         264 :     mpImpl->mpUndoManager = pUndoManager;
    2002         264 : }
    2003             : 
    2004           0 : SfxUndoManager* SdrModel::GetSdrUndoManager() const
    2005             : {
    2006           0 :     return mpImpl->mpUndoManager;
    2007             : }
    2008             : 
    2009         676 : SdrUndoFactory& SdrModel::GetSdrUndoFactory() const
    2010             : {
    2011         676 :     if( !mpImpl->mpUndoFactory )
    2012           6 :         mpImpl->mpUndoFactory = new SdrUndoFactory;
    2013         676 :     return *mpImpl->mpUndoFactory;
    2014             : }
    2015             : 
    2016         155 : void SdrModel::SetSdrUndoFactory( SdrUndoFactory* pUndoFactory )
    2017             : {
    2018         155 :     if( pUndoFactory && (pUndoFactory != mpImpl->mpUndoFactory) )
    2019             :     {
    2020         155 :         delete mpImpl->mpUndoFactory;
    2021         155 :         mpImpl->mpUndoFactory = pUndoFactory;
    2022             :     }
    2023         155 : }
    2024             : 
    2025             : namespace
    2026             : {
    2027             :     class theSdrModelUnoTunnelImplementationId : public rtl::Static< UnoTunnelIdInit, theSdrModelUnoTunnelImplementationId > {};
    2028             : }
    2029             : 
    2030        5607 : const ::com::sun::star::uno::Sequence< sal_Int8 >& SdrModel::getUnoTunnelImplementationId()
    2031             : {
    2032        5607 :     return theSdrModelUnoTunnelImplementationId::get().getSeq();
    2033             : }
    2034             : 
    2035             : 
    2036             : 
    2037    19960120 : TYPEINIT1(SdrHint,SfxHint);
    2038             : 
    2039       28717 : SdrHint::SdrHint(SdrHintKind eNewHint)
    2040             : :   mpPage(0L),
    2041             :     mpObj(0L),
    2042             :     mpObjList(0L),
    2043       28717 :     meHint(eNewHint)
    2044             : {
    2045       28717 : }
    2046             : 
    2047      106525 : SdrHint::SdrHint(const SdrObject& rNewObj)
    2048      106525 : :   mpPage(rNewObj.GetPage()),
    2049             :     mpObj(&rNewObj),
    2050      106525 :     mpObjList(rNewObj.GetObjList()),
    2051      319575 :     meHint(HINT_OBJCHG)
    2052             : {
    2053      106525 :     maRectangle = rNewObj.GetLastBoundRect();
    2054      106525 : }
    2055             : 
    2056        7880 : void SdrHint::SetPage(const SdrPage* pNewPage)
    2057             : {
    2058        7880 :     mpPage = pNewPage;
    2059        7880 : }
    2060             : 
    2061           0 : void SdrHint::SetObject(const SdrObject* pNewObj)
    2062             : {
    2063           0 :     mpObj = pNewObj;
    2064           0 : }
    2065             : 
    2066       65644 : void SdrHint::SetKind(SdrHintKind eNewKind)
    2067             : {
    2068       65644 :     meHint = eNewKind;
    2069       65644 : }
    2070             : 
    2071        7243 : const SdrPage* SdrHint::GetPage() const
    2072             : {
    2073        7243 :     return mpPage;
    2074             : }
    2075             : 
    2076      555649 : const SdrObject* SdrHint::GetObject() const
    2077             : {
    2078      555649 :     return mpObj;
    2079             : }
    2080             : 
    2081     5028921 : SdrHintKind SdrHint::GetKind() const
    2082             : {
    2083     5028921 :     return meHint;
    2084             : }
    2085             : 
    2086             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10