xref: /aoo41x/main/sw/source/core/fields/fldlst.cxx (revision c0286415)
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 #include "switerator.hxx"
28cdf0e10cSrcweir #include "editsh.hxx"
29cdf0e10cSrcweir #include "doc.hxx"
30cdf0e10cSrcweir #include <docary.hxx>
31cdf0e10cSrcweir #include <fmtfld.hxx>
32cdf0e10cSrcweir #include <txtfld.hxx>
33cdf0e10cSrcweir #include "edimp.hxx"
34cdf0e10cSrcweir #include "expfld.hxx"
35cdf0e10cSrcweir #include "pam.hxx"
36cdf0e10cSrcweir #include "docfld.hxx"
37cdf0e10cSrcweir #include "ndtxt.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir /*--------------------------------------------------------------------
41cdf0e10cSrcweir 	Beschreibung: Sortieren der Input-Eintraege
42cdf0e10cSrcweir  --------------------------------------------------------------------*/
43cdf0e10cSrcweir 
SwInputFieldList(SwEditShell * pShell,sal_Bool bBuildTmpLst)44cdf0e10cSrcweir SwInputFieldList::SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst )
45cdf0e10cSrcweir 	: pSh(pShell)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	// Hier die Liste aller Eingabefelder sortiert erstellen
48cdf0e10cSrcweir 	pSrtLst = new _SetGetExpFlds();
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes();
51cdf0e10cSrcweir 	const sal_uInt16 nSize = rFldTypes.Count();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	// Alle Typen abklappern
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
58cdf0e10cSrcweir 		sal_uInt16 nType = pFldType->Which();
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType || RES_DROPDOWN == nType )
61cdf0e10cSrcweir 		{
62cdf0e10cSrcweir 			SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
63*c0286415SOliver-Rainer Wittmann 			for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
64cdf0e10cSrcweir 			{
65*c0286415SOliver-Rainer Wittmann 				const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 				//	nur InputFields und interaktive SetExpFlds bearbeiten
68cdf0e10cSrcweir                 //  and DropDown fields
69cdf0e10cSrcweir 				if( !pTxtFld || ( RES_SETEXPFLD == nType &&
70*c0286415SOliver-Rainer Wittmann 					!((SwSetExpField*)pFmtFld->GetField())->GetInputFlag()))
71cdf0e10cSrcweir 					continue;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 				const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
74cdf0e10cSrcweir 				if( rTxtNode.GetNodes().IsDocNodes() )
75cdf0e10cSrcweir 				{
76cdf0e10cSrcweir 					if( bBuildTmpLst )
77cdf0e10cSrcweir 					{
78cdf0e10cSrcweir 						VoidPtr pTmp = (VoidPtr)pTxtFld;
79cdf0e10cSrcweir 						aTmpLst.Insert( pTmp, aTmpLst.Count() );
80cdf0e10cSrcweir 					}
81cdf0e10cSrcweir 					else
82cdf0e10cSrcweir 					{
83cdf0e10cSrcweir 						SwNodeIndex aIdx( rTxtNode );
84cdf0e10cSrcweir 						_SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
85cdf0e10cSrcweir 						pSrtLst->Insert( pNew );
86cdf0e10cSrcweir 					}
87cdf0e10cSrcweir 				}
88cdf0e10cSrcweir 			}
89cdf0e10cSrcweir 		}
90cdf0e10cSrcweir 	}
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
~SwInputFieldList()93cdf0e10cSrcweir SwInputFieldList::~SwInputFieldList()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	delete pSrtLst;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir /*--------------------------------------------------------------------
99cdf0e10cSrcweir 	Beschreibung: Felder aus der Liste in sortierter Reihenfolge
100cdf0e10cSrcweir  --------------------------------------------------------------------*/
101cdf0e10cSrcweir 
Count() const102cdf0e10cSrcweir sal_uInt16 SwInputFieldList::Count() const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	return pSrtLst->Count();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
GetField(sal_uInt16 nId)108cdf0e10cSrcweir SwField* SwInputFieldList::GetField(sal_uInt16 nId)
109cdf0e10cSrcweir {
110*c0286415SOliver-Rainer Wittmann 	const SwTxtFld* pTxtFld = (*pSrtLst)[ nId ]->GetTxtFld();
111cdf0e10cSrcweir 	ASSERT( pTxtFld, "kein TextFld" );
112*c0286415SOliver-Rainer Wittmann 	return (SwField*)pTxtFld->GetFmtFld().GetField();
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir /*--------------------------------------------------------------------
116cdf0e10cSrcweir 	Beschreibung: Cursor sichern
117cdf0e10cSrcweir  --------------------------------------------------------------------*/
118cdf0e10cSrcweir 
PushCrsr()119cdf0e10cSrcweir void SwInputFieldList::PushCrsr()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	pSh->Push();
122cdf0e10cSrcweir 	pSh->ClearMark();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
PopCrsr()125cdf0e10cSrcweir void SwInputFieldList::PopCrsr()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	pSh->Pop(sal_False);
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir /*--------------------------------------------------------------------
131cdf0e10cSrcweir 	Beschreibung: Position eines Feldes ansteuern
132cdf0e10cSrcweir  --------------------------------------------------------------------*/
133cdf0e10cSrcweir 
GotoFieldPos(sal_uInt16 nId)134cdf0e10cSrcweir void SwInputFieldList::GotoFieldPos(sal_uInt16 nId)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	pSh->StartAllAction();
137cdf0e10cSrcweir 	(*pSrtLst)[ nId ]->GetPosOfContent( *pSh->GetCrsr()->GetPoint() );
138cdf0e10cSrcweir 	pSh->EndAllAction();
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 	// vergleiche TmpLst mit akt Feldern. Alle neue kommen in die SortLst
142cdf0e10cSrcweir 	// damit sie geupdatet werden koennen. Returnt die Anzahl.
143cdf0e10cSrcweir 	// (Fuer Textbausteine: nur seine Input-Felder aktualisieren)
BuildSortLst()144cdf0e10cSrcweir sal_uInt16 SwInputFieldList::BuildSortLst()
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes();
147cdf0e10cSrcweir 	sal_uInt16 nSize = rFldTypes.Count();
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	// Alle Typen abklappern
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	for( sal_uInt16 i = 0; i < nSize; ++i )
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
154cdf0e10cSrcweir 		sal_uInt16 nType = pFldType->Which();
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType )
157cdf0e10cSrcweir 		{
158cdf0e10cSrcweir 			SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
159*c0286415SOliver-Rainer Wittmann             for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
160cdf0e10cSrcweir 			{
161*c0286415SOliver-Rainer Wittmann 				const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 				//	nur InputFields und interaktive SetExpFlds bearbeiten
164cdf0e10cSrcweir 				if( !pTxtFld || ( RES_SETEXPFLD == nType &&
165*c0286415SOliver-Rainer Wittmann 					!((SwSetExpField*)pFmtFld->GetField())->GetInputFlag()))
166cdf0e10cSrcweir 					continue;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 				const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
169cdf0e10cSrcweir 				if( rTxtNode.GetNodes().IsDocNodes() )
170cdf0e10cSrcweir 				{
171cdf0e10cSrcweir 					VoidPtr pTmp = (VoidPtr)pTxtFld;
172cdf0e10cSrcweir 					// nicht in der TempListe vorhanden, also in die SortListe
173cdf0e10cSrcweir 					// aufnehemen
174cdf0e10cSrcweir 					sal_uInt16 nFndPos = aTmpLst.GetPos( pTmp );
175cdf0e10cSrcweir 					if( USHRT_MAX == nFndPos )
176cdf0e10cSrcweir 					{
177cdf0e10cSrcweir 						SwNodeIndex aIdx( rTxtNode );
178cdf0e10cSrcweir 						_SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
179cdf0e10cSrcweir 						pSrtLst->Insert( pNew );
180cdf0e10cSrcweir 					}
181cdf0e10cSrcweir 					else
182cdf0e10cSrcweir 						aTmpLst.Remove( nFndPos );
183cdf0e10cSrcweir 				}
184cdf0e10cSrcweir 			}
185cdf0e10cSrcweir 		}
186cdf0e10cSrcweir 	}
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	// die Pointer werden nicht mehr gebraucht
189cdf0e10cSrcweir 	aTmpLst.Remove( 0, aTmpLst.Count() );
190cdf0e10cSrcweir 	return pSrtLst->Count();
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir /*--------------------------------------------------------------------
194cdf0e10cSrcweir 	Beschreibung: Alle Felder au�erhalb von Selektionen aus Liste entfernen
195cdf0e10cSrcweir  --------------------------------------------------------------------*/
196cdf0e10cSrcweir 
RemoveUnselectedFlds()197cdf0e10cSrcweir void SwInputFieldList::RemoveUnselectedFlds()
198cdf0e10cSrcweir {
199cdf0e10cSrcweir 	_SetGetExpFlds*	pNewLst = new _SetGetExpFlds();
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	FOREACHPAM_START(pSh)
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		for (sal_uInt16 i = 0; i < Count();)
204cdf0e10cSrcweir 		{
205cdf0e10cSrcweir 			_SetGetExpFld* pFld = (*pSrtLst)[i];
206cdf0e10cSrcweir 			SwPosition aPos(*PCURCRSR->GetPoint());
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 			pFld->GetPos( aPos );
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 			if (aPos >= *PCURCRSR->Start() && aPos < *PCURCRSR->End())
211cdf0e10cSrcweir 			{
212cdf0e10cSrcweir 				// Feld innerhalb der Selektion
213cdf0e10cSrcweir 				pNewLst->Insert( (*pSrtLst)[i] );
214cdf0e10cSrcweir 				pSrtLst->Remove(i, 1);
215cdf0e10cSrcweir 			}
216cdf0e10cSrcweir 			else
217cdf0e10cSrcweir 				i++;
218cdf0e10cSrcweir 		}
219cdf0e10cSrcweir 	}
220cdf0e10cSrcweir 	FOREACHPAM_END()
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 	delete pSrtLst;
223cdf0e10cSrcweir 	pSrtLst = pNewLst;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 
227