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 <docary.hxx>
21 #include <redline.hxx>
22 #include <doc.hxx>
23 #include <swundo.hxx>
24 #include <editsh.hxx>
25 #include <edimp.hxx>
26 #include <frmtool.hxx>
27
GetRedlineFlags() const28 RedlineFlags SwEditShell::GetRedlineFlags() const
29 {
30 return GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags();
31 }
32
SetRedlineFlags(RedlineFlags eMode)33 void SwEditShell::SetRedlineFlags( RedlineFlags eMode )
34 {
35 if( eMode != GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags() )
36 {
37 SET_CURR_SHELL( this );
38 StartAllAction();
39 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eMode );
40 EndAllAction();
41 }
42 }
43
IsRedlineOn() const44 bool SwEditShell::IsRedlineOn() const
45 {
46 return GetDoc()->getIDocumentRedlineAccess().IsRedlineOn();
47 }
48
GetRedlineCount() const49 SwRedlineTable::size_type SwEditShell::GetRedlineCount() const
50 {
51 return GetDoc()->getIDocumentRedlineAccess().GetRedlineTable().size();
52 }
53
GetRedline(SwRedlineTable::size_type nPos) const54 const SwRangeRedline& SwEditShell::GetRedline( SwRedlineTable::size_type nPos ) const
55 {
56 return *GetDoc()->getIDocumentRedlineAccess().GetRedlineTable()[ nPos ];
57 }
58
lcl_InvalidateAll(SwViewShell * pSh)59 static void lcl_InvalidateAll( SwViewShell* pSh )
60 {
61 for(SwViewShell& rCurrentShell : pSh->GetRingContainer())
62 {
63 if ( rCurrentShell.GetWin() )
64 rCurrentShell.GetWin()->Invalidate();
65 }
66 }
67
AcceptRedline(SwRedlineTable::size_type nPos)68 bool SwEditShell::AcceptRedline( SwRedlineTable::size_type nPos )
69 {
70 SET_CURR_SHELL( this );
71 StartAllAction();
72 bool bRet = GetDoc()->getIDocumentRedlineAccess().AcceptRedline( nPos, true );
73 if( !nPos && !::IsExtraData( GetDoc() ) )
74 lcl_InvalidateAll( this );
75 EndAllAction();
76 return bRet;
77 }
78
RejectRedline(SwRedlineTable::size_type nPos)79 bool SwEditShell::RejectRedline( SwRedlineTable::size_type nPos )
80 {
81 SET_CURR_SHELL( this );
82 StartAllAction();
83 bool bRet = GetDoc()->getIDocumentRedlineAccess().RejectRedline( nPos, true );
84 if( !nPos && !::IsExtraData( GetDoc() ) )
85 lcl_InvalidateAll( this );
86 EndAllAction();
87 return bRet;
88 }
89
AcceptRedlinesInSelection()90 bool SwEditShell::AcceptRedlinesInSelection()
91 {
92 SET_CURR_SHELL( this );
93 StartAllAction();
94 bool bRet = GetDoc()->getIDocumentRedlineAccess().AcceptRedline( *GetCursor(), true );
95 EndAllAction();
96 return bRet;
97 }
98
RejectRedlinesInSelection()99 bool SwEditShell::RejectRedlinesInSelection()
100 {
101 SET_CURR_SHELL( this );
102 StartAllAction();
103 bool bRet = GetDoc()->getIDocumentRedlineAccess().RejectRedline( *GetCursor(), true );
104 EndAllAction();
105 return bRet;
106 }
107
108 // Set the comment at the Redline
SetRedlineComment(const OUString & rS)109 bool SwEditShell::SetRedlineComment( const OUString& rS )
110 {
111 bool bRet = false;
112 for(const SwPaM& rPaM : GetCursor()->GetRingContainer())
113 {
114 bRet = bRet || GetDoc()->getIDocumentRedlineAccess().SetRedlineComment( rPaM, rS );
115 }
116
117 return bRet;
118 }
119
GetCurrRedline() const120 const SwRangeRedline* SwEditShell::GetCurrRedline() const
121 {
122 if (const SwRangeRedline* pRed = GetDoc()->getIDocumentRedlineAccess().GetRedline( *GetCursor()->GetPoint(), nullptr ))
123 return pRed;
124 // check the other side of the selection to handle completely selected changes, where the Point is at the end
125 return GetDoc()->getIDocumentRedlineAccess().GetRedline( *GetCursor()->GetMark(), nullptr );
126 }
127
UpdateRedlineAttr()128 void SwEditShell::UpdateRedlineAttr()
129 {
130 if( IDocumentRedlineAccess::IsShowChanges(GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags()) )
131 {
132 SET_CURR_SHELL( this );
133 StartAllAction();
134
135 GetDoc()->getIDocumentRedlineAccess().UpdateRedlineAttr();
136
137 EndAllAction();
138 }
139 }
140
141 /** Search the Redline of the data given
142 *
143 * @return Returns the Pos of the Array, or SwRedlineTable::npos if not present
144 */
FindRedlineOfData(const SwRedlineData & rData) const145 SwRedlineTable::size_type SwEditShell::FindRedlineOfData( const SwRedlineData& rData ) const
146 {
147 const SwRedlineTable& rTable = GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
148
149 for( SwRedlineTable::size_type i = 0, nCnt = rTable.size(); i < nCnt; ++i )
150 if( &rTable[ i ]->GetRedlineData() == &rData )
151 return i;
152 return SwRedlineTable::npos;
153 }
154
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
156