xref: /trunk/main/sw/source/core/edit/edfcol.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <hintids.hxx>
33 #include <editeng/brkitem.hxx>
34 #include <editsh.hxx>
35 #include <doc.hxx>		// fuer SwTxtFmtColls
36 #include <IDocumentUndoRedo.hxx>
37 #include <edimp.hxx>	// fuer MACROS
38 #include <ndtxt.hxx>
39 #include <paratr.hxx>
40 #include <fmtpdsc.hxx>
41 // --> FME 2004-06-29 #114856# Formular view
42 #include <viewopt.hxx>
43 // <--
44 #include <SwRewriter.hxx>
45 #include <numrule.hxx>
46 #include <swundo.hxx>
47 
48 /*************************************
49  * FormatColl
50  *************************************/
51 // TXT
52 
53 
54 SwTxtFmtColl& SwEditShell::GetDfltTxtFmtColl() const
55 {
56 	return *((SwTxtFmtColl*) (GetDoc()->GetDfltTxtFmtColl()));
57 }
58 
59 
60 sal_uInt16 SwEditShell::GetTxtFmtCollCount() const
61 {
62 	return GetDoc()->GetTxtFmtColls()->Count();
63 }
64 
65 
66 SwTxtFmtColl& SwEditShell::GetTxtFmtColl( sal_uInt16 nFmtColl) const
67 {
68 	return *((*(GetDoc()->GetTxtFmtColls()))[nFmtColl]);
69 }
70 
71 // --> OD 2007-11-06 #i62675#
72 void SwEditShell::SetTxtFmtColl( SwTxtFmtColl *pFmt,
73                                  bool bResetListAttrs )
74 {
75 	SwTxtFmtColl *pLocal = pFmt? pFmt: (*GetDoc()->GetTxtFmtColls())[0];
76 	StartAllAction();
77 
78     SwRewriter aRewriter;
79     aRewriter.AddRule(UNDO_ARG1, pLocal->GetName());
80 
81     GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_SETFMTCOLL, &aRewriter);
82 	FOREACHPAM_START(this)
83 
84         if( !PCURCRSR->HasReadonlySel(
85                     // --> FME 2004-06-29 #114856# Formular view
86                     GetViewOptions()->IsFormView() ) )
87                     // <--
88             GetDoc()->SetTxtFmtColl( *PCURCRSR, pLocal, true, bResetListAttrs );
89 
90 	FOREACHPAM_END()
91     GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_SETFMTCOLL, &aRewriter);
92 	EndAllAction();
93 }
94 // <--
95 
96 
97 SwTxtFmtColl* SwEditShell::MakeTxtFmtColl(const String& rFmtCollName,
98 		SwTxtFmtColl* pParent)
99 {
100 	SwTxtFmtColl *pColl;
101 	if ( pParent == 0 )
102 		pParent = &GetTxtFmtColl(0);
103 	if (  (pColl=GetDoc()->MakeTxtFmtColl(rFmtCollName, pParent)) == 0 )
104     {
105 		ASSERT( sal_False, "MakeTxtFmtColl failed" )
106     }
107 	return pColl;
108 
109 }
110 
111 
112 void SwEditShell::FillByEx(SwTxtFmtColl* pColl, sal_Bool bReset)
113 {
114 	if( bReset )
115     {
116         // --> OD 2007-01-25 #i73790# - method renamed
117         pColl->ResetAllFmtAttr();
118         // <--
119     }
120 
121     SwPaM * pCrsr = GetCrsr();
122     SwCntntNode * pCnt = pCrsr->GetCntntNode();
123 	const SfxItemSet* pSet = pCnt->GetpSwAttrSet();
124 	if( pSet )
125 	{
126 		// JP 05.10.98: falls eines der Attribute Break/PageDesc/NumRule(auto)
127 		//		im ItemSet steht, so entferne die VORM setzen an der Collection.
128 		//		Ansonst wird zu viel gemacht oder falsche gemacht (NumRules!)
129 		//		Bug 57568
130 
131 		// AutoNumRules NICHT in die Vorlagen uebernehmen
132 		const SfxPoolItem* pItem;
133 		const SwNumRule* pRule = 0;
134 		if( SFX_ITEM_SET == pSet->GetItemState( RES_BREAK, sal_False ) ||
135 			SFX_ITEM_SET == pSet->GetItemState( RES_PAGEDESC,sal_False ) ||
136 			( SFX_ITEM_SET == pSet->GetItemState( RES_PARATR_NUMRULE,
137 				sal_False, &pItem ) && 0 != (pRule = GetDoc()->FindNumRulePtr(
138 				((SwNumRuleItem*)pItem)->GetValue() )) &&
139 				pRule && pRule->IsAutoRule() )
140 			)
141 		{
142 			SfxItemSet aSet( *pSet );
143 			aSet.ClearItem( RES_BREAK );
144 			aSet.ClearItem( RES_PAGEDESC );
145 
146 			if( pRule || (SFX_ITEM_SET == pSet->GetItemState( RES_PARATR_NUMRULE,
147 				sal_False, &pItem ) && 0 != (pRule = GetDoc()->FindNumRulePtr(
148 				((SwNumRuleItem*)pItem)->GetValue() )) &&
149 				pRule && pRule->IsAutoRule() ))
150 				aSet.ClearItem( RES_PARATR_NUMRULE );
151 
152 			if( aSet.Count() )
153 				GetDoc()->ChgFmt(*pColl, aSet );
154 		}
155 		else
156             GetDoc()->ChgFmt(*pColl, *pSet );
157 	}
158 }
159 
160 
161 
162 
163