Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "switerator.hxx"
21 : #include "editsh.hxx"
22 : #include "doc.hxx"
23 : #include <IDocumentFieldsAccess.hxx>
24 : #include <docary.hxx>
25 : #include <fmtfld.hxx>
26 : #include <txtfld.hxx>
27 : #include "edimp.hxx"
28 : #include "expfld.hxx"
29 : #include "pam.hxx"
30 : #include "docfld.hxx"
31 : #include "ndtxt.hxx"
32 :
33 : // sort input values
34 :
35 0 : SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
36 0 : : pSh(pShell)
37 : {
38 : // create sorted list of all input fields
39 0 : pSrtLst = new _SetGetExpFlds();
40 :
41 0 : const SwFldTypes& rFldTypes = *pSh->GetDoc()->getIDocumentFieldsAccess().GetFldTypes();
42 0 : const size_t nSize = rFldTypes.size();
43 :
44 : // iterate over all types
45 0 : for(size_t i=0; i < nSize; ++i)
46 : {
47 0 : SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
48 0 : const sal_uInt16 nType = pFldType->Which();
49 :
50 0 : if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType || RES_DROPDOWN == nType )
51 : {
52 0 : SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
53 0 : for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
54 : {
55 0 : const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
56 :
57 : // only process InputFields, interactive SetExpFlds and DropDown fields
58 0 : if( !pTxtFld || ( RES_SETEXPFLD == nType &&
59 0 : !((SwSetExpField*)pFmtFld->GetField())->GetInputFlag()))
60 0 : continue;
61 :
62 0 : const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
63 0 : if( rTxtNode.GetNodes().IsDocNodes() )
64 : {
65 0 : if( bBuildTmpLst )
66 : {
67 0 : aTmpLst.insert( pTxtFld );
68 : }
69 : else
70 : {
71 0 : SwNodeIndex aIdx( rTxtNode );
72 0 : _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
73 0 : pSrtLst->insert( pNew );
74 : }
75 : }
76 0 : }
77 : }
78 : }
79 0 : }
80 :
81 0 : SwInputFieldList::~SwInputFieldList()
82 : {
83 0 : delete pSrtLst;
84 0 : }
85 :
86 0 : size_t SwInputFieldList::Count() const
87 : {
88 0 : return pSrtLst->size();
89 : }
90 :
91 : // get field from list in sorted order
92 0 : SwField* SwInputFieldList::GetField(size_t nId)
93 : {
94 0 : const SwTxtFld* pTxtFld = (*pSrtLst)[ nId ]->GetTxtFld();
95 : OSL_ENSURE( pTxtFld, "no TextFld" );
96 0 : return (SwField*)pTxtFld->GetFmtFld().GetField();
97 : }
98 :
99 : /// save cursor
100 0 : void SwInputFieldList::PushCrsr()
101 : {
102 0 : pSh->Push();
103 0 : pSh->ClearMark();
104 0 : }
105 :
106 : /// get cursor
107 0 : void SwInputFieldList::PopCrsr()
108 : {
109 0 : pSh->Pop(false);
110 0 : }
111 :
112 : /// go to position of a field
113 0 : void SwInputFieldList::GotoFieldPos(size_t nId)
114 : {
115 0 : pSh->StartAllAction();
116 0 : (*pSrtLst)[ nId ]->GetPosOfContent( *pSh->GetCrsr()->GetPoint() );
117 0 : pSh->EndAllAction();
118 0 : }
119 :
120 : /** Compare TmpLst with current fields.
121 : *
122 : * All new ones are added to SortList so that they can be updated.
123 : * For text blocks: update only input fields.
124 : *
125 : * @return true if not empty
126 : */
127 0 : bool SwInputFieldList::BuildSortLst()
128 : {
129 0 : const SwFldTypes& rFldTypes = *pSh->GetDoc()->getIDocumentFieldsAccess().GetFldTypes();
130 0 : const size_t nSize = rFldTypes.size();
131 :
132 : // iterate over all types
133 0 : for( size_t i = 0; i < nSize; ++i )
134 : {
135 0 : SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
136 0 : const sal_uInt16 nType = pFldType->Which();
137 :
138 0 : if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType )
139 : {
140 0 : SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
141 0 : for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
142 : {
143 0 : const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
144 :
145 : // process only InputFields and interactive SetExpFlds
146 0 : if( !pTxtFld || ( RES_SETEXPFLD == nType &&
147 0 : !((SwSetExpField*)pFmtFld->GetField())->GetInputFlag()))
148 0 : continue;
149 :
150 0 : const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
151 0 : if( rTxtNode.GetNodes().IsDocNodes() )
152 : {
153 : // not in TempList, thus add to SortList
154 0 : std::set<const SwTxtFld*>::iterator it = aTmpLst.find( pTxtFld );
155 0 : if( aTmpLst.end() == it )
156 : {
157 0 : SwNodeIndex aIdx( rTxtNode );
158 0 : _SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
159 0 : pSrtLst->insert( pNew );
160 : }
161 : else
162 0 : aTmpLst.erase( it );
163 : }
164 0 : }
165 : }
166 : }
167 :
168 : // the pointers are not needed anymore
169 0 : aTmpLst.clear();
170 0 : return !pSrtLst->empty();
171 270 : }
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|