1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 #include "switerator.hxx" 28 #include "editsh.hxx" 29 #include "doc.hxx" 30 #include <docary.hxx> 31 #include <fmtfld.hxx> 32 #include <txtfld.hxx> 33 #include "edimp.hxx" 34 #include "expfld.hxx" 35 #include "pam.hxx" 36 #include "docfld.hxx" 37 #include "ndtxt.hxx" 38 39 40 /*-------------------------------------------------------------------- 41 Beschreibung: Sortieren der Input-Eintraege 42 --------------------------------------------------------------------*/ 43 44 SwInputFieldList::SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst ) 45 : pSh(pShell) 46 { 47 // Hier die Liste aller Eingabefelder sortiert erstellen 48 pSrtLst = new _SetGetExpFlds(); 49 50 const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes(); 51 const sal_uInt16 nSize = rFldTypes.Count(); 52 53 // Alle Typen abklappern 54 55 for(sal_uInt16 i=0; i < nSize; ++i) 56 { 57 SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ]; 58 sal_uInt16 nType = pFldType->Which(); 59 60 if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType || RES_DROPDOWN == nType ) 61 { 62 SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType ); 63 for( SwFmtFld* pFld = aIter.First(); pFld; pFld = aIter.Next() ) 64 { 65 const SwTxtFld* pTxtFld = pFld->GetTxtFld(); 66 67 // nur InputFields und interaktive SetExpFlds bearbeiten 68 // and DropDown fields 69 if( !pTxtFld || ( RES_SETEXPFLD == nType && 70 !((SwSetExpField*)pFld->GetFld())->GetInputFlag())) 71 continue; 72 73 const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode(); 74 if( rTxtNode.GetNodes().IsDocNodes() ) 75 { 76 if( bBuildTmpLst ) 77 { 78 VoidPtr pTmp = (VoidPtr)pTxtFld; 79 aTmpLst.Insert( pTmp, aTmpLst.Count() ); 80 } 81 else 82 { 83 SwNodeIndex aIdx( rTxtNode ); 84 _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld ); 85 pSrtLst->Insert( pNew ); 86 } 87 } 88 } 89 } 90 } 91 } 92 93 SwInputFieldList::~SwInputFieldList() 94 { 95 delete pSrtLst; 96 } 97 98 /*-------------------------------------------------------------------- 99 Beschreibung: Felder aus der Liste in sortierter Reihenfolge 100 --------------------------------------------------------------------*/ 101 102 sal_uInt16 SwInputFieldList::Count() const 103 { 104 return pSrtLst->Count(); 105 } 106 107 108 SwField* SwInputFieldList::GetField(sal_uInt16 nId) 109 { 110 const SwTxtFld* pTxtFld = (*pSrtLst)[ nId ]->GetFld(); 111 ASSERT( pTxtFld, "kein TextFld" ); 112 return (SwField*)pTxtFld->GetFld().GetFld(); 113 } 114 115 /*-------------------------------------------------------------------- 116 Beschreibung: Cursor sichern 117 --------------------------------------------------------------------*/ 118 119 void SwInputFieldList::PushCrsr() 120 { 121 pSh->Push(); 122 pSh->ClearMark(); 123 } 124 125 void SwInputFieldList::PopCrsr() 126 { 127 pSh->Pop(sal_False); 128 } 129 130 /*-------------------------------------------------------------------- 131 Beschreibung: Position eines Feldes ansteuern 132 --------------------------------------------------------------------*/ 133 134 void SwInputFieldList::GotoFieldPos(sal_uInt16 nId) 135 { 136 pSh->StartAllAction(); 137 (*pSrtLst)[ nId ]->GetPosOfContent( *pSh->GetCrsr()->GetPoint() ); 138 pSh->EndAllAction(); 139 } 140 141 // vergleiche TmpLst mit akt Feldern. Alle neue kommen in die SortLst 142 // damit sie geupdatet werden koennen. Returnt die Anzahl. 143 // (Fuer Textbausteine: nur seine Input-Felder aktualisieren) 144 sal_uInt16 SwInputFieldList::BuildSortLst() 145 { 146 const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes(); 147 sal_uInt16 nSize = rFldTypes.Count(); 148 149 // Alle Typen abklappern 150 151 for( sal_uInt16 i = 0; i < nSize; ++i ) 152 { 153 SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ]; 154 sal_uInt16 nType = pFldType->Which(); 155 156 if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType ) 157 { 158 SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType ); 159 for( SwFmtFld* pFld = aIter.First(); pFld; pFld = aIter.Next() ) 160 { 161 const SwTxtFld* pTxtFld = pFld->GetTxtFld(); 162 163 // nur InputFields und interaktive SetExpFlds bearbeiten 164 if( !pTxtFld || ( RES_SETEXPFLD == nType && 165 !((SwSetExpField*)pFld->GetFld())->GetInputFlag())) 166 continue; 167 168 const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode(); 169 if( rTxtNode.GetNodes().IsDocNodes() ) 170 { 171 VoidPtr pTmp = (VoidPtr)pTxtFld; 172 // nicht in der TempListe vorhanden, also in die SortListe 173 // aufnehemen 174 sal_uInt16 nFndPos = aTmpLst.GetPos( pTmp ); 175 if( USHRT_MAX == nFndPos ) 176 { 177 SwNodeIndex aIdx( rTxtNode ); 178 _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld ); 179 pSrtLst->Insert( pNew ); 180 } 181 else 182 aTmpLst.Remove( nFndPos ); 183 } 184 } 185 } 186 } 187 188 // die Pointer werden nicht mehr gebraucht 189 aTmpLst.Remove( 0, aTmpLst.Count() ); 190 return pSrtLst->Count(); 191 } 192 193 /*-------------------------------------------------------------------- 194 Beschreibung: Alle Felder au�erhalb von Selektionen aus Liste entfernen 195 --------------------------------------------------------------------*/ 196 197 void SwInputFieldList::RemoveUnselectedFlds() 198 { 199 _SetGetExpFlds* pNewLst = new _SetGetExpFlds(); 200 201 FOREACHPAM_START(pSh) 202 { 203 for (sal_uInt16 i = 0; i < Count();) 204 { 205 _SetGetExpFld* pFld = (*pSrtLst)[i]; 206 SwPosition aPos(*PCURCRSR->GetPoint()); 207 208 pFld->GetPos( aPos ); 209 210 if (aPos >= *PCURCRSR->Start() && aPos < *PCURCRSR->End()) 211 { 212 // Feld innerhalb der Selektion 213 pNewLst->Insert( (*pSrtLst)[i] ); 214 pSrtLst->Remove(i, 1); 215 } 216 else 217 i++; 218 } 219 } 220 FOREACHPAM_END() 221 222 delete pSrtLst; 223 pSrtLst = pNewLst; 224 } 225 226 227