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 <edimp.hxx>
26 #include <swundo.hxx>
27 #include <ndtxt.hxx>
28 
29 /*
30  * hard formatting (Attribute)
31  */
32 
33 void SwEditShell::ResetAttr( const std::set<sal_uInt16> &attrs, SwPaM* pPaM )
34 {
35  SET_CURR_SHELL( this );
36  SwPaM* pCursor = pPaM ? pPaM : GetCursor( );
37 
39  bool bUndoGroup = pCursor->GetNext() != pCursor;
40  if( bUndoGroup )
41  {
43  }
44 
45  for(const SwPaM& rCurrentCursor : pCursor->GetRingContainer())
46  GetDoc()->ResetAttrs(rCurrentCursor, true, attrs, true, GetLayout());
47 
48  if( bUndoGroup )
49  {
51  }
52  CallChgLnk();
53  EndAllAction();
54 }
55 
57 {
58  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
59  {
60  if ( !rPaM.HasMark() )
61  {
62  SwTextNode *const pTextNode =
63  rPaM.GetPoint()->nNode.GetNode().GetTextNode();
64  if (pTextNode)
65  {
66  pTextNode->GCAttr();
67  }
68  }
69  else
70  {
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();
77  }
78  while( nullptr != ( pNd = GetDoc()->GetNodes().GoNext( &aIdx )) &&
79  aIdx <= rEnd );
80  }
81  }
82 }
83 
85 void SwEditShell::SetDefault( const SfxPoolItem& rFormatHint )
86 {
87  // 7502: Action-Parenthesis
89  GetDoc()->SetDefault( rFormatHint );
90  EndAllAction();
91 }
92 
94 const SfxPoolItem& SwEditShell::GetDefault( sal_uInt16 nFormatHint ) const
95 {
96  return GetDoc()->GetDefault( nFormatHint );
97 }
98 
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 )
102 {
103  if ( IDocumentRedlineAccess::IsShowChanges(eRedlMode) &&
104  // is there redlining at beginning of the position (possible redline block before the modified node)
107  {
109  pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
110  }
111 }
112 
113 void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, SetAttrMode nFlags, const bool bParagraphSetting )
114 {
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
120  {
121  bool bIsTableMode = IsTableMode();
123 
124  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
125  {
126  if( rPaM.HasMark() && ( bIsTableMode ||
127  *rPaM.GetPoint() != *rPaM.GetMark() ))
128  {
129  if (bParagraphSetting)
130  lcl_disableShowChangesIfNeeded( GetDoc(), (*rPaM.Start()).nNode.GetNode(), eRedlMode);
131 
132  GetDoc()->getIDocumentContentOperations().InsertPoolItem(rPaM, rHint, nFlags, GetLayout());
133  }
134  }
135 
137  }
138  else
139  {
140  if( !HasSelection() )
141  UpdateAttr();
142 
143  if (bParagraphSetting)
144  lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
145 
146  GetDoc()->getIDocumentContentOperations().InsertPoolItem(*pCursor, rHint, nFlags, GetLayout());
147  }
148  EndAllAction();
150 }
151 
152 void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM* pPaM, const bool bParagraphSetting )
153 {
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
159  {
160  bool bIsTableMode = IsTableMode();
162 
163  for(SwPaM& rTmpCursor : pCursor->GetRingContainer())
164  {
165  if( rTmpCursor.HasMark() && ( bIsTableMode ||
166  *rTmpCursor.GetPoint() != *rTmpCursor.GetMark() ))
167  {
168  if (bParagraphSetting)
169  lcl_disableShowChangesIfNeeded( GetDoc(), (*rTmpCursor.Start()).nNode.GetNode(), eRedlMode);
170 
171  GetDoc()->getIDocumentContentOperations().InsertItemSet(rTmpCursor, rSet, nFlags, GetLayout());
172  }
173  }
174 
176  }
177  else
178  {
179  if( !HasSelection() )
180  UpdateAttr();
181 
182  if (bParagraphSetting)
183  lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
184 
185  GetDoc()->getIDocumentContentOperations().InsertItemSet(*pCursor, rSet, nFlags, GetLayout());
186  }
187  EndAllAction();
189 }
190 
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetDefault(const SfxPoolItem &)
Set attribute as new default attribute in document.
Definition: edatmisc.cxx:85
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:256
const SwNodes & GetNodes() const
Definition: viewsh.cxx:2089
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:184
bool IsTableMode() const
Definition: crsrsh.hxx:646
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:152
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:185
void UpdateAttr()
Definition: crsrsh.hxx:760
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:176
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:347
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:672
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:94
bool GoNext(SwNode *pNd, SwIndex *pIdx, sal_uInt16 nMode)
Definition: pam.cxx:268
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:113
#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:544
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:367
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:56
static void lcl_disableShowChangesIfNeeded(SwDoc *const pDoc, const SwNode &rNode, RedlineFlags &eRedlMode)
Definition: edatmisc.cxx:101
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:33
virtual const SwRedlineTable & GetRedlineTable() const =0
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2071
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:843
Base class of the Writer document model elements.
Definition: node.hxx:79