From 7c99fff933a112044589874d91e226df8e0332fd Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Wed, 9 May 2012 15:24:16 -0400 Subject: Access properties in the edit source when the field item is already inserted. Change-Id: Idbc8b7fde425c1c14af27472a4850b290cf0a68c --- sc/source/ui/unoobj/fielduno.cxx | 202 +++++++++++++++++++++++++++++++++++---- 1 file changed, 185 insertions(+), 17 deletions(-) (limited to 'sc/source/ui/unoobj') diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index 0bd3bf40c480..7bc82b770f8f 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -898,31 +898,199 @@ uno::Any ScEditFieldObj::getPropertyValueFile(const rtl::OUString& rName) void ScEditFieldObj::setPropertyValueDateTime(const rtl::OUString& rName, const uno::Any& rVal) { - if (rName == SC_UNONAME_ISDATE) - mbIsDate = rVal.get(); - else if (rName == SC_UNONAME_ISFIXED) - mbIsFixed = rVal.get(); - else if (rName == SC_UNONAME_DATETIME) - maDateTime = rVal.get(); - else if (rName == SC_UNONAME_NUMFMT) - mnNumFormat = rVal.get(); + if (mpEditSource) + { + // Field already inserted. + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + SvxFieldData* pField = aTempEngine.FindByPos(aSelection.nStartPara, aSelection.nStartPos, meType); + if (!pField) + return; + + switch (meType) + { + case text::textfield::Type::DATE: + { + SvxDateField* p = static_cast(pField); + if (rName == SC_UNONAME_ISDATE) + { + // Do nothing for now. + } + else if (rName == SC_UNONAME_ISFIXED) + { + SvxDateType eType = rVal.get() ? SVXDATETYPE_FIX : SVXDATETYPE_VAR; + p->SetType(eType); + } + else if (rName == SC_UNONAME_DATETIME) + { + maDateTime = rVal.get(); + Date aDate(maDateTime.Day, maDateTime.Month, maDateTime.Year); + p->SetFixDate(aDate); + } + else if (rName == SC_UNONAME_NUMFMT) + { + mnNumFormat = rVal.get(); + p->SetFormat(static_cast(mnNumFormat)); + } + else + throw beans::UnknownPropertyException(); + } + break; + case text::textfield::Type::TIME: + { + // SvxTimeField doesn't have any attributes. + if (rName != SC_UNONAME_ISDATE && rName != SC_UNONAME_ISFIXED && + rName != SC_UNONAME_DATETIME && rName != SC_UNONAME_NUMFMT) + throw beans::UnknownPropertyException(); + } + break; + case text::textfield::Type::EXTENDED_TIME: + { + SvxExtTimeField* p = static_cast(pField); + if (rName == SC_UNONAME_ISDATE) + { + // Do nothing for now. + } + else if (rName == SC_UNONAME_ISFIXED) + { + SvxTimeType eType = rVal.get() ? SVXTIMETYPE_FIX : SVXTIMETYPE_VAR; + p->SetType(eType); + } + else if (rName == SC_UNONAME_DATETIME) + { + maDateTime = rVal.get(); + Time aTime(maDateTime.Hours, maDateTime.Minutes, maDateTime.Seconds, maDateTime.HundredthSeconds); + p->SetFixTime(aTime); + } + else if (rName == SC_UNONAME_NUMFMT) + { + mnNumFormat = rVal.get(); + p->SetFormat(static_cast(mnNumFormat)); + } + else + throw beans::UnknownPropertyException(); + } + break; + default: + throw beans::UnknownPropertyException(); + } + } else - throw beans::UnknownPropertyException(); + { + if (rName == SC_UNONAME_ISDATE) + mbIsDate = rVal.get(); + else if (rName == SC_UNONAME_ISFIXED) + mbIsFixed = rVal.get(); + else if (rName == SC_UNONAME_DATETIME) + maDateTime = rVal.get(); + else if (rName == SC_UNONAME_NUMFMT) + mnNumFormat = rVal.get(); + else + throw beans::UnknownPropertyException(); + } } uno::Any ScEditFieldObj::getPropertyValueDateTime(const rtl::OUString& rName) { - if (rName == SC_UNONAME_ISDATE) - return uno::makeAny(mbIsDate); + if (mpEditSource) + { + // Field already inserted. + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + SvxFieldData* pField = aTempEngine.FindByPos(aSelection.nStartPara, aSelection.nStartPos, meType); + if (!pField) + throw uno::RuntimeException(); + + switch (meType) + { + case text::textfield::Type::DATE: + { + SvxDateField* p = static_cast(pField); + if (rName == SC_UNONAME_ISDATE) + return uno::makeAny(sal_True); - if (rName == SC_UNONAME_ISFIXED) - return uno::makeAny(mbIsFixed); + if (rName == SC_UNONAME_ISFIXED) + return uno::makeAny(p->GetType() == SVXDATETYPE_FIX); + + if (rName == SC_UNONAME_DATETIME) + { + Date aD(p->GetFixDate()); + maDateTime.Year = aD.GetYear(); + maDateTime.Month = aD.GetMonth(); + maDateTime.Day = aD.GetDay(); + maDateTime.Hours = 0; + maDateTime.Minutes = 0; + maDateTime.Seconds = 0; + maDateTime.HundredthSeconds = 0; + return uno::makeAny(maDateTime); + } + + if (rName == SC_UNONAME_NUMFMT) + return uno::makeAny(p->GetFormat()); + } + break; + case text::textfield::Type::TIME: + { + // SvxTimeField doesn't have any attributes. + if (rName == SC_UNONAME_ISDATE) + return uno::makeAny(sal_False); - if (rName == SC_UNONAME_DATETIME) - return uno::makeAny(maDateTime); + if (rName == SC_UNONAME_ISFIXED) + return uno::makeAny(sal_False); - if (rName == SC_UNONAME_NUMFMT) - return uno::makeAny(mnNumFormat); + if (rName == SC_UNONAME_DATETIME) + // This is the best we can do. + return uno::makeAny(maDateTime); + + if (rName == SC_UNONAME_NUMFMT) + // Same as above. + return uno::makeAny(0); + } + break; + case text::textfield::Type::EXTENDED_TIME: + { + SvxExtTimeField* p = static_cast(pField); + if (rName == SC_UNONAME_ISDATE) + return uno::makeAny(sal_False); + + if (rName == SC_UNONAME_ISFIXED) + return uno::makeAny(p->GetType() == SVXTIMETYPE_FIX); + + if (rName == SC_UNONAME_DATETIME) + { + Time aT(p->GetFixTime()); + maDateTime.Year = 0; + maDateTime.Month = 0; + maDateTime.Day = 0; + maDateTime.Hours = aT.GetHour(); + maDateTime.Minutes = aT.GetMin(); + maDateTime.Seconds = aT.GetSec(); + maDateTime.HundredthSeconds = aT.Get100Sec(); + return uno::makeAny(maDateTime); + } + + if (rName == SC_UNONAME_NUMFMT) + return uno::makeAny(p->GetFormat()); + } + break; + default: + ; + } + } + else + { + if (rName == SC_UNONAME_ISDATE) + return uno::makeAny(mbIsDate); + + if (rName == SC_UNONAME_ISFIXED) + return uno::makeAny(mbIsFixed); + + if (rName == SC_UNONAME_DATETIME) + return uno::makeAny(maDateTime); + + if (rName == SC_UNONAME_NUMFMT) + return uno::makeAny(mnNumFormat); + } throw beans::UnknownPropertyException(); } -- cgit