Kaydet (Commit) 4d8f12f5 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

More text selection WIP hacking

Change-Id: Ia29725295613faf875a688b3917b144a5f05bbe3
üst 5732ff54
...@@ -89,12 +89,17 @@ void touch_ui_selection_none(); ...@@ -89,12 +89,17 @@ void touch_ui_selection_none();
// where that is wanted, and this all is work in progress. Prefixed by // where that is wanted, and this all is work in progress. Prefixed by
// touch_lo_. // 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_keyboard_did_hide();
void touch_lo_runMain(); void touch_lo_runMain();
void touch_lo_set_view_size(int width, int height); 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_render_windows(void *context, int minX, int minY, int width, int height);
void touch_lo_tap(int x, int y); 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_pan(int deltaX, int deltaY);
void touch_lo_zoom(int x, int y, float scale); void touch_lo_zoom(int x, int y, float scale);
void touch_lo_keyboard_input(int c); void touch_lo_keyboard_input(int c);
...@@ -106,8 +111,6 @@ context, contextHeight, contextWidth specify where to draw. ...@@ -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); 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_mouse_drag(int x, int y, MLOMouseButtonState state);
void touch_lo_selection_attempt_resize(const void *documentHandle, void touch_lo_selection_attempt_resize(const void *documentHandle,
......
...@@ -16,24 +16,12 @@ ...@@ -16,24 +16,12 @@
@property int selectionRectangleCount; @property int selectionRectangleCount;
@end @end
#define HANDLE_BLOB 20 #define HANDLE_BLOB 40
#define HANDLE_STEM_WIDTH 6 #define HANDLE_STEM_WIDTH 6
#define HANDLE_STEM_HEIGHT 20 #define HANDLE_STEM_HEIGHT 40
@implementation View @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 - (CGRect) topLeftResizeHandle
{ {
if (self.selectionRectangleCount == 0) if (self.selectionRectangleCount == 0)
...@@ -166,39 +154,72 @@ ...@@ -166,39 +154,72 @@
- (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer - (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer
{ {
static enum { NONE, TOPLEFT, BOTTOMRIGHT } draggedHandle = NONE;
static CGFloat previousX = 0.0f, previousY = 0.0f; static CGFloat previousX = 0.0f, previousY = 0.0f;
CGPoint translation = [gestureRecognizer translationInView:self]; CGPoint translation = [gestureRecognizer translationInView:self];
if ([gestureRecognizer numberOfTouches] == 1) { if (gestureRecognizer.state == UIGestureRecognizerStateBegan &&
gestureRecognizer.numberOfTouches == 1) {
if (CGRectContainsPoint([self topLeftResizeHandle], if (CGRectContainsPoint([self topLeftResizeHandle],
[gestureRecognizer locationInView:self])) { [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.x += translation.x;
self.selectionRectangles[0].origin.y += translation.y; self.selectionRectangles[0].origin.y += translation.y;
self.selectionRectangles[0].size.width -= translation.x; self.selectionRectangles[0].size.width -= translation.x;
self.selectionRectangles[0].size.height -= translation.y; self.selectionRectangles[0].size.height -= translation.y;
#if 0
touch_lo_selection_attempt_resize(self.documentHandle, touch_lo_selection_attempt_resize(self.documentHandle,
self.selectionRectangles, self.selectionRectangles,
self.selectionRectangleCount); 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; return;
} else if (CGRectContainsPoint([self bottomRightResizeHandle], } else if (draggedHandle == BOTTOMRIGHT) {
[gestureRecognizer locationInView:self])) { const int N = self.selectionRectangleCount;
const int N = self.selectionRectangleCount - 1;
self.selectionRectangles[N].origin.x += translation.x; self.selectionRectangles[N-1].origin.x += translation.x;
self.selectionRectangles[N].origin.y += translation.y; self.selectionRectangles[N-1].origin.y += translation.y;
self.selectionRectangles[N].size.width -= translation.x; self.selectionRectangles[N-1].size.width += translation.x;
self.selectionRectangles[N].size.height -= translation.y; self.selectionRectangles[N-1].size.height += translation.y;
#if 0
touch_lo_selection_attempt_resize(self.documentHandle, touch_lo_selection_attempt_resize(self.documentHandle,
self.selectionRectangles, self.selectionRectangles,
self.selectionRectangleCount); 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; return;
} }
}
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) { if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
int deltaX = translation.x - previousX; int deltaX = translation.x - previousX;
...@@ -238,6 +259,17 @@ ...@@ -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)startSelectionOfType:(MLOSelectionKind)kind withNumber:(int)number ofRectangles:(CGRect *)rects forDocument:(const void *)document
{ {
(void) kind; (void) kind;
...@@ -257,6 +289,9 @@ ...@@ -257,6 +289,9 @@
self.selectionRectangleCount = number; self.selectionRectangleCount = number;
self.documentHandle = document; 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]; [self requestSelectionRedisplay];
} }
......
...@@ -413,48 +413,52 @@ void touch_lo_render_windows(void *context, int minX, int minY, int width, int h ...@@ -413,48 +413,52 @@ void touch_lo_render_windows(void *context, int minX, int minY, int width, int h
extern "C" extern "C"
void touch_lo_tap(int x, int y) void touch_lo_tap(int x, int y)
{ {
SalFrame *pFocus = IosSalInstance::getInstance()->getFocusFrame(); touch_lo_mouse(x, y, DOWN, NONE);
if (pFocus) { touch_lo_mouse(x, y, UP, NONE);
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);
}
} }
extern "C" 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(); SalFrame *pFocus = IosSalInstance::getInstance()->getFocusFrame();
if (pFocus) { if (pFocus) {
MouseEvent aEvent; MouseEvent aEvent;
sal_uLong nEvent; sal_uLong nEvent;
sal_uInt16 nModifiers = 0;
if (modifiers & SHIFT)
nModifiers |= KEY_SHIFT;
switch(state) { if (modifiers & META)
nModifiers |= KEY_MOD1;
switch (state) {
case DOWN: 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; nEvent = VCLEVENT_WINDOW_MOUSEBUTTONDOWN;
break; break;
case MOVE: 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; nEvent = VCLEVENT_WINDOW_MOUSEMOVE;
break; break;
case UP: 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; nEvent = VCLEVENT_WINDOW_MOUSEBUTTONUP;
break; break;
default:
assert(false);
} }
Application::PostMouseEvent(nEvent, pFocus->GetWindow(), &aEvent); 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" extern "C"
void touch_lo_pan(int deltaX, int deltaY) void touch_lo_pan(int deltaX, int deltaY)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment