Kaydet (Commit) 980fd719 authored tarafından Eike Rathke's avatar Eike Rathke

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
üst da4a5fa5
...@@ -267,22 +267,29 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr) ...@@ -267,22 +267,29 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
const sal_uInt32 nCurNumFormat = rDoc.GetNumberFormat(aCurPos); const sal_uInt32 nCurNumFormat = rDoc.GetNumberFormat(aCurPos);
SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
const SvNumberformat* pCurNumFormatEntry = pFormatter->GetEntry(nCurNumFormat); const SvNumberformat* pCurNumFormatEntry = pFormatter->GetEntry(nCurNumFormat);
const short nCurNumFormatType = (pCurNumFormatEntry ?
(pCurNumFormatEntry->GetType() & ~NUMBERFORMAT_DEFINED) : NUMBERFORMAT_UNDEFINED);
if (bInputMode) if (bInputMode)
{ {
double fVal = 0.0; double fVal = 0.0;
sal_uInt32 nFormat = 0;
switch (nReqFmt) switch (nReqFmt)
{ {
case NUMBERFORMAT_DATE: case NUMBERFORMAT_DATE:
{ {
Date aActDate( Date::SYSTEM ); Date aActDate( Date::SYSTEM );
fVal = aActDate - *pFormatter->GetNullDate(); fVal = aActDate - *pFormatter->GetNullDate();
if (nCurNumFormatType == NUMBERFORMAT_DATE)
nFormat = nCurNumFormat;
} }
break; break;
case NUMBERFORMAT_TIME: case NUMBERFORMAT_TIME:
{ {
tools::Time aActTime( tools::Time::SYSTEM ); tools::Time aActTime( tools::Time::SYSTEM );
fVal = aActTime.GetTimeInDays(); fVal = aActTime.GetTimeInDays();
if (nCurNumFormatType == NUMBERFORMAT_TIME)
nFormat = nCurNumFormat;
} }
break; break;
default: default:
...@@ -293,15 +300,20 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr) ...@@ -293,15 +300,20 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
{ {
DateTime aActDateTime( DateTime::SYSTEM ); DateTime aActDateTime( DateTime::SYSTEM );
fVal = aActDateTime - DateTime( *pFormatter->GetNullDate()); fVal = aActDateTime - DateTime( *pFormatter->GetNullDate());
if (nCurNumFormatType == NUMBERFORMAT_DATETIME)
nFormat = nCurNumFormat;
} }
break; break;
} }
LanguageType nLang = (pCurNumFormatEntry ? pCurNumFormatEntry->GetLanguage() : ScGlobal::eLnge); if (!nFormat)
sal_uInt32 nFormat = pFormatter->GetStandardFormat( nReqFmt, nLang); {
// This would return a more precise format with seconds and 100th const LanguageType nLang = (pCurNumFormatEntry ? pCurNumFormatEntry->GetLanguage() : ScGlobal::eLnge);
// seconds for a time request. nFormat = pFormatter->GetStandardFormat( nReqFmt, nLang);
//nFormat = pFormatter->GetStandardFormat( fVal, nFormat, 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; OUString aString;
Color* pColor; Color* pColor;
pFormatter->GetOutputString( fVal, nFormat, aString, &pColor); pFormatter->GetOutputString( fVal, nFormat, aString, &pColor);
...@@ -317,8 +329,6 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr) ...@@ -317,8 +329,6 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
} }
else else
{ {
const short nCurNumFormatType = (pCurNumFormatEntry ?
(pCurNumFormatEntry->GetType() & ~NUMBERFORMAT_DEFINED) : NUMBERFORMAT_UNDEFINED);
bool bForceReqFmt = false; bool bForceReqFmt = false;
const double fCell = rDoc.GetValue( aCurPos); const double fCell = rDoc.GetValue( aCurPos);
// Combine requested date/time stamp with existing cell time/date, if any. // Combine requested date/time stamp with existing cell time/date, if any.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment