diff options
author | Tor Lillqvist <tml@collabora.com> | 2013-10-22 01:06:56 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2013-10-22 01:10:41 +0300 |
commit | 657a3a81828216240b6ff31377d62ca17e656368 (patch) | |
tree | 5729af9bbbd63c5d729ad183b14d52065d70fffa | |
parent | 36fb29338bbe2f3013ccedd244043e510b9ba0c1 (diff) |
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
-rw-r--r-- | include/touch/touch-impl.h | 33 | ||||
-rw-r--r-- | include/touch/touch.h | 23 | ||||
-rw-r--r-- | ios/experimental/LibreOffice/LibreOffice/View.m | 55 | ||||
-rw-r--r-- | sw/source/core/crsr/viscrs.cxx | 22 | ||||
-rw-r--r-- | sw/source/ui/docvw/edtwin.cxx | 32 | ||||
-rw-r--r-- | vcl/inc/ios/iosinst.hxx | 7 | ||||
-rw-r--r-- | vcl/ios/iosinst.cxx | 27 |
7 files changed, 153 insertions, 46 deletions
diff --git a/include/touch/touch-impl.h b/include/touch/touch-impl.h new file mode 100644 index 000000000000..a2550b1958bf --- /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 9e5c011df708..f999eca745e0 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 c90859592b92..cb96e48507e3 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 ab2e2f863b88..e08501961de7 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 6bc42f15ebc6..9ced231648c3 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 2ff9e5784f14..0dfa7eb2f750 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 2416bf6c97d5..50716f030dfc 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*/) { |