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 
29 namespace {
30 
32 struct 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 
50 int 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 
69 bool SwFindParaFormatColl::IsReplaceMode() const
70 {
71  return nullptr != pReplColl;
72 }
73 
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() );
83  rDoc.SetOle2Link( Link<bool,void>() );
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_uLong nRet = FindAll( aSwFindParaFormatColl, nStart, nEnd, eFndRngs, bCancel );
101  rDoc.SetOle2Link( aLnk );
102 
103  if( nRet && pReplFormatColl )
105 
106  if (bStartUndo)
107  {
108  rDoc.GetIDocumentUndoRedo().EndUndo(SwUndoId::END, nullptr);
109  }
110  return nRet;
111 }
112 
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool, std::unique_ptr< SvxSearchItem > &xSearchItem)=0
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
virtual void SetModified()=0
Must be called manually at changes of format.
sal_uIntPtr sal_uLong
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:186
void SetOle2Link(const Link< bool, void > &rLink)
Definition: doc.hxx:1326
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:144
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
SwDocPositions
Definition: cshtyp.hxx:103
bool SetTextFormatColl(const SwPaM &rRg, SwTextFormatColl *pFormat, const bool bReset=true, const bool bResetListAttrs=false, SwRootFrame const *pLayout=nullptr)
Add 4th optional parameter .
Definition: docfmt.cxx:1072
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1327
const OUString & GetName() const
Definition: format.hxx:111
FindRanges
Definition: cshtyp.hxx:90
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 DoesUndo() const =0
Is Undo enabled?
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual bool IsReplaceMode() const =0
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
sal_uLong FindAll(SwFindParas &, SwDocPositions, SwDocPositions, FindRanges, bool &bCancel)
Definition: swcrsr.cxx:952
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:27
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
const int FIND_NO_RING
Definition: swcrsr.hxx:37
const int FIND_FOUND
Definition: swcrsr.hxx:36
const int FIND_NOT_FOUND
Definition: swcrsr.hxx:35
SwDoc & GetDoc() const
Definition: pam.hxx:243
sal_uLong 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