Show
Ignore:
Timestamp:
05/17/08 11:34:28 (8 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Update to SWT 3.4M7

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/custom/StyledTextDropTargetEffect.d

    r155 r213  
    1919import dwt.dnd.DropTargetEffect; 
    2020import dwt.dnd.DropTargetEvent; 
     21import dwt.graphics.FontMetrics; 
     22import dwt.graphics.GC; 
    2123import dwt.graphics.Point; 
    2224import dwt.graphics.Rectangle; 
     
    3234/** 
    3335 * This adapter class provides a default drag under effect (eg. select and scroll) 
    34  * when a drag occurs over a <code>Table</code>. 
     36 * when a drag occurs over a <code>StyledText</code>. 
    3537 * 
    3638 * <p>Classes that wish to provide their own drag under effect for a <code>StyledText</code> 
     
    173175                    if (System.currentTimeMillis() >= scrollBeginTime) { 
    174176                        Rectangle area = text.getClientArea(); 
    175                         Rectangle bounds = text.getTextBounds(0, 0); 
    176                         int charWidth = bounds.width; 
     177                        GC gc = new GC(text); 
     178                        FontMetrics fm = gc.getFontMetrics(); 
     179                        gc.dispose(); 
     180                        int charWidth = fm.getAverageCharWidth(); 
    177181                        int scrollAmount = 10*charWidth; 
    178182                        if (pt.x < area.x + 3*charWidth) { 
    179183                            int leftPixel = text.getHorizontalPixel(); 
    180184                            text.setHorizontalPixel(leftPixel - scrollAmount); 
    181                             if (text.getHorizontalPixel() !is leftPixel) { 
    182                                 text.redraw(); 
    183                             } 
    184185                        } 
    185186                        if (pt.x > area.width - 3*charWidth) { 
    186187                            int leftPixel = text.getHorizontalPixel(); 
    187188                            text.setHorizontalPixel(leftPixel + scrollAmount); 
    188                             if (text.getHorizontalPixel() !is leftPixel) { 
    189                                 text.redraw(); 
    190                             } 
    191                         } 
    192                         int lineHeight = bounds.height; 
     189                        } 
     190                        int lineHeight = text.getLineHeight(); 
    193191                        if (pt.y < area.y + lineHeight) { 
    194192                            int topPixel = text.getTopPixel(); 
    195193                            text.setTopPixel(topPixel - lineHeight); 
    196                             if (text.getTopPixel() !is topPixel) { 
    197                                 text.redraw(); 
    198                             } 
    199194                        } 
    200195                        if (pt.y > area.height - lineHeight) { 
    201196                            int topPixel = text.getTopPixel(); 
    202197                            text.setTopPixel(topPixel + lineHeight); 
    203                             if (text.getTopPixel() !is topPixel) { 
    204                                 text.redraw(); 
    205                             } 
    206198                        } 
    207199                        scrollBeginTime = 0; 
     
    217209 
    218210        if ((effect & DND.FEEDBACK_SELECT) !is 0) { 
    219             StyledTextContent content = text.getContent(); 
    220             int newOffset = -1; 
    221             try { 
    222                 newOffset = text.getOffsetAtLocation(pt); 
    223             } catch ( tango.core.Exception.IllegalArgumentException ex1) { 
    224                 int maxOffset = content.getCharCount(); 
    225                 Point maxLocation = text.getLocationAtOffset(maxOffset); 
    226                 if (pt.y >= maxLocation.y) { 
    227                     try { 
    228                         newOffset = text.getOffsetAtLocation(new Point(pt.x, maxLocation.y)); 
    229                     } catch (tango.core.Exception.IllegalArgumentException ex2) { 
    230                         newOffset = maxOffset; 
    231                     } 
    232                 } else { 
    233                     try { 
    234                         int startOffset = text.getOffsetAtLocation(new Point(0, pt.y)); 
    235                         int endOffset = maxOffset; 
    236                         int line = content.getLineAtOffset(startOffset); 
    237                         int lineCount = content.getLineCount(); 
    238                         if (line + 1 < lineCount) { 
    239                             endOffset = content.getOffsetAtLine(line + 1)  - 1; 
    240                         } 
    241                         int lineHeight = text.getLineHeight(startOffset); 
    242                         for (int i = endOffset; i >= startOffset; i--) { 
    243                             Point p = text.getLocationAtOffset(i); 
    244                             if (p.x < pt.x && p.y < pt.y && p.y + lineHeight > pt.y) { 
    245                                 newOffset = i; 
    246                                 break; 
    247                             } 
    248                         } 
    249                     } catch (tango.core.Exception.IllegalArgumentException ex2) { 
    250                         newOffset = -1; 
    251                     } 
    252                 } 
    253             } 
    254             if (newOffset !is -1 && newOffset !is currentOffset) { 
    255                 // check if offset is line delimiter 
    256                 // see StyledText.isLineDelimiter() 
    257                 int line = content.getLineAtOffset(newOffset); 
    258                 int lineOffset = content.getOffsetAtLine(line); 
    259                 int offsetInLine = newOffset - lineOffset; 
    260                 // offsetInLine will be greater than line length if the line 
    261                 // delimiter is longer than one character and the offset is set 
    262                 // in between parts of the line delimiter. 
    263                 if (offsetInLine > content.getLine(line).length) { 
    264                     newOffset = Math.max(0, newOffset - 1); 
    265                 } 
     211            int[] trailing = new int [1]; 
     212            int newOffset = text.getOffsetAtPoint(pt.x, pt.y, trailing, false); 
     213            newOffset += trailing [0]; 
     214            if (newOffset !is currentOffset) { 
    266215                refreshCaret(text, currentOffset, newOffset); 
    267216                currentOffset = newOffset;