libreofficekit/source/gtk/lokdocview.cxx | 25 +++++++++++++----- sw/qa/extras/tiledrendering/tiledrendering.cxx | 5 +++ sw/source/uibase/docvw/edtwin.cxx | 33 +++++++++++++++++-------- 3 files changed, 46 insertions(+), 17 deletions(-)
New commits: commit f1d86fc7af53e7bdba9c00df1abd791e92f3321e Author: Miklos Vajna <[email protected]> Date: Fri May 15 10:13:53 2015 +0200 lokdocview: implement desktop style click+move selection creation Change-Id: I69663c0801bc95b8876c8dcbdf68d7a99fec4fb3 diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 00f4f4b..35ce543 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -103,6 +103,9 @@ struct LOKDocView_Impl bool m_bInDragGraphicHandles[8]; ///@} + /// If text selection is adjusted -> then mouse up event is a NOP. + bool m_bTextSelectionAdjusted; + /// Callback data, allocated in lok_docview_callback_worker(), released in lok_docview_callback(). struct CallbackData { @@ -222,8 +225,8 @@ LOKDocView_Impl::LOKDocView_Impl(LOKDocView* pDocView) m_pHandleEnd(0), m_aHandleEndRect({0, 0, 0, 0}), m_bInDragEndHandle(false), - - m_pGraphicHandle(0) + m_pGraphicHandle(0), + m_bTextSelectionAdjusted(false) { memset(&m_aGraphicHandleRects, 0, sizeof(m_aGraphicHandleRects)); memset(&m_bInDragGraphicHandles, 0, sizeof(m_bInDragGraphicHandles)); @@ -415,16 +418,20 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent) if ((pEvent->time - m_nLastButtonPressTime) < 250) nCount++; m_nLastButtonPressTime = pEvent->time; + m_bTextSelectionAdjusted = false; m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount); break; } case GDK_BUTTON_RELEASE: { - int nCount = 1; - if ((pEvent->time - m_nLastButtonReleaseTime) < 250) - nCount++; - m_nLastButtonReleaseTime = pEvent->time; - m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount); + if (!m_bTextSelectionAdjusted) + { + int nCount = 1; + if ((pEvent->time - m_nLastButtonReleaseTime) < 250) + nCount++; + m_nLastButtonReleaseTime = pEvent->time; + m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount); + } break; } default: @@ -505,6 +512,10 @@ gboolean LOKDocView_Impl::signalMotionImpl(GdkEventButton* pEvent) return FALSE; } + // Otherwise adjust the text selection, as on the desktop. + m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_END, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y)); + m_bTextSelectionAdjusted = true; + return FALSE; } commit 3de68db1cd69627f4e529e5621eb97a8ea898aa3 Author: Miklos Vajna <[email protected]> Date: Fri May 15 09:58:25 2015 +0200 SwEditWin::SetCursorTwipPosition: support creating a selection The Android LOK client always creates a text selection by double clicking on a word, and then the start/end of the selection can be adjusted using handles. In the GTK LOK client, it makes sense to allow the desktop-style selection, where you click somewhere, move the mouse and finally release the mouse to create a selection. That can be mapped to settextselect-reset on mouse-down, and settextselect-end on mouse-move easily. The only problem was that SetCursorTwipPosition() assumed that there is a selection already -- fix that by adding the missing Stt/EndSelect() calls and limiting the lifetime of the SwMvContext instance. Change-Id: Iaeeadd8e4d9030614ee069b9fcfa269ce74ed58a diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 67c04db..b42f05c 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -163,6 +163,11 @@ void SwTiledRenderingTest::testSetTextSelection() pXTextDocument->setTextSelection(LOK_SETTEXTSELECTION_START, aStart.getX(), aStart.getY()); // The new selection must include the first word, too -- but not the ending dot. CPPUNIT_ASSERT_EQUAL(OUString("Aaa bbb"), pShellCrsr->GetTxt()); + + // Next: test that LOK_SETTEXTSELECTION_RESET + LOK_SETTEXTSELECTION_END can be used to create a selection. + pXTextDocument->setTextSelection(LOK_SETTEXTSELECTION_RESET, aStart.getX(), aStart.getY()); + pXTextDocument->setTextSelection(LOK_SETTEXTSELECTION_END, aStart.getX() + 1000, aStart.getY()); + CPPUNIT_ASSERT_EQUAL(OUString("Aaa b"), pShellCrsr->GetTxt()); } void SwTiledRenderingTest::testSetGraphicSelection() diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index fe41345..7a5d711 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -6247,16 +6247,29 @@ void SwEditWin::SetCursorTwipPosition(const Point& rPosition, bool bPoint, bool // Not an SwWrtShell, as that would make SwCrsrShell::GetCrsr() inaccessible. SwEditShell& rShell = m_rView.GetWrtShell(); - SwMvContext aMvContext(&rShell); - if (bClearMark) - rShell.ClearMark(); - // If the mark is to be updated, then exchange the point and mark before - // and after, as we can't easily set the mark. - if (!bPoint) - rShell.getShellCrsr(/*bBlock=*/false)->Exchange(); - rShell.SetCrsr(rPosition); - if (!bPoint) - rShell.getShellCrsr(/*bBlock=*/false)->Exchange(); + + bool bCreateSelection = false; + { + SwMvContext aMvContext(&rShell); + if (bClearMark) + rShell.ClearMark(); + else + bCreateSelection = !rShell.HasMark(); + + if (bCreateSelection) + m_rView.GetWrtShell().SttSelect(); + + // If the mark is to be updated, then exchange the point and mark before + // and after, as we can't easily set the mark. + if (!bPoint) + rShell.getShellCrsr(/*bBlock=*/false)->Exchange(); + rShell.SetCrsr(rPosition); + if (!bPoint) + rShell.getShellCrsr(/*bBlock=*/false)->Exchange(); + } + + if (bCreateSelection) + m_rView.GetWrtShell().EndSelect(); } void SwEditWin::SetGraphicTwipPosition(bool bStart, const Point& rPosition) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
