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