1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <IDocumentUndoRedo.hxx>
23 #include <IDocumentState.hxx>
26 #include <SwRewriter.hxx>
27 #include <strings.hrc>
31 /// parameters for a search for FormatCollections
32 struct SwFindParaFormatColl
: public SwFindParas
34 const SwTextFormatColl
*pFormatColl
, *pReplColl
;
35 SwRootFrame
const* m_pLayout
;
36 SwFindParaFormatColl(const SwTextFormatColl
& rFormatColl
,
37 const SwTextFormatColl
*const pRpColl
,
38 SwRootFrame
const*const pLayout
)
39 : pFormatColl( &rFormatColl
)
40 , pReplColl( pRpColl
)
43 virtual ~SwFindParaFormatColl() {}
44 virtual int DoFind(SwPaM
&, SwMoveFnCollection
const &, const SwPaM
&, bool bInReadOnly
, std::unique_ptr
<SvxSearchItem
>& xSearchItem
) override
;
45 virtual bool IsReplaceMode() const override
;
50 int SwFindParaFormatColl::DoFind(SwPaM
& rCursor
, SwMoveFnCollection
const & fnMove
,
51 const SwPaM
& rRegion
, bool bInReadOnly
,
52 std::unique_ptr
<SvxSearchItem
>& /*xSearchItem*/)
54 int nRet
= FIND_FOUND
;
55 if( bInReadOnly
&& pReplColl
)
58 if (!sw::FindFormatImpl(rCursor
, *pFormatColl
, fnMove
, rRegion
, bInReadOnly
, m_pLayout
))
59 nRet
= FIND_NOT_FOUND
;
62 rCursor
.GetDoc().SetTextFormatColl(rCursor
,
63 const_cast<SwTextFormatColl
*>(pReplColl
), true, false, m_pLayout
);
69 bool SwFindParaFormatColl::IsReplaceMode() const
71 return nullptr != pReplColl
;
74 /// search for Format-Collections
75 sal_Int32
SwCursor::FindFormat( const SwTextFormatColl
& rFormatColl
, SwDocPositions nStart
,
76 SwDocPositions nEnd
, bool& bCancel
,
77 FindRanges eFndRngs
, const SwTextFormatColl
* pReplFormatColl
,
78 SwRootFrame
const*const pLayout
)
80 // switch off OLE-notifications
81 SwDoc
& rDoc
= GetDoc();
82 Link
<bool,void> aLnk( rDoc
.GetOle2Link() );
83 rDoc
.SetOle2Link( Link
<bool,void>() );
85 bool const bStartUndo
=
86 rDoc
.GetIDocumentUndoRedo().DoesUndo() && pReplFormatColl
;
90 aRewriter
.AddRule(UndoArg1
, rFormatColl
.GetName());
91 aRewriter
.AddRule(UndoArg2
, SwResId(STR_YIELDS
));
92 aRewriter
.AddRule(UndoArg3
, pReplFormatColl
->GetName());
94 rDoc
.GetIDocumentUndoRedo().StartUndo( SwUndoId::UI_REPLACE_STYLE
,
98 SwFindParaFormatColl
aSwFindParaFormatColl(rFormatColl
, pReplFormatColl
, pLayout
);
100 sal_Int32 nRet
= FindAll( aSwFindParaFormatColl
, nStart
, nEnd
, eFndRngs
, bCancel
);
101 rDoc
.SetOle2Link( aLnk
);
103 if( nRet
&& pReplFormatColl
)
104 rDoc
.getIDocumentState().SetModified();
108 rDoc
.GetIDocumentUndoRedo().EndUndo(SwUndoId::END
, nullptr);
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */