[Libreoffice-commits] core.git: include/touch ios/experimental vcl/ios

Tor Lillqvist tml at collabora.com
Fri Oct 18 08:48:31 PDT 2013


 include/touch/touch.h                           |    7 +
 ios/experimental/LibreOffice/LibreOffice/View.m |  117 +++++++++++++++---------
 vcl/ios/iosinst.cxx                             |   40 ++++----
 3 files changed, 103 insertions(+), 61 deletions(-)

New commits:
commit 4d8f12f57b0f02d3610269eae7b5981010dc7e98
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Oct 18 18:45:13 2013 +0300

    More text selection WIP hacking
    
    Change-Id: Ia29725295613faf875a688b3917b144a5f05bbe3

diff --git a/include/touch/touch.h b/include/touch/touch.h
index 11440f1..9e5c011 100644
--- a/include/touch/touch.h
+++ b/include/touch/touch.h
@@ -89,12 +89,17 @@ void touch_ui_selection_none();
 // where that is wanted, and this all is work in progress. Prefixed by
 // touch_lo_.
 
+typedef enum { DOWN, MOVE, UP} MLOMouseButtonState;
+typedef enum { NONE, SHIFT, META } MLOModifiers;
+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);
 void touch_lo_zoom(int x, int y, float scale);
 void touch_lo_keyboard_input(int c);
@@ -106,8 +111,6 @@ context, contextHeight, contextWidth specify where to draw.
 */
 void touch_lo_draw_tile(void *context, int contextWidth, int contextHeight, int tilePosX, int tilePosY, int tileWidth, int tileHeight);
 
-typedef enum { DOWN, MOVE, UP} MLOMouseButtonState;
-
 void touch_lo_mouse_drag(int x, int y, MLOMouseButtonState state);
 
 void touch_lo_selection_attempt_resize(const void *documentHandle,
diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m
index 2e5f3ef..44fa6df 100644
--- a/ios/experimental/LibreOffice/LibreOffice/View.m
+++ b/ios/experimental/LibreOffice/LibreOffice/View.m
@@ -16,24 +16,12 @@
 @property int selectionRectangleCount;
 @end
 
-#define HANDLE_BLOB 20
+#define HANDLE_BLOB 40
 #define HANDLE_STEM_WIDTH 6
-#define HANDLE_STEM_HEIGHT 20
+#define HANDLE_STEM_HEIGHT 40
 
 @implementation View
 
-#if 0
-- (id) initWithFrame:(CGRect)rect
-{
-    self = [super initWithFrame:rect];
-    if (self) {
-        self.selectionRectangles = NULL;
-        self.selectionRectangleCount = 0;
-    }
-    return self;
-}
-#endif
-
 - (CGRect) topLeftResizeHandle
 {
     if (self.selectionRectangleCount == 0)
@@ -166,38 +154,71 @@
 
 - (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer
 {
+    static enum { NONE, TOPLEFT, BOTTOMRIGHT } draggedHandle = NONE;
     static CGFloat previousX = 0.0f, previousY = 0.0f;
 
     CGPoint translation = [gestureRecognizer translationInView:self];
 
-    if ([gestureRecognizer numberOfTouches] == 1) {
+    if (gestureRecognizer.state == UIGestureRecognizerStateBegan &&
+        gestureRecognizer.numberOfTouches == 1) {
         if (CGRectContainsPoint([self topLeftResizeHandle],
-                                [gestureRecognizer locationInView:self])) {
-
-            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;
-
-            touch_lo_selection_attempt_resize(self.documentHandle,
-                                              self.selectionRectangles,
-                                              self.selectionRectangleCount);
-            return;
-        } else if (CGRectContainsPoint([self bottomRightResizeHandle],
-                                       [gestureRecognizer locationInView:self])) {
-
-            const int N = self.selectionRectangleCount - 1;
-
-            self.selectionRectangles[N].origin.x += translation.x;
-            self.selectionRectangles[N].origin.y += translation.y;
-            self.selectionRectangles[N].size.width -= translation.x;
-            self.selectionRectangles[N].size.height -= translation.y;
-
-            touch_lo_selection_attempt_resize(self.documentHandle,
-                                              self.selectionRectangles,
-                                              self.selectionRectangleCount);
-            return;
-        }
+                                [gestureRecognizer locationInView:self]))
+            draggedHandle = TOPLEFT;
+        else if (CGRectContainsPoint([self bottomRightResizeHandle],
+                                     [gestureRecognizer locationInView:self]))
+            draggedHandle = BOTTOMRIGHT;
+    }
+
+    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;
+
+#if 0
+        touch_lo_selection_attempt_resize(self.documentHandle,
+                                          self.selectionRectangles,
+                                          self.selectionRectangleCount);
+#else
+        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;
+    } 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;
+
+#if 0
+        touch_lo_selection_attempt_resize(self.documentHandle,
+                                          self.selectionRectangles,
+                                          self.selectionRectangleCount);
+#else
+        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) {
@@ -238,6 +259,17 @@
     }
 }
 
+static int compare_rects(const void *a, const void *b)
+{
+    const CGRect *ra = a;
+    const CGRect *rb = b;
+
+    if (ra->origin.y != rb->origin.y)
+        return ra->origin.y - rb->origin.y;
+    else
+        return ra->origin.x - rb->origin.x;
+}
+
 - (void)startSelectionOfType:(MLOSelectionKind)kind withNumber:(int)number ofRectangles:(CGRect *)rects forDocument:(const void *)document
 {
     (void) kind;
@@ -257,6 +289,9 @@
     self.selectionRectangleCount = number;
     self.documentHandle = document;
 
+    // The selection rectangle provided by LO are not sorted in any sane way
+    qsort(self.selectionRectangles, self.selectionRectangleCount, sizeof(self.selectionRectangles[0]), compare_rects);
+
     [self requestSelectionRedisplay];
 }
 
diff --git a/vcl/ios/iosinst.cxx b/vcl/ios/iosinst.cxx
index b4e7257..2416bf6 100644
--- a/vcl/ios/iosinst.cxx
+++ b/vcl/ios/iosinst.cxx
@@ -413,49 +413,53 @@ void touch_lo_render_windows(void *context, int minX, int minY, int width, int h
 extern "C"
 void touch_lo_tap(int x, int y)
 {
-    SalFrame *pFocus = IosSalInstance::getInstance()->getFocusFrame();
-    if (pFocus) {
-        MouseEvent aEvent;
-        sal_uLong nEvent;
-
-        aEvent = MouseEvent(Point(x, y), 1, MOUSE_SIMPLECLICK, MOUSE_LEFT);
-        nEvent = VCLEVENT_WINDOW_MOUSEBUTTONDOWN;
-        Application::PostMouseEvent(nEvent, pFocus->GetWindow(), &aEvent);
-
-        nEvent = VCLEVENT_WINDOW_MOUSEBUTTONUP;
-        Application::PostMouseEvent(nEvent, pFocus->GetWindow(), &aEvent);
-    }
+    touch_lo_mouse(x, y, DOWN, NONE);
+    touch_lo_mouse(x, y, UP, NONE);
 }
 
 extern "C"
-void touch_lo_mouse_drag(int x, int y, MLOMouseButtonState state)
+void touch_lo_mouse(int x, int y, MLOMouseButtonState state, MLOModifierMask modifiers)
 {
     SalFrame *pFocus = IosSalInstance::getInstance()->getFocusFrame();
 
     if (pFocus) {
         MouseEvent aEvent;
         sal_uLong nEvent;
+        sal_uInt16 nModifiers = 0;
+
+        if (modifiers & SHIFT)
+            nModifiers |= KEY_SHIFT;
+
+        if (modifiers & META)
+            nModifiers |= KEY_MOD1;
 
-        switch(state) {
+        switch (state) {
         case DOWN:
-            aEvent = MouseEvent(Point(x, y), 1, MOUSE_SIMPLECLICK, MOUSE_LEFT);
+            aEvent = MouseEvent(Point(x, y), 1, MOUSE_SIMPLECLICK, MOUSE_LEFT, nModifiers);
             nEvent = VCLEVENT_WINDOW_MOUSEBUTTONDOWN;
             break;
         case MOVE:
-            aEvent = MouseEvent(Point(x, y), 1, MOUSE_SIMPLEMOVE, MOUSE_LEFT);
+            aEvent = MouseEvent(Point(x, y), 1, MOUSE_SIMPLEMOVE, MOUSE_LEFT, nModifiers);
             nEvent = VCLEVENT_WINDOW_MOUSEMOVE;
             break;
         case UP:
-            aEvent = MouseEvent(Point(x, y), 1, MOUSE_SIMPLECLICK, MOUSE_LEFT);
+            aEvent = MouseEvent(Point(x, y), 1, MOUSE_SIMPLECLICK, MOUSE_LEFT, nModifiers);
             nEvent = VCLEVENT_WINDOW_MOUSEBUTTONUP;
             break;
+        default:
+            assert(false);
         }
-
         Application::PostMouseEvent(nEvent, pFocus->GetWindow(), &aEvent);
     }
 }
 
 extern "C"
+void touch_lo_mouse_drag(int x, int y, MLOMouseButtonState state)
+{
+    touch_lo_mouse(x, y, state, NONE);
+}
+
+extern "C"
 void touch_lo_pan(int deltaX, int deltaY)
 {
     SalFrame *pFocus = IosSalInstance::getInstance()->getFocusFrame();


More information about the Libreoffice-commits mailing list