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

Eike Rathke erack at redhat.com
Fri Aug 22 14:45:49 PDT 2014


 sc/source/ui/view/viewfun6.cxx |  279 +++++++++++++++++++++++++----------------
 1 file changed, 171 insertions(+), 108 deletions(-)

New commits:
commit d40700d58e3a418fa54d8f1e424a1bccbd2f188e
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Aug 22 23:40:58 2014 +0200

    treat datetime as handled
    
    Change-Id: Idc94174662eee5a75a6b467e47cbf9027e3ba224

diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx
index b6856d0..b2494c1 100644
--- a/sc/source/ui/view/viewfun6.cxx
+++ b/sc/source/ui/view/viewfun6.cxx
@@ -379,6 +379,9 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
             default:
                 assert(!"unhandled current date/time request");
                 nReqFmt = NUMBERFORMAT_DATETIME;
+                // fallthru
+            case NUMBERFORMAT_DATETIME:
+                break;
         }
         double fVal = 0.0;
         switch (nReqFmt)
commit 0f4a999e02aff56043506e38dfa53ea3b349ce25
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Aug 22 23:25:23 2014 +0200

    current date/time hotkey inserts also if cell is in input or edit mode
    
    Change-Id: Ib3caed607a5ca1b5ce82de0472223c7bdc8f7f54

diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx
index c688a54..b6856d0 100644
--- a/sc/source/ui/view/viewfun6.cxx
+++ b/sc/source/ui/view/viewfun6.cxx
@@ -24,6 +24,7 @@
 #include <vcl/msgbox.hxx>
 #include <svl/zforlist.hxx>
 #include <svl/zformat.hxx>
+#include <editeng/editview.hxx>
 
 #include "viewfunc.hxx"
 #include "detfunc.hxx"
@@ -239,6 +240,9 @@ void ScViewFunc::DetectiveMarkSucc()
 
 /** Insert date or time into current cell.
 
+    If cell is in input or edit mode, insert date/time at cursor position, else
+    create a date or time or date+time cell as follows:
+
     - key date on time cell  =>  current date + time of cell  =>  date+time formatted cell
       - unless time cell was empty or 00:00 time  =>  current date  =>  date formatted cell
     - key date on date+time cell  =>  current date + 00:00 time  =>  date+time formatted cell
@@ -255,138 +259,188 @@ void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
     ScViewData& rViewData = GetViewData();
 
     ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl( rViewData.GetViewShell());
-    if (pInputHdl && pInputHdl->IsInputMode())
-        return;     // don't fiddle with the cell while editing
+    bool bInputMode = (pInputHdl && pInputHdl->IsInputMode());
 
-    ScAddress aCurPos = rViewData.GetCurPos();
     ScDocShell* pDocSh = rViewData.GetDocShell();
     ScDocument& rDoc = pDocSh->GetDocument();
-    ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
-    SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+    ScAddress aCurPos = rViewData.GetCurPos();
     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);
-    bool bForceReqFmt = false;
-    const double fCell = rDoc.GetValue( aCurPos);
-    // Combine requested date/time stamp with existing cell time/date, if any.
-    switch (nReqFmt)
+
+    if (bInputMode)
     {
-        case NUMBERFORMAT_DATE:
-            switch (nCurNumFormatType)
-            {
-                case NUMBERFORMAT_TIME:
-                    // An empty cell formatted as time (or 00:00 time) shall
-                    // not result in the current date with 00:00 time, but only
-                    // in current date.
-                    if (fCell != 0.0)
-                        nReqFmt = NUMBERFORMAT_DATETIME;
-                    break;
-                case NUMBERFORMAT_DATETIME:
-                    {
-                        // Force to only date if the existing date+time is the
-                        // current date. This way inserting current date twice
-                        // on an existing date+time cell can be used to force
-                        // date, which otherwise would only be possible by
-                        // applying a date format.
-                        double fDate = rtl::math::approxFloor( fCell);
-                        if (fDate == (Date( Date::SYSTEM) - *pFormatter->GetNullDate()))
-                            bForceReqFmt = true;
-                    }
-                    break;
-            }
-            break;
-        case NUMBERFORMAT_TIME:
-            switch (nCurNumFormatType)
-            {
-                case NUMBERFORMAT_DATE:
-                    // An empty cell formatted as date shall not result in the
-                    // null date and current time, but only in current time.
-                    if (fCell != 0.0)
-                        nReqFmt = NUMBERFORMAT_DATETIME;
-                    break;
-                case NUMBERFORMAT_DATETIME:
-                    // Requesting current time on an empty date+time cell
-                    // inserts both current date+time.
-                    if (fCell == 0.0)
-                        nReqFmt = NUMBERFORMAT_DATETIME;
-                    else
-                    {
-                        // Add current time to an existing date+time where time is
-                        // zero and date is current date, else force time only.
-                        double fDate = rtl::math::approxFloor( fCell);
-                        double fTime = fCell - fDate;
-                        if (fTime == 0.0 && fDate == (Date( Date::SYSTEM) - *pFormatter->GetNullDate()))
-                            nReqFmt = NUMBERFORMAT_DATETIME;
-                        else
-                            bForceReqFmt = true;
-                    }
-                    break;
-            }
-            break;
-        default:
-            assert(!"unhandled current date/time request");
-            nReqFmt = NUMBERFORMAT_DATETIME;
+        double fVal = 0.0;
+        switch (nReqFmt)
+        {
+            case NUMBERFORMAT_DATE:
+                {
+                    Date aActDate( Date::SYSTEM );
+                    fVal = aActDate - *pFormatter->GetNullDate();
+                }
+                break;
+            case NUMBERFORMAT_TIME:
+                {
+                    Time aActTime( Time::SYSTEM );
+                    fVal = aActTime.GetTimeInDays();
+                }
+                break;
+            default:
+                assert(!"unhandled current date/time request");
+                nReqFmt = NUMBERFORMAT_DATETIME;
+                // fallthru
+            case NUMBERFORMAT_DATETIME:
+                {
+                    DateTime aActDateTime( DateTime::SYSTEM );
+                    fVal = aActDateTime - DateTime( *pFormatter->GetNullDate());
+                }
+                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);
+        OUString aString;
+        Color* pColor;
+        pFormatter->GetOutputString( fVal, nFormat, aString, &pColor);
+
+        pInputHdl->DataChanging();
+        EditView* pTopView = pInputHdl->GetTopView();
+        if (pTopView)
+            pTopView->InsertText( aString);
+        EditView* pTableView = pInputHdl->GetTableView();
+        if (pTableView)
+            pTableView->InsertText( aString);
+        pInputHdl->DataChanged( false, true);
     }
-    double fVal(0);
-    switch (nReqFmt)
+    else
     {
-        case NUMBERFORMAT_DATE:
-            {
-                Date aActDate( Date::SYSTEM );
-                fVal = aActDate - *pFormatter->GetNullDate();
-            }
-            break;
-        case NUMBERFORMAT_TIME:
-            {
-                Time aActTime( Time::SYSTEM );
-                fVal = aActTime.GetTimeInDays();
-            }
-            break;
-        case NUMBERFORMAT_DATETIME:
-            {
+        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.
+        switch (nReqFmt)
+        {
+            case NUMBERFORMAT_DATE:
                 switch (nCurNumFormatType)
                 {
-                    case NUMBERFORMAT_DATE:
+                    case NUMBERFORMAT_TIME:
+                        // An empty cell formatted as time (or 00:00 time) shall
+                        // not result in the current date with 00:00 time, but only
+                        // in current date.
+                        if (fCell != 0.0)
+                            nReqFmt = NUMBERFORMAT_DATETIME;
+                        break;
+                    case NUMBERFORMAT_DATETIME:
                         {
+                            // Force to only date if the existing date+time is the
+                            // current date. This way inserting current date twice
+                            // on an existing date+time cell can be used to force
+                            // date, which otherwise would only be possible by
+                            // applying a date format.
                             double fDate = rtl::math::approxFloor( fCell);
-                            Time aActTime( Time::SYSTEM );
-                            fVal = fDate + aActTime.GetTimeInDays();
+                            if (fDate == (Date( Date::SYSTEM) - *pFormatter->GetNullDate()))
+                                bForceReqFmt = true;
                         }
                         break;
-                    case NUMBERFORMAT_TIME:
-                        {
-                            double fTime = fCell - rtl::math::approxFloor( fCell);
-                            Date aActDate( Date::SYSTEM );
-                            fVal = (aActDate - *pFormatter->GetNullDate()) + fTime;
-                        }
+                }
+                break;
+            case NUMBERFORMAT_TIME:
+                switch (nCurNumFormatType)
+                {
+                    case NUMBERFORMAT_DATE:
+                        // An empty cell formatted as date shall not result in the
+                        // null date and current time, but only in current time.
+                        if (fCell != 0.0)
+                            nReqFmt = NUMBERFORMAT_DATETIME;
                         break;
-                    default:
+                    case NUMBERFORMAT_DATETIME:
+                        // Requesting current time on an empty date+time cell
+                        // inserts both current date+time.
+                        if (fCell == 0.0)
+                            nReqFmt = NUMBERFORMAT_DATETIME;
+                        else
                         {
-                            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());
+                            // Add current time to an existing date+time where time is
+                            // zero and date is current date, else force time only.
+                            double fDate = rtl::math::approxFloor( fCell);
+                            double fTime = fCell - fDate;
+                            if (fTime == 0.0 && fDate == (Date( Date::SYSTEM) - *pFormatter->GetNullDate()))
+                                nReqFmt = NUMBERFORMAT_DATETIME;
+                            else
+                                bForceReqFmt = true;
                         }
+                        break;
                 }
-            }
-            break;
-    }
+                break;
+            default:
+                assert(!"unhandled current date/time request");
+                nReqFmt = NUMBERFORMAT_DATETIME;
+        }
+        double fVal = 0.0;
+        switch (nReqFmt)
+        {
+            case NUMBERFORMAT_DATE:
+                {
+                    Date aActDate( Date::SYSTEM );
+                    fVal = aActDate - *pFormatter->GetNullDate();
+                }
+                break;
+            case NUMBERFORMAT_TIME:
+                {
+                    Time aActTime( Time::SYSTEM );
+                    fVal = aActTime.GetTimeInDays();
+                }
+                break;
+            case NUMBERFORMAT_DATETIME:
+                {
+                    switch (nCurNumFormatType)
+                    {
+                        case NUMBERFORMAT_DATE:
+                            {
+                                double fDate = rtl::math::approxFloor( fCell);
+                                Time aActTime( Time::SYSTEM );
+                                fVal = fDate + aActTime.GetTimeInDays();
+                            }
+                            break;
+                        case NUMBERFORMAT_TIME:
+                            {
+                                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);
+        ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
+        pUndoMgr->EnterListAction(rUndoStr, rUndoStr);
 
-    pDocSh->GetDocFunc().SetValueCell(aCurPos, fVal, true);
+        pDocSh->GetDocFunc().SetValueCell(aCurPos, fVal, true);
 
-    // Set the new cell format only when it differs from the current cell
-    // format type. Preserve a date+time format unless we force a format
-    // through.
-    if (bForceReqFmt || (nReqFmt != nCurNumFormatType && nCurNumFormatType != NUMBERFORMAT_DATETIME))
-        SetNumberFormat(nReqFmt);
-    else
-        rViewData.UpdateInputHandler();     // update input bar with new value
+        // Set the new cell format only when it differs from the current cell
+        // format type. Preserve a date+time format unless we force a format
+        // through.
+        if (bForceReqFmt || (nReqFmt != nCurNumFormatType && nCurNumFormatType != NUMBERFORMAT_DATETIME))
+            SetNumberFormat(nReqFmt);
+        else
+            rViewData.UpdateInputHandler();     // update input bar with new value
 
-    pUndoMgr->LeaveListAction();
+        pUndoMgr->LeaveListAction();
+    }
 }
 
 void ScViewFunc::ShowNote( bool bShow )
commit e45001fad0f07c547a80bbe117d3523df4d67b63
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Aug 22 22:10:45 2014 +0200

    InsertCurrentTime: don't fiddle with the cell while editing
    
    Change-Id: Ia12b10a44b7d90344a009753ddae801b7d58dddf

diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx
index 3874548..c688a54 100644
--- a/sc/source/ui/view/viewfun6.cxx
+++ b/sc/source/ui/view/viewfun6.cxx
@@ -43,6 +43,7 @@
 #include "markdata.hxx"
 #include "drawview.hxx"
 #include "globalnames.hxx"
+#include "inputhdl.hxx"
 
 #include <vector>
 
@@ -252,6 +253,11 @@ void ScViewFunc::DetectiveMarkSucc()
 void ScViewFunc::InsertCurrentTime(short nReqFmt, const OUString& rUndoStr)
 {
     ScViewData& rViewData = GetViewData();
+
+    ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl( rViewData.GetViewShell());
+    if (pInputHdl && pInputHdl->IsInputMode())
+        return;     // don't fiddle with the cell while editing
+
     ScAddress aCurPos = rViewData.GetCurPos();
     ScDocShell* pDocSh = rViewData.GetDocShell();
     ScDocument& rDoc = pDocSh->GetDocument();


More information about the Libreoffice-commits mailing list