# HG changeset patch # User Jacob Carlborg # Date 1230650545 -3600 # Node ID 4e8317766ba0df346b6c6ed8d7fccd9901dbe565 # Parent 102ff2adce19dbbcf64994b79620bd550e43d726 Ported dwt.widgets.Tree diff -r 102ff2adce19 -r 4e8317766ba0 dwt/internal/cocoa/NSButtonCell.d --- a/dwt/internal/cocoa/NSButtonCell.d Sun Dec 28 20:07:20 2008 +0100 +++ b/dwt/internal/cocoa/NSButtonCell.d Tue Dec 30 16:22:25 2008 +0100 @@ -40,11 +40,11 @@ OS.objc_msgSend(this.id, OS.sel_setBackgroundColor_, color !is null ? color.id : null); } -public void setButtonType(objc.id aType) { +public void setButtonType(NSButtonType aType) { OS.objc_msgSend(this.id, OS.sel_setButtonType_, aType); } -public void setImagePosition(objc.id aPosition) { +public void setImagePosition(NSCellImagePosition aPosition) { OS.objc_msgSend(this.id, OS.sel_setImagePosition_, aPosition); } diff -r 102ff2adce19 -r 4e8317766ba0 dwt/widgets/Tree.d --- a/dwt/widgets/Tree.d Sun Dec 28 20:07:20 2008 +0100 +++ b/dwt/widgets/Tree.d Tue Dec 30 16:22:25 2008 +0100 @@ -7,6 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg *******************************************************************************/ module dwt.widgets.Tree; @@ -58,7 +61,17 @@ import dwt.internal.cocoa.SWTTableHeaderCell; import dwt.internal.cocoa.SWTTableHeaderView; import dwt.internal.cocoa.SWTTreeItem; -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.TreeColumn; +import dwt.widgets.TreeItem; +import dwt.widgets.TypedListener; +import dwt.widgets.Widget; /** * Instances of this class provide a selectable user interface object @@ -126,7 +139,7 @@ TreeColumn sortColumn; int columnCount; int sortDirection; - float /*double*/ levelIndent; + CGFloat levelIndent; bool ignoreExpand, ignoreSelect; /** @@ -184,11 +197,11 @@ return item; } -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; } @@ -310,7 +323,7 @@ TreeItem item = _getItem (parentItem, index, false); if (item !is null) { item.clear(); - ((NSOutlineView) view).reloadItem (item.handle); + (cast(NSOutlineView) view).reloadItem (item.handle); if (all) { clearAll (item, true); } @@ -325,7 +338,7 @@ TreeItem item = children [i]; if (item !is null) { item.clear (); - ((NSOutlineView) view).reloadItem (item.handle); + (cast(NSOutlineView) view).reloadItem (item.handle); if (all) clearAll (item, true); } } @@ -417,7 +430,7 @@ width = wHint; } if (hHint is DWT.DEFAULT) { - height = (int)/*64*/(cast(NSOutlineView) view).numberOfRows () * getItemHeight () + getHeaderHeight (); + height = cast(int)/*64*/(cast(NSOutlineView) view).numberOfRows () * getItemHeight () + getHeaderHeight (); } else { height = hHint; } @@ -474,15 +487,15 @@ } void createHandle () { - NSScrollView scrollWidget = cast(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); - NSOutlineView widget = cast(NSOutlineView) new SWTOutlineView ().alloc (); - widget.initWithFrame (new NSRect ()); + NSOutlineView widget = cast(NSOutlineView) (new SWTOutlineView ()).alloc (); + widget.initWithFrame (NSRect ()); widget.setAllowsMultipleSelection ((style & DWT.MULTI) !is 0); widget.setAllowsColumnReordering (false); widget.setAutoresizesOutlineColumn (false); @@ -492,17 +505,17 @@ 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); widget.setOutlineTableColumn (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); @@ -513,13 +526,13 @@ cell.release (); } - firstColumn = cast(NSTableColumn) new NSTableColumn ().alloc (); + firstColumn = cast(NSTableColumn) (new NSTableColumn ()).alloc (); firstColumn.initWithIdentifier (firstColumn); firstColumn.setMinWidth(0); firstColumn.headerCell ().setTitle (str); widget.addTableColumn (firstColumn); widget.setOutlineTableColumn (firstColumn); - dataCell = cast(NSBrowserCell)new SWTBrowserCell ().alloc ().init (); + dataCell = cast(NSBrowserCell)(new SWTBrowserCell ()).alloc ().init (); dataCell.setLeaf (true); firstColumn.setDataCell (dataCell); levelIndent = widget.indentationPerLevel (); @@ -548,9 +561,9 @@ firstColumn = null; } else { //TODO - set attributes, alignment etc. - NSOutlineView outlineView = (NSOutlineView)view; + NSOutlineView outlineView = cast(NSOutlineView)view; NSString str = NSString.stringWith (""); - nsColumn = cast(NSTableColumn) new NSTableColumn ().alloc (); + nsColumn = cast(NSTableColumn) (new NSTableColumn ()).alloc (); nsColumn.initWithIdentifier (nsColumn); nsColumn.setMinWidth(0); nsColumn.headerCell ().setTitle (str); @@ -563,7 +576,7 @@ } } 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; @@ -607,7 +620,7 @@ System.arraycopy (items, index, items, index + 1, count++ - index); items [index] = item; item.items = new TreeItem [4]; - SWTTreeItem handle = (SWTTreeItem) new SWTTreeItem ().alloc ().init (); + SWTTreeItem handle = cast(SWTTreeItem) (new SWTTreeItem ()).alloc ().init (); item.handle = handle; item.createJNIRef (); item.register (); @@ -766,7 +779,7 @@ } } - int oldIndex = (int)/*64*/((NSOutlineView)view).columnWithIdentifier (column.nsColumn); + NSInteger oldIndex = (cast(NSOutlineView)view).columnWithIdentifier (column.nsColumn); if (columnCount is 1) { //TODO - reset attributes @@ -774,17 +787,17 @@ firstColumn.setWidth (0); } else { if (index is 0) { - ((NSOutlineView)view).setOutlineTableColumn(columns[1].nsColumn); + (cast(NSOutlineView)view).setOutlineTableColumn(columns[1].nsColumn); } - ((NSOutlineView)view).removeTableColumn(column.nsColumn); + (cast(NSOutlineView)view).removeTableColumn(column.nsColumn); } System.arraycopy (columns, index + 1, columns, index, --columnCount - index); columns [columnCount] = null; - NSArray array = ((NSOutlineView)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(NSOutlineView)view).tableColumns (); + NSUInteger arraySize = cast(int)/*64*/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); @@ -833,21 +846,21 @@ // fixScrollBar (); } -void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, int /*long*/ cellFrame, int /*long*/ view) { - NSRect rect = new NSRect (); - OS.memmove (rect, cellFrame, NSRect.sizeof); +void drawInteriorWithFrame_inView (objc.id id, objc.SEL sel, objc.id cellFrame, objc.id view) { + NSRect rect = NSRect (); + OS.memmove (&rect, cellFrame, NSRect.sizeof); - NSOutlineView outlineView = (NSOutlineView)this.view; + NSOutlineView outlineView = cast(NSOutlineView)this.view; NSBrowserCell cell = new NSBrowserCell (id); NSRange rowsRange = outlineView.rowsInRect (rect); - int rowIndex = (int)/*64*/rowsRange.location; - TreeItem item = (TreeItem) display.getWidget (outlineView.itemAtRow (rowIndex).id); + NSUInteger rowIndex = rowsRange.location; + TreeItem item = cast(TreeItem) display.getWidget (outlineView.itemAtRow (rowIndex).id); int columnIndex = 0; - id nsColumn = null; - int nsColumnIndex = 0; + cocoa.id nsColumn = null; + NSUInteger nsColumnIndex = 0; if (columnCount !is 0) { NSIndexSet columnsSet = outlineView.columnIndexesInRect (rect); - nsColumnIndex = (int)/*64*/columnsSet.firstIndex (); + nsColumnIndex = columnsSet.firstIndex (); NSArray nsColumns = outlineView.tableColumns (); nsColumn = nsColumns.objectAtIndex (nsColumnIndex); for (int i = 0; i < columnCount; i++) { @@ -878,7 +891,7 @@ nsSelectionBackground = nsSelectionBackground.colorUsingColorSpace (NSColorSpace.deviceRGBColorSpace ()); } - NSRect fullRect = new NSRect (); + NSRect fullRect = NSRect (); fullRect.y = rect.y; fullRect.height = rect.height; if (columnCount is 0) { fullRect.x = rect.x; @@ -900,11 +913,11 @@ } if (hooks (DWT.EraseItem)) { - NSRect eraseItemRect = null; + NSRect eraseItemRect; // 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 || outlineView.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; @@ -912,16 +925,17 @@ eraseItemRect = fullRect; } GCData data = new GCData (); - data.paintRect = eraseItemRect; + data.paintRectStruct = eraseItemRect; + data.paintRect = &data.paintRectStruct; GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); if (isSelected) { - float /*double*/[] components = new float /*double*/[(int)/*64*/nsSelectionForeground.numberOfComponents ()]; - nsSelectionForeground.getComponents (components); + CGFloat[] components = new CGFloat[nsSelectionForeground.numberOfComponents ()]; + nsSelectionForeground.getComponents (components.ptr); Color selectionForeground = Color.cocoa_new (display, components); gc.setForeground (selectionForeground); - components = new float /*double*/[(int)/*64*/nsSelectionBackground.numberOfComponents ()]; - nsSelectionBackground.getComponents (components); + components = new CGFloat[nsSelectionBackground.numberOfComponents ()]; + nsSelectionBackground.getComponents (components.ptr); Color selectionBackground = Color.cocoa_new (display, components); gc.setBackground (selectionBackground); } else { @@ -936,10 +950,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; @@ -951,7 +965,7 @@ drawSelection = drawSelection && (event.detail & DWT.SELECTED) !is 0; } if (drawSelection) { - NSRect selectionRect = new NSRect (); + NSRect selectionRect = NSRect (); selectionRect.y = rect.y; selectionRect.height = rect.height; if (columnCount > 0) { NSRect columnRect = outlineView.rectOfColumn (nsColumnIndex); @@ -960,7 +974,7 @@ NSRect rowRect = outlineView.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 { @@ -974,7 +988,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); @@ -994,23 +1008,25 @@ // 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 || outlineView.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; - data.paintRect = gcRect; + data.paintRectStruct = gcRect; + data.paintRect = &data.paintRectStruct; } else { - data.paintRect = fullRect; + data.paintRectStruct = fullRect; + data.paintRect = &data.paintRectStruct; } GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); if (isSelected) { - float /*double*/[] components = new float /*double*/[(int)/*64*/nsSelectionForeground.numberOfComponents ()]; - nsSelectionForeground.getComponents (components); + CGFloat[] components = new CGFloat[nsSelectionForeground.numberOfComponents ()]; + nsSelectionForeground.getComponents (components.ptr); Color selectionForeground = Color.cocoa_new (display, components); gc.setForeground (selectionForeground); - components = new float /*double*/[(int)/*64*/nsSelectionBackground.numberOfComponents ()]; - nsSelectionBackground.getComponents (components); + components = new CGFloat[nsSelectionBackground.numberOfComponents ()]; + nsSelectionBackground.getComponents (components.ptr); Color selectionBackground = Color.cocoa_new (display, components); gc.setBackground (selectionBackground); gc.setBackground (display.getSystemColor (DWT.COLOR_GREEN)); @@ -1024,10 +1040,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 (); } @@ -1052,7 +1068,7 @@ return 20; //TODO - compute width } -TreeColumn getColumn (id id) { +TreeColumn getColumn (cocoa.id id) { for (int i = 0; i < columnCount; i++) { if (columns[i].nsColumn.id is id.id) { return columns[i]; @@ -1150,7 +1166,7 @@ int [] order = new int [columnCount]; for (int i = 0; i < columnCount; i++) { TreeColumn column = columns [i]; - int index = ((NSOutlineView)view).columnWithIdentifier (column.nsColumn); + int index = (cast(NSOutlineView)view).columnWithIdentifier (column.nsColumn); if ((style & DWT.CHECK) !is 0) index -= 1; order [index] = i; } @@ -1308,16 +1324,16 @@ public TreeItem getItem (Point point) { checkWidget (); if (point is null) error (DWT.ERROR_NULL_ARGUMENT); - NSOutlineView widget = (NSOutlineView)view; + NSOutlineView widget = cast(NSOutlineView)view; NSPoint pt = NSPoint(); pt.x = point.x; pt.y = point.y; - int row = (int)/*64*/widget.rowAtPoint(pt); + NSInteger row = widget.rowAtPoint(pt); if (row is -1) return null; - id id = widget.itemAtRow(row); + cocoa.id id = widget.itemAtRow(row); Widget item = display.getWidget (id.id); - if (item !is null && item instanceof TreeItem) { - return (TreeItem)item; + if (item !is null && cast(TreeItem) item) { + return cast(TreeItem)item; } return null; } @@ -1407,7 +1423,7 @@ */ public bool getLinesVisible () { checkWidget (); - return ((NSOutlineView) view).usesAlternatingRowBackgroundColors (); + return (cast(NSOutlineView) view).usesAlternatingRowBackgroundColors (); } /** @@ -1450,14 +1466,14 @@ return new TreeItem [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); TreeItem [] result = new TreeItem [count]; - for (int i=0; i 1)) return; - NSOutlineView outlineView = (NSOutlineView) view; - NSMutableIndexSet rows = (NSMutableIndexSet) new NSMutableIndexSet ().alloc ().init (); + NSOutlineView outlineView = cast(NSOutlineView) view; + NSMutableIndexSet rows = cast(NSMutableIndexSet) (new NSMutableIndexSet ()).alloc ().init (); rows.autorelease (); for (int i=0; i