Mercurial > projects > dwt-mac
diff dwt/graphics/TextLayout.d @ 37:642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Fri, 10 Oct 2008 12:29:48 +0200 |
parents | db5a898b2119 |
children | d8635bb48c7c |
line wrap: on
line diff
--- a/dwt/graphics/TextLayout.d Tue Oct 07 12:56:18 2008 +0200 +++ b/dwt/graphics/TextLayout.d Fri Oct 10 12:29:48 2008 +0200 @@ -29,6 +29,8 @@ import dwt.internal.cocoa.NSTextStorage; import dwt.internal.cocoa.OS; +import tango.text.convert.Format; + import dwt.dwthelper.utils; import dwt.graphics.Color; import dwt.graphics.Device; @@ -42,6 +44,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.cocoa.NSText; /** * <code>TextLayout</code> is a graphic object that represents @@ -84,7 +89,7 @@ int start; public String toString () { - return "StyleItem {" + start + ", " + style + "}"; + return Format("StyleItem {{}{}{}{}" , start , ", " , style , "}"); } } @@ -132,7 +137,7 @@ textStorage.initWithString_(str); layoutManager = cast(NSLayoutManager)(new NSLayoutManager()).alloc().init(); textContainer = cast(NSTextContainer)(new NSTextContainer()).alloc(); - NSSize size = new NSSize(); + NSSize size = NSSize(); size.width = wrapWidth !is -1 ? wrapWidth : Float.MAX_VALUE; size.height = Float.MAX_VALUE; textContainer.initWithContainerSize(size); @@ -141,21 +146,21 @@ textStorage.beginEditing(); Font defaultFont = font !is null ? font : device.systemFont; - NSRange range = new NSRange(); + NSRange range = NSRange(); range.length = str.length(); textStorage.addAttribute(OS.NSFontAttributeName(), defaultFont.handle, range); NSMutableParagraphStyle paragraph = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle()).alloc().init(); - int align_ = OS.NSLeftTextAlignment; + NSTextAlignment align_ = NSLeftTextAlignment; if (justify) { - align_ = OS.NSJustifiedTextAlignment; + align_ = NSJustifiedTextAlignment; } else { switch (alignment) { case DWT.CENTER: - align_ = OS.NSCenterTextAlignment; + align_ = NSCenterTextAlignment; break; case DWT.RIGHT: - align_ = OS.NSRightTextAlignment; + align_ = NSRightTextAlignment; } } paragraph.setAlignment(align_); @@ -186,7 +191,7 @@ Color background = style.background; if (background !is null) { NSColor color = NSColor.colorWithDeviceRed(background.handle[0], background.handle[1], background.handle[2], 1); - textStorage.addAttribute(OS.NSBackgroundColorAttributeName(), color, range); + textStorage.addAttribute(OS.NSBackgroundColorAttributeName, color, range); } if (style.strikeout) { textStorage.addAttribute(OS.NSStrikethroughStyleAttributeName(), NSNumber.numberWithInt(OS.NSUnderlineStyleSingle), range); @@ -229,11 +234,11 @@ layoutManager.glyphRangeForTextContainer(textContainer); int numberOfLines, index, numberOfGlyphs = layoutManager.numberOfGlyphs(); - int rangePtr = OS.malloc(NSRange.sizeof); - NSRange lineRange = new NSRange(); + NSRangePointer rangePtr = cast(NSRangePointer) OS.malloc(NSRange.sizeof); + NSRange lineRange = NSRange(); for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){ layoutManager.lineFragmentUsedRectForGlyphAtIndex_effectiveRange_withoutAdditionalLayout_(index, rangePtr, true); - OS.memmove(lineRange, rangePtr, NSRange.sizeof); + OS.memmove(&lineRange, rangePtr, NSRange.sizeof); index = lineRange.location + lineRange.length; } if (numberOfLines is 0) numberOfLines++; @@ -241,14 +246,14 @@ NSRect[] bounds = new NSRect[numberOfLines]; for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){ bounds[numberOfLines] = layoutManager.lineFragmentUsedRectForGlyphAtIndex_effectiveRange_withoutAdditionalLayout_(index, rangePtr, true); - OS.memmove(lineRange, rangePtr, NSRange.sizeof); + OS.memmove(&lineRange, rangePtr, NSRange.sizeof); offsets[numberOfLines] = lineRange.location; index = lineRange.location + lineRange.length; } if (numberOfLines is 0) { Font font = this.font !is null ? this.font : device.systemFont; NSFont nsFont = font.handle; - bounds[0] = new NSRect(); + bounds[0] = NSRect(); bounds[0].height = Math.max(layoutManager.defaultLineHeightForFont(nsFont), ascent + descent); } OS.free(rangePtr); @@ -344,20 +349,20 @@ // float[] foreground = gc.data.foreground; // NSColor color = NSColor.colorWithDeviceRed(foreground[0], foreground[1], foreground[2], foreground[3]); // textStorage.setForegroundColor(color); - NSPoint pt = new NSPoint(); + NSPoint pt = NSPoint(); pt.x = x; pt.y = y; - NSRange range = new NSRange(); + NSRange range = NSRange(); range.length = layoutManager.numberOfGlyphs(); bool hasSelection = selectionStart <= selectionEnd && selectionStart !is -1 && selectionEnd !is -1; - NSRange selectionRange = null; + NSRange* selectionRange = null; if (hasSelection) { selectionRange = new NSRange(); selectionRange.location = selectionStart; selectionRange.length = selectionEnd - selectionStart + 1; if (selectionBackground is null) selectionBackground = device.getSystemColor(DWT.COLOR_LIST_SELECTION); NSColor selectionColor = NSColor.colorWithDeviceRed(selectionBackground.handle[0], selectionBackground.handle[1], selectionBackground.handle[2], selectionBackground.handle[3]); - layoutManager.addTemporaryAttribute(OS.NSBackgroundColorAttributeName, selectionColor, selectionRange); + layoutManager.addTemporaryAttribute(OS.NSBackgroundColorAttributeName, selectionColor, *selectionRange); } //TODO draw selection for flags (LAST_LINE_SELECTION and FULL_SELECTION) if (range.length > 0) { @@ -365,7 +370,7 @@ layoutManager.drawGlyphsForGlyphRange(range, pt); } if (selectionRange !is null) { - layoutManager.removeTemporaryAttribute(OS.NSBackgroundColorAttributeName, selectionRange); + layoutManager.removeTemporaryAttribute(OS.NSBackgroundColorAttributeName, *selectionRange); } } @@ -467,7 +472,7 @@ end = Math.min(Math.max(0, end), length - 1); start = translateOffset(start); end = translateOffset(end); - NSRange range = new NSRange(); + NSRange range = NSRange(); range.location = layoutManager.glyphIndexForCharacterAtIndex(start); range.length = layoutManager.glyphIndexForCharacterAtIndex(end + 1) - range.location; NSRect rect = layoutManager.boundingRectForGlyphRange(range, textContainer); @@ -707,11 +712,11 @@ if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); if (length is 0) return new Point(0, 0); offset = translateOffset(offset); - int glyphIndex = layoutManager.glyphIndexForCharacterAtIndex(offset); - NSRect rect = layoutManager.lineFragmentUsedRectForGlyphAtIndex_effectiveRange_(glyphIndex, 0); + NSUInteger glyphIndex = layoutManager.glyphIndexForCharacterAtIndex(offset); + NSRect rect = layoutManager.lineFragmentUsedRectForGlyphAtIndex_effectiveRange_(glyphIndex, null); NSPoint point = layoutManager.locationForGlyphAtIndex(glyphIndex); if (trailing) { - NSRange range = new NSRange(); + NSRange range = NSRange(); range.location = glyphIndex; range.length = 1; NSRect bounds = layoutManager.boundingRectForGlyphRange(range, textContainer); @@ -836,13 +841,13 @@ if (trailing !is null && trailing.length < 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); int length = text.length(); if (length is 0) return 0; - NSPoint pt = new NSPoint(); + NSPoint pt = NSPoint(); pt.x = x; pt.y = y; - float[] partialFration = new float[1]; - int glyphIndex = layoutManager.glyphIndexForPoint_inTextContainer_fractionOfDistanceThroughGlyph_(pt, textContainer, partialFration); + CGFloat partialFration; + NSUInteger glyphIndex = layoutManager.glyphIndexForPoint_inTextContainer_fractionOfDistanceThroughGlyph_(pt, textContainer, &partialFration); int offset = layoutManager.characterIndexForGlyphAtIndex(glyphIndex); - if (trailing !is null) trailing[0] = Math.round(partialFration[0]); + if (trailing !is null) trailing[0] = cast(int) Math.round(partialFration); return Math.min(untranslateOffset(offset), length - 1); } @@ -1447,7 +1452,7 @@ */ public String toString () { if (isDisposed()) return "TextLayout {*DISPOSED*}"; - return "TextLayout {" + text + "}"; + return "TextLayout {" ~ text ~ "}"; } /*