diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-05-03 00:14:56 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-05-03 20:28:17 -0400 |
commit | 9fbcdedb98f096abfcf1893b3658bc8dc4a2efd4 (patch) | |
tree | 71acad37ce0d59b6d5b173f4148ad16a79f6f76d /editeng/source | |
parent | e4e4b3d65788d14d5f10cd6bccc713cfe2411cb1 (diff) |
Added a field updater wrapper to allow updating of field items.
Change-Id: If39637fd1123b7e6971c639cb7e6774780106ba2
Diffstat (limited to 'editeng/source')
-rw-r--r-- | editeng/source/editeng/editattr.hxx | 7 | ||||
-rw-r--r-- | editeng/source/editeng/editobj.cxx | 10 | ||||
-rw-r--r-- | editeng/source/editeng/editobj2.hxx | 3 | ||||
-rw-r--r-- | editeng/source/editeng/fieldupdater.cxx | 88 |
4 files changed, 105 insertions, 3 deletions
diff --git a/editeng/source/editeng/editattr.hxx b/editeng/source/editeng/editattr.hxx index d2cdb42aec35..30dd97c18f84 100644 --- a/editeng/source/editeng/editattr.hxx +++ b/editeng/source/editeng/editattr.hxx @@ -30,6 +30,9 @@ #define _EDITATTR_HXX #include <editeng/eeitem.hxx> +#include <svl/poolitem.hxx> + +#include <boost/noncopyable.hpp> class SvxFont; class SvxFontItem; @@ -52,10 +55,8 @@ class SvxFieldItem; class SvxLanguageItem; class SvxEmphasisMarkItem; class SvxCharReliefItem; -#include <svl/poolitem.hxx> - - class SfxVoidItem; +class OutputDevice; #define CH_FEATURE_OLD (sal_uInt8) 0xFF #define CH_FEATURE (sal_Unicode) 0x01 diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index 0fd9de60a465..ef84d0b8d5b1 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -35,6 +35,7 @@ #include <tools/stream.hxx> +#include "editeng/fieldupdater.hxx" #include <editobj2.hxx> #include <editeng/editdata.hxx> #include <editattr.hxx> @@ -86,6 +87,10 @@ bool XEditAttribute::IsFeature() const return ((nWhich >= EE_FEATURE_START) && (nWhich <= EE_FEATURE_END)); } +void XEditAttribute::SetItem(const SfxPoolItem& rNew) +{ + pItem = &rNew; +} XParaPortionList::XParaPortionList( OutputDevice* pRefDev, sal_uLong nPW, sal_uInt16 _nStretchX, sal_uInt16 _nStretchY) : @@ -1023,6 +1028,11 @@ void BinTextObject::ChangeStyleSheetName( SfxStyleFamily eFamily, ImpChangeStyleSheets( rOldName, eFamily, rNewName, eFamily ); } +editeng::FieldUpdater BinTextObject::GetFieldUpdater() +{ + return editeng::FieldUpdater(*this); +} + namespace { class FindAttribByChar : public std::unary_function<XEditAttribute, bool> diff --git a/editeng/source/editeng/editobj2.hxx b/editeng/source/editeng/editobj2.hxx index 233865350a51..cb0642db9209 100644 --- a/editeng/source/editeng/editobj2.hxx +++ b/editeng/source/editeng/editobj2.hxx @@ -63,6 +63,7 @@ public: sal_uInt16 GetLen() const { return nEnd-nStart; } bool IsFeature() const; + void SetItem(const SfxPoolItem& rNew); inline bool operator==( const XEditAttribute& rCompare ) const; @@ -254,6 +255,8 @@ public: const String& rNewName, SfxStyleFamily eNewFamily ); virtual void ChangeStyleSheetName( SfxStyleFamily eFamily, const XubString& rOldName, const XubString& rNewName ); + virtual editeng::FieldUpdater GetFieldUpdater(); + void CreateData300( SvStream& rIStream ); sal_Bool HasMetric() const { return nMetric != 0xFFFF; } diff --git a/editeng/source/editeng/fieldupdater.cxx b/editeng/source/editeng/fieldupdater.cxx new file mode 100644 index 000000000000..007844093144 --- /dev/null +++ b/editeng/source/editeng/fieldupdater.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com> + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include "editeng/fieldupdater.hxx" +#include "editeng/flditem.hxx" +#include "editobj2.hxx" + +namespace editeng { + +class FieldUpdaterImpl +{ + BinTextObject& mrObj; +public: + FieldUpdaterImpl(EditTextObject& rObj) : mrObj(static_cast<BinTextObject&>(rObj)) {} + FieldUpdaterImpl(const FieldUpdaterImpl& r) : mrObj(r.mrObj) {} + + void updateTableFields(int nTab) + { + SfxItemPool* pPool = mrObj.GetPool(); + BinTextObject::ContentInfosType& rContents = mrObj.GetContents(); + for (size_t i = 0; i < rContents.size(); ++i) + { + ContentInfo& rContent = rContents[i]; + ContentInfo::XEditAttributesType& rAttribs = rContent.GetAttribs(); + for (size_t j = 0; j < rAttribs.size(); ++j) + { + XEditAttribute& rAttr = rAttribs[j]; + const SfxPoolItem* pItem = rAttr.GetItem(); + if (pItem->Which() != EE_FEATURE_FIELD) + // This is not a field item. + continue; + + const SvxFieldItem* pFI = static_cast<const SvxFieldItem*>(pItem); + const SvxFieldData* pData = pFI->GetField(); + if (pData->GetClassId() != SVX_TABLEFIELD) + // This is not a table field. + continue; + + // Create a new table field with the new ID, and set it to the + // attribute object. + SvxFieldItem aNewItem(SvxTableField(nTab), EE_FEATURE_FIELD); + rAttr.SetItem(pPool->Put(aNewItem)); + } + } + } +}; + +FieldUpdater::FieldUpdater(EditTextObject& rObj) : mpImpl(new FieldUpdaterImpl(rObj)) {} +FieldUpdater::FieldUpdater(const FieldUpdater& r) : mpImpl(new FieldUpdaterImpl(*r.mpImpl)) {} + +FieldUpdater::~FieldUpdater() +{ + delete mpImpl; +} + +void FieldUpdater::updateTableFields(int nTab) +{ + mpImpl->updateTableFields(nTab); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |