LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdotxat.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 207 0.0 %
Date: 2014-04-14 Functions: 0 6 0.0 %
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           0 : bool SdrTextObj::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt, bool bWdt) const
      55             : {
      56           0 :     if (bTextFrame && pModel!=NULL && !rR.IsEmpty())
      57             :     {
      58           0 :         bool bFitToSize(IsFitToSize());
      59           0 :         bool bWdtGrow=bWdt && IsAutoGrowWidth();
      60           0 :         bool bHgtGrow=bHgt && IsAutoGrowHeight();
      61           0 :         SdrTextAniKind eAniKind=GetTextAniKind();
      62           0 :         SdrTextAniDirection eAniDir=GetTextAniDirection();
      63           0 :         bool bScroll=eAniKind==SDRTEXTANI_SCROLL || eAniKind==SDRTEXTANI_ALTERNATE || eAniKind==SDRTEXTANI_SLIDE;
      64           0 :         bool bHScroll=bScroll && (eAniDir==SDRTEXTANI_LEFT || eAniDir==SDRTEXTANI_RIGHT);
      65           0 :         bool bVScroll=bScroll && (eAniDir==SDRTEXTANI_UP || eAniDir==SDRTEXTANI_DOWN);
      66           0 :         if (!bFitToSize && (bWdtGrow || bHgtGrow))
      67             :         {
      68           0 :             Rectangle aR0(rR);
      69           0 :             long nHgt=0,nMinHgt=0,nMaxHgt=0;
      70           0 :             long nWdt=0,nMinWdt=0,nMaxWdt=0;
      71           0 :             Size aSiz(rR.GetSize()); aSiz.Width()--; aSiz.Height()--;
      72           0 :             Size aMaxSiz(100000,100000);
      73           0 :             Size aTmpSiz(pModel->GetMaxObjSize());
      74           0 :             if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
      75           0 :             if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
      76           0 :             if (bWdtGrow)
      77             :             {
      78           0 :                 nMinWdt=GetMinTextFrameWidth();
      79           0 :                 nMaxWdt=GetMaxTextFrameWidth();
      80           0 :                 if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width()) nMaxWdt=aMaxSiz.Width();
      81           0 :                 if (nMinWdt<=0) nMinWdt=1;
      82           0 :                 aSiz.Width()=nMaxWdt;
      83             :             }
      84           0 :             if (bHgtGrow)
      85             :             {
      86           0 :                 nMinHgt=GetMinTextFrameHeight();
      87           0 :                 nMaxHgt=GetMaxTextFrameHeight();
      88           0 :                 if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
      89           0 :                 if (nMinHgt<=0) nMinHgt=1;
      90           0 :                 aSiz.Height()=nMaxHgt;
      91             :             }
      92           0 :             long nHDist=GetTextLeftDistance()+GetTextRightDistance();
      93           0 :             long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
      94           0 :             aSiz.Width()-=nHDist;
      95           0 :             aSiz.Height()-=nVDist;
      96           0 :             if (aSiz.Width()<2) aSiz.Width()=2;
      97           0 :             if (aSiz.Height()<2) aSiz.Height()=2;
      98             : 
      99           0 :             sal_Bool bInEditMode = IsInEditMode();
     100             : 
     101           0 :             if(!bInEditMode)
     102             :             {
     103           0 :                 if (bHScroll) aSiz.Width()=0x0FFFFFFF; // don't break ticker text
     104           0 :                 if (bVScroll) aSiz.Height()=0x0FFFFFFF;
     105             :             }
     106             : 
     107           0 :             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           0 :                 Outliner& rOutliner=ImpGetDrawOutliner();
     119           0 :                 rOutliner.SetPaperSize(aSiz);
     120           0 :                 rOutliner.SetUpdateMode(true);
     121             :                 // TODO: add the optimization with bPortionInfoChecked etc. here
     122           0 :                 OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
     123           0 :                 if ( pOutlinerParaObject != NULL )
     124             :                 {
     125           0 :                     rOutliner.SetText(*pOutlinerParaObject);
     126           0 :                     rOutliner.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
     127             :                 }
     128           0 :                 if (bWdtGrow)
     129             :                 {
     130           0 :                     Size aSiz2(rOutliner.CalcTextSize());
     131           0 :                     nWdt=aSiz2.Width()+1; // a little tolerance
     132           0 :                     if (bHgtGrow) nHgt=aSiz2.Height()+1; // a little tolerance
     133             :                 } else {
     134           0 :                     nHgt=rOutliner.GetTextHeight()+1; // a little tolerance
     135             :                 }
     136           0 :                 rOutliner.Clear();
     137             :             }
     138           0 :             if (nWdt<nMinWdt) nWdt=nMinWdt;
     139           0 :             if (nWdt>nMaxWdt) nWdt=nMaxWdt;
     140           0 :             nWdt+=nHDist;
     141           0 :             if (nWdt<1) nWdt=1; // nHDist may be negative
     142           0 :             if (nHgt<nMinHgt) nHgt=nMinHgt;
     143           0 :             if (nHgt>nMaxHgt) nHgt=nMaxHgt;
     144           0 :             nHgt+=nVDist;
     145           0 :             if (nHgt<1) nHgt=1; // nVDist may be negative
     146           0 :             long nWdtGrow=nWdt-(rR.Right()-rR.Left());
     147           0 :             long nHgtGrow=nHgt-(rR.Bottom()-rR.Top());
     148           0 :             if (nWdtGrow==0) bWdtGrow=false;
     149           0 :             if (nHgtGrow==0) bHgtGrow=false;
     150           0 :             if (bWdtGrow || bHgtGrow) {
     151           0 :                 if (bWdtGrow) {
     152           0 :                     SdrTextHorzAdjust eHAdj=GetTextHorizontalAdjust();
     153           0 :                     if (eHAdj==SDRTEXTHORZADJUST_LEFT) rR.Right()+=nWdtGrow;
     154           0 :                     else if (eHAdj==SDRTEXTHORZADJUST_RIGHT) rR.Left()-=nWdtGrow;
     155             :                     else {
     156           0 :                         long nWdtGrow2=nWdtGrow/2;
     157           0 :                         rR.Left()-=nWdtGrow2;
     158           0 :                         rR.Right()=rR.Left()+nWdt;
     159             :                     }
     160             :                 }
     161           0 :                 if (bHgtGrow) {
     162           0 :                     SdrTextVertAdjust eVAdj=GetTextVerticalAdjust();
     163           0 :                     if (eVAdj==SDRTEXTVERTADJUST_TOP) rR.Bottom()+=nHgtGrow;
     164           0 :                     else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM) rR.Top()-=nHgtGrow;
     165             :                     else {
     166           0 :                         long nHgtGrow2=nHgtGrow/2;
     167           0 :                         rR.Top()-=nHgtGrow2;
     168           0 :                         rR.Bottom()=rR.Top()+nHgt;
     169             :                     }
     170             :                 }
     171           0 :                 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           0 :                 return true;
     180             :             }
     181             :         }
     182             :     }
     183           0 :     return false;
     184             : }
     185             : 
     186           0 : bool SdrTextObj::NbcAdjustTextFrameWidthAndHeight(bool bHgt, bool bWdt)
     187             : {
     188           0 :     bool bRet=AdjustTextFrameWidthAndHeight(aRect,bHgt,bWdt);
     189           0 :     if (bRet) {
     190           0 :         SetRectsDirty();
     191           0 :         if (HAS_BASE(SdrRectObj,this)) { // this is a hack
     192           0 :             ((SdrRectObj*)this)->SetXPolyDirty();
     193             :         }
     194           0 :         if (HAS_BASE(SdrCaptionObj,this)) { // this is a hack
     195           0 :             ((SdrCaptionObj*)this)->ImpRecalcTail();
     196             :         }
     197             :     }
     198           0 :     return bRet;
     199             : }
     200             : 
     201           0 : bool SdrTextObj::AdjustTextFrameWidthAndHeight(bool bHgt, bool bWdt)
     202             : {
     203           0 :     Rectangle aNeuRect(aRect);
     204           0 :     bool bRet=AdjustTextFrameWidthAndHeight(aNeuRect,bHgt,bWdt);
     205           0 :     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           0 :     return bRet;
     220             : }
     221             : 
     222           0 : void SdrTextObj::ImpSetTextStyleSheetListeners()
     223             : {
     224           0 :     SfxStyleSheetBasePool* pStylePool=pModel!=NULL ? pModel->GetStyleSheetPool() : NULL;
     225           0 :     if (pStylePool!=NULL)
     226             :     {
     227           0 :         std::vector<OUString> aStyleNames;
     228           0 :         OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
     229           0 :         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           0 :             const EditTextObject& rTextObj=pOutlinerParaObject->GetTextObject();
     235           0 :             OUString aStyleName;
     236             :             SfxStyleFamily eStyleFam;
     237           0 :             sal_Int32 nParaAnz=rTextObj.GetParagraphCount();
     238             : 
     239           0 :             for(sal_Int32 nParaNum(0); nParaNum < nParaAnz; nParaNum++)
     240             :             {
     241           0 :                 rTextObj.GetStyleSheet(nParaNum, aStyleName, eStyleFam);
     242             : 
     243           0 :                 if (!aStyleName.isEmpty())
     244             :                 {
     245           0 :                     OUStringBuffer aFam;
     246           0 :                     aFam.append(static_cast<sal_Int32>(eStyleFam));
     247           0 :                     comphelper::string::padToLength(aFam, 5, ' ');
     248             : 
     249           0 :                     aStyleName += OUString('|');
     250           0 :                     aStyleName += aFam.makeStringAndClear();
     251             : 
     252           0 :                     sal_Bool bFnd(sal_False);
     253           0 :                     sal_uInt32 nNum(aStyleNames.size());
     254             : 
     255           0 :                     while(!bFnd && nNum > 0)
     256             :                     {
     257             :                         // we don't want duplicate stylesheets
     258           0 :                         nNum--;
     259           0 :                         bFnd = aStyleName == aStyleNames[nNum];
     260             :                     }
     261             : 
     262           0 :                     if(!bFnd)
     263             :                     {
     264           0 :                         aStyleNames.push_back(aStyleName);
     265           0 :                     }
     266             :                 }
     267           0 :             }
     268             :         }
     269             : 
     270             :         // now convert the strings in the vector from names to StyleSheet*
     271           0 :         std::set<SfxStyleSheet*> aStyleSheets;
     272           0 :         while (!aStyleNames.empty()) {
     273           0 :             OUString aName = aStyleNames.back();
     274           0 :             aStyleNames.pop_back();
     275             : 
     276           0 :             OUString aFam = aName.copy(0, aName.getLength() - 6);
     277             : 
     278           0 :             aFam = aFam.copy(1);
     279           0 :             aFam = comphelper::string::stripEnd(aFam, ' ');
     280             : 
     281           0 :             sal_uInt16 nFam = (sal_uInt16)aFam.toInt32();
     282             : 
     283           0 :             SfxStyleFamily eFam = (SfxStyleFamily)nFam;
     284           0 :             SfxStyleSheetBase* pStyleBase = pStylePool->Find(aName,eFam);
     285           0 :             SfxStyleSheet* pStyle = PTR_CAST(SfxStyleSheet,pStyleBase);
     286           0 :             if (pStyle!=NULL && pStyle!=GetStyleSheet()) {
     287           0 :                 aStyleSheets.insert(pStyle);
     288             :             }
     289           0 :         }
     290             :         // now remove all superfluous stylesheets
     291           0 :         sal_uIntPtr nNum=GetBroadcasterCount();
     292           0 :         while (nNum>0) {
     293           0 :             nNum--;
     294           0 :             SfxBroadcaster* pBroadcast=GetBroadcasterJOE((sal_uInt16)nNum);
     295           0 :             SfxStyleSheet* pStyle=PTR_CAST(SfxStyleSheet,pBroadcast);
     296           0 :             if (pStyle!=NULL && pStyle!=GetStyleSheet()) { // special case for stylesheet of the object
     297           0 :                 if (aStyleSheets.find(pStyle)==aStyleSheets.end()) {
     298           0 :                     EndListening(*pStyle);
     299             :                 }
     300             :             }
     301             :         }
     302             :         // and finally, merge all stylesheets that are contained in aStyles with previous broadcasters
     303           0 :         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           0 :         }
     308             :     }
     309           0 : }
     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           0 : bool SdrTextObj::HasText() const
     356             : {
     357           0 :     if( pEdtOutl )
     358           0 :         return HasEditText();
     359             : 
     360           0 :     OutlinerParaObject* pOPO = GetOutlinerParaObject();
     361             : 
     362           0 :     bool bHasText = false;
     363           0 :     if( pOPO )
     364             :     {
     365           0 :         const EditTextObject& rETO = pOPO->GetTextObject();
     366           0 :         sal_Int32 nParaCount = rETO.GetParagraphCount();
     367             : 
     368           0 :         if( nParaCount > 0 )
     369           0 :             bHasText = (nParaCount > 1) || (!rETO.GetText( 0 ).isEmpty());
     370             :     }
     371             : 
     372           0 :     return bHasText;
     373             : }
     374             : 
     375             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10