comparison dwt/custom/TableCursor.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children fd9c62a2998e
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
158 Table table; 158 Table table;
159 TableItem row = null; 159 TableItem row = null;
160 TableColumn column = null; 160 TableColumn column = null;
161 Listener tableListener, resizeListener, disposeItemListener, disposeColumnListener; 161 Listener tableListener, resizeListener, disposeItemListener, disposeColumnListener;
162 162
163 Color background = null;
164 Color foreground = null;
165
163 // By default, invert the list selection colors 166 // By default, invert the list selection colors
164 static final int BACKGROUND = DWT.COLOR_LIST_SELECTION_TEXT; 167 static final int BACKGROUND = DWT.COLOR_LIST_SELECTION_TEXT;
165 static final int FOREGROUND = DWT.COLOR_LIST_SELECTION; 168 static final int FOREGROUND = DWT.COLOR_LIST_SELECTION;
166 169
167 /** 170 /**
251 table.addListener(DWT.FocusIn, tableListener); 254 table.addListener(DWT.FocusIn, tableListener);
252 table.addListener(DWT.MouseDown, tableListener); 255 table.addListener(DWT.MouseDown, tableListener);
253 256
254 disposeItemListener = new class() Listener { 257 disposeItemListener = new class() Listener {
255 public void handleEvent(Event event) { 258 public void handleEvent(Event event) {
259 unhookRowColumnListeners();
256 row = null; 260 row = null;
257 column = null; 261 column = null;
258 _resize(); 262 _resize();
259 } 263 }
260 }; 264 };
261 disposeColumnListener = new class() Listener { 265 disposeColumnListener = new class() Listener {
262 public void handleEvent(Event event) { 266 public void handleEvent(Event event) {
267 unhookRowColumnListeners();
263 row = null; 268 row = null;
264 column = null; 269 column = null;
265 _resize(); 270 _resize();
266 } 271 }
267 }; 272 };
317 } 322 }
318 323
319 void dispose(Event event) { 324 void dispose(Event event) {
320 table.removeListener(DWT.FocusIn, tableListener); 325 table.removeListener(DWT.FocusIn, tableListener);
321 table.removeListener(DWT.MouseDown, tableListener); 326 table.removeListener(DWT.MouseDown, tableListener);
322 if (column !is null) { 327 unhookRowColumnListeners();
323 column.removeListener(DWT.Dispose, disposeColumnListener);
324 column.removeListener(DWT.Move, resizeListener);
325 column.removeListener(DWT.Resize, resizeListener);
326 column = null;
327 }
328 if (row !is null) {
329 row.removeListener(DWT.Dispose, disposeItemListener);
330 row = null;
331 }
332 ScrollBar hBar = table.getHorizontalBar(); 328 ScrollBar hBar = table.getHorizontalBar();
333 if (hBar !is null) { 329 if (hBar !is null) {
334 hBar.removeListener(DWT.Selection, resizeListener); 330 hBar.removeListener(DWT.Selection, resizeListener);
335 } 331 }
336 ScrollBar vBar = table.getVerticalBar(); 332 ScrollBar vBar = table.getVerticalBar();
490 gc.drawFocus(0, 0, size.x, size.y); 486 gc.drawFocus(0, 0, size.x, size.y);
491 } 487 }
492 } 488 }
493 489
494 void tableFocusIn(Event event) { 490 void tableFocusIn(Event event) {
495 if (isDisposed()) 491 if (isDisposed()) return;
496 return; 492 if (isVisible()) {
497 if (isVisible()) 493 if (row is null && column is null) return;
498 setFocus(); 494 setFocus();
495 }
499 } 496 }
500 497
501 void tableMouseDown(Event event) { 498 void tableMouseDown(Event event) {
502 if (isDisposed() || !isVisible()) return; 499 if (isDisposed() || !isVisible()) return;
503 Point pt = new Point(event.x, event.y); 500 Point pt = new Point(event.x, event.y);
520 } 517 }
521 if (item is null) return; 518 if (item is null) return;
522 } 519 }
523 TableColumn newColumn = null; 520 TableColumn newColumn = null;
524 int columnCount = table.getColumnCount(); 521 int columnCount = table.getColumnCount();
525 if (columnCount > 0) { 522 if (columnCount is 0) {
523 if ((table.getStyle() & DWT.FULL_SELECTION) is 0) {
524 Rectangle rect = item.getBounds(0);
525 rect.width += lineWidth;
526 rect.height += lineWidth;
527 if (!rect.contains(pt)) return;
528 }
529 } else {
526 for (int i = 0; i < columnCount; i++) { 530 for (int i = 0; i < columnCount; i++) {
527 Rectangle rect = item.getBounds(i); 531 Rectangle rect = item.getBounds(i);
528 rect.width += lineWidth; 532 rect.width += lineWidth;
529 rect.height += lineWidth; 533 rect.height += lineWidth;
530 if (rect.contains(pt)) { 534 if (rect.contains(pt)) {
531 newColumn = table.getColumn(i); 535 newColumn = table.getColumn(i);
532 break; 536 break;
533 } 537 }
534 } 538 }
535 if (newColumn is null) { 539 if (newColumn is null) {
540 if ((table.getStyle() & DWT.FULL_SELECTION) is 0) return;
536 newColumn = table.getColumn(0); 541 newColumn = table.getColumn(0);
537 } 542 }
538 } 543 }
539 setRowColumn(item, newColumn, true); 544 setRowColumn(item, newColumn, true);
540 setFocus(); 545 setFocus();
636 public int getColumn() { 641 public int getColumn() {
637 checkWidget(); 642 checkWidget();
638 return column is null ? 0 : table.indexOf(column); 643 return column is null ? 0 : table.indexOf(column);
639 } 644 }
640 /** 645 /**
646 * Returns the background color that the receiver will use to draw.
647 *
648 * @return the receiver's background color
649 */
650 public Color getBackground() {
651 checkWidget();
652 if (background is null) {
653 return getDisplay().getSystemColor(BACKGROUND);
654 }
655 return background;
656 }
657 /**
658 * Returns the foreground color that the receiver will use to draw.
659 *
660 * @return the receiver's foreground color
661 */
662 public Color getForeground() {
663 checkWidget();
664 if (foreground is null) {
665 return getDisplay().getSystemColor(FOREGROUND);
666 }
667 return foreground;
668 }
669 /**
641 * Returns the row over which the TableCursor is positioned. 670 * Returns the row over which the TableCursor is positioned.
642 * 671 *
643 * @return the item for the current position 672 * @return the item for the current position
644 * 673 *
645 * @exception DWTException <ul> 674 * @exception DWTException <ul>
649 */ 678 */
650 public TableItem getRow() { 679 public TableItem getRow() {
651 checkWidget(); 680 checkWidget();
652 return row; 681 return row;
653 } 682 }
683 /**
684 * Sets the receiver's background color to the color specified
685 * by the argument, or to the default system color for the control
686 * if the argument is null.
687 * <p>
688 * Note: This operation is a hint and may be overridden by the platform.
689 * For example, on Windows the background of a Button cannot be changed.
690 * </p>
691 * @param color the new color (or null)
692 *
693 * @exception IllegalArgumentException <ul>
694 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
695 * </ul>
696 * @exception DWTException <ul>
697 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
698 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
699 * </ul>
700 */
654 public override void setBackground (Color color) { 701 public override void setBackground (Color color) {
655 if (color is null) color = getDisplay().getSystemColor(BACKGROUND); 702 background = color;
656 super.setBackground(color); 703 super.setBackground(getBackground());
657 redraw(); 704 redraw();
658 } 705 }
706 /**
707 * Sets the receiver's foreground color to the color specified
708 * by the argument, or to the default system color for the control
709 * if the argument is null.
710 * <p>
711 * Note: This operation is a hint and may be overridden by the platform.
712 * </p>
713 * @param color the new color (or null)
714 *
715 * @exception IllegalArgumentException <ul>
716 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
717 * </ul>
718 * @exception DWTException <ul>
719 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
720 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
721 * </ul>
722 */
659 public override void setForeground (Color color) { 723 public override void setForeground (Color color) {
660 if (color is null) color = getDisplay().getSystemColor(FOREGROUND); 724 foreground = color;
661 super.setForeground(color); 725 super.setForeground(getForeground());
662 redraw(); 726 redraw();
663 } 727 }
664 /** 728 /**
665 * Positions the TableCursor over the cell at the given row and column in the parent table. 729 * Positions the TableCursor over the cell at the given row and column in the parent table.
666 * 730 *
705 || column < 0 769 || column < 0
706 || column > maxColumnIndex) 770 || column > maxColumnIndex)
707 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 771 DWT.error(DWT.ERROR_INVALID_ARGUMENT);
708 setRowColumn(table.indexOf(row), column, false); 772 setRowColumn(table.indexOf(row), column, false);
709 } 773 }
710 } 774 void unhookRowColumnListeners() {
775 if (column !is null) {
776 column.removeListener(DWT.Dispose, disposeColumnListener);
777 column.removeListener(DWT.Move, resizeListener);
778 column.removeListener(DWT.Resize, resizeListener);
779 column = null;
780 }
781 if (row !is null) {
782 row.removeListener(DWT.Dispose, disposeItemListener);
783 row = null;
784 }
785 }
786 }