comparison dwt/widgets/Tree.d @ 90:c7f7f4d7091a

All widgets are ported
author Jacob Carlborg <doob@me.com>
date Tue, 30 Dec 2008 18:54:31 +0100
parents 4e8317766ba0
children 63a09873578e
comparison
equal deleted inserted replaced
89:8e3c85e1733d 90:c7f7f4d7091a
61 import dwt.internal.cocoa.SWTTableHeaderCell; 61 import dwt.internal.cocoa.SWTTableHeaderCell;
62 import dwt.internal.cocoa.SWTTableHeaderView; 62 import dwt.internal.cocoa.SWTTableHeaderView;
63 import dwt.internal.cocoa.SWTTreeItem; 63 import dwt.internal.cocoa.SWTTreeItem;
64 import cocoa = dwt.internal.cocoa.id; 64 import cocoa = dwt.internal.cocoa.id;
65 65
66 import dwt.internal.c.Carbon; 66 import Carbon = dwt.internal.c.Carbon;
67 import dwt.internal.objc.cocoa.Cocoa; 67 import dwt.internal.objc.cocoa.Cocoa;
68 import objc = dwt.internal.objc.runtime; 68 import objc = dwt.internal.objc.runtime;
69 import dwt.widgets.Composite; 69 import dwt.widgets.Composite;
70 import dwt.widgets.Event; 70 import dwt.widgets.Event;
71 import dwt.widgets.TreeColumn; 71 import dwt.widgets.TreeColumn;
137 int itemCount; 137 int itemCount;
138 TreeColumn [] columns; 138 TreeColumn [] columns;
139 TreeColumn sortColumn; 139 TreeColumn sortColumn;
140 int columnCount; 140 int columnCount;
141 int sortDirection; 141 int sortDirection;
142 CGFloat levelIndent; 142 Carbon.CGFloat levelIndent;
143 bool ignoreExpand, ignoreSelect; 143 bool ignoreExpand, ignoreSelect;
144 144
145 /** 145 /**
146 * Constructs a new instance of this class given its parent 146 * Constructs a new instance of this class given its parent
147 * and a style value describing its behavior and appearance. 147 * and a style value describing its behavior and appearance.
421 // levelIndent = cast(int) metric [0]; 421 // levelIndent = cast(int) metric [0];
422 // } 422 // }
423 // GC gc = new GC (this); 423 // GC gc = new GC (this);
424 // width = calculateWidth (childIds, gc, true, 0, levelIndent); 424 // width = calculateWidth (childIds, gc, true, 0, levelIndent);
425 // gc.dispose (); 425 // gc.dispose ();
426 // width += getInsetWidth (column_id, true); 426 // width += getInsetWidth (columnid, true);
427 } 427 }
428 if ((style & DWT.CHECK) !is 0) width += getCheckColumnWidth (); 428 if ((style & DWT.CHECK) !is 0) width += getCheckColumnWidth ();
429 } else { 429 } else {
430 width = wHint; 430 width = wHint;
431 } 431 }
928 data.paintRectStruct = eraseItemRect; 928 data.paintRectStruct = eraseItemRect;
929 data.paintRect = &data.paintRectStruct; 929 data.paintRect = &data.paintRectStruct;
930 GC gc = GC.cocoa_new (this, data); 930 GC gc = GC.cocoa_new (this, data);
931 gc.setFont (item.getFont (columnIndex)); 931 gc.setFont (item.getFont (columnIndex));
932 if (isSelected) { 932 if (isSelected) {
933 CGFloat[] components = new CGFloat[nsSelectionForeground.numberOfComponents ()]; 933 Carbon.CGFloat[] components = new Carbon.CGFloat[nsSelectionForeground.numberOfComponents ()];
934 nsSelectionForeground.getComponents (components.ptr); 934 nsSelectionForeground.getComponents (components.ptr);
935 Color selectionForeground = Color.cocoa_new (display, components); 935 Color selectionForeground = Color.cocoa_new (display, components);
936 gc.setForeground (selectionForeground); 936 gc.setForeground (selectionForeground);
937 components = new CGFloat[nsSelectionBackground.numberOfComponents ()]; 937 components = new Carbon.CGFloat[nsSelectionBackground.numberOfComponents ()];
938 nsSelectionBackground.getComponents (components.ptr); 938 nsSelectionBackground.getComponents (components.ptr);
939 Color selectionBackground = Color.cocoa_new (display, components); 939 Color selectionBackground = Color.cocoa_new (display, components);
940 gc.setBackground (selectionBackground); 940 gc.setBackground (selectionBackground);
941 } else { 941 } else {
942 gc.setForeground (item.getForeground (columnIndex)); 942 gc.setForeground (item.getForeground (columnIndex));
972 selectionRect.x = columnRect.x; selectionRect.width = columnRect.width; 972 selectionRect.x = columnRect.x; selectionRect.width = columnRect.width;
973 } else { 973 } else {
974 NSRect rowRect = outlineView.rectOfRow (rowIndex); 974 NSRect rowRect = outlineView.rectOfRow (rowIndex);
975 if ((style & DWT.CHECK) !is 0) { 975 if ((style & DWT.CHECK) !is 0) {
976 /* highlighting at this stage draws over the checkbox, so don't include its column */ 976 /* highlighting at this stage draws over the checkbox, so don't include its column */
977 CGFloat checkWidth = checkColumn.width (); 977 Carbon.CGFloat checkWidth = checkColumn.width ();
978 selectionRect.x = checkWidth; 978 selectionRect.x = checkWidth;
979 selectionRect.width = rowRect.width - checkWidth; 979 selectionRect.width = rowRect.width - checkWidth;
980 } else { 980 } else {
981 selectionRect.width = rowRect.width; 981 selectionRect.width = rowRect.width;
982 } 982 }
986 } 986 }
987 987
988 if (drawBackground && !drawSelection) { 988 if (drawBackground && !drawSelection) {
989 NSGraphicsContext context = NSGraphicsContext.currentContext (); 989 NSGraphicsContext context = NSGraphicsContext.currentContext ();
990 context.saveGraphicsState (); 990 context.saveGraphicsState ();
991 CGFloat[] colorRGB = background.handle; 991 Carbon.CGFloat[] colorRGB = background.handle;
992 NSColor color = NSColor.colorWithDeviceRed (colorRGB[0], colorRGB[1], colorRGB[2], 1f); 992 NSColor color = NSColor.colorWithDeviceRed (colorRGB[0], colorRGB[1], colorRGB[2], 1f);
993 color.setFill (); 993 color.setFill ();
994 NSBezierPath.fillRect (fullRect); 994 NSBezierPath.fillRect (fullRect);
995 context.restoreGraphicsState (); 995 context.restoreGraphicsState ();
996 } 996 }
1019 data.paintRect = &data.paintRectStruct; 1019 data.paintRect = &data.paintRectStruct;
1020 } 1020 }
1021 GC gc = GC.cocoa_new (this, data); 1021 GC gc = GC.cocoa_new (this, data);
1022 gc.setFont (item.getFont (columnIndex)); 1022 gc.setFont (item.getFont (columnIndex));
1023 if (isSelected) { 1023 if (isSelected) {
1024 CGFloat[] components = new CGFloat[nsSelectionForeground.numberOfComponents ()]; 1024 Carbon.CGFloat[] components = new Carbon.CGFloat[nsSelectionForeground.numberOfComponents ()];
1025 nsSelectionForeground.getComponents (components.ptr); 1025 nsSelectionForeground.getComponents (components.ptr);
1026 Color selectionForeground = Color.cocoa_new (display, components); 1026 Color selectionForeground = Color.cocoa_new (display, components);
1027 gc.setForeground (selectionForeground); 1027 gc.setForeground (selectionForeground);
1028 components = new CGFloat[nsSelectionBackground.numberOfComponents ()]; 1028 components = new Carbon.CGFloat[nsSelectionBackground.numberOfComponents ()];
1029 nsSelectionBackground.getComponents (components.ptr); 1029 nsSelectionBackground.getComponents (components.ptr);
1030 Color selectionBackground = Color.cocoa_new (display, components); 1030 Color selectionBackground = Color.cocoa_new (display, components);
1031 gc.setBackground (selectionBackground); 1031 gc.setBackground (selectionBackground);
1032 gc.setBackground (display.getSystemColor (DWT.COLOR_GREEN)); 1032 gc.setBackground (display.getSystemColor (DWT.COLOR_GREEN));
1033 } else { 1033 } else {
1558 // Rect rect = new Rect (); 1558 // Rect rect = new Rect ();
1559 // int y = getBorder () + getHeaderHeight (); 1559 // int y = getBorder () + getHeaderHeight ();
1560 // for (int i=0; i<items.length; i++) { 1560 // for (int i=0; i<items.length; i++) {
1561 // TreeItem item = items [i]; 1561 // TreeItem item = items [i];
1562 // if (item !is null) { 1562 // if (item !is null) {
1563 // int columnId = (columnCount is 0) ? column_id : columns [0].id; 1563 // int columnId = (columnCount is 0) ? columnid : columns [0].id;
1564 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) is OS.noErr) { 1564 // if (OS.GetDataBrowserItemPartBounds (handle, item.id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) is OS.noErr) {
1565 // if (rect.top <= y && y <= rect.bottom) return item; 1565 // if (rect.top <= y && y <= rect.bottom) return item;
1566 // } 1566 // }
1567 // } 1567 // }
1568 // } 1568 // }
1746 int startIndex = Math.min (oldIndex, newIndex); 1746 int startIndex = Math.min (oldIndex, newIndex);
1747 int endIndex = Math.max (oldIndex, newIndex); 1747 int endIndex = Math.max (oldIndex, newIndex);
1748 NSOutlineView outlineView = cast(NSOutlineView)view; 1748 NSOutlineView outlineView = cast(NSOutlineView)view;
1749 NSArray nsColumns = outlineView.tableColumns (); 1749 NSArray nsColumns = outlineView.tableColumns ();
1750 for (int i = startIndex; i <= endIndex; i++) { 1750 for (int i = startIndex; i <= endIndex; i++) {
1751 id columnId = nsColumns.objectAtIndex (i); 1751 cocoa.id columnId = nsColumns.objectAtIndex (i);
1752 TreeColumn column = getColumn (columnId); 1752 TreeColumn column = getColumn (columnId);
1753 if (column !is null) { 1753 if (column !is null) {
1754 column.sendEvent (DWT.Move); 1754 column.sendEvent (DWT.Move);
1755 if (isDisposed ()) return; 1755 if (isDisposed ()) return;
1756 } 1756 }
1797 NSOutlineView widget = cast(NSOutlineView) view; 1797 NSOutlineView widget = cast(NSOutlineView) view;
1798 NSInteger row = widget.selectedRow (); 1798 NSInteger row = widget.selectedRow ();
1799 if (row is -1) 1799 if (row is -1)
1800 postEvent (DWT.Selection); 1800 postEvent (DWT.Selection);
1801 else { 1801 else {
1802 id _id = widget.itemAtRow (row); 1802 cocoa.id _id = widget.itemAtRow (row);
1803 TreeItem item = cast(TreeItem) display.getWidget (_id.id); 1803 TreeItem item = cast(TreeItem) display.getWidget (_id.id);
1804 Event event = new Event (); 1804 Event event = new Event ();
1805 event.item = item; 1805 event.item = item;
1806 event.index = row; 1806 event.index = row;
1807 postEvent (DWT.Selection, event); 1807 postEvent (DWT.Selection, event);
2052 } 2052 }
2053 } 2053 }
2054 return result; 2054 return result;
2055 } 2055 }
2056 2056
2057 void setBackground (CGFloat [] color) { 2057 void setBackground (Carbon.CGFloat [] color) {
2058 super.setBackground (color); 2058 super.setBackground (color);
2059 NSColor nsColor; 2059 NSColor nsColor;
2060 if (color is null) { 2060 if (color is null) {
2061 nsColor = null; 2061 nsColor = null;
2062 } else { 2062 } else {