Mercurial > projects > dwt-mac
comparison dwt/widgets/Table.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 1a8b3cb347e0 |
children | d8635bb48c7c |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
58 * <code><pre> | 58 * <code><pre> |
59 * final Table table = new Table (parent, DWT.VIRTUAL | DWT.BORDER); | 59 * final Table table = new Table (parent, DWT.VIRTUAL | DWT.BORDER); |
60 * table.setItemCount (1000000); | 60 * table.setItemCount (1000000); |
61 * table.addListener (DWT.SetData, new Listener () { | 61 * table.addListener (DWT.SetData, new Listener () { |
62 * public void handleEvent (Event event) { | 62 * public void handleEvent (Event event) { |
63 * TableItem item = (TableItem) event.item; | 63 * TableItem item = cast(TableItem) event.item; |
64 * int index = table.indexOf (item); | 64 * int index = table.indexOf (item); |
65 * item.setText ("Item " + index); | 65 * item.setText ("Item " + index); |
66 * System.out.println (item.getText ()); | 66 * System.out.println (item.getText ()); |
67 * } | 67 * } |
68 * }); | 68 * }); |
384 return new Point (rect.width, rect.height); | 384 return new Point (rect.width, rect.height); |
385 } | 385 } |
386 | 386 |
387 void createHandle () { | 387 void createHandle () { |
388 //TODO - DWT.CHECK | 388 //TODO - DWT.CHECK |
389 SWTScrollView scrollWidget = (SWTScrollView)new SWTScrollView().alloc(); | 389 SWTScrollView scrollWidget = cast(SWTScrollView)new SWTScrollView().alloc(); |
390 scrollWidget.initWithFrame(new NSRect ()); | 390 scrollWidget.initWithFrame(new NSRect ()); |
391 scrollWidget.setHasHorizontalScroller(true); | 391 scrollWidget.setHasHorizontalScroller(true); |
392 scrollWidget.setHasVerticalScroller(true); | 392 scrollWidget.setHasVerticalScroller(true); |
393 scrollWidget.setAutohidesScrollers(true); | 393 scrollWidget.setAutohidesScrollers(true); |
394 scrollWidget.setBorderType(hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder); | 394 scrollWidget.setBorderType(hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder); |
395 scrollWidget.setTag(jniRef); | 395 scrollWidget.setTag(jniRef); |
396 | 396 |
397 NSTableView widget = (NSTableView)new SWTTableView().alloc(); | 397 NSTableView widget = cast(NSTableView)new SWTTableView().alloc(); |
398 widget.initWithFrame(new NSRect()); | 398 widget.initWithFrame(new NSRect()); |
399 widget.setAllowsMultipleSelection((style & DWT.MULTI) !is 0); | 399 widget.setAllowsMultipleSelection((style & DWT.MULTI) !is 0); |
400 widget.setDataSource(widget); | 400 widget.setDataSource(widget); |
401 widget.setDelegate(widget); | 401 widget.setDelegate(widget); |
402 widget.setDoubleAction(OS.sel_sendDoubleSelection); | 402 widget.setDoubleAction(OS.sel_sendDoubleSelection); |
407 headerView.retain(); | 407 headerView.retain(); |
408 widget.setHeaderView(null); | 408 widget.setHeaderView(null); |
409 | 409 |
410 NSString str = NSString.stringWith(""); | 410 NSString str = NSString.stringWith(""); |
411 if ((style & DWT.CHECK) !is 0) { | 411 if ((style & DWT.CHECK) !is 0) { |
412 checkColumn = (NSTableColumn)new NSTableColumn().alloc(); | 412 checkColumn = cast(NSTableColumn)new NSTableColumn().alloc(); |
413 checkColumn.initWithIdentifier(str); | 413 checkColumn.initWithIdentifier(str); |
414 checkColumn.headerCell().setTitle(str); | 414 checkColumn.headerCell().setTitle(str); |
415 widget.addTableColumn (checkColumn); | 415 widget.addTableColumn (checkColumn); |
416 NSButtonCell cell = (NSButtonCell)new NSButtonCell().alloc().init(); | 416 NSButtonCell cell = cast(NSButtonCell)new NSButtonCell().alloc().init(); |
417 checkColumn.setDataCell(cell); | 417 checkColumn.setDataCell(cell); |
418 cell.setButtonType(OS.NSSwitchButton); | 418 cell.setButtonType(OS.NSSwitchButton); |
419 cell.setImagePosition(OS.NSImageOnly); | 419 cell.setImagePosition(OS.NSImageOnly); |
420 cell.setAllowsMixedState(true); | 420 cell.setAllowsMixedState(true); |
421 cell.release(); | 421 cell.release(); |
422 checkColumn.setWidth(getCheckColumnWidth()); | 422 checkColumn.setWidth(getCheckColumnWidth()); |
423 checkColumn.setResizingMask(OS.NSTableColumnNoResizing); | 423 checkColumn.setResizingMask(OS.NSTableColumnNoResizing); |
424 checkColumn.setEditable(false); | 424 checkColumn.setEditable(false); |
425 } | 425 } |
426 | 426 |
427 firstColumn = (NSTableColumn)new NSTableColumn().alloc(); | 427 firstColumn = cast(NSTableColumn)new NSTableColumn().alloc(); |
428 firstColumn.initWithIdentifier(str); | 428 firstColumn.initWithIdentifier(str); |
429 //column.setResizingMask(OS.NSTableColumnAutoresizingMask); | 429 //column.setResizingMask(OS.NSTableColumnAutoresizingMask); |
430 NSCell cell = (NSBrowserCell)new NSBrowserCell().alloc().init(); | 430 NSCell cell = cast(NSBrowserCell)new NSBrowserCell().alloc().init(); |
431 firstColumn.setDataCell(cell); | 431 firstColumn.setDataCell(cell); |
432 cell.release(); | 432 cell.release(); |
433 widget.addTableColumn (firstColumn); | 433 widget.addTableColumn (firstColumn); |
434 | 434 |
435 scrollView = scrollWidget; | 435 scrollView = scrollWidget; |
450 //TODO - clear attributes, alignment etc. | 450 //TODO - clear attributes, alignment etc. |
451 nsColumn = firstColumn; | 451 nsColumn = firstColumn; |
452 firstColumn = null; | 452 firstColumn = null; |
453 } else { | 453 } else { |
454 //TODO - set attributes, alignment etc. | 454 //TODO - set attributes, alignment etc. |
455 nsColumn = (NSTableColumn)new NSTableColumn().alloc(); | 455 nsColumn = cast(NSTableColumn)new NSTableColumn().alloc(); |
456 nsColumn.initWithIdentifier(NSString.stringWith("")); | 456 nsColumn.initWithIdentifier(NSString.stringWith("")); |
457 ((NSTableView)view).addTableColumn (nsColumn); | 457 (cast(NSTableView)view).addTableColumn (nsColumn); |
458 int checkColumn = (style & DWT.CHECK) !is 0 ? 1 : 0; | 458 int checkColumn = (style & DWT.CHECK) !is 0 ? 1 : 0; |
459 ((NSTableView)view).moveColumn (columnCount + checkColumn, index + checkColumn); | 459 (cast(NSTableView)view).moveColumn (columnCount + checkColumn, index + checkColumn); |
460 NSCell cell = (NSBrowserCell)new NSBrowserCell().alloc().init(); | 460 NSCell cell = cast(NSBrowserCell)new NSBrowserCell().alloc().init(); |
461 nsColumn.setDataCell(cell); | 461 nsColumn.setDataCell(cell); |
462 cell.release(); | 462 cell.release(); |
463 } | 463 } |
464 column.nsColumn = nsColumn; | 464 column.nsColumn = nsColumn; |
465 nsColumn.headerCell().setTitle(NSString.stringWith("")); | 465 nsColumn.headerCell().setTitle(NSString.stringWith("")); |
523 items = newItems; | 523 items = newItems; |
524 } | 524 } |
525 System.arraycopy (items, index, items, index + 1, itemCount++ - index); | 525 System.arraycopy (items, index, items, index + 1, itemCount++ - index); |
526 items [index] = item; | 526 items [index] = item; |
527 //TODO - use noteNumberOfRowsChanged? | 527 //TODO - use noteNumberOfRowsChanged? |
528 ((NSTableView)view).reloadData(); | 528 (cast(NSTableView)view).reloadData(); |
529 } | 529 } |
530 | 530 |
531 void createWidget () { | 531 void createWidget () { |
532 super.createWidget (); | 532 super.createWidget (); |
533 items = new TableItem [4]; | 533 items = new TableItem [4]; |
555 * </ul> | 555 * </ul> |
556 */ | 556 */ |
557 public void deselect (int index) { | 557 public void deselect (int index) { |
558 checkWidget(); | 558 checkWidget(); |
559 if (0 <= index && index < itemCount) { | 559 if (0 <= index && index < itemCount) { |
560 NSTableView widget = (NSTableView)view; | 560 NSTableView widget = cast(NSTableView)view; |
561 ignoreSelect = true; | 561 ignoreSelect = true; |
562 widget.deselectRow (index); | 562 widget.deselectRow (index); |
563 ignoreSelect = false; | 563 ignoreSelect = false; |
564 } | 564 } |
565 } | 565 } |
584 //TODO - check range | 584 //TODO - check range |
585 if (start is 0 && end is itemCount - 1) { | 585 if (start is 0 && end is itemCount - 1) { |
586 deselectAll (); | 586 deselectAll (); |
587 } else { | 587 } else { |
588 int length = end - start + 1; | 588 int length = end - start + 1; |
589 NSTableView widget = (NSTableView)view; | 589 NSTableView widget = cast(NSTableView)view; |
590 ignoreSelect = true; | 590 ignoreSelect = true; |
591 for (int i=0; i<length; i++) { | 591 for (int i=0; i<length; i++) { |
592 widget.deselectRow (i); | 592 widget.deselectRow (i); |
593 } | 593 } |
594 ignoreSelect = false; | 594 ignoreSelect = false; |
613 * </ul> | 613 * </ul> |
614 */ | 614 */ |
615 public void deselect (int [] indices) { | 615 public void deselect (int [] indices) { |
616 checkWidget(); | 616 checkWidget(); |
617 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); | 617 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); |
618 NSTableView widget = (NSTableView)view; | 618 NSTableView widget = cast(NSTableView)view; |
619 ignoreSelect = true; | 619 ignoreSelect = true; |
620 for (int i=0; i<indices.length; i++) { | 620 for (int i=0; i<indices.length; i++) { |
621 widget.deselectRow (indices [i]); | 621 widget.deselectRow (indices [i]); |
622 } | 622 } |
623 ignoreSelect = false; | 623 ignoreSelect = false; |
631 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 631 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
632 * </ul> | 632 * </ul> |
633 */ | 633 */ |
634 public void deselectAll () { | 634 public void deselectAll () { |
635 checkWidget (); | 635 checkWidget (); |
636 NSTableView widget = (NSTableView)view; | 636 NSTableView widget = cast(NSTableView)view; |
637 ignoreSelect = true; | 637 ignoreSelect = true; |
638 widget.deselectAll(null); | 638 widget.deselectAll(null); |
639 ignoreSelect = false; | 639 ignoreSelect = false; |
640 } | 640 } |
641 | 641 |
704 if (columnCount is 1) { | 704 if (columnCount is 1) { |
705 //TODO - reset attributes | 705 //TODO - reset attributes |
706 firstColumn = column.nsColumn; | 706 firstColumn = column.nsColumn; |
707 firstColumn.setWidth (0); | 707 firstColumn.setWidth (0); |
708 } else { | 708 } else { |
709 ((NSTableView)view).removeTableColumn(column.nsColumn); | 709 (cast(NSTableView)view).removeTableColumn(column.nsColumn); |
710 } | 710 } |
711 System.arraycopy (columns, index + 1, columns, index, --columnCount - index); | 711 System.arraycopy (columns, index + 1, columns, index, --columnCount - index); |
712 columns [columnCount] = null; | 712 columns [columnCount] = null; |
713 for (int i=index; i<columnCount; i++) { | 713 for (int i=index; i<columnCount; i++) { |
714 columns [i].sendEvent (DWT.Move); | 714 columns [i].sendEvent (DWT.Move); |
722 index++; | 722 index++; |
723 } | 723 } |
724 if (index !is itemCount - 1) fixSelection (index, false); | 724 if (index !is itemCount - 1) fixSelection (index, false); |
725 System.arraycopy (items, index + 1, items, index, --itemCount - index); | 725 System.arraycopy (items, index + 1, items, index, --itemCount - index); |
726 items [itemCount] = null; | 726 items [itemCount] = null; |
727 ((NSTableView)view).noteNumberOfRowsChanged(); | 727 (cast(NSTableView)view).noteNumberOfRowsChanged(); |
728 if (itemCount is 0) { | 728 if (itemCount is 0) { |
729 setTableEmpty (); | 729 setTableEmpty (); |
730 } else { | 730 } else { |
731 // fixScrollBar (); | 731 // fixScrollBar (); |
732 } | 732 } |
910 * | 910 * |
911 * @since 2.0 | 911 * @since 2.0 |
912 */ | 912 */ |
913 public int getHeaderHeight () { | 913 public int getHeaderHeight () { |
914 checkWidget (); | 914 checkWidget (); |
915 NSTableHeaderView headerView = ((NSTableView)view).headerView(); | 915 NSTableHeaderView headerView = (cast(NSTableView)view).headerView(); |
916 if (headerView is null) return 0; | 916 if (headerView is null) return 0; |
917 return (int)headerView.bounds().height; | 917 return cast(int)headerView.bounds().height; |
918 } | 918 } |
919 | 919 |
920 /** | 920 /** |
921 * Returns <code>true</code> if the receiver's header is visible, | 921 * Returns <code>true</code> if the receiver's header is visible, |
922 * and <code>false</code> otherwise. | 922 * and <code>false</code> otherwise. |
934 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 934 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
935 * </ul> | 935 * </ul> |
936 */ | 936 */ |
937 public bool getHeaderVisible () { | 937 public bool getHeaderVisible () { |
938 checkWidget (); | 938 checkWidget (); |
939 return ((NSTableView)view).headerView() !is null; | 939 return (cast(NSTableView)view).headerView() !is null; |
940 } | 940 } |
941 | 941 |
942 int getInsetWidth () { | 942 int getInsetWidth () { |
943 //TODO - wrong | 943 //TODO - wrong |
944 return 20; | 944 return 20; |
992 checkWidget (); | 992 checkWidget (); |
993 // checkItems (true); | 993 // checkItems (true); |
994 // if (point is null) error (DWT.ERROR_NULL_ARGUMENT); | 994 // if (point is null) error (DWT.ERROR_NULL_ARGUMENT); |
995 // Rect rect = new Rect (); | 995 // Rect rect = new Rect (); |
996 // dwt.internal.carbon.Point pt = new dwt.internal.carbon.Point (); | 996 // dwt.internal.carbon.Point pt = new dwt.internal.carbon.Point (); |
997 // OS.SetPt (pt, (short) point.x, (short) point.y); | 997 // OS.SetPt (pt, cast(short) point.x, cast(short) point.y); |
998 // if (0 < lastHittest && lastHittest <= itemCount && lastHittestColumn !is 0) { | 998 // if (0 < lastHittest && lastHittest <= itemCount && lastHittestColumn !is 0) { |
999 // if (OS.GetDataBrowserItemPartBounds (handle, lastHittest, lastHittestColumn, OS.kDataBrowserPropertyEnclosingPart, rect) is OS.noErr) { | 999 // if (OS.GetDataBrowserItemPartBounds (handle, lastHittest, lastHittestColumn, OS.kDataBrowserPropertyEnclosingPart, rect) is OS.noErr) { |
1000 // if (rect.top <= pt.v && pt.v <= rect.bottom) { | 1000 // if (rect.top <= pt.v && pt.v <= rect.bottom) { |
1001 // if ((style & DWT.FULL_SELECTION) !is 0) { | 1001 // if ((style & DWT.FULL_SELECTION) !is 0) { |
1002 // return _getItem (lastHittest - 1); | 1002 // return _getItem (lastHittest - 1); |
1097 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1097 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1098 * </ul> | 1098 * </ul> |
1099 */ | 1099 */ |
1100 public int getItemHeight () { | 1100 public int getItemHeight () { |
1101 checkWidget (); | 1101 checkWidget (); |
1102 return (int)((NSTableView)view).rowHeight(); | 1102 return cast(int)(cast(NSTableView)view).rowHeight(); |
1103 } | 1103 } |
1104 | 1104 |
1105 /** | 1105 /** |
1106 * Returns a (possibly empty) array of <code>TableItem</code>s which | 1106 * Returns a (possibly empty) array of <code>TableItem</code>s which |
1107 * are the items in the receiver. | 1107 * are the items in the receiver. |
1174 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1174 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1175 * </ul> | 1175 * </ul> |
1176 */ | 1176 */ |
1177 public TableItem [] getSelection () { | 1177 public TableItem [] getSelection () { |
1178 checkWidget (); | 1178 checkWidget (); |
1179 NSTableView widget = (NSTableView)view; | 1179 NSTableView widget = cast(NSTableView)view; |
1180 if (widget.numberOfSelectedRows() is 0) { | 1180 if (widget.numberOfSelectedRows() is 0) { |
1181 return new TableItem [0]; | 1181 return new TableItem [0]; |
1182 } | 1182 } |
1183 NSIndexSet selection = widget.selectedRowIndexes(); | 1183 NSIndexSet selection = widget.selectedRowIndexes(); |
1184 int count = selection.count(); | 1184 int count = selection.count(); |
1201 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1201 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1202 * </ul> | 1202 * </ul> |
1203 */ | 1203 */ |
1204 public int getSelectionCount () { | 1204 public int getSelectionCount () { |
1205 checkWidget (); | 1205 checkWidget (); |
1206 return ((NSTableView)view).numberOfSelectedRows(); | 1206 return (cast(NSTableView)view).numberOfSelectedRows(); |
1207 } | 1207 } |
1208 | 1208 |
1209 /** | 1209 /** |
1210 * Returns the zero-relative index of the item which is currently | 1210 * Returns the zero-relative index of the item which is currently |
1211 * selected in the receiver, or -1 if no item is selected. | 1211 * selected in the receiver, or -1 if no item is selected. |
1218 * </ul> | 1218 * </ul> |
1219 */ | 1219 */ |
1220 public int getSelectionIndex () { | 1220 public int getSelectionIndex () { |
1221 checkWidget(); | 1221 checkWidget(); |
1222 //TODO - check empty selection case | 1222 //TODO - check empty selection case |
1223 return ((NSTableView)view).selectedRow(); | 1223 return (cast(NSTableView)view).selectedRow(); |
1224 } | 1224 } |
1225 | 1225 |
1226 /** | 1226 /** |
1227 * Returns the zero-relative indices of the items which are currently | 1227 * Returns the zero-relative indices of the items which are currently |
1228 * selected in the receiver. The order of the indices is unspecified. | 1228 * selected in the receiver. The order of the indices is unspecified. |
1239 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1239 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1240 * </ul> | 1240 * </ul> |
1241 */ | 1241 */ |
1242 public int [] getSelectionIndices () { | 1242 public int [] getSelectionIndices () { |
1243 checkWidget (); | 1243 checkWidget (); |
1244 NSTableView widget = (NSTableView)view; | 1244 NSTableView widget = cast(NSTableView)view; |
1245 if (widget.numberOfSelectedRows() is 0) { | 1245 if (widget.numberOfSelectedRows() is 0) { |
1246 return new int [0]; | 1246 return new int [0]; |
1247 } | 1247 } |
1248 NSIndexSet selection = widget.selectedRowIndexes(); | 1248 NSIndexSet selection = widget.selectedRowIndexes(); |
1249 int count = selection.count(); | 1249 int count = selection.count(); |
1311 //TODO - partial item at the top | 1311 //TODO - partial item at the top |
1312 NSRect rect = scrollView.documentVisibleRect(); | 1312 NSRect rect = scrollView.documentVisibleRect(); |
1313 NSPoint point = new NSPoint(); | 1313 NSPoint point = new NSPoint(); |
1314 point.x = rect.x; | 1314 point.x = rect.x; |
1315 point.y = rect.y; | 1315 point.y = rect.y; |
1316 return ((NSTableView)view).rowAtPoint(point); | 1316 return (cast(NSTableView)view).rowAtPoint(point); |
1317 } | 1317 } |
1318 | 1318 |
1319 | 1319 |
1320 /** | 1320 /** |
1321 * Searches the receiver's list starting at the first column | 1321 * Searches the receiver's list starting at the first column |
1394 * </ul> | 1394 * </ul> |
1395 */ | 1395 */ |
1396 public bool isSelected (int index) { | 1396 public bool isSelected (int index) { |
1397 checkWidget(); | 1397 checkWidget(); |
1398 //TODO - range check | 1398 //TODO - range check |
1399 return ((NSTableView)view).isRowSelected(index); | 1399 return (cast(NSTableView)view).isRowSelected(index); |
1400 } | 1400 } |
1401 | 1401 |
1402 int numberOfRowsInTableView(int aTableView) { | 1402 int numberOfRowsInTableView(int aTableView) { |
1403 return itemCount; | 1403 return itemCount; |
1404 } | 1404 } |
1461 TableItem item = items [index]; | 1461 TableItem item = items [index]; |
1462 if (item !is null) item.release (false); | 1462 if (item !is null) item.release (false); |
1463 if (index !is itemCount - 1) fixSelection (index, false); | 1463 if (index !is itemCount - 1) fixSelection (index, false); |
1464 System.arraycopy (items, index + 1, items, index, --itemCount - index); | 1464 System.arraycopy (items, index + 1, items, index, --itemCount - index); |
1465 items [itemCount] = null; | 1465 items [itemCount] = null; |
1466 ((NSTableView)view).noteNumberOfRowsChanged(); | 1466 (cast(NSTableView)view).noteNumberOfRowsChanged(); |
1467 if (itemCount is 0) { | 1467 if (itemCount is 0) { |
1468 setTableEmpty (); | 1468 setTableEmpty (); |
1469 } else { | 1469 } else { |
1470 // fixScrollBar (); | 1470 // fixScrollBar (); |
1471 } | 1471 } |
1550 for (int i=0; i<itemCount; i++) { | 1550 for (int i=0; i<itemCount; i++) { |
1551 TableItem item = items [i]; | 1551 TableItem item = items [i]; |
1552 if (item !is null && !item.isDisposed ()) item.release (false); | 1552 if (item !is null && !item.isDisposed ()) item.release (false); |
1553 } | 1553 } |
1554 setTableEmpty (); | 1554 setTableEmpty (); |
1555 ((NSTableView)view).noteNumberOfRowsChanged(); | 1555 (cast(NSTableView)view).noteNumberOfRowsChanged(); |
1556 } | 1556 } |
1557 | 1557 |
1558 /** | 1558 /** |
1559 * Removes the listener from the collection of listeners who will | 1559 * Removes the listener from the collection of listeners who will |
1560 * be notified when the user changes the receiver's selection. | 1560 * be notified when the user changes the receiver's selection. |
1593 * </ul> | 1593 * </ul> |
1594 */ | 1594 */ |
1595 public void select (int index) { | 1595 public void select (int index) { |
1596 checkWidget(); | 1596 checkWidget(); |
1597 if (0 <= index && index < itemCount) { | 1597 if (0 <= index && index < itemCount) { |
1598 NSIndexSet indexes = (NSIndexSet)new NSIndexSet().alloc(); | 1598 NSIndexSet indexes = cast(NSIndexSet)new NSIndexSet().alloc(); |
1599 indexes.initWithIndex(index); | 1599 indexes.initWithIndex(index); |
1600 NSTableView widget = (NSTableView)view; | 1600 NSTableView widget = cast(NSTableView)view; |
1601 ignoreSelect = true; | 1601 ignoreSelect = true; |
1602 ((NSTableView)view).selectRowIndexes(indexes, true); | 1602 (cast(NSTableView)view).selectRowIndexes(indexes, true); |
1603 ignoreSelect = false; | 1603 ignoreSelect = false; |
1604 } | 1604 } |
1605 } | 1605 } |
1606 | 1606 |
1607 /** | 1607 /** |
1635 selectAll (); | 1635 selectAll (); |
1636 } else { | 1636 } else { |
1637 start = Math.max (0, start); | 1637 start = Math.max (0, start); |
1638 end = Math.min (end, itemCount - 1); | 1638 end = Math.min (end, itemCount - 1); |
1639 int length = end - start + 1; | 1639 int length = end - start + 1; |
1640 NSIndexSet indexes = (NSIndexSet)new NSIndexSet().alloc(); | 1640 NSIndexSet indexes = cast(NSIndexSet)new NSIndexSet().alloc(); |
1641 NSRange range = new NSRange(); | 1641 NSRange range = new NSRange(); |
1642 range.location = start; | 1642 range.location = start; |
1643 range.length = length; | 1643 range.length = length; |
1644 indexes.initWithIndexesInRange(range); | 1644 indexes.initWithIndexesInRange(range); |
1645 NSTableView widget = (NSTableView)view; | 1645 NSTableView widget = cast(NSTableView)view; |
1646 ignoreSelect = true; | 1646 ignoreSelect = true; |
1647 widget.selectRowIndexes(indexes, true); | 1647 widget.selectRowIndexes(indexes, true); |
1648 ignoreSelect = false; | 1648 ignoreSelect = false; |
1649 } | 1649 } |
1650 } | 1650 } |
1676 checkWidget (); | 1676 checkWidget (); |
1677 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); | 1677 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); |
1678 int length = indices.length; | 1678 int length = indices.length; |
1679 if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; | 1679 if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; |
1680 int count = 0; | 1680 int count = 0; |
1681 NSMutableIndexSet indexes = (NSMutableIndexSet)new NSMutableIndexSet().alloc().init(); | 1681 NSMutableIndexSet indexes = cast(NSMutableIndexSet)new NSMutableIndexSet().alloc().init(); |
1682 for (int i=0; i<length; i++) { | 1682 for (int i=0; i<length; i++) { |
1683 int index = indices [length - i - 1]; | 1683 int index = indices [length - i - 1]; |
1684 if (index >= 0 && index < itemCount) { | 1684 if (index >= 0 && index < itemCount) { |
1685 indexes.addIndex (indices [i]); | 1685 indexes.addIndex (indices [i]); |
1686 count++; | 1686 count++; |
1687 } | 1687 } |
1688 } | 1688 } |
1689 if (count > 0) { | 1689 if (count > 0) { |
1690 NSTableView widget = (NSTableView)view; | 1690 NSTableView widget = cast(NSTableView)view; |
1691 ignoreSelect = true; | 1691 ignoreSelect = true; |
1692 widget.selectRowIndexes(indexes, true); | 1692 widget.selectRowIndexes(indexes, true); |
1693 ignoreSelect = false; | 1693 ignoreSelect = false; |
1694 } | 1694 } |
1695 } | 1695 } |
1696 | 1696 |
1697 void select (int [] ids, int count, bool clear) { | 1697 void select (int [] ids, int count, bool clear) { |
1698 NSMutableIndexSet indexes = (NSMutableIndexSet)new NSMutableIndexSet().alloc().init(); | 1698 NSMutableIndexSet indexes = cast(NSMutableIndexSet)new NSMutableIndexSet().alloc().init(); |
1699 for (int i=0; i<count; i++) indexes.addIndex (ids [i] - 1); //WRONG -1 | 1699 for (int i=0; i<count; i++) indexes.addIndex (ids [i] - 1); //WRONG -1 |
1700 NSTableView widget = (NSTableView)view; | 1700 NSTableView widget = cast(NSTableView)view; |
1701 ignoreSelect = true; | 1701 ignoreSelect = true; |
1702 widget.selectRowIndexes(indexes, !clear); | 1702 widget.selectRowIndexes(indexes, !clear); |
1703 ignoreSelect = false; | 1703 ignoreSelect = false; |
1704 } | 1704 } |
1705 | 1705 |
1715 * </ul> | 1715 * </ul> |
1716 */ | 1716 */ |
1717 public void selectAll () { | 1717 public void selectAll () { |
1718 checkWidget (); | 1718 checkWidget (); |
1719 if ((style & DWT.SINGLE) !is 0) return; | 1719 if ((style & DWT.SINGLE) !is 0) return; |
1720 NSTableView widget = (NSTableView)view; | 1720 NSTableView widget = cast(NSTableView)view; |
1721 ignoreSelect = true; | 1721 ignoreSelect = true; |
1722 widget.selectAll(null); | 1722 widget.selectAll(null); |
1723 ignoreSelect = false; | 1723 ignoreSelect = false; |
1724 } | 1724 } |
1725 | 1725 |
1817 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1817 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1818 * </ul> | 1818 * </ul> |
1819 */ | 1819 */ |
1820 public void setHeaderVisible (bool show) { | 1820 public void setHeaderVisible (bool show) { |
1821 checkWidget (); | 1821 checkWidget (); |
1822 ((NSTableView)view).setHeaderView (show ? headerView : null); | 1822 (cast(NSTableView)view).setHeaderView (show ? headerView : null); |
1823 } | 1823 } |
1824 | 1824 |
1825 /** | 1825 /** |
1826 * Sets the number of items contained in the receiver. | 1826 * Sets the number of items contained in the receiver. |
1827 * | 1827 * |
1885 checkWidget (); | 1885 checkWidget (); |
1886 if (itemHeight < -1) error (DWT.ERROR_INVALID_ARGUMENT); | 1886 if (itemHeight < -1) error (DWT.ERROR_INVALID_ARGUMENT); |
1887 if (itemHeight is -1) { | 1887 if (itemHeight is -1) { |
1888 //TODO - reset item height, ensure other API's such as setFont don't do this | 1888 //TODO - reset item height, ensure other API's such as setFont don't do this |
1889 } else { | 1889 } else { |
1890 // OS.SetDataBrowserTableViewRowHeight (handle, (short) itemHeight); | 1890 // OS.SetDataBrowserTableViewRowHeight (handle, cast(short) itemHeight); |
1891 } | 1891 } |
1892 } | 1892 } |
1893 | 1893 |
1894 /** | 1894 /** |
1895 * Marks the receiver's lines as visible if the argument is <code>true</code>, | 1895 * Marks the receiver's lines as visible if the argument is <code>true</code>, |
1907 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1907 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1908 * </ul> | 1908 * </ul> |
1909 */ | 1909 */ |
1910 public void setLinesVisible (bool show) { | 1910 public void setLinesVisible (bool show) { |
1911 checkWidget (); | 1911 checkWidget (); |
1912 ((NSTableView)view).setUsesAlternatingRowBackgroundColors(show); | 1912 (cast(NSTableView)view).setUsesAlternatingRowBackgroundColors(show); |
1913 } | 1913 } |
1914 | 1914 |
1915 bool setScrollWidth (TableItem item) { | 1915 bool setScrollWidth (TableItem item) { |
1916 if (columnCount !is 0) return false; | 1916 if (columnCount !is 0) return false; |
1917 if (currentItem !is null) { | 1917 if (currentItem !is null) { |
1924 gc.dispose (); | 1924 gc.dispose (); |
1925 newWidth += getInsetWidth (); | 1925 newWidth += getInsetWidth (); |
1926 // short [] width = new short [1]; | 1926 // short [] width = new short [1]; |
1927 // OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width); | 1927 // OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width); |
1928 // if (width [0] < newWidth) { | 1928 // if (width [0] < newWidth) { |
1929 // OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) newWidth); | 1929 // OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, cast(short) newWidth); |
1930 // return true; | 1930 // return true; |
1931 // } | 1931 // } |
1932 if (firstColumn.width() < newWidth) { | 1932 if (firstColumn.width() < newWidth) { |
1933 firstColumn.setWidth (newWidth); | 1933 firstColumn.setWidth (newWidth); |
1934 } | 1934 } |
1955 // if (!set) { | 1955 // if (!set) { |
1956 // short [] width = new short [1]; | 1956 // short [] width = new short [1]; |
1957 // OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width); | 1957 // OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width); |
1958 // if (width [0] >= newWidth) return false; | 1958 // if (width [0] >= newWidth) return false; |
1959 // } | 1959 // } |
1960 // OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) newWidth); | 1960 // OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, cast(short) newWidth); |
1961 if (!set) { | 1961 if (!set) { |
1962 if (firstColumn.width() > newWidth) return false; | 1962 if (firstColumn.width() > newWidth) return false; |
1963 } | 1963 } |
1964 firstColumn.setWidth (newWidth); | 1964 firstColumn.setWidth (newWidth); |
1965 return true; | 1965 return true; |
2162 // OS.GetDataBrowserCallbacks (handle, callbacks); | 2162 // OS.GetDataBrowserCallbacks (handle, callbacks); |
2163 // callbacks.v1_itemCompareCallback = display.itemCompareProc; | 2163 // callbacks.v1_itemCompareCallback = display.itemCompareProc; |
2164 // OS.SetDataBrowserCallbacks (handle, callbacks); | 2164 // OS.SetDataBrowserCallbacks (handle, callbacks); |
2165 // if (column is null) { | 2165 // if (column is null) { |
2166 // if (sortColumn !is null && !sortColumn.isDisposed () && sortDirection !is DWT.NONE) { | 2166 // if (sortColumn !is null && !sortColumn.isDisposed () && sortDirection !is DWT.NONE) { |
2167 // OS.SetDataBrowserSortOrder (handle, (short) OS.kDataBrowserOrderIncreasing); | 2167 // OS.SetDataBrowserSortOrder (handle, cast(short) OS.kDataBrowserOrderIncreasing); |
2168 // sortColumn = null; | 2168 // sortColumn = null; |
2169 // OS.SetDataBrowserSortProperty (handle, 0); | 2169 // OS.SetDataBrowserSortProperty (handle, 0); |
2170 // } | 2170 // } |
2171 // } | 2171 // } |
2172 // sortColumn = column; | 2172 // sortColumn = column; |
2173 // if (sortColumn !is null && !sortColumn.isDisposed () && sortDirection !is DWT.NONE) { | 2173 // if (sortColumn !is null && !sortColumn.isDisposed () && sortDirection !is DWT.NONE) { |
2174 // OS.SetDataBrowserSortProperty (handle, sortColumn.id); | 2174 // OS.SetDataBrowserSortProperty (handle, sortColumn.id); |
2175 // int order = sortDirection is DWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing; | 2175 // int order = sortDirection is DWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing; |
2176 // OS.SetDataBrowserSortOrder (handle, (short) order); | 2176 // OS.SetDataBrowserSortOrder (handle, cast(short) order); |
2177 // } | 2177 // } |
2178 // callbacks.v1_itemCompareCallback = itemCompareProc (); | 2178 // callbacks.v1_itemCompareCallback = itemCompareProc (); |
2179 // OS.SetDataBrowserCallbacks (handle, callbacks); | 2179 // OS.SetDataBrowserCallbacks (handle, callbacks); |
2180 } | 2180 } |
2181 | 2181 |
2201 // OS.GetDataBrowserCallbacks (handle, callbacks); | 2201 // OS.GetDataBrowserCallbacks (handle, callbacks); |
2202 // callbacks.v1_itemCompareCallback = display.itemCompareProc; | 2202 // callbacks.v1_itemCompareCallback = display.itemCompareProc; |
2203 // OS.SetDataBrowserCallbacks (handle, callbacks); | 2203 // OS.SetDataBrowserCallbacks (handle, callbacks); |
2204 // if (sortColumn !is null && !sortColumn.isDisposed ()) { | 2204 // if (sortColumn !is null && !sortColumn.isDisposed ()) { |
2205 // if (sortDirection is DWT.NONE) { | 2205 // if (sortDirection is DWT.NONE) { |
2206 // OS.SetDataBrowserSortOrder (handle, (short) OS.kDataBrowserOrderIncreasing); | 2206 // OS.SetDataBrowserSortOrder (handle, cast(short) OS.kDataBrowserOrderIncreasing); |
2207 // TableColumn column = sortColumn; | 2207 // TableColumn column = sortColumn; |
2208 // sortColumn = null; | 2208 // sortColumn = null; |
2209 // OS.SetDataBrowserSortProperty (handle, 0); | 2209 // OS.SetDataBrowserSortProperty (handle, 0); |
2210 // sortColumn = column; | 2210 // sortColumn = column; |
2211 // } else { | 2211 // } else { |
2212 // OS.SetDataBrowserSortProperty (handle, 0); | 2212 // OS.SetDataBrowserSortProperty (handle, 0); |
2213 // OS.SetDataBrowserSortProperty (handle, sortColumn.id); | 2213 // OS.SetDataBrowserSortProperty (handle, sortColumn.id); |
2214 // int order = sortDirection is DWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing; | 2214 // int order = sortDirection is DWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing; |
2215 // OS.SetDataBrowserSortOrder (handle, (short) order); | 2215 // OS.SetDataBrowserSortOrder (handle, cast(short) order); |
2216 // } | 2216 // } |
2217 // } | 2217 // } |
2218 // callbacks.v1_itemCompareCallback = itemCompareProc (); | 2218 // callbacks.v1_itemCompareCallback = itemCompareProc (); |
2219 // OS.SetDataBrowserCallbacks (handle, callbacks); | 2219 // OS.SetDataBrowserCallbacks (handle, callbacks); |
2220 } | 2220 } |
2236 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 2236 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
2237 * </ul> | 2237 * </ul> |
2238 */ | 2238 */ |
2239 public void setTopIndex (int index) { | 2239 public void setTopIndex (int index) { |
2240 checkWidget(); | 2240 checkWidget(); |
2241 NSRect rect = ((NSTableView)view).rectOfRow(index); | 2241 NSRect rect = (cast(NSTableView)view).rectOfRow(index); |
2242 ((NSTableView)view).scrollRectToVisible(rect); | 2242 (cast(NSTableView)view).scrollRectToVisible(rect); |
2243 } | 2243 } |
2244 | 2244 |
2245 /** | 2245 /** |
2246 * Shows the column. If the column is already showing in the receiver, | 2246 * Shows the column. If the column is already showing in the receiver, |
2247 * this method simply returns. Otherwise, the columns are scrolled until | 2247 * this method simply returns. Otherwise, the columns are scrolled until |
2265 if (column is null) error (DWT.ERROR_NULL_ARGUMENT); | 2265 if (column is null) error (DWT.ERROR_NULL_ARGUMENT); |
2266 if (column.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT); | 2266 if (column.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT); |
2267 if (column.parent !is this) return; | 2267 if (column.parent !is this) return; |
2268 int index = indexOf (column); | 2268 int index = indexOf (column); |
2269 if (columnCount <= 1 || !(0 <= index && index < columnCount)) return; | 2269 if (columnCount <= 1 || !(0 <= index && index < columnCount)) return; |
2270 ((NSTableView)view).scrollColumnToVisible(index + ((style & DWT.CHECK) !is 0 ? 1 : 0)); | 2270 (cast(NSTableView)view).scrollColumnToVisible(index + ((style & DWT.CHECK) !is 0 ? 1 : 0)); |
2271 } | 2271 } |
2272 | 2272 |
2273 void showIndex (int index) { | 2273 void showIndex (int index) { |
2274 if (0 <= index && index < itemCount) { | 2274 if (0 <= index && index < itemCount) { |
2275 ((NSTableView)view).scrollRowToVisible(index); | 2275 (cast(NSTableView)view).scrollRowToVisible(index); |
2276 } | 2276 } |
2277 } | 2277 } |
2278 | 2278 |
2279 /** | 2279 /** |
2280 * Shows the item. If the item is already showing in the receiver, | 2280 * Shows the item. If the item is already showing in the receiver, |
2324 postEvent (DWT.DefaultSelection); | 2324 postEvent (DWT.DefaultSelection); |
2325 } | 2325 } |
2326 | 2326 |
2327 void tableViewSelectionDidChange (int aNotification) { | 2327 void tableViewSelectionDidChange (int aNotification) { |
2328 if (ignoreSelect) return; | 2328 if (ignoreSelect) return; |
2329 NSTableView widget = (NSTableView)view; | 2329 NSTableView widget = cast(NSTableView)view; |
2330 int row = widget.selectedRow(); | 2330 int row = widget.selectedRow(); |
2331 if(row is -1) | 2331 if(row is -1) |
2332 postEvent(DWT.Selection); | 2332 postEvent(DWT.Selection); |
2333 else { | 2333 else { |
2334 TableItem item = _getItem(row); | 2334 TableItem item = _getItem(row); |