Changeset 213:36f5cb12e1a2 for dwt/custom/StyledTextDropTargetEffect.d
- Timestamp:
- 05/17/08 11:34:28 (8 months ago)
- Files:
-
- dwt/custom/StyledTextDropTargetEffect.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/custom/StyledTextDropTargetEffect.d
r155 r213 19 19 import dwt.dnd.DropTargetEffect; 20 20 import dwt.dnd.DropTargetEvent; 21 import dwt.graphics.FontMetrics; 22 import dwt.graphics.GC; 21 23 import dwt.graphics.Point; 22 24 import dwt.graphics.Rectangle; … … 32 34 /** 33 35 * 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>. 35 37 * 36 38 * <p>Classes that wish to provide their own drag under effect for a <code>StyledText</code> … … 173 175 if (System.currentTimeMillis() >= scrollBeginTime) { 174 176 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(); 177 181 int scrollAmount = 10*charWidth; 178 182 if (pt.x < area.x + 3*charWidth) { 179 183 int leftPixel = text.getHorizontalPixel(); 180 184 text.setHorizontalPixel(leftPixel - scrollAmount); 181 if (text.getHorizontalPixel() !is leftPixel) {182 text.redraw();183 }184 185 } 185 186 if (pt.x > area.width - 3*charWidth) { 186 187 int leftPixel = text.getHorizontalPixel(); 187 188 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(); 193 191 if (pt.y < area.y + lineHeight) { 194 192 int topPixel = text.getTopPixel(); 195 193 text.setTopPixel(topPixel - lineHeight); 196 if (text.getTopPixel() !is topPixel) {197 text.redraw();198 }199 194 } 200 195 if (pt.y > area.height - lineHeight) { 201 196 int topPixel = text.getTopPixel(); 202 197 text.setTopPixel(topPixel + lineHeight); 203 if (text.getTopPixel() !is topPixel) {204 text.redraw();205 }206 198 } 207 199 scrollBeginTime = 0; … … 217 209 218 210 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) { 266 215 refreshCaret(text, currentOffset, newOffset); 267 216 currentOffset = newOffset;
