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
33{
34 CurrShell aCurr( this );
35 SwPaM* pCursor = pPaM ? pPaM : GetCursor( );
36
38 bool bUndoGroup = pCursor->GetNext() != pCursor;
39 if( bUndoGroup )
40 {
41 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::RESETATTR, nullptr);
42 }
43
44 for(const SwPaM& rCurrentCursor : pCursor->GetRingContainer())
45 GetDoc()->ResetAttrs(rCurrentCursor, true, attrs, true, GetLayout());
46
47 if( bUndoGroup )
48 {
49 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::RESETATTR, nullptr);
50 }
51 CallChgLnk();
53}
54
56{
57 for(SwPaM& rPaM : GetCursor()->GetRingContainer())
58 {
59 if ( !rPaM.HasMark() )
60 {
61 SwTextNode *const pTextNode =
62 rPaM.GetPoint()->GetNode().GetTextNode();
63 if (pTextNode)
64 {
65 pTextNode->GCAttr();
66 }
67 }
68 else
69 {
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();
76 }
77 while( nullptr != ( pNd = GetDoc()->GetNodes().GoNext( &aIdx )) &&
78 aIdx <= rEnd );
79 }
80 }
81}
82
84void SwEditShell::SetDefault( const SfxPoolItem& rFormatHint )
85{
86 // 7502: Action-Parenthesis
88 GetDoc()->SetDefault( rFormatHint );
90}
91
93const SfxPoolItem& SwEditShell::GetDefault( sal_uInt16 nFormatHint ) const
94{
95 return GetDoc()->GetDefault( nFormatHint );
96}
97
98void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, SetAttrMode nFlags, const bool /*bParagraphSetting*/ )
99{
100 CurrShell aCurr( this );
102 SwPaM* pCursor = GetCursor();
103 if( pCursor->GetNext() != pCursor ) // Ring of Cursors
104 {
105 bool bIsTableMode = IsTableMode();
106 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSATTR, nullptr);
107
108 for(SwPaM& rPaM : GetCursor()->GetRingContainer())
109 {
110 if( rPaM.HasMark() && ( bIsTableMode ||
111 *rPaM.GetPoint() != *rPaM.GetMark() ))
112 {
114 }
115 }
116
117 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSATTR, nullptr);
118 }
119 else
120 {
121 if( !HasSelection() )
122 UpdateAttr();
123
124 GetDoc()->getIDocumentContentOperations().InsertPoolItem(*pCursor, rHint, nFlags, GetLayout());
125 }
126 EndAllAction();
127}
128
129void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM* pPaM, const bool /*bParagraphSetting*/ )
130{
131 CurrShell aCurr( this );
132 SwPaM* pCursor = pPaM ? pPaM : GetCursor();
134 if( pCursor->GetNext() != pCursor ) // Ring of Cursors
135 {
136 bool bIsTableMode = IsTableMode();
137 GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSATTR, nullptr);
138
139 for(SwPaM& rTmpCursor : pCursor->GetRingContainer())
140 {
141 if( rTmpCursor.HasMark() && ( bIsTableMode ||
142 *rTmpCursor.GetPoint() != *rTmpCursor.GetMark() ))
143 {
145 }
146 }
147
148 GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSATTR, nullptr);
149 }
150 else
151 {
152 if( !HasSelection() )
153 UpdateAttr();
154
156 }
157 EndAllAction();
158}
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void InsertItemSet(const SwPaM &rRg, const SfxItemSet &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr)=0
virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr, SwTextAttr **ppNewTextAttr=nullptr)=0
Insert an attribute.
bool HasSelection() const
Does the current cursor create a selection?
Definition: crsrsh.cxx:2838
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
void UpdateAttr()
Definition: crsrsh.hxx:787
void CallChgLnk()
Definition: crsrsh.cxx:2847
bool IsTableMode() const
Definition: crsrsh.hxx:668
void SetDefault(const SfxPoolItem &)
Set attribute as new default attribute in current document.
Definition: docfmt.cxx:548
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:329
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:158
const SfxPoolItem & GetDefault(sal_uInt16 nFormatHint) const
Get the default attribute in this document.
Definition: docfmt.cxx:672
void ResetAttrs(const SwPaM &rRg, bool bTextAttr=true, const o3tl::sorted_vector< sal_uInt16 > &rAttrs=o3tl::sorted_vector< sal_uInt16 >(), const bool bSendDataChangedEvents=true, SwRootFrame const *pLayout=nullptr)
Reset attributes.
Definition: docfmt.cxx:249
void GCAttr()
Definition: edatmisc.cxx:55
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
const SfxPoolItem & GetDefault(sal_uInt16 nFormatHint) const
Query default attribute of document.
Definition: edatmisc.cxx:93
void SetAttrItem(const SfxPoolItem &, SetAttrMode nFlags=SetAttrMode::DEFAULT, const bool bParagraphSetting=false)
Definition: edatmisc.cxx:98
void SetAttrSet(const SfxItemSet &, SetAttrMode nFlags=SetAttrMode::DEFAULT, SwPaM *pCursor=nullptr, const bool bParagraphSetting=false)
Definition: edatmisc.cxx:129
void SetDefault(const SfxPoolItem &)
Set attribute as new default attribute in document.
Definition: edatmisc.cxx:84
void ResetAttr(const o3tl::sorted_vector< sal_uInt16 > &attrs=o3tl::sorted_vector< sal_uInt16 >(), SwPaM *pCursor=nullptr)
Definition: edatmisc.cxx:32
void EndAllAction()
Definition: edws.cxx:97
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:123
Base class of the Writer document model elements.
Definition: node.hxx:98
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:901
bool IsTextNode() const
Definition: node.hxx:190
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
SwPaM * GetNext()
Definition: pam.hxx:314
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
void GCAttr()
Definition: ndtxt.cxx:2875
const SwNodes & GetNodes() const
Definition: viewsh.cxx:2181
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
ring_container GetRingContainer()
Definition: ring.hxx:240
bool GoNext(SwNode *pNd, SwContentIndex *pIdx, SwCursorSkipMode nMode)
Definition: pam.cxx:381
static SfxItemSet & rSet
SetAttrMode
Definition: swtypes.hxx:133