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 <editsh.hxx>
21 #include <doc.hxx>
23 #include <docary.hxx>
24 #include <fmtfld.hxx>
25 #include <txtfld.hxx>
26 #include <expfld.hxx>
27 #include <docfld.hxx>
28 #include <ndtxt.hxx>
29 
30 #include <osl/diagnose.h>
31 
32 // sort input values
33 
34 SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
35  : mpSh(pShell)
36 {
37  // create sorted list of all input fields
38  mpSrtLst.reset( new SetGetExpFields );
39 
40  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
41  const size_t nSize = rFieldTypes.size();
42 
43  // iterate over all types
44  std::vector<SwFormatField*> vFields;
45  for(size_t i = 0; i < nSize; ++i)
46  {
47  SwFieldType* pFieldType = rFieldTypes[ i ].get();
48  const SwFieldIds nType = pFieldType->Which();
49  if(SwFieldIds::SetExp == nType || SwFieldIds::Input == nType || SwFieldIds::Dropdown == nType)
50  pFieldType->GatherFields(vFields);
51  }
52  for(auto pFormatField: vFields)
53  {
54  auto pSetExpField = dynamic_cast<SwSetExpField*>(pFormatField->GetField());
55  if(pSetExpField && !pSetExpField->GetInputFlag())
56  continue;
57  const SwTextField* pTextField = pFormatField->GetTextField();
58  if(bBuildTmpLst)
59  maTmpLst.insert(pTextField);
60  else
61  {
62  SwNodeIndex aIdx(pTextField->GetTextNode());
63  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField));
64  mpSrtLst->insert(std::move(pNew));
65  }
66  }
67 }
68 
70 {
71 }
72 
74 {
75  return mpSrtLst->size();
76 }
77 
78 // get field from list in sorted order
80 {
81  const SwTextField* pTextField = (*mpSrtLst)[ nId ]->GetTextField();
82  OSL_ENSURE( pTextField, "no TextField" );
83  return const_cast<SwField*>(pTextField->GetFormatField().GetField());
84 }
85 
88 {
89  mpSh->Push();
90  mpSh->ClearMark();
91 }
92 
95 {
97 }
98 
101 {
102  mpSh->StartAllAction();
103  (*mpSrtLst)[ nId ]->GetPosOfContent( *mpSh->GetCursor()->GetPoint() );
104  mpSh->EndAllAction();
105 }
106 
115 {
116  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
117  const size_t nSize = rFieldTypes.size();
118 
119  // iterate over all types
120  std::vector<SwFormatField*> vFields;
121  for(size_t i = 0; i < nSize; ++i)
122  {
123  SwFieldType* pFieldType = rFieldTypes[ i ].get();
124  const SwFieldIds nType = pFieldType->Which();
125  if(SwFieldIds::SetExp == nType || SwFieldIds::Input == nType)
126  pFieldType->GatherFields(vFields);
127  }
128  for(auto pFormatField: vFields)
129  {
130  auto pSetExpField = dynamic_cast<SwSetExpField*>(pFormatField->GetField());
131  if(pSetExpField && !pSetExpField->GetInputFlag())
132  continue;
133  const SwTextField* pTextField = pFormatField->GetTextField();
134  // not in TempList, thus add to SortList
135  auto it = maTmpLst.find(pTextField);
136  if(maTmpLst.end() == it)
137  {
138  SwNodeIndex aIdx(pTextField->GetTextNode());
139  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
140  mpSrtLst->insert(std::move(pNew));
141  }
142  else
143  maTmpLst.erase(it);
144  }
145 
146  // the pointers are not needed anymore
147  maTmpLst.clear();
148  return !mpSrtLst->empty();
149 }
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:241
SwInputFieldList(SwEditShell *pShell, bool bBuildTmpLst=false)
Definition: fldlst.cxx:34
o3tl::sorted_vector< const SwTextField * > maTmpLst
Definition: expfld.hxx:368
bool BuildSortLst()
Put all that are new into SortList for updating.
Definition: fldlst.cxx:114
const SwField * GetField() const
Definition: fmtfld.hxx:116
SwField * GetField(size_t nId)
Definition: fldlst.cxx:79
Base class of all fields.
Definition: fldbas.hxx:291
const_iterator find(const Value &x) const
void EndAllAction()
Definition: edws.cxx:97
void PushCursor()
save cursor
Definition: fldlst.cxx:87
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:203
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
SwDoc * GetDoc() const
Definition: viewsh.hxx:282
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
void PopCursor()
get cursor
Definition: fldlst.cxx:94
void GotoFieldPos(size_t nId)
go to position of a field
Definition: fldlst.cxx:100
int i
const SwPosition * GetPoint() const
Definition: pam.hxx:208
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2248
SwFieldIds
Definition: fldbas.hxx:45
size_t Count() const
Definition: fldlst.cxx:73
Marks a node in the document model.
Definition: ndindex.hxx:30
virtual const SwFieldTypes * GetFieldTypes() const =0
const_iterator end() const
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:195
QPRO_FUNC_TYPE nType
void ClearMark()
Definition: crsrsh.cxx:939
bool Pop(PopMode)
delete cursor
Definition: crsrsh.cxx:2270
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:86
SwEditShell * mpSh
Definition: expfld.hxx:366
SwFieldIds Which() const
Definition: fldbas.hxx:273
std::unique_ptr< SetGetExpFields > mpSrtLst
Definition: expfld.hxx:367
size_type erase(const Value &x)