Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com>
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include "editeng/fieldupdater.hxx"
30 : #include "editeng/flditem.hxx"
31 : #include "editobj2.hxx"
32 :
33 : #include <com/sun/star/text/textfield/Type.hpp>
34 :
35 : using namespace com::sun::star;
36 :
37 : namespace editeng {
38 :
39 : class FieldUpdaterImpl
40 : {
41 : BinTextObject& mrObj;
42 : public:
43 0 : FieldUpdaterImpl(EditTextObject& rObj) : mrObj(static_cast<BinTextObject&>(rObj)) {}
44 0 : FieldUpdaterImpl(const FieldUpdaterImpl& r) : mrObj(r.mrObj) {}
45 :
46 0 : void updateTableFields(int nTab)
47 : {
48 0 : SfxItemPool* pPool = mrObj.GetPool();
49 0 : BinTextObject::ContentInfosType& rContents = mrObj.GetContents();
50 0 : for (size_t i = 0; i < rContents.size(); ++i)
51 : {
52 0 : ContentInfo& rContent = rContents[i];
53 0 : ContentInfo::XEditAttributesType& rAttribs = rContent.GetAttribs();
54 0 : for (size_t j = 0; j < rAttribs.size(); ++j)
55 : {
56 0 : XEditAttribute& rAttr = rAttribs[j];
57 0 : const SfxPoolItem* pItem = rAttr.GetItem();
58 0 : if (pItem->Which() != EE_FEATURE_FIELD)
59 : // This is not a field item.
60 0 : continue;
61 :
62 0 : const SvxFieldItem* pFI = static_cast<const SvxFieldItem*>(pItem);
63 0 : const SvxFieldData* pData = pFI->GetField();
64 0 : if (pData->GetClassId() != text::textfield::Type::TABLE)
65 : // This is not a table field.
66 0 : continue;
67 :
68 : // Create a new table field with the new ID, and set it to the
69 : // attribute object.
70 0 : SvxFieldItem aNewItem(SvxTableField(nTab), EE_FEATURE_FIELD);
71 0 : rAttr.SetItem(pPool->Put(aNewItem));
72 0 : }
73 : }
74 0 : }
75 : };
76 :
77 0 : FieldUpdater::FieldUpdater(EditTextObject& rObj) : mpImpl(new FieldUpdaterImpl(rObj)) {}
78 0 : FieldUpdater::FieldUpdater(const FieldUpdater& r) : mpImpl(new FieldUpdaterImpl(*r.mpImpl)) {}
79 :
80 0 : FieldUpdater::~FieldUpdater()
81 : {
82 0 : delete mpImpl;
83 0 : }
84 :
85 0 : void FieldUpdater::updateTableFields(int nTab)
86 : {
87 0 : mpImpl->updateTableFields(nTab);
88 0 : }
89 :
90 : }
91 :
92 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|