[Libreoffice-commits] core.git: 3 commits - android/experimental sc/source sw/source vcl/inc vcl/source

Tor Lillqvist tml at iki.fi
Sun Mar 3 12:31:44 PST 2013


 android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java |   52 +++++++---
 sc/source/ui/view/tabview.cxx                                                      |   18 ++-
 sw/source/ui/uiview/viewport.cxx                                                   |    6 +
 vcl/inc/vcl/cmdevt.hxx                                                             |    1 
 vcl/source/window/winproc.cxx                                                      |   26 +----
 5 files changed, 63 insertions(+), 40 deletions(-)

New commits:
commit 6339bf132518130d4093869f9913df5b103bf5d3
Author: Tor Lillqvist <tml at iki.fi>
Date:   Sun Mar 3 22:23:54 2013 +0200

    Android "desktop" app: More hacking on scaling
    
    Added a new "mode" for the CommandWheelData, COMMAND_WHEEL_ZOOM_SCALE, where
    the "delta" is the scale percentage to multiply the curent zoom factor
    with. Implement in Writer and Calc.
    
    But actually, I am more and more startng to think that live scaling of the
    document view during the pinch/spread gesture will never perform fast
    enough. Need to go back to the (simple) trick to just scale the BitmapView,
    and do the actual LO re-zoom only when the gesture finishes. But in order for
    that to look nicer, need to get rid of the LO UI element clutter around the
    document, scrollbars, buttons etc. Plus of course need to make sure the LO
    zooming happens around the gesture center position.
    
    Change-Id: I20dfcb4c2a97aacbf7e5b6ea5c24816b237fe687

diff --git a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
index d01c323..baa36dc 100644
--- a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
+++ b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
@@ -166,7 +166,7 @@ public class Desktop
         boolean scalingInProgress;
         GestureDetector gestureDetector;
         ScaleGestureDetector scaleDetector;
-        float scale = 1;
+        long lastGestureEventTime;
 
         public BitmapView()
         {
@@ -201,27 +201,31 @@ public class Desktop
                                          new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                                              @Override public boolean onScaleBegin(ScaleGestureDetector detector)
                                              {
-                                                 Log.i(TAG, "onScaleBegin: pivot=(" + detector.getFocusX() + ", " + detector.getFocusY() + ")");
                                                  scalingInProgress = true;
+                                                 lastGestureEventTime = System.currentTimeMillis();
                                                  return true;
                                              }
 
                                              @Override public boolean onScale(ScaleGestureDetector detector)
                                              {
-                                                 float s = detector.getScaleFactor();
-                                                 if (s > 0.95 && s < 1.05)
+                                                 long now = System.currentTimeMillis();
+                                                 if (now - lastGestureEventTime < 100)
                                                      return false;
-                                                 scale *= s;
-                                                 Log.i(TAG, "onScale: " + s + " => " + scale);
+                                                 float scale = detector.getScaleFactor();
+                                                 if (scale > 0.95 && scale < 1.05)
+                                                     return false;
+                                                 Log.i(TAG, "onScale: " + scale);
+                                                 lastGestureEventTime = now;
                                                  Desktop.zoom(scale, (int) detector.getFocusX(), (int) detector.getFocusY());
                                                  return true;
                                              }
 
                                              @Override public void onScaleEnd(ScaleGestureDetector detector)
                                              {
+                                                 float scale = detector.getScaleFactor();
                                                  Log.i(TAG, "onScaleEnd: " + scale);
-                                                 Desktop.zoom(scale, (int) detector.getFocusX(), (int) detector.getFocusY());
-                                                 scale = 1;
+                                                 if (!(scale > 0.95 && scale < 1.05))
+                                                     Desktop.zoom(scale, (int) detector.getFocusX(), (int) detector.getFocusY());
                                                  scalingInProgress = false;
                                              }
                                          });
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 0d3c92c..52ef47b 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -965,7 +965,8 @@ bool ScTabView::ScrollCommand( const CommandEvent& rCEvt, ScSplitPos ePos )
 
     bool bDone = false;
     const CommandWheelData* pData = rCEvt.GetWheelData();
-    if ( pData && pData->GetMode() == COMMAND_WHEEL_ZOOM )
+    if ( pData && (pData->GetMode() == COMMAND_WHEEL_ZOOM ||
+                   pData->GetMode() == COMMAND_WHEEL_ZOOM_SCALE ) )
     {
         if ( !aViewData.GetViewShell()->GetViewFrame()->GetFrame().IsInPlace() )
         {
@@ -975,11 +976,16 @@ bool ScTabView::ScrollCommand( const CommandEvent& rCEvt, ScSplitPos ePos )
             const Fraction& rOldY = aViewData.GetZoomY();
             long nOld = (long)(( rOldY.GetNumerator() * 100 ) / rOldY.GetDenominator());
             long nNew = nOld;
-            if ( pData->GetDelta() < 0 )
-                nNew = Max( (long) MINZOOM, basegfx::zoomtools::zoomOut( nOld ));
-            else
-                nNew = Min( (long) MAXZOOM, basegfx::zoomtools::zoomIn( nOld ));
-
+            if ( pData->GetMode() == COMMAND_WHEEL_ZOOM_SCALE )
+            {
+                nNew = 100 * (long) ((nOld / 100.0) * (pData->GetDelta() / 100.0));
+            } else
+            {
+                if ( pData->GetDelta() < 0 )
+                    nNew = Max( (long) MINZOOM, basegfx::zoomtools::zoomOut( nOld ));
+                else
+                    nNew = Min( (long) MAXZOOM, basegfx::zoomtools::zoomIn( nOld ));
+            }
             if ( nNew != nOld )
             {
                 // scroll wheel doesn't set the AppOptions default
diff --git a/sw/source/ui/uiview/viewport.cxx b/sw/source/ui/uiview/viewport.cxx
index 6d44292..905f450 100644
--- a/sw/source/ui/uiview/viewport.cxx
+++ b/sw/source/ui/uiview/viewport.cxx
@@ -1267,6 +1267,12 @@ sal_Bool SwView::HandleWheelCommands( const CommandEvent& rCEvt )
         SetZoom( SVX_ZOOM_PERCENT, nFact );
         bOk = sal_True;
     }
+    else if( pWData && COMMAND_WHEEL_ZOOM_SCALE == pWData->GetMode() )
+    {
+        long newZoom = 100 * (long) ((pWrtShell->GetViewOptions()->GetZoom() / 100.0) * (pWData->GetDelta() / 100.0));
+        SetZoom( SVX_ZOOM_PERCENT, Max( 20L, Min( 600L, newZoom ) ) );
+        bOk = sal_True;
+    }
     else
     {
         if(pWData->GetMode()==COMMAND_WHEEL_SCROLL)
diff --git a/vcl/inc/vcl/cmdevt.hxx b/vcl/inc/vcl/cmdevt.hxx
index a437a5b..03876e5 100644
--- a/vcl/inc/vcl/cmdevt.hxx
+++ b/vcl/inc/vcl/cmdevt.hxx
@@ -116,6 +116,7 @@ inline CommandInputContextData::CommandInputContextData( LanguageType eLang )
 
 #define COMMAND_WHEEL_SCROLL            ((sal_uInt16)0x0001)
 #define COMMAND_WHEEL_ZOOM              ((sal_uInt16)0x0002)
+#define COMMAND_WHEEL_ZOOM_SCALE        ((sal_uInt16)0x0003)
 #define COMMAND_WHEEL_DATAZOOM          ((sal_uInt16)0x0004)
 
 #define COMMAND_WHEEL_PAGESCROLL        ((sal_uLong)0xFFFFFFFF)
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index d86342d..1ecbbb1 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -1438,7 +1438,7 @@ static sal_Bool ImplCallWheelCommand( Window* pWindow, const Point& rPos,
 
 // -----------------------------------------------------------------------
 
-static long ImplHandleWheelEvent( Window* pWindow, const SalWheelMouseEvent& rEvt )
+static long ImplHandleWheelEvent( Window* pWindow, const SalWheelMouseEvent& rEvt, bool scaleDirectly = false )
 {
     ImplDelData aDogTag( pWindow );
 
@@ -1454,7 +1454,9 @@ static long ImplHandleWheelEvent( Window* pWindow, const SalWheelMouseEvent& rEv
     sal_uInt16 nCode = rEvt.mnCode;
     bool bHorz = rEvt.mbHorz;
     bool bPixel = rEvt.mbDeltaIsPixel;
-    if ( nCode & KEY_MOD1 )
+    if ( scaleDirectly )
+        nMode = COMMAND_WHEEL_ZOOM_SCALE;
+    else if ( nCode & KEY_MOD1 )
         nMode = COMMAND_WHEEL_ZOOM;
     else if ( nCode & KEY_MOD2 )
         nMode = COMMAND_WHEEL_DATAZOOM;
@@ -2594,14 +2596,6 @@ long ImplWindowFrameProc( Window* pWindow, SalFrame* /*pFrame*/,
             break;
         case SALEVENT_EXTERNALZOOM:
             {
-            // At least in Writer (see SwView::HandleWheelCommands()
-            // in sw/source/ui/uiview/viewport.cxx) the delta value in the event is cheerfully
-            // ignored and only its sign matters, zooming always is one "step" per event.
-            // Thus this factor has no meaning. Will have to fix this probably by adding a new
-            // CommandWheelData mode to actually multiply the current zoom level with a value
-            // specified.
-            const int ZOOM_FACTOR = 100;
-
             ZoomEvent* pZoomEvent = (ZoomEvent*) pEvent;
             SalWheelMouseEvent aSalWheelMouseEvent;
 
@@ -2609,19 +2603,10 @@ long ImplWindowFrameProc( Window* pWindow, SalFrame* /*pFrame*/,
             aSalWheelMouseEvent.mnX = pZoomEvent->GetCenter().getX();
             aSalWheelMouseEvent.mnY = pZoomEvent->GetCenter().getY();
 
-            if ( pZoomEvent->GetScale() < 1 ) {
-                aSalWheelMouseEvent.mnDelta = - (long) ((1 - pZoomEvent->GetScale()) * ZOOM_FACTOR);
-                aSalWheelMouseEvent.mnNotchDelta = -1;
-            } else {
-                aSalWheelMouseEvent.mnDelta = (long) ((pZoomEvent->GetScale() - 1) * ZOOM_FACTOR);
-                aSalWheelMouseEvent.mnNotchDelta = 1;
-            }
-
-            aSalWheelMouseEvent.mnScrollLines = 1; // ???
-            aSalWheelMouseEvent.mnCode = KEY_MOD1;
-            aSalWheelMouseEvent.mbDeltaIsPixel = 0; // ???
+            // Pass on the scale as a percentage of current zoom factor
+            aSalWheelMouseEvent.mnDelta = (long) (pZoomEvent->GetScale() * 100);
 
-            nRet = ImplHandleWheelEvent( pWindow, aSalWheelMouseEvent );
+            nRet = ImplHandleWheelEvent( pWindow, aSalWheelMouseEvent, true );
             }
             break;
         case SALEVENT_EXTERNALSCROLL:
commit 5facce3c212387054d2da05672445556f5bca14d
Author: Tor Lillqvist <tml at iki.fi>
Date:   Sun Mar 3 12:51:38 2013 +0200

    Add scroll and fling gesture recognition
    
    Not yet passed on down.
    
    Also fix a misleading comment.
    
    Change-Id: I1e6f79c84b1e13f48e4b2620e44b326fb6fc4ee9

diff --git a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
index 6e5627b..d01c323 100644
--- a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
+++ b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
@@ -22,6 +22,7 @@ import android.graphics.Rect;
 import android.os.Bundle;
 import android.text.InputType;
 import android.util.Log;
+import android.view.GestureDetector;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.ScaleGestureDetector;
@@ -163,7 +164,8 @@ public class Desktop
         Bitmap mBitmap;
         boolean renderedOnce;
         boolean scalingInProgress;
-        ScaleGestureDetector gestureDetector;
+        GestureDetector gestureDetector;
+        ScaleGestureDetector scaleDetector;
         float scale = 1;
 
         public BitmapView()
@@ -171,6 +173,22 @@ public class Desktop
             super(Desktop.this);
             setFocusableInTouchMode(true);
 
+            gestureDetector =
+                new GestureDetector(Desktop.this,
+                                    new GestureDetector.SimpleOnGestureListener() {
+                                        @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
+                                        {
+                                            Log.i(TAG, "onFling: events:" + e1 + ", " + e2 + ", velocity: (" + velocityX + ", " + velocityY + ")");
+                                            return false;
+                                        }
+
+                                        @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
+                                        {
+                                            Log.i(TAG, "onScroll: events:" + e1 + ", " + e2 + ", velocity: (" + velocityX + ", " + velocityY + ")");
+                                            return false;
+                                        }
+                                    });
+
             // Is this sane? It is rather slow to ask LO to zoom
             // continuously while the scaling gesture is in progress.
 
@@ -178,7 +196,7 @@ public class Desktop
             // progress to just scale the bitmap view (UI elements
             // too, which of course was a bit silly).
 
-            gestureDetector =
+            scaleDetector =
                 new ScaleGestureDetector(Desktop.this,
                                          new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                                              @Override public boolean onScaleBegin(ScaleGestureDetector detector)
@@ -255,12 +273,12 @@ public class Desktop
 
         @Override public boolean onTouchEvent(MotionEvent event)
         {
-            Log.i(TAG, "onTouchEvent, scalingInProgress=" + scalingInProgress);
+            if (gestureDetector.onTouchEvent(event))
+                return true;
 
-            // For now, when during scaling we just scale the bitmap
-            // view, if a scaling gesture is in progress no other
-            // touch processing should be done.
-            if (gestureDetector.onTouchEvent(event) && scalingInProgress)
+            // If a scaling gesture is in progress no other touch
+            // processing should be done.
+            if (scaleDetector.onTouchEvent(event) && scalingInProgress)
                 return true;
 
             if (!renderedOnce)
commit 779a7015fd25099759bf00cee345a03e0e40e08f
Author: Tor Lillqvist <tml at iki.fi>
Date:   Sun Mar 3 12:50:25 2013 +0200

    Note that for COMMAND_WHEEL_ZOOM the delta value is ignored
    
    Change-Id: Ia8b8e98ff48a54fd1c295df439e8fd57aeb3fa25

diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index 0ec4f83..d86342d 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -2594,10 +2594,13 @@ long ImplWindowFrameProc( Window* pWindow, SalFrame* /*pFrame*/,
             break;
         case SALEVENT_EXTERNALZOOM:
             {
-            // Manually tuned to get a pleasing effect at least on my
-            // device... Would be better to actually achieve the
-            // requested scale factor of course.
-            const int ZOOM_FACTOR = 300;
+            // At least in Writer (see SwView::HandleWheelCommands()
+            // in sw/source/ui/uiview/viewport.cxx) the delta value in the event is cheerfully
+            // ignored and only its sign matters, zooming always is one "step" per event.
+            // Thus this factor has no meaning. Will have to fix this probably by adding a new
+            // CommandWheelData mode to actually multiply the current zoom level with a value
+            // specified.
+            const int ZOOM_FACTOR = 100;
 
             ZoomEvent* pZoomEvent = (ZoomEvent*) pEvent;
             SalWheelMouseEvent aSalWheelMouseEvent;


More information about the Libreoffice-commits mailing list