[Libreoffice-commits] core.git: 2 commits - sc/source

Eike Rathke erack at redhat.com
Tue Aug 19 12:55:09 PDT 2014


 sc/source/ui/view/viewfun6.cxx |   81 +++++++++++++++++++++++++++++++++++------
 1 file changed, 70 insertions(+), 11 deletions(-)

New commits:
commit 5a05115ee25683b5fc7c79ab418eaeed120bd3b0
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Aug 19 21:47:33 2014 +0200

    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

diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx
index 483156b8..ba9fbfb 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();
 }
 
commit 11f145d90f6a6781be5ec3787f41cb1b76eb8c8c
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Aug 19 19:05:40 2014 +0200

    a date is a date, without time
    
    And use DateTime instead of manually concatenating Date and Time.
    
    Change-Id: I6f9fb988beea2a9a17c976d3b98860c4f9ed063b

diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx
index f6addba..483156b8 100644
--- a/sc/source/ui/view/viewfun6.cxx
+++ b/sc/source/ui/view/viewfun6.cxx
@@ -244,15 +244,31 @@ void ScViewFunc::InsertCurrentTime(short nCellFmt, const OUString& rUndoStr)
     ScDocument& rDoc = pDocSh->GetDocument();
     ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
     SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
-    Date aActDate( Date::SYSTEM );
-    double fDate = aActDate - *pFormatter->GetNullDate();
-    Time aActTime( Time::SYSTEM );
-    double fTime = aActTime.GetHour()    / static_cast<double>(::Time::hourPerDay)   +
-                   aActTime.GetMin()     / static_cast<double>(::Time::minutePerDay) +
-                   aActTime.GetSec()     / static_cast<double>(::Time::secondPerDay) +
-                   aActTime.GetNanoSec() / static_cast<double>(::Time::nanoSecPerDay);
+    double fVal;
+    switch (nCellFmt)
+    {
+        case NUMBERFORMAT_DATE:
+            {
+                Date aActDate( Date::SYSTEM );
+                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());
+            }
+            break;
+    }
     pUndoMgr->EnterListAction(rUndoStr, rUndoStr);
-    pDocSh->GetDocFunc().SetValueCell(aCurPos, fDate+fTime, true);
+    pDocSh->GetDocFunc().SetValueCell(aCurPos, fVal, true);
 
     // Set the new cell format only when it differs from the current cell
     // format type.


More information about the Libreoffice-commits mailing list