LCOV - code coverage report
Current view: top level - sw/source/core/crsr - findcoll.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 37 2.7 %
Date: 2014-11-03 Functions: 2 8 25.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 <tools/resid.hxx>
      21             : #include <swcrsr.hxx>
      22             : #include <doc.hxx>
      23             : #include <IDocumentUndoRedo.hxx>
      24             : #include <IDocumentState.hxx>
      25             : #include <pamtyp.hxx>
      26             : #include <swundo.hxx>
      27             : #include <SwRewriter.hxx>
      28             : #include <comcore.hrc>
      29             : 
      30             : /// parameters for a search for FormatCollections
      31             : struct SwFindParaFmtColl : public SwFindParas
      32             : {
      33             :     const SwTxtFmtColl *pFmtColl, *pReplColl;
      34             :     SwCursor& rCursor;
      35           0 :     SwFindParaFmtColl( const SwTxtFmtColl& rFmtColl,
      36             :                         const SwTxtFmtColl* pRpColl, SwCursor& rCrsr )
      37           0 :         : pFmtColl( &rFmtColl ), pReplColl( pRpColl ), rCursor( rCrsr )
      38           0 :     {}
      39           0 :     virtual ~SwFindParaFmtColl() {}
      40             :     virtual int Find( SwPaM* , SwMoveFn , const SwPaM*, bool bInReadOnly ) SAL_OVERRIDE;
      41             :     virtual bool IsReplaceMode() const SAL_OVERRIDE;
      42             : };
      43             : 
      44           0 : int SwFindParaFmtColl::Find( SwPaM* pCrsr, SwMoveFn fnMove, const SwPaM* pRegion,
      45             :                              bool bInReadOnly )
      46             : {
      47           0 :     int nRet = FIND_FOUND;
      48           0 :     if( bInReadOnly && pReplColl )
      49           0 :         bInReadOnly = false;
      50             : 
      51           0 :     if( !pCrsr->Find( *pFmtColl, fnMove, pRegion, bInReadOnly ) )
      52           0 :         nRet = FIND_NOT_FOUND;
      53           0 :     else if( pReplColl )
      54             :     {
      55           0 :         pCrsr->GetDoc()->SetTxtFmtColl( *pCrsr, (SwTxtFmtColl*)pReplColl );
      56           0 :         nRet = FIND_NO_RING;
      57             :     }
      58           0 :     return nRet;
      59             : }
      60             : 
      61           0 : bool SwFindParaFmtColl::IsReplaceMode() const
      62             : {
      63           0 :     return 0 != pReplColl;
      64             : }
      65             : 
      66             : /// search for Format-Collections
      67           0 : sal_uLong SwCursor::Find( const SwTxtFmtColl& rFmtColl, SwDocPositions nStart,
      68             :                           SwDocPositions nEnd, bool& bCancel,
      69             :                           FindRanges eFndRngs, const SwTxtFmtColl* pReplFmtColl )
      70             : {
      71             :     // switch off OLE-notifications
      72           0 :     SwDoc* pDoc = GetDoc();
      73           0 :     Link aLnk( pDoc->GetOle2Link() );
      74           0 :     pDoc->SetOle2Link( Link() );
      75             : 
      76             :     bool const bStartUndo =
      77           0 :         pDoc->GetIDocumentUndoRedo().DoesUndo() && pReplFmtColl;
      78           0 :     if (bStartUndo)
      79             :     {
      80           0 :         SwRewriter aRewriter;
      81           0 :         aRewriter.AddRule(UndoArg1, rFmtColl.GetName());
      82           0 :         aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
      83           0 :         aRewriter.AddRule(UndoArg3, pReplFmtColl->GetName());
      84             : 
      85           0 :         pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE_STYLE,
      86           0 :                 &aRewriter );
      87             :     }
      88             : 
      89           0 :     SwFindParaFmtColl aSwFindParaFmtColl( rFmtColl, pReplFmtColl, *this );
      90             : 
      91           0 :     sal_uLong nRet = FindAll( aSwFindParaFmtColl, nStart, nEnd, eFndRngs, bCancel );
      92           0 :     pDoc->SetOle2Link( aLnk );
      93             : 
      94           0 :     if( nRet && pReplFmtColl )
      95           0 :         pDoc->getIDocumentState().SetModified();
      96             : 
      97           0 :     if (bStartUndo)
      98             :     {
      99           0 :         pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_END, 0);
     100             :     }
     101           0 :     return nRet;
     102         270 : }
     103             : 
     104             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10