loplugin:constvars in sw
[LibreOffice.git] / sw / source / core / edit / edatmisc.cxx
blobe8f82956106fb808ec1639f54de79b39e8778e88
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 <editsh.hxx>
21 #include <doc.hxx>
22 #include <IDocumentUndoRedo.hxx>
23 #include <IDocumentRedlineAccess.hxx>
24 #include <pam.hxx>
25 #include <edimp.hxx>
26 #include <swundo.hxx>
27 #include <ndtxt.hxx>
30 * hard formatting (Attribute)
33 void SwEditShell::ResetAttr( const std::set<sal_uInt16> &attrs, SwPaM* pPaM )
35 SET_CURR_SHELL( this );
36 SwPaM* pCursor = pPaM ? pPaM : GetCursor( );
38 StartAllAction();
39 bool bUndoGroup = pCursor->GetNext() != pCursor;
40 if( bUndoGroup )
42 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::RESETATTR, nullptr);
45 for(const SwPaM& rCurrentCursor : pCursor->GetRingContainer())
46 GetDoc()->ResetAttrs(rCurrentCursor, true, attrs, true, GetLayout());
48 if( bUndoGroup )
50 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::RESETATTR, nullptr);
52 CallChgLnk();
53 EndAllAction();
56 void SwEditShell::GCAttr()
58 for(SwPaM& rPaM : GetCursor()->GetRingContainer())
60 if ( !rPaM.HasMark() )
62 SwTextNode *const pTextNode =
63 rPaM.GetPoint()->nNode.GetNode().GetTextNode();
64 if (pTextNode)
66 pTextNode->GCAttr();
69 else
71 const SwNodeIndex& rEnd = rPaM.End()->nNode;
72 SwNodeIndex aIdx( rPaM.Start()->nNode );
73 SwNode* pNd = &aIdx.GetNode();
74 do {
75 if( pNd->IsTextNode() )
76 static_cast<SwTextNode*>(pNd)->GCAttr();
78 while( nullptr != ( pNd = GetDoc()->GetNodes().GoNext( &aIdx )) &&
79 aIdx <= rEnd );
84 /// Set the attribute as new default attribute in the document.
85 void SwEditShell::SetDefault( const SfxPoolItem& rFormatHint )
87 // 7502: Action-Parenthesis
88 StartAllAction();
89 GetDoc()->SetDefault( rFormatHint );
90 EndAllAction();
93 /// request the default attribute in this document.
94 const SfxPoolItem& SwEditShell::GetDefault( sal_uInt16 nFormatHint ) const
96 return GetDoc()->GetDefault( nFormatHint );
99 // tdf#122893 turn off ShowChanges mode to apply paragraph formatting permanently with redlining
100 // ie. in all directly preceding deleted paragraphs at the actual cursor positions
101 static void lcl_disableShowChangesIfNeeded( SwDoc *const pDoc, const SwNode& rNode, RedlineFlags &eRedlMode )
103 if ( IDocumentRedlineAccess::IsShowChanges(eRedlMode) &&
104 // is there redlining at beginning of the position (possible redline block before the modified node)
105 pDoc->getIDocumentRedlineAccess().GetRedlinePos( rNode, RedlineType::Any ) <
106 pDoc->getIDocumentRedlineAccess().GetRedlineTable().size() )
108 eRedlMode = RedlineFlags::ShowInsert | RedlineFlags::Ignore;
109 pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
113 void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, SetAttrMode nFlags, const bool bParagraphSetting )
115 SET_CURR_SHELL( this );
116 StartAllAction();
117 RedlineFlags eRedlMode = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
118 SwPaM* pCursor = GetCursor();
119 if( pCursor->GetNext() != pCursor ) // Ring of Cursors
121 bool bIsTableMode = IsTableMode();
122 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSATTR, nullptr);
124 for(SwPaM& rPaM : GetCursor()->GetRingContainer())
126 if( rPaM.HasMark() && ( bIsTableMode ||
127 *rPaM.GetPoint() != *rPaM.GetMark() ))
129 if (bParagraphSetting)
130 lcl_disableShowChangesIfNeeded( GetDoc(), (*rPaM.Start()).nNode.GetNode(), eRedlMode);
132 GetDoc()->getIDocumentContentOperations().InsertPoolItem(rPaM, rHint, nFlags, GetLayout());
136 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSATTR, nullptr);
138 else
140 if( !HasSelection() )
141 UpdateAttr();
143 if (bParagraphSetting)
144 lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
146 GetDoc()->getIDocumentContentOperations().InsertPoolItem(*pCursor, rHint, nFlags, GetLayout());
148 EndAllAction();
149 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOldMode );
152 void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM* pPaM, const bool bParagraphSetting )
154 SET_CURR_SHELL( this );
155 SwPaM* pCursor = pPaM ? pPaM : GetCursor();
156 StartAllAction();
157 RedlineFlags eRedlMode = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
158 if( pCursor->GetNext() != pCursor ) // Ring of Cursors
160 bool bIsTableMode = IsTableMode();
161 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSATTR, nullptr);
163 for(SwPaM& rTmpCursor : pCursor->GetRingContainer())
165 if( rTmpCursor.HasMark() && ( bIsTableMode ||
166 *rTmpCursor.GetPoint() != *rTmpCursor.GetMark() ))
168 if (bParagraphSetting)
169 lcl_disableShowChangesIfNeeded( GetDoc(), (*rTmpCursor.Start()).nNode.GetNode(), eRedlMode);
171 GetDoc()->getIDocumentContentOperations().InsertItemSet(rTmpCursor, rSet, nFlags, GetLayout());
175 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSATTR, nullptr);
177 else
179 if( !HasSelection() )
180 UpdateAttr();
182 if (bParagraphSetting)
183 lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
185 GetDoc()->getIDocumentContentOperations().InsertItemSet(*pCursor, rSet, nFlags, GetLayout());
187 EndAllAction();
188 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOldMode );
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */