Kaydet (Commit) 657a3a81 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst 36fb2933
/* -*- 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: */
...@@ -82,12 +82,14 @@ void touch_ui_selection_resize_done(bool success, ...@@ -82,12 +82,14 @@ void touch_ui_selection_resize_done(bool success,
void touch_ui_selection_none(); 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 // layer, in cases where we don't want to include a bunch of the
// "normal" LibreOffice C++ headers in an otherwise purely Objective-C // "normal" LibreOffice C++ headers in an otherwise purely Objective-C
// CocoaTouch-based source file. Of course it depends on the case // CocoaTouch-based source file. Of course it depends on the case
// 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_. 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 { DOWN, MOVE, UP} MLOMouseButtonState;
typedef enum { NONE, SHIFT, META } MLOModifiers; typedef enum { NONE, SHIFT, META } MLOModifiers;
...@@ -95,9 +97,7 @@ typedef int MLOModifierMask; ...@@ -95,9 +97,7 @@ typedef int MLOModifierMask;
void touch_lo_keyboard_did_hide(); void touch_lo_keyboard_did_hide();
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_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_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);
...@@ -113,10 +113,25 @@ void touch_lo_draw_tile(void *context, int contextWidth, int contextHeight, int ...@@ -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); 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, void touch_lo_selection_attempt_resize(const void *documentHandle,
MLORect *selectedRectangles, MLORect *selectedRectangles,
int numberOfRectangles); 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 #ifdef __cplusplus
} }
#endif #endif
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
- (void)drawRect:(CGRect)rect - (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]); // NSLog(@"statusBarOrientation: %ld", (long)[[UIApplication sharedApplication] statusBarOrientation]);
CGContextRef context = UIGraphicsGetCurrentContext(); CGContextRef context = UIGraphicsGetCurrentContext();
...@@ -157,44 +157,50 @@ ...@@ -157,44 +157,50 @@
static enum { NONE, TOPLEFT, BOTTOMRIGHT } draggedHandle = NONE; static enum { NONE, TOPLEFT, BOTTOMRIGHT } draggedHandle = NONE;
static CGFloat previousX, previousY; static CGFloat previousX, previousY;
CGPoint location = [gestureRecognizer locationInView:self];
CGPoint translation = [gestureRecognizer translationInView:self]; CGPoint translation = [gestureRecognizer translationInView:self];
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) { if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
previousX = previousY = 0; previousX = previousY = 0;
} }
CGFloat deltaX = translation.x - previousX; CGPoint delta;
CGFloat deltaY = translation.y - previousY; 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; previousX = translation.x;
previousY = translation.y; previousY = translation.y;
if (gestureRecognizer.state == UIGestureRecognizerStateBegan && if (gestureRecognizer.state == UIGestureRecognizerStateBegan &&
gestureRecognizer.numberOfTouches == 1) { gestureRecognizer.numberOfTouches == 1) {
if (CGRectContainsPoint([self topLeftResizeHandle], if (CGRectContainsPoint([self topLeftResizeHandle], location)) {
[gestureRecognizer locationInView:self])) NSLog(@"===> dragging TOPLEFT handle");
draggedHandle = TOPLEFT; draggedHandle = TOPLEFT;
else if (CGRectContainsPoint([self bottomRightResizeHandle], } else if (CGRectContainsPoint([self bottomRightResizeHandle], location)) {
[gestureRecognizer locationInView:self])) NSLog(@"===> dragging BOTTOMRIGHT handle");
draggedHandle = BOTTOMRIGHT; draggedHandle = BOTTOMRIGHT;
}
} }
if (draggedHandle == TOPLEFT) { if (draggedHandle == TOPLEFT) {
const int N = self.selectionRectangleCount; const int N = self.selectionRectangleCount;
self.selectionRectangles[0].origin.x += deltaX; CGPoint old = self.selectionRectangles[0].origin;
self.selectionRectangles[0].origin.y += deltaY;
self.selectionRectangles[0].size.width -= deltaX; self.selectionRectangles[0].origin = location;
self.selectionRectangles[0].size.height -= deltaY; self.selectionRectangles[0].size.width -= (location.x - old.x);
self.selectionRectangles[0].size.height -= (location.y - old.y);
#if 0 #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 #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, touch_lo_mouse(self.selectionRectangles[0].origin.x,
self.selectionRectangles[0].origin.y, self.selectionRectangles[0].origin.y,
DOWN, NONE); DOWN, NONE);
...@@ -208,35 +214,16 @@ ...@@ -208,35 +214,16 @@
draggedHandle = NONE; draggedHandle = NONE;
return; return;
} else if (draggedHandle == BOTTOMRIGHT) { } else if (draggedHandle == BOTTOMRIGHT) {
const int N = self.selectionRectangleCount;
self.selectionRectangles[N-1].size.width += deltaX; touch_lo_selection_end_move(self.documentHandle, location.x, location.y);
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);
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) if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
draggedHandle = NONE; draggedHandle = NONE;
return; return;
} }
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) { if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
// NSLog(@"panGesture: pan (delta): (%d,%d)", deltaX, deltaY); touch_lo_pan(delta.x, delta.y);
touch_lo_pan(deltaX, deltaY);
} }
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <ndtxt.hxx> #include <ndtxt.hxx>
#include <scriptinfo.hxx> #include <scriptinfo.hxx>
#include <mdiexp.hxx> #include <mdiexp.hxx>
#include <wrtsh.hxx>
#include <comcore.hrc> #include <comcore.hrc>
#include <svx/sdr/overlay/overlaymanager.hxx> #include <svx/sdr/overlay/overlaymanager.hxx>
...@@ -272,16 +273,21 @@ void SwSelPaintRects::Show() ...@@ -272,16 +273,21 @@ void SwSelPaintRects::Show()
const OutputDevice* pOut = GetShell()->GetWin(); const OutputDevice* pOut = GetShell()->GetWin();
if ( ! pOut ) if ( ! pOut )
pOut = GetShell()->GetOut(); pOut = GetShell()->GetOut();
// Buffer will be deallocated in the UI layer SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(const_cast<SwCrsrShell*>(GetShell()));
CGRect *rects = (CGRect *) malloc((sizeof(CGRect))*size()); if ( pWrtShell )
for (size_t i = 0; i < size(); ++i)
{ {
Point origin = pOut->LogicToPixel((*this)[i].Pos()); // Buffer will be deallocated in the UI layer
Size size = pOut->LogicToPixel((*this)[i].SSize()); CGRect *rects = (CGRect *) malloc((sizeof(CGRect))*size());
rects[i] = CGRectMake(origin.X(), origin.Y(), for (size_t i = 0; i < size(); ++i)
size.Width(), size.Height()); {
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 #else
// Not yet implemented // Not yet implemented
#endif #endif
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <config_features.h>
#include <swtypes.hxx> #include <swtypes.hxx>
#include <hintids.hxx> #include <hintids.hxx>
...@@ -66,6 +67,8 @@ ...@@ -66,6 +67,8 @@
#include <basegfx/color/bcolortools.hxx> #include <basegfx/color/bcolortools.hxx>
#include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygon.hxx>
#include <touch/touch-impl.h>
#include <editeng/acorrcfg.hxx> #include <editeng/acorrcfg.hxx>
#include <SwSmartTagMgr.hxx> #include <SwSmartTagMgr.hxx>
#include <edtwin.hxx> #include <edtwin.hxx>
...@@ -2683,6 +2686,35 @@ static bool lcl_urlOverBackground(SwWrtShell& rSh, const Point& rDocPos) ...@@ -2683,6 +2686,35 @@ static bool lcl_urlOverBackground(SwWrtShell& rSh, const Point& rDocPos)
return rSh.GetContentAtPos(rDocPos, aSwContentAtPos) && pSelectableObj->GetLayer() == rSh.GetDoc()->GetHellId(); 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) void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
{ {
SwWrtShell &rSh = m_rView.GetWrtShell(); SwWrtShell &rSh = m_rView.GetWrtShell();
......
...@@ -52,6 +52,7 @@ public: ...@@ -52,6 +52,7 @@ public:
void damaged( IosSalFrame *frame, void damaged( IosSalFrame *frame,
const basegfx::B2IBox& rDamageRect); const basegfx::B2IBox& rDamageRect);
// Functions scheduled to be run as "user events" in the LO thread
typedef struct { typedef struct {
bool done; bool done;
CGContextRef context; CGContextRef context;
...@@ -61,6 +62,12 @@ public: ...@@ -61,6 +62,12 @@ public:
DECL_LINK( DisplayConfigurationChanged, void* ); DECL_LINK( DisplayConfigurationChanged, void* );
typedef struct {
const void *documentHandle;
int x, y;
} SelectionEndMoveArg;
DECL_LINK( SelectionEndMove, SelectionEndMoveArg* );
pthread_mutex_t m_aRenderMutex; pthread_mutex_t m_aRenderMutex;
pthread_cond_t m_aRenderCond; pthread_cond_t m_aRenderCond;
}; };
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <basebmp/scanlineformats.hxx> #include <basebmp/scanlineformats.hxx>
#include <vcl/msgbox.hxx> #include <vcl/msgbox.hxx>
#include <touch/touch.h> #include <touch/touch.h>
#include <touch/touch-impl.h>
#include "ios/iosinst.hxx" #include "ios/iosinst.hxx"
#include "headless/svpdummies.hxx" #include "headless/svpdummies.hxx"
...@@ -507,6 +508,32 @@ void touch_lo_keyboard_did_hide() ...@@ -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" extern "C"
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*/)
{ {
......
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