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

Generated by: LCOV version 1.10