[Libreoffice-commits] .: 3 commits - sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Wed May 9 13:28:27 PDT 2012
sc/source/ui/unoobj/fielduno.cxx | 275 ++++++++++++++++++++++++++++++++-------
1 file changed, 231 insertions(+), 44 deletions(-)
New commits:
commit 7c99fff933a112044589874d91e226df8e0332fd
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed May 9 15:24:16 2012 -0400
Access properties in the edit source when the field item is already inserted.
Change-Id: Idbc8b7fde425c1c14af27472a4850b290cf0a68c
diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx
index 0bd3bf4..7bc82b7 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<sal_Bool>();
- else if (rName == SC_UNONAME_ISFIXED)
- mbIsFixed = rVal.get<sal_Bool>();
- else if (rName == SC_UNONAME_DATETIME)
- maDateTime = rVal.get<util::DateTime>();
- else if (rName == SC_UNONAME_NUMFMT)
- mnNumFormat = rVal.get<sal_Int32>();
+ 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<SvxDateField*>(pField);
+ if (rName == SC_UNONAME_ISDATE)
+ {
+ // Do nothing for now.
+ }
+ else if (rName == SC_UNONAME_ISFIXED)
+ {
+ SvxDateType eType = rVal.get<sal_Bool>() ? SVXDATETYPE_FIX : SVXDATETYPE_VAR;
+ p->SetType(eType);
+ }
+ else if (rName == SC_UNONAME_DATETIME)
+ {
+ maDateTime = rVal.get<util::DateTime>();
+ Date aDate(maDateTime.Day, maDateTime.Month, maDateTime.Year);
+ p->SetFixDate(aDate);
+ }
+ else if (rName == SC_UNONAME_NUMFMT)
+ {
+ mnNumFormat = rVal.get<sal_Int32>();
+ p->SetFormat(static_cast<SvxDateFormat>(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<SvxExtTimeField*>(pField);
+ if (rName == SC_UNONAME_ISDATE)
+ {
+ // Do nothing for now.
+ }
+ else if (rName == SC_UNONAME_ISFIXED)
+ {
+ SvxTimeType eType = rVal.get<sal_Bool>() ? SVXTIMETYPE_FIX : SVXTIMETYPE_VAR;
+ p->SetType(eType);
+ }
+ else if (rName == SC_UNONAME_DATETIME)
+ {
+ maDateTime = rVal.get<util::DateTime>();
+ Time aTime(maDateTime.Hours, maDateTime.Minutes, maDateTime.Seconds, maDateTime.HundredthSeconds);
+ p->SetFixTime(aTime);
+ }
+ else if (rName == SC_UNONAME_NUMFMT)
+ {
+ mnNumFormat = rVal.get<sal_Int32>();
+ p->SetFormat(static_cast<SvxTimeFormat>(mnNumFormat));
+ }
+ else
+ throw beans::UnknownPropertyException();
+ }
+ break;
+ default:
+ throw beans::UnknownPropertyException();
+ }
+ }
else
- throw beans::UnknownPropertyException();
+ {
+ if (rName == SC_UNONAME_ISDATE)
+ mbIsDate = rVal.get<sal_Bool>();
+ else if (rName == SC_UNONAME_ISFIXED)
+ mbIsFixed = rVal.get<sal_Bool>();
+ else if (rName == SC_UNONAME_DATETIME)
+ maDateTime = rVal.get<util::DateTime>();
+ else if (rName == SC_UNONAME_NUMFMT)
+ mnNumFormat = rVal.get<sal_Int32>();
+ else
+ throw beans::UnknownPropertyException();
+ }
}
uno::Any ScEditFieldObj::getPropertyValueDateTime(const rtl::OUString& rName)
{
- if (rName == SC_UNONAME_ISDATE)
- return uno::makeAny<sal_Bool>(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<SvxDateField*>(pField);
+ if (rName == SC_UNONAME_ISDATE)
+ return uno::makeAny(sal_True);
- if (rName == SC_UNONAME_ISFIXED)
- return uno::makeAny<sal_Bool>(mbIsFixed);
+ if (rName == SC_UNONAME_ISFIXED)
+ return uno::makeAny<sal_Bool>(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<sal_Int32>(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<sal_Int32>(0);
+ }
+ break;
+ case text::textfield::Type::EXTENDED_TIME:
+ {
+ SvxExtTimeField* p = static_cast<SvxExtTimeField*>(pField);
+ if (rName == SC_UNONAME_ISDATE)
+ return uno::makeAny(sal_False);
+
+ if (rName == SC_UNONAME_ISFIXED)
+ return uno::makeAny<sal_Bool>(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<sal_Int32>(p->GetFormat());
+ }
+ break;
+ default:
+ ;
+ }
+ }
+ else
+ {
+ if (rName == SC_UNONAME_ISDATE)
+ return uno::makeAny<sal_Bool>(mbIsDate);
+
+ if (rName == SC_UNONAME_ISFIXED)
+ return uno::makeAny<sal_Bool>(mbIsFixed);
+
+ if (rName == SC_UNONAME_DATETIME)
+ return uno::makeAny(maDateTime);
+
+ if (rName == SC_UNONAME_NUMFMT)
+ return uno::makeAny(mnNumFormat);
+ }
throw beans::UnknownPropertyException();
}
commit 47910c495331a0173e304cac40e573c1195e77ee
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed May 9 11:36:08 2012 -0400
FILE (title) field doesn't have any properties.
Change-Id: I67c62e6be5afc65d74462a17b047946de88659a0
diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx
index f196978..0bd3bf4 100644
--- a/sc/source/ui/unoobj/fielduno.cxx
+++ b/sc/source/ui/unoobj/fielduno.cxx
@@ -74,6 +74,16 @@ const SfxItemPropertySet* getDateTimePropertySet()
return &aMap;
}
+const SfxItemPropertySet* getEmptyPropertySet()
+{
+ static SfxItemPropertyMapEntry aMapContent[] =
+ {
+ {0,0,0,0,0,0}
+ };
+ static SfxItemPropertySet aMap(aMapContent);
+ return &aMap;
+}
+
const SfxItemPropertySet* lcl_GetURLPropertySet()
{
static SfxItemPropertyMapEntry aURLPropertyMap_Impl[] =
@@ -979,6 +989,8 @@ ScEditFieldObj::ScEditFieldObj(
switch (meType)
{
case text::textfield::Type::FILE:
+ pPropSet = getEmptyPropertySet();
+ break;
case text::textfield::Type::EXTENDED_FILE:
pPropSet = lcl_GetFileFieldPropertySet();
break;
@@ -1159,7 +1171,6 @@ void SAL_CALL ScEditFieldObj::setPropertyValue(
case text::textfield::Type::URL:
setPropertyValueURL(aPropertyName, aValue);
break;
- case text::textfield::Type::FILE:
case text::textfield::Type::EXTENDED_FILE:
setPropertyValueFile(aPropertyName, aValue);
break;
@@ -1172,6 +1183,7 @@ void SAL_CALL ScEditFieldObj::setPropertyValue(
case text::textfield::Type::TABLE:
setPropertyValueSheet(aPropertyName, aValue);
break;
+ case text::textfield::Type::FILE:
default:
throw beans::UnknownPropertyException();
}
@@ -1213,7 +1225,6 @@ uno::Any SAL_CALL ScEditFieldObj::getPropertyValue( const rtl::OUString& aProper
{
case text::textfield::Type::URL:
return getPropertyValueURL(aPropertyName);
- case text::textfield::Type::FILE:
case text::textfield::Type::EXTENDED_FILE:
return getPropertyValueFile(aPropertyName);
case text::textfield::Type::DATE:
@@ -1221,6 +1232,7 @@ uno::Any SAL_CALL ScEditFieldObj::getPropertyValue( const rtl::OUString& aProper
case text::textfield::Type::EXTENDED_DATE:
case text::textfield::Type::EXTENDED_TIME:
return getPropertyValueDateTime(aPropertyName);
+ case text::textfield::Type::FILE:
default:
throw beans::UnknownPropertyException();
}
commit 151c2aeb1054679dde6f3b2b4e9480d564b5ca3f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed May 9 11:07:10 2012 -0400
Use UNO field type when searching for specific field items.
Change-Id: Ic79a545132aabaf93bd4ef465829b024c2e6a865
diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx
index 60c8e75..f196978 100644
--- a/sc/source/ui/unoobj/fielduno.cxx
+++ b/sc/source/ui/unoobj/fielduno.cxx
@@ -161,11 +161,16 @@ enum ScUnoCollectMode
SC_UNO_COLLECT_FINDPOS
};
+/**
+ * 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;
- TypeId aFieldType;
+ sal_Int32 mnFieldType;
SvxFieldData* pFound; // lokale Kopie
sal_uInt16 nFieldPar;
xub_StrLen nFieldPos;
@@ -179,9 +184,9 @@ public:
virtual String CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos,
Color*& rTxtColor, Color*& rFldColor );
- sal_uInt16 CountFields(TypeId aType);
- SvxFieldData* FindByIndex(sal_uInt16 nIndex, TypeId aType);
- SvxFieldData* FindByPos(sal_uInt16 nPar, xub_StrLen nPos, TypeId aType);
+ sal_uInt16 CountFields();
+ SvxFieldData* FindByIndex(sal_uInt16 nIndex);
+ SvxFieldData* FindByPos(sal_uInt16 nPar, xub_StrLen nPos, sal_Int32 nType);
sal_uInt16 GetFieldPar() const { return nFieldPar; }
xub_StrLen GetFieldPos() const { return nFieldPos; }
@@ -191,7 +196,7 @@ ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource) :
ScEditEngineDefaulter( *pSource ),
eMode( SC_UNO_COLLECT_NONE ),
nFieldCount( 0 ),
- aFieldType( NULL ),
+ mnFieldType(SvxFieldData::UNKNOWN_FIELD),
pFound( NULL )
{
if (pSource)
@@ -216,7 +221,7 @@ String ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField,
const SvxFieldData* pFieldData = rField.GetField();
if ( pFieldData )
{
- if ( !aFieldType || pFieldData->Type() == aFieldType )
+ if (mnFieldType == SvxFieldData::UNKNOWN_FIELD || pFieldData->GetClassId() == mnFieldType)
{
if ( eMode == SC_UNO_COLLECT_FINDINDEX && !pFound && nFieldCount == nFieldIndex )
{
@@ -237,40 +242,38 @@ String ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField,
return aRet;
}
-sal_uInt16 ScUnoEditEngine::CountFields(TypeId aType)
+sal_uInt16 ScUnoEditEngine::CountFields()
{
eMode = SC_UNO_COLLECT_COUNT;
- aFieldType = aType;
+ mnFieldType = SvxFieldData::UNKNOWN_FIELD;
nFieldCount = 0;
UpdateFields();
- aFieldType = NULL;
eMode = SC_UNO_COLLECT_NONE;
return nFieldCount;
}
-SvxFieldData* ScUnoEditEngine::FindByIndex(sal_uInt16 nIndex, TypeId aType)
+SvxFieldData* ScUnoEditEngine::FindByIndex(sal_uInt16 nIndex)
{
eMode = SC_UNO_COLLECT_FINDINDEX;
nFieldIndex = nIndex;
- aFieldType = aType;
+ mnFieldType = SvxFieldData::UNKNOWN_FIELD;
nFieldCount = 0;
UpdateFields();
- aFieldType = NULL;
eMode = SC_UNO_COLLECT_NONE;
return pFound;
}
-SvxFieldData* ScUnoEditEngine::FindByPos(sal_uInt16 nPar, xub_StrLen nPos, TypeId aType)
+SvxFieldData* ScUnoEditEngine::FindByPos(sal_uInt16 nPar, xub_StrLen nPos, sal_Int32 nType)
{
eMode = SC_UNO_COLLECT_FINDPOS;
nFieldPar = nPar;
nFieldPos = nPos;
- aFieldType = aType;
+ mnFieldType = nType;
nFieldCount = 0;
UpdateFields();
- aFieldType = NULL;
+ mnFieldType = SvxFieldData::UNKNOWN_FIELD;
eMode = SC_UNO_COLLECT_NONE;
return pFound;
@@ -335,7 +338,7 @@ uno::Reference<text::XTextField> ScCellFieldsObj::GetObjectByIndex_Impl(sal_Int3
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
- SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index), 0);
+ SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index));
if (!pData)
return uno::Reference<text::XTextField>();
@@ -357,7 +360,7 @@ sal_Int32 SAL_CALL ScCellFieldsObj::getCount() throw(uno::RuntimeException)
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
- return aTempEngine.CountFields(NULL); // Felder zaehlen, in Zelle ist der Typ egal
+ return aTempEngine.CountFields(); // Felder zaehlen, in Zelle ist der Typ egal
}
uno::Any SAL_CALL ScCellFieldsObj::getByIndex( sal_Int32 nIndex )
@@ -501,7 +504,7 @@ uno::Reference<text::XTextField> ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_In
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
- SvxFieldData* pData = aTempEngine.FindByIndex((sal_uInt16)Index, 0);
+ SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index));
if (!pData)
return NULL;
@@ -537,7 +540,7 @@ sal_Int32 SAL_CALL ScHeaderFieldsObj::getCount() throw(uno::RuntimeException)
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
- return aTempEngine.CountFields(0);
+ return aTempEngine.CountFields();
}
uno::Any SAL_CALL ScHeaderFieldsObj::getByIndex( sal_Int32 nIndex )
@@ -704,7 +707,8 @@ void ScEditFieldObj::setPropertyValueURL(const rtl::OUString& rName, const com::
ScUnoEditEngine aTempEngine(pEditEngine);
// Typ egal (in Zellen gibts nur URLs)
- SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
+ SvxFieldData* pField = aTempEngine.FindByPos(
+ aSelection.nStartPara, aSelection.nStartPos, SvxFieldData::UNKNOWN_FIELD);
OSL_ENSURE(pField,"setPropertyValue: Feld nicht gefunden");
if (!pField)
return;
@@ -776,7 +780,8 @@ uno::Any ScEditFieldObj::getPropertyValueURL(const rtl::OUString& rName)
ScUnoEditEngine aTempEngine(pEditEngine);
// Typ egal (in Zellen gibts nur URLs)
- const SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
+ const SvxFieldData* pField = aTempEngine.FindByPos(
+ aSelection.nStartPara, aSelection.nStartPos, SvxFieldData::UNKNOWN_FIELD);
OSL_ENSURE(pField,"getPropertyValue: Feld nicht gefunden");
if (!pField)
throw uno::RuntimeException();
@@ -827,7 +832,7 @@ void ScEditFieldObj::setPropertyValueFile(const rtl::OUString& rName, const uno:
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
SvxFieldData* pField = aTempEngine.FindByPos(
- aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField));
+ aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::EXTENDED_FILE);
OSL_ENSURE(pField, "setPropertyValueFile: Field not found");
if (pField)
{
@@ -861,7 +866,7 @@ uno::Any ScEditFieldObj::getPropertyValueFile(const rtl::OUString& rName)
ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
pField = aTempEngine.FindByPos(
- aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField));
+ aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::EXTENDED_FILE);
}
else
pField = getData();
@@ -921,7 +926,8 @@ void ScEditFieldObj::setPropertyValueSheet(const rtl::OUString& rName, const uno
ScUnoEditEngine aTempEngine(pEditEngine);
// Typ egal (in Zellen gibts nur URLs)
- SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
+ SvxFieldData* pField = aTempEngine.FindByPos(
+ aSelection.nStartPara, aSelection.nStartPos, SvxFieldData::UNKNOWN_FIELD);
OSL_ENSURE(pField,"setPropertyValue: Feld nicht gefunden");
if (!pField)
return;
@@ -1058,7 +1064,8 @@ rtl::OUString SAL_CALL ScEditFieldObj::getPresentation( sal_Bool bShowCommand )
ScUnoEditEngine aTempEngine(pEditEngine);
// Typ egal (in Zellen gibts nur URLs)
- const SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
+ const SvxFieldData* pField = aTempEngine.FindByPos(
+ aSelection.nStartPara, aSelection.nStartPos, SvxFieldData::UNKNOWN_FIELD);
OSL_ENSURE(pField,"getPresentation: Feld nicht gefunden");
if (!pField)
return rtl::OUString();
More information about the Libreoffice-commits
mailing list