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 <edimp.hxx>
28 #include <expfld.hxx>
29 #include <pam.hxx>
30 #include <docfld.hxx>
31 #include <ndtxt.hxx>
32 
33 #include <osl/diagnose.h>
34 
35 // sort input values
36 
37 SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
38  : mpSh(pShell)
39 {
40  // create sorted list of all input fields
41  mpSrtLst.reset( new SetGetExpFields );
42 
43  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
44  const size_t nSize = rFieldTypes.size();
45 
46  // iterate over all types
47  for(size_t i=0; i < nSize; ++i)
48  {
49  SwFieldType* pFieldType = rFieldTypes[ i ].get();
50  const SwFieldIds nType = pFieldType->Which();
51 
52  if( SwFieldIds::SetExp == nType || SwFieldIds::Input == nType || SwFieldIds::Dropdown == nType )
53  {
54  SwIterator<SwFormatField,SwFieldType> aIter( *pFieldType );
55  for( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
56  {
57  const SwTextField* pTextField = pFormatField->GetTextField();
58 
59  // only process InputFields, interactive SetExpFields and DropDown fields
60  if( !pTextField || ( SwFieldIds::SetExp == nType &&
61  !static_cast<SwSetExpField*>(pFormatField->GetField())->GetInputFlag()))
62  continue;
63 
64  const SwTextNode& rTextNode = pTextField->GetTextNode();
65  if( rTextNode.GetNodes().IsDocNodes() )
66  {
67  if( bBuildTmpLst )
68  {
69  maTmpLst.insert( pTextField );
70  }
71  else
72  {
73  SwNodeIndex aIdx( rTextNode );
74  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
75  mpSrtLst->insert( std::move(pNew) );
76  }
77  }
78  }
79  }
80  }
81 }
82 
84 {
85 }
86 
88 {
89  return mpSrtLst->size();
90 }
91 
92 // get field from list in sorted order
94 {
95  const SwTextField* pTextField = (*mpSrtLst)[ nId ]->GetTextField();
96  OSL_ENSURE( pTextField, "no TextField" );
97  return const_cast<SwField*>(pTextField->GetFormatField().GetField());
98 }
99 
102 {
103  mpSh->Push();
104  mpSh->ClearMark();
105 }
106 
109 {
111 }
112 
115 {
116  mpSh->StartAllAction();
117  (*mpSrtLst)[ nId ]->GetPosOfContent( *mpSh->GetCursor()->GetPoint() );
118  mpSh->EndAllAction();
119 }
120 
129 {
130  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
131  const size_t nSize = rFieldTypes.size();
132 
133  // iterate over all types
134  for( size_t i = 0; i < nSize; ++i )
135  {
136  SwFieldType* pFieldType = rFieldTypes[ i ].get();
137  const SwFieldIds nType = pFieldType->Which();
138 
139  if( SwFieldIds::SetExp == nType || SwFieldIds::Input == nType )
140  {
141  SwIterator<SwFormatField,SwFieldType> aIter( *pFieldType );
142  for( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
143  {
144  const SwTextField* pTextField = pFormatField->GetTextField();
145 
146  // process only InputFields and interactive SetExpFields
147  if( !pTextField || ( SwFieldIds::SetExp == nType &&
148  !static_cast<SwSetExpField*>(pFormatField->GetField())->GetInputFlag()))
149  continue;
150 
151  const SwTextNode& rTextNode = pTextField->GetTextNode();
152  if( rTextNode.GetNodes().IsDocNodes() )
153  {
154  // not in TempList, thus add to SortList
155  std::set<const SwTextField*>::iterator it = maTmpLst.find( pTextField );
156  if( maTmpLst.end() == it )
157  {
158  SwNodeIndex aIdx( rTextNode );
159  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
160  mpSrtLst->insert( std::move(pNew) );
161  }
162  else
163  maTmpLst.erase( it );
164  }
165  }
166  }
167  }
168 
169  // the pointers are not needed anymore
170  maTmpLst.clear();
171  return !mpSrtLst->empty();
172 }
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:233
SwInputFieldList(SwEditShell *pShell, bool bBuildTmpLst=false)
Definition: fldlst.cxx:37
bool BuildSortLst()
Put all that are new into SortList for updating.
Definition: fldlst.cxx:128
const SwField * GetField() const
Definition: fmtfld.hxx:71
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:93
std::set< const SwTextField * > maTmpLst
Definition: expfld.hxx:363
Base class of all fields.
Definition: fldbas.hxx:279
TElementType * Next()
Definition: calbck.hxx:376
void EndAllAction()
Definition: edws.cxx:96
void PushCursor()
save cursor
Definition: fldlst.cxx:101
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:389
FUNC_TYPE const nType
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
void PopCursor()
get cursor
Definition: fldlst.cxx:108
void GotoFieldPos(size_t nId)
go to position of a field
Definition: fldlst.cxx:114
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2225
TElementType * First()
Definition: calbck.hxx:345
int i
SwFieldIds
Definition: fldbas.hxx:38
size_t Count() const
Definition: fldlst.cxx:87
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
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:2336
bool Pop(PopMode)
delete cursor
Definition: crsrsh.cxx:2247
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SwEditShell * mpSh
Definition: expfld.hxx:361
SwFieldIds Which() const
Definition: fldbas.hxx:265
std::unique_ptr< SetGetExpFields > mpSrtLst
Definition: expfld.hxx:362