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 SwFindParaFormatColl : public SwFindParas
32 : {
33 : const SwTextFormatColl *pFormatColl, *pReplColl;
34 : SwCursor& rCursor;
35 0 : SwFindParaFormatColl( const SwTextFormatColl& rFormatColl,
36 : const SwTextFormatColl* pRpColl, SwCursor& rCrsr )
37 0 : : pFormatColl( &rFormatColl ), pReplColl( pRpColl ), rCursor( rCrsr )
38 0 : {}
39 0 : virtual ~SwFindParaFormatColl() {}
40 : virtual int Find( SwPaM* , SwMoveFn , const SwPaM*, bool bInReadOnly ) SAL_OVERRIDE;
41 : virtual bool IsReplaceMode() const SAL_OVERRIDE;
42 : };
43 :
44 0 : int SwFindParaFormatColl::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( *pFormatColl, fnMove, pRegion, bInReadOnly ) )
52 0 : nRet = FIND_NOT_FOUND;
53 0 : else if( pReplColl )
54 : {
55 0 : pCrsr->GetDoc()->SetTextFormatColl( *pCrsr, const_cast<SwTextFormatColl*>(pReplColl) );
56 0 : nRet = FIND_NO_RING;
57 : }
58 0 : return nRet;
59 : }
60 :
61 0 : bool SwFindParaFormatColl::IsReplaceMode() const
62 : {
63 0 : return 0 != pReplColl;
64 : }
65 :
66 : /// search for Format-Collections
67 0 : sal_uLong SwCursor::Find( const SwTextFormatColl& rFormatColl, SwDocPositions nStart,
68 : SwDocPositions nEnd, bool& bCancel,
69 : FindRanges eFndRngs, const SwTextFormatColl* pReplFormatColl )
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() && pReplFormatColl;
78 0 : if (bStartUndo)
79 : {
80 0 : SwRewriter aRewriter;
81 0 : aRewriter.AddRule(UndoArg1, rFormatColl.GetName());
82 0 : aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
83 0 : aRewriter.AddRule(UndoArg3, pReplFormatColl->GetName());
84 :
85 0 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE_STYLE,
86 0 : &aRewriter );
87 : }
88 :
89 0 : SwFindParaFormatColl aSwFindParaFormatColl( rFormatColl, pReplFormatColl, *this );
90 :
91 0 : sal_uLong nRet = FindAll( aSwFindParaFormatColl, nStart, nEnd, eFndRngs, bCancel );
92 0 : pDoc->SetOle2Link( aLnk );
93 :
94 0 : if( nRet && pReplFormatColl )
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 177 : }
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|