[Libreoffice-commits] core.git: Branch 'libreoffice-4-0' - sw/inc sw/source

Michael Stahl mstahl at redhat.com
Sun Sep 1 04:39:51 PDT 2013


 sw/inc/crstate.hxx                |    2 -
 sw/source/core/layout/trvlfrm.cxx |   45 +++++++++++++++++++++++++++++++++++---
 2 files changed, 43 insertions(+), 4 deletions(-)

New commits:
commit c1db93a0663e9346e165ac58ddeee018f30d35ff
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Aug 28 14:16:38 2013 +0200

    fdo#66215: sw: fix clicking on text above background fly
    
    SwPageFrm::GetCrsrOfst() tries to compare the distance to the closest
    text vs. fly but does not do it right because GetCharRect()
    returns just a line of width 1 on the left edge of the character;
    try to figure out the entire area covered by the character via 2 calls
    to GetCrsrOfst(), which gives much better clickability.
    
    (regression from e8fbe97900f13305b17015d9044993bde4adab36)
    
    Change-Id: I825e86daf65692dfb962ad576772c5f543d02d19
    (cherry picked from commit edd2db1c783bd571ff796a5298385cacc91877b9)
    Reviewed-on: https://gerrit.libreoffice.org/5662
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/inc/crstate.hxx b/sw/inc/crstate.hxx
index 6c8c86f..7bd3cb4 100644
--- a/sw/inc/crstate.hxx
+++ b/sw/inc/crstate.hxx
@@ -143,7 +143,7 @@ struct SwCrsrMoveState
     sal_Bool bRealWidth;            ///< Calculation of the width required
     sal_Bool b2Lines;               ///< Check 2line portions and fill p2Lines
     sal_Bool bNoScroll;             ///< No scrolling of undersized textframes
-    sal_Bool bPosMatchesBounds;     /**< GetCrsrOfst should not return the next
+    bool bPosMatchesBounds;         /**< GetCrsrOfst should not return the next
                                        position if screen position is inside second
                                        have of bound rect */
 
diff --git a/sw/source/core/layout/trvlfrm.cxx b/sw/source/core/layout/trvlfrm.cxx
index 443af12..51d3d13 100644
--- a/sw/source/core/layout/trvlfrm.cxx
+++ b/sw/source/core/layout/trvlfrm.cxx
@@ -19,6 +19,7 @@
 
 #include <hintids.hxx>
 #include <hints.hxx>
+#include <comphelper/flagguard.hxx>
 #include <tools/bigint.hxx>
 #include <tools/line.hxx>
 #include <editeng/opaqitem.hxx>
@@ -283,10 +284,48 @@ sal_Bool SwPageFrm::GetCrsrOfst( SwPosition *pPos, Point &rPoint,
             if ( pTextNd )
             {
                 SwCntntFrm* pTextFrm = pTextNd->getLayoutFrm( getRootFrm( ) );
-                SwRect rTextRect;
-                pTextFrm->GetCharRect( rTextRect, aTextPos );
 
-                nTextDistance = lcl_getDistance( rTextRect, rPoint );
+                // try this again but prefer the "previous" position
+                SwCrsrMoveState aMoveState;
+                SwCrsrMoveState *const pState((pCMS) ? pCMS : &aMoveState);
+                comphelper::FlagRestorationGuard g(
+                        pState->bPosMatchesBounds, true);
+                SwPosition prevTextPos(*pPos);
+                SwLayoutFrm::GetCrsrOfst(&prevTextPos, aPoint, pState);
+
+                SwRect aTextRect;
+                pTextFrm->GetCharRect(aTextRect, prevTextPos);
+
+                if (prevTextPos.nContent < pTextNd->Len())
+                {
+                    // aRextRect is just a line on the left edge of the
+                    // previous character; to get a better measure from
+                    // lcl_getDistance, extend that to a rectangle over
+                    // the entire character.
+                    SwPosition const nextTextPos(prevTextPos.nNode,
+                            SwIndex(prevTextPos.nContent, +1));
+                    SwRect nextTextRect;
+                    pTextFrm->GetCharRect(nextTextRect, nextTextPos);
+                    SWRECTFN(pTextFrm);
+                    if ((aTextRect.*fnRect->fnGetTop)() ==
+                        (nextTextRect.*fnRect->fnGetTop)()) // same line?
+                    {
+                        // need to handle mixed RTL/LTR portions somehow
+                        if ((aTextRect.*fnRect->fnGetLeft)() <
+                            (nextTextRect.*fnRect->fnGetLeft)())
+                        {
+                            (aTextRect.*fnRect->fnSetRight)(
+                                    (nextTextRect.*fnRect->fnGetLeft)());
+                        }
+                        else // RTL
+                        {
+                            (aTextRect.*fnRect->fnSetLeft)(
+                                    (nextTextRect.*fnRect->fnGetLeft)());
+                        }
+                    }
+                }
+
+                nTextDistance = lcl_getDistance(aTextRect, rPoint);
                 bValidTextDistance = true;
             }
 


More information about the Libreoffice-commits mailing list