xref: /aoo42x/main/sw/source/core/edit/edfcol.cxx (revision 28f5a95a)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir #include <editeng/brkitem.hxx>
30cdf0e10cSrcweir #include <editsh.hxx>
31cdf0e10cSrcweir #include <doc.hxx>		// fuer SwTxtFmtColls
32cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
33cdf0e10cSrcweir #include <edimp.hxx>	// fuer MACROS
34cdf0e10cSrcweir #include <ndtxt.hxx>
35cdf0e10cSrcweir #include <paratr.hxx>
36cdf0e10cSrcweir #include <fmtpdsc.hxx>
37cdf0e10cSrcweir // --> FME 2004-06-29 #114856# Formular view
38cdf0e10cSrcweir #include <viewopt.hxx>
39cdf0e10cSrcweir // <--
40cdf0e10cSrcweir #include <SwRewriter.hxx>
41cdf0e10cSrcweir #include <numrule.hxx>
42cdf0e10cSrcweir #include <swundo.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /*************************************
45cdf0e10cSrcweir  * FormatColl
46cdf0e10cSrcweir  *************************************/
47cdf0e10cSrcweir // TXT
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
GetDfltTxtFmtColl() const50cdf0e10cSrcweir SwTxtFmtColl& SwEditShell::GetDfltTxtFmtColl() const
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	return *((SwTxtFmtColl*) (GetDoc()->GetDfltTxtFmtColl()));
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 
GetTxtFmtCollCount() const56cdf0e10cSrcweir sal_uInt16 SwEditShell::GetTxtFmtCollCount() const
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	return GetDoc()->GetTxtFmtColls()->Count();
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
GetTxtFmtColl(sal_uInt16 nFmtColl) const62cdf0e10cSrcweir SwTxtFmtColl& SwEditShell::GetTxtFmtColl( sal_uInt16 nFmtColl) const
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	return *((*(GetDoc()->GetTxtFmtColls()))[nFmtColl]);
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // --> OD 2007-11-06 #i62675#
SetTxtFmtColl(SwTxtFmtColl * pFmt,const bool bResetListAttrs)68cdf0e10cSrcweir void SwEditShell::SetTxtFmtColl( SwTxtFmtColl *pFmt,
69*28f5a95aSOliver-Rainer Wittmann                                  const bool bResetListAttrs )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	SwTxtFmtColl *pLocal = pFmt? pFmt: (*GetDoc()->GetTxtFmtColls())[0];
72cdf0e10cSrcweir 	StartAllAction();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     SwRewriter aRewriter;
75cdf0e10cSrcweir     aRewriter.AddRule(UNDO_ARG1, pLocal->GetName());
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_SETFMTCOLL, &aRewriter);
78cdf0e10cSrcweir 	FOREACHPAM_START(this)
79cdf0e10cSrcweir 
8023d8f725SOliver-Rainer Wittmann         if ( !PCURCRSR->HasReadonlySel( GetViewOptions()->IsFormView() ) )
8123d8f725SOliver-Rainer Wittmann         {
82cdf0e10cSrcweir             GetDoc()->SetTxtFmtColl( *PCURCRSR, pLocal, true, bResetListAttrs );
8323d8f725SOliver-Rainer Wittmann         }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	FOREACHPAM_END()
86cdf0e10cSrcweir     GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_SETFMTCOLL, &aRewriter);
87cdf0e10cSrcweir 	EndAllAction();
88cdf0e10cSrcweir }
89cdf0e10cSrcweir // <--
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
MakeTxtFmtColl(const String & rFmtCollName,SwTxtFmtColl * pParent)92cdf0e10cSrcweir SwTxtFmtColl* SwEditShell::MakeTxtFmtColl(const String& rFmtCollName,
93cdf0e10cSrcweir 		SwTxtFmtColl* pParent)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	SwTxtFmtColl *pColl;
96cdf0e10cSrcweir 	if ( pParent == 0 )
97cdf0e10cSrcweir 		pParent = &GetTxtFmtColl(0);
98cdf0e10cSrcweir 	if (  (pColl=GetDoc()->MakeTxtFmtColl(rFmtCollName, pParent)) == 0 )
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir 		ASSERT( sal_False, "MakeTxtFmtColl failed" )
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 	return pColl;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
FillByEx(SwTxtFmtColl * pColl,sal_Bool bReset)107cdf0e10cSrcweir void SwEditShell::FillByEx(SwTxtFmtColl* pColl, sal_Bool bReset)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	if( bReset )
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         // --> OD 2007-01-25 #i73790# - method renamed
112cdf0e10cSrcweir         pColl->ResetAllFmtAttr();
113cdf0e10cSrcweir         // <--
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     SwPaM * pCrsr = GetCrsr();
117cdf0e10cSrcweir     SwCntntNode * pCnt = pCrsr->GetCntntNode();
118cdf0e10cSrcweir 	const SfxItemSet* pSet = pCnt->GetpSwAttrSet();
119cdf0e10cSrcweir 	if( pSet )
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		// JP 05.10.98: falls eines der Attribute Break/PageDesc/NumRule(auto)
122cdf0e10cSrcweir 		//		im ItemSet steht, so entferne die VORM setzen an der Collection.
123cdf0e10cSrcweir 		//		Ansonst wird zu viel gemacht oder falsche gemacht (NumRules!)
124cdf0e10cSrcweir 		//		Bug 57568
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 		// AutoNumRules NICHT in die Vorlagen uebernehmen
127cdf0e10cSrcweir 		const SfxPoolItem* pItem;
128cdf0e10cSrcweir 		const SwNumRule* pRule = 0;
129cdf0e10cSrcweir 		if( SFX_ITEM_SET == pSet->GetItemState( RES_BREAK, sal_False ) ||
130cdf0e10cSrcweir 			SFX_ITEM_SET == pSet->GetItemState( RES_PAGEDESC,sal_False ) ||
131cdf0e10cSrcweir 			( SFX_ITEM_SET == pSet->GetItemState( RES_PARATR_NUMRULE,
132cdf0e10cSrcweir 				sal_False, &pItem ) && 0 != (pRule = GetDoc()->FindNumRulePtr(
133cdf0e10cSrcweir 				((SwNumRuleItem*)pItem)->GetValue() )) &&
134cdf0e10cSrcweir 				pRule && pRule->IsAutoRule() )
135cdf0e10cSrcweir 			)
136cdf0e10cSrcweir 		{
137cdf0e10cSrcweir 			SfxItemSet aSet( *pSet );
138cdf0e10cSrcweir 			aSet.ClearItem( RES_BREAK );
139cdf0e10cSrcweir 			aSet.ClearItem( RES_PAGEDESC );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 			if( pRule || (SFX_ITEM_SET == pSet->GetItemState( RES_PARATR_NUMRULE,
142cdf0e10cSrcweir 				sal_False, &pItem ) && 0 != (pRule = GetDoc()->FindNumRulePtr(
143cdf0e10cSrcweir 				((SwNumRuleItem*)pItem)->GetValue() )) &&
144cdf0e10cSrcweir 				pRule && pRule->IsAutoRule() ))
145cdf0e10cSrcweir 				aSet.ClearItem( RES_PARATR_NUMRULE );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 			if( aSet.Count() )
148cdf0e10cSrcweir 				GetDoc()->ChgFmt(*pColl, aSet );
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 		else
151cdf0e10cSrcweir             GetDoc()->ChgFmt(*pColl, *pSet );
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
158