diff options
author | Scott Kovatch <skovatch> | 2010-11-16 17:10:59 +0000 |
---|---|---|
committer | Scott Kovatch <skovatch> | 2010-11-16 17:10:59 +0000 |
commit | b6d9911240fd498e3f172d356c74aa9dea6cee07 (patch) | |
tree | 8a5cb2748c91756b2b9bc18db6c6c8ad4241838d /bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets | |
parent | deae4ffede0b128d12edaa3fadba406eb7ad3185 (diff) | |
download | eclipse.platform.swt-b6d9911240fd498e3f172d356c74aa9dea6cee07.tar.gz eclipse.platform.swt-b6d9911240fd498e3f172d356c74aa9dea6cee07.tar.xz eclipse.platform.swt-b6d9911240fd498e3f172d356c74aa9dea6cee07.zip |
329840 - click on checkbox shouldn't select row.
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets')
4 files changed, 141 insertions, 20 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index e2ef89b9b7..14209a6984 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -151,6 +151,9 @@ public class Display extends Device { Control focusControl, currentFocusControl; int focusEvent; + /* Table/Tree click tracking */ + int /*long*/ trackedButtonRow = -1; + NSWindow screenWindow, keyWindow; NSAutoreleasePool[] pools; @@ -2428,11 +2431,12 @@ void initClasses () { OS.class_addMethod(cls, OS.sel_outlineView_child_ofItem_, proc5, "@:@i@"); OS.class_addMethod(cls, OS.sel_outlineView_isItemExpandable_, proc4, "@:@@"); OS.class_addMethod(cls, OS.sel_outlineView_numberOfChildrenOfItem_, proc4, "@:@@"); - OS.class_addMethod(cls, OS.sel_outlineView_selectionIndexesForProposedSelection_, proc4, "@:@@"); OS.class_addMethod(cls, OS.sel_outlineView_objectValueForTableColumn_byItem_, proc5, "@:@@@"); OS.class_addMethod(cls, OS.sel_outlineView_willDisplayCell_forTableColumn_item_, proc6, "@:@@@@"); OS.class_addMethod(cls, OS.sel_outlineView_setObjectValue_forTableColumn_byItem_, proc6, "@:@@@@"); OS.class_addMethod(cls, OS.sel_outlineView_shouldEditTableColumn_item_, proc5, "@:@@@"); + OS.class_addMethod(cls, OS.sel_outlineView_shouldSelectItem_, proc4, "@:@@"); + OS.class_addMethod(cls, OS.sel_outlineView_shouldTrackCell_forTableColumn_item_, proc6, "@:@@@i"); OS.class_addMethod(cls, OS.sel_outlineViewColumnDidMove_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_outlineViewColumnDidResize_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_outlineView_didClickTableColumn_, proc4, "@:@@"); @@ -2599,6 +2603,8 @@ void initClasses () { OS.class_addMethod(cls, OS.sel_numberOfRowsInTableView_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_tableView_objectValueForTableColumn_row_, proc5, "@:@@i"); OS.class_addMethod(cls, OS.sel_tableView_shouldEditTableColumn_row_, proc5, "@:@@i"); + OS.class_addMethod(cls, OS.sel_tableView_shouldSelectRow_, proc4, "@:@i"); + OS.class_addMethod(cls, OS.sel_tableView_shouldTrackCell_forTableColumn_row_, proc6, "@:@@@i"); OS.class_addMethod(cls, OS.sel_tableViewSelectionIsChanging_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_tableViewSelectionDidChange_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_tableView_willDisplayCell_forTableColumn_row_, proc6, "@:@@@i"); @@ -2606,7 +2612,6 @@ void initClasses () { OS.class_addMethod(cls, OS.sel_tableViewColumnDidMove_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_tableViewColumnDidResize_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_tableView_didClickTableColumn_, proc4, "@:@@"); - OS.class_addMethod(cls, OS.sel_tableView_selectionIndexesForProposedSelection_, proc4, "@:@@"); OS.class_addMethod(cls, OS.sel_canDragRowsWithIndexes_atPoint_, canDragRowsWithIndexes_atPoint_Proc, "@:@{NSPoint=ff}"); OS.class_addMethod(cls, OS.sel_tableView_writeRowsWithIndexes_toPasteboard_, proc5, "@:@@@"); OS.class_addMethod(cls, OS.sel_drawBackgroundInClipRect_, drawBackgroundInClipRectProc, "@:{NSRect}"); @@ -5457,12 +5462,12 @@ static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ a return widget.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1); } else if (sel == OS.sel_tableView_didClickTableColumn_) { widget.tableView_didClickTableColumn (id, sel, arg0, arg1); - } else if (sel == OS.sel_tableView_selectionIndexesForProposedSelection_) { - return widget.tableView_selectionIndexesForProposedSelection(id, sel, arg0, arg1); + } else if (sel == OS.sel_tableView_shouldSelectRow_) { + return (widget.tableView_shouldSelectRow(id, sel, arg0, arg1) ? 1 : 0); } else if (sel == OS.sel_outlineView_didClickTableColumn_) { widget.outlineView_didClickTableColumn (id, sel, arg0, arg1); - } else if (sel == OS.sel_outlineView_selectionIndexesForProposedSelection_) { - return widget.outlineView_selectionIndexesForProposedSelection(id, sel, arg0, arg1); + } else if (sel == OS.sel_outlineView_shouldSelectItem_) { + return (widget.outlineView_shouldSelectItem(id, sel, arg0, arg1) ? 1 : 0); } else if (sel == OS.sel_shouldChangeTextInRange_replacementString_) { return widget.shouldChangeTextInRange_replacementString(id, sel, arg0, arg1) ? 1 : 0; } else if (sel == OS.sel_canDragRowsWithIndexes_atPoint_) { @@ -5561,6 +5566,10 @@ static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ a widget.tableView_setObjectValue_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3); } else if (sel == OS.sel_view_stringForToolTip_point_userData_) { return widget.view_stringForToolTip_point_userData(id, sel, arg0, arg1, arg2, arg3); + } else if (sel == OS.sel_tableView_shouldTrackCell_forTableColumn_row_) { + return (widget.tableView_shouldTrackCell_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3) ? 1 : 0); + } else if (sel == OS.sel_outlineView_shouldTrackCell_forTableColumn_item_) { + return (widget.outlineView_shouldTrackCell_forTableColumn_item(id, sel, arg0, arg1, arg2, arg3) ? 1 : 0); } return 0; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java index 7df91205a7..1547c96fbb 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java @@ -1987,6 +1987,7 @@ void mouseDownSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { } } } + display.trackedButtonRow = -1; didSelect = false; super.mouseDownSuper(id, sel, theEvent); didSelect = false; @@ -2000,7 +2001,8 @@ void mouseDownSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { */ int /*long*/ nextState (int /*long*/ id, int /*long*/ sel) { NSTableView tableView = (NSTableView)view; - int index = (int)/*64*/tableView.selectedRow (); + int index = (int)/*64*/tableView.clickedRow(); + if (index == -1) index = (int)/*64*/tableView.selectedRow (); TableItem item = items[index]; if (item.grayed) { return item.checked ? OS.NSOffState : OS.NSMixedState; @@ -3206,6 +3208,64 @@ int /*long*/ tableView_selectionIndexesForProposedSelection (int /*long*/ id, in return indexSet; } +boolean tableView_shouldSelectRow(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ rowIndex) { + boolean result = true; + + if ((style & SWT.SINGLE) != 0) { + /* + * Feature in Cocoa. Calling setAllowsEmptySelection will automatically select the first row of the list. + * And, single-selection NSTable/OutlineViews allow the user to de-select the selected item via command-click. + * This is normal platform behavior, but for compatibility with other platforms, if the SINGLE style is in use, + * force a selection by seeing if the proposed selection set is empty, and if so, put back the currently selected row. + */ + NSTableView table = new NSTableView(aTableView); + NSIndexSet indexes = table.selectedRowIndexes(); + if (indexes.count() != 1 && table.selectedRow() != -1) { + return false; + } + } + + // If a checkbox is being tracked don't select the row. + if (display.trackedButtonRow != -1) return false; + NSTableView tableView = (NSTableView)view; + int /*long*/ clickedCol = tableView.clickedColumn(); + int /*long*/ clickedRow = tableView.clickedRow(); + if (clickedRow >= 0 && clickedCol >= 0) { + NSCell cell = tableView.preparedCellAtColumn(clickedCol, clickedRow); + if (cell.isKindOfClass(OS.class_NSButtonCell) && cell.isEnabled()) { + NSRect cellFrame = tableView.frameOfCellAtColumn(clickedCol, clickedRow); + NSRect imageFrame = cell.imageRectForBounds(cellFrame); + NSPoint hitPoint = tableView.convertPoint_fromView_(NSApplication.sharedApplication().currentEvent().locationInWindow(), null); + result = ! OS.NSPointInRect(hitPoint, imageFrame) || didSelect; + } + } + return result; +} + +boolean tableView_shouldTrackCell_forTableColumn_row(int /*long*/ id, int /*long*/ sel, + int /*long*/ table, int /*long*/ cell, /*long*/ int /*long*/ tableColumn, int /*long*/ rowIndex) { + NSCell theCell = new NSCell(cell); + NSTableView tableView = (NSTableView)view; + if (theCell.isKindOfClass(OS.class_NSButtonCell)) { + // Allow tracking of the checkbox area of the button, not the text itself. + int columnIndex = 0; + for (int i=0; i<columnCount; i++) { + if (columns [i].nsColumn.id == tableColumn) { + columnIndex = i; + break; + } + } + NSRect cellFrame = tableView.frameOfCellAtColumn(columnIndex, rowIndex); + NSRect imageFrame = theCell.imageRectForBounds(cellFrame); + NSPoint hitPoint = tableView.convertPoint_fromView_(NSApplication.sharedApplication().currentEvent().locationInWindow(), null); + boolean shouldTrack = OS.NSPointInRect(hitPoint, imageFrame) && (display.trackedButtonRow == -1 || display.trackedButtonRow == rowIndex) && !didSelect; + if (OS.NSPointInRect(hitPoint, imageFrame) && display.trackedButtonRow == -1 && !didSelect) display.trackedButtonRow = rowIndex; + return shouldTrack; + } else { + return tableView.isRowSelected(rowIndex); + } +} + void tableView_setObjectValue_forTableColumn_row (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ anObject, int /*long*/ aTableColumn, int /*long*/ rowIndex) { if (checkColumn != null && aTableColumn == checkColumn.id) { TableItem item = items [(int)/*64*/rowIndex]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java index 81c153de87..f70fc90292 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java @@ -2030,6 +2030,7 @@ void mouseDownSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { } } } + display.trackedButtonRow = -1; didSelect = false; super.mouseDownSuper(id, sel, theEvent); didSelect = false; @@ -2043,7 +2044,8 @@ void mouseDownSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { */ int /*long*/ nextState (int /*long*/ id, int /*long*/ sel) { NSOutlineView outlineView = (NSOutlineView)view; - int index = (int)/*64*/outlineView.selectedRow (); + int index = (int)/*64*/outlineView.clickedRow(); + if (index == -1) index = (int)/*64*/outlineView.selectedRow (); TreeItem item = (TreeItem)display.getWidget (outlineView.itemAtRow (index).id); if (item.grayed) { return item.checked ? OS.NSOffState : OS.NSMixedState; @@ -2093,7 +2095,10 @@ int /*long*/ outlineView_numberOfChildrenOfItem (int /*long*/ id, int /*long*/ s return ((TreeItem) display.getWidget (item)).itemCount; } -int /*long*/ outlineView_selectionIndexesForProposedSelection (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ indexSet) { +boolean outlineView_shouldSelectItem(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ item) { + boolean result = true; + NSOutlineView tree = new NSOutlineView(aTableView); + if ((style & SWT.SINGLE) != 0) { /* * Feature in Cocoa. Calling setAllowsEmptySelection will automatically select the first row of the list. @@ -2101,19 +2106,54 @@ int /*long*/ outlineView_selectionIndexesForProposedSelection (int /*long*/ id, * This is normal platform behavior, but for compatibility with other platforms, if the SINGLE style is in use, * force a selection by seeing if the proposed selection set is empty, and if so, put back the currently selected row. */ - NSIndexSet indexes = new NSIndexSet(indexSet); - NSOutlineView table = new NSOutlineView(aTableView); - if (indexes.count() != 1 && table.selectedRow() != -1) { - NSIndexSet newSelection = (NSIndexSet)new NSIndexSet().alloc(); - newSelection = newSelection.initWithIndex(table.selectedRow()); - newSelection.autorelease(); - return newSelection.id; + NSIndexSet indexes = tree.selectedRowIndexes(); + if (indexes.count() != 1 && tree.selectedRow() != -1) { + return false; } } - - return indexSet; + + // If a checkbox is being tracked don't select the row. + if (display.trackedButtonRow != -1) return false; + int /*long*/ clickedCol = tree.clickedColumn(); + int /*long*/ clickedRow = tree.clickedRow(); + if (clickedRow >= 0 && clickedCol >= 0) { + NSCell cell = tree.preparedCellAtColumn(clickedCol, clickedRow); + if (cell.isKindOfClass(OS.class_NSButtonCell) && cell.isEnabled()) { + NSRect cellFrame = tree.frameOfCellAtColumn(clickedCol, clickedRow); + NSRect imageFrame = cell.imageRectForBounds(cellFrame); + NSPoint hitPoint = tree.convertPoint_fromView_(NSApplication.sharedApplication().currentEvent().locationInWindow(), null); + result = ! OS.NSPointInRect(hitPoint, imageFrame) || didSelect; + } + } + return result; +} + +boolean outlineView_shouldTrackCell_forTableColumn_item(int /*long*/ id, int /*long*/ sel, + int /*long*/ table, int /*long*/ cell, /*long*/ int /*long*/ tableColumn, int /*long*/ item) { + NSCell theCell = new NSCell(cell); + NSOutlineView tableView = (NSOutlineView)view; + int /*long*/ rowIndex = tableView.rowForItem(new id(item)); + if (theCell.isKindOfClass(OS.class_NSButtonCell)) { + // Allow tracking of the checkbox area of the button, not the text itself. + int columnIndex = 0; + for (int i=0; i<columnCount; i++) { + if (columns [i].nsColumn.id == tableColumn) { + columnIndex = i; + break; + } + } + NSRect cellFrame = tableView.frameOfCellAtColumn(columnIndex, rowIndex); + NSRect imageFrame = theCell.imageRectForBounds(cellFrame); + NSPoint hitPoint = tableView.convertPoint_fromView_(NSApplication.sharedApplication().currentEvent().locationInWindow(), null); + boolean shouldTrack = OS.NSPointInRect(hitPoint, imageFrame) && (display.trackedButtonRow == -1 || display.trackedButtonRow == rowIndex) && !didSelect; + if (OS.NSPointInRect(hitPoint, imageFrame) && display.trackedButtonRow == -1 && !didSelect) display.trackedButtonRow = rowIndex; + return shouldTrack; + } else { + return tableView.isRowSelected(rowIndex); + } } + void outlineView_willDisplayCell_forTableColumn_item (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ cell, int /*long*/ tableColumn, int /*long*/ itemID) { if (checkColumn != null && tableColumn == checkColumn.id) return; TreeItem item = (TreeItem) display.getWidget(itemID); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java index 460f906f55..adfa2052a6 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java @@ -1194,8 +1194,12 @@ int /*long*/ outlineView_numberOfChildrenOfItem(int /*long*/ id, int /*long*/ se return 0; } -int /*long*/ outlineView_selectionIndexesForProposedSelection (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ indexSet) { - return indexSet; +boolean outlineView_shouldTrackCell_forTableColumn_item(int /*long*/ id, int /*long*/ sel, int /*long*/ table, int /*long*/ cell, /*long*/ int /*long*/ tableColumn, int /*long*/ item) { + return true; +} + +boolean outlineView_shouldSelectItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tableView, int /*long*/ index) { + return true; } boolean outlineView_shouldEditTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ item) { @@ -1907,6 +1911,14 @@ int /*long*/ tableView_selectionIndexesForProposedSelection (int /*long*/ id, in return indexSet; } +boolean tableView_shouldTrackCell_forTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ table, int /*long*/ cell, /*long*/ int /*long*/ tableColumn, int /*long*/ rowIndex) { + return true; +} + +boolean tableView_shouldSelectRow(int /*long*/ id, int /*long*/ sel, int /*long*/ tableView, int /*long*/ index) { + return true; +} + void tableView_setObjectValue_forTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ anObject, int /*long*/ aTableColumn, int /*long*/ rowIndex) { } |