LibreOffice Module sw (master)  1
parachangetrackinginfo.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 
21 
22 #include <wrong.hxx>
23 #include <com/sun/star/text/TextMarkupType.hpp>
24 
25 #include <txtfrm.hxx>
26 #include <rootfrm.hxx>
27 #include <ndtxt.hxx>
29 #include <docary.hxx>
30 #include <redline.hxx>
31 
32 #include <algorithm>
33 
34 namespace {
35  void initChangeTrackTextMarkupLists( const SwTextFrame& rTextFrame,
36  std::unique_ptr<SwWrongList>& opChangeTrackInsertionTextMarkupList,
37  std::unique_ptr<SwWrongList>& opChangeTrackDeletionTextMarkupList,
38  std::unique_ptr<SwWrongList>& opChangeTrackFormatChangeTextMarkupList )
39  {
40  opChangeTrackInsertionTextMarkupList.reset( new SwWrongList( WRONGLIST_CHANGETRACKING ) );
41  opChangeTrackDeletionTextMarkupList.reset( new SwWrongList( WRONGLIST_CHANGETRACKING ) );
42  opChangeTrackFormatChangeTextMarkupList.reset( new SwWrongList( WRONGLIST_CHANGETRACKING ) );
43 
44  if (!rTextFrame.GetTextNodeFirst())
45  {
46  OSL_FAIL( "<initChangeTrackTextMarkupLists(..) - missing <SwTextNode> instance!" );
47  return;
48  }
49  // sw_redlinehide: the first node is sufficient - there are only
50  // multiple ones in Hide case and the code below returns early then
51  const SwTextNode& rTextNode(*(rTextFrame.GetTextNodeFirst()));
52 
53  const IDocumentRedlineAccess& rIDocChangeTrack( rTextNode.getIDocumentRedlineAccess() );
54 
55  if (!IDocumentRedlineAccess::IsShowChanges(rIDocChangeTrack.GetRedlineFlags())
56  || rTextFrame.getRootFrame()->IsHideRedlines()
57  || rIDocChangeTrack.GetRedlineTable().empty())
58  {
59  // nothing to do --> empty change track text markup lists.
60  return;
61  }
62 
63  const SwRedlineTable::size_type nIdxOfFirstRedlineForTextNode =
64  rIDocChangeTrack.GetRedlinePos( rTextNode, RedlineType::Any );
65  if ( nIdxOfFirstRedlineForTextNode == SwRedlineTable::npos )
66  {
67  // nothing to do --> empty change track text markup lists.
68  return;
69  }
70 
71  // sw_redlinehide: rely on the Hide early return above & cast
72  // TextFrameIndex to SwIndex directly
73  const sal_Int32 nTextFrameTextStartPos = rTextFrame.IsFollow()
74  ? sal_Int32(rTextFrame.GetOfst())
75  : 0;
76  const sal_Int32 nTextFrameTextEndPos = rTextFrame.HasFollow()
77  ? sal_Int32(rTextFrame.GetFollow()->GetOfst())
78  : rTextFrame.GetText().getLength();
79 
80  // iteration over the redlines which overlap with the text node.
81  const SwRedlineTable& rRedlineTable = rIDocChangeTrack.GetRedlineTable();
82  const SwRedlineTable::size_type nRedlineCount( rRedlineTable.size() );
83  for ( SwRedlineTable::size_type nActRedline = nIdxOfFirstRedlineForTextNode;
84  nActRedline < nRedlineCount;
85  ++nActRedline)
86  {
87  const SwRangeRedline* pActRedline = rRedlineTable[ nActRedline ];
88  if ( pActRedline->Start()->nNode > rTextNode.GetIndex() )
89  {
90  break;
91  }
92 
93  sal_Int32 nTextNodeChangeTrackStart(COMPLETE_STRING);
94  sal_Int32 nTextNodeChangeTrackEnd(COMPLETE_STRING);
95  pActRedline->CalcStartEnd( rTextNode.GetIndex(),
96  nTextNodeChangeTrackStart,
97  nTextNodeChangeTrackEnd );
98  if ( nTextNodeChangeTrackStart > nTextFrameTextEndPos ||
99  nTextNodeChangeTrackEnd < nTextFrameTextStartPos )
100  {
101  // Consider only redlines which overlap with the text frame's text.
102  continue;
103  }
104 
105  SwWrongList* pMarkupList( nullptr );
106  switch ( pActRedline->GetType() )
107  {
108  case RedlineType::Insert:
109  {
110  pMarkupList = opChangeTrackInsertionTextMarkupList.get();
111  }
112  break;
113  case RedlineType::Delete:
114  {
115  pMarkupList = opChangeTrackDeletionTextMarkupList.get();
116  }
117  break;
118  case RedlineType::Format:
119  {
120  pMarkupList = opChangeTrackFormatChangeTextMarkupList.get();
121  }
122  break;
123  default:
124  {
125  // other types are not considered
126  }
127  }
128  if ( pMarkupList )
129  {
130  const sal_Int32 nTextFrameChangeTrackStart =
131  std::max(nTextNodeChangeTrackStart, nTextFrameTextStartPos);
132 
133  const sal_Int32 nTextFrameChangeTrackEnd =
134  std::min(nTextNodeChangeTrackEnd, nTextFrameTextEndPos);
135 
136  pMarkupList->Insert( OUString(), nullptr,
137  nTextFrameChangeTrackStart,
138  nTextFrameChangeTrackEnd - nTextFrameChangeTrackStart,
139  pMarkupList->Count() );
140  }
141  } // eof iteration over the redlines which overlap with the text node
142  }
143 } // eof anonymous namespace
144 
146  : mrTextFrame( rTextFrame )
147 {
148 }
149 
151 {
152  reset();
153 }
154 
156 {
160 }
161 
163 {
164  SwWrongList* pChangeTrackingTextMarkupList = nullptr;
165 
166  if ( mpChangeTrackInsertionTextMarkupList == nullptr )
167  {
168  OSL_ENSURE( mpChangeTrackDeletionTextMarkupList == nullptr,
169  "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..) - <mpChangeTrackDeletionTextMarkupList> expected to be NULL." );
170  OSL_ENSURE( mpChangeTrackFormatChangeTextMarkupList == nullptr,
171  "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..) - <mpChangeTrackFormatChangeTextMarkupList> expected to be NULL." );
172  initChangeTrackTextMarkupLists( mrTextFrame,
176  }
177 
178  switch ( nTextMarkupType )
179  {
180  case css::text::TextMarkupType::TRACK_CHANGE_INSERTION:
181  {
182  pChangeTrackingTextMarkupList = mpChangeTrackInsertionTextMarkupList.get();
183  }
184  break;
185  case css::text::TextMarkupType::TRACK_CHANGE_DELETION:
186  {
187  pChangeTrackingTextMarkupList = mpChangeTrackDeletionTextMarkupList.get();
188  }
189  break;
190  case css::text::TextMarkupType::TRACK_CHANGE_FORMATCHANGE:
191  {
192  pChangeTrackingTextMarkupList = mpChangeTrackFormatChangeTextMarkupList.get();
193  }
194  break;
195  default:
196  {
197  OSL_FAIL( "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..)> - misusage - unexpected text markup type for change tracking." );
198  }
199  }
200 
201  return pChangeTrackingTextMarkupList;
202 }
203 
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
bool IsFollow() const
Definition: flowfrm.hxx:166
const SwWrongList * getChangeTrackingTextMarkupList(const sal_Int32 nTextMarkupType)
SwNodeIndex nNode
Definition: pam.hxx:37
bool HasFollow() const
Definition: flowfrm.hxx:165
TextFrameIndex GetOfst() const
Definition: txtfrm.hxx:426
std::unique_ptr< SwWrongList > mpChangeTrackFormatChangeTextMarkupList
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1290
void CalcStartEnd(sal_uLong nNdIdx, sal_Int32 &rStart, sal_Int32 &rEnd) const
Calculates the intersection with text node number nNdIdx.
Definition: docredln.cxx:1264
static bool IsShowChanges(const RedlineFlags eM)
size_type size() const
Definition: docary.hxx:368
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
SwTextFrame * GetFollow()
Definition: txtfrm.hxx:844
SwTextNode * GetTextNodeFirst()
Definition: txtfrm.hxx:445
virtual SwRedlineTable::size_type GetRedlinePos(const SwNode &rNode, RedlineType nType) const =0
vector_type::size_type size_type
Definition: docary.hxx:330
SwParaChangeTrackingInfo(const SwTextFrame &rTextFrame)
std::unique_ptr< SwWrongList > mpChangeTrackInsertionTextMarkupList
const SwPosition * Start() const
Definition: pam.hxx:212
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
RedlineType GetType(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1728
std::unique_ptr< SwWrongList > mpChangeTrackDeletionTextMarkupList
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:416
static constexpr size_type npos
Definition: docary.hxx:331
const sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:61
SwRootFrame * getRootFrame()
Definition: frame.hxx:657