diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-05-07 18:04:12 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-05-08 14:23:05 -0400 |
commit | 63114e6d863de32e2d93f0da54caca928916d9c2 (patch) | |
tree | 5325f9c76cbee3f144ad89079d9071bbead176e3 /editeng/source | |
parent | aac15b638410f181133dc15343136b4e9a1675ba (diff) |
Create SvxFieldData instance directly from the UNO textfield object.
Change-Id: Ifa8210ffdf29624689f547b436fd687a2de82eb1
Diffstat (limited to 'editeng/source')
-rw-r--r-- | editeng/source/items/flditem.cxx | 181 | ||||
-rw-r--r-- | editeng/source/uno/unofield.cxx | 5 | ||||
-rw-r--r-- | editeng/source/uno/unotext.cxx | 9 |
3 files changed, 185 insertions, 10 deletions
diff --git a/editeng/source/items/flditem.cxx b/editeng/source/items/flditem.cxx index 5b5361dd93be..36ba686a9960 100644 --- a/editeng/source/items/flditem.cxx +++ b/editeng/source/items/flditem.cxx @@ -34,15 +34,192 @@ #include <unotools/localfilehelper.hxx> #include <editeng/flditem.hxx> - #include <editeng/measfld.hxx> +#include "editeng/unonames.hxx" #include <tools/tenccvt.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/FilenameDisplayFormat.hpp> +#include <com/sun/star/util/DateTime.hpp> + +using namespace com::sun::star; + #define FRAME_MARKER (sal_uInt32)0x21981357 #define CHARSET_MARKER (FRAME_MARKER+1) -// ----------------------------------------------------------------------- +SvxFieldData* SvxFieldData::Create(const uno::Reference<text::XTextContent>& xTextContent) +{ + uno::Reference<beans::XPropertySet> xPropSet(xTextContent, uno::UNO_QUERY); + if (!xPropSet.is()) + return NULL; + + uno::Any aAny = xPropSet->getPropertyValue(UNO_TC_PROP_TEXTFIELD_TYPE); + sal_Int32 nFieldType = aAny.get<sal_Int32>(); + + switch (nFieldType) + { + case text::textfield::Type::TIME: + case text::textfield::Type::EXTENDED_TIME: + case text::textfield::Type::DATE: + case text::textfield::Type::EXTENDED_DATE: + { + sal_Bool bIsDate = false; + xPropSet->getPropertyValue(UNO_TC_PROP_IS_DATE) >>= bIsDate; + + if (bIsDate) + { + util::DateTime aDateTime = xPropSet->getPropertyValue(UNO_TC_PROP_DATE_TIME).get<util::DateTime>(); + Date aDate(aDateTime.Day, aDateTime.Month, aDateTime.Year); + sal_Bool bIsFixed = false; + xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; + + SvxDateField* pData = new SvxDateField(aDate, bIsFixed ? SVXDATETYPE_FIX : SVXDATETYPE_VAR); + sal_Int32 nNumFmt = -1; + xPropSet->getPropertyValue(UNO_TC_PROP_NUMFORMAT) >>= nNumFmt; + if (nNumFmt >= SVXDATEFORMAT_APPDEFAULT && nNumFmt <= SVXDATEFORMAT_F) + pData->SetFormat(static_cast<SvxDateFormat>(nNumFmt)); + + return pData; + } + + if (nFieldType != text::textfield::Type::TIME && nFieldType != text::textfield::Type::DATE) + { + util::DateTime aDateTime = xPropSet->getPropertyValue(UNO_TC_PROP_DATE_TIME).get<util::DateTime>(); + Time aTime(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds); + + sal_Bool bIsFixed = false; + xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; + + SvxExtTimeField* pData = new SvxExtTimeField(aTime, bIsFixed ? SVXTIMETYPE_FIX : SVXTIMETYPE_VAR); + + sal_Int32 nNumFmt = -1; + xPropSet->getPropertyValue(UNO_TC_PROP_NUMFORMAT) >>= nNumFmt; + if (nNumFmt >= SVXTIMEFORMAT_APPDEFAULT && nNumFmt <= SVXTIMEFORMAT_AM_HMSH) + pData->SetFormat(static_cast<SvxTimeFormat>(nNumFmt)); + + return pData; + } + + return new SvxTimeField(); + } + case text::textfield::Type::URL: + { + rtl::OUString aRep, aTarget, aURL; + sal_Int16 nFmt = -1; + xPropSet->getPropertyValue(UNO_TC_PROP_URL_REPRESENTATION) >>= aRep; + xPropSet->getPropertyValue(UNO_TC_PROP_URL_TARGET) >>= aTarget; + xPropSet->getPropertyValue(UNO_TC_PROP_URL) >>= aURL; + xPropSet->getPropertyValue(UNO_TC_PROP_URL_FORMAT) >>= nFmt; + SvxURLField* pData = new SvxURLField(aURL, aRep, aRep.isEmpty() ? SVXURLFORMAT_URL : SVXURLFORMAT_REPR); + pData->SetTargetFrame(aTarget); + if (nFmt >= SVXURLFORMAT_APPDEFAULT && nFmt <= SVXURLFORMAT_REPR) + pData->SetFormat(static_cast<SvxURLFormat>(nFmt)); + + return pData; + } + case text::textfield::Type::PAGE: + return new SvxPageField(); + case text::textfield::Type::PAGES: + return new SvxPagesField(); + case text::textfield::Type::FILE: + return new SvxFileField(); + case text::textfield::Type::TABLE: + { + sal_Int32 nTab = 0; + xPropSet->getPropertyValue(UNO_TC_PROP_TABLE_POSITION) >>= nTab; + return new SvxTableField(nTab); + } + case text::textfield::Type::EXTENDED_FILE: + { + rtl::OUString aPresentation; + sal_Bool bIsFixed = false; + sal_Int16 nFmt = text::FilenameDisplayFormat::FULL; + xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; + xPropSet->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION) >>= aPresentation; + xPropSet->getPropertyValue(UNO_TC_PROP_FILE_FORMAT) >>= nFmt; + + SvxFileFormat eFmt = SVXFILEFORMAT_NAME_EXT; + switch (nFmt) + { + case text::FilenameDisplayFormat::FULL: eFmt = SVXFILEFORMAT_FULLPATH; break; + case text::FilenameDisplayFormat::PATH: eFmt = SVXFILEFORMAT_PATH; break; + case text::FilenameDisplayFormat::NAME: eFmt = SVXFILEFORMAT_NAME; break; + default:; + } + + // pass fixed attribute to constructor + return new SvxExtFileField( + aPresentation, bIsFixed ? SVXFILETYPE_FIX : SVXFILETYPE_VAR, eFmt); + } + case text::textfield::Type::AUTHOR: + { + sal_Bool bIsFixed = false; + sal_Bool bFullName = false; + sal_Int16 nFmt = -1; + rtl::OUString aPresentation, aContent, aFirstName, aLastName; + xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; + xPropSet->getPropertyValue(UNO_TC_PROP_AUTHOR_FULLNAME) >>= bFullName; + xPropSet->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION) >>= aPresentation; + xPropSet->getPropertyValue(UNO_TC_PROP_AUTHOR_CONTENT) >>= aContent; + xPropSet->getPropertyValue(UNO_TC_PROP_AUTHOR_FORMAT) >>= nFmt; + + // do we have CurrentPresentation given? Mimic behaviour of + // writer, which means: prefer CurrentPresentation over Content + // if both are given. + if (!aPresentation.isEmpty()) + aContent = aPresentation; + + sal_Int32 nPos = aContent.lastIndexOf(sal_Unicode(' '), 0); + if (nPos > 0) + { + aFirstName = aContent.copy(0, nPos); + aLastName = aContent.copy(nPos + 1); + } + else + { + aLastName = aContent; + } + + // #92009# pass fixed attribute to constructor + SvxAuthorField* pData = new SvxAuthorField( + aFirstName, aLastName, rtl::OUString(), bIsFixed ? SVXAUTHORTYPE_FIX : SVXAUTHORTYPE_VAR); + + if (!bFullName) + { + pData->SetFormat(SVXAUTHORFORMAT_SHORTNAME); + } + else if (nFmt >= SVXAUTHORFORMAT_FULLNAME || nFmt <= SVXAUTHORFORMAT_SHORTNAME) + { + pData->SetFormat(static_cast<SvxAuthorFormat>(nFmt)); + } + + return pData; + } + case text::textfield::Type::MEASURE: + { + SdrMeasureFieldKind eKind = SDRMEASUREFIELD_VALUE; + sal_Int16 nTmp = -1; + xPropSet->getPropertyValue(UNO_TC_PROP_MEASURE_KIND) >>= nTmp; + if (nTmp == static_cast<sal_Int16>(SDRMEASUREFIELD_UNIT) || + nTmp == static_cast<sal_Int16>(SDRMEASUREFIELD_ROTA90BLANCS)) + eKind = static_cast<SdrMeasureFieldKind>(nTmp); + + return new SdrMeasureField(eKind); + } + case text::textfield::Type::HEADER: + return new SvxHeaderField(); + case text::textfield::Type::FOOTER: + return new SvxFooterField(); + case text::textfield::Type::DATE_TIME: + return new SvxDateTimeField(); + default: + ; + }; + + return NULL; +} TYPEINIT1( SvxFieldItem, SfxPoolItem ); diff --git a/editeng/source/uno/unofield.cxx b/editeng/source/uno/unofield.cxx index 50c578f567ee..5333ac313596 100644 --- a/editeng/source/uno/unofield.cxx +++ b/editeng/source/uno/unofield.cxx @@ -90,7 +90,7 @@ const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId ) { MAP_CHAR_LEN("DateTime"), WID_DATE, &::getCppuType((const util::DateTime*)0), 0, 0 }, { MAP_CHAR_LEN("IsFixed"), WID_BOOL1, &::getBooleanCppuType(), 0, 0 }, { MAP_CHAR_LEN("IsDate"), WID_BOOL2, &::getBooleanCppuType(), 0, 0 }, - { MAP_CHAR_LEN("NumberFormat"), WID_INT32, &::getCppuType((const sal_Int16*)0), 0, 0 }, + { MAP_CHAR_LEN("NumberFormat"), WID_INT32, &::getCppuType((const sal_Int32*)0), 0, 0 }, {0,0,0,0,0,0} }; static SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl); @@ -849,6 +849,9 @@ uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyNam if (PropertyName == UNO_TC_PROP_ANCHOR) return uno::makeAny(mxAnchor); + if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE) + return uno::makeAny(mnServiceId); + uno::Any aValue; const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName ); diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index 52d31bb56aae..56a26357cbf7 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -1799,11 +1799,6 @@ void SAL_CALL SvxUnoTextBase::insertTextContent( const uno::Reference< text::XTe if (!pForwarder) return; - SvxUnoTextField* pField = SvxUnoTextField::getImplementation( xContent ); - - if (pField == NULL) - throw lang::IllegalArgumentException(); - uno::Reference<beans::XPropertySet> xPropSet(xRange, uno::UNO_QUERY); if (!xPropSet.is()) throw lang::IllegalArgumentException(); @@ -1813,8 +1808,8 @@ void SAL_CALL SvxUnoTextBase::insertTextContent( const uno::Reference< text::XTe if (!bAbsorb) aSel.Start = aSel.End; - SvxFieldData* pFieldData = pField->CreateFieldData(); - if( pFieldData == NULL ) + SvxFieldData* pFieldData = SvxFieldData::Create(xContent); + if (!pFieldData) throw lang::IllegalArgumentException(); SvxFieldItem aField( *pFieldData, EE_FEATURE_FIELD ); |