Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / edit / edredln.cxx
blob835a1c37389c27e8bfb08e231d1a6cb405858645
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 <IDocumentRedlineAccess.hxx>
21 #include <docary.hxx>
22 #include <redline.hxx>
23 #include <doc.hxx>
24 #include <editsh.hxx>
25 #include <frmtool.hxx>
27 RedlineFlags SwEditShell::GetRedlineFlags() const
29 return GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags();
32 void SwEditShell::SetRedlineFlags( RedlineFlags eMode )
34 if( eMode != GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags() )
36 CurrShell aCurr( this );
37 StartAllAction();
38 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eMode );
39 EndAllAction();
43 bool SwEditShell::IsRedlineOn() const
45 return GetDoc()->getIDocumentRedlineAccess().IsRedlineOn();
48 SwRedlineTable::size_type SwEditShell::GetRedlineCount() const
50 return GetDoc()->getIDocumentRedlineAccess().GetRedlineTable().size();
53 const SwRangeRedline& SwEditShell::GetRedline( SwRedlineTable::size_type nPos ) const
55 return *GetDoc()->getIDocumentRedlineAccess().GetRedlineTable()[ nPos ];
58 static void lcl_InvalidateAll( SwViewShell* pSh )
60 for(SwViewShell& rCurrentShell : pSh->GetRingContainer())
62 if ( rCurrentShell.GetWin() )
63 rCurrentShell.GetWin()->Invalidate();
67 bool SwEditShell::AcceptRedline( SwRedlineTable::size_type nPos )
69 CurrShell aCurr( this );
70 StartAllAction();
71 bool bRet = GetDoc()->getIDocumentRedlineAccess().AcceptRedline( nPos, true );
72 if( !nPos && !::IsExtraData( GetDoc() ) )
73 lcl_InvalidateAll( this );
74 EndAllAction();
75 return bRet;
78 bool SwEditShell::RejectRedline( SwRedlineTable::size_type nPos )
80 CurrShell aCurr( this );
81 StartAllAction();
82 bool bRet = GetDoc()->getIDocumentRedlineAccess().RejectRedline( nPos, true );
83 if( !nPos && !::IsExtraData( GetDoc() ) )
84 lcl_InvalidateAll( this );
85 EndAllAction();
86 return bRet;
89 bool SwEditShell::AcceptRedlinesInSelection()
91 CurrShell aCurr( this );
92 StartAllAction();
93 // in table selection mode, process the selected boxes in reverse order
94 // to allow accepting their text changes and the tracked row deletions
95 bool bRet = false;
96 if ( IsTableMode() )
98 const SwSelBoxes& rBoxes = GetTableCursor()->GetSelectedBoxes();
99 std::vector<std::unique_ptr<SwPaM>> vBoxes;
100 for(auto pBox : rBoxes)
102 if ( !pBox->IsEmpty() )
104 const SwStartNode *pSttNd = pBox->GetSttNd();
105 SwNode* pEndNode = pSttNd->GetNodes()[pSttNd->EndOfSectionIndex()];
106 vBoxes.push_back(std::unique_ptr<SwPaM>(new SwPaM(*pEndNode, 0, *pSttNd, 0)));
110 for (size_t i = 0; i < vBoxes.size(); ++i)
111 bRet |= GetDoc()->getIDocumentRedlineAccess().AcceptRedline( *vBoxes[vBoxes.size()-i-1], true );
113 else
114 bRet = GetDoc()->getIDocumentRedlineAccess().AcceptRedline( *GetCursor(), true );
115 EndAllAction();
116 return bRet;
119 bool SwEditShell::RejectRedlinesInSelection()
121 CurrShell aCurr( this );
122 StartAllAction();
123 bool bRet = false;
124 // in table selection mode, process the selected boxes in reverse order
125 // to allow rejecting their text changes and the tracked row insertions
126 if ( IsTableMode() )
128 const SwSelBoxes& rBoxes = GetTableCursor()->GetSelectedBoxes();
129 std::vector<std::unique_ptr<SwPaM>> vBoxes;
130 for(auto pBox : rBoxes)
132 if ( !pBox->IsEmpty() )
134 const SwStartNode *pSttNd = pBox->GetSttNd();
135 SwNode* pEndNode = pSttNd->GetNodes()[pSttNd->EndOfSectionIndex()];
136 vBoxes.push_back(std::unique_ptr<SwPaM>(new SwPaM(*pEndNode, 0, *pSttNd, 0)));
140 for (size_t i = 0; i < vBoxes.size(); ++i)
141 bRet |= GetDoc()->getIDocumentRedlineAccess().RejectRedline( *vBoxes[vBoxes.size()-i-1], true );
143 else
144 bRet = GetDoc()->getIDocumentRedlineAccess().RejectRedline( *GetCursor(), true );
145 EndAllAction();
146 return bRet;
149 // Set the comment at the Redline
150 bool SwEditShell::SetRedlineComment( const OUString& rS )
152 bool bRet = false;
153 for(const SwPaM& rPaM : GetCursor()->GetRingContainer())
155 bRet = bRet || GetDoc()->getIDocumentRedlineAccess().SetRedlineComment( rPaM, rS );
158 return bRet;
161 const SwRangeRedline* SwEditShell::GetCurrRedline() const
163 if (const SwRangeRedline* pRed = GetDoc()->getIDocumentRedlineAccess().GetRedline( *GetCursor()->GetPoint(), nullptr ))
164 return pRed;
165 // check the other side of the selection to handle completely selected changes, where the Point is at the end
166 return GetDoc()->getIDocumentRedlineAccess().GetRedline( *GetCursor()->GetMark(), nullptr );
169 void SwEditShell::UpdateRedlineAttr()
171 if( IDocumentRedlineAccess::IsShowChanges(GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags()) )
173 CurrShell aCurr( this );
174 StartAllAction();
176 GetDoc()->getIDocumentRedlineAccess().UpdateRedlineAttr();
178 EndAllAction();
182 /** Search the Redline of the data given
184 * @return Returns the Pos of the Array, or SwRedlineTable::npos if not present
186 SwRedlineTable::size_type SwEditShell::FindRedlineOfData( const SwRedlineData& rData ) const
188 const SwRedlineTable& rTable = GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
190 for( SwRedlineTable::size_type i = 0, nCnt = rTable.size(); i < nCnt; ++i )
191 if( &rTable[ i ]->GetRedlineData() == &rData )
192 return i;
193 return SwRedlineTable::npos;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */