Line data Source code
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>
23 : #include <pam.hxx>
24 : #include <edimp.hxx>
25 : #include <swundo.hxx>
26 : #include <ndtxt.hxx>
27 :
28 : /*
29 : * hard formatting (Attribute)
30 : */
31 :
32 4 : void SwEditShell::ResetAttr( const std::set<sal_uInt16> &attrs, SwPaM* pPaM )
33 : {
34 4 : SET_CURR_SHELL( this );
35 4 : SwPaM* pCrsr = pPaM ? pPaM : GetCrsr( );
36 :
37 4 : StartAllAction();
38 4 : bool bUndoGroup = pCrsr->GetNext() != pCrsr;
39 4 : if( bUndoGroup )
40 : {
41 0 : GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_RESETATTR, NULL);
42 : }
43 :
44 4 : SwPaM* pStartCrsr = pCrsr;
45 4 : do {
46 4 : GetDoc()->ResetAttrs(*pCrsr, true, attrs);
47 4 : } while ( ( pCrsr = ( SwPaM* ) pCrsr->GetNext() ) != pStartCrsr );
48 :
49 4 : if( bUndoGroup )
50 : {
51 0 : GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_RESETATTR, NULL);
52 : }
53 4 : CallChgLnk();
54 4 : EndAllAction();
55 4 : }
56 :
57 0 : void SwEditShell::GCAttr()
58 : {
59 0 : FOREACHPAM_START(GetCrsr())
60 0 : if ( !PCURCRSR->HasMark() )
61 : {
62 : SwTxtNode *const pTxtNode =
63 0 : PCURCRSR->GetPoint()->nNode.GetNode().GetTxtNode();
64 0 : if (pTxtNode)
65 : {
66 0 : pTxtNode->GCAttr();
67 : }
68 : }
69 : else
70 : {
71 0 : const SwNodeIndex& rEnd = PCURCRSR->End()->nNode;
72 0 : SwNodeIndex aIdx( PCURCRSR->Start()->nNode );
73 0 : SwNode* pNd = &aIdx.GetNode();
74 0 : do {
75 0 : if( pNd->IsTxtNode() )
76 0 : ((SwTxtNode*)pNd)->GCAttr();
77 : }
78 0 : while( 0 != ( pNd = GetDoc()->GetNodes().GoNext( &aIdx )) &&
79 0 : aIdx <= rEnd );
80 : }
81 0 : FOREACHPAM_END()
82 0 : }
83 :
84 : /// Set the attribute as new default attribute in the document.
85 0 : void SwEditShell::SetDefault( const SfxPoolItem& rFmtHint )
86 : {
87 : // 7502: Action-Parenthesis
88 0 : StartAllAction();
89 0 : GetDoc()->SetDefault( rFmtHint );
90 0 : EndAllAction();
91 0 : }
92 :
93 : /// request the default attribute in this document.
94 195 : const SfxPoolItem& SwEditShell::GetDefault( sal_uInt16 nFmtHint ) const
95 : {
96 195 : return GetDoc()->GetDefault( nFmtHint );
97 : }
98 :
99 10 : void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, sal_uInt16 nFlags )
100 : {
101 10 : SET_CURR_SHELL( this );
102 10 : StartAllAction();
103 10 : SwPaM* pCrsr = GetCrsr();
104 10 : if( pCrsr->GetNext() != pCrsr ) // Ring of Cursors
105 : {
106 0 : bool bIsTblMode = IsTableMode();
107 0 : GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_INSATTR, NULL);
108 :
109 0 : FOREACHPAM_START(GetCrsr())
110 0 : if( PCURCRSR->HasMark() && ( bIsTblMode ||
111 0 : *PCURCRSR->GetPoint() != *PCURCRSR->GetMark() ))
112 : {
113 0 : GetDoc()->getIDocumentContentOperations().InsertPoolItem(*PCURCRSR, rHint, nFlags );
114 : }
115 0 : FOREACHPAM_END()
116 :
117 0 : GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_INSATTR, NULL);
118 : }
119 : else
120 : {
121 10 : if( !HasSelection() )
122 10 : UpdateAttr();
123 10 : GetDoc()->getIDocumentContentOperations().InsertPoolItem( *pCrsr, rHint, nFlags );
124 : }
125 10 : EndAllAction();
126 10 : }
127 :
128 8 : void SwEditShell::SetAttrSet( const SfxItemSet& rSet, sal_uInt16 nFlags, SwPaM* pPaM )
129 : {
130 8 : SET_CURR_SHELL( this );
131 :
132 8 : SwPaM* pCrsr = pPaM ? pPaM : GetCrsr();
133 8 : StartAllAction();
134 8 : if( pCrsr->GetNext() != pCrsr ) // Ring of Cursors
135 : {
136 0 : bool bIsTblMode = IsTableMode();
137 0 : GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_INSATTR, NULL);
138 :
139 0 : SwPaM* pTmpCrsr = pCrsr;
140 0 : SwPaM* pStartPaM = pCrsr;
141 0 : do {
142 0 : if( pTmpCrsr->HasMark() && ( bIsTblMode ||
143 0 : *pTmpCrsr->GetPoint() != *pTmpCrsr->GetMark() ))
144 : {
145 0 : GetDoc()->getIDocumentContentOperations().InsertItemSet(*pTmpCrsr, rSet, nFlags );
146 : }
147 0 : } while ( ( pTmpCrsr = (SwPaM*)pTmpCrsr->GetNext() ) != pStartPaM );
148 :
149 0 : GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_INSATTR, NULL);
150 : }
151 : else
152 : {
153 8 : if( !HasSelection() )
154 0 : UpdateAttr();
155 8 : GetDoc()->getIDocumentContentOperations().InsertItemSet( *pCrsr, rSet, nFlags );
156 : }
157 8 : EndAllAction();
158 278 : }
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|