summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2014-10-09 21:10:35 +0200
committerEike Rathke <erack@redhat.com>2014-10-09 21:15:40 +0200
commit980fd719648fb5b7cbe93ba23c1ee2f180ffcee8 (patch)
treeb46a62b5aae04ad386654c016f78329cdc579c2c
parentda4a5fa517a7379da84bf7d514eafe2c721246d3 (diff)
InsertCurrentTime: in input mode inherit matching format if set
In case a date or time cell format was set, inherit that format for Ctrl+; or Ctrl+: date/time insertion while editing the cell. Change-Id: If13e680fc74ab36611f8c11d992dba4b9c91ddb4
-rw-r--r--sc/source/ui/view/viewfun6.cxx24
1 files changed, 17 insertions, 7 deletions
diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx
index 228e1b45703d..d88650a594e5 100644
--- a/sc/source/ui/view/viewfun6.cxx
+++ b/sc/source/ui/view/viewfun6.cxx
@@ -267,22 +267,29 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
const sal_uInt32 nCurNumFormat = rDoc.GetNumberFormat(aCurPos);
SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
const SvNumberformat* pCurNumFormatEntry = pFormatter->GetEntry(nCurNumFormat);
+ const short nCurNumFormatType = (pCurNumFormatEntry ?
+ (pCurNumFormatEntry->GetType() & ~NUMBERFORMAT_DEFINED) : NUMBERFORMAT_UNDEFINED);
if (bInputMode)
{
double fVal = 0.0;
+ sal_uInt32 nFormat = 0;
switch (nReqFmt)
{
case NUMBERFORMAT_DATE:
{
Date aActDate( Date::SYSTEM );
fVal = aActDate - *pFormatter->GetNullDate();
+ if (nCurNumFormatType == NUMBERFORMAT_DATE)
+ nFormat = nCurNumFormat;
}
break;
case NUMBERFORMAT_TIME:
{
tools::Time aActTime( tools::Time::SYSTEM );
fVal = aActTime.GetTimeInDays();
+ if (nCurNumFormatType == NUMBERFORMAT_TIME)
+ nFormat = nCurNumFormat;
}
break;
default:
@@ -293,15 +300,20 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
{
DateTime aActDateTime( DateTime::SYSTEM );
fVal = aActDateTime - DateTime( *pFormatter->GetNullDate());
+ if (nCurNumFormatType == NUMBERFORMAT_DATETIME)
+ nFormat = nCurNumFormat;
}
break;
}
- LanguageType nLang = (pCurNumFormatEntry ? pCurNumFormatEntry->GetLanguage() : ScGlobal::eLnge);
- sal_uInt32 nFormat = pFormatter->GetStandardFormat( nReqFmt, nLang);
- // This would return a more precise format with seconds and 100th
- // seconds for a time request.
- //nFormat = pFormatter->GetStandardFormat( fVal, nFormat, nReqFmt, nLang);
+ if (!nFormat)
+ {
+ const LanguageType nLang = (pCurNumFormatEntry ? pCurNumFormatEntry->GetLanguage() : ScGlobal::eLnge);
+ nFormat = pFormatter->GetStandardFormat( nReqFmt, nLang);
+ // This would return a more precise format with seconds and 100th
+ // seconds for a time request.
+ //nFormat = pFormatter->GetStandardFormat( fVal, nFormat, nReqFmt, nLang);
+ }
OUString aString;
Color* pColor;
pFormatter->GetOutputString( fVal, nFormat, aString, &pColor);
@@ -317,8 +329,6 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
}
else
{
- const short nCurNumFormatType = (pCurNumFormatEntry ?
- (pCurNumFormatEntry->GetType() & ~NUMBERFORMAT_DEFINED) : NUMBERFORMAT_UNDEFINED);
bool bForceReqFmt = false;
const double fCell = rDoc.GetValue( aCurPos);
// Combine requested date/time stamp with existing cell time/date, if any.