LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdotxed.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 173 0.0 %
Date: 2012-08-25 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 244 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <svx/svdotext.hxx>
      31                 :            : #include "svx/svditext.hxx"
      32                 :            : #include <svx/svdmodel.hxx> // for GetMaxObjSize
      33                 :            : #include <svx/svdoutl.hxx>
      34                 :            : #include <editeng/outliner.hxx>
      35                 :            : #include <editeng/editstat.hxx>
      36                 :            : #include <svl/itemset.hxx>
      37                 :            : #include <editeng/eeitem.hxx>
      38                 :            : #include <svx/sdtfchim.hxx>
      39                 :            : 
      40                 :            : 
      41                 :          0 : bool SdrTextObj::HasTextEdit() const
      42                 :            : {
      43                 :            :     // linked text objects may be changed (no automatic reload)
      44                 :          0 :     return true;
      45                 :            : }
      46                 :            : 
      47                 :          0 : sal_Bool SdrTextObj::BegTextEdit(SdrOutliner& rOutl)
      48                 :            : {
      49         [ #  # ]:          0 :     if (pEdtOutl!=NULL) return sal_False; // Textedit might already run in another View!
      50                 :          0 :     pEdtOutl=&rOutl;
      51                 :            : 
      52                 :          0 :     mbInEditMode = sal_True;
      53                 :            : 
      54                 :          0 :     sal_uInt16 nOutlinerMode = OUTLINERMODE_OUTLINEOBJECT;
      55         [ #  # ]:          0 :     if ( !IsOutlText() )
      56                 :          0 :         nOutlinerMode = OUTLINERMODE_TEXTOBJECT;
      57                 :          0 :     rOutl.Init( nOutlinerMode );
      58                 :          0 :     rOutl.SetRefDevice( pModel->GetRefDevice() );
      59                 :            : 
      60                 :          0 :     bool bFitToSize(IsFitToSize());
      61                 :          0 :     bool bContourFrame=IsContourTextFrame();
      62                 :          0 :     ImpSetTextEditParams();
      63                 :            : 
      64         [ #  # ]:          0 :     if (!bContourFrame) {
      65                 :          0 :         sal_uIntPtr nStat=rOutl.GetControlWord();
      66                 :          0 :         nStat|=EE_CNTRL_AUTOPAGESIZE;
      67 [ #  # ][ #  # ]:          0 :         if (bFitToSize || IsAutoFit())
                 [ #  # ]
      68                 :          0 :             nStat|=EE_CNTRL_STRETCHING;
      69                 :            :         else
      70                 :          0 :             nStat&=~EE_CNTRL_STRETCHING;
      71                 :          0 :         rOutl.SetControlWord(nStat);
      72                 :            :     }
      73                 :            : 
      74                 :          0 :     OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
      75         [ #  # ]:          0 :     if(pOutlinerParaObject!=NULL)
      76                 :            :     {
      77                 :          0 :         rOutl.SetText(*GetOutlinerParaObject());
      78                 :          0 :         rOutl.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
      79                 :            :     }
      80                 :            : 
      81                 :            :     // if necessary, set frame attributes for the first (new) paragraph of the
      82                 :            :     // outliner
      83         [ #  # ]:          0 :     if( !HasTextImpl( &rOutl ) )
      84                 :            :     {
      85                 :            :         // Outliner has no text so we must set some
      86                 :            :         // empty text so the outliner initialise itself
      87 [ #  # ][ #  # ]:          0 :         rOutl.SetText( String(), rOutl.GetParagraph( 0 ) );
         [ #  # ][ #  # ]
      88                 :            : 
      89 [ #  # ][ #  # ]:          0 :         if(GetStyleSheet())
      90 [ #  # ][ #  # ]:          0 :             rOutl.SetStyleSheet( 0, GetStyleSheet());
      91                 :            : 
      92                 :            :         // When setting the "hard" attributes for first paragraph, the Parent
      93                 :            :         // pOutlAttr (i. e. the template) has to be removed temporarily. Else,
      94                 :            :         // at SetParaAttribs(), all attributes contained in the parent become
      95                 :            :         // attributed hard to the paragraph.
      96         [ #  # ]:          0 :         const SfxItemSet& rSet = GetObjectItemSet();
      97         [ #  # ]:          0 :         SfxItemSet aFilteredSet(*rSet.GetPool(), EE_ITEMS_START, EE_ITEMS_END);
      98         [ #  # ]:          0 :         aFilteredSet.Put(rSet);
      99 [ #  # ][ #  # ]:          0 :         rOutl.SetParaAttribs(0, aFilteredSet);
     100                 :            :     }
     101         [ #  # ]:          0 :     if (bFitToSize)
     102                 :            :     {
     103         [ #  # ]:          0 :         Rectangle aAnchorRect;
     104         [ #  # ]:          0 :         Rectangle aTextRect;
     105                 :            :         TakeTextRect(rOutl, aTextRect, sal_False,
     106         [ #  # ]:          0 :             &aAnchorRect);
     107         [ #  # ]:          0 :         Fraction aFitXKorreg(1,1);
     108 [ #  # ][ #  # ]:          0 :         ImpSetCharStretching(rOutl,aTextRect.GetSize(),aAnchorRect.GetSize(),aFitXKorreg);
                 [ #  # ]
     109                 :            :     }
     110         [ #  # ]:          0 :     else if (IsAutoFit())
     111                 :            :     {
     112                 :          0 :         ImpAutoFitText(rOutl);
     113                 :            :     }
     114                 :            : 
     115         [ #  # ]:          0 :     if(pOutlinerParaObject)
     116                 :            :     {
     117 [ #  # ][ #  # ]:          0 :         if(aGeo.nDrehWink || IsFontwork())
                 [ #  # ]
     118                 :            :         {
     119                 :            :             // only repaint here, no real objectchange
     120                 :          0 :             BroadcastObjectChange();
     121                 :            :         }
     122                 :            :     }
     123                 :            : 
     124                 :          0 :     rOutl.UpdateFields();
     125                 :          0 :     rOutl.ClearModifyFlag();
     126                 :            : 
     127                 :          0 :     return sal_True;
     128                 :            : }
     129                 :            : 
     130                 :          0 : void SdrTextObj::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin) const
     131                 :            : {
     132         [ #  # ]:          0 :     bool bFitToSize(IsFitToSize());
     133                 :          0 :     Size aPaperMin,aPaperMax;
     134         [ #  # ]:          0 :     Rectangle aViewInit;
     135         [ #  # ]:          0 :     TakeTextAnchorRect(aViewInit);
     136         [ #  # ]:          0 :     if (aGeo.nDrehWink!=0) {
     137         [ #  # ]:          0 :         Point aCenter(aViewInit.Center());
     138                 :          0 :         aCenter-=aViewInit.TopLeft();
     139                 :          0 :         Point aCenter0(aCenter);
     140                 :          0 :         RotatePoint(aCenter,Point(),aGeo.nSin,aGeo.nCos);
     141                 :          0 :         aCenter-=aCenter0;
     142         [ #  # ]:          0 :         aViewInit.Move(aCenter.X(),aCenter.Y());
     143                 :            :     }
     144         [ #  # ]:          0 :     Size aAnkSiz(aViewInit.GetSize());
     145                 :          0 :     aAnkSiz.Width()--; aAnkSiz.Height()--; // because GetSize() adds 1
     146                 :          0 :     Size aMaxSiz(1000000,1000000);
     147         [ #  # ]:          0 :     if (pModel!=NULL) {
     148                 :          0 :         Size aTmpSiz(pModel->GetMaxObjSize());
     149         [ #  # ]:          0 :         if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
     150         [ #  # ]:          0 :         if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
     151                 :            :     }
     152                 :            : 
     153                 :            :     // Done earlier since used in else tree below
     154         [ #  # ]:          0 :     SdrTextHorzAdjust eHAdj(GetTextHorizontalAdjust());
     155         [ #  # ]:          0 :     SdrTextVertAdjust eVAdj(GetTextVerticalAdjust());
     156                 :            : 
     157         [ #  # ]:          0 :     if(IsTextFrame())
     158                 :            :     {
     159         [ #  # ]:          0 :         long nMinWdt=GetMinTextFrameWidth();
     160         [ #  # ]:          0 :         long nMinHgt=GetMinTextFrameHeight();
     161         [ #  # ]:          0 :         long nMaxWdt=GetMaxTextFrameWidth();
     162         [ #  # ]:          0 :         long nMaxHgt=GetMaxTextFrameHeight();
     163         [ #  # ]:          0 :         if (nMinWdt<1) nMinWdt=1;
     164         [ #  # ]:          0 :         if (nMinHgt<1) nMinHgt=1;
     165         [ #  # ]:          0 :         if (!bFitToSize) {
     166 [ #  # ][ #  # ]:          0 :             if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width())  nMaxWdt=aMaxSiz.Width();
                 [ #  # ]
     167 [ #  # ][ #  # ]:          0 :             if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
                 [ #  # ]
     168 [ #  # ][ #  # ]:          0 :             if (!IsAutoGrowWidth() ) { nMaxWdt=aAnkSiz.Width();  nMinWdt=nMaxWdt; }
     169 [ #  # ][ #  # ]:          0 :             if (!IsAutoGrowHeight()) { nMaxHgt=aAnkSiz.Height(); nMinHgt=nMaxHgt; }
     170         [ #  # ]:          0 :             SdrTextAniKind      eAniKind=GetTextAniKind();
     171         [ #  # ]:          0 :             SdrTextAniDirection eAniDirection=GetTextAniDirection();
     172                 :            : 
     173                 :          0 :             sal_Bool bInEditMode = IsInEditMode();
     174                 :            : 
     175 [ #  # ][ #  # ]:          0 :             if (!bInEditMode && (eAniKind==SDRTEXTANI_SCROLL || eAniKind==SDRTEXTANI_ALTERNATE || eAniKind==SDRTEXTANI_SLIDE))
         [ #  # ][ #  # ]
     176                 :            :             {
     177                 :            :                 // ticker text uses an unlimited paper size
     178 [ #  # ][ #  # ]:          0 :                 if (eAniDirection==SDRTEXTANI_LEFT || eAniDirection==SDRTEXTANI_RIGHT) nMaxWdt=1000000;
     179 [ #  # ][ #  # ]:          0 :                 if (eAniDirection==SDRTEXTANI_UP || eAniDirection==SDRTEXTANI_DOWN) nMaxHgt=1000000;
     180                 :            :             }
     181                 :          0 :             aPaperMax.Width()=nMaxWdt;
     182                 :          0 :             aPaperMax.Height()=nMaxHgt;
     183                 :            :         } else {
     184                 :          0 :             aPaperMax=aMaxSiz;
     185                 :            :         }
     186                 :          0 :         aPaperMin.Width()=nMinWdt;
     187                 :          0 :         aPaperMin.Height()=nMinHgt;
     188                 :            :     }
     189                 :            :     else
     190                 :            :     {
     191                 :            :         // aPaperMin needs to be set to object's size if full width is activated
     192                 :            :         // for hor or ver writing respectively
     193 [ #  # ][ #  # ]:          0 :         if((SDRTEXTHORZADJUST_BLOCK == eHAdj && !IsVerticalWriting())
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     194         [ #  # ]:          0 :             || (SDRTEXTVERTADJUST_BLOCK == eVAdj && IsVerticalWriting()))
     195                 :            :         {
     196                 :          0 :             aPaperMin = aAnkSiz;
     197                 :            :         }
     198                 :            : 
     199                 :          0 :         aPaperMax=aMaxSiz;
     200                 :            :     }
     201                 :            : 
     202         [ #  # ]:          0 :     if (pViewMin!=NULL) {
     203                 :          0 :         *pViewMin=aViewInit;
     204                 :            : 
     205                 :          0 :         long nXFree=aAnkSiz.Width()-aPaperMin.Width();
     206         [ #  # ]:          0 :         if (eHAdj==SDRTEXTHORZADJUST_LEFT) pViewMin->Right()-=nXFree;
     207         [ #  # ]:          0 :         else if (eHAdj==SDRTEXTHORZADJUST_RIGHT) pViewMin->Left()+=nXFree;
     208                 :          0 :         else { pViewMin->Left()+=nXFree/2; pViewMin->Right()=pViewMin->Left()+aPaperMin.Width(); }
     209                 :            : 
     210                 :          0 :         long nYFree=aAnkSiz.Height()-aPaperMin.Height();
     211         [ #  # ]:          0 :         if (eVAdj==SDRTEXTVERTADJUST_TOP) pViewMin->Bottom()-=nYFree;
     212         [ #  # ]:          0 :         else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM) pViewMin->Top()+=nYFree;
     213                 :          0 :         else { pViewMin->Top()+=nYFree/2; pViewMin->Bottom()=pViewMin->Top()+aPaperMin.Height(); }
     214                 :            :     }
     215                 :            : 
     216                 :            :     // PaperSize should grow automatically in most cases
     217 [ #  # ][ #  # ]:          0 :     if(IsVerticalWriting())
     218                 :          0 :         aPaperMin.Width() = 0;
     219                 :            :     else
     220                 :          0 :         aPaperMin.Height() = 0;
     221                 :            : 
     222 [ #  # ][ #  # ]:          0 :     if(eHAdj!=SDRTEXTHORZADJUST_BLOCK || bFitToSize) {
     223                 :          0 :         aPaperMin.Width()=0;
     224                 :            :     }
     225                 :            : 
     226                 :            :     // For complete vertical adjustment support, set paper min height to 0, here.
     227 [ #  # ][ #  # ]:          0 :     if(SDRTEXTVERTADJUST_BLOCK != eVAdj || bFitToSize)
     228                 :            :     {
     229                 :          0 :         aPaperMin.Height() = 0;
     230                 :            :     }
     231                 :            : 
     232         [ #  # ]:          0 :     if (pPaperMin!=NULL) *pPaperMin=aPaperMin;
     233         [ #  # ]:          0 :     if (pPaperMax!=NULL) *pPaperMax=aPaperMax;
     234         [ #  # ]:          0 :     if (pViewInit!=NULL) *pViewInit=aViewInit;
     235                 :          0 : }
     236                 :            : 
     237                 :          0 : void SdrTextObj::EndTextEdit(SdrOutliner& rOutl)
     238                 :            : {
     239         [ #  # ]:          0 :     if(rOutl.IsModified())
     240                 :            :     {
     241                 :          0 :         OutlinerParaObject* pNewText = NULL;
     242                 :            : 
     243         [ #  # ]:          0 :         if(HasTextImpl( &rOutl ) )
     244                 :            :         {
     245                 :            :             // to make the gray field background vanish again
     246                 :          0 :             rOutl.UpdateFields();
     247                 :            : 
     248                 :          0 :             sal_uInt16 nParaAnz = static_cast< sal_uInt16 >( rOutl.GetParagraphCount() );
     249                 :          0 :             pNewText = rOutl.CreateParaObject( 0, nParaAnz );
     250                 :            :         }
     251                 :            : 
     252                 :            :         // need to end edit mode early since SetOutlinerParaObject already
     253                 :            :         // uses GetCurrentBoundRect() which needs to take the text into account
     254                 :            :         // to work correct
     255                 :          0 :         mbInEditMode = sal_False;
     256                 :          0 :         SetOutlinerParaObject(pNewText);
     257                 :            :     }
     258                 :            : 
     259                 :          0 :     pEdtOutl = NULL;
     260                 :          0 :     rOutl.Clear();
     261                 :          0 :     sal_uInt32 nStat = rOutl.GetControlWord();
     262                 :          0 :     nStat &= ~EE_CNTRL_AUTOPAGESIZE;
     263                 :          0 :     rOutl.SetControlWord(nStat);
     264                 :            : 
     265                 :          0 :     mbInEditMode = sal_False;
     266                 :          0 : }
     267                 :            : 
     268                 :          0 : sal_uInt16 SdrTextObj::GetOutlinerViewAnchorMode() const
     269                 :            : {
     270                 :          0 :     SdrTextHorzAdjust eH=GetTextHorizontalAdjust();
     271                 :          0 :     SdrTextVertAdjust eV=GetTextVerticalAdjust();
     272                 :          0 :     EVAnchorMode eRet=ANCHOR_TOP_LEFT;
     273         [ #  # ]:          0 :     if (IsContourTextFrame()) return (sal_uInt16)eRet;
     274         [ #  # ]:          0 :     if (eH==SDRTEXTHORZADJUST_LEFT) {
     275         [ #  # ]:          0 :         if (eV==SDRTEXTVERTADJUST_TOP) {
     276                 :          0 :             eRet=ANCHOR_TOP_LEFT;
     277         [ #  # ]:          0 :         } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
     278                 :          0 :             eRet=ANCHOR_BOTTOM_LEFT;
     279                 :            :         } else {
     280                 :          0 :             eRet=ANCHOR_VCENTER_LEFT;
     281                 :            :         }
     282         [ #  # ]:          0 :     } else if (eH==SDRTEXTHORZADJUST_RIGHT) {
     283         [ #  # ]:          0 :         if (eV==SDRTEXTVERTADJUST_TOP) {
     284                 :          0 :             eRet=ANCHOR_TOP_RIGHT;
     285         [ #  # ]:          0 :         } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
     286                 :          0 :             eRet=ANCHOR_BOTTOM_RIGHT;
     287                 :            :         } else {
     288                 :          0 :             eRet=ANCHOR_VCENTER_RIGHT;
     289                 :            :         }
     290                 :            :     } else {
     291         [ #  # ]:          0 :         if (eV==SDRTEXTVERTADJUST_TOP) {
     292                 :          0 :             eRet=ANCHOR_TOP_HCENTER;
     293         [ #  # ]:          0 :         } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
     294                 :          0 :             eRet=ANCHOR_BOTTOM_HCENTER;
     295                 :            :         } else {
     296                 :          0 :             eRet=ANCHOR_VCENTER_HCENTER;
     297                 :            :         }
     298                 :            :     }
     299                 :          0 :     return (sal_uInt16)eRet;
     300                 :            : }
     301                 :            : 
     302                 :          0 : void SdrTextObj::ImpSetTextEditParams() const
     303                 :            : {
     304         [ #  # ]:          0 :     if (pEdtOutl!=NULL) {
     305         [ #  # ]:          0 :         bool bUpdMerk=pEdtOutl->GetUpdateMode();
     306 [ #  # ][ #  # ]:          0 :         if (bUpdMerk) pEdtOutl->SetUpdateMode(sal_False);
     307                 :          0 :         Size aPaperMin;
     308                 :          0 :         Size aPaperMax;
     309         [ #  # ]:          0 :         Rectangle aEditArea;
     310         [ #  # ]:          0 :         TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,NULL);
     311         [ #  # ]:          0 :         bool bContourFrame=IsContourTextFrame();
     312         [ #  # ]:          0 :         pEdtOutl->SetMinAutoPaperSize(aPaperMin);
     313         [ #  # ]:          0 :         pEdtOutl->SetMaxAutoPaperSize(aPaperMax);
     314         [ #  # ]:          0 :         pEdtOutl->SetPaperSize(Size());
     315         [ #  # ]:          0 :         if (bContourFrame) {
     316         [ #  # ]:          0 :             Rectangle aAnchorRect;
     317         [ #  # ]:          0 :             TakeTextAnchorRect(aAnchorRect);
     318         [ #  # ]:          0 :             ImpSetContourPolygon(*pEdtOutl,aAnchorRect, sal_True);
     319                 :            :         }
     320 [ #  # ][ #  # ]:          0 :         if (bUpdMerk) pEdtOutl->SetUpdateMode(sal_True);
     321                 :            :     }
     322                 :          0 : }
     323                 :            : 
     324                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10