From 4a3bc808f901fc912cb07ed81b640170056cb41c Mon Sep 17 00:00:00 2001 From: Felipe Heidrich Date: Thu, 13 Sep 2007 16:33:44 +0000 Subject: Bug 149576 [DnD] StyledText auto-scroll does not work if first line is empty --- .../swt/custom/StyledTextDropTargetEffect.java | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse') diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextDropTargetEffect.java index 4af30cb234..9761630761 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextDropTargetEffect.java @@ -158,37 +158,27 @@ public class StyledTextDropTargetEffect extends DropTargetEffect { pt.y >= scrollY && pt.y <= (scrollY + SCROLL_TOLERANCE))) { if (System.currentTimeMillis() >= scrollBeginTime) { Rectangle area = text.getClientArea(); - Rectangle bounds = text.getTextBounds(0, 0); - int charWidth = bounds.width; + GC gc = new GC(text); + FontMetrics fm = gc.getFontMetrics(); + gc.dispose(); + int charWidth = fm.getAverageCharWidth(); int scrollAmount = 10*charWidth; if (pt.x < area.x + 3*charWidth) { int leftPixel = text.getHorizontalPixel(); text.setHorizontalPixel(leftPixel - scrollAmount); - if (text.getHorizontalPixel() != leftPixel) { - text.redraw(); - } } if (pt.x > area.width - 3*charWidth) { int leftPixel = text.getHorizontalPixel(); text.setHorizontalPixel(leftPixel + scrollAmount); - if (text.getHorizontalPixel() != leftPixel) { - text.redraw(); - } } - int lineHeight = bounds.height; + int lineHeight = text.getLineHeight(); if (pt.y < area.y + lineHeight) { int topPixel = text.getTopPixel(); text.setTopPixel(topPixel - lineHeight); - if (text.getTopPixel() != topPixel) { - text.redraw(); - } } if (pt.y > area.height - lineHeight) { int topPixel = text.getTopPixel(); text.setTopPixel(topPixel + lineHeight); - if (text.getTopPixel() != topPixel) { - text.redraw(); - } } scrollBeginTime = 0; scrollX = scrollY = -1; -- cgit