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 <pam.hxx>
28 #include <docfld.hxx>
29 #include <ndtxt.hxx>
30 
31 #include <osl/diagnose.h>
32 
33 // sort input values
34 
35 SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
36  : mpSh(pShell)
37 {
38  // create sorted list of all input fields
39  mpSrtLst.reset( new SetGetExpFields );
40 
41  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
42  const size_t nSize = rFieldTypes.size();
43 
44  // iterate over all types
45  std::vector<SwFormatField*> vFields;
46  for(size_t i = 0; i < nSize; ++i)
47  {
48  SwFieldType* pFieldType = rFieldTypes[ i ].get();
49  const SwFieldIds nType = pFieldType->Which();
50  if(SwFieldIds::SetExp == nType || SwFieldIds::Input == nType || SwFieldIds::Dropdown == nType)
51  pFieldType->GatherFields(vFields);
52  }
53  for(auto pFormatField: vFields)
54  {
55  auto pSetExpField = dynamic_cast<SwSetExpField*>(pFormatField->GetField());
56  if(pSetExpField && !pSetExpField->GetInputFlag())
57  continue;
58  const SwTextField* pTextField = pFormatField->GetTextField();
59  if(bBuildTmpLst)
60  maTmpLst.insert(pTextField);
61  else
62  {
63  SwNodeIndex aIdx(pTextField->GetTextNode());
64  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField));
65  mpSrtLst->insert(std::move(pNew));
66  }
67  }
68 }
69 
71 {
72 }
73 
75 {
76  return mpSrtLst->size();
77 }
78 
79 // get field from list in sorted order
81 {
82  const SwTextField* pTextField = (*mpSrtLst)[ nId ]->GetTextField();
83  OSL_ENSURE( pTextField, "no TextField" );
84  return const_cast<SwField*>(pTextField->GetFormatField().GetField());
85 }
86 
89 {
90  mpSh->Push();
91  mpSh->ClearMark();
92 }
93 
96 {
98 }
99 
102 {
103  mpSh->StartAllAction();
104  (*mpSrtLst)[ nId ]->GetPosOfContent( *mpSh->GetCursor()->GetPoint() );
105  mpSh->EndAllAction();
106 }
107 
116 {
117  const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
118  const size_t nSize = rFieldTypes.size();
119 
120  // iterate over all types
121  std::vector<SwFormatField*> vFields;
122  for(size_t i = 0; i < nSize; ++i)
123  {
124  SwFieldType* pFieldType = rFieldTypes[ i ].get();
125  const SwFieldIds nType = pFieldType->Which();
126  if(SwFieldIds::SetExp == nType || SwFieldIds::Input == nType)
127  pFieldType->GatherFields(vFields);
128  }
129  for(auto pFormatField: vFields)
130  {
131  auto pSetExpField = dynamic_cast<SwSetExpField*>(pFormatField->GetField());
132  if(pSetExpField && !pSetExpField->GetInputFlag())
133  continue;
134  const SwTextField* pTextField = pFormatField->GetTextField();
135  // not in TempList, thus add to SortList
136  auto it = maTmpLst.find(pTextField);
137  if(maTmpLst.end() == it)
138  {
139  SwNodeIndex aIdx(pTextField->GetTextNode());
140  std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
141  mpSrtLst->insert(std::move(pNew));
142  }
143  else
144  maTmpLst.erase(it);
145  }
146 
147  // the pointers are not needed anymore
148  maTmpLst.clear();
149  return !mpSrtLst->empty();
150 }
151 
152 /* 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:35
o3tl::sorted_vector< const SwTextField * > maTmpLst
Definition: expfld.hxx:362
bool BuildSortLst()
Put all that are new into SortList for updating.
Definition: fldlst.cxx:115
const SwField * GetField() const
Definition: fmtfld.hxx:110
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
SwField * GetField(size_t nId)
Definition: fldlst.cxx:80
Base class of all fields.
Definition: fldbas.hxx:289
const_iterator find(const Value &x) const
void EndAllAction()
Definition: edws.cxx:97
void PushCursor()
save cursor
Definition: fldlst.cxx:88
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:205
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:195
void PopCursor()
get cursor
Definition: fldlst.cxx:95
void GotoFieldPos(size_t nId)
go to position of a field
Definition: fldlst.cxx:101
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:2241
SwFieldIds
Definition: fldbas.hxx:44
size_t Count() const
Definition: fldlst.cxx:74
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:942
bool Pop(PopMode)
delete cursor
Definition: crsrsh.cxx:2263
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:360
SwFieldIds Which() const
Definition: fldbas.hxx:272
std::unique_ptr< SetGetExpFields > mpSrtLst
Definition: expfld.hxx:361
size_type erase(const Value &x)