LibreOffice Module sw (master)  1
edatmisc.cxx
Go to the documentation of this file.
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 <editsh.hxx>
21 #include <doc.hxx>
22 #include <IDocumentUndoRedo.hxx>
24 #include <pam.hxx>
25 #include <swundo.hxx>
26 #include <ndtxt.hxx>
27 
28 /*
29  * hard formatting (Attribute)
30  */
31 
32 void SwEditShell::ResetAttr( const std::set<sal_uInt16> &attrs, SwPaM* pPaM )
33 {
34  SET_CURR_SHELL( this );
35  SwPaM* pCursor = pPaM ? pPaM : GetCursor( );
36 
38  bool bUndoGroup = pCursor->GetNext() != pCursor;
39  if( bUndoGroup )
40  {
42  }
43 
44  for(const SwPaM& rCurrentCursor : pCursor->GetRingContainer())
45  GetDoc()->ResetAttrs(rCurrentCursor, true, attrs, true, GetLayout());
46 
47  if( bUndoGroup )
48  {
50  }
51  CallChgLnk();
52  EndAllAction();
53 }
54 
56 {
57  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
58  {
59  if ( !rPaM.HasMark() )
60  {
61  SwTextNode *const pTextNode =
62  rPaM.GetPoint()->nNode.GetNode().GetTextNode();
63  if (pTextNode)
64  {
65  pTextNode->GCAttr();
66  }
67  }
68  else
69  {
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();
76  }
77  while( nullptr != ( pNd = GetDoc()->GetNodes().GoNext( &aIdx )) &&
78  aIdx <= rEnd );
79  }
80  }
81 }
82 
84 void SwEditShell::SetDefault( const SfxPoolItem& rFormatHint )
85 {
86  // 7502: Action-Parenthesis
88  GetDoc()->SetDefault( rFormatHint );
89  EndAllAction();
90 }
91 
93 const SfxPoolItem& SwEditShell::GetDefault( sal_uInt16 nFormatHint ) const
94 {
95  return GetDoc()->GetDefault( nFormatHint );
96 }
97 
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 )
101 {
102  if ( IDocumentRedlineAccess::IsShowChanges(eRedlMode) &&
103  // is there redlining at beginning of the position (possible redline block before the modified node)
106  {
108  pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
109  }
110 }
111 
112 void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, SetAttrMode nFlags, const bool bParagraphSetting )
113 {
114  SET_CURR_SHELL( this );
115  StartAllAction();
116  RedlineFlags eRedlMode = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
117  SwPaM* pCursor = GetCursor();
118  if( pCursor->GetNext() != pCursor ) // Ring of Cursors
119  {
120  bool bIsTableMode = IsTableMode();
122 
123  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
124  {
125  if( rPaM.HasMark() && ( bIsTableMode ||
126  *rPaM.GetPoint() != *rPaM.GetMark() ))
127  {
128  if (bParagraphSetting)
129  lcl_disableShowChangesIfNeeded( GetDoc(), (*rPaM.Start()).nNode.GetNode(), eRedlMode);
130 
131  GetDoc()->getIDocumentContentOperations().InsertPoolItem(rPaM, rHint, nFlags, GetLayout());
132  }
133  }
134 
136  }
137  else
138  {
139  if( !HasSelection() )
140  UpdateAttr();
141 
142  if (bParagraphSetting)
143  lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
144 
145  GetDoc()->getIDocumentContentOperations().InsertPoolItem(*pCursor, rHint, nFlags, GetLayout());
146  }
147  EndAllAction();
149 }
150 
151 void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM* pPaM, const bool bParagraphSetting )
152 {
153  SET_CURR_SHELL( 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
158  {
159  bool bIsTableMode = IsTableMode();
161 
162  for(SwPaM& rTmpCursor : pCursor->GetRingContainer())
163  {
164  if( rTmpCursor.HasMark() && ( bIsTableMode ||
165  *rTmpCursor.GetPoint() != *rTmpCursor.GetMark() ))
166  {
167  if (bParagraphSetting)
168  lcl_disableShowChangesIfNeeded( GetDoc(), (*rTmpCursor.Start()).nNode.GetNode(), eRedlMode);
169 
170  GetDoc()->getIDocumentContentOperations().InsertItemSet(rTmpCursor, rSet, nFlags, GetLayout());
171  }
172  }
173 
175  }
176  else
177  {
178  if( !HasSelection() )
179  UpdateAttr();
180 
181  if (bParagraphSetting)
182  lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
183 
184  GetDoc()->getIDocumentContentOperations().InsertItemSet(*pCursor, rSet, nFlags, GetLayout());
185  }
186  EndAllAction();
188 }
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetDefault(const SfxPoolItem &)
Set attribute as new default attribute in document.
Definition: edatmisc.cxx:84
void ResetAttrs(const SwPaM &rRg, bool bTextAttr=true, const std::set< sal_uInt16 > &rAttrs=std::set< sal_uInt16 >(), const bool bSendDataChangedEvents=true, SwRootFrame const *pLayout=nullptr)
Reset attributes.
Definition: docfmt.cxx:239
const SwNodes & GetNodes() const
Definition: viewsh.cxx:2093
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:184
bool IsTableMode() const
Definition: crsrsh.hxx:647
virtual void InsertItemSet(const SwPaM &rRg, const SfxItemSet &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr)=0
void GCAttr()
Definition: ndtxt.cxx:2767
void SetAttrSet(const SfxItemSet &, SetAttrMode nFlags=SetAttrMode::DEFAULT, SwPaM *pCursor=nullptr, const bool bParagraphSetting=false)
Definition: edatmisc.cxx:151
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:185
void UpdateAttr()
Definition: crsrsh.hxx:761
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:143
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:314
void EndAllAction()
Definition: edws.cxx:96
bool HasSelection() const
Does the current cursor create a selection?
Definition: crsrsh.cxx:2486
static bool IsShowChanges(const RedlineFlags eM)
show all inserts
size_type size() const
Definition: docary.hxx:368
const SfxPoolItem & GetDefault(sal_uInt16 nFormatHint) const
Get the default attribute in this document.
Definition: docfmt.cxx:650
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
SwPaM * GetNext()
Definition: pam.hxx:264
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual SwRedlineTable::size_type GetRedlinePos(const SwNode &rNode, RedlineType nType) const =0
const SfxPoolItem & GetDefault(sal_uInt16 nFormatHint) const
Query default attribute of document.
Definition: edatmisc.cxx:93
bool GoNext(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:272
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
SetAttrMode
Definition: swtypes.hxx:143
void SetAttrItem(const SfxPoolItem &, SetAttrMode nFlags=SetAttrMode::DEFAULT, const bool bParagraphSetting=false)
Definition: edatmisc.cxx:112
#define SET_CURR_SHELL(shell)
Definition: swtypes.hxx:101
Marks a node in the document model.
Definition: ndindex.hxx:31
ring_container GetRingContainer()
Definition: ring.hxx:240
const SwPosition * Start() const
Definition: pam.hxx:212
ignore Redlines
void CallChgLnk()
Definition: crsrsh.cxx:2492
void SetDefault(const SfxPoolItem &)
Set attribute as new default attribute in current document.
Definition: docfmt.cxx:524
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:334
virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr, bool bExpandCharToPara=false, SwTextAttr **ppNewTextAttr=nullptr)=0
Insert an attribute.
virtual void SetRedlineFlags(RedlineFlags eMode)=0
Set a new redline mode.
void GCAttr()
Definition: edatmisc.cxx:55
static void lcl_disableShowChangesIfNeeded(SwDoc *const pDoc, const SwNode &rNode, RedlineFlags &eRedlMode)
Definition: edatmisc.cxx:100
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
void ResetAttr(const std::set< sal_uInt16 > &attrs=std::set< sal_uInt16 >(), SwPaM *pCursor=nullptr)
Definition: edatmisc.cxx:32
virtual const SwRedlineTable & GetRedlineTable() const =0
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2075
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:842
Base class of the Writer document model elements.
Definition: node.hxx:79