diff options
author | Steve Northover <steve> | 2002-10-30 20:09:31 +0000 |
---|---|---|
committer | Steve Northover <steve> | 2002-10-30 20:09:31 +0000 |
commit | 04ac6e8392db54e20567dedfb52656e6c81376c9 (patch) | |
tree | 08083c33b3b931134aead594fbe87013e018c7bf | |
parent | 4222a06bf89edd9ebd45aeb45cd7f08f2954a65a (diff) | |
download | eclipse.platform.swt-04ac6e8392db54e20567dedfb52656e6c81376c9.tar.gz eclipse.platform.swt-04ac6e8392db54e20567dedfb52656e6c81376c9.tar.xz eclipse.platform.swt-04ac6e8392db54e20567dedfb52656e6c81376c9.zip |
24359
4 files changed, 73 insertions, 26 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java index f4f4e25a40..96ce8ae607 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java @@ -475,7 +475,9 @@ int processFocusOut () { } int processSelection (Object callData) { if ((style & SWT.RADIO) != 0) { - if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) selectRadio (); + if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) { + selectRadio (); + } } return super.processSelection (callData); } @@ -523,19 +525,13 @@ public void removeSelectionListener(SelectionListener listener) { eventTable.unhook(SWT.DefaultSelection,listener); } void selectRadio () { + int index = 0; Control [] children = parent._getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (this != child && child instanceof Button) { - Button button = (Button) child; - if ((button.getStyle () & SWT.RADIO) != 0) { - if (button.getSelection ()) { - button.setSelection (false); - button.postEvent (SWT.Selection); - } - } - } - } + while (index < children.length && children [index] != this) index++; + int i = index - 1; + while (i >= 0 && children [i].setRadioSelection (false)) --i; + int j = index + 1; + while (j < children.length && children [j].setRadioSelection (false)) j++; setSelection (true); } /** @@ -602,6 +598,14 @@ public void setImage (Image image) { } else setMode(0); } +boolean setRadioSelection (boolean value) { + if ((style & SWT.RADIO) == 0) return false; + if (getSelection () != value) { + setSelection (value); + postEvent (SWT.Selection); + } + return true; +} /** * Sets the selection state of the receiver, if it is of type <code>CHECK</code>, * <code>RADIO</code>, or <code>TOGGLE</code>. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Control.java index 78e100a6fa..9718d7b788 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Control.java @@ -2104,7 +2104,9 @@ public boolean setParent (Composite parent) { if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); return false; } - +boolean setRadioSelection (boolean value) { + return false; +} /** * If the argument is <code>false</code>, causes subsequent drawing * operations in the receiver to be ignored. No drawing of any kind diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java index c3ac9d6e47..d4253c0816 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java @@ -312,8 +312,16 @@ public boolean getSelection () { } void handleMenuSelect () { - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { + if ((style & SWT.CHECK) != 0) { setSelection (!getSelection ()); + } else { + if ((style & SWT.RADIO) != 0) { + if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) { + setSelection (!getSelection ()); + } else { + selectRadio (); + } + } } Event event = new Event (); /* AW @@ -397,6 +405,9 @@ void releaseWidget () { menu = null; super.releaseWidget (); accelerator = 0; + if (this == parent.defaultItem) { + parent.defaultItem = null; + } Decorations shell = parent.parent; shell.remove (this); parent = null; @@ -479,6 +490,17 @@ public void removeSelectionListener (SelectionListener listener) { eventTable.unhook (SWT.DefaultSelection,listener); } +void selectRadio () { + int index = 0; + MenuItem [] items = parent.getItems (); + while (index < items.length && items [index] != this) index++; + int i = index - 1; + while (i >= 0 && items [i].setRadioSelection (false)) --i; + int j = index + 1; + while (j < items.length && items [j].setRadioSelection (false)) j++; + setSelection (true); +} + /** * Sets the widget accelerator. An accelerator is the bit-wise * OR of zero or more modifier masks and a key. Examples: @@ -543,9 +565,15 @@ public void setAccelerator (int accelerator) { */ public void setEnabled (boolean enabled) { checkWidget (); + short [] outIndex = new short [1]; + OS.GetIndMenuItemWithCommandID (parent.handle, id, 1, null, outIndex); + int outMenuRef [] = new int [1]; + OS.GetMenuItemHierarchicalMenu (parent.handle, outIndex [0], outMenuRef); if (enabled) { + if (outMenuRef [0] != 0) OS.EnableMenuItem (outMenuRef [0], (short) 0); OS.EnableMenuCommand (parent.handle, id); } else { + if (outMenuRef [0] != 0) OS.DisableMenuItem (outMenuRef [0], (short) 0); OS.DisableMenuCommand (parent.handle, id); } } @@ -636,6 +664,15 @@ public void setMenu (Menu menu) { } } +boolean setRadioSelection (boolean value) { + if ((style & SWT.RADIO) == 0) return false; + if (getSelection () != value) { + setSelection (value); + postEvent (SWT.Selection); + } + return true; +} + /** * Sets the selection state of the receiver. * <p> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java index bc0054812e..dfe20976fc 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java @@ -544,19 +544,14 @@ public void removeSelectionListener(SelectionListener listener) { eventTable.unhook(SWT.DefaultSelection,listener); } void selectRadio () { - this.setSelection (true); - ToolItem [] items = parent.getItems (); int index = 0; + ToolItem [] items = parent.getItems (); while (index < items.length && items [index] != this) index++; - ToolItem item; - int i = index; - while (--i >= 0 && ((item = items [i]).style & SWT.RADIO) != 0) { - item.setSelection (false); - } - i = index; - while (++i < items.length && ((item = items [i]).style & SWT.RADIO) != 0) { - item.setSelection (false); - } + int i = index - 1; + while (i >= 0 && items [i].setRadioSelection (false)) --i; + int j = index + 1; + while (j < items.length && items [j].setRadioSelection (false)) j++; + setSelection (true); } /* * This setBounds is only called from ToolBar.relayout() @@ -681,6 +676,15 @@ public void setImage (Image image) { //redraw (); } +boolean setRadioSelection (boolean value) { + if ((style & SWT.RADIO) == 0) return false; + if (getSelection () != value) { + setSelection (value); + postEvent (SWT.Selection); + } + return true; +} + /** * Sets the selection state of the receiver. * <p> |