diff options
author | Veronika Irvine <veronika> | 2005-06-08 12:57:07 +0000 |
---|---|---|
committer | Veronika Irvine <veronika> | 2005-06-08 12:57:07 +0000 |
commit | d0a02b5fe5dc8e5435ab975c91e0ce2da6cb3682 (patch) | |
tree | 0a5bfc8b28af6e9597df959d4ad72ed6a47b9796 | |
parent | d2291e408cccebb2b5324af06dcc1449f6e28e05 (diff) | |
download | eclipse.platform.swt-d0a02b5fe5dc8e5435ab975c91e0ce2da6cb3682.tar.gz eclipse.platform.swt-d0a02b5fe5dc8e5435ab975c91e0ce2da6cb3682.tar.xz eclipse.platform.swt-d0a02b5fe5dc8e5435ab975c91e0ce2da6cb3682.zip |
Bug97915 - restore selection when items added or removed
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java | 22 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java | 32 |
2 files changed, 54 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java index 7d06750340..e20bd08921 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java @@ -138,6 +138,7 @@ public void add (String string, int index) { if (OS.AddDataBrowserItems (handle, OS.kDataBrowserNoItem, 1, id, OS.kDataBrowserItemNoProperty) != OS.noErr) { error (SWT.ERROR_ITEM_NOT_ADDED); } + if (index != itemCount) fixSelection (index, true); if (itemCount == items.length) { String [] newItems = new String [itemCount + 4]; System.arraycopy (items, 0, newItems, 0, items.length); @@ -411,6 +412,26 @@ public void deselectAll () { deselect (null, 0); } +void fixSelection (int index, boolean add) { + int [] selection = getSelectionIndices (); + if (selection.length == 0) return; + int newCount = 0; + boolean fix = false; + for (int i = 0; i < selection.length; i++) { + if (!add && selection [i] == index) { + fix = true; + } else { + int newIndex = newCount++; + selection [newIndex] = selection [i] + 1; + if (selection [newIndex] - 1 >= index) { + selection [newIndex] += add ? 1 : -1; + fix = true; + } + } + } + if (fix) select (selection, newCount, true); +} + public Rectangle getClientArea () { checkWidget(); int border = 0; @@ -870,6 +891,7 @@ public boolean isSelected (int index) { public void remove (int index) { checkWidget(); if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); + if (index != itemCount - 1) fixSelection (index, false); int [] id = new int [] {itemCount}; if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) { error (SWT.ERROR_ITEM_NOT_REMOVED); 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 f329d6bcc6..b91938872c 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 @@ -578,6 +578,7 @@ void createItem (TableItem item, int index) { if (OS.AddDataBrowserItems (handle, OS.kDataBrowserNoItem, 1, id, OS.kDataBrowserItemNoProperty) != OS.noErr) { error (SWT.ERROR_ITEM_NOT_ADDED); } + if (index != itemCount) fixSelection (index, true); } if (itemCount == items.length) { /* Grow the array faster when redraw is off */ @@ -693,6 +694,15 @@ public void deselect (int [] indices) { void deselect (int [] ids, int count) { 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]; @@ -811,6 +821,7 @@ void destroyItem (TableItem item) { if (items [index] == item) break; index++; } + if (index != itemCount - 1) fixSelection (index, false); int [] id = new int [] {itemCount}; if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) { error (SWT.ERROR_ITEM_NOT_REMOVED); @@ -923,6 +934,26 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect, return OS.noErr; } +void fixSelection (int index, boolean add) { + int [] selection = getSelectionIndices (); + if (selection.length == 0) return; + int newCount = 0; + boolean fix = false; + for (int i = 0; i < selection.length; i++) { + if (!add && selection [i] == index) { + fix = true; + } else { + int newIndex = newCount++; + selection [newIndex] = selection [i] + 1; + if (selection [newIndex] - 1 >= index) { + selection [newIndex] += add ? 1 : -1; + fix = true; + } + } + } + if (fix) select (selection, newCount, true); +} + public Rectangle getClientArea () { checkWidget(); int border = 0; @@ -1712,6 +1743,7 @@ public void remove (int index) { checkWidget(); checkItems (true); if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); + if (index != itemCount - 1) fixSelection (index, false); int [] id = new int [] {itemCount}; if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) { error (SWT.ERROR_ITEM_NOT_REMOVED); |