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  std::vector<SwFormatField*> vFields;
47  for(size_t i = 0; i < nSize; ++i)
48  {
49  SwFieldType* pFieldType = rFieldTypes[ i ].get();
50  const SwFieldIds nType = pFieldType->Which();
51  if(SwFieldIds::SetExp == nType || SwFieldIds::Input == nType || SwFieldIds::Dropdown == nType)
52  pFieldType->GatherFields(vFields);
53  }
54  for(auto pFormatField: vFields)
55  {
56  auto pSetExpField = dynamic_cast<SwSetExpField*>(pFormatField->GetField());
57  if(pSetExpField && !pSetExpField->GetInputFlag())
58  continue;
59  const SwTextField* pTextField = pFormatField->GetTextField();
60  if(bBuildTmpLst)
61  maTmpLst.insert(pTextField);
62  else
63  {
64  SwNodeIndex aIdx(pTextField->GetTextNode());
65  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField));
66  mpSrtLst->insert(std::move(pNew));
67  }
68  }
69 }
70 
72 {
73 }
74 
76 {
77  return mpSrtLst->size();
78 }
79 
80 // get field from list in sorted order
82 {
83  const SwTextField* pTextField = (*mpSrtLst)[ nId ]->GetTextField();
84  OSL_ENSURE( pTextField, "no TextField" );
85  return const_cast<SwField*>(pTextField->GetFormatField().GetField());
86 }
87 
90 {
91  mpSh->Push();
92  mpSh->ClearMark();
93 }
94 
97 {
99 }
100 
103 {
104  mpSh->StartAllAction();
105  (*mpSrtLst)[ nId ]->GetPosOfContent( *mpSh->GetCursor()->GetPoint() );
106  mpSh->EndAllAction();
107 }
108 
117 {
118  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
119  const size_t nSize = rFieldTypes.size();
120 
121  // iterate over all types
122  std::vector<SwFormatField*> vFields;
123  for(size_t i = 0; i < nSize; ++i)
124  {
125  SwFieldType* pFieldType = rFieldTypes[ i ].get();
126  const SwFieldIds nType = pFieldType->Which();
127  if(SwFieldIds::SetExp == nType || SwFieldIds::Input == nType)
128  pFieldType->GatherFields(vFields);
129  }
130  for(auto pFormatField: vFields)
131  {
132  auto pSetExpField = dynamic_cast<SwSetExpField*>(pFormatField->GetField());
133  if(pSetExpField && !pSetExpField->GetInputFlag())
134  continue;
135  const SwTextField* pTextField = pFormatField->GetTextField();
136  // not in TempList, thus add to SortList
137  auto it = maTmpLst.find(pTextField);
138  if(maTmpLst.end() == it)
139  {
140  SwNodeIndex aIdx(pTextField->GetTextNode());
141  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
142  mpSrtLst->insert(std::move(pNew));
143  }
144  else
145  maTmpLst.erase(it);
146  }
147 
148  // the pointers are not needed anymore
149  maTmpLst.clear();
150  return !mpSrtLst->empty();
151 }
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
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:116
const SwField * GetField() const
Definition: fmtfld.hxx:111
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:189
SwField * GetField(size_t nId)
Definition: fldlst.cxx:81
Base class of all fields.
Definition: fldbas.hxx:293
const_iterator find(const Value &x) const
void EndAllAction()
Definition: edws.cxx:97
void PushCursor()
save cursor
Definition: fldlst.cxx:89
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:193
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
void PopCursor()
get cursor
Definition: fldlst.cxx:96
void GotoFieldPos(size_t nId)
go to position of a field
Definition: fldlst.cxx:102
int i
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2236
SwFieldIds
Definition: fldbas.hxx:44
size_t Count() const
Definition: fldlst.cxx:75
Marks a node in the document model.
Definition: ndindex.hxx:31
virtual const SwFieldTypes * GetFieldTypes() const =0
const_iterator end() const
QPRO_FUNC_TYPE nType
void ClearMark()
Definition: crsrsh.cxx:937
bool Pop(PopMode)
delete cursor
Definition: crsrsh.cxx:2258
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:361
SwFieldIds Which() const
Definition: fldbas.hxx:272
std::unique_ptr< SetGetExpFields > mpSrtLst
Definition: expfld.hxx:362
size_type erase(const Value &x)