LCOV - code coverage report
Current view: top level - sw/source/core/edit - edglss.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 78 159 49.1 %
Date: 2012-08-25 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 95 375 25.3 %

           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                 :            : #include <comphelper/string.hxx>
      30                 :            : #include <osl/endian.h>
      31                 :            : #include <hintids.hxx>
      32                 :            : #include <svl/urihelper.hxx>
      33                 :            : #include <tools/cachestr.hxx>
      34                 :            : #include <doc.hxx>
      35                 :            : #include <pam.hxx>
      36                 :            : #include <docary.hxx>
      37                 :            : #include <editsh.hxx>
      38                 :            : #include <edimp.hxx>
      39                 :            : #include <frmfmt.hxx>
      40                 :            : #include <swundo.hxx>       // fuer die UndoIds
      41                 :            : #include <ndtxt.hxx>
      42                 :            : #include <swtable.hxx>      // fuers kopieren von Tabellen
      43                 :            : #include <shellio.hxx>      // SwTextBlocks
      44                 :            : #include <acorrect.hxx>
      45                 :            : #include <swerror.h>        // SwTextBlocks
      46                 :            : 
      47                 :            : /******************************************************************************
      48                 :            :  *              jetzt mit einem verkappten Reader/Writer/Dokument
      49                 :            :  ******************************************************************************/
      50                 :            : 
      51                 :          2 : void SwEditShell::InsertGlossary( SwTextBlocks& rGlossary, const String& rStr )
      52                 :            : {
      53                 :          2 :     StartAllAction();
      54                 :          2 :     GetDoc()->InsertGlossary( rGlossary, rStr, *GetCrsr(), this );
      55                 :          2 :     EndAllAction();
      56                 :          2 : }
      57                 :            : 
      58                 :            : 
      59                 :            : /******************************************************************************
      60                 :            :  *              aktuelle Selektion zum Textbaustein machen und ins
      61                 :            :  *          Textbausteindokument einfuegen, einschliesslich Vorlagen
      62                 :            :  ******************************************************************************/
      63                 :            : 
      64                 :            : 
      65                 :          0 : sal_uInt16 SwEditShell::MakeGlossary( SwTextBlocks& rBlks, const String& rName, const String& rShortName,
      66                 :            :                                     sal_Bool bSaveRelFile, const String* pOnlyTxt )
      67                 :            : {
      68         [ #  # ]:          0 :     SwDoc* pGDoc = rBlks.GetDoc();
      69                 :            : 
      70         [ #  # ]:          0 :     String sBase;
      71         [ #  # ]:          0 :     if(bSaveRelFile)
      72                 :            :     {
      73 [ #  # ][ #  # ]:          0 :         INetURLObject aURL( rBlks.GetFileName() );
                 [ #  # ]
      74 [ #  # ][ #  # ]:          0 :         sBase = aURL.GetMainURL( INetURLObject::NO_DECODE );
                 [ #  # ]
      75                 :            :     }
      76         [ #  # ]:          0 :     rBlks.SetBaseURL( sBase );
      77                 :            : 
      78                 :            :     sal_uInt16 nRet;
      79                 :            : 
      80         [ #  # ]:          0 :     if( pOnlyTxt )
      81         [ #  # ]:          0 :         nRet = rBlks.PutText( rShortName, rName, *pOnlyTxt );
      82                 :            :     else
      83                 :            :     {
      84         [ #  # ]:          0 :         rBlks.ClearDoc();
      85 [ #  # ][ #  # ]:          0 :         if( rBlks.BeginPutDoc( rShortName, rName ) )
      86                 :            :         {
      87 [ #  # ][ #  # ]:          0 :             rBlks.GetDoc()->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES );
      88         [ #  # ]:          0 :             _CopySelToDoc( pGDoc );
      89 [ #  # ][ #  # ]:          0 :             rBlks.GetDoc()->SetRedlineMode_intern( (RedlineMode_t)0 );
      90         [ #  # ]:          0 :             nRet = rBlks.PutDoc();
      91                 :            :         }
      92                 :            :         else
      93                 :          0 :             nRet = (sal_uInt16) -1;
      94                 :            :     }
      95                 :            : 
      96         [ #  # ]:          0 :     return nRet;
      97                 :            : }
      98                 :            : 
      99                 :          4 : sal_uInt16 SwEditShell::SaveGlossaryDoc( SwTextBlocks& rBlock,
     100                 :            :                                     const String& rName,
     101                 :            :                                     const String& rShortName,
     102                 :            :                                     sal_Bool bSaveRelFile,
     103                 :            :                                     sal_Bool bOnlyTxt )
     104                 :            : {
     105         [ +  - ]:          4 :     StartAllAction();
     106                 :            : 
     107         [ +  - ]:          4 :     SwDoc* pGDoc = rBlock.GetDoc();
     108                 :          4 :     SwDoc* pMyDoc = GetDoc();
     109                 :            : 
     110         [ +  - ]:          4 :     String sBase;
     111         [ -  + ]:          4 :     if(bSaveRelFile)
     112                 :            :     {
     113 [ #  # ][ #  # ]:          0 :         INetURLObject aURL( rBlock.GetFileName() );
                 [ #  # ]
     114 [ #  # ][ #  # ]:          0 :         sBase = aURL.GetMainURL( INetURLObject::NO_DECODE );
                 [ #  # ]
     115                 :            :     }
     116         [ +  - ]:          4 :     rBlock.SetBaseURL( sBase );
     117                 :          4 :     sal_uInt16 nRet = USHRT_MAX;
     118                 :            : 
     119         [ +  + ]:          4 :     if( bOnlyTxt )
     120                 :            :     {
     121         [ +  - ]:          2 :         KillPams();
     122                 :            : 
     123         [ +  - ]:          2 :         SwPaM* pCrsr = GetCrsr();
     124                 :            : 
     125 [ +  - ][ +  - ]:          2 :         SwNodeIndex aStt( pMyDoc->GetNodes().GetEndOfExtras(), 1 );
     126 [ +  - ][ +  - ]:          2 :         SwCntntNode* pCntntNd = pMyDoc->GetNodes().GoNext( &aStt );
     127         [ +  - ]:          2 :         const SwNode* pNd = pCntntNd->FindTableNode();
     128         [ +  - ]:          2 :         if( !pNd )
     129         [ +  - ]:          2 :             pNd = pCntntNd;
     130                 :            : 
     131         [ +  - ]:          2 :         pCrsr->GetPoint()->nNode = *pNd;
     132 [ +  - ][ +  - ]:          2 :         if( pNd == pCntntNd )
     133 [ +  - ][ +  - ]:          2 :             pCrsr->GetPoint()->nContent.Assign( pCntntNd, 0 );
     134         [ +  - ]:          2 :         pCrsr->SetMark();
     135                 :            : 
     136                 :            :         // dann bis zum Ende vom Nodes Array
     137 [ +  - ][ +  - ]:          2 :         pCrsr->GetPoint()->nNode = pMyDoc->GetNodes().GetEndOfContent().GetIndex()-1;
     138                 :          2 :         pCntntNd = pCrsr->GetCntntNode();
     139         [ +  - ]:          2 :         if( pCntntNd )
     140 [ +  - ][ +  - ]:          2 :             pCrsr->GetPoint()->nContent.Assign( pCntntNd, pCntntNd->Len() );
                 [ +  - ]
     141                 :            : 
     142         [ +  - ]:          2 :         String sBuf;
     143 [ +  - ][ +  - ]:          2 :         if( GetSelectedText( sBuf, GETSELTXT_PARABRK_TO_ONLYCR ) && sBuf.Len() )
         [ +  - ][ +  - ]
     144 [ +  - ][ +  - ]:          2 :             nRet = rBlock.PutText( rShortName, rName, sBuf );
                 [ +  - ]
     145                 :            :     }
     146                 :            :     else
     147                 :            :     {
     148         [ +  - ]:          2 :         rBlock.ClearDoc();
     149 [ +  - ][ +  - ]:          2 :         if( rBlock.BeginPutDoc( rShortName, rName ) )
     150                 :            :         {
     151 [ +  - ][ +  - ]:          2 :             SwNodeIndex aStt( pMyDoc->GetNodes().GetEndOfExtras(), 1 );
     152 [ +  - ][ +  - ]:          2 :             SwCntntNode* pCntntNd = pMyDoc->GetNodes().GoNext( &aStt );
     153         [ +  - ]:          2 :             const SwNode* pNd = pCntntNd->FindTableNode();
     154 [ +  - ][ +  - ]:          2 :             if( !pNd ) pNd = pCntntNd;
     155         [ +  - ]:          2 :             SwPaM aCpyPam( *pNd );
     156         [ +  - ]:          2 :             aCpyPam.SetMark();
     157                 :            : 
     158                 :            :             // dann bis zum Ende vom Nodes Array
     159 [ +  - ][ +  - ]:          2 :             aCpyPam.GetPoint()->nNode = pMyDoc->GetNodes().GetEndOfContent().GetIndex()-1;
     160                 :          2 :             pCntntNd = aCpyPam.GetCntntNode();
     161 [ +  - ][ +  - ]:          2 :             aCpyPam.GetPoint()->nContent.Assign( pCntntNd, pCntntNd->Len() );
                 [ +  - ]
     162                 :            : 
     163 [ +  - ][ +  - ]:          2 :             aStt = pGDoc->GetNodes().GetEndOfExtras();
     164 [ +  - ][ +  - ]:          2 :             pCntntNd = pGDoc->GetNodes().GoNext( &aStt );
     165 [ +  - ][ +  - ]:          2 :             SwPosition aInsPos( aStt, SwIndex( pCntntNd ));
         [ +  - ][ +  - ]
     166         [ +  - ]:          2 :             pMyDoc->CopyRange( aCpyPam, aInsPos, false );
     167                 :            : 
     168 [ +  - ][ +  - ]:          2 :             nRet = rBlock.PutDoc();
         [ +  - ][ +  - ]
     169                 :            :         }
     170                 :            :     }
     171         [ +  - ]:          4 :     EndAllAction();
     172         [ +  - ]:          4 :     return nRet;
     173                 :            : }
     174                 :            : 
     175                 :            : /******************************************************************************
     176                 :            :  *                  kopiere alle Selectionen und das Doc
     177                 :            :  ******************************************************************************/
     178                 :            : 
     179                 :            : 
     180                 :          0 : sal_Bool SwEditShell::_CopySelToDoc( SwDoc* pInsDoc, SwNodeIndex* pSttNd )
     181                 :            : {
     182                 :            :     OSL_ENSURE( pInsDoc, "kein Ins.Dokument"  );
     183                 :            : 
     184         [ #  # ]:          0 :     SwNodes& rNds = pInsDoc->GetNodes();
     185                 :            : 
     186         [ #  # ]:          0 :     SwNodeIndex aIdx( rNds.GetEndOfContent(), -1 );
     187                 :          0 :     SwCntntNode * pNd = aIdx.GetNode().GetCntntNode();
     188 [ #  # ][ #  # ]:          0 :     SwPosition aPos( aIdx, SwIndex( pNd, pNd->Len() ));
         [ #  # ][ #  # ]
                 [ #  # ]
     189                 :            : 
     190                 :            :     // soll der Index auf Anfang returnt werden ?
     191         [ #  # ]:          0 :     if( pSttNd )
     192                 :            :     {
     193         [ #  # ]:          0 :         *pSttNd = aPos.nNode;
     194         [ #  # ]:          0 :         (*pSttNd)--;
     195                 :            :     }
     196                 :            : 
     197                 :          0 :     sal_Bool bRet = sal_False;
     198         [ #  # ]:          0 :     SET_CURR_SHELL( this );
     199                 :            : 
     200         [ #  # ]:          0 :     pInsDoc->LockExpFlds();
     201                 :            : 
     202         [ #  # ]:          0 :     if( IsTableMode() )
     203                 :            :     {
     204                 :            :         // kopiere Teile aus einer Tabelle: lege eine Tabelle mit der Breite
     205                 :            :         // von der Originalen an und kopiere die selectierten Boxen.
     206                 :            :         // Die Groessen werden prozentual korrigiert.
     207                 :            : 
     208                 :            :         // lasse ueber das Layout die Boxen suchen
     209                 :            :         SwTableNode* pTblNd;
     210         [ #  # ]:          0 :         SwSelBoxes aBoxes;
     211         [ #  # ]:          0 :         GetTblSel( *this, aBoxes );
     212         [ #  # ]:          0 :         if( !aBoxes.empty() && 0 != (pTblNd = (SwTableNode*)aBoxes[0]
           [ #  #  #  # ]
         [ #  # ][ #  # ]
     213                 :          0 :             ->GetSttNd()->FindTableNode() ))
     214                 :            :         {
     215                 :            :             // teste ob der TabellenName kopiert werden kann
     216                 :          0 :             sal_Bool bCpyTblNm = aBoxes.size() == pTblNd->GetTable().GetTabSortBoxes().size();
     217         [ #  # ]:          0 :             if( bCpyTblNm )
     218                 :            :             {
     219                 :          0 :                 const String& rTblName = pTblNd->GetTable().GetFrmFmt()->GetName();
     220                 :          0 :                 const SwFrmFmts& rTblFmts = *pInsDoc->GetTblFrmFmts();
     221         [ #  # ]:          0 :                 for( sal_uInt16 n = rTblFmts.size(); n; )
     222 [ #  # ][ #  # ]:          0 :                     if( rTblFmts[ --n ]->GetName() == rTblName )
     223                 :            :                     {
     224                 :          0 :                         bCpyTblNm = sal_False;
     225                 :          0 :                         break;
     226                 :            :                     }
     227                 :            :             }
     228         [ #  # ]:          0 :             bRet = pInsDoc->InsCopyOfTbl( aPos, aBoxes, 0, bCpyTblNm, sal_False );
     229                 :            :         }
     230                 :            :         else
     231                 :          0 :             bRet = sal_False;
     232                 :            :     }
     233                 :            :     else
     234                 :            :     {
     235                 :          0 :         bool bColSel = _GetCrsr()->IsColumnSelection();
     236 [ #  # ][ #  # ]:          0 :         if( bColSel && pInsDoc->IsClipBoard() )
                 [ #  # ]
     237                 :          0 :             pInsDoc->SetColumnSelection( true );
     238                 :            :         {
     239 [ #  # ][ #  # ]:          0 :         FOREACHPAM_START(this)
     240                 :            : 
     241         [ #  # ]:          0 :             if( !PCURCRSR->HasMark() )
     242                 :            :             {
     243         [ #  # ]:          0 :                 if( 0 != (pNd = PCURCRSR->GetCntntNode()) &&
           [ #  #  #  # ]
                 [ #  # ]
     244                 :          0 :                     ( bColSel || !pNd->GetTxtNode() ) )
     245                 :            :                 {
     246         [ #  # ]:          0 :                     PCURCRSR->SetMark();
     247         [ #  # ]:          0 :                     PCURCRSR->Move( fnMoveForward, fnGoCntnt );
     248         [ #  # ]:          0 :                     bRet = GetDoc()->CopyRange( *PCURCRSR, aPos, false )
     249 [ #  # ][ #  # ]:          0 :                         || bRet;
     250                 :          0 :                     PCURCRSR->Exchange();
     251         [ #  # ]:          0 :                     PCURCRSR->DeleteMark();
     252                 :            :                 }
     253                 :            :             }
     254                 :            :             else
     255                 :            :             {
     256 [ #  # ][ #  # ]:          0 :                 bRet = GetDoc()->CopyRange( *PCURCRSR, aPos, false ) || bRet;
                 [ #  # ]
     257                 :            :             }
     258                 :            : 
     259                 :          0 :         FOREACHPAM_END()
     260                 :            :         }
     261                 :            :     }
     262                 :            : 
     263         [ #  # ]:          0 :     pInsDoc->UnlockExpFlds();
     264 [ #  # ][ #  # ]:          0 :     if( !pInsDoc->IsExpFldsLocked() )
     265         [ #  # ]:          0 :         pInsDoc->UpdateExpFlds(NULL, true);
     266                 :            : 
     267                 :            :     // die gemerkte Node-Position wieder auf den richtigen Node
     268 [ #  # ][ #  # ]:          0 :     if( bRet && pSttNd )
     269         [ #  # ]:          0 :         (*pSttNd)++;
     270                 :            : 
     271                 :            : 
     272 [ #  # ][ #  # ]:          0 :     return bRet;
                 [ #  # ]
     273                 :            : }
     274                 :            : 
     275                 :            : /*------------------------------------------------------------------------
     276                 :            :  Beschreibung:  Text innerhalb der Selektion erfragen
     277                 :            :  Returnwert:    liefert sal_False, wenn der selektierte Bereich
     278                 :            :                 zu gross ist, um in den Stringpuffer kopiert zu werden.
     279                 :            : ------------------------------------------------------------------------*/
     280                 :            : 
     281                 :          2 : sal_Bool SwEditShell::GetSelectedText( String &rBuf, int nHndlParaBrk )
     282                 :            : {
     283                 :          2 :     GetCrsr();  // ggfs. alle Cursor erzeugen lassen
     284         [ -  + ]:          2 :     if( IsSelOnePara() )
     285                 :            :     {
     286         [ #  # ]:          0 :         rBuf = GetSelTxt();
     287         [ #  # ]:          0 :         if( GETSELTXT_PARABRK_TO_BLANK == nHndlParaBrk )
     288                 :            :         {
     289                 :          0 :             xub_StrLen nPos = 0;
     290         [ #  # ]:          0 :             while( STRING_NOTFOUND !=
     291                 :          0 :                 ( nPos = rBuf.SearchAndReplace( 0x0a, ' ', nPos )) )
     292                 :            :                 ;
     293                 :            :         }
     294 [ #  # ][ #  # ]:          0 :         else if( IsSelFullPara() &&
                 [ #  # ]
     295                 :            :             GETSELTXT_PARABRK_TO_ONLYCR != nHndlParaBrk )
     296                 :            :         {
     297                 :            : #if defined(UNX)
     298                 :          0 :                 rBuf += '\012';
     299                 :            : #else
     300                 :            :                 rBuf += rtl::OUString("\015\012");
     301                 :            : #endif
     302                 :            :         }
     303                 :            :     }
     304         [ +  - ]:          2 :     else if( IsSelection() )
     305                 :            :     {
     306         [ +  - ]:          2 :         SvCacheStream aStream(20480);
     307                 :            : #ifdef OSL_BIGENDIAN
     308                 :            :         aStream.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
     309                 :            : #else
     310         [ +  - ]:          2 :         aStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
     311                 :            : #endif
     312                 :          2 :         WriterRef xWrt;
     313 [ +  - ][ +  - ]:          2 :         SwReaderWriter::GetWriter( rtl::OUString(FILTER_TEXT), String(), xWrt );
         [ +  - ][ +  - ]
                 [ +  - ]
     314         [ +  - ]:          2 :         if( xWrt.Is() )
     315                 :            :         {
     316                 :            :                 // Selektierte Bereiche in ein ASCII Dokument schreiben
     317         [ +  - ]:          2 :             SwWriter aWriter( aStream, *this);
     318                 :          2 :             xWrt->SetShowProgress( sal_False );
     319                 :            : 
     320      [ -  +  - ]:          2 :             switch( nHndlParaBrk )
     321                 :            :             {
     322                 :            :             case GETSELTXT_PARABRK_TO_BLANK:
     323                 :          0 :                 xWrt->bASCII_ParaAsBlanc = sal_True;
     324                 :          0 :                 xWrt->bASCII_NoLastLineEnd = sal_True;
     325                 :          0 :                 break;
     326                 :            : 
     327                 :            :             case GETSELTXT_PARABRK_TO_ONLYCR:
     328                 :          2 :                 xWrt->bASCII_ParaAsCR = sal_True;
     329                 :          2 :                 xWrt->bASCII_NoLastLineEnd = sal_True;
     330                 :          2 :                 break;
     331                 :            :             }
     332                 :            : 
     333                 :            :             //JP 09.05.00: write as UNICODE ! (and not as ANSI)
     334         [ +  - ]:          2 :             SwAsciiOptions aAsciiOpt( xWrt->GetAsciiOptions() );
     335                 :          2 :             aAsciiOpt.SetCharSet( RTL_TEXTENCODING_UCS2 );
     336         [ +  - ]:          2 :             xWrt->SetAsciiOptions( aAsciiOpt );
     337                 :          2 :             xWrt->bUCS2_WithStartChar = sal_False;
     338                 :            : 
     339                 :            :             long lLen;
     340 [ +  - ][ +  - ]:          4 :             if( !IsError( aWriter.Write( xWrt ) ) &&
         [ +  - ][ +  - ]
     341         [ +  - ]:          2 :                 STRING_MAXLEN > (( lLen  = aStream.GetSize() )
     342                 :            :                                         / sizeof( sal_Unicode )) + 1 )
     343                 :            :             {
     344         [ +  - ]:          2 :                 aStream << (sal_Unicode)'\0';
     345                 :            : 
     346         [ +  - ]:          2 :                 const sal_Unicode *p = (sal_Unicode*)aStream.GetBuffer();
     347         [ +  - ]:          2 :                 if( p )
     348         [ +  - ]:          2 :                     rBuf = rtl::OUString(p);
     349                 :            :                 else
     350                 :            :                 {
     351                 :            :                     using comphelper::string::rtl_uString_alloc;
     352         [ #  # ]:          0 :                     rtl_uString *pStr = rtl_uString_alloc(lLen / sizeof( sal_Unicode ));
     353         [ #  # ]:          0 :                     aStream.Seek( 0 );
     354         [ #  # ]:          0 :                     aStream.ResetError();
     355                 :            :                     //endian specific?, yipes!
     356         [ #  # ]:          0 :                     aStream.Read(pStr->buffer, lLen);
     357         [ #  # ]:          0 :                     rBuf = rtl::OUString(pStr, SAL_NO_ACQUIRE);
     358                 :            :                 }
     359 [ +  - ][ +  - ]:          2 :             }
     360 [ +  - ][ +  - ]:          2 :         }
     361                 :            :     }
     362                 :            : 
     363                 :          2 :     return sal_True;
     364                 :            : }
     365                 :            : 
     366                 :            : 
     367                 :            : 
     368                 :            : 
     369                 :            : 
     370                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10