[Libreoffice-commits] core.git: 3 commits - include/touch ios/experimental sw/source vcl/inc vcl/ios

Tor Lillqvist tml at collabora.com
Mon Oct 21 15:11:14 PDT 2013


 include/touch/touch-impl.h                             |   33 ++++++++
 include/touch/touch.h                                  |   23 ++++-
 ios/experimental/LibreOffice/LibreOffice/AppDelegate.m |    8 -
 ios/experimental/LibreOffice/LibreOffice/View.m        |   69 +++++++----------
 sw/source/core/crsr/viscrs.cxx                         |   22 +++--
 sw/source/ui/docvw/edtwin.cxx                          |   32 +++++++
 vcl/inc/ios/iosinst.hxx                                |    7 +
 vcl/ios/iosinst.cxx                                    |   27 ++++++
 8 files changed, 163 insertions(+), 58 deletions(-)

New commits:
commit 657a3a81828216240b6ff31377d62ca17e656368
Author: Tor Lillqvist <tml at collabora.com>
Date:   Tue Oct 22 01:06:56 2013 +0300

    Try to handle selection resizing in a more "correct" way
    
    Faking mouse clicks is a stupid way to do it of course. Try to do it
    "right". For now just worked on moving the end handle, but once that
    works, similar code should be used for the start handle, too.
    
    Does not work yet. It is hard to extract out from
    SwEditWin::MouseButtonDown() exactly what all is relevant, and what
    isn't, for this use case.
    
    Change-Id: I76a226f787facbac645aaff8b4852d693bcf4ccb

diff --git a/include/touch/touch-impl.h b/include/touch/touch-impl.h
new file mode 100644
index 0000000..a2550b1
--- /dev/null
+++ b/include/touch/touch-impl.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright 2013 LibreOffice contributors.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_TOUCH_TOUCH_IMPL_H
+#define INCLUDED_TOUCH_TOUCH_IMPL_H
+
+#ifdef __cplusplus
+extern "C" {
+#if 0
+} // To avoid an editor indenting all inside the extern "C"
+#endif
+#endif
+
+// "Implementation" of touch_lo_* functions, called on the LO thread through
+// the PostUserEvent mechanism. Not called by UI thread code.
+
+void touch_lo_selection_end_move_impl(const void *documentHandle,
+                                      int x,
+                                      int y);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // INCLUDED_TOUCH_TOUCH_IMPL_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/touch/touch.h b/include/touch/touch.h
index 9e5c011..f999eca 100644
--- a/include/touch/touch.h
+++ b/include/touch/touch.h
@@ -82,12 +82,14 @@ void touch_ui_selection_resize_done(bool success,
 
 void touch_ui_selection_none();
 
-// 2) Those implmented in the lower layers to be called by the upper
+// 2) Those implemented in the lower layers to be called by the upper
 // layer, in cases where we don't want to include a bunch of the
 // "normal" LibreOffice C++ headers in an otherwise purely Objective-C
 // CocoaTouch-based source file. Of course it depends on the case
 // where that is wanted, and this all is work in progress. Prefixed by
-// touch_lo_.
+// touch_lo_. All these are called on the UI thread and except for
+// those so marked schedule work to be done asynchronously on the LO
+// thread.
 
 typedef enum { DOWN, MOVE, UP} MLOMouseButtonState;
 typedef enum { NONE, SHIFT, META } MLOModifiers;
@@ -95,9 +97,7 @@ typedef int MLOModifierMask;
 
 void touch_lo_keyboard_did_hide();
 
-void touch_lo_runMain();
 void touch_lo_set_view_size(int width, int height);
-void touch_lo_render_windows(void *context, int minX, int minY, int width, int height);
 void touch_lo_tap(int x, int y);
 void touch_lo_mouse(int x, int y, MLOMouseButtonState state, MLOModifierMask modifiers);
 void touch_lo_pan(int deltaX, int deltaY);
@@ -113,10 +113,25 @@ void touch_lo_draw_tile(void *context, int contextWidth, int contextHeight, int
 
 void touch_lo_mouse_drag(int x, int y, MLOMouseButtonState state);
 
+// Move the end of the selection to (x,y)
+// (work in progress, of course there should be a corresponding function
+// to move the start of the selection, too.)
+void touch_lo_selection_end_move(const void *documentHandle,
+                                 int x,
+                                 int y);
+
 void touch_lo_selection_attempt_resize(const void *documentHandle,
                                        MLORect *selectedRectangles,
                                        int numberOfRectangles);
 
+// Special case: synchronous: waits for the rendering to complete
+void touch_lo_render_windows(void *context, int minX, int minY, int width, int height);
+
+// Special case: This is the function that is called in the newly
+// created LO thread to run the LO code.
+void touch_lo_runMain();
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m
index c908595..cb96e48 100644
--- a/ios/experimental/LibreOffice/LibreOffice/View.m
+++ b/ios/experimental/LibreOffice/LibreOffice/View.m
@@ -101,7 +101,7 @@
 
 - (void)drawRect:(CGRect)rect
 {
-    NSLog(@"View drawRect: %dx%d@(%d,%d)", (int) rect.size.width, (int) rect.size.height, (int) rect.origin.x, (int) rect.origin.y);
+    // NSLog(@"View drawRect: %dx%d@(%d,%d)", (int) rect.size.width, (int) rect.size.height, (int) rect.origin.x, (int) rect.origin.y);
     // NSLog(@"statusBarOrientation: %ld", (long)[[UIApplication sharedApplication] statusBarOrientation]);
 
     CGContextRef context = UIGraphicsGetCurrentContext();
@@ -157,44 +157,50 @@
     static enum { NONE, TOPLEFT, BOTTOMRIGHT } draggedHandle = NONE;
     static CGFloat previousX, previousY;
 
+    CGPoint location = [gestureRecognizer locationInView:self];
     CGPoint translation = [gestureRecognizer translationInView:self];
 
     if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
         previousX = previousY = 0;
     }
 
-    CGFloat deltaX = translation.x - previousX;
-    CGFloat deltaY = translation.y - previousY;
+    CGPoint delta;
+    delta.x = translation.x - previousX;
+    delta.y = translation.y - previousY;
 
-    NSLog(@"drag: %f,%f", deltaX, deltaY);
+    // NSLog(@"location: (%f,%f) , drag: (%f,%f)", location.x, location.y, delta.x, delta.y);
 
     previousX = translation.x;
     previousY = translation.y;
 
     if (gestureRecognizer.state == UIGestureRecognizerStateBegan &&
         gestureRecognizer.numberOfTouches == 1) {
-        if (CGRectContainsPoint([self topLeftResizeHandle],
-                                [gestureRecognizer locationInView:self]))
+        if (CGRectContainsPoint([self topLeftResizeHandle], location)) {
+            NSLog(@"===> dragging TOPLEFT handle");
             draggedHandle = TOPLEFT;
-        else if (CGRectContainsPoint([self bottomRightResizeHandle],
-                                     [gestureRecognizer locationInView:self]))
+        } else if (CGRectContainsPoint([self bottomRightResizeHandle], location)) {
+            NSLog(@"===> dragging BOTTOMRIGHT handle");
             draggedHandle = BOTTOMRIGHT;
+        }
     }
 
     if (draggedHandle == TOPLEFT) {
         const int N = self.selectionRectangleCount;
 
-        self.selectionRectangles[0].origin.x += deltaX;
-        self.selectionRectangles[0].origin.y += deltaY;
-        self.selectionRectangles[0].size.width -= deltaX;
-        self.selectionRectangles[0].size.height -= deltaY;
+        CGPoint old = self.selectionRectangles[0].origin;
+
+        self.selectionRectangles[0].origin = location;
+        self.selectionRectangles[0].size.width -= (location.x - old.x);
+        self.selectionRectangles[0].size.height -= (location.y - old.y);
 
 #if 0
         touch_lo_selection_attempt_resize(self.documentHandle,
                                           self.selectionRectangles,
                                           self.selectionRectangleCount);
 #else
-        touch_lo_tap(0, 0);
+        touch_lo_tap((self.selectionRectangles[0].origin.x + self.selectionRectangles[N-1].origin.x) / 2,
+                     (self.selectionRectangles[0].origin.y + self.selectionRectangles[N-1].origin.y) / 2);
+
         touch_lo_mouse(self.selectionRectangles[0].origin.x,
                        self.selectionRectangles[0].origin.y,
                        DOWN, NONE);
@@ -208,35 +214,16 @@
             draggedHandle = NONE;
         return;
     } else if (draggedHandle == BOTTOMRIGHT) {
-        const int N = self.selectionRectangleCount;
 
-        self.selectionRectangles[N-1].size.width += deltaX;
-        self.selectionRectangles[N-1].size.height += deltaY;
+        touch_lo_selection_end_move(self.documentHandle, location.x, location.y);
 
-#if 0
-        touch_lo_selection_attempt_resize(self.documentHandle,
-                                          self.selectionRectangles,
-                                          self.selectionRectangleCount);
-#else
-        touch_lo_tap(0, 0);
-        touch_lo_mouse(self.selectionRectangles[0].origin.x,
-                       self.selectionRectangles[0].origin.y,
-                       DOWN, NONE);
-        touch_lo_mouse(self.selectionRectangles[N-1].origin.x +
-                       self.selectionRectangles[N-1].size.width,
-                       self.selectionRectangles[N-1].origin.y +
-                       self.selectionRectangles[N-1].size.height,
-                       UP, NONE);
-#endif
         if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
             draggedHandle = NONE;
         return;
     }
 
     if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
-        // NSLog(@"panGesture: pan (delta): (%d,%d)", deltaX, deltaY);
-
-        touch_lo_pan(deltaX, deltaY);
+        touch_lo_pan(delta.x, delta.y);
     }
 }
 
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index ab2e2f8..e085019 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -37,6 +37,7 @@
 #include <ndtxt.hxx>
 #include <scriptinfo.hxx>
 #include <mdiexp.hxx>
+#include <wrtsh.hxx>
 #include <comcore.hrc>
 
 #include <svx/sdr/overlay/overlaymanager.hxx>
@@ -272,16 +273,21 @@ void SwSelPaintRects::Show()
             const OutputDevice* pOut = GetShell()->GetWin();
             if ( ! pOut )
                 pOut = GetShell()->GetOut();
-            // Buffer will be deallocated in the UI layer
-            CGRect *rects = (CGRect *) malloc((sizeof(CGRect))*size());
-            for (size_t i = 0; i < size(); ++i)
+            SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(const_cast<SwCrsrShell*>(GetShell()));
+            if ( pWrtShell )
             {
-                Point origin = pOut->LogicToPixel((*this)[i].Pos());
-                Size size = pOut->LogicToPixel((*this)[i].SSize());
-                rects[i] = CGRectMake(origin.X(), origin.Y(),
-                                      size.Width(), size.Height());
+                // Buffer will be deallocated in the UI layer
+                CGRect *rects = (CGRect *) malloc((sizeof(CGRect))*size());
+                for (size_t i = 0; i < size(); ++i)
+                {
+                    Point origin = pOut->LogicToPixel((*this)[i].Pos());
+                    Size size = pOut->LogicToPixel((*this)[i].SSize());
+                    rects[i] = CGRectMake(origin.X(), origin.Y(),
+                                          size.Width(), size.Height());
+                }
+                // GetShell returns a SwCrsrShell which actually is a SwWrtShell
+                touch_ui_selection_start(MLOSelectionText, pWrtShell, rects, size(), NULL);
             }
-            touch_ui_selection_start(MLOSelectionText, GetShell(), rects, size(), NULL);
 #else
             // Not yet implemented
 #endif
diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx
index 6bc42f1..9ced231 100644
--- a/sw/source/ui/docvw/edtwin.cxx
+++ b/sw/source/ui/docvw/edtwin.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <config_features.h>
 
 #include <swtypes.hxx>
 #include <hintids.hxx>
@@ -66,6 +67,8 @@
 #include <basegfx/color/bcolortools.hxx>
 #include <basegfx/polygon/b2dpolygon.hxx>
 
+#include <touch/touch-impl.h>
+
 #include <editeng/acorrcfg.hxx>
 #include <SwSmartTagMgr.hxx>
 #include <edtwin.hxx>
@@ -2683,6 +2686,35 @@ static bool lcl_urlOverBackground(SwWrtShell& rSh, const Point& rDocPos)
     return rSh.GetContentAtPos(rDocPos, aSwContentAtPos) && pSelectableObj->GetLayer() == rSh.GetDoc()->GetHellId();
 }
 
+#if !HAVE_FEATURE_DESKTOP
+
+void touch_lo_selection_end_move_impl(const void *documentHandle,
+                                      int x,
+                                      int y)
+{
+    SwWrtShell *pWrtShell = reinterpret_cast<SwWrtShell*>(const_cast<void*>(documentHandle));
+
+    if (!pWrtShell)
+        return;
+
+    const OutputDevice *pOut = pWrtShell->GetWin();
+    if (!pOut)
+        pOut = pWrtShell->GetOut();
+
+    const Point aDocPos( pOut->PixelToLogic( Point(x, y) ) );
+
+    // SAL _ DEBUG("touch_lo_selection_end_move_impl: " << Point(x, y) << " => " << aDocPos);
+
+    pWrtShell->ChgCurrPam( aDocPos );
+
+    {
+        SwMvContext aMvContext( pWrtShell );
+        pWrtShell->SetCursor( &aDocPos, sal_False );
+    }
+}
+
+#endif
+
 void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
 {
     SwWrtShell &rSh = m_rView.GetWrtShell();
diff --git a/vcl/inc/ios/iosinst.hxx b/vcl/inc/ios/iosinst.hxx
index 2ff9e57..0dfa7eb 100644
--- a/vcl/inc/ios/iosinst.hxx
+++ b/vcl/inc/ios/iosinst.hxx
@@ -52,6 +52,7 @@ public:
     void damaged( IosSalFrame *frame,
                   const basegfx::B2IBox& rDamageRect);
 
+    // Functions scheduled to be run as "user events" in the LO thread
     typedef struct {
         bool done;
         CGContextRef context;
@@ -61,6 +62,12 @@ public:
 
     DECL_LINK( DisplayConfigurationChanged, void* );
 
+    typedef struct {
+        const void *documentHandle;
+        int x, y;
+    } SelectionEndMoveArg;
+    DECL_LINK( SelectionEndMove, SelectionEndMoveArg* );
+
     pthread_mutex_t m_aRenderMutex;
     pthread_cond_t m_aRenderCond;
 };
diff --git a/vcl/ios/iosinst.cxx b/vcl/ios/iosinst.cxx
index 2416bf6..50716f0 100644
--- a/vcl/ios/iosinst.cxx
+++ b/vcl/ios/iosinst.cxx
@@ -24,6 +24,7 @@
 #include <basebmp/scanlineformats.hxx>
 #include <vcl/msgbox.hxx>
 #include <touch/touch.h>
+#include <touch/touch-impl.h>
 
 #include "ios/iosinst.hxx"
 #include "headless/svpdummies.hxx"
@@ -507,6 +508,32 @@ void touch_lo_keyboard_did_hide()
     }
 }
 
+IMPL_LINK( IosSalInstance, SelectionEndMove, SelectionEndMoveArg*, pArg )
+{
+    touch_lo_selection_end_move_impl(pArg->documentHandle, pArg->x, pArg->y);
+
+    delete pArg;
+
+    return 0;
+}
+
+extern "C"
+void touch_lo_selection_end_move(const void *documentHandle,
+                                 int x,
+                                 int y)
+{
+    IosSalInstance *pInstance = IosSalInstance::getInstance();
+
+    if ( pInstance == NULL )
+        return;
+
+    IosSalInstance::SelectionEndMoveArg *pArg = new IosSalInstance::SelectionEndMoveArg;
+    pArg->documentHandle = documentHandle;
+    pArg->x = x;
+    pArg->y = y;
+    Application::PostUserEvent( LINK( pInstance, IosSalInstance, SelectionEndMove), pArg );
+}
+
 extern "C"
 void touch_lo_draw_tile(void * /*context*/, int /*contextWidth*/, int /*contextHeight*/, int /*tilePosX*/, int /*tilePosY*/, int /*tileWidth*/, int /*tileHeight*/)
 {
commit 36fb29338bbe2f3013ccedd244043e510b9ba0c1
Author: Tor Lillqvist <tml at collabora.com>
Date:   Tue Oct 22 00:58:13 2013 +0300

    Bin verbose logging
    
    Change-Id: Ifd3613f7a48f966f23ea2023f922b05b5f83fcab

diff --git a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m
index b4d027e..a2abfb8 100644
--- a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m
+++ b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m
@@ -228,14 +228,6 @@ void touch_ui_selection_start(MLOSelectionKind kind,
     (void) preview;
 
     // Note that this is called on the LO thread
-    NSLog(@"==> touch_ui_selection_start");
-    for(int i = 0; i < rectangleCount; ++i){
-        NSLog(@"  %fx%f@(%f,%f)",
-              rectangles[i].size.width,
-              rectangles[i].size.height,
-              rectangles[i].origin.x,
-              rectangles[i].origin.y);
-    }
     dispatch_async(dispatch_get_main_queue(), ^{
             [theView startSelectionOfType:kind withNumber:rectangleCount ofRectangles:rectangles forDocument:documentHandle];
         });
commit bdf2b506c38b38af531d8c8aa14dd51d89386899
Author: Tor Lillqvist <tml at collabora.com>
Date:   Sun Oct 20 16:19:16 2013 +0300

    Intermediate commit of experimental iOS app hacking
    
    Change-Id: I9326c9684a9c53f1f9a3ea5603bcb44c941e8918

diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m
index 44fa6df..c908595 100644
--- a/ios/experimental/LibreOffice/LibreOffice/View.m
+++ b/ios/experimental/LibreOffice/LibreOffice/View.m
@@ -155,10 +155,22 @@
 - (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer
 {
     static enum { NONE, TOPLEFT, BOTTOMRIGHT } draggedHandle = NONE;
-    static CGFloat previousX = 0.0f, previousY = 0.0f;
+    static CGFloat previousX, previousY;
 
     CGPoint translation = [gestureRecognizer translationInView:self];
 
+    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
+        previousX = previousY = 0;
+    }
+
+    CGFloat deltaX = translation.x - previousX;
+    CGFloat deltaY = translation.y - previousY;
+
+    NSLog(@"drag: %f,%f", deltaX, deltaY);
+
+    previousX = translation.x;
+    previousY = translation.y;
+
     if (gestureRecognizer.state == UIGestureRecognizerStateBegan &&
         gestureRecognizer.numberOfTouches == 1) {
         if (CGRectContainsPoint([self topLeftResizeHandle],
@@ -172,16 +184,17 @@
     if (draggedHandle == TOPLEFT) {
         const int N = self.selectionRectangleCount;
 
-        self.selectionRectangles[0].origin.x += translation.x;
-        self.selectionRectangles[0].origin.y += translation.y;
-        self.selectionRectangles[0].size.width -= translation.x;
-        self.selectionRectangles[0].size.height -= translation.y;
+        self.selectionRectangles[0].origin.x += deltaX;
+        self.selectionRectangles[0].origin.y += deltaY;
+        self.selectionRectangles[0].size.width -= deltaX;
+        self.selectionRectangles[0].size.height -= deltaY;
 
 #if 0
         touch_lo_selection_attempt_resize(self.documentHandle,
                                           self.selectionRectangles,
                                           self.selectionRectangleCount);
 #else
+        touch_lo_tap(0, 0);
         touch_lo_mouse(self.selectionRectangles[0].origin.x,
                        self.selectionRectangles[0].origin.y,
                        DOWN, NONE);
@@ -197,16 +210,15 @@
     } else if (draggedHandle == BOTTOMRIGHT) {
         const int N = self.selectionRectangleCount;
 
-        self.selectionRectangles[N-1].origin.x += translation.x;
-        self.selectionRectangles[N-1].origin.y += translation.y;
-        self.selectionRectangles[N-1].size.width += translation.x;
-        self.selectionRectangles[N-1].size.height += translation.y;
+        self.selectionRectangles[N-1].size.width += deltaX;
+        self.selectionRectangles[N-1].size.height += deltaY;
 
 #if 0
         touch_lo_selection_attempt_resize(self.documentHandle,
                                           self.selectionRectangles,
                                           self.selectionRectangleCount);
 #else
+        touch_lo_tap(0, 0);
         touch_lo_mouse(self.selectionRectangles[0].origin.x,
                        self.selectionRectangles[0].origin.y,
                        DOWN, NONE);
@@ -222,16 +234,10 @@
     }
 
     if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
-        int deltaX = translation.x - previousX;
-        int deltaY = translation.y - previousY;
-
         // NSLog(@"panGesture: pan (delta): (%d,%d)", deltaX, deltaY);
 
         touch_lo_pan(deltaX, deltaY);
     }
-
-    previousX = translation.x;
-    previousY = translation.y;
 }
 
 - (void)pinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer


More information about the Libreoffice-commits mailing list