Mercurial > projects > dwt-win
diff dwt/custom/StyledTextDropTargetEffect.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | a5afe31f5cdd |
children | fd9c62a2998e |
line wrap: on
line diff
--- a/dwt/custom/StyledTextDropTargetEffect.d Mon May 05 00:12:38 2008 +0200 +++ b/dwt/custom/StyledTextDropTargetEffect.d Sat May 17 17:34:28 2008 +0200 @@ -18,6 +18,8 @@ import dwt.dnd.DropTargetAdapter; import dwt.dnd.DropTargetEffect; import dwt.dnd.DropTargetEvent; +import dwt.graphics.FontMetrics; +import dwt.graphics.GC; import dwt.graphics.Point; import dwt.graphics.Rectangle; import dwt.widgets.Event; @@ -31,7 +33,7 @@ /** * This adapter class provides a default drag under effect (eg. select and scroll) - * when a drag occurs over a <code>Table</code>. + * when a drag occurs over a <code>StyledText</code>. * * <p>Classes that wish to provide their own drag under effect for a <code>StyledText</code> * can extend this class, override the <code>StyledTextDropTargetEffect.dragOver</code> @@ -172,37 +174,27 @@ 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() !is leftPixel) { - text.redraw(); - } } if (pt.x > area.width - 3*charWidth) { int leftPixel = text.getHorizontalPixel(); text.setHorizontalPixel(leftPixel + scrollAmount); - if (text.getHorizontalPixel() !is 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() !is topPixel) { - text.redraw(); - } } if (pt.y > area.height - lineHeight) { int topPixel = text.getTopPixel(); text.setTopPixel(topPixel + lineHeight); - if (text.getTopPixel() !is topPixel) { - text.redraw(); - } } scrollBeginTime = 0; scrollX = scrollY = -1; @@ -216,53 +208,10 @@ } if ((effect & DND.FEEDBACK_SELECT) !is 0) { - StyledTextContent content = text.getContent(); - int newOffset = -1; - try { - newOffset = text.getOffsetAtLocation(pt); - } catch ( tango.core.Exception.IllegalArgumentException ex1) { - int maxOffset = content.getCharCount(); - Point maxLocation = text.getLocationAtOffset(maxOffset); - if (pt.y >= maxLocation.y) { - try { - newOffset = text.getOffsetAtLocation(new Point(pt.x, maxLocation.y)); - } catch (tango.core.Exception.IllegalArgumentException ex2) { - newOffset = maxOffset; - } - } else { - try { - int startOffset = text.getOffsetAtLocation(new Point(0, pt.y)); - int endOffset = maxOffset; - int line = content.getLineAtOffset(startOffset); - int lineCount = content.getLineCount(); - if (line + 1 < lineCount) { - endOffset = content.getOffsetAtLine(line + 1) - 1; - } - int lineHeight = text.getLineHeight(startOffset); - for (int i = endOffset; i >= startOffset; i--) { - Point p = text.getLocationAtOffset(i); - if (p.x < pt.x && p.y < pt.y && p.y + lineHeight > pt.y) { - newOffset = i; - break; - } - } - } catch (tango.core.Exception.IllegalArgumentException ex2) { - newOffset = -1; - } - } - } - if (newOffset !is -1 && newOffset !is currentOffset) { - // check if offset is line delimiter - // see StyledText.isLineDelimiter() - int line = content.getLineAtOffset(newOffset); - int lineOffset = content.getOffsetAtLine(line); - int offsetInLine = newOffset - lineOffset; - // offsetInLine will be greater than line length if the line - // delimiter is longer than one character and the offset is set - // in between parts of the line delimiter. - if (offsetInLine > content.getLine(line).length) { - newOffset = Math.max(0, newOffset - 1); - } + int[] trailing = new int [1]; + int newOffset = text.getOffsetAtPoint(pt.x, pt.y, trailing, false); + newOffset += trailing [0]; + if (newOffset !is currentOffset) { refreshCaret(text, currentOffset, newOffset); currentOffset = newOffset; }