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
35 : mpSh(pShell)
36{
37 // create sorted list of all input fields
38 mpSrtLst.reset( new SetGetExpFields );
39
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();
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 std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(pTextField->GetTextNode(), pTextField));
63 mpSrtLst->insert(std::move(pNew));
64 }
65 }
66}
67
69{
70}
71
73{
74 return mpSrtLst->size();
75}
76
77// get field from list in sorted order
79{
80 const SwTextField* pTextField = (*mpSrtLst)[ nId ]->GetTextField();
81 OSL_ENSURE( pTextField, "no TextField" );
82 return const_cast<SwField*>(pTextField->GetFormatField().GetField());
83}
84
87{
88 mpSh->Push();
89 mpSh->ClearMark();
90}
91
94{
96}
97
100{
102 (*mpSrtLst)[ nId ]->GetPosOfContent( *mpSh->GetCursor()->GetPoint() );
104}
105
114{
115 const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
116 const size_t nSize = rFieldTypes.size();
117
118 // iterate over all types
119 std::vector<SwFormatField*> vFields;
120 for(size_t i = 0; i < nSize; ++i)
121 {
122 SwFieldType* pFieldType = rFieldTypes[ i ].get();
123 const SwFieldIds nType = pFieldType->Which();
125 pFieldType->GatherFields(vFields);
126 }
127 for(auto pFormatField: vFields)
128 {
129 auto pSetExpField = dynamic_cast<SwSetExpField*>(pFormatField->GetField());
130 if(pSetExpField && !pSetExpField->GetInputFlag())
131 continue;
132 const SwTextField* pTextField = pFormatField->GetTextField();
133 // not in TempList, thus add to SortList
134 auto it = maTmpLst.find(pTextField);
135 if(maTmpLst.end() == it)
136 {
137 std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(pTextField->GetTextNode(), pTextField ));
138 mpSrtLst->insert(std::move(pNew));
139 }
140 else
141 maTmpLst.erase(it);
142 }
143
144 // the pointers are not needed anymore
145 maTmpLst.clear();
146 return !mpSrtLst->empty();
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual const SwFieldTypes * GetFieldTypes() const =0
bool Pop(PopMode, ::std::optional< SwCallLink > &roLink)
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2550
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
void ClearMark()
Definition: crsrsh.cxx:1225
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:371
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
void EndAllAction()
Definition: edws.cxx:97
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:247
SwFieldIds Which() const
Definition: fldbas.hxx:276
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:205
Base class of all fields.
Definition: fldbas.hxx:296
const SwField * GetField() const
Definition: fmtfld.hxx:131
SwEditShell * mpSh
Definition: expfld.hxx:367
void PopCursor()
get cursor
Definition: fldlst.cxx:93
SwField * GetField(size_t nId)
Definition: fldlst.cxx:78
std::unique_ptr< SetGetExpFields > mpSrtLst
Definition: expfld.hxx:368
size_t Count() const
Definition: fldlst.cxx:72
SwInputFieldList(SwEditShell *pShell, bool bBuildTmpLst=false)
Definition: fldlst.cxx:34
void GotoFieldPos(size_t nId)
go to position of a field
Definition: fldlst.cxx:99
void PushCursor()
save cursor
Definition: fldlst.cxx:86
bool BuildSortLst()
Put all that are new into SortList for updating.
Definition: fldlst.cxx:113
o3tl::sorted_vector< const SwTextField * > maTmpLst
Definition: expfld.hxx:369
const SwPosition * GetPoint() const
Definition: pam.hxx:253
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
const_iterator find(const Value &x) const
size_type erase(const Value &x)
const_iterator end() const
std::pair< const_iterator, bool > insert(Value &&x)
SwFieldIds
Definition: fldbas.hxx:49
int i
sal_Int16 nId
QPRO_FUNC_TYPE nType