summaryrefslogtreecommitdiff
path: root/editeng/source/editeng/fieldupdater.cxx
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-05-03 00:14:56 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-05-03 20:28:17 -0400
commit9fbcdedb98f096abfcf1893b3658bc8dc4a2efd4 (patch)
tree71acad37ce0d59b6d5b173f4148ad16a79f6f76d /editeng/source/editeng/fieldupdater.cxx
parente4e4b3d65788d14d5f10cd6bccc713cfe2411cb1 (diff)
Added a field updater wrapper to allow updating of field items.
Change-Id: If39637fd1123b7e6971c639cb7e6774780106ba2
Diffstat (limited to 'editeng/source/editeng/fieldupdater.cxx')
-rw-r--r--editeng/source/editeng/fieldupdater.cxx88
1 files changed, 88 insertions, 0 deletions
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: */