LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdotxat.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 165 207 79.7 %
Date: 2014-04-11 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/svdmodel.hxx>
      24             : #include <svx/svdoutl.hxx>
      25             : #include <svx/svdorect.hxx>
      26             : #include <svx/svdocapt.hxx>
      27             : #include <svx/svdetc.hxx>
      28             : #include <editeng/writingmodeitem.hxx>
      29             : #include <editeng/editdata.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      188851 : bool SdrTextObj::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt, bool bWdt) const
      55             : {
      56      188851 :     if (bTextFrame && pModel!=NULL && !rR.IsEmpty())
      57             :     {
      58      170735 :         bool bFitToSize(IsFitToSize());
      59      170735 :         bool bWdtGrow=bWdt && IsAutoGrowWidth();
      60      170735 :         bool bHgtGrow=bHgt && IsAutoGrowHeight();
      61      170735 :         SdrTextAniKind eAniKind=GetTextAniKind();
      62      170735 :         SdrTextAniDirection eAniDir=GetTextAniDirection();
      63      170735 :         bool bScroll=eAniKind==SDRTEXTANI_SCROLL || eAniKind==SDRTEXTANI_ALTERNATE || eAniKind==SDRTEXTANI_SLIDE;
      64      170735 :         bool bHScroll=bScroll && (eAniDir==SDRTEXTANI_LEFT || eAniDir==SDRTEXTANI_RIGHT);
      65      170735 :         bool bVScroll=bScroll && (eAniDir==SDRTEXTANI_UP || eAniDir==SDRTEXTANI_DOWN);
      66      170735 :         if (!bFitToSize && (bWdtGrow || bHgtGrow))
      67             :         {
      68      155190 :             Rectangle aR0(rR);
      69      155190 :             long nHgt=0,nMinHgt=0,nMaxHgt=0;
      70      155190 :             long nWdt=0,nMinWdt=0,nMaxWdt=0;
      71      155190 :             Size aSiz(rR.GetSize()); aSiz.Width()--; aSiz.Height()--;
      72      155190 :             Size aMaxSiz(100000,100000);
      73      155190 :             Size aTmpSiz(pModel->GetMaxObjSize());
      74      155190 :             if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
      75      155190 :             if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
      76      155190 :             if (bWdtGrow)
      77             :             {
      78       71983 :                 nMinWdt=GetMinTextFrameWidth();
      79       71983 :                 nMaxWdt=GetMaxTextFrameWidth();
      80       71983 :                 if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width()) nMaxWdt=aMaxSiz.Width();
      81       71983 :                 if (nMinWdt<=0) nMinWdt=1;
      82       71983 :                 aSiz.Width()=nMaxWdt;
      83             :             }
      84      155190 :             if (bHgtGrow)
      85             :             {
      86      154856 :                 nMinHgt=GetMinTextFrameHeight();
      87      154856 :                 nMaxHgt=GetMaxTextFrameHeight();
      88      154856 :                 if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
      89      154856 :                 if (nMinHgt<=0) nMinHgt=1;
      90      154856 :                 aSiz.Height()=nMaxHgt;
      91             :             }
      92      155190 :             long nHDist=GetTextLeftDistance()+GetTextRightDistance();
      93      155190 :             long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
      94      155190 :             aSiz.Width()-=nHDist;
      95      155190 :             aSiz.Height()-=nVDist;
      96      155190 :             if (aSiz.Width()<2) aSiz.Width()=2;
      97      155190 :             if (aSiz.Height()<2) aSiz.Height()=2;
      98             : 
      99      155190 :             sal_Bool bInEditMode = IsInEditMode();
     100             : 
     101      155190 :             if(!bInEditMode)
     102             :             {
     103      155190 :                 if (bHScroll) aSiz.Width()=0x0FFFFFFF; // don't break ticker text
     104      155190 :                 if (bVScroll) aSiz.Height()=0x0FFFFFFF;
     105             :             }
     106             : 
     107      155190 :             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      155190 :                 Outliner& rOutliner=ImpGetDrawOutliner();
     119      155190 :                 rOutliner.SetPaperSize(aSiz);
     120      155190 :                 rOutliner.SetUpdateMode(true);
     121             :                 // TODO: add the optimization with bPortionInfoChecked etc. here
     122      155190 :                 OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
     123      155190 :                 if ( pOutlinerParaObject != NULL )
     124             :                 {
     125       96203 :                     rOutliner.SetText(*pOutlinerParaObject);
     126       96203 :                     rOutliner.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
     127             :                 }
     128      155190 :                 if (bWdtGrow)
     129             :                 {
     130       71983 :                     Size aSiz2(rOutliner.CalcTextSize());
     131       71983 :                     nWdt=aSiz2.Width()+1; // a little tolerance
     132       71983 :                     if (bHgtGrow) nHgt=aSiz2.Height()+1; // a little tolerance
     133             :                 } else {
     134       83207 :                     nHgt=rOutliner.GetTextHeight()+1; // a little tolerance
     135             :                 }
     136      155190 :                 rOutliner.Clear();
     137             :             }
     138      155190 :             if (nWdt<nMinWdt) nWdt=nMinWdt;
     139      155190 :             if (nWdt>nMaxWdt) nWdt=nMaxWdt;
     140      155190 :             nWdt+=nHDist;
     141      155190 :             if (nWdt<1) nWdt=1; // nHDist may be negative
     142      155190 :             if (nHgt<nMinHgt) nHgt=nMinHgt;
     143      155190 :             if (nHgt>nMaxHgt) nHgt=nMaxHgt;
     144      155190 :             nHgt+=nVDist;
     145      155190 :             if (nHgt<1) nHgt=1; // nVDist may be negative
     146      155190 :             long nWdtGrow=nWdt-(rR.Right()-rR.Left());
     147      155190 :             long nHgtGrow=nHgt-(rR.Bottom()-rR.Top());
     148      155190 :             if (nWdtGrow==0) bWdtGrow=false;
     149      155190 :             if (nHgtGrow==0) bHgtGrow=false;
     150      155190 :             if (bWdtGrow || bHgtGrow) {
     151       75553 :                 if (bWdtGrow) {
     152       33741 :                     SdrTextHorzAdjust eHAdj=GetTextHorizontalAdjust();
     153       33741 :                     if (eHAdj==SDRTEXTHORZADJUST_LEFT) rR.Right()+=nWdtGrow;
     154       31531 :                     else if (eHAdj==SDRTEXTHORZADJUST_RIGHT) rR.Left()-=nWdtGrow;
     155             :                     else {
     156       17858 :                         long nWdtGrow2=nWdtGrow/2;
     157       17858 :                         rR.Left()-=nWdtGrow2;
     158       17858 :                         rR.Right()=rR.Left()+nWdt;
     159             :                     }
     160             :                 }
     161       75553 :                 if (bHgtGrow) {
     162       73619 :                     SdrTextVertAdjust eVAdj=GetTextVerticalAdjust();
     163       73619 :                     if (eVAdj==SDRTEXTVERTADJUST_TOP) rR.Bottom()+=nHgtGrow;
     164       18918 :                     else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM) rR.Top()-=nHgtGrow;
     165             :                     else {
     166       16538 :                         long nHgtGrow2=nHgtGrow/2;
     167       16538 :                         rR.Top()-=nHgtGrow2;
     168       16538 :                         rR.Bottom()=rR.Top()+nHgt;
     169             :                     }
     170             :                 }
     171       75553 :                 if (aGeo.nDrehWink!=0) {
     172           2 :                     Point aD1(rR.TopLeft());
     173           2 :                     aD1-=aR0.TopLeft();
     174           2 :                     Point aD2(aD1);
     175           2 :                     RotatePoint(aD2,Point(),aGeo.nSin,aGeo.nCos);
     176           2 :                     aD2-=aD1;
     177           2 :                     rR.Move(aD2.X(),aD2.Y());
     178             :                 }
     179       75553 :                 return true;
     180             :             }
     181             :         }
     182             :     }
     183      113298 :     return false;
     184             : }
     185             : 
     186      188875 : bool SdrTextObj::NbcAdjustTextFrameWidthAndHeight(bool bHgt, bool bWdt)
     187             : {
     188      188875 :     bool bRet=AdjustTextFrameWidthAndHeight(aRect,bHgt,bWdt);
     189      188875 :     if (bRet) {
     190       75568 :         SetRectsDirty();
     191       75568 :         if (HAS_BASE(SdrRectObj,this)) { // this is a hack
     192       75553 :             ((SdrRectObj*)this)->SetXPolyDirty();
     193             :         }
     194       75568 :         if (HAS_BASE(SdrCaptionObj,this)) { // this is a hack
     195         131 :             ((SdrCaptionObj*)this)->ImpRecalcTail();
     196             :         }
     197             :     }
     198      188875 :     return bRet;
     199             : }
     200             : 
     201          15 : bool SdrTextObj::AdjustTextFrameWidthAndHeight(bool bHgt, bool bWdt)
     202             : {
     203          15 :     Rectangle aNeuRect(aRect);
     204          15 :     bool bRet=AdjustTextFrameWidthAndHeight(aNeuRect,bHgt,bWdt);
     205          15 :     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          15 :     return bRet;
     220             : }
     221             : 
     222       59350 : void SdrTextObj::ImpSetTextStyleSheetListeners()
     223             : {
     224       59350 :     SfxStyleSheetBasePool* pStylePool=pModel!=NULL ? pModel->GetStyleSheetPool() : NULL;
     225       59350 :     if (pStylePool!=NULL)
     226             :     {
     227        7138 :         std::vector<OUString> aStyleNames;
     228        7138 :         OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
     229        7138 :         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        6958 :             const EditTextObject& rTextObj=pOutlinerParaObject->GetTextObject();
     235        6958 :             OUString aStyleName;
     236             :             SfxStyleFamily eStyleFam;
     237        6958 :             sal_Int32 nParaAnz=rTextObj.GetParagraphCount();
     238             : 
     239       16950 :             for(sal_Int32 nParaNum(0); nParaNum < nParaAnz; nParaNum++)
     240             :             {
     241        9992 :                 rTextObj.GetStyleSheet(nParaNum, aStyleName, eStyleFam);
     242             : 
     243        9992 :                 if (!aStyleName.isEmpty())
     244             :                 {
     245        9992 :                     OUStringBuffer aFam;
     246        9992 :                     aFam.append(static_cast<sal_Int32>(eStyleFam));
     247        9992 :                     comphelper::string::padToLength(aFam, 5, ' ');
     248             : 
     249        9992 :                     aStyleName += OUString('|');
     250        9992 :                     aStyleName += aFam.makeStringAndClear();
     251             : 
     252        9992 :                     sal_Bool bFnd(sal_False);
     253        9992 :                     sal_uInt32 nNum(aStyleNames.size());
     254             : 
     255       25076 :                     while(!bFnd && nNum > 0)
     256             :                     {
     257             :                         // we don't want duplicate stylesheets
     258        5092 :                         nNum--;
     259        5092 :                         bFnd = aStyleName == aStyleNames[nNum];
     260             :                     }
     261             : 
     262        9992 :                     if(!bFnd)
     263             :                     {
     264        7756 :                         aStyleNames.push_back(aStyleName);
     265        9992 :                     }
     266             :                 }
     267        6958 :             }
     268             :         }
     269             : 
     270             :         // now convert the strings in the vector from names to StyleSheet*
     271       14276 :         std::set<SfxStyleSheet*> aStyleSheets;
     272       22032 :         while (!aStyleNames.empty()) {
     273        7756 :             OUString aName = aStyleNames.back();
     274        7756 :             aStyleNames.pop_back();
     275             : 
     276       15512 :             OUString aFam = aName.copy(0, aName.getLength() - 6);
     277             : 
     278        7756 :             aFam = aFam.copy(1);
     279        7756 :             aFam = comphelper::string::stripEnd(aFam, ' ');
     280             : 
     281        7756 :             sal_uInt16 nFam = (sal_uInt16)aFam.toInt32();
     282             : 
     283        7756 :             SfxStyleFamily eFam = (SfxStyleFamily)nFam;
     284        7756 :             SfxStyleSheetBase* pStyleBase = pStylePool->Find(aName,eFam);
     285        7756 :             SfxStyleSheet* pStyle = PTR_CAST(SfxStyleSheet,pStyleBase);
     286        7756 :             if (pStyle!=NULL && pStyle!=GetStyleSheet()) {
     287           0 :                 aStyleSheets.insert(pStyle);
     288             :             }
     289        7756 :         }
     290             :         // now remove all superfluous stylesheets
     291        7138 :         sal_uIntPtr nNum=GetBroadcasterCount();
     292       14709 :         while (nNum>0) {
     293         433 :             nNum--;
     294         433 :             SfxBroadcaster* pBroadcast=GetBroadcasterJOE((sal_uInt16)nNum);
     295         433 :             SfxStyleSheet* pStyle=PTR_CAST(SfxStyleSheet,pBroadcast);
     296         433 :             if (pStyle!=NULL && pStyle!=GetStyleSheet()) { // special case for stylesheet of the object
     297         344 :                 if (aStyleSheets.find(pStyle)==aStyleSheets.end()) {
     298         344 :                     EndListening(*pStyle);
     299             :                 }
     300             :             }
     301             :         }
     302             :         // and finally, merge all stylesheets that are contained in aStyles with previous broadcasters
     303        7138 :         for(std::set<SfxStyleSheet*>::const_iterator it = aStyleSheets.begin(); it != aStyleSheets.end(); ++it) {
     304           0 :             SfxStyleSheet* pStyle=*it;
     305             :             // let StartListening see for itself if there's already a listener registered
     306           0 :             StartListening(*pStyle,true);
     307        7138 :         }
     308             :     }
     309       59350 : }
     310             : 
     311             : /**  iterates over the paragraphs of a given SdrObject and removes all
     312             :      hard set character attributes with the which ids contained in the
     313             :      given vector
     314             : */
     315           0 : void SdrTextObj::RemoveOutlinerCharacterAttribs( const std::vector<sal_uInt16>& rCharWhichIds )
     316             : {
     317           0 :     sal_Int32 nText = getTextCount();
     318             : 
     319           0 :     while( --nText >= 0 )
     320             :     {
     321           0 :         SdrText* pText = getText( nText );
     322           0 :         OutlinerParaObject* pOutlinerParaObject = pText ? pText->GetOutlinerParaObject() : 0;
     323             : 
     324           0 :         if(pOutlinerParaObject)
     325             :         {
     326           0 :             Outliner* pOutliner = 0;
     327             : 
     328           0 :             if( pEdtOutl || (pText == getActiveText()) )
     329           0 :                 pOutliner = pEdtOutl;
     330             : 
     331           0 :             if(!pOutliner)
     332             :             {
     333           0 :                 pOutliner = &ImpGetDrawOutliner();
     334           0 :                 pOutliner->SetText(*pOutlinerParaObject);
     335             :             }
     336             : 
     337           0 :             ESelection aSelAll( 0, 0, EE_PARA_ALL, EE_TEXTPOS_ALL );
     338           0 :             std::vector<sal_uInt16>::const_iterator aIter( rCharWhichIds.begin() );
     339           0 :             while( aIter != rCharWhichIds.end() )
     340             :             {
     341           0 :                 pOutliner->RemoveAttribs( aSelAll, false, (*aIter++) );
     342             :             }
     343             : 
     344           0 :             if(!pEdtOutl || (pText != getActiveText()) )
     345             :             {
     346           0 :                 const sal_Int32 nParaCount = pOutliner->GetParagraphCount();
     347           0 :                 OutlinerParaObject* pTemp = pOutliner->CreateParaObject(0, nParaCount);
     348           0 :                 pOutliner->Clear();
     349           0 :                 NbcSetOutlinerParaObjectForText(pTemp, pText);
     350             :             }
     351             :         }
     352             :     }
     353           0 : }
     354             : 
     355       41513 : bool SdrTextObj::HasText() const
     356             : {
     357       41513 :     if( pEdtOutl )
     358           0 :         return HasEditText();
     359             : 
     360       41513 :     OutlinerParaObject* pOPO = GetOutlinerParaObject();
     361             : 
     362       41513 :     bool bHasText = false;
     363       41513 :     if( pOPO )
     364             :     {
     365       29546 :         const EditTextObject& rETO = pOPO->GetTextObject();
     366       29546 :         sal_Int32 nParaCount = rETO.GetParagraphCount();
     367             : 
     368       29546 :         if( nParaCount > 0 )
     369       29546 :             bHasText = (nParaCount > 1) || (!rETO.GetText( 0 ).isEmpty());
     370             :     }
     371             : 
     372       41513 :     return bHasText;
     373             : }
     374             : 
     375             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10