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 | |
parent | e4e4b3d65788d14d5f10cd6bccc713cfe2411cb1 (diff) |
Added a field updater wrapper to allow updating of field items.
Change-Id: If39637fd1123b7e6971c639cb7e6774780106ba2
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/Library_editeng.mk | 1 | ||||
-rw-r--r-- | editeng/Package_inc.mk | 1 | ||||
-rw-r--r-- | editeng/inc/editeng/editobj.hxx | 8 | ||||
-rw-r--r-- | editeng/inc/editeng/fieldupdater.hxx | 66 | ||||
-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 |
8 files changed, 181 insertions, 3 deletions
diff --git a/editeng/Library_editeng.mk b/editeng/Library_editeng.mk index 3645247fc6ab..f2a8594e575c 100644 --- a/editeng/Library_editeng.mk +++ b/editeng/Library_editeng.mk @@ -69,6 +69,7 @@ $(eval $(call gb_Library_add_exception_objects,editeng,\ editeng/source/editeng/eeobj \ editeng/source/editeng/eerdll \ editeng/source/editeng/eertfpar \ + editeng/source/editeng/fieldupdater \ editeng/source/editeng/impedit \ editeng/source/editeng/impedit2 \ editeng/source/editeng/impedit3 \ diff --git a/editeng/Package_inc.mk b/editeng/Package_inc.mk index 0305a047032a..300e2ae89c9f 100644 --- a/editeng/Package_inc.mk +++ b/editeng/Package_inc.mk @@ -72,6 +72,7 @@ $(eval $(call gb_Package_add_file,editeng_inc,inc/editeng/eerdll.hxx,editeng/eer $(eval $(call gb_Package_add_file,editeng_inc,inc/editeng/emphitem.hxx,editeng/emphitem.hxx)) $(eval $(call gb_Package_add_file,editeng_inc,inc/editeng/escpitem.hxx,editeng/escpitem.hxx)) $(eval $(call gb_Package_add_file,editeng_inc,inc/editeng/fhgtitem.hxx,editeng/fhgtitem.hxx)) +$(eval $(call gb_Package_add_file,editeng_inc,inc/editeng/fieldupdater.hxx,editeng/fieldupdater.hxx)) $(eval $(call gb_Package_add_file,editeng_inc,inc/editeng/flditem.hxx,editeng/flditem.hxx)) $(eval $(call gb_Package_add_file,editeng_inc,inc/editeng/flstitem.hxx,editeng/flstitem.hxx)) $(eval $(call gb_Package_add_file,editeng_inc,inc/editeng/fontitem.hxx,editeng/fontitem.hxx)) diff --git a/editeng/inc/editeng/editobj.hxx b/editeng/inc/editeng/editobj.hxx index c57a70b0e3e0..37aaa023bf78 100644 --- a/editeng/inc/editeng/editobj.hxx +++ b/editeng/inc/editeng/editobj.hxx @@ -48,6 +48,12 @@ class SvxFieldItem; #define EDTOBJ_SETTINGS_ULITEMSUMMATION 0x00000001 #define EDTOBJ_SETTINGS_ULITEMFIRSTPARA 0x00000002 +namespace editeng { + +class FieldUpdater; + +} + class EDITENG_DLLPUBLIC EditTextObject { private: @@ -119,6 +125,8 @@ public: const XubString& rNewName, SfxStyleFamily eNewFamily ); virtual void ChangeStyleSheetName( SfxStyleFamily eFamily, const XubString& rOldName, const XubString& rNewName ); + virtual editeng::FieldUpdater GetFieldUpdater() = 0; + bool operator==( const EditTextObject& rCompare ) const; // #i102062# diff --git a/editeng/inc/editeng/fieldupdater.hxx b/editeng/inc/editeng/fieldupdater.hxx new file mode 100644 index 000000000000..960d0e093362 --- /dev/null +++ b/editeng/inc/editeng/fieldupdater.hxx @@ -0,0 +1,66 @@ +/* -*- 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. + */ + +#ifndef __EDITENG_FIELDUPDATER_HXX__ +#define __EDITENG_FIELDUPDATER_HXX__ + +#include "editengdllapi.h" + +class EditTextObject; + +namespace editeng { + +class FieldUpdaterImpl; + +/** + * Wrapper for EditTextObject to handle updating of fields without exposing + * the internals of EditTextObject structure. + */ +class EDITENG_DLLPUBLIC FieldUpdater +{ + FieldUpdaterImpl* mpImpl; + + FieldUpdater(); // disabled +public: + FieldUpdater(EditTextObject& rObj); + FieldUpdater(const FieldUpdater& r); + ~FieldUpdater(); + + /** + * Set a new table ID to all table fields. + * + * @param nTab new table ID + */ + void updateTableFields(int nTab); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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: */ |