LibreOffice Module editeng (master) 1
fieldupdater.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
10#include <memory>
12#include <editeng/flditem.hxx>
13#include "editobj2.hxx"
14
15#include <com/sun/star/text/textfield/Type.hpp>
16
17using namespace com::sun::star;
18
19namespace editeng {
20
22{
24public:
25 explicit FieldUpdaterImpl(EditTextObject& rObj) : mrObj(toImpl(rObj)) {}
26
27 void updateTableFields(int nTab)
28 {
29 SfxItemPool* pPool = mrObj.GetPool();
31 for (std::unique_ptr<ContentInfo> & i : rContents)
32 {
33 ContentInfo& rContent = *i;
34 for (XEditAttribute & rAttr : rContent.GetCharAttribs())
35 {
36 const SfxPoolItem* pItem = rAttr.GetItem();
37 if (pItem->Which() != EE_FEATURE_FIELD)
38 // This is not a field item.
39 continue;
40
41 const SvxFieldItem* pFI = static_cast<const SvxFieldItem*>(pItem);
42 const SvxFieldData* pData = pFI->GetField();
43 if (pData->GetClassId() != text::textfield::Type::TABLE)
44 // This is not a table field.
45 continue;
46
47 // Create a new table field with the new ID, and set it to the
48 // attribute object.
50 rAttr.SetItem(pPool->Put(aNewItem));
51 }
52 }
53 }
54};
55
57FieldUpdater::FieldUpdater(const FieldUpdater& r) : mpImpl(new FieldUpdaterImpl(*r.mpImpl)) {}
58
60{
61}
62
64{
65 mpImpl->updateTableFields(nTab);
66}
67
68}
69
70/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const std::vector< XEditAttribute > & GetCharAttribs() const
Definition: editobj2.hxx:148
std::vector< std::unique_ptr< ContentInfo > > ContentInfosType
Definition: editobj2.hxx:175
SfxItemPool * GetPool()
Definition: editobj2.hxx:223
ContentInfosType & GetContents()
Definition: editobj2.hxx:221
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
sal_uInt16 Which() const
This item stores a field (SvxFieldData).
Definition: flditem.hxx:70
const SvxFieldData * GetField() const
Definition: flditem.hxx:81
FieldUpdaterImpl(EditTextObject &rObj)
void updateTableFields(int nTab)
EditTextObjectImpl & mrObj
Wrapper for EditTextObject to handle updating of fields without exposing the internals of EditTextObj...
std::unique_ptr< FieldUpdaterImpl > mpImpl
FieldUpdater(EditTextObject &rObj)
void updateTableFields(int nTab)
Set a new table ID to all table fields.
EditTextObjectImpl & toImpl(EditTextObject &rObj)
Definition: editobj2.hxx:273
constexpr TypedWhichId< SvxFieldItem > EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
std::unique_ptr< sal_Int32[]> pData
int i