Mercurial > projects > dwt-mac
changeset 80:b24476d6dedf
Ported dwt.widgets.Table
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 24 Dec 2008 22:50:11 +0100 |
parents | 0dc55b17c290 |
children | 97f1b638de63 |
files | dwt/internal/cocoa/OS.d dwt/widgets/Table.d dwt/widgets/Widget.d |
diffstat | 3 files changed, 136 insertions(+), 123 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/internal/cocoa/OS.d Wed Dec 24 13:18:04 2008 +0100 +++ b/dwt/internal/cocoa/OS.d Wed Dec 24 22:50:11 2008 +0100 @@ -65,6 +65,7 @@ import dwt.internal.cocoa.NSScroller; import dwt.internal.cocoa.NSSize; import dwt.internal.cocoa.NSString; +import dwt.internal.cocoa.NSTableView; import dwt.internal.cocoa.NSText; import dwt.internal.cocoa.NSView; import NSWindowTypes = dwt.internal.cocoa.NSWindow; @@ -3457,7 +3458,7 @@ public static const int NSTableViewFirstColumnOnlyAutoresizingStyle = 5; public static const int NSTableViewGridNone = 0; public static const int NSTableViewLastColumnOnlyAutoresizingStyle = 4; -public static const int NSTableViewNoColumnAutoresizing = 0; +alias NSTableViewColumnAutoresizingStyle.NSTableViewNoColumnAutoresizing NSTableViewNoColumnAutoresizing; public static const int NSTableViewReverseSequentialColumnAutoresizingStyle = 3; public static const int NSTableViewSelectionHighlightStyleRegular = 0; public static const int NSTableViewSelectionHighlightStyleSourceList = 1;
--- a/dwt/widgets/Table.d Wed Dec 24 13:18:04 2008 +0100 +++ b/dwt/widgets/Table.d Wed Dec 24 22:50:11 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.Table; @@ -55,7 +58,16 @@ import dwt.internal.cocoa.SWTTableHeaderCell; import dwt.internal.cocoa.SWTTableHeaderView; 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.Event; +import dwt.widgets.TableColumn; +import dwt.widgets.TableItem; +import dwt.widgets.TypedListener; /** * Instances of this class implement a selectable user interface @@ -155,11 +167,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; } @@ -281,7 +293,7 @@ TableItem item = items [index]; if (item !is null) { item.clear (); - NSTableView widget = (NSTableView) view; + NSTableView widget = cast(NSTableView) view; widget.reloadData (); } } @@ -321,7 +333,7 @@ TableItem item = items [i]; if (item !is null) item.clear (); } - NSTableView widget = (NSTableView) view; + NSTableView widget = cast(NSTableView) view; widget.reloadData (); } } @@ -361,7 +373,7 @@ TableItem item = items [indices [i]]; if (item !is null) item.clear (); } - NSTableView widget = (NSTableView) view; + NSTableView widget = cast(NSTableView) view; widget.reloadData (); } @@ -387,7 +399,7 @@ TableItem item = items [i]; if (item !is null) item.clear (); } - NSTableView widget = (NSTableView) view; + NSTableView widget = cast(NSTableView) view; widget.reloadData (); } @@ -428,14 +440,14 @@ } void createHandle () { - NSScrollView scrollWidget = (NSScrollView)new SWTScrollView().alloc(); - scrollWidget.initWithFrame(new NSRect ()); + NSScrollView scrollWidget = cast(NSScrollView)(new SWTScrollView()).alloc(); + scrollWidget.initWithFrame(NSRect ()); scrollWidget.setHasHorizontalScroller(true); scrollWidget.setHasVerticalScroller(true); scrollWidget.setAutohidesScrollers(true); scrollWidget.setBorderType(hasBorder() ? 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.setAllowsColumnReordering (false); @@ -444,16 +456,16 @@ widget.setDoubleAction(OS.sel_sendDoubleSelection); if (!hasBorder()) widget.setFocusRingType(OS.NSFocusRingTypeNone); - headerView = (NSTableHeaderView)new SWTTableHeaderView ().alloc ().init (); + headerView = cast(NSTableHeaderView)(new SWTTableHeaderView ()).alloc ().init (); widget.setHeaderView (null); NSString str = NSString.stringWith(""); if ((style & DWT.CHECK) !is 0) { - checkColumn = cast(NSTableColumn)new NSTableColumn().alloc(); + checkColumn = cast(NSTableColumn)(new NSTableColumn()).alloc(); checkColumn.initWithIdentifier(checkColumn); checkColumn.headerCell().setTitle(str); widget.addTableColumn (checkColumn); - NSButtonCell cell = cast(NSButtonCell)new NSButtonCell().alloc().init(); + NSButtonCell cell = cast(NSButtonCell)(new NSButtonCell()).alloc().init(); checkColumn.setDataCell(cell); cell.setButtonType(OS.NSSwitchButton); cell.setImagePosition(OS.NSImageOnly); @@ -464,7 +476,7 @@ checkColumn.setEditable(false); } - firstColumn = cast(NSTableColumn)new NSTableColumn().alloc(); + firstColumn = cast(NSTableColumn)(new NSTableColumn()).alloc(); firstColumn.initWithIdentifier(firstColumn); firstColumn.setMinWidth(0); //column.setResizingMask(OS.NSTableColumnAutoresizingMask); @@ -491,7 +503,7 @@ firstColumn = null; } else { //TODO - set attributes, alignment etc. - nsColumn = cast(NSTableColumn)new NSTableColumn().alloc(); + nsColumn = cast(NSTableColumn)(new NSTableColumn()).alloc(); nsColumn.initWithIdentifier(nsColumn); nsColumn.setMinWidth(0); int checkColumn = (style & DWT.CHECK) !is 0 ? 1 : 0; @@ -499,7 +511,7 @@ nsColumn.setDataCell (dataCell); } column.createJNIRef (); - NSTableHeaderCell headerCell = (NSTableHeaderCell)new SWTTableHeaderCell ().alloc ().init (); + NSTableHeaderCell headerCell = cast(NSTableHeaderCell)(new SWTTableHeaderCell ()).alloc ().init (); nsColumn.setHeaderCell (headerCell); display.addWidget (headerCell, column); column.nsColumn = nsColumn; @@ -754,7 +766,7 @@ } } - int oldIndex = (int)/*64*/((NSTableView)view).columnWithIdentifier (column.nsColumn); + NSInteger oldIndex = (cast(NSTableView)view).columnWithIdentifier (column.nsColumn); if (columnCount is 1) { //TODO - reset attributes @@ -766,10 +778,10 @@ System.arraycopy (columns, index + 1, columns, index, --columnCount - index); columns [columnCount] = null; - NSArray array = ((NSTableView)view).tableColumns (); - int arraySize = (int)/*64*/array.count (); - for (int i = oldIndex; i < arraySize; i++) { - int /*long*/ columnId = array.objectAtIndex (i).id; + NSArray array = (cast(NSTableView)view).tableColumns (); + NSUInteger arraySize = array.count (); + for (NSUInteger i = oldIndex; i < arraySize; i++) { + objc.id columnId = array.objectAtIndex (i).id; for (int j = 0; j < columnCount; j++) { if (columns[j].nsColumn.id is columnId) { columns [j].sendEvent (DWT.Move); @@ -796,20 +808,20 @@ } } -void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, int /*long*/ cellFrame, int /*long*/ view) { - NSRect rect = new NSRect (); +void drawInteriorWithFrame_inView (objc.id id, objc.SEL sel, objc.id cellFrame, objc.id view) { + NSRect rect = NSRect (); OS.memmove (rect, cellFrame, NSRect.sizeof); - NSTableView tableView = (NSTableView)this.view; + NSTableView tableView = cast(NSTableView)this.view; NSBrowserCell cell = new NSBrowserCell (id); NSRange rowsRange = tableView.rowsInRect (rect); - int rowIndex = (int)/*64*/rowsRange.location; + NSUInteger rowIndex = rowsRange.location; TableItem item = items [rowIndex]; int columnIndex = 0; - int nsColumnIndex = 0; + NSUInteger nsColumnIndex = 0; if (columnCount !is 0) { NSIndexSet columnsSet = tableView.columnIndexesInRect (rect); - nsColumnIndex = (int)/*64*/columnsSet.firstIndex (); + nsColumnIndex = columnsSet.firstIndex (); NSArray nsColumns = tableView.tableColumns (); id nsColumn = nsColumns.objectAtIndex (nsColumnIndex); for (int i = 0; i < columnCount; i++) { @@ -840,7 +852,7 @@ nsSelectionBackground = nsSelectionBackground.colorUsingColorSpace (NSColorSpace.deviceRGBColorSpace ()); } - NSRect fullRect = new NSRect (); + NSRect fullRect = NSRect (); fullRect.x = rect.x; fullRect.y = rect.y; fullRect.height = rect.height; if (columnCount is 0) { if (item.customWidth !is -1) { @@ -859,7 +871,7 @@ // TODO how to handle rearranged columns? The third clause below ensures that // there are either 0 columns or that column 0 is still the first physical column. if (columnIndex is 0 && (style & DWT.CHECK) !is 0 && (columnCount is 0 || tableView.columnWithIdentifier (columns[0].nsColumn) is 1)) { - eraseItemRect = new NSRect (); + eraseItemRect = NSRect (); eraseItemRect.y = fullRect.y; eraseItemRect.width = fullRect.x + fullRect.width; eraseItemRect.height = fullRect.height; @@ -871,11 +883,11 @@ GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); if (isSelected) { - float /*double*/[] components = new float /*double*/[(int)/*64*/nsSelectionForeground.numberOfComponents ()]; + CGFloat[] components = [nsSelectionForeground.numberOfComponents ()]; nsSelectionForeground.getComponents (components); Color selectionForeground = Color.cocoa_new (display, components); gc.setForeground (selectionForeground); - components = new float /*double*/[(int)/*64*/nsSelectionBackground.numberOfComponents ()]; + components = [nsSelectionBackground.numberOfComponents ()]; nsSelectionBackground.getComponents (components); Color selectionBackground = Color.cocoa_new (display, components); gc.setBackground (selectionBackground); @@ -891,10 +903,10 @@ event.detail = DWT.FOREGROUND; if (drawBackground) event.detail |= DWT.BACKGROUND; if (isSelected) event.detail |= DWT.SELECTED; - event.x = (int)eraseItemRect.x; - event.y = (int)eraseItemRect.y; - event.width = (int)eraseItemRect.width; - event.height = (int)eraseItemRect.height; + event.x = cast(int)eraseItemRect.x; + event.y = cast(int)eraseItemRect.y; + event.width = cast(int)eraseItemRect.width; + event.height = cast(int)eraseItemRect.height; sendEvent (DWT.EraseItem, event); gc.dispose (); if (item.isDisposed ()) return; @@ -907,7 +919,7 @@ } if (drawSelection) { - NSRect selectionRect = new NSRect (); + NSRect selectionRect = NSRect (); selectionRect.y = rect.y; selectionRect.height = rect.height; if (columnCount > 0) { NSRect columnRect = tableView.rectOfColumn (nsColumnIndex); @@ -916,7 +928,7 @@ NSRect rowRect = tableView.rectOfRow (rowIndex); if ((style & DWT.CHECK) !is 0) { /* highlighting at this stage draws over the checkbox, so don't include its column */ - int checkWidth = (int)/*64*/checkColumn.width (); + CGFloat checkWidth = checkColumn.width (); selectionRect.x = checkWidth; selectionRect.width = rowRect.width - checkWidth; } else { @@ -930,7 +942,7 @@ if (drawBackground && !drawSelection) { NSGraphicsContext context = NSGraphicsContext.currentContext (); context.saveGraphicsState (); - float[] colorRGB = background.handle; + CGFloat[] colorRGB = background.handle; NSColor color = NSColor.colorWithDeviceRed (colorRGB[0], colorRGB[1], colorRGB[2], 1f); color.setFill (); NSBezierPath.fillRect (fullRect); @@ -950,7 +962,7 @@ // TODO how to handle rearranged columns? The third clause below ensures that // there are either 0 columns or that column 0 is still the first physical column. if (columnIndex is 0 && (style & DWT.CHECK) !is 0 && (columnCount is 0 || tableView.columnWithIdentifier (columns[0].nsColumn) is 1)) { - NSRect gcRect = new NSRect (); + NSRect gcRect = NSRect (); gcRect.y = fullRect.y; gcRect.width = fullRect.x + fullRect.width; gcRect.height = fullRect.height; @@ -961,11 +973,11 @@ GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); if (isSelected) { - float /*double*/[] components = new float /*double*/[(int)/*64*/nsSelectionForeground.numberOfComponents ()]; + CGFloat[] components = [nsSelectionForeground.numberOfComponents ()]; nsSelectionForeground.getComponents (components); Color selectionForeground = Color.cocoa_new (display, components); gc.setForeground (selectionForeground); - components = new float /*double*/[(int)/*64*/nsSelectionBackground.numberOfComponents ()]; + components = [nsSelectionBackground.numberOfComponents ()]; nsSelectionBackground.getComponents (components); Color selectionBackground = Color.cocoa_new (display, components); gc.setBackground (selectionBackground); @@ -980,10 +992,10 @@ event.gc = gc; event.index = columnIndex; if (isSelected) event.detail |= DWT.SELECTED; - event.x = (int)contentRect.x; - event.y = (int)contentRect.y; - event.width = (int)Math.ceil (contentSize.width); - event.height = (int)Math.ceil (fullRect.height); + event.x = cast(int)contentRect.x; + event.y = cast(int)contentRect.y; + event.width = cast(int)Math.ceil (contentSize.width); + event.height = cast(int)Math.ceil (fullRect.height); sendEvent (DWT.PaintItem, event); gc.dispose (); } @@ -1013,7 +1025,7 @@ return 20; //TODO - compute width } -TableColumn getColumn (id id) { +TableColumn getColumn (cocoa.id id) { for (int i = 0; i < columnCount; i++) { if (columns[i].nsColumn.id is id.id) { return columns[i]; @@ -1107,7 +1119,7 @@ int [] order = new int [columnCount]; for (int i = 0; i < columnCount; i++) { TableColumn column = columns [i]; - int index = ((NSTableView)view).columnWithIdentifier (column.nsColumn); + int index = (cast(NSTableView)view).columnWithIdentifier (column.nsColumn); if ((style & DWT.CHECK) !is 0) index -= 1; order [index] = i; } @@ -1255,7 +1267,7 @@ */ public TableItem getItem (Point point) { checkWidget (); - NSTableView widget = (NSTableView)view; + NSTableView widget = cast(NSTableView)view; NSPoint pt = NSPoint(); pt.x = point.x; pt.y = point.y; @@ -1343,7 +1355,7 @@ */ public bool getLinesVisible () { checkWidget (); - return ((NSTableView)view).usesAlternatingRowBackgroundColors(); + return (cast(NSTableView)view).usesAlternatingRowBackgroundColors(); } /** @@ -1369,12 +1381,12 @@ return new TableItem [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, null); TableItem [] result = new TableItem [count]; - for (int i=0; i<count; i++) { - result [i] = _getItem ((int)/*64*/indexBuffer [i]); + for (NSUInteger i=0; i<count; i++) { + result [i] = _getItem (cast(int)/*64*/indexBuffer [i]); } return result; } @@ -1407,15 +1419,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 = new NSUInteger [count]; + selection.getIndexes(result.ptr, count, null); + return cast(int)/*64*/result [0]; } /** @@ -1441,12 +1453,12 @@ 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 < indices.length; i++) { - result [i] = (int)/*64*/indices [i]; + result [i] = cast(int)/*64*/indices [i]; } return result; } @@ -1512,13 +1524,13 @@ NSPoint point = NSPoint(); point.x = rect.x; point.y = rect.y; - return csat(int)/*64*/(cast(NSTableView)view).rowAtPoint(point); + return cast(int)/*64*/(cast(NSTableView)view).rowAtPoint(point); } -void highlightSelectionInClipRect(int /*long*/ id, int /*long*/ sel, int /*long*/ rect) { +void highlightSelectionInClipRect(objc.id id, objc.SEL sel, objc.id rect) { if (!hooks (DWT.EraseItem)) { - NSRect clipRect = new NSRect (); - OS.memmove (clipRect, rect, NSRect.sizeof); + NSRect clipRect = NSRect (); + OS.memmove (&clipRect, rect, NSRect.sizeof); callSuper (id, sel, clipRect); } } @@ -1610,8 +1622,8 @@ return view.id is headerView.id; } -int /*long*/ numberOfRowsInTableView(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView) { - return itemCount; +objc.id numberOfRowsInTableView(objc.id id, objc.SEL sel, objc.id aTableView) { + return cast(objc.id )itemCount; } void register () { @@ -1814,7 +1826,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; @@ -1856,7 +1868,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; @@ -1897,7 +1909,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) { @@ -1914,7 +1926,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; @@ -1942,7 +1954,7 @@ ignoreSelect = false; } -void setBackground (float [] color) { +void setBackground (CGFloat [] color) { super.setBackground (color); NSColor nsColor; if (color is null) { @@ -1950,7 +1962,7 @@ } else { nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1); } - ((NSTableView) view).setBackgroundColor (nsColor); + (cast(NSTableView) view).setBackgroundColor (nsColor); } /** @@ -1996,12 +2008,12 @@ if (order [i] !is oldOrder [i]) reorder = true; } if (reorder) { - NSTableView tableView = (NSTableView)view; + NSTableView tableView = cast(NSTableView)view; int [] oldX = new int [oldOrder.length]; int check = (style & DWT.CHECK) !is 0 ? 1 : 0; for (int i=0; i<oldOrder.length; i++) { int index = oldOrder[i]; - oldX [index] = (int)tableView.rectOfColumn (i + check).x; + oldX [index] = cast(int)tableView.rectOfColumn (i + check).x; } int [] newX = new int [order.length]; for (int i=0; i<order.length; i++) { @@ -2010,7 +2022,7 @@ int oldIndex = tableView.columnWithIdentifier (column.nsColumn); int newIndex = i + check; tableView.moveColumn (oldIndex, newIndex); - newX [index] = (int)tableView.rectOfColumn (newIndex).x; + newX [index] = cast(int)tableView.rectOfColumn (newIndex).x; } TableColumn[] newColumns = new TableColumn [columnCount]; System.arraycopy (columns, 0, newColumns, 0, columnCount); @@ -2030,7 +2042,7 @@ if (!hooks (DWT.MeasureItem)) { float ascent = font.ascender (); float descent = -font.descender () + font.leading (); - ((NSTableView)view).setRowHeight ((int)Math.ceil (ascent + descent) + 1); + (cast(NSTableView)view).setRowHeight (cast(int)Math.ceil (ascent + descent) + 1); } else { view.setNeedsDisplay (true); } @@ -2097,7 +2109,7 @@ children = newItems; this.items = newItems; this.itemCount = count; - ((NSTableView) view).noteNumberOfRowsChanged (); + (cast(NSTableView) view).noteNumberOfRowsChanged (); } /*public*/ void setItemHeight (int itemHeight) { @@ -2144,7 +2156,7 @@ } bool setScrollWidth (TableItem item, bool callMeasureItem) { - return setScrollWidth (new TableItem[] {item}, callMeasureItem); + return setScrollWidth ([item], callMeasureItem); } bool setScrollWidth (TableItem items[], bool callMeasureItem) { @@ -2169,8 +2181,8 @@ gc.dispose (); newWidth += getInsetWidth (); if (firstColumn.width () < newWidth) { - NSTableView tableView = (NSTableView)view; - int /*long*/ oldResize = tableView.columnAutoresizingStyle (); + NSTableView tableView = cast(NSTableView)view; + NSTableViewColumnAutoresizingStyle oldResize = tableView.columnAutoresizingStyle (); tableView.setColumnAutoresizingStyle (OS.NSTableViewNoColumnAutoresizing); firstColumn.setWidth (newWidth); tableView.setColumnAutoresizingStyle (oldResize); @@ -2303,7 +2315,7 @@ public void setSelection (TableItem item) { checkWidget (); if (item is null) error (DWT.ERROR_NULL_ARGUMENT); - setSelection (new TableItem [] {item}); + setSelection ([item]); } /** @@ -2375,15 +2387,15 @@ TableColumn oldSortColumn = sortColumn; sortColumn = column; if (sortDirection is DWT.NONE) return; - NSTableHeaderView headerView = ((NSTableView)view).headerView (); + NSTableHeaderView headerView = (cast(NSTableView)view).headerView (); if (headerView is null) return; if (oldSortColumn !is null) { - NSInteger index = ((NSTableView)view).columnWithIdentifier (oldSortColumn.nsColumn); + NSInteger index = (cast(NSTableView)view).columnWithIdentifier (oldSortColumn.nsColumn); NSRect rect = headerView.headerRectOfColumn (index); headerView.setNeedsDisplayInRect (rect); } if (sortColumn !is null) { - int /*long*/ index = ((NSTableView)view).columnWithIdentifier (sortColumn.nsColumn); + NSInteger index = (cast(NSTableView)view).columnWithIdentifier (sortColumn.nsColumn); NSRect rect = headerView.headerRectOfColumn (index); headerView.setNeedsDisplayInRect (rect); } @@ -2408,9 +2420,9 @@ if (direction is sortDirection) return; sortDirection = direction; if (sortColumn is null) return; - NSTableHeaderView headerView = ((NSTableView)view).headerView (); + NSTableHeaderView headerView = (cast(NSTableView)view).headerView (); if (headerView is null) return; - int /*long*/ index = ((NSTableView)view).columnWithIdentifier (sortColumn.nsColumn); + NSInteger index = (cast(NSTableView)view).columnWithIdentifier (sortColumn.nsColumn); NSRect rect = headerView.headerRectOfColumn (index); headerView.setNeedsDisplayInRect (rect); } @@ -2462,9 +2474,9 @@ if (column.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT); if (column.parent !is this) return; if (columnCount <= 1) return; - int index = (int)/*64*/((NSTableView)view).columnWithIdentifier (column.nsColumn); + int index = cast(int)/*64*/(cast(NSTableView)view).columnWithIdentifier (column.nsColumn); if (!(0 <= index && index < columnCount + ((style & DWT.CHECK) !is 0 ? 1 : 0))) return; - ((NSTableView)view).scrollColumnToVisible (index); + (cast(NSTableView)view).scrollColumnToVisible (index); } void showIndex (int index) { @@ -2525,7 +2537,7 @@ bool result = super.sendKeyEvent (nsEvent, type); if (!result) return result; if (type !is DWT.KeyDown) return result; - short keyCode = nsEvent.keyCode (); + ushort keyCode = nsEvent.keyCode (); switch (keyCode) { case 76: /* KP Enter */ case 36: { /* Return */ @@ -2536,19 +2548,19 @@ return result; } -void tableViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { +void tableViewColumnDidMove (objc.id id, objc.SEL sel, objc.id aNotification) { NSNotification notification = new NSNotification (aNotification); NSDictionary userInfo = notification.userInfo (); id nsOldIndex = userInfo.valueForKey (NSString.stringWith ("NSOldColumn")); //$NON-NLS-1$ id nsNewIndex = userInfo.valueForKey (NSString.stringWith ("NSNewColumn")); //$NON-NLS-1$ - int oldIndex = new NSNumber (nsOldIndex).intValue (); - int newIndex = new NSNumber (nsNewIndex).intValue (); + int oldIndex = (new NSNumber (nsOldIndex)).intValue (); + int newIndex = (new NSNumber (nsNewIndex)).intValue (); int startIndex = Math.min (oldIndex, newIndex); int endIndex = Math.max (oldIndex, newIndex); - NSTableView tableView = (NSTableView)view; + NSTableView tableView = cast(NSTableView)view; NSArray nsColumns = tableView.tableColumns (); for (int i = startIndex; i <= endIndex; i++) { - id columnId = nsColumns.objectAtIndex (i); + cocoa.id columnId = nsColumns.objectAtIndex (i); TableColumn column = getColumn (columnId); if (column !is null) { column.sendEvent (DWT.Move); @@ -2557,7 +2569,7 @@ } } -void tableViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { +void tableViewColumnDidResize (objc.id id, objc.SEL sel, objc.id aNotification) { NSNotification notification = new NSNotification (aNotification); NSDictionary userInfo = notification.userInfo (); id columnId = userInfo.valueForKey (NSString.stringWith ("NSTableColumn")); //$NON-NLS-1$ @@ -2567,12 +2579,12 @@ column.sendEvent (DWT.Resize); if (isDisposed ()) return; - NSTableView tableView = (NSTableView)view; - int index = (int)/*64*/tableView.columnWithIdentifier (columnId); + NSTableView tableView = cast(NSTableView)view; + int index = cast(int)/*64*/tableView.columnWithIdentifier (columnId); if (index is -1) return; /* column was disposed in Resize callback */ NSArray nsColumns = tableView.tableColumns (); - int columnCount = (int)/*64*/tableView.numberOfColumns (); + int columnCount = cast(int)/*64*/tableView.numberOfColumns (); for (int i = index + 1; i < columnCount; i++) { columnId = nsColumns.objectAtIndex (i); column = getColumn (columnId); @@ -2583,10 +2595,10 @@ } } -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; NSTableView widget = cast(NSTableView) view; - int row = (int)/*64*/widget.selectedRow (); + int row = cast(int)/*64*/widget.selectedRow (); if(row is -1) postEvent (DWT.Selection); else { @@ -2598,13 +2610,13 @@ } } -void tableView_didClickTableColumn (int /*long*/ id, int /*long*/ sel, int /*long*/ tableView, int /*long*/ tableColumn) { +void tableView_didClickTableColumn (objc.id id, objc.SEL sel, objc.id tableView, objc.id tableColumn) { TableColumn column = getColumn (new id (tableColumn)); column.postEvent (DWT.Selection); } -int /*long*/ tableView_objectValueForTableColumn_row (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) { - TableItem item = _getItem ((int)/*64*/rowIndex); +objc.id tableView_objectValueForTableColumn_row (objc.id id, objc.SEL sel, objc.id aTableView, objc.id aTableColumn, objc.id rowIndex) { + TableItem item = _getItem (cast(int)/*64*/rowIndex); if (checkColumn !is null && aTableColumn is checkColumn.id) { NSNumber value; if (item.checked && item.grayed) { @@ -2622,28 +2634,28 @@ return item.createString (0).id; } -void tableView_setObjectValue_forTableColumn_row (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ anObject, int /*long*/ aTableColumn, int /*long*/ rowIndex) { +void tableView_setObjectValue_forTableColumn_row (objc.id id, objc.SEL sel, objc.id aTableView, objc.id anObject, objc.id aTableColumn, objc.id rowIndex) { if (checkColumn !is null && aTableColumn is checkColumn.id) { - TableItem item = items [(int)/*64*/rowIndex]; + TableItem item = items [cast(int)/*64*/rowIndex]; item.checked = !item.checked; Event event = new Event (); event.detail = DWT.CHECK; event.item = item; - event.index = (int)/*64*/rowIndex; + event.index = cast(int)/*64*/rowIndex; postEvent (DWT.Selection, event); - NSTableView tableView = (NSTableView)view; + NSTableView tableView = cast(NSTableView)view; NSRect rect = tableView.rectOfRow (rowIndex); tableView.setNeedsDisplayInRect (rect); } } -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; } -void tableView_willDisplayCell_forTableColumn_row (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aCell, int /*long*/ aTableColumn, int /*long*/ rowIndex) { +void tableView_willDisplayCell_forTableColumn_row (objc.id id, objc.SEL sel, objc.id aTableView, objc.id aCell, objc.id aTableColumn, objc.id rowIndex) { if (checkColumn !is null && aTableColumn is checkColumn.id) return; - TableItem item = items [(int)/*64*/rowIndex]; + TableItem item = items [cast(int)/*64*/rowIndex]; Image image = item.image; int columnIndex = 0; for (int i=0; i<columnCount; i++) { @@ -2658,8 +2670,8 @@ cell.setLeaf (true); if (hooks (DWT.MeasureItem)) { - NSTableView tableView = (NSTableView)this.view; - int nsColumnIndex = (int)/*64*/tableView.columnWithIdentifier (new id (aTableColumn)); + NSTableView tableView = cast(NSTableView)this.view; + NSInteger nsColumnIndex = tableView.columnWithIdentifier (new cocoa.id (aTableColumn)); NSRect rect = tableView.frameOfCellAtColumn (nsColumnIndex, rowIndex); NSRect contentRect = cell.titleRectForBounds (rect); NSSize contentSize = cell.cellSizeForBounds (rect); @@ -2668,14 +2680,14 @@ data.paintRect = tableView.frame (); GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); - int rowHeight = (int)tableView.rowHeight (); + int rowHeight = cast(int)tableView.rowHeight (); Event event = new Event (); event.item = item; event.gc = gc; event.index = columnIndex; - event.x = (int)contentRect.x; - event.y = (int)contentRect.y; - event.width = (int)Math.ceil (contentSize.width); + event.x = cast(int)contentRect.x; + event.y = cast(int)contentRect.y; + event.width = cast(int)Math.ceil (contentSize.width); event.height = rowHeight; sendEvent (DWT.MeasureItem, event); gc.dispose (); @@ -2684,8 +2696,8 @@ tableView.setRowHeight(event.height); } if (columnCount is 0) { - int change = event.width - (item.customWidth !is -1 ? item.customWidth : (int)Math.ceil (contentSize.width)); - if (item.customWidth !is -1 || event.width !is (int)Math.ceil (contentSize.width)) { + int change = event.width - (item.customWidth !is -1 ? item.customWidth : cast(int)Math.ceil (contentSize.width)); + if (item.customWidth !is -1 || event.width !is cast(int)Math.ceil (contentSize.width)) { item.customWidth = event.width; } if (change !is 0) setScrollWidth (item, false);
--- a/dwt/widgets/Widget.d Wed Dec 24 13:18:04 2008 +0100 +++ b/dwt/widgets/Widget.d Wed Dec 24 22:50:11 2008 +0100 @@ -884,8 +884,8 @@ void menuWillOpen(objc.id id, objc.SEL sel, objc.id menu) { } -NSInteger numberOfRowsInTableView(objc.id id, objc.SEL sel, objc.id aTableView) { - return 0; +objc.id numberOfRowsInTableView(objc.id id, objc.SEL sel, objc.id aTableView) { + return cast(objc.id )0; } objc.id outlineView_child_ofItem(objc.id id, objc.SEL sel, objc.id outlineView, objc.id index, objc.id item) {