LCOV - code coverage report
Current view: top level - libreoffice/svx/source/svdraw - svdotxat.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 160 208 76.9 %
Date: 2012-12-27 Functions: 5 6 83.3 %
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 <comphelper/string.hxx>
      21             : #include <svl/style.hxx>
      22             : #include <svx/svdotext.hxx>
      23             : #include "svx/svditext.hxx"
      24             : #include <svx/svdmodel.hxx> // for GetMaxObjSize and GetStyleSheetPool
      25             : #include <svx/svdoutl.hxx>
      26             : #include <svx/svdorect.hxx> // for SetDirty at NbcAdjustTextFrameWidthAndHeight
      27             : #include <svx/svdocapt.hxx> // for SetDirty at NbcAdjustTextFrameWidthAndHeight
      28             : #include <svx/svdetc.hxx>
      29             : #include <editeng/writingmodeitem.hxx>
      30             : #include <editeng/editeng.hxx>
      31             : #include <editeng/eeitem.hxx>
      32             : #include <editeng/flditem.hxx>
      33             : #include <svx/sdtfchim.hxx>
      34             : 
      35             : 
      36             : #include <editeng/editview.hxx>
      37             : #include <svl/smplhint.hxx>
      38             : #include <svl/whiter.hxx>
      39             : #include <editeng/outlobj.hxx>
      40             : #include <editeng/outliner.hxx>
      41             : #include <editeng/editobj.hxx>
      42             : #include <editeng/fhgtitem.hxx>
      43             : 
      44             : #include <editeng/charscaleitem.hxx>
      45             : #include <svl/itemiter.hxx>
      46             : #include <editeng/lrspitem.hxx>
      47             : #include <svl/itempool.hxx>
      48             : #include <editeng/numitem.hxx>
      49             : #include <editeng/postitem.hxx>
      50             : 
      51             : #include <set>
      52             : 
      53             : 
      54        9456 : bool SdrTextObj::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt, bool bWdt) const
      55             : {
      56        9456 :     if (bTextFrame && pModel!=NULL && !rR.IsEmpty())
      57             :     {
      58        8111 :         bool bFitToSize(IsFitToSize());
      59        8111 :         bool bWdtGrow=bWdt && IsAutoGrowWidth();
      60        8111 :         bool bHgtGrow=bHgt && IsAutoGrowHeight();
      61        8111 :         SdrTextAniKind eAniKind=GetTextAniKind();
      62        8111 :         SdrTextAniDirection eAniDir=GetTextAniDirection();
      63        8111 :         bool bScroll=eAniKind==SDRTEXTANI_SCROLL || eAniKind==SDRTEXTANI_ALTERNATE || eAniKind==SDRTEXTANI_SLIDE;
      64        8111 :         bool bHScroll=bScroll && (eAniDir==SDRTEXTANI_LEFT || eAniDir==SDRTEXTANI_RIGHT);
      65        8111 :         bool bVScroll=bScroll && (eAniDir==SDRTEXTANI_UP || eAniDir==SDRTEXTANI_DOWN);
      66        8111 :         if (!bFitToSize && (bWdtGrow || bHgtGrow))
      67             :         {
      68        6372 :             Rectangle aR0(rR);
      69        6372 :             long nHgt=0,nMinHgt=0,nMaxHgt=0;
      70        6372 :             long nWdt=0,nMinWdt=0,nMaxWdt=0;
      71        6372 :             Size aSiz(rR.GetSize()); aSiz.Width()--; aSiz.Height()--;
      72        6372 :             Size aMaxSiz(100000,100000);
      73        6372 :             Size aTmpSiz(pModel->GetMaxObjSize());
      74        6372 :             if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
      75        6372 :             if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
      76        6372 :             if (bWdtGrow)
      77             :             {
      78        2142 :                 nMinWdt=GetMinTextFrameWidth();
      79        2142 :                 nMaxWdt=GetMaxTextFrameWidth();
      80        2142 :                 if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width()) nMaxWdt=aMaxSiz.Width();
      81        2142 :                 if (nMinWdt<=0) nMinWdt=1;
      82        2142 :                 aSiz.Width()=nMaxWdt;
      83             :             }
      84        6372 :             if (bHgtGrow)
      85             :             {
      86        6372 :                 nMinHgt=GetMinTextFrameHeight();
      87        6372 :                 nMaxHgt=GetMaxTextFrameHeight();
      88        6372 :                 if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
      89        6372 :                 if (nMinHgt<=0) nMinHgt=1;
      90        6372 :                 aSiz.Height()=nMaxHgt;
      91             :             }
      92        6372 :             long nHDist=GetTextLeftDistance()+GetTextRightDistance();
      93        6372 :             long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
      94        6372 :             aSiz.Width()-=nHDist;
      95        6372 :             aSiz.Height()-=nVDist;
      96        6372 :             if (aSiz.Width()<2) aSiz.Width()=2;
      97        6372 :             if (aSiz.Height()<2) aSiz.Height()=2;
      98             : 
      99        6372 :             sal_Bool bInEditMode = IsInEditMode();
     100             : 
     101        6372 :             if(!bInEditMode)
     102             :             {
     103        6372 :                 if (bHScroll) aSiz.Width()=0x0FFFFFFF; // don't break ticker text
     104        6372 :                 if (bVScroll) aSiz.Height()=0x0FFFFFFF;
     105             :             }
     106             : 
     107        6372 :             if(pEdtOutl)
     108             :             {
     109           0 :                 pEdtOutl->SetMaxAutoPaperSize(aSiz);
     110           0 :                 if (bWdtGrow) {
     111           0 :                     Size aSiz2(pEdtOutl->CalcTextSize());
     112           0 :                     nWdt=aSiz2.Width()+1; // a little tolerance
     113           0 :                     if (bHgtGrow) nHgt=aSiz2.Height()+1; // a little tolerance
     114             :                 } else {
     115           0 :                     nHgt=pEdtOutl->GetTextHeight()+1; // a little tolerance
     116             :                 }
     117             :             } else {
     118        6372 :                 Outliner& rOutliner=ImpGetDrawOutliner();
     119        6372 :                 rOutliner.SetPaperSize(aSiz);
     120        6372 :                 rOutliner.SetUpdateMode(sal_True);
     121             :                 // TODO: add the optimization with bPortionInfoChecked etc. here
     122        6372 :                 OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
     123        6372 :                 if ( pOutlinerParaObject != NULL )
     124             :                 {
     125        4032 :                     rOutliner.SetText(*pOutlinerParaObject);
     126        4032 :                     rOutliner.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
     127             :                 }
     128        6372 :                 if (bWdtGrow)
     129             :                 {
     130        2142 :                     Size aSiz2(rOutliner.CalcTextSize());
     131        2142 :                     nWdt=aSiz2.Width()+1; // a little tolerance
     132        2142 :                     if (bHgtGrow) nHgt=aSiz2.Height()+1; // a little tolerance
     133             :                 } else {
     134        4230 :                     nHgt=rOutliner.GetTextHeight()+1; // a little tolerance
     135             :                 }
     136        6372 :                 rOutliner.Clear();
     137             :             }
     138        6372 :             if (nWdt<nMinWdt) nWdt=nMinWdt;
     139        6372 :             if (nWdt>nMaxWdt) nWdt=nMaxWdt;
     140        6372 :             nWdt+=nHDist;
     141        6372 :             if (nWdt<1) nWdt=1; // nHDist may be negative
     142        6372 :             if (nHgt<nMinHgt) nHgt=nMinHgt;
     143        6372 :             if (nHgt>nMaxHgt) nHgt=nMaxHgt;
     144        6372 :             nHgt+=nVDist;
     145        6372 :             if (nHgt<1) nHgt=1; // nVDist may be negative
     146        6372 :             long nWdtGrow=nWdt-(rR.Right()-rR.Left());
     147        6372 :             long nHgtGrow=nHgt-(rR.Bottom()-rR.Top());
     148        6372 :             if (nWdtGrow==0) bWdtGrow=sal_False;
     149        6372 :             if (nHgtGrow==0) bHgtGrow=sal_False;
     150        6372 :             if (bWdtGrow || bHgtGrow) {
     151        5126 :                 if (bWdtGrow) {
     152        2135 :                     SdrTextHorzAdjust eHAdj=GetTextHorizontalAdjust();
     153        2135 :                     if (eHAdj==SDRTEXTHORZADJUST_LEFT) rR.Right()+=nWdtGrow;
     154        2009 :                     else if (eHAdj==SDRTEXTHORZADJUST_RIGHT) rR.Left()-=nWdtGrow;
     155             :                     else {
     156         820 :                         long nWdtGrow2=nWdtGrow/2;
     157         820 :                         rR.Left()-=nWdtGrow2;
     158         820 :                         rR.Right()=rR.Left()+nWdt;
     159             :                     }
     160             :                 }
     161        5126 :                 if (bHgtGrow) {
     162        5123 :                     SdrTextVertAdjust eVAdj=GetTextVerticalAdjust();
     163        5123 :                     if (eVAdj==SDRTEXTVERTADJUST_TOP) rR.Bottom()+=nHgtGrow;
     164        1297 :                     else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM) rR.Top()-=nHgtGrow;
     165             :                     else {
     166        1286 :                         long nHgtGrow2=nHgtGrow/2;
     167        1286 :                         rR.Top()-=nHgtGrow2;
     168        1286 :                         rR.Bottom()=rR.Top()+nHgt;
     169             :                     }
     170             :                 }
     171        5126 :                 if (aGeo.nDrehWink!=0) {
     172           0 :                     Point aD1(rR.TopLeft());
     173           0 :                     aD1-=aR0.TopLeft();
     174           0 :                     Point aD2(aD1);
     175           0 :                     RotatePoint(aD2,Point(),aGeo.nSin,aGeo.nCos);
     176           0 :                     aD2-=aD1;
     177           0 :                     rR.Move(aD2.X(),aD2.Y());
     178             :                 }
     179        5126 :                 return sal_True;
     180             :             }
     181             :         }
     182             :     }
     183        4330 :     return sal_False;
     184             : }
     185             : 
     186        9494 : bool SdrTextObj::NbcAdjustTextFrameWidthAndHeight(bool bHgt, bool bWdt)
     187             : {
     188        9494 :     bool bRet=AdjustTextFrameWidthAndHeight(aRect,bHgt,bWdt);
     189        9494 :     if (bRet) {
     190        5141 :         SetRectsDirty();
     191        5141 :         if (HAS_BASE(SdrRectObj,this)) { // this is a hack
     192        5126 :             ((SdrRectObj*)this)->SetXPolyDirty();
     193             :         }
     194        5141 :         if (HAS_BASE(SdrCaptionObj,this)) { // this is a hack
     195           8 :             ((SdrCaptionObj*)this)->ImpRecalcTail();
     196             :         }
     197             :     }
     198        9494 :     return bRet;
     199             : }
     200             : 
     201           1 : bool SdrTextObj::AdjustTextFrameWidthAndHeight(bool bHgt, bool bWdt)
     202             : {
     203           1 :     Rectangle aNeuRect(aRect);
     204           1 :     bool bRet=AdjustTextFrameWidthAndHeight(aNeuRect,bHgt,bWdt);
     205           1 :     if (bRet) {
     206           0 :         Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
     207           0 :         aRect=aNeuRect;
     208           0 :         SetRectsDirty();
     209           0 :         if (HAS_BASE(SdrRectObj,this)) { // this is a hack
     210           0 :             ((SdrRectObj*)this)->SetXPolyDirty();
     211             :         }
     212           0 :         if (HAS_BASE(SdrCaptionObj,this)) { // this is a hack
     213           0 :             ((SdrCaptionObj*)this)->ImpRecalcTail();
     214             :         }
     215           0 :         SetChanged();
     216           0 :         BroadcastObjectChange();
     217           0 :         SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
     218             :     }
     219           1 :     return bRet;
     220             : }
     221             : 
     222        3619 : void SdrTextObj::ImpSetTextStyleSheetListeners()
     223             : {
     224        3619 :     SfxStyleSheetBasePool* pStylePool=pModel!=NULL ? pModel->GetStyleSheetPool() : NULL;
     225        3619 :     if (pStylePool!=NULL)
     226             :     {
     227        1500 :         std::vector<XubString*> aStyleNames;
     228        1500 :         OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
     229        1500 :         if (pOutlinerParaObject!=NULL)
     230             :         {
     231             :             // First, we collect all stylesheets contained in the ParaObject in
     232             :             // the container aStyles. The Family is always appended to the name
     233             :             // of the stylesheet.
     234        1421 :             const EditTextObject& rTextObj=pOutlinerParaObject->GetTextObject();
     235        1421 :             XubString aStyleName;
     236             :             SfxStyleFamily eStyleFam;
     237        1421 :             sal_uInt16 nParaAnz=rTextObj.GetParagraphCount();
     238             : 
     239        3305 :             for(sal_uInt16 nParaNum(0); nParaNum < nParaAnz; nParaNum++)
     240             :             {
     241        1884 :                 rTextObj.GetStyleSheet(nParaNum, aStyleName, eStyleFam);
     242             : 
     243        1884 :                 if(aStyleName.Len())
     244             :                 {
     245        1884 :                     OUStringBuffer aFam;
     246        1884 :                     aFam.append(static_cast<sal_Int32>(eStyleFam));
     247        1884 :                     comphelper::string::padToLength(aFam, 5, ' ');
     248             : 
     249        1884 :                     aStyleName += sal_Unicode('|');
     250        1884 :                     aStyleName += aFam.makeStringAndClear();
     251             : 
     252        1884 :                     sal_Bool bFnd(sal_False);
     253        1884 :                     sal_uInt32 nNum(aStyleNames.size());
     254             : 
     255        4649 :                     while(!bFnd && nNum > 0)
     256             :                     {
     257             :                         // we don't want duplicate stylesheets
     258         881 :                         nNum--;
     259         881 :                         bFnd = aStyleName.Equals(*aStyleNames[nNum]);
     260             :                     }
     261             : 
     262        1884 :                     if(!bFnd)
     263             :                     {
     264        1588 :                         aStyleNames.push_back(new XubString(aStyleName));
     265        1884 :                     }
     266             :                 }
     267        1421 :             }
     268             :         }
     269             : 
     270             :         // now convert the strings in the vector from names to StyleSheet*
     271        1500 :         std::set<SfxStyleSheet*> aStyleSheets;
     272        4588 :         while (!aStyleNames.empty()) {
     273        1588 :             XubString* pName=aStyleNames.back();
     274        1588 :             aStyleNames.pop_back();
     275             : 
     276        1588 :             String aFam = pName->Copy(0, pName->Len() - 6);
     277             : 
     278        1588 :             aFam.Erase(0,1);
     279        1588 :             aFam = comphelper::string::stripEnd(aFam, ' ');
     280             : 
     281        1588 :             sal_uInt16 nFam = (sal_uInt16)aFam.ToInt32();
     282             : 
     283        1588 :             SfxStyleFamily eFam=(SfxStyleFamily)nFam;
     284        1588 :             SfxStyleSheetBase* pStyleBase=pStylePool->Find(*pName,eFam);
     285        1588 :             SfxStyleSheet* pStyle=PTR_CAST(SfxStyleSheet,pStyleBase);
     286        1588 :             delete pName;
     287        1588 :             if (pStyle!=NULL && pStyle!=GetStyleSheet()) {
     288           0 :                 aStyleSheets.insert(pStyle);
     289             :             }
     290        1588 :         }
     291             :         // now remove all superfluous stylesheets
     292        1500 :         sal_uIntPtr nNum=GetBroadcasterCount();
     293        3291 :         while (nNum>0) {
     294         291 :             nNum--;
     295         291 :             SfxBroadcaster* pBroadcast=GetBroadcasterJOE((sal_uInt16)nNum);
     296         291 :             SfxStyleSheet* pStyle=PTR_CAST(SfxStyleSheet,pBroadcast);
     297         291 :             if (pStyle!=NULL && pStyle!=GetStyleSheet()) { // special case for stylesheet of the object
     298         240 :                 if (aStyleSheets.find(pStyle)==aStyleSheets.end()) {
     299         240 :                     EndListening(*pStyle);
     300             :                 }
     301             :             }
     302             :         }
     303             :         // and finally, merge all stylesheets that are contained in aStyles with previous broadcasters
     304        1500 :         for(std::set<SfxStyleSheet*>::const_iterator it = aStyleSheets.begin(); it != aStyleSheets.end(); ++it) {
     305           0 :             SfxStyleSheet* pStyle=*it;
     306             :             // let StartListening see for itself if there's already a listener registered
     307           0 :             StartListening(*pStyle,sal_True);
     308        1500 :         }
     309             :     }
     310        3619 : }
     311             : 
     312             : /**  iterates over the paragraphs of a given SdrObject and removes all
     313             :      hard set character attributes with the which ids contained in the
     314             :      given vector
     315             : */
     316           0 : void SdrTextObj::RemoveOutlinerCharacterAttribs( const std::vector<sal_uInt16>& rCharWhichIds )
     317             : {
     318           0 :     sal_Int32 nText = getTextCount();
     319             : 
     320           0 :     while( --nText >= 0 )
     321             :     {
     322           0 :         SdrText* pText = getText( nText );
     323           0 :         OutlinerParaObject* pOutlinerParaObject = pText ? pText->GetOutlinerParaObject() : 0;
     324             : 
     325           0 :         if(pOutlinerParaObject)
     326             :         {
     327           0 :             Outliner* pOutliner = 0;
     328             : 
     329           0 :             if( pEdtOutl || (pText == getActiveText()) )
     330           0 :                 pOutliner = pEdtOutl;
     331             : 
     332           0 :             if(!pOutliner)
     333             :             {
     334           0 :                 pOutliner = &ImpGetDrawOutliner();
     335           0 :                 pOutliner->SetText(*pOutlinerParaObject);
     336             :             }
     337             : 
     338           0 :             ESelection aSelAll( 0, 0, 0xffff, 0xffff );
     339           0 :             std::vector<sal_uInt16>::const_iterator aIter( rCharWhichIds.begin() );
     340           0 :             while( aIter != rCharWhichIds.end() )
     341             :             {
     342           0 :                 pOutliner->RemoveAttribs( aSelAll, false, (*aIter++) );
     343             :             }
     344             : 
     345           0 :             if(!pEdtOutl || (pText != getActiveText()) )
     346             :             {
     347           0 :                 const sal_uInt32 nParaCount = pOutliner->GetParagraphCount();
     348           0 :                 OutlinerParaObject* pTemp = pOutliner->CreateParaObject(0, (sal_uInt16)nParaCount);
     349           0 :                 pOutliner->Clear();
     350           0 :                 NbcSetOutlinerParaObjectForText(pTemp, pText);
     351             :             }
     352             :         }
     353             :     }
     354           0 : }
     355             : 
     356        7460 : bool SdrTextObj::HasText() const
     357             : {
     358        7460 :     if( pEdtOutl )
     359           0 :         return HasEditText();
     360             : 
     361        7460 :     OutlinerParaObject* pOPO = GetOutlinerParaObject();
     362             : 
     363        7460 :     bool bHasText = false;
     364        7460 :     if( pOPO )
     365             :     {
     366        4689 :         const EditTextObject& rETO = pOPO->GetTextObject();
     367        4689 :         sal_uInt16 nParaCount = rETO.GetParagraphCount();
     368             : 
     369        4689 :         if( nParaCount > 0 )
     370        4689 :             bHasText = (nParaCount > 1) || (rETO.GetText( 0 ).Len() != 0);
     371             :     }
     372             : 
     373        7460 :     return bHasText;
     374             : }
     375             : 
     376             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10