Mercurial > projects > dwt-mac
changeset 72:e08aaf7b6830
Ported dwt.widgets.List
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 23 Dec 2008 23:51:30 +0100 |
parents | 3607217555f2 |
children | 16f9078aa1ff |
files | dwt/widgets/List.d |
diffstat | 1 files changed, 52 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/widgets/List.d Tue Dec 23 23:40:01 2008 +0100 +++ b/dwt/widgets/List.d Tue Dec 23 23:51:30 2008 +0100 @@ -42,7 +42,14 @@ import dwt.internal.cocoa.OS; import dwt.internal.cocoa.SWTScrollView; import dwt.internal.cocoa.SWTTableView; -import dwt.internal.cocoa.id; +import cocoa = dwt.internal.cocoa.id; + +import dwt.internal.c.Carbon; +import dwt.internal.objc.cocoa.Cocoa; +import objc = dwt.internal.objc.runtime; +import dwt.widgets.Composite; +import dwt.widgets.Scrollable; +import dwt.widgets.TypedListener; /** * Instances of this class represent a selectable user interface @@ -104,11 +111,11 @@ super (parent, checkStyle (style)); } -int accessibilityAttributeValue (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { +objc.id accessibilityAttributeValue (objc.id id, objc.SEL sel, objc.id arg0) { if (accessible !is null) { NSString attribute = new NSString(arg0); - id returnValue = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF); + cocoa.id returnValue = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF); if (returnValue !is null) return returnValue.id; } @@ -263,14 +270,14 @@ } void createHandle () { - NSScrollView scrollWidget = cast(NSScrollView)new SWTScrollView().alloc(); - scrollWidget.initWithFrame(new NSRect ()); + NSScrollView scrollWidget = cast(NSScrollView)(new SWTScrollView()).alloc(); + scrollWidget.initWithFrame(NSRect ()); if ((style & DWT.H_SCROLL) !is 0) scrollWidget.setHasHorizontalScroller(true); if ((style & DWT.V_SCROLL) !is 0) scrollWidget.setHasVerticalScroller(true); scrollWidget.setAutohidesScrollers(true); scrollWidget.setBorderType((style & DWT.BORDER) !is 0 ? OS.NSBezelBorder : OS.NSNoBorder); - NSTableView widget = cast(NSTableView)new SWTTableView().alloc(); + NSTableView widget = cast(NSTableView)(new SWTTableView()).alloc(); widget.initWithFrame(NSRect()); widget.setAllowsMultipleSelection((style & DWT.MULTI) !is 0); widget.setDataSource(widget); @@ -279,7 +286,7 @@ widget.setDoubleAction(OS.sel_sendDoubleSelection); if (!hasBorder()) widget.setFocusRingType(OS.NSFocusRingTypeNone); - column = cast(NSTableColumn)new NSTableColumn().alloc(); + column = cast(NSTableColumn)(new NSTableColumn()).alloc(); column.initWithIdentifier(NSString.stringWith("")); widget.addTableColumn (column); @@ -432,7 +439,7 @@ */ public int getFocusIndex () { checkWidget(); - return (int)/*64*/((NSTableView)view).selectedRow(); + return cast(int)/*64*/(cast(NSTableView)view).selectedRow(); } /** @@ -533,12 +540,12 @@ return new String [0]; } NSIndexSet selection = widget.selectedRowIndexes(); - int count = (int)/*64*/selection.count(); - int /*long*/ [] indexBuffer = new int /*long*/ [count]; - selection.getIndexes(indexBuffer, count, 0); + NSUInteger count = selection.count(); + NSUInteger [] indexBuffer = new NSUInteger [count]; + selection.getIndexes(indexBuffer.ptr, count, 0); String [] result = new String [count]; - for (int i=0; i<count; i++) { - result [i] = items [(int)/*64*/indexBuffer [i]]; + for (NSUInteger i=0; i<count; i++) { + result [i] = items [indexBuffer [i]]; } return result; } @@ -571,15 +578,15 @@ */ public int getSelectionIndex () { checkWidget(); - NSTableView widget = (NSTableView)view; + NSTableView widget = cast(NSTableView)view; if (widget.numberOfSelectedRows() is 0) { return -1; } NSIndexSet selection = widget.selectedRowIndexes(); - int count = (int)/*64*/selection.count(); - int /*long*/ [] result = new int /*long*/ [count]; - selection.getIndexes(result, count, 0); - return (int)/*64*/result [0]; + NSUInteger count = selection.count(); + NSUInteger [] result = NSUInteger [count]; + selection.getIndexes(result.ptr, count, 0); + return cast(int) NSUInteger [0]; } /** @@ -605,14 +612,14 @@ return new int [0]; } NSIndexSet selection = widget.selectedRowIndexes(); - int count = (int)/*64*/selection.count(); - int /*long*/ [] indices = new int /*long*/ [count]; + NSUInteger count = selection.count(); + NSUInteger [] indices = new NSUInteger [count]; selection.getIndexes(indices, count, 0); - int [] result = new int [count]; - for (int i = 0; i < result.length; i++) { - result [i] = (int)/*64*/indices [i]; + NSUInteger [] result = new NSUInteger [count]; + for (NSUInteger i = 0; i < result.length; i++) { + result [i] = indices [i]; } - return result; + return cast(int[]) result; } /** @@ -634,7 +641,7 @@ NSPoint point = NSPoint(); point.x = rect.x; point.y = rect.y; - int result = (int)/*64*/(cast(NSTableView)view).rowAtPoint(point); + int result = cast(int)/*64*/(cast(NSTableView)view).rowAtPoint(point); if (result is -1) result = 0; return result; } @@ -714,7 +721,7 @@ return (cast(NSTableView)view).isRowSelected(index); } -int /*long*/ numberOfRowsInTableView(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView) { +int numberOfRowsInTableView(objc.id id, objc.SEL sel, objc.id aTableView) { return itemCount; } @@ -894,7 +901,7 @@ public void select (int index) { checkWidget(); if (0 <= index && index < itemCount) { - NSIndexSet indexes = cast(NSIndexSet)new NSIndexSet().alloc(); + NSIndexSet indexes = cast(NSIndexSet)(new NSIndexSet()).alloc(); indexes.initWithIndex(index); NSTableView widget = cast(NSTableView)view; ignoreSelect = true; @@ -935,7 +942,7 @@ start = Math.max (0, start); end = Math.min (end, itemCount - 1); int length = end - start + 1; - NSIndexSet indexes = cast(NSIndexSet)new NSIndexSet().alloc(); + NSIndexSet indexes = cast(NSIndexSet)(new NSIndexSet()).alloc(); NSRange range = NSRange(); range.location = start; range.length = length; @@ -975,7 +982,7 @@ int length = indices.length; if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; int count = 0; - NSMutableIndexSet indexes = cast(NSMutableIndexSet)new NSMutableIndexSet().alloc().init(); + NSMutableIndexSet indexes = cast(NSMutableIndexSet)(new NSMutableIndexSet()).alloc().init(); for (int i=0; i<length; i++) { int index = indices [i]; if (index >= 0 && index < itemCount) { @@ -992,7 +999,7 @@ } void select (int [] ids, int count, bool clear) { - NSMutableIndexSet indexes = cast(NSMutableIndexSet)new NSMutableIndexSet().alloc().init(); + NSMutableIndexSet indexes = cast(NSMutableIndexSet)(new NSMutableIndexSet()).alloc().init(); for (int i=0; i<count; i++) indexes.addIndex (ids [i] - 1); //WRONG -1 NSTableView widget = cast(NSTableView)view; ignoreSelect = true; @@ -1038,7 +1045,7 @@ return result; } -void setBackground (float [] color) { +void setBackground (CGFloat [] color) { super.setBackground (color); NSColor nsColor; if (color is null) { @@ -1046,14 +1053,14 @@ } else { nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1); } - ((NSTableView) view).setBackgroundColor (nsColor); + (cast(NSTableView) view).setBackgroundColor (nsColor); } void setFont (NSFont font) { super.setFont (font); - float ascent = font.ascender (); - float descent = -font.descender () + font.leading (); - ((NSTableView)view).setRowHeight ((int)Math.ceil (ascent + descent) + 1); + CGFloat ascent = font.ascender (); + CGFloat descent = -font.descender () + font.leading (); + (cast(NSTableView)view).setRowHeight (cast(int)Math.ceil (ascent + descent) + 1); } /** @@ -1074,7 +1081,7 @@ */ public void setItem (int index, String string) { checkWidget(); - if (string is null) error (DWT.ERROR_NULL_ARGUMENT); + //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); if (!(0 <= index && index < itemCount)) error (DWT.ERROR_INVALID_RANGE); items [index] = string; (cast(NSTableView)view).reloadData(); @@ -1130,7 +1137,7 @@ void setSelection (int index, bool notify) { // checkWidget(); if (0 <= index && index < itemCount) { - int [] ids = new int [] {index + 1}; + int [] ids = [index + 1]; select (ids, ids.length, true); showIndex (index); if (notify) postEvent (DWT.Selection); @@ -1249,7 +1256,7 @@ int index = indexOf (string, 0); if (index !is -1) { count = 1; - ids = new int [] {index + 1}; + ids = [index + 1]; } } else { int index = 0; @@ -1310,16 +1317,16 @@ if (index >= 0) showIndex (index); } -void tableViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { +void tableViewSelectionDidChange (objc.id id, objc.SEL sel, objc.id aNotification) { if (ignoreSelect) return; postEvent (DWT.Selection); } -bool tableView_shouldEditTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) { +bool tableView_shouldEditTableColumn_row(objc.id id, objc.SEL sel, objc.id aTableView, objc.id aTableColumn, objc.id rowIndex) { return false; } -int /*long*/ tableView_objectValueForTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) { +objc.id tableView_objectValueForTableColumn_row(objc.id id, objc.SEL sel, objc.id aTableView, objc.id aTableColumn, objc.id rowIndex) { NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); if (foreground !is null) { NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1); @@ -1328,12 +1335,12 @@ if (font !is null) { dict.setObject(font.handle, OS.NSFontAttributeName); } - String text = items[(int)/*64*/rowIndex]; - int length = text.length(); - char[] chars = new char[length]; + String text = items[cast(size_t)rowIndex]; + int length_ = text.length(); + char[] chars = new char[length_]; text.getChars(0, length, chars, 0); NSString str = NSString.stringWithCharacters(chars, length); - NSAttributedString attribStr = (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_(str, dict); + NSAttributedString attribStr = (cast(NSAttributedString)(new NSAttributedString()).alloc()).initWithString_(str, dict); return attribStr.id; }