diff options
author | Eike Rathke <erack@redhat.com> | 2014-08-19 21:47:33 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2014-08-19 21:54:46 +0200 |
commit | 5a05115ee25683b5fc7c79ab418eaeed120bd3b0 (patch) | |
tree | cf3d45b39d4b22205da494828efa8895c1baf410 /sc/source/ui/view/viewfun6.cxx | |
parent | 11f145d90f6a6781be5ec3787f41cb1b76eb8c8c (diff) |
more flexible handling of current date/time hotkeys
Let Ctrl+; current date and Shift+Ctrl+; (Ctrl+:) current time behave more
flexible, depending on the formatting (and as such the type) of the existing
cell content.
key date on time cell => current date + time of cell => date+time formatted cell
key date on other cell => current date => date formatted cell
key time on date cell => date of cell + current time => date+time formatted cell
key time on other cell => current time => time formatted cell
Change-Id: I2ccbfbab3c50c36a72c4db4696520e32f94caefa
Diffstat (limited to 'sc/source/ui/view/viewfun6.cxx')
-rw-r--r-- | sc/source/ui/view/viewfun6.cxx | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx index 483156b8d48f..ba9fbfbfcef6 100644 --- a/sc/source/ui/view/viewfun6.cxx +++ b/sc/source/ui/view/viewfun6.cxx @@ -244,6 +244,25 @@ void ScViewFunc::InsertCurrentTime(short nCellFmt, const OUString& rUndoStr) ScDocument& rDoc = pDocSh->GetDocument(); ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager(); SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); + const sal_uInt32 nCurNumFormat = rDoc.GetNumberFormat(aCurPos); + const SvNumberformat* pCurNumFormatEntry = pFormatter->GetEntry(nCurNumFormat); + const short nCurNumFormatType = (pCurNumFormatEntry ? + (pCurNumFormatEntry->GetType() & ~NUMBERFORMAT_DEFINED) : NUMBERFORMAT_UNDEFINED); + // Combine requested date/time stamp with existing cell time/date, if any. + switch (nCellFmt) + { + case NUMBERFORMAT_DATE: + if (nCurNumFormatType == NUMBERFORMAT_TIME) + nCellFmt = NUMBERFORMAT_DATETIME; + break; + case NUMBERFORMAT_TIME: + if (nCurNumFormatType == NUMBERFORMAT_DATE) + nCellFmt = NUMBERFORMAT_DATETIME; + break; + default: + assert(!"unhandled current date/time request"); + nCellFmt = NUMBERFORMAT_DATETIME; + } double fVal; switch (nCellFmt) { @@ -253,29 +272,53 @@ void ScViewFunc::InsertCurrentTime(short nCellFmt, const OUString& rUndoStr) fVal = aActDate - *pFormatter->GetNullDate(); } break; - default: - assert(!"unhandled current date/time"); - // fallthru case NUMBERFORMAT_TIME: - case NUMBERFORMAT_DATETIME: // for now treat datetime and time identically { - DateTime aActDateTime( DateTime::SYSTEM ); - // Converting the null date to DateTime forces the correct - // operator-() to be used, resulting in a fractional date&time - // instead of only date value. - fVal = aActDateTime - DateTime( *pFormatter->GetNullDate()); + Time aActTime( Time::SYSTEM ); + fVal = aActTime.GetTimeInDays(); + } + break; + case NUMBERFORMAT_DATETIME: + { + switch (nCurNumFormatType) + { + case NUMBERFORMAT_DATE: + { + double fDate = rtl::math::approxFloor( rDoc.GetValue( aCurPos)); + Time aActTime( Time::SYSTEM ); + fVal = fDate + aActTime.GetTimeInDays(); + } + break; + case NUMBERFORMAT_TIME: + { + double fCell = rDoc.GetValue( aCurPos); + double fTime = fCell - rtl::math::approxFloor( fCell); + Date aActDate( Date::SYSTEM ); + fVal = (aActDate - *pFormatter->GetNullDate()) + fTime; + } + break; + default: + { + DateTime aActDateTime( DateTime::SYSTEM ); + // Converting the null date to DateTime forces the + // correct operator-() to be used, resulting in a + // fractional date&time instead of only date value. + fVal = aActDateTime - DateTime( *pFormatter->GetNullDate()); + } + } } break; } + pUndoMgr->EnterListAction(rUndoStr, rUndoStr); + pDocSh->GetDocFunc().SetValueCell(aCurPos, fVal, true); // Set the new cell format only when it differs from the current cell // format type. - sal_uInt32 nCurNumFormat = rDoc.GetNumberFormat(aCurPos); - const SvNumberformat* pEntry = pFormatter->GetEntry(nCurNumFormat); - if (!pEntry || !(pEntry->GetType() & nCellFmt)) + if (nCellFmt != nCurNumFormatType) SetNumberFormat(nCellFmt); + pUndoMgr->LeaveListAction(); } |