/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** * This class exists solely to allow searching through field items. TODO: * Look into providing the same functionality directly in EditEngine, to * avoid having this class altogether.
*/ class ScUnoEditEngine : public ScEditEngineDefaulter
{
ScUnoCollectMode eMode;
sal_uInt16 nFieldCount;
sal_Int32 mnFieldType;
std::unique_ptr<SvxFieldData>
pFound; // local copy
sal_Int32 nFieldPar;
sal_Int32 nFieldPos;
sal_uInt16 nFieldIndex;
uno::Reference<text::XTextField> ScCellFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const
{ //! Field functions have to be passed to the forwarder !!!
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index)); if (!pData) return uno::Reference<text::XTextField>();
sal_Int32 nPar = aTempEngine.GetFieldPar();
sal_Int32 nPos = aTempEngine.GetFieldPos();
ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Field size is 1 character
//! Field functions have to be passed to the forwarder !!!
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
return aTempEngine.CountFields(); // count the fields, we don't care about their type in the cell
}
uno::Reference<text::XTextField> ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const
{ //! Field functions have to be passed to the forwarder !!!
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index)); if (!pData) return nullptr;
// Get the parent text range instance.
uno::Reference<text::XTextRange> xTextRange;
rtl::Reference<ScHeaderFooterContentObj> xContentObj = mrData.GetContentObj(); if (!xContentObj.is()) throw uno::RuntimeException(u""_ustr);
uno::Reference<text::XText> xText;
switch ( mrData.GetPart() )
{ case ScHeaderFooterPart::LEFT:
xText = xContentObj->getLeftText(); break; case ScHeaderFooterPart::CENTER:
xText = xContentObj->getCenterText(); break; case ScHeaderFooterPart::RIGHT:
xText = xContentObj->getRightText(); break;
}
xTextRange = xText;
sal_Int32 nPar = aTempEngine.GetFieldPar();
sal_Int32 nPos = aTempEngine.GetFieldPos();
ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Field size is 1 character
//! Field functions have to be passed to the forwarder !!!
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine); return aTempEngine.CountFields();
}
SvxFieldData& ScEditFieldObj::getData()
{ if (!mpData)
{ switch (meType)
{ case text::textfield::Type::DATE:
mpData.reset(new SvxDateField); break; case text::textfield::Type::EXTENDED_FILE:
mpData.reset( new SvxExtFileField(OUString(), SvxFileType::Var, SvxFileFormat::NameAndExt)); break; case text::textfield::Type::PAGE:
mpData.reset(new SvxPageField); break; case text::textfield::Type::PAGES:
mpData.reset(new SvxPagesField); break; case text::textfield::Type::TABLE:
mpData.reset(new SvxTableField); break; case text::textfield::Type::TIME:
mpData.reset(new SvxTimeField); break; case text::textfield::Type::EXTENDED_TIME:
{ if (mbIsDate)
mpData.reset(new SvxDateField); else
mpData.reset(new SvxExtTimeField);
} break; case text::textfield::Type::DOCINFO_TITLE:
mpData.reset(new SvxFileField); break; case text::textfield::Type::URL:
mpData.reset( new SvxURLField(OUString(), OUString(), SvxURLFormat::AppDefault)); break; default:
mpData.reset(new SvxFieldData);
}
} return *mpData;
}
void ScEditFieldObj::setPropertyValueURL(const OUString& rName, const css::uno::Any& rVal)
{
OUString aStrVal; if (mpEditSource)
{ // Edit engine instance already exists for this field item. Use it.
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
// don't care about the type (only URLs can be found in the cells)
SvxFieldData* pField = aTempEngine.FindByPos(
aSelection.start, text::textfield::Type::UNSPECIFIED);
OSL_ENSURE(pField,"setPropertyValue: Field not found"); if (!pField) return;
if (pField->GetClassId() != text::textfield::Type::URL) // Make sure this is indeed a URL field. return;
// anchor type is always "as character", text wrap always "none"
if (mpEditSource)
{ //! Field functions have to be passed to the forwarder !!!
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
// don't care about the type (only URLs can be found in the cells) const SvxFieldData* pField = aTempEngine.FindByPos(
aSelection.start, text::textfield::Type::UNSPECIFIED);
OSL_ENSURE(pField,"getPropertyValue: Field not found"); if (!pField) throw uno::RuntimeException();
if (pField->GetClassId() != text::textfield::Type::URL) throw uno::RuntimeException();
if (rName == SC_UNONAME_NUMFMT) return uno::Any(static_cast<sal_Int32>(p->GetFormat()));
} break; case text::textfield::Type::TIME:
{ // SvxTimeField doesn't have any attributes. if (rName == SC_UNONAME_ISDATE) return uno::Any(false);
if (rName == SC_UNONAME_ISFIXED) return uno::Any(false);
if (rName == SC_UNONAME_DATETIME) // This is the best we can do. return uno::Any(maDateTime);
if (rName == SC_UNONAME_NUMFMT) // Same as above. return uno::Any(sal_Int32(0));
} break; case text::textfield::Type::EXTENDED_TIME:
{
SvxExtTimeField* p = static_cast<SvxExtTimeField*>(pField); if (rName == SC_UNONAME_ISDATE) return uno::Any(false);
if (rName == SC_UNONAME_ISFIXED) return uno::Any(p->GetType() == SvxTimeType::Fix);
if (rName == SC_UNONAME_NUMFMT) return uno::Any(static_cast<sal_Int32>(p->GetFormat()));
} break; default:
;
}
} else
{ if (rName == SC_UNONAME_ISDATE) return uno::Any(mbIsDate);
if (rName == SC_UNONAME_ISFIXED) return uno::Any(mbIsFixed);
if (rName == SC_UNONAME_DATETIME) return uno::Any(maDateTime);
if (rName == SC_UNONAME_NUMFMT) return uno::Any(mnNumFormat);
}
throw beans::UnknownPropertyException(rName);
}
void ScEditFieldObj::setPropertyValueSheet(const OUString& rName, const uno::Any& rVal)
{ if (mpEditSource)
{ // Edit engine instance already exists for this field item. Use it.
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
// don't care about the type (only URLs can be found in the cells)
SvxFieldData* pField = aTempEngine.FindByPos(
aSelection.start, text::textfield::Type::UNSPECIFIED);
OSL_ENSURE(pField,"setPropertyValue: Field not found"); if (!pField) return;
if (pField->GetClassId() != text::textfield::Type::TABLE) // Make sure this is indeed a URL field. return;
SvxTableField* p = static_cast<SvxTableField*>(pField);
if (rName != SC_UNONAME_TABLEPOS) throw beans::UnknownPropertyException(rName);
// Edit engine instance not yet present. Store the item data for later use.
SvxTableField& r = static_cast<SvxTableField&>(getData()); if (rName != SC_UNONAME_TABLEPOS) throw beans::UnknownPropertyException(rName);
//! Field functions have to be passed to the forwarder !!!
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
// don't care about the type (only URLs can be found in the cells) const SvxFieldData* pField = aTempEngine.FindByPos(
aSelection.start, text::textfield::Type::UNSPECIFIED);
OSL_ENSURE(pField,"getPresentation: Field not found"); if (!pField) return OUString();
switch (meType)
{ case text::textfield::Type::URL:
{ if (pField->GetClassId() != text::textfield::Type::URL) // Not a URL field, but URL is expected. throw uno::RuntimeException();
switch (meType)
{ case text::textfield::Type::URL:
setPropertyValueURL(aPropertyName, aValue); break; case text::textfield::Type::EXTENDED_FILE:
setPropertyValueFile(aPropertyName, aValue); break; case text::textfield::Type::DATE: case text::textfield::Type::TIME: case text::textfield::Type::EXTENDED_TIME:
setPropertyValueDateTime(aPropertyName, aValue); break; case text::textfield::Type::TABLE:
setPropertyValueSheet(aPropertyName, aValue); break; case text::textfield::Type::DOCINFO_TITLE: default: throw beans::UnknownPropertyException(OUString::number(meType));
}
}
switch (meType)
{ case text::textfield::Type::URL: return getPropertyValueURL(aPropertyName); case text::textfield::Type::EXTENDED_FILE: return getPropertyValueFile(aPropertyName); case text::textfield::Type::DATE: case text::textfield::Type::TIME: case text::textfield::Type::EXTENDED_TIME: return getPropertyValueDateTime(aPropertyName); case text::textfield::Type::DOCINFO_TITLE: default: throw beans::UnknownPropertyException(OUString::number(meType));
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.