diff 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
line wrap: on
line diff
--- a/dwt/graphics/TextLayout.d	Mon Dec 01 17:07:00 2008 +0100
+++ b/dwt/graphics/TextLayout.d	Fri Dec 05 16:00:41 2008 +0100
@@ -50,9 +50,9 @@
 import dwt.graphics.Region;
 import dwt.graphics.Resource;
 import dwt.graphics.TextStyle;
-import dwt.internal.cocoa.CGFloat;
-import dwt.internal.cocoa.NSInteger;
+import dwt.internal.c.Carbon;
 import dwt.internal.cocoa.NSText;
+import dwt.internal.objc.cocoa.Cocoa;
 
 /**
  * <code>TextLayout</code> is a graphic object that represents
@@ -207,7 +207,7 @@
         int count = tabs.length;
         for (int i = 0, pos = 0; i < count; i++) {
             pos += tabs[i];
-            NSTextTab tab = (NSTextTab)new NSTextTab().alloc();
+            NSTextTab tab = cast(NSTextTab)(new NSTextTab()).alloc();
             tab = tab.initWithType(OS.NSLeftTabStopType, pos);
             paragraph.addTabStop(tab);
             tab.release();
@@ -221,7 +221,7 @@
     textStorage.addAttribute(OS.NSParagraphStyleAttributeName, paragraph, range);
     paragraph.release();
     
-    int /*long*/ textLength = str.length();
+    NSUInteger textLength = str.length();
     for (int i = 0; i < styles.length - 1; i++) {
         StyleItem run = styles[i];
         if (run.style is null) continue;
@@ -299,7 +299,7 @@
         bounds[numberOfLines] = layoutManager.lineFragmentUsedRectForGlyphAtIndex(index, rangePtr, true);
         if (numberOfLines < bounds.length - 1) bounds[numberOfLines].height -= spacing;
         OS.memmove(&lineRange, rangePtr, NSRange.sizeof);
-        offsets[numberOfLines] = (int)/*64*/lineRange.location;
+        offsets[numberOfLines] = cast(int)/*64*/lineRange.location;
         index = lineRange.location + lineRange.length;
     }
     if (numberOfLines is 0) {
@@ -309,7 +309,7 @@
         bounds[0].height = Math.max(layoutManager.defaultLineHeightForFont(nsFont), ascent + descent);
     }
     OS.free(rangePtr);
-    offsets[numberOfLines] = (int)/*64*/textStorage.length();
+    offsets[numberOfLines] = cast(int)/*64*/textStorage.length();
     this.lineOffsets = offsets;
     this.lineBounds = bounds;
 }
@@ -415,7 +415,7 @@
             selectionColor = NSColor.colorWithDeviceRed(selectionBackground.handle[0], selectionBackground.handle[1], selectionBackground.handle[2], selectionBackground.handle[3]);
         }
         if (hasSelection) {
-            selectionRange = new NSRange();
+            selectionRange = NSRange();
             selectionRange.location = selectionStart;
             selectionRange.length = selectionEnd - selectionStart + 1;
         layoutManager.addTemporaryAttribute(OS.NSBackgroundColorAttributeName, selectionColor, *selectionRange);
@@ -423,7 +423,7 @@
         //TODO draw selection for flags (DELIMITER_SELECTION)
         int numberOfGlyphs = layoutManager.numberOfGlyphs();
         if (numberOfGlyphs > 0) {
-            NSRange range = new NSRange();
+            NSRange range = NSRange();
             for (int i = 0; i < styles.length - 1; i++) {
                 StyleItem run = styles[i];
                 if (run.style !is null && run.style.foreground !is null) continue;
@@ -437,7 +437,7 @@
             layoutManager.drawGlyphsForGlyphRange(range, pt);
             range.length = length;
             layoutManager.removeTemporaryAttribute(OS.NSForegroundColorAttributeName, range);
-            NSPoint point = new NSPoint();
+            NSPoint point = NSPoint();
             for (int j = 0; j < styles.length; j++) {
                 StyleItem run = styles[j];
                 TextStyle style = run.style;
@@ -478,7 +478,7 @@
                                     path.setLineWidth(2f);
                                     path.setLineCapStyle(OS.NSRoundLineCapStyle);
                                     path.setLineJoinStyle(OS.NSRoundLineJoinStyle);
-                                    path.setLineDash(new float[]{1, 3f}, 2, 0);
+                                    path.setLineDash([1, 3f], 2, 0);
                                     point.x = underlineX;
                                     point.y = underlineY + 0.5f;
                                     path.moveToPoint(point);
@@ -496,7 +496,7 @@
                                     float squigglyThickness = 1;
                                     float squigglyHeight = 2 * squigglyThickness;
                                     float squigglyY = Math.min(underlineY - squigglyHeight / 2, lineBottom - squigglyHeight - 1);
-                                    float[] points = computePolyline((int)underlineX, (int)squigglyY, (int)(underlineX + rect.width), (int)(squigglyY + squigglyHeight));
+                                    float[] points = computePolyline(cast(int)underlineX, cast(int)squigglyY, cast(int)(underlineX + rect.width), cast(int)(squigglyY + squigglyHeight));
                                     point.x = points[0] + 0.5f;
                                     point.y = points[1] + 0.5f;
                                     path.moveToPoint(point);
@@ -556,7 +556,7 @@
         }
         if ((flags & DWT.LAST_LINE_SELECTION) !is 0) {
             NSRect bounds = lineBounds[lineBounds.length - 1];
-            NSRect rect = new NSRect();
+            NSRect rect = NSRect();
             rect.x = pt.x + bounds.x + bounds.width;
             rect.y = y + bounds.y;
             rect.width = (flags & DWT.FULL_SELECTION) !is 0 ? 0x7fffffff : bounds.height / 3;
@@ -643,7 +643,7 @@
 public Rectangle getBounds() {
     checkLayout();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         NSRect rect = layoutManager.usedRectForTextContainer(textContainer);
@@ -677,7 +677,7 @@
 public Rectangle getBounds(int start, int end) {
     checkLayout();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         int length = text.length();
@@ -780,7 +780,7 @@
 public int getLevel(int offset) {
     checkLayout();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         int length = text.length();
@@ -808,7 +808,7 @@
 public int[] getLineOffsets() {
     checkLayout ();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         int[] offsets = new int[lineOffsets.length];
@@ -838,7 +838,7 @@
 public int getLineIndex(int offset) {
     checkLayout ();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         int length = text.length();
@@ -871,7 +871,7 @@
 public Rectangle getLineBounds(int lineIndex) {
     checkLayout();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         if (!(0 <= lineIndex && lineIndex < lineBounds.length)) DWT.error(DWT.ERROR_INVALID_RANGE);
@@ -895,7 +895,7 @@
 public int getLineCount() {
     checkLayout ();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();  
         return lineOffsets.length - 1;
@@ -920,7 +920,7 @@
 public FontMetrics getLineMetrics (int lineIndex) {
     checkLayout ();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         int lineCount = getLineCount();
@@ -962,7 +962,7 @@
 public Point getLocation(int offset, bool trailing) {
     checkLayout();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         int length = text.length();
@@ -1006,7 +1006,7 @@
  */
 public int getNextOffset (int offset, int movement) {
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         return _getOffset(offset, movement, true);
     } finally {
@@ -1032,15 +1032,15 @@
             return Math.max(0, Math.min(length, untranslateOffset(offset)));
         }
         case DWT.MOVEMENT_WORD: {
-            return untranslateOffset((int)/*64*/textStorage.nextWordFromIndex(offset, forward));
+            return untranslateOffset(cast(int)/*64*/textStorage.nextWordFromIndex(offset, forward));
         }
         case DWT.MOVEMENT_WORD_END: {
             NSRange range = textStorage.doubleClickAtIndex(length is offset ? length - 1 : offset);
-            return untranslateOffset((int)/*64*/(range.location + range.length));
+            return untranslateOffset(cast(int)/*64*/(range.location + range.length));
         }
         case DWT.MOVEMENT_WORD_START: {
             NSRange range = textStorage.doubleClickAtIndex(length is offset ? length - 1 : offset);
-            return untranslateOffset((int)/*64*/range.location);
+            return untranslateOffset(cast(int)/*64*/range.location);
         }
         default:
             break;
@@ -1074,7 +1074,7 @@
 public int getOffset(Point point, int[] trailing) {
     checkLayout();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         if (point is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
@@ -1110,7 +1110,7 @@
 public int getOffset(int x, int y, int[] trailing) {
     checkLayout();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         computeRuns();
         if (trailing !is null && trailing.length < 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
@@ -1121,9 +1121,9 @@
         pt.y = y;
     CGFloat partialFration;
     NSUInteger glyphIndex = layoutManager.glyphIndexForPoint(pt, textContainer, &partialFration);
-        int /*long*/ offset = layoutManager.characterIndexForGlyphAtIndex(glyphIndex);
+        NSUInteger offset = layoutManager.characterIndexForGlyphAtIndex(glyphIndex);
     if (trailing !is null) trailing[0] = cast(int) Math.round(partialFration);
-        return Math.min(untranslateOffset((int)/*64*/offset), length - 1);
+        return Math.min(untranslateOffset(cast(int)/*64*/offset), length - 1);
     } finally {
         if (pool !is null) pool.release();
     }
@@ -1164,7 +1164,7 @@
  */
 public int getPreviousOffset (int index, int movement) {
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         return _getOffset(index, movement, false);
     } finally {
@@ -1373,7 +1373,7 @@
     if ((alignment & DWT.RIGHT) !is 0) alignment = DWT.RIGHT;
     if (this.alignment is alignment) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.alignment = alignment;
@@ -1405,7 +1405,7 @@
     if (ascent < -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     if (this.ascent is ascent) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.ascent = ascent;
@@ -1437,7 +1437,7 @@
     if (descent < -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     if (this.descent is descent) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.descent = descent;
@@ -1470,7 +1470,7 @@
     this.font = font;
     if (oldFont !is null && oldFont.equals(font)) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
     } finally {
@@ -1495,7 +1495,7 @@
     if (indent < 0) return;
     if (this.indent is indent) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.indent = indent;
@@ -1520,7 +1520,7 @@
     checkLayout ();
     if (justify is this.justify) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.justify = justify;
@@ -1548,7 +1548,7 @@
     if (this.orientation is orientation) return;
     this.orientation = orientation;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
     } finally {
@@ -1587,7 +1587,7 @@
         }
     }
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.segments = segments;
@@ -1614,7 +1614,7 @@
     if (spacing < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     if (this.spacing is spacing) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.spacing = spacing;
@@ -1639,7 +1639,7 @@
 public void setStyle (TextStyle style, int start, int end) {
     checkLayout();
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         int length = text.length();
         if (length is 0) return;
@@ -1737,7 +1737,7 @@
         }
     }
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.tabs = tabs;
@@ -1763,7 +1763,7 @@
     if (text is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (text.equals(this.text)) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.text = text;
@@ -1797,7 +1797,7 @@
     if (width < -1 || width is 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     if (this.wrapWidth is width) return;
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         freeRuns();
         this.wrapWidth = width;