android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / fields / fldlst.cxx
blob635d09d0ea30e638bd9d12fbc1aa36e37a0df173
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 <editsh.hxx>
21 #include <doc.hxx>
22 #include <IDocumentFieldsAccess.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>
30 #include <osl/diagnose.h>
32 // sort input values
34 SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
35 : mpSh(pShell)
37 // create sorted list of all input fields
38 mpSrtLst.reset( new SetGetExpFields );
40 const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
41 const size_t nSize = rFieldTypes.size();
43 // iterate over all types
44 std::vector<SwFormatField*> vFields;
45 for(size_t i = 0; i < nSize; ++i)
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);
52 for(auto pFormatField: vFields)
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
62 std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(pTextField->GetTextNode(), pTextField));
63 mpSrtLst->insert(std::move(pNew));
68 SwInputFieldList::~SwInputFieldList()
72 size_t SwInputFieldList::Count() const
74 return mpSrtLst->size();
77 // get field from list in sorted order
78 SwField* SwInputFieldList::GetField(size_t nId)
80 const SwTextField* pTextField = (*mpSrtLst)[ nId ]->GetTextField();
81 OSL_ENSURE( pTextField, "no TextField" );
82 return const_cast<SwField*>(pTextField->GetFormatField().GetField());
85 /// save cursor
86 void SwInputFieldList::PushCursor()
88 mpSh->Push();
89 mpSh->ClearMark();
92 /// get cursor
93 void SwInputFieldList::PopCursor()
95 mpSh->Pop(SwCursorShell::PopMode::DeleteCurrent);
98 /// go to position of a field
99 void SwInputFieldList::GotoFieldPos(size_t nId)
101 mpSh->StartAllAction();
102 (*mpSrtLst)[ nId ]->GetPosOfContent( *mpSh->GetCursor()->GetPoint() );
103 mpSh->EndAllAction();
106 /** Compare TmpLst with current fields.
108 * All new ones are added to SortList so that they can be updated.
109 * For text blocks: update only input fields.
111 * @return true if not empty
113 bool SwInputFieldList::BuildSortLst()
115 const SwFieldTypes& rFieldTypes = *mpSh->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
116 const size_t nSize = rFieldTypes.size();
118 // iterate over all types
119 std::vector<SwFormatField*> vFields;
120 for(size_t i = 0; i < nSize; ++i)
122 SwFieldType* pFieldType = rFieldTypes[ i ].get();
123 const SwFieldIds nType = pFieldType->Which();
124 if(SwFieldIds::SetExp == nType || SwFieldIds::Input == nType)
125 pFieldType->GatherFields(vFields);
127 for(auto pFormatField: vFields)
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)
137 std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(pTextField->GetTextNode(), pTextField ));
138 mpSrtLst->insert(std::move(pNew));
140 else
141 maTmpLst.erase(it);
144 // the pointers are not needed anymore
145 maTmpLst.clear();
146 return !mpSrtLst->empty();
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */