nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / edit / edatmisc.cxx
blob4e26e33773a12da8d97bc7b3e6590051da1a3edf
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 <swundo.hxx>
26 #include <ndtxt.hxx>
29 * hard formatting (Attribute)
32 void SwEditShell::ResetAttr( const o3tl::sorted_vector<sal_uInt16> &attrs, SwPaM* pPaM )
34 CurrShell aCurr( this );
35 SwPaM* pCursor = pPaM ? pPaM : GetCursor( );
37 StartAllAction();
38 bool bUndoGroup = pCursor->GetNext() != pCursor;
39 if( bUndoGroup )
41 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::RESETATTR, nullptr);
44 for(const SwPaM& rCurrentCursor : pCursor->GetRingContainer())
45 GetDoc()->ResetAttrs(rCurrentCursor, true, attrs, true, GetLayout());
47 if( bUndoGroup )
49 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::RESETATTR, nullptr);
51 CallChgLnk();
52 EndAllAction();
55 void SwEditShell::GCAttr()
57 for(SwPaM& rPaM : GetCursor()->GetRingContainer())
59 if ( !rPaM.HasMark() )
61 SwTextNode *const pTextNode =
62 rPaM.GetPoint()->nNode.GetNode().GetTextNode();
63 if (pTextNode)
65 pTextNode->GCAttr();
68 else
70 const SwNodeIndex& rEnd = rPaM.End()->nNode;
71 SwNodeIndex aIdx( rPaM.Start()->nNode );
72 SwNode* pNd = &aIdx.GetNode();
73 do {
74 if( pNd->IsTextNode() )
75 static_cast<SwTextNode*>(pNd)->GCAttr();
77 while( nullptr != ( pNd = GetDoc()->GetNodes().GoNext( &aIdx )) &&
78 aIdx <= rEnd );
83 /// Set the attribute as new default attribute in the document.
84 void SwEditShell::SetDefault( const SfxPoolItem& rFormatHint )
86 // 7502: Action-Parenthesis
87 StartAllAction();
88 GetDoc()->SetDefault( rFormatHint );
89 EndAllAction();
92 /// request the default attribute in this document.
93 const SfxPoolItem& SwEditShell::GetDefault( sal_uInt16 nFormatHint ) const
95 return GetDoc()->GetDefault( nFormatHint );
98 // tdf#122893 turn off ShowChanges mode to apply paragraph formatting permanently with redlining
99 // ie. in all directly preceding deleted paragraphs at the actual cursor positions
100 static void lcl_disableShowChangesIfNeeded( SwDoc *const pDoc, const SwNode& rNode, RedlineFlags &eRedlMode )
102 if ( IDocumentRedlineAccess::IsShowChanges(eRedlMode) &&
103 // is there redlining at beginning of the position (possible redline block before the modified node)
104 pDoc->getIDocumentRedlineAccess().GetRedlinePos( rNode, RedlineType::Any ) <
105 pDoc->getIDocumentRedlineAccess().GetRedlineTable().size() )
107 eRedlMode = RedlineFlags::ShowInsert | RedlineFlags::Ignore;
108 pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
112 void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, SetAttrMode nFlags, const bool bParagraphSetting )
114 CurrShell aCurr( this );
115 StartAllAction();
116 RedlineFlags eRedlMode = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
117 SwPaM* pCursor = GetCursor();
118 if( pCursor->GetNext() != pCursor ) // Ring of Cursors
120 bool bIsTableMode = IsTableMode();
121 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSATTR, nullptr);
123 for(SwPaM& rPaM : GetCursor()->GetRingContainer())
125 if( rPaM.HasMark() && ( bIsTableMode ||
126 *rPaM.GetPoint() != *rPaM.GetMark() ))
128 if (bParagraphSetting)
129 lcl_disableShowChangesIfNeeded( GetDoc(), (*rPaM.Start()).nNode.GetNode(), eRedlMode);
131 GetDoc()->getIDocumentContentOperations().InsertPoolItem(rPaM, rHint, nFlags, GetLayout());
135 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSATTR, nullptr);
137 else
139 if( !HasSelection() )
140 UpdateAttr();
142 if (bParagraphSetting)
143 lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
145 GetDoc()->getIDocumentContentOperations().InsertPoolItem(*pCursor, rHint, nFlags, GetLayout());
147 EndAllAction();
148 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOldMode );
151 void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM* pPaM, const bool bParagraphSetting )
153 CurrShell aCurr( this );
154 SwPaM* pCursor = pPaM ? pPaM : GetCursor();
155 StartAllAction();
156 RedlineFlags eRedlMode = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
157 if( pCursor->GetNext() != pCursor ) // Ring of Cursors
159 bool bIsTableMode = IsTableMode();
160 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSATTR, nullptr);
162 for(SwPaM& rTmpCursor : pCursor->GetRingContainer())
164 if( rTmpCursor.HasMark() && ( bIsTableMode ||
165 *rTmpCursor.GetPoint() != *rTmpCursor.GetMark() ))
167 if (bParagraphSetting)
168 lcl_disableShowChangesIfNeeded( GetDoc(), (*rTmpCursor.Start()).nNode.GetNode(), eRedlMode);
170 GetDoc()->getIDocumentContentOperations().InsertItemSet(rTmpCursor, rSet, nFlags, GetLayout());
174 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSATTR, nullptr);
176 else
178 if( !HasSelection() )
179 UpdateAttr();
181 if (bParagraphSetting)
182 lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
184 GetDoc()->getIDocumentContentOperations().InsertItemSet(*pCursor, rSet, nFlags, GetLayout());
186 EndAllAction();
187 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOldMode );
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */