Mercurial > projects > dwt-mac
changeset 70:2d5ef909b21d
Ported dwt.widgets.Lable
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 23 Dec 2008 23:30:38 +0100 |
parents | 39340f7612f8 |
children | 3607217555f2 |
files | dwt/internal/cocoa/OS.d dwt/widgets/Label.d |
diffstat | 2 files changed, 29 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/internal/cocoa/OS.d Tue Dec 23 23:21:45 2008 +0100 +++ b/dwt/internal/cocoa/OS.d Tue Dec 23 23:30:38 2008 +0100 @@ -2767,7 +2767,7 @@ public static const int NSBoxOldStyle = 3; public static const int NSBoxPrimary = 0; public static const int NSBoxSecondary = 1; -public static const int NSBoxSeparator = 2; +public static const NSBoxType NSBoxSeparator = 2; public static const int NSBreakFunctionKey = 63282; public static const int NSBrowserAutoColumnResizing = 1; public static const int NSBrowserDropAbove = 1;
--- a/dwt/widgets/Label.d Tue Dec 23 23:21:45 2008 +0100 +++ b/dwt/widgets/Label.d Tue Dec 23 23:30:38 2008 +0100 @@ -7,6 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg <doob@me.com> *******************************************************************************/ module dwt.widgets.Label; @@ -38,7 +41,12 @@ import dwt.internal.cocoa.SWTBox; import dwt.internal.cocoa.SWTImageView; import dwt.internal.cocoa.SWTTextField; -import dwt.internal.cocoa.id; +import cocoa = dwt.internal.cocoa.id; + +import dwt.internal.c.Carbon; +import objc = dwt.internal.objc.runtime; +import dwt.widgets.Composite; +import dwt.widgets.Control; /** * Instances of this class represent a non-selectable @@ -120,7 +128,7 @@ super (parent, checkStyle (style)); } -int accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) { +objc.id accessibilityAttributeNames(objc.id id, objc.SEL sel) { if (accessible !is null) { if ((textView !is null && (id is textView.id || id is textView.cell().id)) || (imageView !is null && (id is imageView.id || id is imageView.cell().id))) { @@ -139,13 +147,13 @@ } if (extraAttributes.count() > 0) { - int superResult = super.accessibilityAttributeNames(id, sel); + objc.id superResult = super.accessibilityAttributeNames(id, sel); NSArray baseAttributes = new NSArray(superResult); NSMutableArray mutableAttributes = NSMutableArray.arrayWithCapacity(baseAttributes.count() + 1); mutableAttributes.addObjectsFromArray(baseAttributes); for (int i = 0; i < extraAttributes.count(); i++) { - id currAttribute = extraAttributes.objectAtIndex(i); + cocoa.id currAttribute = extraAttributes.objectAtIndex(i); if (!mutableAttributes.containsObject(currAttribute)) { mutableAttributes.addObject(currAttribute); } @@ -159,7 +167,7 @@ return super.accessibilityAttributeNames(id, sel); } -bool accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) { +bool accessibilityIsIgnored(objc.id id, objc.SEL sel) { if (id is view.id) return true; return super.accessibilityIsIgnored(id, sel); } @@ -179,23 +187,23 @@ int width = DEFAULT_WIDTH; int height = DEFAULT_HEIGHT; if ((style & DWT.SEPARATOR) !is 0) { - ((NSBox) view).sizeToFit (); + (cast(NSBox) view).sizeToFit (); NSRect newRect = view.frame (); - width = (int) newRect.width; - height = (int) newRect.height; + width = cast(int) newRect.width; + height = cast(int) newRect.height; view.setFrame (oldRect); } else { if (isImage) { if (image !is null) { NSImage nsimage = image.handle; NSSize size = nsimage.size (); - width = (int)size.width; - height = (int)size.height; + width = cast(int)size.width; + height = cast(int)size.height; } else { width = height = 0; } } else { - NSRect rect = new NSRect (); + NSRect rect = NSRect (); rect.width = wHint !is DWT.DEFAULT ? wHint : Float.MAX_VALUE; rect.height = hHint !is DWT.DEFAULT ? hHint : Float.MAX_VALUE; NSSize size = textView.cell ().cellSizeForBounds (rect); @@ -214,17 +222,17 @@ widget.setTitle(NSString.stringWith("")); if ((style & DWT.SEPARATOR) !is 0) { widget.setBoxType(OS.NSBoxSeparator); - NSView child = (NSView) new NSView().alloc().init().autorelease(); + NSView child = cast(NSView) (new NSView()).alloc().init().autorelease(); widget.setContentView(child); } else { widget.setBorderType(OS.NSNoBorder); widget.setBorderWidth (0); widget.setBoxType (OS.NSBoxCustom); - NSSize offsetSize = new NSSize (); + NSSize offsetSize = NSSize (); widget.setContentViewMargins (offsetSize); - NSImageView imageWidget = cast(NSImageView) new SWTImageView ().alloc (); - imageWidget.initWithFrame(new NSRect ()); + NSImageView imageWidget = cast(NSImageView) (new SWTImageView ()).alloc (); + imageWidget.initWithFrame(NSRect ()); imageWidget.setImageScaling (OS.NSScaleNone); NSTextField textWidget = cast(NSTextField)(new SWTTextField()).alloc(); @@ -259,8 +267,8 @@ text.getChars (0, chars.length, chars, 0); int length = fixMnemonic (chars); - NSString str = NSString.stringWithCharacters(chars, length); - NSAttributedString attribStr = (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString(str, dict); + NSString str = NSString.stringWithCharacters(chars.toString16().ptr, length); + NSAttributedString attribStr = (cast(NSAttributedString)(new NSAttributedString()).alloc()).initWithString(str, dict); attribStr.autorelease(); return attribStr; } @@ -379,12 +387,12 @@ _setAlignment(); } -void setBackground (float [] color) { +void setBackground (CGFloat [] color) { if ((style & DWT.SEPARATOR) !is 0) return; textView.setDrawsBackground(color !is null); if (color is null) return; NSColor nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); - ((NSTextField)textView).setBackgroundColor(nsColor); + (cast(NSTextField)textView).setBackgroundColor(nsColor); } void _setAlignment() { @@ -409,7 +417,7 @@ } } -void setForeground (float [] color) { +void setForeground (CGFloat [] color) { if ((style & DWT.SEPARATOR) !is 0) return; NSCell cell = new NSCell(textView.cell()); cell.setAttributedStringValue(createString());