Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / edit / edatmisc.cxx
blobcfc465fce8376473dd6e3552106442b08bfc0ed2
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()->GetNode().GetTextNode();
63 if (pTextNode)
65 pTextNode->GCAttr();
68 else
70 const SwNode& rEnd = rPaM.End()->GetNode();
71 SwNodeIndex aIdx( rPaM.Start()->GetNode() );
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 void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, SetAttrMode nFlags, const bool /*bParagraphSetting*/ )
100 CurrShell aCurr( this );
101 StartAllAction();
102 SwPaM* pCursor = GetCursor();
103 if( pCursor->GetNext() != pCursor ) // Ring of Cursors
105 bool bIsTableMode = IsTableMode();
106 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSATTR, nullptr);
108 for(SwPaM& rPaM : GetCursor()->GetRingContainer())
110 if( rPaM.HasMark() && ( bIsTableMode ||
111 *rPaM.GetPoint() != *rPaM.GetMark() ))
113 GetDoc()->getIDocumentContentOperations().InsertPoolItem(rPaM, rHint, nFlags, GetLayout());
117 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSATTR, nullptr);
119 else
121 if( !HasSelection() )
122 UpdateAttr();
124 GetDoc()->getIDocumentContentOperations().InsertPoolItem(*pCursor, rHint, nFlags, GetLayout());
126 EndAllAction();
129 void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM* pPaM, const bool /*bParagraphSetting*/ )
131 CurrShell aCurr( this );
132 SwPaM* pCursor = pPaM ? pPaM : GetCursor();
133 StartAllAction();
134 if( pCursor->GetNext() != pCursor ) // Ring of Cursors
136 bool bIsTableMode = IsTableMode();
137 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSATTR, nullptr);
139 for(SwPaM& rTmpCursor : pCursor->GetRingContainer())
141 if( rTmpCursor.HasMark() && ( bIsTableMode ||
142 *rTmpCursor.GetPoint() != *rTmpCursor.GetMark() ))
144 GetDoc()->getIDocumentContentOperations().InsertItemSet(rTmpCursor, rSet, nFlags, GetLayout());
148 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSATTR, nullptr);
150 else
152 if( !HasSelection() )
153 UpdateAttr();
155 GetDoc()->getIDocumentContentOperations().InsertItemSet(*pCursor, rSet, nFlags, GetLayout());
157 EndAllAction();
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */