27 #include <unonames.hxx>
35 #include <editeng/editeng.hxx>
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
43 #include <com/sun/star/text/TextContentAnchorType.hpp>
44 #include <com/sun/star/text/WrapTextMode.hpp>
45 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
46 #include <com/sun/star/text/textfield/Type.hpp>
62 {
u"", 0, css::uno::Type(), 0, 0 }
72 {
u"", 0, css::uno::Type(), 0, 0 }
88 {
u"", 0, css::uno::Type(), 0, 0 }
91 return &aURLPropertySet_Impl;
101 {
u"", 0, css::uno::Type(), 0, 0 }
103 static SfxItemPropertySet aHeaderFieldPropertySet_Impl( aHeaderFieldPropertyMap_Impl );
104 return &aHeaderFieldPropertySet_Impl;
115 {
u"", 0, css::uno::Type(), 0, 0 }
118 return &aFileFieldPropertySet_Impl;
125 case text::FilenameDisplayFormat::FULL:
return SvxFileFormat::PathFull;
126 case text::FilenameDisplayFormat::PATH:
return SvxFileFormat::PathOnly;
127 case text::FilenameDisplayFormat::NAME:
return SvxFileFormat::NameOnly;
129 return SvxFileFormat::NameAndExt;
137 case SvxFileFormat::NameAndExt:
return text::FilenameDisplayFormat::NAME_AND_EXT;
138 case SvxFileFormat::PathFull:
return text::FilenameDisplayFormat::FULL;
139 case SvxFileFormat::PathOnly:
return text::FilenameDisplayFormat::PATH;
141 return text::FilenameDisplayFormat::NAME;
155 SC_UNO_COLLECT_COUNT,
156 SC_UNO_COLLECT_FINDINDEX,
157 SC_UNO_COLLECT_FINDPOS
168 sal_uInt16 nFieldCount;
169 sal_Int32 mnFieldType;
170 std::unique_ptr<SvxFieldData>
174 sal_uInt16 nFieldIndex;
179 virtual OUString CalcFieldValue(
const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos,
180 std::optional<Color>& rTxtColor, std::optional<Color>& rFldColor )
override;
182 sal_uInt16 CountFields();
186 sal_Int32 GetFieldPar()
const {
return nFieldPar; }
187 sal_Int32 GetFieldPos()
const {
return nFieldPos; }
194 ,
eMode(SC_UNO_COLLECT_NONE)
202 SetTextCurrentDefaults( *pData );
205 OUString ScUnoEditEngine::CalcFieldValue(
const SvxFieldItem& rField,
206 sal_Int32 nPara, sal_Int32 nPos, std::optional<Color>& rTxtColor, std::optional<Color>& rFldColor )
209 if (eMode != SC_UNO_COLLECT_NONE)
214 if (mnFieldType == text::textfield::Type::UNSPECIFIED || pFieldData->
GetClassId() == mnFieldType)
216 if ( eMode == SC_UNO_COLLECT_FINDINDEX && !pFound && nFieldCount == nFieldIndex )
218 pFound = pFieldData->
Clone();
222 if ( eMode == SC_UNO_COLLECT_FINDPOS && !pFound &&
223 nPara == nFieldPar && nPos == nFieldPos )
225 pFound = pFieldData->
Clone();
226 nFieldIndex = nFieldCount;
235 sal_uInt16 ScUnoEditEngine::CountFields()
237 eMode = SC_UNO_COLLECT_COUNT;
238 mnFieldType = text::textfield::Type::UNSPECIFIED;
241 eMode = SC_UNO_COLLECT_NONE;
246 SvxFieldData* ScUnoEditEngine::FindByIndex(sal_uInt16 nIndex)
248 eMode = SC_UNO_COLLECT_FINDINDEX;
249 nFieldIndex = nIndex;
250 mnFieldType = text::textfield::Type::UNSPECIFIED;
253 eMode = SC_UNO_COLLECT_NONE;
258 SvxFieldData* ScUnoEditEngine::FindByPos(sal_Int32 nPar, sal_Int32 nPos, sal_Int32
nType)
260 eMode = SC_UNO_COLLECT_FINDPOS;
266 mnFieldType = text::textfield::Type::UNSPECIFIED;
267 eMode = SC_UNO_COLLECT_NONE;
273 const uno::Reference<text::XTextRange>& xContent,
299 aEvent.Source.set(static_cast<cppu::OWeakObject*>(
this));
307 if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
311 else if ( rHint.
GetId() == SfxHintId::Dying )
325 ScUnoEditEngine aTempEngine(pEditEngine);
326 SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index));
328 return uno::Reference<text::XTextField>();
330 sal_Int32 nPar = aTempEngine.GetFieldPar();
331 sal_Int32 nPos = aTempEngine.GetFieldPos();
332 ESelection aSelection( nPar, nPos, nPar, nPos+1 );
335 uno::Reference<text::XTextField> xRet(
346 ScUnoEditEngine aTempEngine(pEditEngine);
348 return aTempEngine.CountFields();
356 throw lang::IndexOutOfBoundsException();
358 return uno::makeAny(xField);
380 const uno::Reference<container::XContainerListener>& )
382 OSL_FAIL(
"not implemented");
386 const uno::Reference<container::XContainerListener>& )
388 OSL_FAIL(
"not implemented");
398 aEvent.Source.set(uno::Reference< util::XRefreshable >(
this));
452 ScUnoEditEngine aTempEngine(pEditEngine);
454 SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index));
459 uno::Reference<text::XTextRange> xTextRange;
461 if (!xContentObj.is())
462 throw uno::RuntimeException(
"");
465 uno::Reference<text::XText> xText;
470 xText = pContentObj->getLeftText();
473 xText = pContentObj->getCenterText();
476 xText = pContentObj->getRightText();
482 sal_Int32 nPar = aTempEngine.GetFieldPar();
483 sal_Int32 nPos = aTempEngine.GetFieldPos();
484 ESelection aSelection( nPar, nPos, nPar, nPos+1 );
487 uno::Reference<text::XTextField> xRet(
488 new ScEditFieldObj(xTextRange, std::make_unique<ScHeaderFooterEditSource>(
mrData), eRealType, aSelection));
498 ScUnoEditEngine aTempEngine(pEditEngine);
499 return aTempEngine.CountFields();
507 throw lang::IndexOutOfBoundsException();
509 return uno::makeAny(xField);
531 const uno::Reference<container::XContainerListener>& )
533 OSL_FAIL(
"not implemented");
537 const uno::Reference<container::XContainerListener>& )
539 OSL_FAIL(
"not implemented");
549 aEvent.Source.set(uno::Reference< util::XRefreshable >(
this));
584 case text::textfield::Type::EXTENDED_FILE:
586 new SvxExtFileField(OUString(), SvxFileType::Var, SvxFileFormat::NameAndExt));
588 case text::textfield::Type::PAGE:
591 case text::textfield::Type::PAGES:
597 case text::textfield::Type::TIME:
600 case text::textfield::Type::EXTENDED_TIME:
608 case text::textfield::Type::DOCINFO_TITLE:
611 case text::textfield::Type::URL:
613 new SvxURLField(OUString(), OUString(), SvxURLFormat::AppDefault));
629 ScUnoEditEngine aTempEngine(pEditEngine);
634 OSL_ENSURE(pField,
"setPropertyValue: Field not found");
638 if (pField->
GetClassId() != text::textfield::Type::URL)
646 if (rVal >>= aStrVal)
651 if (rVal >>= aStrVal)
656 if (rVal >>= aStrVal)
660 throw beans::UnknownPropertyException(rName);
671 if (rVal >>= aStrVal)
676 if (rVal >>= aStrVal)
681 if (rVal >>= aStrVal)
685 throw beans::UnknownPropertyException(rName);
698 ScUnoEditEngine aTempEngine(pEditEngine);
703 OSL_ENSURE(pField,
"getPropertyValue: Field not found");
705 throw uno::RuntimeException();
707 if (pField->
GetClassId() != text::textfield::Type::URL)
708 throw uno::RuntimeException();
719 throw beans::UnknownPropertyException(rName);
732 throw beans::UnknownPropertyException(rName);
740 throw beans::UnknownPropertyException(rName);
742 sal_Int16 nIntVal = 0;
743 if (!(rVal >>= nIntVal))
750 ScUnoEditEngine aTempEngine(pEditEngine);
753 OSL_ENSURE(pField,
"setPropertyValueFile: Field not found");
774 throw beans::UnknownPropertyException(rName);
781 ScUnoEditEngine aTempEngine(pEditEngine);
782 pField = aTempEngine.FindByPos(
788 OSL_ENSURE(pField,
"setPropertyValueFile: Field not found");
790 throw uno::RuntimeException();
794 sal_Int16 nIntVal = lcl_SvxToUnoFileFormat(eFormat);
806 ScUnoEditEngine aTempEngine(pEditEngine);
837 throw beans::UnknownPropertyException(rName);
840 case text::textfield::Type::TIME:
845 throw beans::UnknownPropertyException(rName);
848 case text::textfield::Type::EXTENDED_TIME:
872 throw beans::UnknownPropertyException(rName);
876 throw beans::UnknownPropertyException(rName);
890 throw beans::UnknownPropertyException(rName);
900 ScUnoEditEngine aTempEngine(pEditEngine);
903 throw uno::RuntimeException();
911 return uno::makeAny(
true);
914 return uno::makeAny<sal_Bool>(p->
GetType() == SvxDateType::Fix);
930 return uno::makeAny<sal_Int32>(
static_cast<sal_Int32
>(p->
GetFormat()));
933 case text::textfield::Type::TIME:
937 return uno::makeAny(
false);
940 return uno::makeAny(
false);
948 return uno::makeAny<sal_Int32>(0);
951 case text::textfield::Type::EXTENDED_TIME:
955 return uno::makeAny(
false);
958 return uno::makeAny<sal_Bool>(p->
GetType() == SvxTimeType::Fix);
974 return uno::makeAny<sal_Int32>(
static_cast<sal_Int32
>(p->
GetFormat()));
984 return uno::makeAny<sal_Bool>(
mbIsDate);
987 return uno::makeAny<sal_Bool>(
mbIsFixed);
996 throw beans::UnknownPropertyException(rName);
1005 ScUnoEditEngine aTempEngine(pEditEngine);
1010 OSL_ENSURE(pField,
"setPropertyValue: Field not found");
1021 throw beans::UnknownPropertyException(rName);
1023 sal_Int32 nTab = rVal.get<sal_Int32>();
1035 throw beans::UnknownPropertyException(rName);
1037 sal_Int32 nTab = rVal.get<sal_Int32>();
1042 const uno::Reference<text::XTextRange>& rContent,
1043 std::unique_ptr<ScEditSource> pEditSrc, sal_Int32 eType,
const ESelection& rSel) :
1046 mpEditSource(
std::move(pEditSrc)),
1048 meType(eType), mpContent(rContent), mnNumFormat(0), mbIsDate(false), mbIsFixed(false)
1052 case text::textfield::Type::DOCINFO_TITLE:
1055 case text::textfield::Type::EXTENDED_FILE:
1056 pPropSet = lcl_GetFileFieldPropertySet();
1058 case text::textfield::Type::URL:
1059 pPropSet = lcl_GetURLPropertySet();
1062 case text::textfield::Type::TIME:
1063 case text::textfield::Type::EXTENDED_TIME:
1064 pPropSet = getDateTimePropertySet();
1067 pPropSet = lcl_GetHeaderFieldPropertySet();
1075 const uno::Reference<text::XTextRange>& rContent, std::unique_ptr<ScEditSource> pEditSrc,
const ESelection& rSel)
1093 OSL_ENSURE( !
mpEditSource,
"CreateFieldItem with inserted field" );
1129 ScUnoEditEngine aTempEngine(pEditEngine);
1134 OSL_ENSURE(pField,
"getPresentation: Field not found");
1140 case text::textfield::Type::URL:
1142 if (pField->
GetClassId() != text::textfield::Type::URL)
1144 throw uno::RuntimeException();
1161 if (xTextRange.is())
1163 uno::Reference<text::XText> xText(xTextRange->getText());
1166 xText->insertTextContent( xTextRange,
this,
true );
1181 OComponentHelper::dispose();
1185 const uno::Reference<lang::XEventListener>& xListener )
1187 OComponentHelper::addEventListener( xListener );
1191 const uno::Reference<lang::XEventListener>& xListener )
1193 OComponentHelper::removeEventListener( xListener );
1206 const OUString& aPropertyName,
const uno::Any& aValue )
1217 case text::textfield::Type::URL:
1220 case text::textfield::Type::EXTENDED_FILE:
1224 case text::textfield::Type::TIME:
1225 case text::textfield::Type::EXTENDED_TIME:
1231 case text::textfield::Type::DOCINFO_TITLE:
1233 throw beans::UnknownPropertyException(OUString::number(
meType));
1241 return uno::makeAny(
meType);
1249 aRet <<= text::TextContentAnchorType_AS_CHARACTER;
1255 uno::Sequence<text::TextContentAnchorType>
aSeq(1);
1256 aSeq[0] = text::TextContentAnchorType_AS_CHARACTER;
1263 aRet <<= text::WrapTextMode_NONE;
1269 case text::textfield::Type::URL:
1271 case text::textfield::Type::EXTENDED_FILE:
1274 case text::textfield::Type::TIME:
1275 case text::textfield::Type::EXTENDED_TIME:
1277 case text::textfield::Type::DOCINFO_TITLE:
1279 throw beans::UnknownPropertyException(OUString::number(
meType));
1291 OUString SAL_CALL ScEditFieldObj::getImplementationName()
1293 return "ScEditFieldObj";
1303 return {
"com.sun.star.text.TextField",
1304 "com.sun.star.text.TextContent"};
1310 OComponentHelper::getTypes(),
1311 uno::Sequence<uno::Type>
1322 return css::uno::Sequence<sal_Int8>();
#define SC_UNONAME_ISFIXED
std::unique_ptr< ScEditSource > mpEditSource
void SetFixDate(const Date &rDate)
virtual OUString SAL_CALL getPresentation(sal_Bool bShowCommand) override
void SetTargetFrame(const OUString &rFrm)
std::unique_ptr< SvxFieldData > mpData
std::unique_ptr< ScEditSource > mpEditSource
virtual OUString CalcFieldValue(const SvxFieldItem &rField, sal_Int32 nPara, sal_Int32 nPos, std::optional< Color > &rTxtColor, std::optional< Color > &rFldColor)
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
std::unique_ptr< ContentProperties > pData
void SetFormat(SvxDateFormat eFmt)
const SfxItemPropertySet * pPropSet
void QuickInsertField(const SvxFieldItem &rFld, const ESelection &rSel)
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
const ContentProperties & rData
SvxTimeType GetType() const
virtual ~ScCellFieldsObj() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
void SetFormat(SvxTimeFormat eFmt)
css::uno::Reference< css::text::XTextRange > mxContent
const OUString & GetTargetFrame() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
void setPropertyValueURL(const OUString &rName, const css::uno::Any &rVal)
css::uno::Reference< css::text::XTextRange > mpContent
UNO3_GETIMPLEMENTATION_IMPL(ScEditFieldObj)
#define SC_UNONAME_ANCTYPE
HashMap_OWString_Interface aMap
Generic UNO wrapper for edit engine's field item in cells, headers, and footers.
#define SC_UNONAME_ANCHOR
void SetFixTime(const tools::Time &rTime)
#define SC_UNONAME_DATETIME
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
void SetFormat(SvxFileFormat eFmt)
SvxFileFormat GetFormat() const
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
SvxDateFormat GetFormat() const
#define SC_UNONAME_TEXTWRAP
exports com.sun.star. text
SvxFieldItem CreateFieldItem()
css::uno::Reference< css::text::XTextField > GetObjectByIndex_Impl(sal_Int32 Index) const
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
css::uno::Any getPropertyValueFile(const OUString &rName)
virtual void SAL_CALL refresh() override
sal_Int32 GetFixDate() const
void InitDoc(const css::uno::Reference< css::text::XTextRange > &rContent, std::unique_ptr< ScEditSource > pEditSrc, const ESelection &rSel)
void SetRepresentation(const OUString &rRep)
osl::Mutex aMutex
mutex to lock the InterfaceContainerHelper
std::unique_ptr< EditTextObject > CreateTextObject()
#define SC_UNONAME_TARGET
virtual ~ScEditFieldObj() override
virtual sal_Bool SAL_CALL hasElements() override
css::util::DateTime maDateTime
const OUString & GetRepresentation() const
css::uno::Type const & get()
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
void setPropertyValueFile(const OUString &rName, const css::uno::Any &rVal)
css::uno::Any getPropertyValueDateTime(const OUString &rName)
virtual sal_Int32 SAL_CALL getCount() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &...rSn)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
sal_Int64 GetFixTime() const
#define SC_IMPL_DUMMY_PROPERTY_LISTENER(ClassName)
const OUString & GetURL() const
void AddUnoObject(SfxListener &rObject)
virtual sal_Int32 GetClassId() const
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
css::uno::Any getPropertyValueURL(const OUString &rName)
virtual void SAL_CALL removeRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > mpRefreshListeners
List of refresh listeners.
#define SC_UNONAME_ISDATE
#define SC_UNONAME_NUMFMT
#define SC_UNONAME_TABLEPOS
virtual void SAL_CALL dispose() override
void RemoveUnoObject(SfxListener &rObject)
Sequence< sal_Int8 > aSeq
const ScDocument & GetDocument() const
SvxDateType GetType() const
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void QuickInsertText(const OUString &rText, const ESelection &rSel)=0
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
SvxTimeFormat GetFormat() const
constexpr sal_uInt16 EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
exports com.sun.star.text. textfield
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
void SetURL(const OUString &rURL)
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
virtual css::uno::Type SAL_CALL getElementType() override
void setPropertyValueDateTime(const OUString &rName, const css::uno::Any &rVal)
virtual std::unique_ptr< SvxFieldData > Clone() const
#define SC_UNONAME_FILEFORM
void setPropertyValueSheet(const OUString &rName, const css::uno::Any &rVal)
void SetType(SvxTimeType eTp)
#define SC_UNONAME_ANCTYPES
ScCellFieldsObj(const css::uno::Reference< css::text::XTextRange > &xContent, ScDocShell *pDocSh, const ScAddress &rPos)
void SetType(SvxDateType eTp)
const SvxFieldData * GetField() const
#define SC_UNONAME_TEXTFIELD_TYPE
::osl::Mutex & getMutex()
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override