android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / access / parachangetrackinginfo.cxx
blobb20d9702e744dd1b7735f062b55e050bdded43b6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "parachangetrackinginfo.hxx"
22 #include <wrong.hxx>
23 #include <com/sun/star/text/TextMarkupType.hpp>
24 #include <osl/diagnose.h>
26 #include <txtfrm.hxx>
27 #include <rootfrm.hxx>
28 #include <ndtxt.hxx>
29 #include <IDocumentRedlineAccess.hxx>
30 #include <docary.hxx>
31 #include <redline.hxx>
33 #include <algorithm>
35 namespace {
36 void initChangeTrackTextMarkupLists( const SwTextFrame& rTextFrame,
37 std::unique_ptr<SwWrongList>& opChangeTrackInsertionTextMarkupList,
38 std::unique_ptr<SwWrongList>& opChangeTrackDeletionTextMarkupList,
39 std::unique_ptr<SwWrongList>& opChangeTrackFormatChangeTextMarkupList )
41 opChangeTrackInsertionTextMarkupList.reset( new SwWrongList( WRONGLIST_CHANGETRACKING ) );
42 opChangeTrackDeletionTextMarkupList.reset( new SwWrongList( WRONGLIST_CHANGETRACKING ) );
43 opChangeTrackFormatChangeTextMarkupList.reset( new SwWrongList( WRONGLIST_CHANGETRACKING ) );
45 if (!rTextFrame.GetTextNodeFirst())
47 OSL_FAIL( "<initChangeTrackTextMarkupLists(..) - missing <SwTextNode> instance!" );
48 return;
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()));
54 const IDocumentRedlineAccess& rIDocChangeTrack( rTextNode.getIDocumentRedlineAccess() );
56 if (!IDocumentRedlineAccess::IsShowChanges(rIDocChangeTrack.GetRedlineFlags())
57 || rTextFrame.getRootFrame()->IsHideRedlines()
58 || rIDocChangeTrack.GetRedlineTable().empty())
60 // nothing to do --> empty change track text markup lists.
61 return;
64 const SwRedlineTable::size_type nIdxOfFirstRedlineForTextNode =
65 rIDocChangeTrack.GetRedlinePos( rTextNode, RedlineType::Any );
66 if ( nIdxOfFirstRedlineForTextNode == SwRedlineTable::npos )
68 // nothing to do --> empty change track text markup lists.
69 return;
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();
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)
88 const SwRangeRedline* pActRedline = rRedlineTable[ nActRedline ];
89 if ( pActRedline->Start()->GetNode() > rTextNode )
91 break;
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 )
102 // Consider only redlines which overlap with the text frame's text.
103 continue;
106 SwWrongList* pMarkupList( nullptr );
107 switch ( pActRedline->GetType() )
109 case RedlineType::Insert:
111 pMarkupList = opChangeTrackInsertionTextMarkupList.get();
113 break;
114 case RedlineType::Delete:
116 pMarkupList = opChangeTrackDeletionTextMarkupList.get();
118 break;
119 case RedlineType::Format:
121 pMarkupList = opChangeTrackFormatChangeTextMarkupList.get();
123 break;
124 default:
126 // other types are not considered
129 if ( pMarkupList )
131 const sal_Int32 nTextFrameChangeTrackStart =
132 std::max(nTextNodeChangeTrackStart, nTextFrameTextStartPos);
134 const sal_Int32 nTextFrameChangeTrackEnd =
135 std::min(nTextNodeChangeTrackEnd, nTextFrameTextEndPos);
137 pMarkupList->Insert( OUString(), nullptr,
138 nTextFrameChangeTrackStart,
139 nTextFrameChangeTrackEnd - nTextFrameChangeTrackStart,
140 pMarkupList->Count() );
142 } // eof iteration over the redlines which overlap with the text node
144 } // eof anonymous namespace
146 SwParaChangeTrackingInfo::SwParaChangeTrackingInfo( const SwTextFrame& rTextFrame )
147 : mrTextFrame( rTextFrame )
151 SwParaChangeTrackingInfo::~SwParaChangeTrackingInfo()
153 reset();
156 void SwParaChangeTrackingInfo::reset()
158 mpChangeTrackInsertionTextMarkupList.reset();
159 mpChangeTrackDeletionTextMarkupList.reset();
160 mpChangeTrackFormatChangeTextMarkupList.reset();
163 const SwWrongList* SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList( const sal_Int32 nTextMarkupType )
165 SwWrongList* pChangeTrackingTextMarkupList = nullptr;
167 if ( mpChangeTrackInsertionTextMarkupList == nullptr )
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,
174 mpChangeTrackInsertionTextMarkupList,
175 mpChangeTrackDeletionTextMarkupList,
176 mpChangeTrackFormatChangeTextMarkupList );
179 switch ( nTextMarkupType )
181 case css::text::TextMarkupType::TRACK_CHANGE_INSERTION:
183 pChangeTrackingTextMarkupList = mpChangeTrackInsertionTextMarkupList.get();
185 break;
186 case css::text::TextMarkupType::TRACK_CHANGE_DELETION:
188 pChangeTrackingTextMarkupList = mpChangeTrackDeletionTextMarkupList.get();
190 break;
191 case css::text::TextMarkupType::TRACK_CHANGE_FORMATCHANGE:
193 pChangeTrackingTextMarkupList = mpChangeTrackFormatChangeTextMarkupList.get();
195 break;
196 default:
198 OSL_FAIL( "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..)> - misusage - unexpected text markup type for change tracking." );
202 return pChangeTrackingTextMarkupList;
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */