From 8eb3a3a923b1dc0dd736643e85ba2711d0ae3c6d Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 17 Jun 2007 17:52:40 +0000 Subject: [PATCH] when selecting text in wxHTML, selecting half a character is enough to select it (patch #1719530; this is standard behaviour when selecting text git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46506 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/html/htmlcell.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index d70af49a3a..e0ca15d66e 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -408,19 +408,26 @@ void wxHtmlWordCell::Split(const wxDC& dc, pt2.x = m_Width; // before selection: + // (include character under caret only if in first half of width) #ifdef __WXMAC__ // implementation using PartialExtents to support fractional widths wxArrayInt widths ; dc.GetPartialTextExtents(m_Word,widths) ; while( i < len && pt1.x >= widths[i] ) i++ ; -#else // __WXMAC__ + if ( i < len ) + { + int charW = (i > 0) ? widths[i] - widths[i-1] : widths[i]; + if ( widths[i] - pt1.x < charW/2 ) + i++; + } +#else // !__WXMAC__ wxCoord charW, charH; while ( pt1.x > 0 && i < len ) { dc.GetTextExtent(m_Word[i], &charW, &charH); pt1.x -= charW; - if ( pt1.x >= 0 ) + if ( pt1.x >= -charW/2 ) { pos1 += charW; i++; @@ -429,18 +436,25 @@ void wxHtmlWordCell::Split(const wxDC& dc, #endif // __WXMAC__/!__WXMAC__ // in selection: + // (include character under caret only if in first half of width) unsigned j = i; #ifdef __WXMAC__ while( j < len && pt2.x >= widths[j] ) j++ ; -#else // __WXMAC__ + if ( j < len ) + { + int charW = (j > 0) ? widths[j] - widths[j-1] : widths[j]; + if ( widths[j] - pt2.x < charW/2 ) + j++; + } +#else // !__WXMAC__ pos2 = pos1; pt2.x -= pos2; while ( pt2.x > 0 && j < len ) { dc.GetTextExtent(m_Word[j], &charW, &charH); pt2.x -= charW; - if ( pt2.x >= 0 ) + if ( pt2.x >= -charW/2 ) { pos2 += charW; j++; -- 2.45.2