1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <IDocumentUndoRedo.hxx>
23 #include <IDocumentRedlineAccess.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( );
39 bool bUndoGroup
= pCursor
->GetNext() != pCursor
;
42 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::RESETATTR
, nullptr);
45 for(const SwPaM
& rCurrentCursor
: pCursor
->GetRingContainer())
46 GetDoc()->ResetAttrs(rCurrentCursor
, true, attrs
, true, GetLayout());
50 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::RESETATTR
, nullptr);
56 void SwEditShell::GCAttr()
58 for(SwPaM
& rPaM
: GetCursor()->GetRingContainer())
60 if ( !rPaM
.HasMark() )
62 SwTextNode
*const pTextNode
=
63 rPaM
.GetPoint()->nNode
.GetNode().GetTextNode();
71 const SwNodeIndex
& rEnd
= rPaM
.End()->nNode
;
72 SwNodeIndex
aIdx( rPaM
.Start()->nNode
);
73 SwNode
* pNd
= &aIdx
.GetNode();
75 if( pNd
->IsTextNode() )
76 static_cast<SwTextNode
*>(pNd
)->GCAttr();
78 while( nullptr != ( pNd
= GetDoc()->GetNodes().GoNext( &aIdx
)) &&
84 /// Set the attribute as new default attribute in the document.
85 void SwEditShell::SetDefault( const SfxPoolItem
& rFormatHint
)
87 // 7502: Action-Parenthesis
89 GetDoc()->SetDefault( rFormatHint
);
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 );
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);
140 if( !HasSelection() )
143 if (bParagraphSetting
)
144 lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor
->Start()).nNode
.GetNode(), eRedlMode
);
146 GetDoc()->getIDocumentContentOperations().InsertPoolItem(*pCursor
, rHint
, nFlags
, GetLayout());
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();
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);
179 if( !HasSelection() )
182 if (bParagraphSetting
)
183 lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor
->Start()).nNode
.GetNode(), eRedlMode
);
185 GetDoc()->getIDocumentContentOperations().InsertItemSet(*pCursor
, rSet
, nFlags
, GetLayout());
188 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOldMode
);
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */