I'm looking for help/explanation about the coordinate system and scrolling API to use in `SwAccessibleParagraph'. I'm currently working on bug #118418 [1], trying to implement scrollSubstringTo() and scrollSubstringToPoint() like I did for gtk [2] and evince [3]. The diff below clearly shows that I don't know how to translate a character index to coordinates that can be feed to Window's Scroll(). So here are my questions: - Is calling getWindow()'s Scroll() the correct way to realize the scrolling. If so, the code below doesn't correctly refresh all the text, so what am I missing? - What API should I use to convert the coordinates? Thanks in advance, Martin [1] https://bugs.documentfoundation.org/show_bug.cgi?id=118418 [2] https://gitlab.gnome.org/GNOME/gtk/merge_requests/1120 [3] https://gitlab.gnome.org/GNOME/evince/merge_requests/193 diff --git sw/source/core/access/accpara.cxx sw/source/core/access/accpara.cxx index 1b4b7fd5af62..250463929fcf 100644 --- sw/source/core/access/accpara.cxx +++ sw/source/core/access/accpara.cxx @@ -34,6 +34,7 @@ #include <vcl/window.hxx> #include <sal/log.hxx> #include <com/sun/star/accessibility/AccessibleRole.hpp> +#include <com/sun/star/accessibility/AccessibleScrollType.hpp> #include <com/sun/star/accessibility/AccessibleStateType.hpp> #include <com/sun/star/accessibility/AccessibleTextType.hpp> #include <com/sun/star/accessibility/AccessibleEventId.hpp> @@ -2492,8 +2493,81 @@ sal_Bool SwAccessibleParagraph::copyText( sal_Int32 nStartIndex, sal_Int32 nEndI sal_Bool SwAccessibleParagraph::scrollSubstringTo( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int16 aScrollType ) { - fprintf(stderr, "%s: AccPara start=%u, end=%u, type=%d\n", __func__, nStartIndex, nEndIndex, aScrollType); - return false; + SolarMutexGuard aGuard; + + ThrowIfDisposed(); + + // parameter checking + sal_Int32 nLength = GetString().getLength(); + if ( ! IsValidRange( nStartIndex, nEndIndex, nLength ) ) + throw lang::IndexOutOfBoundsException(); + + fprintf(stderr, "%s: start=%u, end=%u, length=%d\n", __func__, nStartIndex, nEndIndex, nLength); + + vcl::Window *pWin = GetWindow(); + if ( ! pWin ) + throw uno::RuntimeException("no Window", static_cast<cppu::OWeakObject*>(this)); + + // WTF + MapMode aMap = pWin->GetMapMode(); + Point aOrg = aMap.GetOrigin(); + fprintf(stderr, "%s: orgX=%ld, orgY=%ld\n", __func__, aOrg.X(), aOrg.Y()); + + + // TEST 2 + SwRect aLogBounds( GetBounds( *(GetMap()), GetFrame() ) ); + Point aPoint( GetMap()->CoreToPixel( aLogBounds.SVRect() ).TopLeft() ); + Point aCorePoint( GetMap()->PixelToCore( aPoint ) ); + fprintf(stderr, "%s: point=%ld,%ld core=%ld,%ld\n", __func__, aPoint.getX(), + aPoint.getY(), aCorePoint.getX(), aCorePoint.getY()); + + + // getCharacterBounds() + awt::Rectangle startR, endR; + startR = getCharacterBounds(nStartIndex); + endR = getCharacterBounds(nEndIndex); + fprintf(stderr, "%s: start=%d,%d end=%d,%d\n", __func__, startR.X, startR.Y, + endR.X, endR.Y); + + Point startPoint = GetMap()->PixelToCore( Point( startR.X, startR.Y ) ); + Point endPoint = GetMap()->PixelToCore( Point( endR.X, endR.Y ) ); + fprintf(stderr, "%s: sP=%d,%d eP=%d,%d\n", __func__, startPoint.getX(), + startPoint.getY(), endPoint.getX(), endPoint.getY()); + + switch (aScrollType) + { + case AccessibleScrollType::SCROLL_TOP_LEFT: + break; + case AccessibleScrollType::SCROLL_BOTTOM_RIGHT: + break; + case AccessibleScrollType::SCROLL_TOP_EDGE: + break; + case AccessibleScrollType::SCROLL_BOTTOM_EDGE: + break; + case AccessibleScrollType::SCROLL_LEFT_EDGE: + break; + case AccessibleScrollType::SCROLL_RIGHT_EDGE: + break; + case AccessibleScrollType::SCROLL_ANYWHERE: + break; + default: + return false; + } + fprintf(stderr, "%s: type=%d\n", __func__, aScrollType); + + long nX, nY; + nX = startPoint.getX(); + nY = startPoint.getY(); + + pWin->Update(); // Needed? + + // TOP LEFT + pWin->Scroll( -nX, -nY, ScrollFlags::Children ); + aMap.SetOrigin( Point( -nX, -nY ) ); + pWin->SetMapMode( aMap ); + pWin->Update(); + + return true; } sal_Bool SwAccessibleParagraph::scrollSubstringToPoint( sal_Int32 nStartIndex, _______________________________________________ LibreOffice mailing list LibreOffice@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/libreoffice