summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2013-10-22 23:30:26 +0300
committerTor Lillqvist <tml@collabora.com>2013-10-23 00:19:20 +0300
commit54ef5bd641ef5c6938b591697115d63af381ebc3 (patch)
tree714690adf71ad9cd358352da0de70eaf28e0d8fd
parent025bd0fab4cd8e4f90c362ec03b51c23e0a55655 (diff)
More work on selection handling in iOS
Got the selection start and end handle dragging working... The trick was not to call SwWrtShell::SetCursor(), but SwCrsrShell::SetCrsr(). Sounds easy but took a lot of guessing and experimentation to figure out. Anyway, now it does what I had expected it to do a few das ago already. There are glitches, especially in corner cases like if you move the start handle past the end handle or vice versa. more Change-Id: Id6c1d99a4052531789bccf0d48165cfb41b89cfe 9b94c0dd55b04a7b6b3c40654562a9c51fa9b450
-rw-r--r--include/touch/touch-impl.h4
-rw-r--r--include/touch/touch.h7
-rw-r--r--ios/experimental/LibreOffice/LibreOffice/View.m48
-rw-r--r--sw/source/core/crsr/viscrs.cxx58
-rw-r--r--sw/source/ui/docvw/edtwin.cxx31
-rw-r--r--vcl/inc/ios/iosinst.hxx6
-rw-r--r--vcl/ios/iosinst.cxx26
7 files changed, 117 insertions, 63 deletions
diff --git a/include/touch/touch-impl.h b/include/touch/touch-impl.h
index a2550b1958bf..f786f44c8e42 100644
--- a/include/touch/touch-impl.h
+++ b/include/touch/touch-impl.h
@@ -20,6 +20,10 @@ extern "C" {
// "Implementation" of touch_lo_* functions, called on the LO thread through
// the PostUserEvent mechanism. Not called by UI thread code.
+void touch_lo_selection_start_move_impl(const void *documentHandle,
+ int x,
+ int y);
+
void touch_lo_selection_end_move_impl(const void *documentHandle,
int x,
int y);
diff --git a/include/touch/touch.h b/include/touch/touch.h
index f999eca745e0..7dddaf36eb8c 100644
--- a/include/touch/touch.h
+++ b/include/touch/touch.h
@@ -113,9 +113,12 @@ 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 start of the selection to (x,y)
+void touch_lo_selection_start_move(const void *documentHandle,
+ int x,
+ int y);
+
// 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);
diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m
index cb96e48507e3..3a9b35bdbdd4 100644
--- a/ios/experimental/LibreOffice/LibreOffice/View.m
+++ b/ios/experimental/LibreOffice/LibreOffice/View.m
@@ -154,71 +154,59 @@
- (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer
{
+ const int N = self.selectionRectangleCount;
+
static enum { NONE, TOPLEFT, BOTTOMRIGHT } draggedHandle = NONE;
- static CGFloat previousX, previousY;
+ static CGPoint previous;
+ static CGPoint dragOffset;
CGPoint location = [gestureRecognizer locationInView:self];
CGPoint translation = [gestureRecognizer translationInView:self];
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
- previousX = previousY = 0;
+ previous = CGPointMake(0, 0);
}
CGPoint delta;
- delta.x = translation.x - previousX;
- delta.y = translation.y - previousY;
+ delta.x = translation.x - previous.x;
+ delta.y = translation.y - previous.y;
// NSLog(@"location: (%f,%f) , drag: (%f,%f)", location.x, location.y, delta.x, delta.y);
- previousX = translation.x;
- previousY = translation.y;
+ previous = translation;
if (gestureRecognizer.state == UIGestureRecognizerStateBegan &&
gestureRecognizer.numberOfTouches == 1) {
if (CGRectContainsPoint([self topLeftResizeHandle], location)) {
NSLog(@"===> dragging TOPLEFT handle");
draggedHandle = TOPLEFT;
+ dragOffset.x = location.x - self.selectionRectangles[0].origin.x;
+ dragOffset.y = location.y - self.selectionRectangles[0].origin.y;
} else if (CGRectContainsPoint([self bottomRightResizeHandle], location)) {
NSLog(@"===> dragging BOTTOMRIGHT handle");
draggedHandle = BOTTOMRIGHT;
+ dragOffset.x = location.x - self.selectionRectangles[N-1].origin.x;
+ dragOffset.y = location.y - self.selectionRectangles[N-1].origin.y;
}
}
if (draggedHandle == TOPLEFT) {
- const int N = self.selectionRectangleCount;
- CGPoint old = self.selectionRectangles[0].origin;
+ touch_lo_selection_start_move(self.documentHandle,
+ location.x - dragOffset.x, location.y - dragOffset.y);
- 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((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);
- 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) {
- touch_lo_selection_end_move(self.documentHandle, location.x, location.y);
+ touch_lo_selection_end_move(self.documentHandle,
+ location.x - dragOffset.x, location.y - dragOffset.y);
if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
draggedHandle = NONE;
+
return;
}
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 432a93b25c09..e766fa5a42f9 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -262,36 +262,8 @@ void SwSelPaintRects::Show()
mpCursorOverlay = 0;
}
}
-#else
- if (false)
- ;
-#endif
else if(!empty())
{
-#if !HAVE_FEATURE_DESKTOP
-#ifdef IOS
- const OutputDevice* pOut = GetShell()->GetWin();
- if ( ! pOut )
- pOut = GetShell()->GetOut();
- SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(const_cast<SwCrsrShell*>(GetShell()));
- if ( pWrtShell )
- {
- // 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);
- }
-#else
- // Not yet implemented
-#endif
-#else
SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
rtl::Reference< ::sdr::overlay::OverlayManager > xTargetOverlay = pCandidate->GetOverlayManager();
@@ -310,8 +282,38 @@ void SwSelPaintRects::Show()
xTargetOverlay->add(*mpCursorOverlay);
}
+ }
+#else
+ const OutputDevice* pOut = GetShell()->GetWin();
+ if ( ! pOut )
+ pOut = GetShell()->GetOut();
+ SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(const_cast<SwCrsrShell*>(GetShell()));
+ if (!empty())
+ {
+ if (pWrtShell)
+ {
+ // Buffer will be deallocated in the UI layer
+ MLORect *rects = (MLORect *) malloc((sizeof(MLORect))*size());
+ for (size_t i = 0; i < size(); ++i)
+ {
+ Point origin = pOut->LogicToPixel((*this)[i].Pos());
+ Size size = pOut->LogicToPixel((*this)[i].SSize());
+#ifdef IOS
+ rects[i] = CGRectMake(origin.X(), origin.Y(),
+ size.Width(), size.Height());
+#else
+ // Not yet implemented
#endif
+ }
+ // GetShell returns a SwCrsrShell which actually is a SwWrtShell
+ touch_ui_selection_start(MLOSelectionText, pWrtShell, rects, size(), NULL);
+ }
+ }
+ else
+ {
+ touch_ui_selection_none();
}
+#endif
}
}
diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx
index 62c5bb1d8444..d6bd8dbb2bd5 100644
--- a/sw/source/ui/docvw/edtwin.cxx
+++ b/sw/source/ui/docvw/edtwin.cxx
@@ -2688,6 +2688,33 @@ static bool lcl_urlOverBackground(SwWrtShell& rSh, const Point& rDocPos)
#if !HAVE_FEATURE_DESKTOP
+void touch_lo_selection_start_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) ) );
+
+ pWrtShell->ChgCurrPam( aDocPos );
+
+ // Keep mark normally at the start and point at the end,
+ // just exchange for the duration of moving the start.
+ pWrtShell->GetCrsr()->Exchange();
+ {
+ SwMvContext aMvContext( pWrtShell );
+ pWrtShell->SwCrsrShell::SetCrsr( aDocPos );
+ }
+ pWrtShell->GetCrsr()->Exchange();
+}
+
void touch_lo_selection_end_move_impl(const void *documentHandle,
int x,
int y)
@@ -2703,13 +2730,11 @@ void touch_lo_selection_end_move_impl(const void *documentHandle,
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 );
+ pWrtShell->SwCrsrShell::SetCrsr( aDocPos );
}
}
diff --git a/vcl/inc/ios/iosinst.hxx b/vcl/inc/ios/iosinst.hxx
index 0dfa7eb2f750..58f0648007b4 100644
--- a/vcl/inc/ios/iosinst.hxx
+++ b/vcl/inc/ios/iosinst.hxx
@@ -65,6 +65,12 @@ public:
typedef struct {
const void *documentHandle;
int x, y;
+ } SelectionStartMoveArg;
+ DECL_LINK( SelectionStartMove, SelectionStartMoveArg* );
+
+ typedef struct {
+ const void *documentHandle;
+ int x, y;
} SelectionEndMoveArg;
DECL_LINK( SelectionEndMove, SelectionEndMoveArg* );
diff --git a/vcl/ios/iosinst.cxx b/vcl/ios/iosinst.cxx
index 50716f030dfc..ccec3f7d08cb 100644
--- a/vcl/ios/iosinst.cxx
+++ b/vcl/ios/iosinst.cxx
@@ -508,6 +508,32 @@ void touch_lo_keyboard_did_hide()
}
}
+IMPL_LINK( IosSalInstance, SelectionStartMove, SelectionStartMoveArg*, pArg )
+{
+ touch_lo_selection_start_move_impl(pArg->documentHandle, pArg->x, pArg->y);
+
+ delete pArg;
+
+ return 0;
+}
+
+extern "C"
+void touch_lo_selection_start_move(const void *documentHandle,
+ int x,
+ int y)
+{
+ IosSalInstance *pInstance = IosSalInstance::getInstance();
+
+ if ( pInstance == NULL )
+ return;
+
+ IosSalInstance::SelectionStartMoveArg *pArg = new IosSalInstance::SelectionStartMoveArg;
+ pArg->documentHandle = documentHandle;
+ pArg->x = x;
+ pArg->y = y;
+ Application::PostUserEvent( LINK( pInstance, IosSalInstance, SelectionStartMove), pArg );
+}
+
IMPL_LINK( IosSalInstance, SelectionEndMove, SelectionEndMoveArg*, pArg )
{
touch_lo_selection_end_move_impl(pArg->documentHandle, pArg->x, pArg->y);