LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdetc.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 143 402 35.6 %
Date: 2014-04-11 Functions: 18 38 47.4 %
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             : #include "sal/config.h"
      21             : 
      22             : #include "editeng/forbiddencharacterstable.hxx"
      23             : #include <com/sun/star/embed/XEmbeddedObject.hpp>
      24             : #include <com/sun/star/embed/EmbedStates.hpp>
      25             : #include "officecfg/Office/Common.hxx"
      26             : #include <svx/svdetc.hxx>
      27             : #include <svx/svdmodel.hxx>
      28             : #include <svx/svdtrans.hxx>
      29             : #include "svx/svdglob.hxx"
      30             : #include "svx/svdstr.hrc"
      31             : #include "svx/svdviter.hxx"
      32             : #include <svx/svdview.hxx>
      33             : #include <svx/svdoutl.hxx>
      34             : #include <vcl/bmpacc.hxx>
      35             : #include <editeng/editdata.hxx>
      36             : #include <editeng/eeitem.hxx>
      37             : #include <svl/itemset.hxx>
      38             : #include <svl/whiter.hxx>
      39             : #include "editeng/fontitem.hxx"
      40             : #include <editeng/colritem.hxx>
      41             : #include <editeng/fhgtitem.hxx>
      42             : #include <svx/xgrad.hxx>
      43             : #include <svx/xfillit0.hxx>
      44             : #include <svx/xflclit.hxx>
      45             : #include <svx/xflhtit.hxx>
      46             : #include <svx/xbtmpit.hxx>
      47             : #include <svx/xflgrit.hxx>
      48             : #include <svx/svdoole2.hxx>
      49             : #include <svl/itempool.hxx>
      50             : #include <unotools/localedatawrapper.hxx>
      51             : #include <com/sun/star/lang/Locale.hpp>
      52             : #include <i18nlangtag/lang.h>
      53             : #include <unotools/syslocale.hxx>
      54             : #include <svx/xflbckit.hxx>
      55             : #include <svx/extrusionbar.hxx>
      56             : #include <svx/fontworkbar.hxx>
      57             : #include <vcl/svapp.hxx>
      58             : #include <vcl/settings.hxx>
      59             : #include <svx/sdr/contact/viewcontact.hxx>
      60             : #include <svx/svdpage.hxx>
      61             : #include <svx/svdotable.hxx>
      62             : #include <svx/sdrhittesthelper.hxx>
      63             : 
      64             : using namespace ::com::sun::star;
      65             : 
      66             : /******************************************************************************
      67             : * Global data of the DrawingEngine
      68             : ******************************************************************************/
      69             : 
      70          74 : SdrGlobalData::SdrGlobalData() :
      71             :     pSysLocale(NULL),
      72             :     pLocaleData(NULL),
      73             :     pOutliner(NULL),
      74             :     pDefaults(NULL),
      75             :     pResMgr(NULL),
      76          74 :     nExchangeFormat(0)
      77             : {
      78             : 
      79          74 :     svx::ExtrusionBar::RegisterInterface();
      80          74 :     svx::FontworkBar::RegisterInterface();
      81          74 : }
      82             : 
      83           0 : const SvtSysLocale*         SdrGlobalData::GetSysLocale()
      84             : {
      85           0 :     if ( !pSysLocale )
      86           0 :         pSysLocale = new SvtSysLocale;
      87           0 :     return pSysLocale;
      88             : }
      89           0 : const LocaleDataWrapper*    SdrGlobalData::GetLocaleData()
      90             : {
      91           0 :     if ( !pLocaleData )
      92           0 :         pLocaleData = GetSysLocale()->GetLocaleDataPtr();
      93           0 :     return pLocaleData;
      94             : }
      95             : 
      96             : 
      97          74 : OLEObjCache::OLEObjCache()
      98          74 : :   std::vector<SdrOle2Obj*>()
      99             : {
     100          74 :     nSize = officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::get();
     101          74 :     pTimer = new AutoTimer();
     102          74 :     Link aLink = LINK(this, OLEObjCache, UnloadCheckHdl);
     103             : 
     104          74 :     pTimer->SetTimeoutHdl(aLink);
     105          74 :     pTimer->SetTimeout(20000);
     106          74 :     pTimer->Start();
     107             : 
     108          74 :     aLink.Call(pTimer);
     109          74 : }
     110             : 
     111           0 : OLEObjCache::~OLEObjCache()
     112             : {
     113           0 :     pTimer->Stop();
     114           0 :     delete pTimer;
     115           0 : }
     116             : 
     117         506 : void OLEObjCache::UnloadOnDemand()
     118             : {
     119         506 :     if ( nSize < size() )
     120             :     {
     121             :         // more objects than configured cache size try to remove objects
     122             :         // of course not the freshly inserted one at nIndex=0
     123           0 :         sal_uIntPtr nCount2 = size();
     124           0 :         sal_uIntPtr nIndex = nCount2-1;
     125           0 :         while( nIndex && nCount2 > nSize )
     126             :         {
     127           0 :             SdrOle2Obj* pUnloadObj = (*this)[nIndex--];
     128           0 :             if ( pUnloadObj )
     129             :             {
     130             :                 try
     131             :                 {
     132             :                     // it is important to get object without reinitialization to avoid reentrance
     133           0 :                     uno::Reference< embed::XEmbeddedObject > xUnloadObj = pUnloadObj->GetObjRef_NoInit();
     134             : 
     135           0 :                     sal_Bool bUnload = SdrOle2Obj::CanUnloadRunningObj( xUnloadObj, pUnloadObj->GetAspect() );
     136             : 
     137             :                     // check whether the object can be unloaded before looking for the parent objects
     138           0 :                     if ( xUnloadObj.is() && bUnload )
     139             :                     {
     140           0 :                         uno::Reference< frame::XModel > xUnloadModel( xUnloadObj->getComponent(), uno::UNO_QUERY );
     141           0 :                         if ( xUnloadModel.is() )
     142             :                         {
     143           0 :                             for ( sal_uIntPtr nCheckInd = 0; nCheckInd < size(); nCheckInd++ )
     144             :                             {
     145           0 :                                 SdrOle2Obj* pCacheObj = (*this)[nCheckInd];
     146           0 :                                 if ( pCacheObj && pCacheObj != pUnloadObj )
     147             :                                 {
     148           0 :                                     uno::Reference< frame::XModel > xParentModel = pCacheObj->GetParentXModel();
     149           0 :                                     if ( xUnloadModel == xParentModel )
     150           0 :                                         bUnload = sal_False; // the object has running embedded objects
     151             :                                 }
     152             :                             }
     153           0 :                         }
     154             :                     }
     155             : 
     156           0 :                     if ( bUnload && UnloadObj(pUnloadObj) )
     157             :                         // object was successfully unloaded
     158           0 :                         nCount2--;
     159             :                 }
     160           0 :                 catch( uno::Exception& )
     161             :                 {}
     162             :             }
     163             :         }
     164             :     }
     165         506 : }
     166             : 
     167        1663 : void OLEObjCache::InsertObj(SdrOle2Obj* pObj)
     168             : {
     169        1663 :     if ( !empty() )
     170             :     {
     171        1628 :         SdrOle2Obj* pExistingObj = front();
     172        1628 :         if ( pObj == pExistingObj )
     173             :             // the object is already on the top, nothing has to be changed
     174        2886 :             return;
     175             :     }
     176             : 
     177             :     // get the old position of the object to know whether it is already in container
     178         220 :     iterator it = std::find( begin(), end(), pObj );
     179         220 :     bool bFound = it != end();
     180             : 
     181         220 :     if( it != end() )
     182          70 :         erase( it );
     183             :     // insert object into first position
     184         220 :     insert(begin(), pObj);
     185             : 
     186         220 :     if ( !bFound )
     187             :     {
     188             :         // a new object was inserted, recalculate the cache
     189         150 :         UnloadOnDemand();
     190             :     }
     191             : }
     192             : 
     193         205 : void OLEObjCache::RemoveObj(SdrOle2Obj* pObj)
     194             : {
     195         205 :     iterator it = std::find( begin(), end(), pObj );
     196         205 :     if( it != end() )
     197         144 :         erase( it );
     198         205 : }
     199             : 
     200           0 : bool OLEObjCache::UnloadObj(SdrOle2Obj* pObj)
     201             : {
     202           0 :     bool bUnloaded = false;
     203           0 :     if (pObj)
     204             :     {
     205             :         //#i80528# The old mechanism is completely useless, only taking into account if
     206             :         // in all views the GrafDraft feature is used. This will nearly never have been the
     207             :         // case since no one ever used this option.
     208             : 
     209             :         // A much better (and working) criteria would be the VOC contact count.
     210             :         // The question is what will happen when i make it work now suddenly? I
     211             :         // will try it for 2.4.
     212           0 :         const sdr::contact::ViewContact& rViewContact = pObj->GetViewContact();
     213           0 :         const bool bVisible(rViewContact.HasViewObjectContacts(true));
     214             : 
     215           0 :         if(!bVisible)
     216             :         {
     217           0 :             bUnloaded = pObj->Unload();
     218             :         }
     219             :     }
     220             : 
     221           0 :     return bUnloaded;
     222             : }
     223             : 
     224         712 : IMPL_LINK(OLEObjCache, UnloadCheckHdl, AutoTimer*, /*pTim*/)
     225             : {
     226         356 :     UnloadOnDemand();
     227         356 :     return 0;
     228             : }
     229             : 
     230             : 
     231             : 
     232           0 : void SdrLinkList::Clear()
     233             : {
     234           0 :     unsigned nAnz=GetLinkCount();
     235           0 :     for (unsigned i=0; i<nAnz; i++) {
     236           0 :         delete aList[i];
     237             :     }
     238           0 :     aList.clear();
     239           0 : }
     240             : 
     241         796 : unsigned SdrLinkList::FindEntry(const Link& rLink) const
     242             : {
     243         796 :     unsigned nAnz=GetLinkCount();
     244        1028 :     for (unsigned i=0; i<nAnz; i++) {
     245         546 :         if (GetLink(i)==rLink) return i;
     246             :     }
     247         482 :     return 0xFFFF;
     248             : }
     249             : 
     250         482 : void SdrLinkList::InsertLink(const Link& rLink, unsigned nPos)
     251             : {
     252         482 :     unsigned nFnd=FindEntry(rLink);
     253         482 :     if (nFnd==0xFFFF) {
     254         482 :         if (rLink.IsSet()) {
     255         482 :             if(nPos==0xFFFF)
     256         482 :                 aList.push_back(new Link(rLink));
     257             :             else
     258           0 :                 aList.insert(aList.begin() + nPos, new Link(rLink));
     259             :         } else {
     260             :             OSL_FAIL("SdrLinkList::InsertLink(): Tried to insert a link that was not set already.");
     261             :         }
     262             :     } else {
     263             :         OSL_FAIL("SdrLinkList::InsertLink(): Link already in place.");
     264             :     }
     265         482 : }
     266             : 
     267         314 : void SdrLinkList::RemoveLink(const Link& rLink)
     268             : {
     269         314 :     unsigned nFnd=FindEntry(rLink);
     270         314 :     if (nFnd!=0xFFFF) {
     271         314 :         Link* pLink = aList[nFnd];
     272         314 :         aList.erase( aList.begin() + nFnd );
     273         314 :         delete pLink;
     274             :     } else {
     275             :         OSL_FAIL("SdrLinkList::RemoveLink(): Link not found.");
     276             :     }
     277         314 : }
     278             : 
     279             : 
     280             : 
     281        3020 : bool GetDraftFillColor(const SfxItemSet& rSet, Color& rCol)
     282             : {
     283        3020 :     XFillStyle eFill=((XFillStyleItem&)rSet.Get(XATTR_FILLSTYLE)).GetValue();
     284        3020 :     bool bRetval = false;
     285             : 
     286        3020 :     switch(eFill)
     287             :     {
     288             :         case XFILL_SOLID:
     289             :         {
     290        1214 :             rCol = ((XFillColorItem&)rSet.Get(XATTR_FILLCOLOR)).GetColorValue();
     291        1214 :             bRetval = true;
     292             : 
     293        1214 :             break;
     294             :         }
     295             :         case XFILL_HATCH:
     296             :         {
     297          13 :             Color aCol1(((XFillHatchItem&)rSet.Get(XATTR_FILLHATCH)).GetHatchValue().GetColor());
     298          13 :             Color aCol2(COL_WHITE);
     299             : 
     300             :             // when hatched background is activated, use object fill color as hatch color
     301          13 :             sal_Bool bFillHatchBackground = ((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue();
     302          13 :             if(bFillHatchBackground)
     303             :             {
     304           0 :                 aCol2 = ((const XFillColorItem&)(rSet.Get(XATTR_FILLCOLOR))).GetColorValue();
     305             :             }
     306             : 
     307          13 :             const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor()));
     308          13 :             rCol = Color(aAverageColor);
     309          13 :             bRetval = true;
     310             : 
     311          13 :             break;
     312             :         }
     313             :         case XFILL_GRADIENT: {
     314          51 :             const XGradient& rGrad=((XFillGradientItem&)rSet.Get(XATTR_FILLGRADIENT)).GetGradientValue();
     315          51 :             Color aCol1(rGrad.GetStartColor());
     316          51 :             Color aCol2(rGrad.GetEndColor());
     317          51 :             const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor()));
     318          51 :             rCol = Color(aAverageColor);
     319          51 :             bRetval = true;
     320             : 
     321          51 :             break;
     322             :         }
     323             :         case XFILL_BITMAP:
     324             :         {
     325         125 :             Bitmap aBitmap(((XFillBitmapItem&)rSet.Get(XATTR_FILLBITMAP)).GetGraphicObject().GetGraphic().GetBitmapEx().GetBitmap());
     326         125 :             const Size aSize(aBitmap.GetSizePixel());
     327         125 :             const sal_uInt32 nWidth = aSize.Width();
     328         125 :             const sal_uInt32 nHeight = aSize.Height();
     329         125 :             BitmapReadAccess* pAccess = aBitmap.AcquireReadAccess();
     330             : 
     331         125 :             if(pAccess && nWidth > 0 && nHeight > 0)
     332             :             {
     333         125 :                 sal_uInt32 nRt(0L);
     334         125 :                 sal_uInt32 nGn(0L);
     335         125 :                 sal_uInt32 nBl(0L);
     336         125 :                 const sal_uInt32 nMaxSteps(8L);
     337         125 :                 const sal_uInt32 nXStep((nWidth > nMaxSteps) ? nWidth / nMaxSteps : 1L);
     338         125 :                 const sal_uInt32 nYStep((nHeight > nMaxSteps) ? nHeight / nMaxSteps : 1L);
     339         125 :                 sal_uInt32 nAnz(0L);
     340             : 
     341        1125 :                 for(sal_uInt32 nY(0L); nY < nHeight; nY += nYStep)
     342             :                 {
     343        9000 :                     for(sal_uInt32 nX(0L); nX < nWidth; nX += nXStep)
     344             :                     {
     345        8000 :                         const BitmapColor& rCol2 = pAccess->GetColor(nY, nX);
     346             : 
     347        8000 :                         nRt += rCol2.GetRed();
     348        8000 :                         nGn += rCol2.GetGreen();
     349        8000 :                         nBl += rCol2.GetBlue();
     350        8000 :                         nAnz++;
     351        8000 :                     }
     352             :                 }
     353             : 
     354         125 :                 nRt /= nAnz;
     355         125 :                 nGn /= nAnz;
     356         125 :                 nBl /= nAnz;
     357             : 
     358         125 :                 rCol = Color(sal_uInt8(nRt), sal_uInt8(nGn), sal_uInt8(nBl));
     359             : 
     360         125 :                 bRetval = true;
     361             :             }
     362             : 
     363         125 :             if(pAccess)
     364             :             {
     365         125 :                 aBitmap.ReleaseAccess(pAccess);
     366             :             }
     367             : 
     368         125 :             break;
     369             :         }
     370        1617 :         default: break;
     371             :     }
     372             : 
     373        3020 :     return bRetval;
     374             : }
     375             : 
     376             : 
     377             : 
     378          71 : SdrEngineDefaults::SdrEngineDefaults():
     379         142 :     aFontName( OutputDevice::GetDefaultFont( DEFAULTFONT_SERIF, LANGUAGE_SYSTEM, DEFAULTFONT_FLAGS_ONLYONE ).GetName() ),
     380             :     eFontFamily(FAMILY_ROMAN),
     381             :     aFontColor(COL_AUTO),
     382             :     nFontHeight(847),             // 847/100mm = ca. 24 Point
     383             :     eMapUnit(MAP_100TH_MM),
     384         142 :     aMapFraction(1,1)
     385             : {
     386          71 : }
     387             : 
     388        8779 : SdrEngineDefaults& SdrEngineDefaults::GetDefaults()
     389             : {
     390        8779 :     SdrGlobalData& rGlobalData=GetSdrGlobalData();
     391        8779 :     if (rGlobalData.pDefaults==NULL) {
     392          71 :         rGlobalData.pDefaults=new SdrEngineDefaults;
     393             :     }
     394        8779 :     return *rGlobalData.pDefaults;
     395             : }
     396             : 
     397             : 
     398             : 
     399       18702 : SdrOutliner* SdrMakeOutliner( sal_uInt16 nOutlinerMode, SdrModel* pModel )
     400             : {
     401       18702 :     SfxItemPool* pPool = &pModel->GetItemPool();
     402       18702 :     SdrOutliner* pOutl = new SdrOutliner( pPool, nOutlinerMode );
     403       18702 :     pOutl->SetEditTextObjectPool( pPool );
     404       18702 :     pOutl->SetStyleSheetPool( (SfxStyleSheetPool*) pModel->GetStyleSheetPool() );
     405       18702 :     pOutl->SetDefTab( pModel->GetDefaultTabulator() );
     406       18702 :     pOutl->SetForbiddenCharsTable( pModel->GetForbiddenCharsTable() );
     407       18702 :     pOutl->SetAsianCompressionMode( pModel->GetCharCompressType() );
     408       18702 :     pOutl->SetKernAsianPunctuation( pModel->IsKernAsianPunctuation() );
     409       18702 :     pOutl->SetAddExtLeading( pModel->IsAddExtLeading() );
     410             : 
     411       18702 :     return pOutl;
     412             : }
     413             : 
     414             : 
     415             : 
     416             : 
     417        1701 : SdrLinkList& ImpGetUserMakeObjHdl()
     418             : {
     419        1701 :     SdrGlobalData& rGlobalData=GetSdrGlobalData();
     420        1701 :     return rGlobalData.aUserMakeObjHdl;
     421             : }
     422             : 
     423         574 : SdrLinkList& ImpGetUserMakeObjUserDataHdl()
     424             : {
     425         574 :     SdrGlobalData& rGlobalData=GetSdrGlobalData();
     426         574 :     return rGlobalData.aUserMakeObjUserDataHdl;
     427             : }
     428             : 
     429             : 
     430             : 
     431        3012 : ResMgr* ImpGetResMgr()
     432             : {
     433        3012 :     SdrGlobalData& rGlobalData = GetSdrGlobalData();
     434             : 
     435        3012 :     if(!rGlobalData.pResMgr)
     436             :     {
     437             :         rGlobalData.pResMgr =
     438          33 :             ResMgr::CreateResMgr( "svx", Application::GetSettings().GetUILanguageTag() );
     439             :     }
     440             : 
     441        3012 :     return rGlobalData.pResMgr;
     442             : }
     443             : 
     444             : 
     445             : 
     446        2828 : OUString ImpGetResStr(sal_uInt16 nResID)
     447             : {
     448        2828 :     return ResId(nResID, *ImpGetResMgr()).toString();
     449             : }
     450             : 
     451             : 
     452             : 
     453             : namespace sdr
     454             : {
     455           0 :     OUString GetResourceString(sal_uInt16 nResID)
     456             :     {
     457           0 :         return ImpGetResStr(nResID);
     458             :     }
     459             : }
     460             : 
     461             : 
     462             : 
     463           0 : bool SearchOutlinerItems(const SfxItemSet& rSet, bool bInklDefaults, bool* pbOnlyEE)
     464             : {
     465           0 :     bool bHas=false;
     466           0 :     bool bOnly=true;
     467           0 :     bool bLookOnly=pbOnlyEE!=NULL;
     468           0 :     SfxWhichIter aIter(rSet);
     469           0 :     sal_uInt16 nWhich=aIter.FirstWhich();
     470           0 :     while (((bLookOnly && bOnly) || !bHas) && nWhich!=0) {
     471             :         // For bInklDefaults, the entire Which range is decisive,
     472             :         // in other cases only the set items are.
     473             :         // Disabled and DontCare are regarded as holes in the Which range.
     474           0 :         SfxItemState eState=rSet.GetItemState(nWhich);
     475           0 :         if ((eState==SFX_ITEM_DEFAULT && bInklDefaults) || eState==SFX_ITEM_SET) {
     476           0 :             if (nWhich<EE_ITEMS_START || nWhich>EE_ITEMS_END) bOnly=false;
     477           0 :             else bHas=true;
     478             :         }
     479           0 :         nWhich=aIter.NextWhich();
     480             :     }
     481           0 :     if (!bHas) bOnly=false;
     482           0 :     if (pbOnlyEE!=NULL) *pbOnlyEE=bOnly;
     483           0 :     return bHas;
     484             : }
     485             : 
     486           0 : sal_uInt16* RemoveWhichRange(const sal_uInt16* pOldWhichTable, sal_uInt16 nRangeBeg, sal_uInt16 nRangeEnd)
     487             : {
     488             :     // Six possible cases (per range):
     489             :     //         [Beg..End]          Range, to delete
     490             :     // [b..e]    [b..e]    [b..e]  Cases 1,3,2: doesn't matter, delete, doesn't matter  + Ranges
     491             :     // [b........e]  [b........e]  Cases 4,5  : shrink range                            | in
     492             :     // [b......................e]  Case  6    : splitting                               + pOldWhichTable
     493           0 :     sal_uInt16 nAnz=0;
     494           0 :     while (pOldWhichTable[nAnz]!=0) nAnz++;
     495           0 :     nAnz++; // nAnz should now be an odd number (0 for end of array)
     496             :     DBG_ASSERT((nAnz&1)==1,"RemoveWhichRange: WhichTable doesn't have an odd number of entries.");
     497           0 :     sal_uInt16 nAlloc=nAnz;
     498             :     // check necessary size of new array
     499           0 :     sal_uInt16 nNum=nAnz-1;
     500           0 :     while (nNum!=0) {
     501           0 :         nNum-=2;
     502           0 :         sal_uInt16 nBeg=pOldWhichTable[nNum];
     503           0 :         sal_uInt16 nEnd=pOldWhichTable[nNum+1];
     504           0 :         if (nEnd<nRangeBeg)  /*nCase=1*/ ;
     505           0 :         else if (nBeg>nRangeEnd) /* nCase=2 */ ;
     506           0 :         else if (nBeg>=nRangeBeg && nEnd<=nRangeEnd) /* nCase=3 */ nAlloc-=2;
     507           0 :         else if (nEnd<=nRangeEnd) /* nCase=4 */;
     508           0 :         else if (nBeg>=nRangeBeg) /* nCase=5*/ ;
     509           0 :         else /* nCase=6 */ nAlloc+=2;
     510             :     }
     511             : 
     512           0 :     sal_uInt16* pNewWhichTable=new sal_uInt16[nAlloc];
     513           0 :     memcpy(pNewWhichTable,pOldWhichTable,nAlloc*sizeof(sal_uInt16));
     514           0 :     pNewWhichTable[nAlloc-1]=0; // in case 3, there's no 0 at the end.
     515             :     // now remove the unwanted ranges
     516           0 :     nNum=nAlloc-1;
     517           0 :     while (nNum!=0) {
     518           0 :         nNum-=2;
     519           0 :         sal_uInt16 nBeg=pNewWhichTable[nNum];
     520           0 :         sal_uInt16 nEnd=pNewWhichTable[nNum+1];
     521           0 :         unsigned nCase=0;
     522           0 :         if (nEnd<nRangeBeg) nCase=1;
     523           0 :         else if (nBeg>nRangeEnd) nCase=2;
     524           0 :         else if (nBeg>=nRangeBeg && nEnd<=nRangeEnd) nCase=3;
     525           0 :         else if (nEnd<=nRangeEnd) nCase=4;
     526           0 :         else if (nBeg>=nRangeBeg) nCase=5;
     527           0 :         else nCase=6;
     528           0 :         switch (nCase) {
     529             :             case 3: {
     530           0 :                 unsigned nTailBytes=(nAnz-(nNum+2))*sizeof(sal_uInt16);
     531           0 :                 memcpy(&pNewWhichTable[nNum],&pNewWhichTable[nNum+2],nTailBytes);
     532           0 :                 nAnz-=2; // remember: array is now smaller
     533           0 :             } break;
     534           0 :             case 4: pNewWhichTable[nNum+1]=nRangeBeg-1; break;
     535           0 :             case 5: pNewWhichTable[nNum]=nRangeEnd+1;     break;
     536             :             case 6: {
     537           0 :                 unsigned nTailBytes=(nAnz-(nNum+2))*sizeof(sal_uInt16);
     538           0 :                 memcpy(&pNewWhichTable[nNum+4],&pNewWhichTable[nNum+2],nTailBytes);
     539           0 :                 nAnz+=2; // remember:array is now larger
     540           0 :                 pNewWhichTable[nNum+2]=nRangeEnd+1;
     541           0 :                 pNewWhichTable[nNum+3]=pNewWhichTable[nNum+1];
     542           0 :                 pNewWhichTable[nNum+1]=nRangeBeg-1;
     543           0 :             } break;
     544             :         } // switch
     545             :     }
     546           0 :     return pNewWhichTable;
     547             : }
     548             : 
     549             : 
     550             : 
     551           0 : SvdProgressInfo::SvdProgressInfo( Link *_pLink )
     552             : {
     553             :     DBG_ASSERT(_pLink!=NULL,"SvdProgressInfo(): No Link stated!");
     554             : 
     555           0 :     pLink = _pLink;
     556           0 :     nSumActionCount = 0;
     557           0 :     nSumCurAction   = 0;
     558             : 
     559           0 :     nObjCount = 0;
     560           0 :     nCurObj   = 0;
     561             : 
     562           0 :     nActionCount = 0;
     563           0 :     nCurAction   = 0;
     564             : 
     565           0 :     nInsertCount = 0;
     566           0 :     nCurInsert   = 0;
     567           0 : }
     568             : 
     569           0 : void SvdProgressInfo::Init( sal_uIntPtr _nSumActionCount, sal_uIntPtr _nObjCount )
     570             : {
     571           0 :     nSumActionCount = _nSumActionCount;
     572           0 :     nObjCount = _nObjCount;
     573           0 : }
     574             : 
     575           0 : bool SvdProgressInfo::ReportActions( sal_uIntPtr nAnzActions )
     576             : {
     577           0 :     nSumCurAction += nAnzActions;
     578           0 :     nCurAction += nAnzActions;
     579           0 :     if(nCurAction > nActionCount)
     580           0 :         nCurAction = nActionCount;
     581             : 
     582           0 :     return pLink->Call(NULL) == 1L;
     583             : }
     584             : 
     585           0 : bool SvdProgressInfo::ReportInserts( sal_uIntPtr nAnzInserts )
     586             : {
     587           0 :     nSumCurAction += nAnzInserts;
     588           0 :     nCurInsert += nAnzInserts;
     589             : 
     590           0 :     return pLink->Call(NULL) == 1L;
     591             : }
     592             : 
     593           0 : bool SvdProgressInfo::ReportRescales( sal_uIntPtr nAnzRescales )
     594             : {
     595           0 :     nSumCurAction += nAnzRescales;
     596           0 :     return pLink->Call(NULL) == 1L;
     597             : }
     598             : 
     599           0 : void SvdProgressInfo::SetActionCount( sal_uIntPtr _nActionCount )
     600             : {
     601           0 :     nActionCount = _nActionCount;
     602           0 : }
     603             : 
     604           0 : void SvdProgressInfo::SetInsertCount( sal_uIntPtr _nInsertCount )
     605             : {
     606           0 :     nInsertCount = _nInsertCount;
     607           0 : }
     608             : 
     609           0 : bool SvdProgressInfo::SetNextObject()
     610             : {
     611           0 :     nActionCount = 0;
     612           0 :     nCurAction   = 0;
     613             : 
     614           0 :     nInsertCount = 0;
     615           0 :     nCurInsert   = 0;
     616             : 
     617           0 :     nCurObj++;
     618           0 :     return ReportActions(0);
     619             : }
     620             : 
     621             : // #i101872# isolate GetTextEditBackgroundColor to tooling; it will anyways only be used as long
     622             : // as text edit is not running on overlay
     623             : 
     624             : namespace
     625             : {
     626           0 :     bool impGetSdrObjListFillColor(
     627             :         const SdrObjList& rList,
     628             :         const Point& rPnt,
     629             :         const SdrPageView& rTextEditPV,
     630             :         const SetOfByte& rVisLayers,
     631             :         Color& rCol)
     632             :     {
     633           0 :         if(!rList.GetModel())
     634           0 :             return false;
     635             : 
     636           0 :         bool bRet(false);
     637           0 :         bool bMaster(rList.GetPage() ? rList.GetPage()->IsMasterPage() : false);
     638             : 
     639           0 :         for(sal_uIntPtr no(rList.GetObjCount()); !bRet && no > 0; )
     640             :         {
     641           0 :             no--;
     642           0 :             SdrObject* pObj = rList.GetObj(no);
     643           0 :             SdrObjList* pOL = pObj->GetSubList();
     644             : 
     645           0 :             if(pOL)
     646             :             {
     647             :                 // group object
     648           0 :                 bRet = impGetSdrObjListFillColor(*pOL, rPnt, rTextEditPV, rVisLayers, rCol);
     649             :             }
     650             :             else
     651             :             {
     652           0 :                 SdrTextObj* pText = dynamic_cast< SdrTextObj * >(pObj);
     653             : 
     654             :                 // Exclude zero master page object (i.e. background shape) from color query
     655           0 :                 if(pText
     656           0 :                     && pObj->IsClosedObj()
     657           0 :                     && (!bMaster || (!pObj->IsNotVisibleAsMaster() && 0 != no))
     658           0 :                     && pObj->GetCurrentBoundRect().IsInside(rPnt)
     659           0 :                     && !pText->IsHideContour()
     660           0 :                     && SdrObjectPrimitiveHit(*pObj, rPnt, 0, rTextEditPV, &rVisLayers, false))
     661             :                 {
     662           0 :                     bRet = GetDraftFillColor(pObj->GetMergedItemSet(), rCol);
     663             :                 }
     664             :             }
     665             :         }
     666             : 
     667           0 :         return bRet;
     668             :     }
     669             : 
     670           0 :     bool impGetSdrPageFillColor(
     671             :         const SdrPage& rPage,
     672             :         const Point& rPnt,
     673             :         const SdrPageView& rTextEditPV,
     674             :         const SetOfByte& rVisLayers,
     675             :         Color& rCol,
     676             :         bool bSkipBackgroundShape)
     677             :     {
     678           0 :         if(!rPage.GetModel())
     679           0 :             return false;
     680             : 
     681           0 :         bool bRet(impGetSdrObjListFillColor(rPage, rPnt, rTextEditPV, rVisLayers, rCol));
     682             : 
     683           0 :         if(!bRet && !rPage.IsMasterPage())
     684             :         {
     685           0 :             if(rPage.TRG_HasMasterPage())
     686             :             {
     687           0 :                 SetOfByte aSet(rVisLayers);
     688           0 :                 aSet &= rPage.TRG_GetMasterPageVisibleLayers();
     689           0 :                 SdrPage& rMasterPage = rPage.TRG_GetMasterPage();
     690             : 
     691             :                 // Don't fall back to background shape on
     692             :                 // master pages. This is later handled by
     693             :                 // GetBackgroundColor, and is necessary to cater for
     694             :                 // the silly ordering: 1. shapes, 2. master page
     695             :                 // shapes, 3. page background, 4. master page
     696             :                 // background.
     697           0 :                 bRet = impGetSdrPageFillColor(rMasterPage, rPnt, rTextEditPV, aSet, rCol, true);
     698             :             }
     699             :         }
     700             : 
     701             :         // Only now determine background color from background shapes
     702           0 :         if(!bRet && !bSkipBackgroundShape)
     703             :         {
     704           0 :             rCol = rPage.GetPageBackgroundColor();
     705           0 :             return true;
     706             :         }
     707             : 
     708           0 :         return bRet;
     709             :     }
     710             : 
     711           0 :     Color impCalcBackgroundColor(
     712             :         const Rectangle& rArea,
     713             :         const SdrPageView& rTextEditPV,
     714             :         const SdrPage& rPage)
     715             :     {
     716           0 :         svtools::ColorConfig aColorConfig;
     717           0 :         Color aBackground(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
     718           0 :         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     719             : 
     720           0 :         if(!rStyleSettings.GetHighContrastMode())
     721             :         {
     722             :             // search in page
     723           0 :             const sal_uInt16 SPOTCOUNT(5);
     724           0 :             Point aSpotPos[SPOTCOUNT];
     725           0 :             Color aSpotColor[SPOTCOUNT];
     726           0 :             sal_uIntPtr nHeight( rArea.GetSize().Height() );
     727           0 :             sal_uIntPtr nWidth( rArea.GetSize().Width() );
     728           0 :             sal_uIntPtr nWidth14  = nWidth / 4;
     729           0 :             sal_uIntPtr nHeight14 = nHeight / 4;
     730           0 :             sal_uIntPtr nWidth34  = ( 3 * nWidth ) / 4;
     731           0 :             sal_uIntPtr nHeight34 = ( 3 * nHeight ) / 4;
     732             : 
     733             :             sal_uInt16 i;
     734           0 :             for ( i = 0; i < SPOTCOUNT; i++ )
     735             :             {
     736             :                 // five spots are used
     737           0 :                 switch ( i )
     738             :                 {
     739             :                     case 0 :
     740             :                     {
     741             :                         // Center-Spot
     742           0 :                         aSpotPos[i] = rArea.Center();
     743             :                     }
     744           0 :                     break;
     745             : 
     746             :                     case 1 :
     747             :                     {
     748             :                         // TopLeft-Spot
     749           0 :                         aSpotPos[i] = rArea.TopLeft();
     750           0 :                         aSpotPos[i].X() += nWidth14;
     751           0 :                         aSpotPos[i].Y() += nHeight14;
     752             :                     }
     753           0 :                     break;
     754             : 
     755             :                     case 2 :
     756             :                     {
     757             :                         // TopRight-Spot
     758           0 :                         aSpotPos[i] = rArea.TopLeft();
     759           0 :                         aSpotPos[i].X() += nWidth34;
     760           0 :                         aSpotPos[i].Y() += nHeight14;
     761             :                     }
     762           0 :                     break;
     763             : 
     764             :                     case 3 :
     765             :                     {
     766             :                         // BottomLeft-Spot
     767           0 :                         aSpotPos[i] = rArea.TopLeft();
     768           0 :                         aSpotPos[i].X() += nWidth14;
     769           0 :                         aSpotPos[i].Y() += nHeight34;
     770             :                     }
     771           0 :                     break;
     772             : 
     773             :                     case 4 :
     774             :                     {
     775             :                         // BottomRight-Spot
     776           0 :                         aSpotPos[i] = rArea.TopLeft();
     777           0 :                         aSpotPos[i].X() += nWidth34;
     778           0 :                         aSpotPos[i].Y() += nHeight34;
     779             :                     }
     780           0 :                     break;
     781             : 
     782             :                 }
     783             : 
     784           0 :                 aSpotColor[i] = Color( COL_WHITE );
     785           0 :                 impGetSdrPageFillColor(rPage, aSpotPos[i], rTextEditPV, rTextEditPV.GetVisibleLayers(), aSpotColor[i], false);
     786             :             }
     787             : 
     788             :             sal_uInt16 aMatch[SPOTCOUNT];
     789             : 
     790           0 :             for ( i = 0; i < SPOTCOUNT; i++ )
     791             :             {
     792             :                 // were same spot colors found?
     793           0 :                 aMatch[i] = 0;
     794             : 
     795           0 :                 for ( sal_uInt16 j = 0; j < SPOTCOUNT; j++ )
     796             :                 {
     797           0 :                     if( j != i )
     798             :                     {
     799           0 :                         if( aSpotColor[i] == aSpotColor[j] )
     800             :                         {
     801           0 :                             aMatch[i]++;
     802             :                         }
     803             :                     }
     804             :                 }
     805             :             }
     806             : 
     807             :             // highest weight to center spot
     808           0 :             aBackground = aSpotColor[0];
     809             : 
     810           0 :             for ( sal_uInt16 nMatchCount = SPOTCOUNT - 1; nMatchCount > 1; nMatchCount-- )
     811             :             {
     812             :                 // which spot color was found most?
     813           0 :                 for ( i = 0; i < SPOTCOUNT; i++ )
     814             :                 {
     815           0 :                     if( aMatch[i] == nMatchCount )
     816             :                     {
     817           0 :                         aBackground = aSpotColor[i];
     818           0 :                         nMatchCount = 1;   // break outer for-loop
     819           0 :                         break;
     820             :                     }
     821             :                 }
     822             :             }
     823             :         }
     824             : 
     825           0 :         return aBackground;
     826             :     }
     827             : } // end of anonymous namespace
     828             : 
     829           0 : Color GetTextEditBackgroundColor(const SdrObjEditView& rView)
     830             : {
     831           0 :     svtools::ColorConfig aColorConfig;
     832           0 :     Color aBackground(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
     833           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     834             : 
     835           0 :     if(!rStyleSettings.GetHighContrastMode())
     836             :     {
     837           0 :         bool bFound(false);
     838           0 :         SdrTextObj* pText = dynamic_cast< SdrTextObj * >(rView.GetTextEditObject());
     839             : 
     840           0 :         if(pText && pText->IsClosedObj())
     841             :         {
     842           0 :             ::sdr::table::SdrTableObj* pTable = dynamic_cast< ::sdr::table::SdrTableObj * >( pText );
     843             : 
     844           0 :             if( pTable )
     845           0 :                 bFound = GetDraftFillColor(pTable->GetActiveCellItemSet(), aBackground );
     846             : 
     847           0 :             if( !bFound )
     848           0 :                 bFound=GetDraftFillColor(pText->GetMergedItemSet(), aBackground);
     849             :         }
     850             : 
     851           0 :         if(!bFound && pText)
     852             :         {
     853           0 :             SdrPageView* pTextEditPV = rView.GetTextEditPageView();
     854             : 
     855           0 :             if(pTextEditPV)
     856             :             {
     857           0 :                 Point aPvOfs(pText->GetTextEditOffset());
     858           0 :                 const SdrPage* pPg = pTextEditPV->GetPage();
     859             : 
     860           0 :                 if(pPg)
     861             :                 {
     862           0 :                     Rectangle aSnapRect( pText->GetSnapRect() );
     863           0 :                     aSnapRect.Move(aPvOfs.X(), aPvOfs.Y());
     864             : 
     865           0 :                     return impCalcBackgroundColor(aSnapRect, *pTextEditPV, *pPg);
     866             :                 }
     867             :             }
     868             :         }
     869             :     }
     870             : 
     871           0 :     return aBackground;
     872             : }
     873             : 
     874             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10