Mercurial > projects > dwt-mac
comparison dwt/graphics/TextLayout.d @ 46:cfa563df4fdd
Updated Widget and Display to 3.514
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 05 Dec 2008 16:00:41 +0100 |
parents | d8635bb48c7c |
children | 62202ce0039f |
comparison
equal
deleted
inserted
replaced
45:d8635bb48c7c | 46:cfa563df4fdd |
---|---|
48 import dwt.graphics.Point; | 48 import dwt.graphics.Point; |
49 import dwt.graphics.Rectangle; | 49 import dwt.graphics.Rectangle; |
50 import dwt.graphics.Region; | 50 import dwt.graphics.Region; |
51 import dwt.graphics.Resource; | 51 import dwt.graphics.Resource; |
52 import dwt.graphics.TextStyle; | 52 import dwt.graphics.TextStyle; |
53 import dwt.internal.cocoa.CGFloat; | 53 import dwt.internal.c.Carbon; |
54 import dwt.internal.cocoa.NSInteger; | |
55 import dwt.internal.cocoa.NSText; | 54 import dwt.internal.cocoa.NSText; |
55 import dwt.internal.objc.cocoa.Cocoa; | |
56 | 56 |
57 /** | 57 /** |
58 * <code>TextLayout</code> is a graphic object that represents | 58 * <code>TextLayout</code> is a graphic object that represents |
59 * styled text. | 59 * styled text. |
60 * <p> | 60 * <p> |
205 paragraph.setTabStops(NSArray.array()); | 205 paragraph.setTabStops(NSArray.array()); |
206 if (tabs !is null) { | 206 if (tabs !is null) { |
207 int count = tabs.length; | 207 int count = tabs.length; |
208 for (int i = 0, pos = 0; i < count; i++) { | 208 for (int i = 0, pos = 0; i < count; i++) { |
209 pos += tabs[i]; | 209 pos += tabs[i]; |
210 NSTextTab tab = (NSTextTab)new NSTextTab().alloc(); | 210 NSTextTab tab = cast(NSTextTab)(new NSTextTab()).alloc(); |
211 tab = tab.initWithType(OS.NSLeftTabStopType, pos); | 211 tab = tab.initWithType(OS.NSLeftTabStopType, pos); |
212 paragraph.addTabStop(tab); | 212 paragraph.addTabStop(tab); |
213 tab.release(); | 213 tab.release(); |
214 } | 214 } |
215 int width = count - 2 >= 0 ? tabs[count - 1] - tabs[count - 2] : tabs[count - 1]; | 215 int width = count - 2 >= 0 ? tabs[count - 1] - tabs[count - 2] : tabs[count - 1]; |
219 //TODO ascend descent wrap | 219 //TODO ascend descent wrap |
220 | 220 |
221 textStorage.addAttribute(OS.NSParagraphStyleAttributeName, paragraph, range); | 221 textStorage.addAttribute(OS.NSParagraphStyleAttributeName, paragraph, range); |
222 paragraph.release(); | 222 paragraph.release(); |
223 | 223 |
224 int /*long*/ textLength = str.length(); | 224 NSUInteger textLength = str.length(); |
225 for (int i = 0; i < styles.length - 1; i++) { | 225 for (int i = 0; i < styles.length - 1; i++) { |
226 StyleItem run = styles[i]; | 226 StyleItem run = styles[i]; |
227 if (run.style is null) continue; | 227 if (run.style is null) continue; |
228 TextStyle style = run.style; | 228 TextStyle style = run.style; |
229 range.location = textLength !is 0 ? translateOffset(run.start) : 0; | 229 range.location = textLength !is 0 ? translateOffset(run.start) : 0; |
297 NSRect[] bounds = new NSRect[numberOfLines]; | 297 NSRect[] bounds = new NSRect[numberOfLines]; |
298 for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){ | 298 for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){ |
299 bounds[numberOfLines] = layoutManager.lineFragmentUsedRectForGlyphAtIndex(index, rangePtr, true); | 299 bounds[numberOfLines] = layoutManager.lineFragmentUsedRectForGlyphAtIndex(index, rangePtr, true); |
300 if (numberOfLines < bounds.length - 1) bounds[numberOfLines].height -= spacing; | 300 if (numberOfLines < bounds.length - 1) bounds[numberOfLines].height -= spacing; |
301 OS.memmove(&lineRange, rangePtr, NSRange.sizeof); | 301 OS.memmove(&lineRange, rangePtr, NSRange.sizeof); |
302 offsets[numberOfLines] = (int)/*64*/lineRange.location; | 302 offsets[numberOfLines] = cast(int)/*64*/lineRange.location; |
303 index = lineRange.location + lineRange.length; | 303 index = lineRange.location + lineRange.length; |
304 } | 304 } |
305 if (numberOfLines is 0) { | 305 if (numberOfLines is 0) { |
306 Font font = this.font !is null ? this.font : device.systemFont; | 306 Font font = this.font !is null ? this.font : device.systemFont; |
307 NSFont nsFont = font.handle; | 307 NSFont nsFont = font.handle; |
308 bounds[0] = NSRect(); | 308 bounds[0] = NSRect(); |
309 bounds[0].height = Math.max(layoutManager.defaultLineHeightForFont(nsFont), ascent + descent); | 309 bounds[0].height = Math.max(layoutManager.defaultLineHeightForFont(nsFont), ascent + descent); |
310 } | 310 } |
311 OS.free(rangePtr); | 311 OS.free(rangePtr); |
312 offsets[numberOfLines] = (int)/*64*/textStorage.length(); | 312 offsets[numberOfLines] = cast(int)/*64*/textStorage.length(); |
313 this.lineOffsets = offsets; | 313 this.lineOffsets = offsets; |
314 this.lineBounds = bounds; | 314 this.lineBounds = bounds; |
315 } | 315 } |
316 | 316 |
317 void destroy() { | 317 void destroy() { |
413 if (hasSelection || (flags & DWT.LAST_LINE_SELECTION) !is 0) { | 413 if (hasSelection || (flags & DWT.LAST_LINE_SELECTION) !is 0) { |
414 if (selectionBackground is null) selectionBackground = device.getSystemColor(DWT.COLOR_LIST_SELECTION); | 414 if (selectionBackground is null) selectionBackground = device.getSystemColor(DWT.COLOR_LIST_SELECTION); |
415 selectionColor = NSColor.colorWithDeviceRed(selectionBackground.handle[0], selectionBackground.handle[1], selectionBackground.handle[2], selectionBackground.handle[3]); | 415 selectionColor = NSColor.colorWithDeviceRed(selectionBackground.handle[0], selectionBackground.handle[1], selectionBackground.handle[2], selectionBackground.handle[3]); |
416 } | 416 } |
417 if (hasSelection) { | 417 if (hasSelection) { |
418 selectionRange = new NSRange(); | 418 selectionRange = NSRange(); |
419 selectionRange.location = selectionStart; | 419 selectionRange.location = selectionStart; |
420 selectionRange.length = selectionEnd - selectionStart + 1; | 420 selectionRange.length = selectionEnd - selectionStart + 1; |
421 layoutManager.addTemporaryAttribute(OS.NSBackgroundColorAttributeName, selectionColor, *selectionRange); | 421 layoutManager.addTemporaryAttribute(OS.NSBackgroundColorAttributeName, selectionColor, *selectionRange); |
422 } | 422 } |
423 //TODO draw selection for flags (DELIMITER_SELECTION) | 423 //TODO draw selection for flags (DELIMITER_SELECTION) |
424 int numberOfGlyphs = layoutManager.numberOfGlyphs(); | 424 int numberOfGlyphs = layoutManager.numberOfGlyphs(); |
425 if (numberOfGlyphs > 0) { | 425 if (numberOfGlyphs > 0) { |
426 NSRange range = new NSRange(); | 426 NSRange range = NSRange(); |
427 for (int i = 0; i < styles.length - 1; i++) { | 427 for (int i = 0; i < styles.length - 1; i++) { |
428 StyleItem run = styles[i]; | 428 StyleItem run = styles[i]; |
429 if (run.style !is null && run.style.foreground !is null) continue; | 429 if (run.style !is null && run.style.foreground !is null) continue; |
430 range.location = length !is 0 ? translateOffset(run.start) : 0; | 430 range.location = length !is 0 ? translateOffset(run.start) : 0; |
431 range.length = translateOffset(styles[i + 1].start) - range.location; | 431 range.length = translateOffset(styles[i + 1].start) - range.location; |
435 range.length = numberOfGlyphs; | 435 range.length = numberOfGlyphs; |
436 layoutManager.drawBackgroundForGlyphRange(range, pt); | 436 layoutManager.drawBackgroundForGlyphRange(range, pt); |
437 layoutManager.drawGlyphsForGlyphRange(range, pt); | 437 layoutManager.drawGlyphsForGlyphRange(range, pt); |
438 range.length = length; | 438 range.length = length; |
439 layoutManager.removeTemporaryAttribute(OS.NSForegroundColorAttributeName, range); | 439 layoutManager.removeTemporaryAttribute(OS.NSForegroundColorAttributeName, range); |
440 NSPoint point = new NSPoint(); | 440 NSPoint point = NSPoint(); |
441 for (int j = 0; j < styles.length; j++) { | 441 for (int j = 0; j < styles.length; j++) { |
442 StyleItem run = styles[j]; | 442 StyleItem run = styles[j]; |
443 TextStyle style = run.style; | 443 TextStyle style = run.style; |
444 if (style is null) continue; | 444 if (style is null) continue; |
445 bool drawUnderline = style.underline && style.underlineStyle !is DWT.UNDERLINE_SINGLE && style.underlineStyle !is DWT.UNDERLINE_DOUBLE; | 445 bool drawUnderline = style.underline && style.underlineStyle !is DWT.UNDERLINE_SINGLE && style.underlineStyle !is DWT.UNDERLINE_DOUBLE; |
476 switch (style.underlineStyle) { | 476 switch (style.underlineStyle) { |
477 case DWT.UNDERLINE_ERROR: { | 477 case DWT.UNDERLINE_ERROR: { |
478 path.setLineWidth(2f); | 478 path.setLineWidth(2f); |
479 path.setLineCapStyle(OS.NSRoundLineCapStyle); | 479 path.setLineCapStyle(OS.NSRoundLineCapStyle); |
480 path.setLineJoinStyle(OS.NSRoundLineJoinStyle); | 480 path.setLineJoinStyle(OS.NSRoundLineJoinStyle); |
481 path.setLineDash(new float[]{1, 3f}, 2, 0); | 481 path.setLineDash([1, 3f], 2, 0); |
482 point.x = underlineX; | 482 point.x = underlineX; |
483 point.y = underlineY + 0.5f; | 483 point.y = underlineY + 0.5f; |
484 path.moveToPoint(point); | 484 path.moveToPoint(point); |
485 point.x = underlineX + rect.width; | 485 point.x = underlineX + rect.width; |
486 point.y = underlineY + 0.5f; | 486 point.y = underlineY + 0.5f; |
494 path.setLineJoinStyle(OS.NSMiterLineJoinStyle); | 494 path.setLineJoinStyle(OS.NSMiterLineJoinStyle); |
495 float lineBottom = pt.y + rect.y + rect.height; | 495 float lineBottom = pt.y + rect.y + rect.height; |
496 float squigglyThickness = 1; | 496 float squigglyThickness = 1; |
497 float squigglyHeight = 2 * squigglyThickness; | 497 float squigglyHeight = 2 * squigglyThickness; |
498 float squigglyY = Math.min(underlineY - squigglyHeight / 2, lineBottom - squigglyHeight - 1); | 498 float squigglyY = Math.min(underlineY - squigglyHeight / 2, lineBottom - squigglyHeight - 1); |
499 float[] points = computePolyline((int)underlineX, (int)squigglyY, (int)(underlineX + rect.width), (int)(squigglyY + squigglyHeight)); | 499 float[] points = computePolyline(cast(int)underlineX, cast(int)squigglyY, cast(int)(underlineX + rect.width), cast(int)(squigglyY + squigglyHeight)); |
500 point.x = points[0] + 0.5f; | 500 point.x = points[0] + 0.5f; |
501 point.y = points[1] + 0.5f; | 501 point.y = points[1] + 0.5f; |
502 path.moveToPoint(point); | 502 path.moveToPoint(point); |
503 for (int p = 2; p < points.length; p+=2) { | 503 for (int p = 2; p < points.length; p+=2) { |
504 point.x = points[p] + 0.5f; | 504 point.x = points[p] + 0.5f; |
554 | 554 |
555 } | 555 } |
556 } | 556 } |
557 if ((flags & DWT.LAST_LINE_SELECTION) !is 0) { | 557 if ((flags & DWT.LAST_LINE_SELECTION) !is 0) { |
558 NSRect bounds = lineBounds[lineBounds.length - 1]; | 558 NSRect bounds = lineBounds[lineBounds.length - 1]; |
559 NSRect rect = new NSRect(); | 559 NSRect rect = NSRect(); |
560 rect.x = pt.x + bounds.x + bounds.width; | 560 rect.x = pt.x + bounds.x + bounds.width; |
561 rect.y = y + bounds.y; | 561 rect.y = y + bounds.y; |
562 rect.width = (flags & DWT.FULL_SELECTION) !is 0 ? 0x7fffffff : bounds.height / 3; | 562 rect.width = (flags & DWT.FULL_SELECTION) !is 0 ? 0x7fffffff : bounds.height / 3; |
563 rect.height = bounds.height; | 563 rect.height = bounds.height; |
564 selectionColor.setFill(); | 564 selectionColor.setFill(); |
641 * @see #getLineBounds(int) | 641 * @see #getLineBounds(int) |
642 */ | 642 */ |
643 public Rectangle getBounds() { | 643 public Rectangle getBounds() { |
644 checkLayout(); | 644 checkLayout(); |
645 NSAutoreleasePool pool = null; | 645 NSAutoreleasePool pool = null; |
646 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 646 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
647 try { | 647 try { |
648 computeRuns(); | 648 computeRuns(); |
649 NSRect rect = layoutManager.usedRectForTextContainer(textContainer); | 649 NSRect rect = layoutManager.usedRectForTextContainer(textContainer); |
650 if (wrapWidth !is -1) rect.width = wrapWidth; | 650 if (wrapWidth !is -1) rect.width = wrapWidth; |
651 if (text.length() is 0) { | 651 if (text.length() is 0) { |
675 * </ul> | 675 * </ul> |
676 */ | 676 */ |
677 public Rectangle getBounds(int start, int end) { | 677 public Rectangle getBounds(int start, int end) { |
678 checkLayout(); | 678 checkLayout(); |
679 NSAutoreleasePool pool = null; | 679 NSAutoreleasePool pool = null; |
680 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 680 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
681 try { | 681 try { |
682 computeRuns(); | 682 computeRuns(); |
683 int length = text.length(); | 683 int length = text.length(); |
684 if (length is 0) return new Rectangle(0, 0, 0, 0); | 684 if (length is 0) return new Rectangle(0, 0, 0, 0); |
685 if (start > end) return new Rectangle(0, 0, 0, 0); | 685 if (start > end) return new Rectangle(0, 0, 0, 0); |
778 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | 778 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> |
779 */ | 779 */ |
780 public int getLevel(int offset) { | 780 public int getLevel(int offset) { |
781 checkLayout(); | 781 checkLayout(); |
782 NSAutoreleasePool pool = null; | 782 NSAutoreleasePool pool = null; |
783 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 783 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
784 try { | 784 try { |
785 computeRuns(); | 785 computeRuns(); |
786 int length = text.length(); | 786 int length = text.length(); |
787 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); | 787 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); |
788 offset = translateOffset(offset); | 788 offset = translateOffset(offset); |
806 * </ul> | 806 * </ul> |
807 */ | 807 */ |
808 public int[] getLineOffsets() { | 808 public int[] getLineOffsets() { |
809 checkLayout (); | 809 checkLayout (); |
810 NSAutoreleasePool pool = null; | 810 NSAutoreleasePool pool = null; |
811 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 811 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
812 try { | 812 try { |
813 computeRuns(); | 813 computeRuns(); |
814 int[] offsets = new int[lineOffsets.length]; | 814 int[] offsets = new int[lineOffsets.length]; |
815 for (int i = 0; i < offsets.length; i++) { | 815 for (int i = 0; i < offsets.length; i++) { |
816 offsets[i] = untranslateOffset(lineOffsets[i]); | 816 offsets[i] = untranslateOffset(lineOffsets[i]); |
836 * </ul> | 836 * </ul> |
837 */ | 837 */ |
838 public int getLineIndex(int offset) { | 838 public int getLineIndex(int offset) { |
839 checkLayout (); | 839 checkLayout (); |
840 NSAutoreleasePool pool = null; | 840 NSAutoreleasePool pool = null; |
841 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 841 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
842 try { | 842 try { |
843 computeRuns(); | 843 computeRuns(); |
844 int length = text.length(); | 844 int length = text.length(); |
845 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); | 845 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); |
846 offset = translateOffset(offset); | 846 offset = translateOffset(offset); |
869 * </ul> | 869 * </ul> |
870 */ | 870 */ |
871 public Rectangle getLineBounds(int lineIndex) { | 871 public Rectangle getLineBounds(int lineIndex) { |
872 checkLayout(); | 872 checkLayout(); |
873 NSAutoreleasePool pool = null; | 873 NSAutoreleasePool pool = null; |
874 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 874 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
875 try { | 875 try { |
876 computeRuns(); | 876 computeRuns(); |
877 if (!(0 <= lineIndex && lineIndex < lineBounds.length)) DWT.error(DWT.ERROR_INVALID_RANGE); | 877 if (!(0 <= lineIndex && lineIndex < lineBounds.length)) DWT.error(DWT.ERROR_INVALID_RANGE); |
878 NSRect rect = lineBounds[lineIndex]; | 878 NSRect rect = lineBounds[lineIndex]; |
879 return new Rectangle(cast(int)rect.x, cast(int)rect.y, cast(int)rect.width, cast(int)rect.height); | 879 return new Rectangle(cast(int)rect.x, cast(int)rect.y, cast(int)rect.width, cast(int)rect.height); |
893 * </ul> | 893 * </ul> |
894 */ | 894 */ |
895 public int getLineCount() { | 895 public int getLineCount() { |
896 checkLayout (); | 896 checkLayout (); |
897 NSAutoreleasePool pool = null; | 897 NSAutoreleasePool pool = null; |
898 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 898 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
899 try { | 899 try { |
900 computeRuns(); | 900 computeRuns(); |
901 return lineOffsets.length - 1; | 901 return lineOffsets.length - 1; |
902 } finally { | 902 } finally { |
903 if (pool !is null) pool.release(); | 903 if (pool !is null) pool.release(); |
918 * </ul> | 918 * </ul> |
919 */ | 919 */ |
920 public FontMetrics getLineMetrics (int lineIndex) { | 920 public FontMetrics getLineMetrics (int lineIndex) { |
921 checkLayout (); | 921 checkLayout (); |
922 NSAutoreleasePool pool = null; | 922 NSAutoreleasePool pool = null; |
923 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 923 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
924 try { | 924 try { |
925 computeRuns(); | 925 computeRuns(); |
926 int lineCount = getLineCount(); | 926 int lineCount = getLineCount(); |
927 if (!(0 <= lineIndex && lineIndex < lineCount)) DWT.error(DWT.ERROR_INVALID_RANGE); | 927 if (!(0 <= lineIndex && lineIndex < lineCount)) DWT.error(DWT.ERROR_INVALID_RANGE); |
928 int length = text.length(); | 928 int length = text.length(); |
960 * @see #getOffset(int, int, int[]) | 960 * @see #getOffset(int, int, int[]) |
961 */ | 961 */ |
962 public Point getLocation(int offset, bool trailing) { | 962 public Point getLocation(int offset, bool trailing) { |
963 checkLayout(); | 963 checkLayout(); |
964 NSAutoreleasePool pool = null; | 964 NSAutoreleasePool pool = null; |
965 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 965 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
966 try { | 966 try { |
967 computeRuns(); | 967 computeRuns(); |
968 int length = text.length(); | 968 int length = text.length(); |
969 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); | 969 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); |
970 if (length is 0) return new Point(0, 0); | 970 if (length is 0) return new Point(0, 0); |
1004 * | 1004 * |
1005 * @see #getPreviousOffset(int, int) | 1005 * @see #getPreviousOffset(int, int) |
1006 */ | 1006 */ |
1007 public int getNextOffset (int offset, int movement) { | 1007 public int getNextOffset (int offset, int movement) { |
1008 NSAutoreleasePool pool = null; | 1008 NSAutoreleasePool pool = null; |
1009 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1009 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1010 try { | 1010 try { |
1011 return _getOffset(offset, movement, true); | 1011 return _getOffset(offset, movement, true); |
1012 } finally { | 1012 } finally { |
1013 if (pool !is null) pool.release(); | 1013 if (pool !is null) pool.release(); |
1014 } | 1014 } |
1030 offset--; | 1030 offset--; |
1031 } | 1031 } |
1032 return Math.max(0, Math.min(length, untranslateOffset(offset))); | 1032 return Math.max(0, Math.min(length, untranslateOffset(offset))); |
1033 } | 1033 } |
1034 case DWT.MOVEMENT_WORD: { | 1034 case DWT.MOVEMENT_WORD: { |
1035 return untranslateOffset((int)/*64*/textStorage.nextWordFromIndex(offset, forward)); | 1035 return untranslateOffset(cast(int)/*64*/textStorage.nextWordFromIndex(offset, forward)); |
1036 } | 1036 } |
1037 case DWT.MOVEMENT_WORD_END: { | 1037 case DWT.MOVEMENT_WORD_END: { |
1038 NSRange range = textStorage.doubleClickAtIndex(length is offset ? length - 1 : offset); | 1038 NSRange range = textStorage.doubleClickAtIndex(length is offset ? length - 1 : offset); |
1039 return untranslateOffset((int)/*64*/(range.location + range.length)); | 1039 return untranslateOffset(cast(int)/*64*/(range.location + range.length)); |
1040 } | 1040 } |
1041 case DWT.MOVEMENT_WORD_START: { | 1041 case DWT.MOVEMENT_WORD_START: { |
1042 NSRange range = textStorage.doubleClickAtIndex(length is offset ? length - 1 : offset); | 1042 NSRange range = textStorage.doubleClickAtIndex(length is offset ? length - 1 : offset); |
1043 return untranslateOffset((int)/*64*/range.location); | 1043 return untranslateOffset(cast(int)/*64*/range.location); |
1044 } | 1044 } |
1045 default: | 1045 default: |
1046 break; | 1046 break; |
1047 } | 1047 } |
1048 return -1; | 1048 return -1; |
1072 * @see #getLocation(int, bool) | 1072 * @see #getLocation(int, bool) |
1073 */ | 1073 */ |
1074 public int getOffset(Point point, int[] trailing) { | 1074 public int getOffset(Point point, int[] trailing) { |
1075 checkLayout(); | 1075 checkLayout(); |
1076 NSAutoreleasePool pool = null; | 1076 NSAutoreleasePool pool = null; |
1077 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1077 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1078 try { | 1078 try { |
1079 computeRuns(); | 1079 computeRuns(); |
1080 if (point is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 1080 if (point is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
1081 return getOffset(point.x, point.y, trailing); | 1081 return getOffset(point.x, point.y, trailing); |
1082 } finally { | 1082 } finally { |
1108 * @see #getLocation(int, bool) | 1108 * @see #getLocation(int, bool) |
1109 */ | 1109 */ |
1110 public int getOffset(int x, int y, int[] trailing) { | 1110 public int getOffset(int x, int y, int[] trailing) { |
1111 checkLayout(); | 1111 checkLayout(); |
1112 NSAutoreleasePool pool = null; | 1112 NSAutoreleasePool pool = null; |
1113 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1113 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1114 try { | 1114 try { |
1115 computeRuns(); | 1115 computeRuns(); |
1116 if (trailing !is null && trailing.length < 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 1116 if (trailing !is null && trailing.length < 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
1117 int length = text.length(); | 1117 int length = text.length(); |
1118 if (length is 0) return 0; | 1118 if (length is 0) return 0; |
1119 NSPoint pt = NSPoint(); | 1119 NSPoint pt = NSPoint(); |
1120 pt.x = x; | 1120 pt.x = x; |
1121 pt.y = y; | 1121 pt.y = y; |
1122 CGFloat partialFration; | 1122 CGFloat partialFration; |
1123 NSUInteger glyphIndex = layoutManager.glyphIndexForPoint(pt, textContainer, &partialFration); | 1123 NSUInteger glyphIndex = layoutManager.glyphIndexForPoint(pt, textContainer, &partialFration); |
1124 int /*long*/ offset = layoutManager.characterIndexForGlyphAtIndex(glyphIndex); | 1124 NSUInteger offset = layoutManager.characterIndexForGlyphAtIndex(glyphIndex); |
1125 if (trailing !is null) trailing[0] = cast(int) Math.round(partialFration); | 1125 if (trailing !is null) trailing[0] = cast(int) Math.round(partialFration); |
1126 return Math.min(untranslateOffset((int)/*64*/offset), length - 1); | 1126 return Math.min(untranslateOffset(cast(int)/*64*/offset), length - 1); |
1127 } finally { | 1127 } finally { |
1128 if (pool !is null) pool.release(); | 1128 if (pool !is null) pool.release(); |
1129 } | 1129 } |
1130 } | 1130 } |
1131 | 1131 |
1162 * | 1162 * |
1163 * @see #getNextOffset(int, int) | 1163 * @see #getNextOffset(int, int) |
1164 */ | 1164 */ |
1165 public int getPreviousOffset (int index, int movement) { | 1165 public int getPreviousOffset (int index, int movement) { |
1166 NSAutoreleasePool pool = null; | 1166 NSAutoreleasePool pool = null; |
1167 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1167 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1168 try { | 1168 try { |
1169 return _getOffset(index, movement, false); | 1169 return _getOffset(index, movement, false); |
1170 } finally { | 1170 } finally { |
1171 if (pool !is null) pool.release(); | 1171 if (pool !is null) pool.release(); |
1172 } | 1172 } |
1371 if (alignment is 0) return; | 1371 if (alignment is 0) return; |
1372 if ((alignment & DWT.LEFT) !is 0) alignment = DWT.LEFT; | 1372 if ((alignment & DWT.LEFT) !is 0) alignment = DWT.LEFT; |
1373 if ((alignment & DWT.RIGHT) !is 0) alignment = DWT.RIGHT; | 1373 if ((alignment & DWT.RIGHT) !is 0) alignment = DWT.RIGHT; |
1374 if (this.alignment is alignment) return; | 1374 if (this.alignment is alignment) return; |
1375 NSAutoreleasePool pool = null; | 1375 NSAutoreleasePool pool = null; |
1376 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1376 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1377 try { | 1377 try { |
1378 freeRuns(); | 1378 freeRuns(); |
1379 this.alignment = alignment; | 1379 this.alignment = alignment; |
1380 } finally { | 1380 } finally { |
1381 if (pool !is null) pool.release(); | 1381 if (pool !is null) pool.release(); |
1403 public void setAscent (int ascent) { | 1403 public void setAscent (int ascent) { |
1404 checkLayout (); | 1404 checkLayout (); |
1405 if (ascent < -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 1405 if (ascent < -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
1406 if (this.ascent is ascent) return; | 1406 if (this.ascent is ascent) return; |
1407 NSAutoreleasePool pool = null; | 1407 NSAutoreleasePool pool = null; |
1408 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1408 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1409 try { | 1409 try { |
1410 freeRuns(); | 1410 freeRuns(); |
1411 this.ascent = ascent; | 1411 this.ascent = ascent; |
1412 } finally { | 1412 } finally { |
1413 if (pool !is null) pool.release(); | 1413 if (pool !is null) pool.release(); |
1435 public void setDescent (int descent) { | 1435 public void setDescent (int descent) { |
1436 checkLayout (); | 1436 checkLayout (); |
1437 if (descent < -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 1437 if (descent < -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
1438 if (this.descent is descent) return; | 1438 if (this.descent is descent) return; |
1439 NSAutoreleasePool pool = null; | 1439 NSAutoreleasePool pool = null; |
1440 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1440 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1441 try { | 1441 try { |
1442 freeRuns(); | 1442 freeRuns(); |
1443 this.descent = descent; | 1443 this.descent = descent; |
1444 } finally { | 1444 } finally { |
1445 if (pool !is null) pool.release(); | 1445 if (pool !is null) pool.release(); |
1468 Font oldFont = this.font; | 1468 Font oldFont = this.font; |
1469 if (oldFont is font) return; | 1469 if (oldFont is font) return; |
1470 this.font = font; | 1470 this.font = font; |
1471 if (oldFont !is null && oldFont.equals(font)) return; | 1471 if (oldFont !is null && oldFont.equals(font)) return; |
1472 NSAutoreleasePool pool = null; | 1472 NSAutoreleasePool pool = null; |
1473 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1473 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1474 try { | 1474 try { |
1475 freeRuns(); | 1475 freeRuns(); |
1476 } finally { | 1476 } finally { |
1477 if (pool !is null) pool.release(); | 1477 if (pool !is null) pool.release(); |
1478 } | 1478 } |
1493 public void setIndent (int indent) { | 1493 public void setIndent (int indent) { |
1494 checkLayout (); | 1494 checkLayout (); |
1495 if (indent < 0) return; | 1495 if (indent < 0) return; |
1496 if (this.indent is indent) return; | 1496 if (this.indent is indent) return; |
1497 NSAutoreleasePool pool = null; | 1497 NSAutoreleasePool pool = null; |
1498 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1498 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1499 try { | 1499 try { |
1500 freeRuns(); | 1500 freeRuns(); |
1501 this.indent = indent; | 1501 this.indent = indent; |
1502 } finally { | 1502 } finally { |
1503 if (pool !is null) pool.release(); | 1503 if (pool !is null) pool.release(); |
1518 */ | 1518 */ |
1519 public void setJustify (bool justify) { | 1519 public void setJustify (bool justify) { |
1520 checkLayout (); | 1520 checkLayout (); |
1521 if (justify is this.justify) return; | 1521 if (justify is this.justify) return; |
1522 NSAutoreleasePool pool = null; | 1522 NSAutoreleasePool pool = null; |
1523 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1523 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1524 try { | 1524 try { |
1525 freeRuns(); | 1525 freeRuns(); |
1526 this.justify = justify; | 1526 this.justify = justify; |
1527 } finally { | 1527 } finally { |
1528 if (pool !is null) pool.release(); | 1528 if (pool !is null) pool.release(); |
1546 if (orientation is 0) return; | 1546 if (orientation is 0) return; |
1547 if ((orientation & DWT.LEFT_TO_RIGHT) !is 0) orientation = DWT.LEFT_TO_RIGHT; | 1547 if ((orientation & DWT.LEFT_TO_RIGHT) !is 0) orientation = DWT.LEFT_TO_RIGHT; |
1548 if (this.orientation is orientation) return; | 1548 if (this.orientation is orientation) return; |
1549 this.orientation = orientation; | 1549 this.orientation = orientation; |
1550 NSAutoreleasePool pool = null; | 1550 NSAutoreleasePool pool = null; |
1551 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1551 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1552 try { | 1552 try { |
1553 freeRuns(); | 1553 freeRuns(); |
1554 } finally { | 1554 } finally { |
1555 if (pool !is null) pool.release(); | 1555 if (pool !is null) pool.release(); |
1556 } | 1556 } |
1585 } | 1585 } |
1586 if (i is segments.length) return; | 1586 if (i is segments.length) return; |
1587 } | 1587 } |
1588 } | 1588 } |
1589 NSAutoreleasePool pool = null; | 1589 NSAutoreleasePool pool = null; |
1590 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1590 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1591 try { | 1591 try { |
1592 freeRuns(); | 1592 freeRuns(); |
1593 this.segments = segments; | 1593 this.segments = segments; |
1594 } finally { | 1594 } finally { |
1595 if (pool !is null) pool.release(); | 1595 if (pool !is null) pool.release(); |
1612 public void setSpacing (int spacing) { | 1612 public void setSpacing (int spacing) { |
1613 checkLayout(); | 1613 checkLayout(); |
1614 if (spacing < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 1614 if (spacing < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
1615 if (this.spacing is spacing) return; | 1615 if (this.spacing is spacing) return; |
1616 NSAutoreleasePool pool = null; | 1616 NSAutoreleasePool pool = null; |
1617 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1617 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1618 try { | 1618 try { |
1619 freeRuns(); | 1619 freeRuns(); |
1620 this.spacing = spacing; | 1620 this.spacing = spacing; |
1621 } finally { | 1621 } finally { |
1622 if (pool !is null) pool.release(); | 1622 if (pool !is null) pool.release(); |
1637 * </ul> | 1637 * </ul> |
1638 */ | 1638 */ |
1639 public void setStyle (TextStyle style, int start, int end) { | 1639 public void setStyle (TextStyle style, int start, int end) { |
1640 checkLayout(); | 1640 checkLayout(); |
1641 NSAutoreleasePool pool = null; | 1641 NSAutoreleasePool pool = null; |
1642 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1642 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1643 try { | 1643 try { |
1644 int length = text.length(); | 1644 int length = text.length(); |
1645 if (length is 0) return; | 1645 if (length is 0) return; |
1646 if (start > end) return; | 1646 if (start > end) return; |
1647 start = Math.min(Math.max(0, start), length - 1); | 1647 start = Math.min(Math.max(0, start), length - 1); |
1735 } | 1735 } |
1736 if (i is tabs.length) return; | 1736 if (i is tabs.length) return; |
1737 } | 1737 } |
1738 } | 1738 } |
1739 NSAutoreleasePool pool = null; | 1739 NSAutoreleasePool pool = null; |
1740 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1740 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1741 try { | 1741 try { |
1742 freeRuns(); | 1742 freeRuns(); |
1743 this.tabs = tabs; | 1743 this.tabs = tabs; |
1744 } finally { | 1744 } finally { |
1745 if (pool !is null) pool.release(); | 1745 if (pool !is null) pool.release(); |
1761 public void setText (String text) { | 1761 public void setText (String text) { |
1762 checkLayout (); | 1762 checkLayout (); |
1763 if (text is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 1763 if (text is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
1764 if (text.equals(this.text)) return; | 1764 if (text.equals(this.text)) return; |
1765 NSAutoreleasePool pool = null; | 1765 NSAutoreleasePool pool = null; |
1766 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1766 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1767 try { | 1767 try { |
1768 freeRuns(); | 1768 freeRuns(); |
1769 this.text = text; | 1769 this.text = text; |
1770 styles = new StyleItem[2]; | 1770 styles = new StyleItem[2]; |
1771 styles[0] = new StyleItem(); | 1771 styles[0] = new StyleItem(); |
1795 public void setWidth (int width) { | 1795 public void setWidth (int width) { |
1796 checkLayout(); | 1796 checkLayout(); |
1797 if (width < -1 || width is 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 1797 if (width < -1 || width is 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
1798 if (this.wrapWidth is width) return; | 1798 if (this.wrapWidth is width) return; |
1799 NSAutoreleasePool pool = null; | 1799 NSAutoreleasePool pool = null; |
1800 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 1800 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
1801 try { | 1801 try { |
1802 freeRuns(); | 1802 freeRuns(); |
1803 this.wrapWidth = width; | 1803 this.wrapWidth = width; |
1804 } finally { | 1804 } finally { |
1805 if (pool !is null) pool.release(); | 1805 if (pool !is null) pool.release(); |