LibreOffice Module sw (master)  1
fldlst.cxx
Go to the documentation of this file.
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 <calbck.hxx>
21 #include <editsh.hxx>
22 #include <doc.hxx>
24 #include <docary.hxx>
25 #include <fmtfld.hxx>
26 #include <txtfld.hxx>
27 #include <expfld.hxx>
28 #include <pam.hxx>
29 #include <docfld.hxx>
30 #include <ndtxt.hxx>
31 
32 #include <osl/diagnose.h>
33 
34 // sort input values
35 
36 SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
37  : mpSh(pShell)
38 {
39  // create sorted list of all input fields
40  mpSrtLst.reset( new SetGetExpFields );
41 
42  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
43  const size_t nSize = rFieldTypes.size();
44 
45  // iterate over all types
46  for(size_t i=0; i < nSize; ++i)
47  {
48  SwFieldType* pFieldType = rFieldTypes[ i ].get();
49  const SwFieldIds nType = pFieldType->Which();
50 
51  if( SwFieldIds::SetExp == nType || SwFieldIds::Input == nType || SwFieldIds::Dropdown == nType )
52  {
53  SwIterator<SwFormatField,SwFieldType> aIter( *pFieldType );
54  for( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
55  {
56  const SwTextField* pTextField = pFormatField->GetTextField();
57 
58  // only process InputFields, interactive SetExpFields and DropDown fields
59  if( !pTextField || ( SwFieldIds::SetExp == nType &&
60  !static_cast<SwSetExpField*>(pFormatField->GetField())->GetInputFlag()))
61  continue;
62 
63  const SwTextNode& rTextNode = pTextField->GetTextNode();
64  if( rTextNode.GetNodes().IsDocNodes() )
65  {
66  if( bBuildTmpLst )
67  {
68  maTmpLst.insert( pTextField );
69  }
70  else
71  {
72  SwNodeIndex aIdx( rTextNode );
73  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
74  mpSrtLst->insert( std::move(pNew) );
75  }
76  }
77  }
78  }
79  }
80 }
81 
83 {
84 }
85 
87 {
88  return mpSrtLst->size();
89 }
90 
91 // get field from list in sorted order
93 {
94  const SwTextField* pTextField = (*mpSrtLst)[ nId ]->GetTextField();
95  OSL_ENSURE( pTextField, "no TextField" );
96  return const_cast<SwField*>(pTextField->GetFormatField().GetField());
97 }
98 
101 {
102  mpSh->Push();
103  mpSh->ClearMark();
104 }
105 
108 {
110 }
111 
114 {
115  mpSh->StartAllAction();
116  (*mpSrtLst)[ nId ]->GetPosOfContent( *mpSh->GetCursor()->GetPoint() );
117  mpSh->EndAllAction();
118 }
119 
128 {
129  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
130  const size_t nSize = rFieldTypes.size();
131 
132  // iterate over all types
133  for( size_t i = 0; i < nSize; ++i )
134  {
135  SwFieldType* pFieldType = rFieldTypes[ i ].get();
136  const SwFieldIds nType = pFieldType->Which();
137 
138  if( SwFieldIds::SetExp == nType || SwFieldIds::Input == nType )
139  {
140  SwIterator<SwFormatField,SwFieldType> aIter( *pFieldType );
141  for( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
142  {
143  const SwTextField* pTextField = pFormatField->GetTextField();
144 
145  // process only InputFields and interactive SetExpFields
146  if( !pTextField || ( SwFieldIds::SetExp == nType &&
147  !static_cast<SwSetExpField*>(pFormatField->GetField())->GetInputFlag()))
148  continue;
149 
150  const SwTextNode& rTextNode = pTextField->GetTextNode();
151  if( rTextNode.GetNodes().IsDocNodes() )
152  {
153  // not in TempList, thus add to SortList
154  auto it = maTmpLst.find( pTextField );
155  if( maTmpLst.end() == it )
156  {
157  SwNodeIndex aIdx( rTextNode );
158  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
159  mpSrtLst->insert( std::move(pNew) );
160  }
161  else
162  maTmpLst.erase( it );
163  }
164  }
165  }
166  }
167 
168  // the pointers are not needed anymore
169  maTmpLst.clear();
170  return !mpSrtLst->empty();
171 }
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:237
SwInputFieldList(SwEditShell *pShell, bool bBuildTmpLst=false)
Definition: fldlst.cxx:36
o3tl::sorted_vector< const SwTextField * > maTmpLst
Definition: expfld.hxx:363
bool BuildSortLst()
Put all that are new into SortList for updating.
Definition: fldlst.cxx:127
const SwField * GetField() const
Definition: fmtfld.hxx:91
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:188
SwField * GetField(size_t nId)
Definition: fldlst.cxx:92
Base class of all fields.
Definition: fldbas.hxx:286
TElementType * Next()
Definition: calbck.hxx:373
const_iterator find(const Value &x) const
void EndAllAction()
Definition: edws.cxx:96
void PushCursor()
save cursor
Definition: fldlst.cxx:100
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:356
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
void PopCursor()
get cursor
Definition: fldlst.cxx:107
void GotoFieldPos(size_t nId)
go to position of a field
Definition: fldlst.cxx:113
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2229
TElementType * First()
Definition: calbck.hxx:342
int i
QPRO_FUNC_TYPE const nType
SwFieldIds
Definition: fldbas.hxx:41
size_t Count() const
Definition: fldlst.cxx:86
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
virtual const SwFieldTypes * GetFieldTypes() const =0
const_iterator end() const
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void ClearMark()
Definition: crsrsh.cxx:930
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2313
bool Pop(PopMode)
delete cursor
Definition: crsrsh.cxx:2251
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
std::pair< const_iterator, bool > insert(Value &&x)
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SwEditShell * mpSh
Definition: expfld.hxx:361
SwFieldIds Which() const
Definition: fldbas.hxx:269
std::unique_ptr< SetGetExpFields > mpSrtLst
Definition: expfld.hxx:362
size_type erase(const Value &x)