# HG changeset patch # User Jacob Carlborg # Date 1230155411 -3600 # Node ID b24476d6dedf9e93f247845284222ff098fa1f12 # Parent 0dc55b17c2902811d3c7f8036fe47ac5f6c64c60 Ported dwt.widgets.Table diff -r 0dc55b17c290 -r b24476d6dedf dwt/internal/cocoa/OS.d --- 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; diff -r 0dc55b17c290 -r b24476d6dedf dwt/widgets/Table.d --- 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 *******************************************************************************/ 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 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= 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