LibreOffice Module sw (master)  1
unbkmk.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 <UndoBookmark.hxx>
21 
22 #include <strings.hrc>
23 #include <doc.hxx>
24 #include <swundo.hxx>
25 #include <pam.hxx>
26 
27 #include <UndoCore.hxx>
28 #include <IMark.hxx>
29 #include <rolbck.hxx>
30 
31 #include <SwRewriter.hxx>
32 
34  const ::sw::mark::IMark& rBkmk )
35  : SwUndo( nUndoId, rBkmk.GetMarkPos().GetDoc() )
36  , m_pHistoryBookmark(new SwHistoryBookmark(rBkmk, true, rBkmk.IsExpanded()))
37 {
38 }
39 
41 {
42 }
43 
45 {
46  m_pHistoryBookmark->SetInDoc( pDoc, false );
47 }
48 
50 {
51  IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
52  for ( IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getAllMarksBegin();
53  ppBkmk != pMarkAccess->getAllMarksEnd();
54  ++ppBkmk )
55  {
56  if ( m_pHistoryBookmark->IsEqualBookmark( **ppBkmk ) )
57  {
58  pMarkAccess->deleteMark( ppBkmk );
59  break;
60  }
61  }
62 }
63 
65 {
66  SwRewriter aResult;
67 
68  aResult.AddRule(UndoArg1, m_pHistoryBookmark->GetName());
69 
70  return aResult;
71 }
72 
73 SwUndoInsBookmark::SwUndoInsBookmark( const ::sw::mark::IMark& rBkmk )
75 {
76 }
77 
79 {
80  ResetInDoc( &rContext.GetDoc() );
81 }
82 
84 {
85  SetInDoc( &rContext.GetDoc() );
86 }
87 
88 SwUndoDeleteBookmark::SwUndoDeleteBookmark( const ::sw::mark::IMark& rBkmk )
90 {
91 }
92 
94 {
95  SetInDoc( &rContext.GetDoc() );
96 }
97 
99 {
100  ResetInDoc( &rContext.GetDoc() );
101 }
102 
103 SwUndoRenameBookmark::SwUndoRenameBookmark( const OUString& rOldName, const OUString& rNewName, const SwDoc* pDoc )
104  : SwUndo( SwUndoId::BOOKMARK_RENAME, pDoc )
105  , m_sOldName( rOldName )
106  , m_sNewName( rNewName )
107 {
108 }
109 
111 {
112 }
113 
114 static OUString lcl_QuoteName(const OUString& rName)
115 {
116  static const OUString sStart = SwResId(STR_START_QUOTE);
117  static const OUString sEnd = SwResId(STR_END_QUOTE);
118  return sStart + rName + sEnd;
119 }
120 
122 {
123  SwRewriter aRewriter;
125  aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
127  return aRewriter;
128 }
129 
130 void SwUndoRenameBookmark::Rename(::sw::UndoRedoContext const & rContext, const OUString& sFrom, const OUString& sTo)
131 {
132  IDocumentMarkAccess* const pMarkAccess = rContext.GetDoc().getIDocumentMarkAccess();
133  IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findMark(sFrom);
134  if (ppBkmk != pMarkAccess->getAllMarksEnd())
135  {
136  pMarkAccess->renameMark( *ppBkmk, sTo );
137  }
138 }
139 
141 {
142  Rename(rContext, m_sNewName, m_sOldName);
143 }
144 
146 {
147  Rename(rContext, m_sOldName, m_sNewName);
148 }
149 
150 SwUndoInsNoTextFieldmark::SwUndoInsNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
151  : SwUndo(SwUndoId::INSERT, rFieldmark.GetMarkPos().GetDoc())
152  , m_pHistoryNoTextFieldmark(new SwHistoryNoTextFieldmark(rFieldmark))
153 {
154 }
155 
157 {
158  m_pHistoryNoTextFieldmark->ResetInDoc(&rContext.GetDoc());
159 }
160 
162 {
163  m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
164 }
165 
166 SwUndoDelNoTextFieldmark::SwUndoDelNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
167  : SwUndo(SwUndoId::DELETE, rFieldmark.GetMarkPos().GetDoc())
168  , m_pHistoryNoTextFieldmark(new SwHistoryNoTextFieldmark(rFieldmark))
169 {
170 }
171 
173 
175 {
176  m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
177 }
178 
180 {
181  m_pHistoryNoTextFieldmark->ResetInDoc(&rContext.GetDoc());
182 }
183 
184 SwUndoInsTextFieldmark::SwUndoInsTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
185  : SwUndo(SwUndoId::INSERT, rFieldmark.GetMarkPos().GetDoc())
186  , m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
187 {
188 }
189 
191 {
192  m_pHistoryTextFieldmark->ResetInDoc(&rContext.GetDoc());
193 }
194 
196 {
197  m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
198 }
199 
200 SwUndoDelTextFieldmark::SwUndoDelTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
201  : SwUndo(SwUndoId::DELETE, rFieldmark.GetMarkPos().GetDoc())
202  , m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
203 {
204 }
205 
207 
209 {
210  m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
211 }
212 
214 {
215  m_pHistoryTextFieldmark->ResetInDoc(&rContext.GetDoc());
216 }
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwUndoDelTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:200
History object containing all information used during undo / redo of text form field insertion...
Definition: rolbck.hxx:281
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:195
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:145
SwUndoId
Definition: swundo.hxx:29
virtual ~SwUndoBookmark() override
Definition: unbkmk.cxx:40
static OUString lcl_QuoteName(const OUString &rName)
Definition: unbkmk.cxx:114
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
void SetInDoc(SwDoc *)
Definition: unbkmk.cxx:44
const std::unique_ptr< SwHistoryNoTextFieldmark > m_pHistoryNoTextFieldmark
Provides access to the marks of a document.
Definition: doc.hxx:186
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:179
SwUndoInsTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:184
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1681
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:156
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unbkmk.cxx:121
virtual ~SwUndoRenameBookmark() override
Definition: unbkmk.cxx:110
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:161
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
SwUndoDelNoTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:166
SwUndoRenameBookmark(const OUString &rOldName, const OUString &rNewName, const SwDoc *pDoc)
Definition: unbkmk.cxx:103
void ResetInDoc(SwDoc *)
Definition: unbkmk.cxx:49
History object containing all information used during undo / redo of checkbox and drop-down form fiel...
Definition: rolbck.hxx:266
const std::unique_ptr< SwHistoryBookmark > m_pHistoryBookmark
SwUndoInsBookmark(const ::sw::mark::IMark &)
Definition: unbkmk.cxx:73
static void Rename(::sw::UndoRedoContext const &, const OUString &sFrom, const OUString &sTo)
Definition: unbkmk.cxx:130
SwDoc & GetDoc() const
Definition: UndoCore.hxx:94
virtual std::unique_ptr< ILazyDeleter > deleteMark(const IDocumentMarkAccess::const_iterator_t &ppMark)=0
Deletes a mark.
virtual const_iterator_t getAllMarksBegin() const =0
returns a STL-like random access iterator to the begin of the sequence of marks.
virtual const_iterator_t getAllMarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of marks.
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this undo object.
Definition: unbkmk.cxx:64
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:174
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:140
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:190
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:83
SwUndoInsNoTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:150
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:98
const std::unique_ptr< SwHistoryTextFieldmark > m_pHistoryTextFieldmark
const std::unique_ptr< SwHistoryTextFieldmark > m_pHistoryTextFieldmark
SwUndoDeleteBookmark(const ::sw::mark::IMark &)
Definition: unbkmk.cxx:88
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:93
const OUString m_sOldName
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:208
const std::unique_ptr< SwHistoryNoTextFieldmark > m_pHistoryNoTextFieldmark
virtual bool renameMark(::sw::mark::IMark *io_pMark, const OUString &rNewName)=0
Renames an existing Mark, if possible.
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:78
SwUndoBookmark(SwUndoId nUndoId, const ::sw::mark::IMark &)
Definition: unbkmk.cxx:33
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:213
const OUString m_sNewName