Mercurial > projects > dwt-mac
changeset 87:4e8317766ba0
Ported dwt.widgets.Tree
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 30 Dec 2008 16:22:25 +0100 |
parents | 102ff2adce19 |
children | 6c56264306a6 |
files | dwt/internal/cocoa/NSButtonCell.d dwt/widgets/Tree.d |
diffstat | 2 files changed, 172 insertions(+), 155 deletions(-) [+] |
line wrap: on
line diff
--- 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); }
--- 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 <doob@me.com> *******************************************************************************/ 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<count; i++) { - id id = widget.itemAtRow (indexBuffer [i]); + for (NSUInteger i=0; i<count; i++) { + cocoa.id id = widget.itemAtRow (indexBuffer [i]); Widget item = display.getWidget (id.id); - if (item !is null && item instanceof TreeItem) { + if (item !is null && cast(TreeItem) item) { //TODO virtual result[i] = cast(TreeItem) item; } @@ -1553,10 +1569,10 @@ return null; } -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); } } @@ -1623,23 +1639,23 @@ bool isTrim (NSView view) { if (super.isTrim (view)) return true; - return view.id_ is headerView.id_; + return view.id is headerView.id; } -int /*long*/ outlineView_child_ofItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ index, int /*long*/ itemID) { - TreeItem parent = (TreeItem) display.getWidget (itemID); - TreeItem item = _getItem (parent, (int)/*64*/index, true); +objc.id outlineView_child_ofItem (objc.id id, objc.SEL sel, objc.id outlineView, objc.id index, objc.id itemID) { + TreeItem parent = cast(TreeItem) display.getWidget (itemID); + TreeItem item = _getItem (parent, cast(int)/*64*/index, true); checkData (item, false); return item.handle.id; } -void outlineView_didClickTableColumn (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn) { - TreeColumn column = getColumn (new id (tableColumn)); +void outlineView_didClickTableColumn (objc.id id, objc.SEL sel, objc.id outlineView, objc.id tableColumn) { + TreeColumn column = getColumn (new cocoa.id (tableColumn)); column.postEvent (DWT.Selection); } -int /*long*/ outlineView_objectValueForTableColumn_byItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn, int /*long*/ itemID) { - TreeItem item = (TreeItem) display.getWidget (itemID); +objc.id outlineView_objectValueForTableColumn_byItem (objc.id id, objc.SEL sel, objc.id outlineView, objc.id tableColumn, objc.id itemID) { + TreeItem item = cast(TreeItem) display.getWidget (itemID); if (checkColumn !is null && tableColumn is checkColumn.id) { NSNumber value; if (item.checked && item.grayed) { @@ -1657,17 +1673,17 @@ return item.createString (0).id; } -bool outlineView_isItemExpandable (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) { - if (item is 0) return true; +bool outlineView_isItemExpandable (objc.id id, objc.SEL sel, objc.id outlineView, objc.id item) { + if (item is null) return true; return (cast(TreeItem) display.getWidget (item)).itemCount !is 0; } -int /*long*/ outlineView_numberOfChildrenOfItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) { - if (item is 0) return itemCount; +int outlineView_numberOfChildrenOfItem (objc.id id, objc.SEL sel, objc.id outlineView, objc.id item) { + if (item is null) return itemCount; return (cast(TreeItem) display.getWidget (item)).itemCount; } -void outlineView_willDisplayCell_forTableColumn_item (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ cell, int /*long*/ tableColumn, int /*long*/ itemID) { +void outlineView_willDisplayCell_forTableColumn_item (objc.id id, objc.SEL sel, objc.id outlineView, objc.id cell, objc.id tableColumn, objc.id itemID) { if (checkColumn !is null && tableColumn is checkColumn.id) return; TreeItem item = cast(TreeItem) display.getWidget(itemID); Image image = item.image; @@ -1683,25 +1699,26 @@ browserCell.setFont (item.getFont (columnIndex).handle); if (hooks (DWT.MeasureItem)) { - NSOutlineView view = (NSOutlineView)this.view; - int nsColumnIndex = (int)/*64*/view.columnWithIdentifier (new id (tableColumn)); - int rowIndex = (int)/*64*/view.rowForItem (new id (itemID)); + NSOutlineView view = cast(NSOutlineView)this.view; + NSInteger nsColumnIndex = view.columnWithIdentifier (new cocoa.id (tableColumn)); + NSInteger rowIndex = view.rowForItem (new cocoa.id (itemID)); NSRect rect = view.frameOfCellAtColumn (nsColumnIndex, rowIndex); NSRect contentRect = browserCell.titleRectForBounds (rect); NSSize contentSize = browserCell.cellSizeForBounds (rect); GCData data = new GCData (); - data.paintRect = view.frame (); + data.paintRectStruct = view.frame (); + data.paintRect = &data.paintRectStruct; GC gc = GC.cocoa_new (this, data); gc.setFont (item.getFont (columnIndex)); - int rowHeight = (int)view.rowHeight (); + int rowHeight = cast(int)view.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 (); @@ -1710,8 +1727,8 @@ view.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, false); @@ -1719,16 +1736,16 @@ } } -void outlineViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { +void outlineViewColumnDidMove (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 (); + cocoa.id nsOldIndex = userInfo.valueForKey (NSString.stringWith ("NSOldColumn")); //$NON-NLS-1$ + cocoa.id nsNewIndex = userInfo.valueForKey (NSString.stringWith ("NSNewColumn")); //$NON-NLS-1$ + int oldIndex = (new NSNumber (nsOldIndex)).intValue (); + int newIndex = (new NSNumber (nsNewIndex)).intValue (); int startIndex = Math.min (oldIndex, newIndex); int endIndex = Math.max (oldIndex, newIndex); - NSOutlineView outlineView = (NSOutlineView)view; + NSOutlineView outlineView = cast(NSOutlineView)view; NSArray nsColumns = outlineView.tableColumns (); for (int i = startIndex; i <= endIndex; i++) { id columnId = nsColumns.objectAtIndex (i); @@ -1740,23 +1757,23 @@ } } -void outlineViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { +void outlineViewColumnDidResize (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$ + cocoa.id columnId = userInfo.valueForKey (NSString.stringWith ("NSTableColumn")); //$NON-NLS-1$ TreeColumn column = getColumn (columnId); if (column is null) return; /* either CHECK column or firstColumn in 0-column Tree */ column.sendEvent (DWT.Resize); if (isDisposed ()) return; - NSOutlineView outlineView = (NSOutlineView)view; - int index = (int)/*64*/outlineView.columnWithIdentifier (columnId); + NSOutlineView outlineView = cast(NSOutlineView)view; + NSInteger index = outlineView.columnWithIdentifier (columnId); if (index is -1) return; /* column was disposed in Resize callback */ NSArray nsColumns = outlineView.tableColumns (); - int columnCount = (int)/*64*/outlineView.numberOfColumns (); - for (int i = index + 1; i < columnCount; i++) { + NSInteger columnCount = outlineView.numberOfColumns (); + for (NSInteger i = index + 1; i < columnCount; i++) { columnId = nsColumns.objectAtIndex (i); column = getColumn (columnId); if (column !is null) { @@ -1766,19 +1783,19 @@ } } -void outlineViewItemDidExpand (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) { +void outlineViewItemDidExpand (objc.id id, objc.SEL sel, objc.id notification) { NSNotification nsNotification = new NSNotification (notification); NSDictionary info = nsNotification.userInfo (); NSString key = NSString.stringWith ("NSObject"); //$NON-NLS-1$ - int /*long*/ itemHandle = info.objectForKey (key).id; - TreeItem item = (TreeItem)display.getWidget (itemHandle); + objc.id itemHandle = info.objectForKey (key).id; + TreeItem item = cast(TreeItem)display.getWidget (itemHandle); setScrollWidth (item.getItems (), true, true); } -void outlineViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) { +void outlineViewSelectionDidChange (objc.id id, objc.SEL sel, objc.id notification) { if (ignoreSelect) return; NSOutlineView widget = cast(NSOutlineView) view; - int row = (int)/*64*/widget.selectedRow (); + NSInteger row = widget.selectedRow (); if (row is -1) postEvent (DWT.Selection); else { @@ -1791,46 +1808,46 @@ } } -bool outlineView_shouldCollapseItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ itemID) { - TreeItem item = (TreeItem) display.getWidget (itemID); +bool outlineView_shouldCollapseItem (objc.id id, objc.SEL sel, objc.id lineView, objc.id itemID) { + TreeItem item = cast(TreeItem) display.getWidget (itemID); if (!ignoreExpand) { Event event = new Event (); event.item = item; sendEvent (DWT.Collapse, event); item.expanded = false; ignoreExpand = true; - ((NSOutlineView) view).collapseItem (item.handle); + (cast(NSOutlineView) view).collapseItem (item.handle); ignoreExpand = false; return false; } return !item.expanded; } -bool outlineView_shouldExpandItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ itemID) { - final TreeItem item = (TreeItem) display.getWidget (itemID); +bool outlineView_shouldExpandItem (objc.id id, objc.SEL sel, objc.id outlineView, objc.id itemID) { + final TreeItem item = cast(TreeItem) display.getWidget (itemID); if (!ignoreExpand) { Event event = new Event (); event.item = item; sendEvent (DWT.Expand, event); item.expanded = true; ignoreExpand = true; - ((NSOutlineView) view).expandItem (item.handle); + (cast(NSOutlineView) view).expandItem (item.handle); ignoreExpand = false; return false; } return item.expanded; } -void outlineView_setObjectValue_forTableColumn_byItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ object, int /*long*/ tableColumn, int /*long*/ itemID) { +void outlineView_setObjectValue_forTableColumn_byItem (objc.id id, objc.SEL sel, objc.id outlineView, objc.id object, objc.id tableColumn, objc.id itemID) { if (checkColumn !is null && tableColumn is checkColumn.id) { - TreeItem item = (TreeItem) display.getWidget (itemID); + TreeItem item = cast(TreeItem) display.getWidget (itemID); item.checked = !item.checked; Event event = new Event (); event.detail = DWT.CHECK; event.item = item; postEvent (DWT.Selection, event); - NSOutlineView view = (NSOutlineView)this.view; - int rowIndex = (int)/*64*/view.rowForItem (new id (itemID)); + NSOutlineView view = cast(NSOutlineView)this.view; + NSInteger rowIndex = view.rowForItem (new cocoa.id (itemID)); NSRect rect = view.rectOfRow (rowIndex); view.setNeedsDisplayInRect (rect); } @@ -2014,7 +2031,7 @@ if (item is null) error (DWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); showItem (item); - NSOutlineView outlineView = (NSOutlineView) view; + NSOutlineView outlineView = cast(NSOutlineView) view; outlineView.selectRow (outlineView.rowForItem (item.handle), false); } @@ -2026,7 +2043,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 */ @@ -2037,7 +2054,7 @@ return result; } -void setBackground (float [] color) { +void setBackground (CGFloat [] color) { super.setBackground (color); NSColor nsColor; if (color is null) { @@ -2045,7 +2062,7 @@ } else { nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1); } - ((NSOutlineView) view).setBackgroundColor (nsColor); + (cast(NSOutlineView) view).setBackgroundColor (nsColor); } /** @@ -2091,12 +2108,12 @@ if (order [i] !is oldOrder [i]) reorder = true; } if (reorder) { - NSOutlineView outlineView = (NSOutlineView)view; + NSOutlineView outlineView = cast(NSOutlineView)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)outlineView.rectOfColumn (i + check).x; + oldX [index] = cast(int)outlineView.rectOfColumn (i + check).x; } int [] newX = new int [order.length]; for (int i=0; i<order.length; i++) { @@ -2105,7 +2122,7 @@ int oldIndex = outlineView.columnWithIdentifier (column.nsColumn); int newIndex = i + check; outlineView.moveColumn (oldIndex, newIndex); - newX [index] = (int)outlineView.rectOfColumn (newIndex).x; + newX [index] = cast(int)outlineView.rectOfColumn (newIndex).x; } TreeColumn[] newColumns = new TreeColumn [columnCount]; @@ -2126,7 +2143,7 @@ if (!hooks (DWT.MeasureItem)) { float ascent = font.ascender (); float descent = -font.descender () + font.leading (); - ((NSOutlineView)view).setRowHeight ((int)Math.ceil (ascent + descent) + 1); + (cast(NSOutlineView)view).setRowHeight (cast(int)Math.ceil (ascent + descent) + 1); } else { view.setNeedsDisplay (true); } @@ -2204,7 +2221,7 @@ parentItem.items = newItems; parentItem.itemCount = count; } - NSOutlineView widget = (NSOutlineView) view; + NSOutlineView widget = cast(NSOutlineView) view; widget.reloadItem (parentItem !is null ? parentItem.handle : null, true); widget.noteNumberOfRowsChanged(); } @@ -2267,7 +2284,7 @@ } bool setScrollWidth (TreeItem item, bool recurse, bool callMeasureItem) { - return setScrollWidth (new TreeItem[] {item}, recurse, callMeasureItem); + return setScrollWidth ([item], recurse, callMeasureItem); } bool setScrollWidth (TreeItem[] items, bool recurse, bool callMeasureItem) { @@ -2291,8 +2308,8 @@ } gc.dispose (); if (firstColumn.width () < newWidth) { - NSOutlineView outlineView = (NSOutlineView)view; - int /*long*/ oldResize = outlineView.columnAutoresizingStyle (); + NSOutlineView outlineView = cast(NSOutlineView)view; + NSTableViewColumnAutoresizingStyle oldResize = outlineView.columnAutoresizingStyle (); outlineView.setColumnAutoresizingStyle (OS.NSTableViewNoColumnAutoresizing); firstColumn.setWidth (newWidth); outlineView.setColumnAutoresizingStyle (oldResize); @@ -2324,7 +2341,7 @@ public void setSelection (TreeItem item) { checkWidget (); if (item is null) error (DWT.ERROR_NULL_ARGUMENT); - setSelection (new TreeItem [] {item}); + setSelection ([item]); } /** @@ -2355,8 +2372,8 @@ deselectAll (); int length = items.length; if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 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<length; i++) { if (items [i] !is null) { @@ -2396,10 +2413,10 @@ TreeColumn oldSortColumn = sortColumn; sortColumn = column; if (sortDirection is DWT.NONE) return; - NSTableHeaderView headerView = ((NSOutlineView)view).headerView (); + NSTableHeaderView headerView = (cast(NSOutlineView)view).headerView (); if (headerView is null) return; if (oldSortColumn !is null) { - int /*long*/ index = ((NSOutlineView)view).columnWithIdentifier (oldSortColumn.nsColumn); + NSInteger index = (cast(NSOutlineView)view).columnWithIdentifier (oldSortColumn.nsColumn); NSRect rect = headerView.headerRectOfColumn (index); headerView.setNeedsDisplayInRect (rect); } @@ -2429,9 +2446,9 @@ if (direction is sortDirection) return; sortDirection = direction; if (sortColumn is null) return; - NSTableHeaderView headerView = ((NSOutlineView)view).headerView (); + NSTableHeaderView headerView = (cast(NSOutlineView)view).headerView (); if (headerView is null) return; - int /*long*/ index = ((NSOutlineView)view).columnWithIdentifier (sortColumn.nsColumn); + NSInteger index = (cast(NSOutlineView)view).columnWithIdentifier (sortColumn.nsColumn); NSRect rect = headerView.headerRectOfColumn (index); headerView.setNeedsDisplayInRect (rect); } @@ -2461,9 +2478,9 @@ if (item is null) error (DWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); showItem (item, false); - NSOutlineView outlineView = (NSOutlineView) view; + NSOutlineView outlineView = cast(NSOutlineView) view; //FIXME - ((NSOutlineView) view).scrollRowToVisible (outlineView.rowForItem (item.handle)); + (cast(NSOutlineView) view).scrollRowToVisible (outlineView.rowForItem (item.handle)); } /** @@ -2490,9 +2507,9 @@ if (column.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); if (column.parent !is this) return; if (columnCount <= 1) return; - int index = (int)/*64*/((NSOutlineView)view).columnWithIdentifier (column.nsColumn); + int index = cast(int)/*64*/(cast(NSOutlineView)view).columnWithIdentifier (column.nsColumn); if (!(0 <= index && index < columnCount + ((style & DWT.CHECK) !is 0 ? 1 : 0))) return; - ((NSOutlineView)view).scrollColumnToVisible (index); + (cast(NSOutlineView)view).scrollColumnToVisible (index); } /** @@ -2527,7 +2544,7 @@ parentItem.setExpanded (true); } if (scroll) { - NSOutlineView outlineView = (NSOutlineView) view; + NSOutlineView outlineView = cast(NSOutlineView) view; outlineView.scrollRowToVisible (outlineView.rowForItem (item.handle)); } }