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 
31 {
35  const SwTextFormatColl *const pRpColl,
36  SwRootFrame const*const pLayout)
37  : pFormatColl( &rFormatColl )
38  , pReplColl( pRpColl )
39  , m_pLayout(pLayout)
40  {}
41  virtual ~SwFindParaFormatColl() {}
42  virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool bInReadOnly) override;
43  virtual bool IsReplaceMode() const override;
44 };
45 
47  const SwPaM & rRegion, bool bInReadOnly)
48 {
49  int nRet = FIND_FOUND;
50  if( bInReadOnly && pReplColl )
51  bInReadOnly = false;
52 
53  if (!sw::FindFormatImpl(rCursor, *pFormatColl, fnMove, rRegion, bInReadOnly, m_pLayout))
54  nRet = FIND_NOT_FOUND;
55  else if( pReplColl )
56  {
57  rCursor.GetDoc()->SetTextFormatColl(rCursor,
58  const_cast<SwTextFormatColl*>(pReplColl), true, false, m_pLayout);
59  nRet = FIND_NO_RING;
60  }
61  return nRet;
62 }
63 
65 {
66  return nullptr != pReplColl;
67 }
68 
71  SwDocPositions nEnd, bool& bCancel,
72  FindRanges eFndRngs, const SwTextFormatColl* pReplFormatColl,
73  SwRootFrame const*const pLayout)
74 {
75  // switch off OLE-notifications
76  SwDoc* pDoc = GetDoc();
77  Link<bool,void> aLnk( pDoc->GetOle2Link() );
78  pDoc->SetOle2Link( Link<bool,void>() );
79 
80  bool const bStartUndo =
81  pDoc->GetIDocumentUndoRedo().DoesUndo() && pReplFormatColl;
82  if (bStartUndo)
83  {
84  SwRewriter aRewriter;
85  aRewriter.AddRule(UndoArg1, rFormatColl.GetName());
86  aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
87  aRewriter.AddRule(UndoArg3, pReplFormatColl->GetName());
88 
90  &aRewriter );
91  }
92 
93  SwFindParaFormatColl aSwFindParaFormatColl(rFormatColl, pReplFormatColl, pLayout);
94 
95  sal_uLong nRet = FindAll( aSwFindParaFormatColl, nStart, nEnd, eFndRngs, bCancel );
96  pDoc->SetOle2Link( aLnk );
97 
98  if( nRet && pReplFormatColl )
100 
101  if (bStartUndo)
102  {
103  pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::END, nullptr);
104  }
105  return nRet;
106 }
107 
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFindParaFormatColl(const SwTextFormatColl &rFormatColl, const SwTextFormatColl *const pRpColl, SwRootFrame const *const pLayout)
Definition: findcoll.cxx:34
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:185
void SetOle2Link(const Link< bool, void > &rLink)
Definition: doc.hxx:1316
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:176
parameters for a search for FormatCollections
Definition: findcoll.cxx:30
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
virtual ~SwFindParaFormatColl()
Definition: findcoll.cxx:41
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:1096
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1317
const OUString & GetName() const
Definition: format.hxx:111
FindRanges
Definition: cshtyp.hxx:90
SwRootFrame const * m_pLayout
Definition: findcoll.cxx:33
bool FindFormatImpl(SwPaM &rSearchPam, const SwFormat &rFormat, SwMoveFnCollection const &fnMove, const SwPaM &rRegion, bool bInReadOnly, SwRootFrame const *const pLayout)
Definition: findfmt.cxx:29
virtual bool DoesUndo() const =0
Is Undo enabled?
virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool bInReadOnly) override
Definition: findcoll.cxx:46
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
virtual bool IsReplaceMode() const override
Definition: findcoll.cxx:64
sal_uLong FindAll(SwFindParas &, SwDocPositions, SwDocPositions, FindRanges, bool &bCancel)
Definition: swcrsr.cxx:925
SwDoc * GetDoc() const
Definition: pam.hxx:243
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:426
const SwTextFormatColl * pFormatColl
Definition: findcoll.cxx:32
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
const int FIND_NO_RING
Definition: swcrsr.hxx:36
sal_uLong FindFormat(const SwTextFormatColl &rFormatColl, SwDocPositions nStart, SwDocPositions nEnde, bool &bCancel, FindRanges, const SwTextFormatColl *pReplFormat, SwRootFrame const *const pLayout=nullptr)
search for Format-Collections
Definition: findcoll.cxx:70
const SwTextFormatColl * pReplColl
Definition: findcoll.cxx:32
const int FIND_FOUND
Definition: swcrsr.hxx:35
const int FIND_NOT_FOUND
Definition: swcrsr.hxx:34