nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / fields / fldlst.cxx
blobaa937cb22140a3f6d83381b89fcacd6e74982339
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <calbck.hxx>
21 #include <editsh.hxx>
22 #include <doc.hxx>
23 #include <IDocumentFieldsAccess.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>
32 #include <osl/diagnose.h>
34 // sort input values
36 SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
37 : mpSh(pShell)
39 // create sorted list of all input fields
40 mpSrtLst.reset( new SetGetExpFields );
42 const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
43 const size_t nSize = rFieldTypes.size();
45 // iterate over all types
46 std::vector<SwFormatField*> vFields;
47 for(size_t i = 0; i < nSize; ++i)
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);
54 for(auto pFormatField: vFields)
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
64 SwNodeIndex aIdx(pTextField->GetTextNode());
65 std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField));
66 mpSrtLst->insert(std::move(pNew));
71 SwInputFieldList::~SwInputFieldList()
75 size_t SwInputFieldList::Count() const
77 return mpSrtLst->size();
80 // get field from list in sorted order
81 SwField* SwInputFieldList::GetField(size_t nId)
83 const SwTextField* pTextField = (*mpSrtLst)[ nId ]->GetTextField();
84 OSL_ENSURE( pTextField, "no TextField" );
85 return const_cast<SwField*>(pTextField->GetFormatField().GetField());
88 /// save cursor
89 void SwInputFieldList::PushCursor()
91 mpSh->Push();
92 mpSh->ClearMark();
95 /// get cursor
96 void SwInputFieldList::PopCursor()
98 mpSh->Pop(SwCursorShell::PopMode::DeleteCurrent);
101 /// go to position of a field
102 void SwInputFieldList::GotoFieldPos(size_t nId)
104 mpSh->StartAllAction();
105 (*mpSrtLst)[ nId ]->GetPosOfContent( *mpSh->GetCursor()->GetPoint() );
106 mpSh->EndAllAction();
109 /** Compare TmpLst with current fields.
111 * All new ones are added to SortList so that they can be updated.
112 * For text blocks: update only input fields.
114 * @return true if not empty
116 bool SwInputFieldList::BuildSortLst()
118 const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
119 const size_t nSize = rFieldTypes.size();
121 // iterate over all types
122 std::vector<SwFormatField*> vFields;
123 for(size_t i = 0; i < nSize; ++i)
125 SwFieldType* pFieldType = rFieldTypes[ i ].get();
126 const SwFieldIds nType = pFieldType->Which();
127 if(SwFieldIds::SetExp == nType || SwFieldIds::Input == nType)
128 pFieldType->GatherFields(vFields);
130 for(auto pFormatField: vFields)
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)
140 SwNodeIndex aIdx(pTextField->GetTextNode());
141 std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
142 mpSrtLst->insert(std::move(pNew));
144 else
145 maTmpLst.erase(it);
148 // the pointers are not needed anymore
149 maTmpLst.clear();
150 return !mpSrtLst->empty();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */