Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "switerator.hxx"
31 : : #include "editsh.hxx"
32 : : #include "doc.hxx"
33 : : #include <docary.hxx>
34 : : #include <fmtfld.hxx>
35 : : #include <txtfld.hxx>
36 : : #include "edimp.hxx"
37 : : #include "expfld.hxx"
38 : : #include "pam.hxx"
39 : : #include "docfld.hxx"
40 : : #include "ndtxt.hxx"
41 : :
42 : :
43 : : /*--------------------------------------------------------------------
44 : : Beschreibung: Sortieren der Input-Eintraege
45 : : --------------------------------------------------------------------*/
46 : :
47 : 0 : SwInputFieldList::SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst )
48 : 0 : : pSh(pShell)
49 : : {
50 : : // Hier die Liste aller Eingabefelder sortiert erstellen
51 [ # # ][ # # ]: 0 : pSrtLst = new _SetGetExpFlds();
52 : :
53 [ # # ]: 0 : const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes();
54 : 0 : const sal_uInt16 nSize = rFldTypes.size();
55 : :
56 : : // Alle Typen abklappern
57 : :
58 [ # # ]: 0 : for(sal_uInt16 i=0; i < nSize; ++i)
59 : : {
60 : 0 : SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
61 : 0 : sal_uInt16 nType = pFldType->Which();
62 : :
63 [ # # ][ # # ]: 0 : if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType || RES_DROPDOWN == nType )
[ # # ]
64 : : {
65 [ # # ]: 0 : SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
66 [ # # ][ # # ]: 0 : for( SwFmtFld* pFld = aIter.First(); pFld; pFld = aIter.Next() )
[ # # ]
67 : : {
68 : 0 : const SwTxtFld* pTxtFld = pFld->GetTxtFld();
69 : :
70 : : // nur InputFields und interaktive SetExpFlds bearbeiten
71 : : // and DropDown fields
72 [ # # # # ]: 0 : if( !pTxtFld || ( RES_SETEXPFLD == nType &&
[ # # ][ # # ]
73 : 0 : !((SwSetExpField*)pFld->GetFld())->GetInputFlag()))
74 : 0 : continue;
75 : :
76 : 0 : const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
77 [ # # ][ # # ]: 0 : if( rTxtNode.GetNodes().IsDocNodes() )
78 : : {
79 [ # # ]: 0 : if( bBuildTmpLst )
80 : : {
81 [ # # ]: 0 : aTmpLst.insert( pTxtFld );
82 : : }
83 : : else
84 : : {
85 [ # # ]: 0 : SwNodeIndex aIdx( rTxtNode );
86 [ # # ][ # # ]: 0 : _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
87 [ # # ][ # # ]: 0 : pSrtLst->insert( pNew );
88 : : }
89 : : }
90 [ # # ]: 0 : }
91 : : }
92 : : }
93 : 0 : }
94 : :
95 : 0 : SwInputFieldList::~SwInputFieldList()
96 : : {
97 [ # # ][ # # ]: 0 : delete pSrtLst;
98 : 0 : }
99 : :
100 : : /*--------------------------------------------------------------------
101 : : Beschreibung: Felder aus der Liste in sortierter Reihenfolge
102 : : --------------------------------------------------------------------*/
103 : :
104 : 0 : sal_uInt16 SwInputFieldList::Count() const
105 : : {
106 : 0 : return pSrtLst->size();
107 : : }
108 : :
109 : :
110 : 0 : SwField* SwInputFieldList::GetField(sal_uInt16 nId)
111 : : {
112 : 0 : const SwTxtFld* pTxtFld = (*pSrtLst)[ nId ]->GetFld();
113 : : OSL_ENSURE( pTxtFld, "kein TextFld" );
114 : 0 : return (SwField*)pTxtFld->GetFld().GetFld();
115 : : }
116 : :
117 : : /*--------------------------------------------------------------------
118 : : Beschreibung: Cursor sichern
119 : : --------------------------------------------------------------------*/
120 : :
121 : 0 : void SwInputFieldList::PushCrsr()
122 : : {
123 : 0 : pSh->Push();
124 : 0 : pSh->ClearMark();
125 : 0 : }
126 : :
127 : 0 : void SwInputFieldList::PopCrsr()
128 : : {
129 : 0 : pSh->Pop(sal_False);
130 : 0 : }
131 : :
132 : : /*--------------------------------------------------------------------
133 : : Beschreibung: Position eines Feldes ansteuern
134 : : --------------------------------------------------------------------*/
135 : :
136 : 0 : void SwInputFieldList::GotoFieldPos(sal_uInt16 nId)
137 : : {
138 : 0 : pSh->StartAllAction();
139 : 0 : (*pSrtLst)[ nId ]->GetPosOfContent( *pSh->GetCrsr()->GetPoint() );
140 : 0 : pSh->EndAllAction();
141 : 0 : }
142 : :
143 : : // vergleiche TmpLst mit akt Feldern. Alle neue kommen in die SortLst
144 : : // damit sie geupdatet werden koennen. Returnt die Anzahl.
145 : : // (Fuer Textbausteine: nur seine Input-Felder aktualisieren)
146 : 0 : sal_uInt16 SwInputFieldList::BuildSortLst()
147 : : {
148 : 0 : const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes();
149 : 0 : sal_uInt16 nSize = rFldTypes.size();
150 : :
151 : : // Alle Typen abklappern
152 : :
153 [ # # ]: 0 : for( sal_uInt16 i = 0; i < nSize; ++i )
154 : : {
155 : 0 : SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
156 : 0 : sal_uInt16 nType = pFldType->Which();
157 : :
158 [ # # ][ # # ]: 0 : if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType )
159 : : {
160 [ # # ]: 0 : SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
161 [ # # ][ # # ]: 0 : for( SwFmtFld* pFld = aIter.First(); pFld; pFld = aIter.Next() )
[ # # ]
162 : : {
163 : 0 : const SwTxtFld* pTxtFld = pFld->GetTxtFld();
164 : :
165 : : // nur InputFields und interaktive SetExpFlds bearbeiten
166 [ # # # # ]: 0 : if( !pTxtFld || ( RES_SETEXPFLD == nType &&
[ # # ][ # # ]
167 : 0 : !((SwSetExpField*)pFld->GetFld())->GetInputFlag()))
168 : 0 : continue;
169 : :
170 : 0 : const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
171 [ # # ][ # # ]: 0 : if( rTxtNode.GetNodes().IsDocNodes() )
172 : : {
173 : : // nicht in der TempListe vorhanden, also in die SortListe
174 : : // aufnehemen
175 [ # # ]: 0 : std::set<const SwTxtFld*>::iterator it = aTmpLst.find( pTxtFld );
176 [ # # ]: 0 : if( aTmpLst.end() == it )
177 : : {
178 [ # # ]: 0 : SwNodeIndex aIdx( rTxtNode );
179 [ # # ][ # # ]: 0 : _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
180 [ # # ][ # # ]: 0 : pSrtLst->insert( pNew );
181 : : }
182 : : else
183 [ # # ]: 0 : aTmpLst.erase( it );
184 : : }
185 [ # # ]: 0 : }
186 : : }
187 : : }
188 : :
189 : : // die Pointer werden nicht mehr gebraucht
190 : 0 : aTmpLst.clear();
191 : 0 : return pSrtLst->size();
192 : : }
193 : :
194 : : /*--------------------------------------------------------------------
195 : : Beschreibung: Alle Felder auáerhalb von Selektionen aus Liste entfernen
196 : : --------------------------------------------------------------------*/
197 : :
198 : 0 : void SwInputFieldList::RemoveUnselectedFlds()
199 : : {
200 [ # # ]: 0 : _SetGetExpFlds* pNewLst = new _SetGetExpFlds();
201 : :
202 [ # # ]: 0 : FOREACHPAM_START(pSh)
203 : : {
204 [ # # ]: 0 : for (sal_uInt16 i = 0; i < Count();)
205 : : {
206 [ # # ]: 0 : _SetGetExpFld* pFld = (*pSrtLst)[i];
207 [ # # ]: 0 : SwPosition aPos(*PCURCRSR->GetPoint());
208 : :
209 [ # # ]: 0 : pFld->GetPos( aPos );
210 : :
211 [ # # ][ # # ]: 0 : if (aPos >= *PCURCRSR->Start() && aPos < *PCURCRSR->End())
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
212 : : {
213 : : // Feld innerhalb der Selektion
214 [ # # ][ # # ]: 0 : pNewLst->insert( (*pSrtLst)[i] );
215 [ # # ]: 0 : pSrtLst->erase(i);
216 : : }
217 : : else
218 : 0 : i++;
219 [ # # ]: 0 : }
220 : : }
221 : 0 : FOREACHPAM_END()
222 : :
223 [ # # ]: 0 : delete pSrtLst;
224 : 0 : pSrtLst = pNewLst;
225 : 0 : }
226 : :
227 : :
228 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|