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