diff options
author | Silenio Quarti <silenio> | 2005-10-24 19:01:51 +0000 |
---|---|---|
committer | Silenio Quarti <silenio> | 2005-10-24 19:01:51 +0000 |
commit | 25da20bae532d82803a26e72660be3bef057a85e (patch) | |
tree | 5391d9dc475edd77956904155891f3f03e94c85b | |
parent | b48c0188461603c1ee49112ea7db13d25d3dec5b (diff) | |
download | eclipse.platform.swt-25da20bae532d82803a26e72660be3bef057a85e.tar.gz eclipse.platform.swt-25da20bae532d82803a26e72660be3bef057a85e.tar.xz eclipse.platform.swt-25da20bae532d82803a26e72660be3bef057a85e.zip |
34612 - vertical scroll bar not updated when items are removed
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java | 30 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java | 33 |
2 files changed, 58 insertions, 5 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java index 1f7cada108..e96aa7e819 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java @@ -864,7 +864,11 @@ void destroyItem (TableItem item) { System.arraycopy (items, index + 1, items, index, --itemCount - index); items [itemCount] = null; OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem); - if (itemCount == 0) setTableEmpty (); + if (itemCount == 0) { + setTableEmpty (); + } else { + fixScrollBar (); + } } int drawItemProc (int browser, int id, int property, int itemState, int theRect, int gdDepth, int colorDevice) { @@ -979,6 +983,21 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect, return OS.noErr; } +void fixScrollBar () { + /* + * Bug in the Macintosh. For some reason, the data browser does not update + * the vertical scrollbar when it is scrolled to the bottom and items are + * removed. The fix is to check if the scrollbar value is bigger the + * maximum number of visible items and clamp it when needed. + */ + int [] top = new int [1], left = new int [1]; + OS.GetDataBrowserScrollPosition (handle, top, left); + int maximum = Math.max (0, getItemHeight () * itemCount - getClientArea ().height); + if (top [0] > maximum) { + OS.SetDataBrowserScrollPosition (handle, maximum, left [0]); + } +} + void fixSelection (int index, boolean add) { int [] selection = getSelectionIndices (); if (selection.length == 0) return; @@ -2041,7 +2060,11 @@ public void remove (int index) { System.arraycopy (items, index + 1, items, index, --itemCount - index); items [itemCount] = null; OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem); - if (itemCount == 0) setTableEmpty (); + if (itemCount == 0) { + setTableEmpty (); + } else { + fixScrollBar (); + } } /** @@ -2138,7 +2161,6 @@ public void removeAll () { OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, 0, null, 0); callbacks.v1_itemNotificationCallback = display.itemNotificationProc; OS.SetDataBrowserCallbacks (handle, callbacks); - OS.SetDataBrowserScrollPosition (handle, 0, 0); setTableEmpty (); } @@ -2503,6 +2525,7 @@ public void setItemCount (int count) { OS.AddDataBrowserItems (handle, 0, itemCount, null, OS.kDataBrowserItemNoProperty); callbacks.v1_itemNotificationCallback = display.itemNotificationProc; OS.SetDataBrowserCallbacks (handle, callbacks); + fixScrollBar (); setRedraw (true); } @@ -2830,6 +2853,7 @@ public void setSortDirection (int direction) { } void setTableEmpty () { + OS.SetDataBrowserScrollPosition (handle, 0, 0); itemCount = anchorFirst = anchorLast = 0; items = new TableItem [4]; if (imageBounds != null) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java index e3c0fe5cb7..327de7fb19 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java @@ -58,7 +58,7 @@ public class Tree extends Composite { boolean ignoreRedraw, ignoreSelect, wasSelected, ignoreExpand, wasExpanded; Rectangle imageBounds; TreeItem showItem; - int lastHittest; + int lastHittest, visibleCount; static final int CHECK_COLUMN_ID = 1024; static final int COLUMN_ID = 1025; static final int GRID_WIDTH = 1; @@ -501,6 +501,7 @@ void createItem (TreeItem item, TreeItem parentItem, int index) { items [id] = null; error (SWT.ERROR_ITEM_NOT_ADDED); } + visibleCount++; } else { /* * Bug in the Macintosh. When the first child of a tree item is @@ -670,6 +671,7 @@ void destroyItem (TreeItem item) { if (OS.RemoveDataBrowserItems (handle, parentID, 1, new int[] {item.id}, 0) != OS.noErr) { error (SWT.ERROR_ITEM_NOT_REMOVED); } + visibleCount--; ignoreExpand = false; } boolean hasChild = false; @@ -693,6 +695,7 @@ void destroyItem (TreeItem item) { //TEMPORARY CODE releaseItem (item, false); setScrollWidth (); + fixScrollBar (); } int drawItemProc (int browser, int id, int property, int itemState, int theRect, int gdDepth, int colorDevice) { @@ -806,6 +809,21 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect, return OS.noErr; } +void fixScrollBar () { + /* + * Bug in the Macintosh. For some reason, the data browser does not update + * the vertical scrollbar when it is scrolled to the bottom and items are + * removed. The fix is to check if the scrollbar value is bigger the + * maximum number of visible items and clamp it when needed. + */ + int [] top = new int [1], left = new int [1]; + OS.GetDataBrowserScrollPosition (handle, top, left); + int maximum = Math.max (0, getItemHeight () * visibleCount - getClientArea ().height); + if (top [0] > maximum) { + OS.SetDataBrowserScrollPosition (handle, maximum, left [0]); + } +} + int getCheckColumnWidth () { int inset = 0; if (OS.VERSION >= 0x1040) { @@ -1771,6 +1789,14 @@ int itemNotificationProc (int browser, int id, int message) { break; } case OS.kDataBrowserContainerClosing: { + + int ptr = OS.NewHandle (0); + if (OS.GetDataBrowserItems (handle, id, true, 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 @@ -1778,7 +1804,7 @@ int itemNotificationProc (int browser, int id, int message) { * fix is to deselect these items ignoring kDataBrowserItemDeselected and then * issue a selection event. */ - int ptr = OS.NewHandle (0); + ptr = OS.NewHandle (0); if (OS.GetDataBrowserItems (handle, id, true, OS.kDataBrowserItemIsSelected, ptr) == OS.noErr) { int count = OS.GetHandleSize (ptr) / 4; if (count > 0) { @@ -1825,6 +1851,7 @@ int itemNotificationProc (int browser, int id, int message) { sendEvent (SWT.Collapse, event); } setScrollWidth (); + fixScrollBar (); break; } case OS.kDataBrowserContainerOpened: { @@ -1852,6 +1879,7 @@ int itemNotificationProc (int browser, int id, int message) { } } OS.AddDataBrowserItems (handle, id, ids.length, ids, OS.kDataBrowserItemNoProperty); + visibleCount += ids.length; setScrollWidth (newItems, false); break; } @@ -2026,6 +2054,7 @@ public void removeAll () { ignoreExpand = false; OS.SetDataBrowserScrollPosition (handle, 0, 0); anchorFirst = anchorLast = 0; + visibleCount = 0; setScrollWidth (); } |