LibreOffice Module sw (master) 1
findcoll.cxx
Go to the documentation of this file.
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 <swcrsr.hxx>
21#include <doc.hxx>
22#include <IDocumentUndoRedo.hxx>
23#include <IDocumentState.hxx>
24#include <pamtyp.hxx>
25#include <swundo.hxx>
26#include <SwRewriter.hxx>
27#include <strings.hrc>
28
29namespace {
30
32struct SwFindParaFormatColl : public SwFindParas
33{
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 )
41 , m_pLayout(pLayout)
42 {}
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;
46};
47
48}
49
50int SwFindParaFormatColl::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
51 const SwPaM & rRegion, bool bInReadOnly,
52 std::unique_ptr<SvxSearchItem>& /*xSearchItem*/)
53{
54 int nRet = FIND_FOUND;
55 if( bInReadOnly && pReplColl )
56 bInReadOnly = false;
57
58 if (!sw::FindFormatImpl(rCursor, *pFormatColl, fnMove, rRegion, bInReadOnly, m_pLayout))
59 nRet = FIND_NOT_FOUND;
60 else if( pReplColl )
61 {
62 rCursor.GetDoc().SetTextFormatColl(rCursor,
63 const_cast<SwTextFormatColl*>(pReplColl), true, false, m_pLayout);
64 nRet = FIND_NO_RING;
65 }
66 return nRet;
67}
68
69bool SwFindParaFormatColl::IsReplaceMode() const
70{
71 return nullptr != pReplColl;
72}
73
75sal_Int32 SwCursor::FindFormat( const SwTextFormatColl& rFormatColl, SwDocPositions nStart,
76 SwDocPositions nEnd, bool& bCancel,
77 FindRanges eFndRngs, const SwTextFormatColl* pReplFormatColl,
78 SwRootFrame const*const pLayout)
79{
80 // switch off OLE-notifications
81 SwDoc& rDoc = GetDoc();
82 Link<bool,void> aLnk( rDoc.GetOle2Link() );
84
85 bool const bStartUndo =
86 rDoc.GetIDocumentUndoRedo().DoesUndo() && pReplFormatColl;
87 if (bStartUndo)
88 {
89 SwRewriter aRewriter;
90 aRewriter.AddRule(UndoArg1, rFormatColl.GetName());
91 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
92 aRewriter.AddRule(UndoArg3, pReplFormatColl->GetName());
93
95 &aRewriter );
96 }
97
98 SwFindParaFormatColl aSwFindParaFormatColl(rFormatColl, pReplFormatColl, pLayout);
99
100 sal_Int32 nRet = FindAll( aSwFindParaFormatColl, nStart, nEnd, eFndRngs, bCancel );
101 rDoc.SetOle2Link( aLnk );
102
103 if( nRet && pReplFormatColl )
105
106 if (bStartUndo)
107 {
109 }
110 return nRet;
111}
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ UndoArg1
Definition: SwRewriter.hxx:29
@ UndoArg3
Definition: SwRewriter.hxx:31
@ UndoArg2
Definition: SwRewriter.hxx:30
virtual void SetModified()=0
Must be called manually at changes of format.
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
virtual bool DoesUndo() const =0
Is Undo enabled?
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
sal_Int32 FindFormat(const SwTextFormatColl &rFormatColl, SwDocPositions nStart, SwDocPositions nEnd, bool &bCancel, FindRanges, const SwTextFormatColl *pReplFormat, SwRootFrame const *const pLayout=nullptr)
search for Format-Collections
Definition: findcoll.cxx:75
sal_Int32 FindAll(SwFindParas &, SwDocPositions, SwDocPositions, FindRanges, bool &bCancel)
Definition: swcrsr.cxx:944
Definition: doc.hxx:192
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:395
void SetOle2Link(const Link< bool, void > &rLink)
Definition: doc.hxx:1331
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:145
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1332
bool SetTextFormatColl(const SwPaM &rRg, SwTextFormatColl *pFormat, const bool bReset=true, const bool bResetListAttrs=false, SwRootFrame const *pLayout=nullptr)
Add 4th optional parameter <bResetListAttrs>.
Definition: docfmt.cxx:1082
const OUString & GetName() const
Definition: format.hxx:131
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
SwDoc & GetDoc() const
Definition: pam.hxx:299
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:25
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
Represents the style of a paragraph.
Definition: fmtcol.hxx:59
SwDocPositions
Definition: cshtyp.hxx:104
FindRanges
Definition: cshtyp.hxx:91
bool FindFormatImpl(SwPaM &rSearchPam, const SwFormat &rFormat, SwMoveFnCollection const &fnMove, const SwPaM &rRegion, bool bInReadOnly, SwRootFrame const *const pLayout)
Definition: findfmt.cxx:28
virtual bool IsReplaceMode() const =0
virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool, std::unique_ptr< SvxSearchItem > &xSearchItem)=0
const int FIND_NOT_FOUND
Definition: swcrsr.hxx:35
const int FIND_FOUND
Definition: swcrsr.hxx:36
const int FIND_NO_RING
Definition: swcrsr.hxx:37
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
@ UI_REPLACE_STYLE