update dev300-m58
[ooovba.git] / sw / source / core / fields / fldlst.cxx
blobb8f3be064eca1fd06ff0849216738016779bde9f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fldlst.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include "editsh.hxx"
36 #include "doc.hxx"
37 #include <docary.hxx>
38 #include <fmtfld.hxx>
39 #include <txtfld.hxx>
40 #include "edimp.hxx"
41 #include "expfld.hxx"
42 #include "pam.hxx"
43 #include "docfld.hxx"
44 #include "ndtxt.hxx"
47 /*--------------------------------------------------------------------
48 Beschreibung: Sortieren der Input-Eintraege
49 --------------------------------------------------------------------*/
51 SwInputFieldList::SwInputFieldList( SwEditShell* pShell, BOOL bBuildTmpLst )
52 : pSh(pShell)
54 // Hier die Liste aller Eingabefelder sortiert erstellen
55 pSrtLst = new _SetGetExpFlds();
57 const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes();
58 const USHORT nSize = rFldTypes.Count();
60 // Alle Typen abklappern
62 for(USHORT i=0; i < nSize; ++i)
64 SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
65 USHORT nType = pFldType->Which();
67 if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType || RES_DROPDOWN == nType )
69 SwClientIter aIter( *pFldType );
70 for( SwFmtFld* pFld = (SwFmtFld*)aIter.First( TYPE(SwFmtFld) );
71 pFld; pFld = (SwFmtFld*)aIter.Next() )
74 const SwTxtFld* pTxtFld = pFld->GetTxtFld();
76 // nur InputFields und interaktive SetExpFlds bearbeiten
77 // and DropDown fields
78 if( !pTxtFld || ( RES_SETEXPFLD == nType &&
79 !((SwSetExpField*)pFld->GetFld())->GetInputFlag()))
80 continue;
82 const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
83 if( rTxtNode.GetNodes().IsDocNodes() )
85 if( bBuildTmpLst )
87 VoidPtr pTmp = (VoidPtr)pTxtFld;
88 aTmpLst.Insert( pTmp, aTmpLst.Count() );
90 else
92 SwNodeIndex aIdx( rTxtNode );
93 _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
94 pSrtLst->Insert( pNew );
102 SwInputFieldList::~SwInputFieldList()
104 delete pSrtLst;
107 /*--------------------------------------------------------------------
108 Beschreibung: Felder aus der Liste in sortierter Reihenfolge
109 --------------------------------------------------------------------*/
111 USHORT SwInputFieldList::Count() const
113 return pSrtLst->Count();
117 SwField* SwInputFieldList::GetField(USHORT nId)
119 const SwTxtFld* pTxtFld = (*pSrtLst)[ nId ]->GetFld();
120 ASSERT( pTxtFld, "kein TextFld" );
121 return (SwField*)pTxtFld->GetFld().GetFld();
124 /*--------------------------------------------------------------------
125 Beschreibung: Cursor sichern
126 --------------------------------------------------------------------*/
128 void SwInputFieldList::PushCrsr()
130 pSh->Push();
131 pSh->ClearMark();
134 void SwInputFieldList::PopCrsr()
136 pSh->Pop(FALSE);
139 /*--------------------------------------------------------------------
140 Beschreibung: Position eines Feldes ansteuern
141 --------------------------------------------------------------------*/
143 void SwInputFieldList::GotoFieldPos(USHORT nId)
145 pSh->StartAllAction();
146 (*pSrtLst)[ nId ]->GetPosOfContent( *pSh->GetCrsr()->GetPoint() );
147 pSh->EndAllAction();
150 // vergleiche TmpLst mit akt Feldern. Alle neue kommen in die SortLst
151 // damit sie geupdatet werden koennen. Returnt die Anzahl.
152 // (Fuer Textbausteine: nur seine Input-Felder aktualisieren)
153 USHORT SwInputFieldList::BuildSortLst()
155 const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes();
156 USHORT nSize = rFldTypes.Count();
158 // Alle Typen abklappern
160 for( USHORT i = 0; i < nSize; ++i )
162 SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
163 USHORT nType = pFldType->Which();
165 if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType )
167 SwClientIter aIter( *pFldType );
168 for( SwFmtFld* pFld = (SwFmtFld*)aIter.First( TYPE(SwFmtFld) );
169 pFld; pFld = (SwFmtFld*)aIter.Next() )
171 const SwTxtFld* pTxtFld = pFld->GetTxtFld();
173 // nur InputFields und interaktive SetExpFlds bearbeiten
174 if( !pTxtFld || ( RES_SETEXPFLD == nType &&
175 !((SwSetExpField*)pFld->GetFld())->GetInputFlag()))
176 continue;
178 const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
179 if( rTxtNode.GetNodes().IsDocNodes() )
181 VoidPtr pTmp = (VoidPtr)pTxtFld;
182 // nicht in der TempListe vorhanden, also in die SortListe
183 // aufnehemen
184 USHORT nFndPos = aTmpLst.GetPos( pTmp );
185 if( USHRT_MAX == nFndPos )
187 SwNodeIndex aIdx( rTxtNode );
188 _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
189 pSrtLst->Insert( pNew );
191 else
192 aTmpLst.Remove( nFndPos );
198 // die Pointer werden nicht mehr gebraucht
199 aTmpLst.Remove( 0, aTmpLst.Count() );
200 return pSrtLst->Count();
203 /*--------------------------------------------------------------------
204 Beschreibung: Alle Felder auáerhalb von Selektionen aus Liste entfernen
205 --------------------------------------------------------------------*/
207 void SwInputFieldList::RemoveUnselectedFlds()
209 _SetGetExpFlds* pNewLst = new _SetGetExpFlds();
211 FOREACHPAM_START(pSh)
213 for (USHORT i = 0; i < Count();)
215 _SetGetExpFld* pFld = (*pSrtLst)[i];
216 SwPosition aPos(*PCURCRSR->GetPoint());
218 pFld->GetPos( aPos );
220 if (aPos >= *PCURCRSR->Start() && aPos < *PCURCRSR->End())
222 // Feld innerhalb der Selektion
223 pNewLst->Insert( (*pSrtLst)[i] );
224 pSrtLst->Remove(i, 1);
226 else
227 i++;
230 FOREACHPAM_END()
232 delete pSrtLst;
233 pSrtLst = pNewLst;