int index = id - 1; if (!(0 <= index && index < items.length)) return OS.noErr; TreeItem item = items [index];
if (!(0 < id && id <= items.length)) return OS.noErr;
int itemNotificationProc (int browser, int id, int message) {	if (message == OS.kDataBrowserUserStateChanged) {		short [] width = new short [1];		TreeColumn [] newColumns = getColumns ();		for (int i = 0; i < columnCount; i++) {			TreeColumn column = newColumns [i];			if (!column.isDisposed ()) {				OS.GetDataBrowserTableViewNamedColumnWidth (handle, column.id, width);				if (width [0] != column.lastWidth) {					column.resized (width [0]);					return OS.noErr;				}			}			if (!column.isDisposed ()) {				int [] position = new int[1];				OS.GetDataBrowserTableViewColumnPosition (handle, column.id, position);				if (position [0] != column.lastPosition) {					column.lastPosition = position [0];					int order = (style & SWT.CHECK) != 0 ? position [0] - 1 : position [0];					if (order == 0) {						int [] disclosure = new int [1];						boolean [] expandableRows = new boolean [1];						OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, expandableRows);						if (disclosure [0] != column.id) {							OS.SetDataBrowserListViewDisclosureColumn (handle, column.id, expandableRows [0]);						}					}					column.sendEvent (SWT.Move);				}			}		}		int [] property = new int [1];		OS.GetDataBrowserSortProperty (handle, property);		if (property [0] != 0) {			for (int i = 0; i < columnCount; i++) {				TreeColumn column = columns [i];				if (property [0] == column.id) {					column.postEvent (clickCount == 2 ? SWT.DefaultSelection : SWT.Selection);					break;				}			}			OS.SetDataBrowserSortProperty (handle, 0);			if (sortColumn != null && !sortColumn.isDisposed () && sortDirection != SWT.NONE) {				OS.SetDataBrowserSortProperty (handle, sortColumn.id);				OS.SetDataBrowserSortOrder (handle, sortDirection == SWT.DOWN ? (short)2 : (short)1);			}		}		return OS.noErr;	}	int index = id - 1;	if (!(0 <= index && index < items.length)) return OS.noErr;	TreeItem item = items [index];	switch (message) {		case OS.kDataBrowserItemSelected:		case OS.kDataBrowserItemDeselected: {			wasSelected = true;			if (ignoreSelect) break;			int [] first = new int [1], last = new int [1];			OS.GetDataBrowserSelectionAnchor (handle, first, last);			boolean selected = false;			if ((style & SWT.MULTI) != 0) {				int modifiers = OS.GetCurrentEventKeyModifiers ();				if ((modifiers & OS.shiftKey) != 0) {					if (message == OS.kDataBrowserItemSelected) {						selected = first [0] == id || last [0] == id;					} else {						selected = id == anchorFirst || id == anchorLast;					}				} else {					if ((modifiers & OS.cmdKey) != 0) {						selected = true;					} else {						selected = first [0] == last [0];					}				}			} else {				selected = message == OS.kDataBrowserItemSelected;			}			if (selected) {				anchorFirst = first [0];				anchorLast = last [0];				Event event = new Event ();				event.item = item;				postEvent (SWT.Selection, event);			}			break;		}			case OS.kDataBrowserItemDoubleClicked: {			wasSelected = true;			Event event = new Event ();			event.item = item;			postEvent (SWT.DefaultSelection, event);			break;		}		case OS.kDataBrowserContainerClosing: {			int ptr = OS.NewHandle (0);			if (OS.GetDataBrowserItems (handle, id, false, OS.kDataBrowserItemAnyState, ptr) == OS.noErr) {				int count = OS.GetHandleSize (ptr) / 4;				visibleCount -= count;			}			OS.DisposeHandle (ptr);			/*			* Bug in the Macintosh.  For some reason, if the selected sub items of an item			* get a kDataBrowserItemDeselected notificaton when the item is collapsed, a			* call to GetDataBrowserSelectionAnchor () will cause a segment fault.  The			* fix is to deselect these items ignoring kDataBrowserItemDeselected and then			* issue a selection event.			*/			ptr = OS.NewHandle (0);			if (OS.GetDataBrowserItems (handle, id, true, OS.kDataBrowserItemIsSelected, ptr) == OS.noErr) {				int count = OS.GetHandleSize (ptr) / 4;				if (count > 0) {					int [] ids = new int [count];					OS.HLock (ptr);					int [] start = new int [1];					OS.memcpy (start, ptr, 4);					OS.memcpy (ids, start [0], count * 4);					OS.HUnlock (ptr);					ignoreSelect = true;					/*					* Bug in the Macintosh.  When the DataBroswer selection flags includes					* both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,				  * two items are selected when SetDataBrowserSelectedItems() is called				  * with kDataBrowserItemsAssign to assign a new seletion despite the fact					* that kDataBrowserSelectOnlyOne was specified.  The fix is to save and					* restore kDataBrowserNeverEmptySelectionSet around each call to					* SetDataBrowserSelectedItems().					*/					int [] selectionFlags = null;					if ((style & SWT.SINGLE) != 0) {						selectionFlags = new int [1];						OS.GetDataBrowserSelectionFlags (handle, selectionFlags);						OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);					}					OS.SetDataBrowserSelectedItems (handle, ids.length, ids, OS.kDataBrowserItemsRemove);					if ((style & SWT.SINGLE) != 0) {						OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);					}					ignoreSelect = false;					Event event = new Event ();					event.item = item;					sendEvent (SWT.Selection, event);				}			}			OS.DisposeHandle (ptr);			break;		}		case OS.kDataBrowserContainerClosed: {			wasExpanded = true;			if (!ignoreExpand) {				Event event = new Event ();				event.item = item;				sendEvent (SWT.Collapse, event);			}			setScrollWidth ();			fixScrollBar ();			break;		}		case OS.kDataBrowserContainerOpened: {			wasExpanded = true;			if (!ignoreExpand) {				Event event = new Event ();				event.item = item;				try {					item.state |= EXPANDING;					sendEvent (SWT.Expand, event);				} finally {					item.state &= ~EXPANDING;				}			}			int count = 0;			for (int i=0; i<items.length; i++) {				if (items [i] != null && items [i].parentItem == item) count++;			}			TreeItem [] newItems = new TreeItem [count];			int [] ids = new int [count];			for (int i=0; i<items.length; i++) {				if (items [i] != null && items [i].parentItem == item) {					ids [items [i].index] = items [i].id;					newItems [items [i].index] = items [i];				}			}			OS.AddDataBrowserItems (handle, id, ids.length, ids, OS.kDataBrowserItemNoProperty);			visibleCount += ids.length;			setScrollWidth (newItems, false);			break;		}	}	return OS.noErr;}