Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2018-11-06 20:00:03 +0000
committerLakshmi Shanmugam2018-11-13 05:34:50 +0000
commit8f55d9b6505aac00a079044efa47358ee5b5ba43 (patch)
tree5868c218799fbd22a8a4afff59088125373ff554
parentaa28988509bf66a25e26fa397ecd87a084fec0a0 (diff)
downloadeclipse.platform.swt-8f55d9b6505aac00a079044efa47358ee5b5ba43.tar.gz
eclipse.platform.swt-8f55d9b6505aac00a079044efa47358ee5b5ba43.tar.xz
eclipse.platform.swt-8f55d9b6505aac00a079044efa47358ee5b5ba43.zip
Bug 536193 - SWT.NO_RADIO_GROUP not working on Cocoa
Change-Id: I835a156c9fef61587a077f628ac0040455e23f90 Signed-off-by: Till Brychcy <register.eclipse@brychcy.de>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java27
1 files changed, 23 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java
index 42f43735cd..2e20e38246 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java
@@ -53,9 +53,9 @@ public class Button extends Control {
/**
* On MacOS 10.8 and later Radiobuttons with the same parent view and action are automatically in group,
- * so the state of the NSButton cannot be used to detect if a selection event should be sent when a button is deselected.
+ * which is avoided by wrapping them individually in an extra parent view.
*/
- private boolean lastRadioState;
+ private SWTView radioParent;
private static final double /*float*/ [] DEFAULT_DISABLED_FOREGROUND = new double /*float*/ [] { 0.6745f, 0.6745f, 0.6745f, 1.0f };
@@ -264,6 +264,7 @@ void createHandle () {
type = OS.NSSwitchButton;
} else if ((style & SWT.RADIO) != 0) {
type = OS.NSRadioButton;
+ radioParent = (SWTView) new SWTView().alloc().init();
} else if ((style & SWT.TOGGLE) != 0) {
type = OS.NSPushOnPushOffButton;
if ((style & SWT.FLAT) != 0) {
@@ -304,6 +305,7 @@ NSFont defaultNSFont() {
void deregister () {
super.deregister ();
display.removeWidget(((NSControl)view).cell());
+ if (radioParent != null) display.removeWidget(radioParent);
}
@Override
@@ -706,6 +708,7 @@ long /*int*/ nextState(long /*int*/ id, long /*int*/ sel) {
void register() {
super.register();
display.addWidget(((NSControl)view).cell(), this);
+ if (radioParent != null) display.addWidget(radioParent, this);
}
@Override
@@ -857,6 +860,12 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean resiz
}
}
super.setBounds(x, y, width, height, move, resize);
+ if (radioParent != null && resize) {
+ NSSize size = new NSSize();
+ size.width = width;
+ size.height = height;
+ view.setFrameSize(size);
+ }
}
@Override
@@ -961,7 +970,7 @@ public void setImage (Image image) {
@Override
boolean setRadioSelection (boolean value){
if ((style & SWT.RADIO) == 0) return false;
- if (getSelection() != value || lastRadioState != value) {
+ if (getSelection() != value) {
setSelection (value);
sendSelectionEvent (SWT.Selection);
}
@@ -992,7 +1001,6 @@ public void setSelection (boolean selected) {
} else {
((NSButton)view).setState (selected ? OS.NSOnState : OS.NSOffState);
}
- lastRadioState = selected;
}
/**
@@ -1069,4 +1077,15 @@ void updateAlignment () {
}
}
+@Override
+NSView topView() {
+ if (radioParent != null) return radioParent;
+ return super.topView();
+}
+
+@Override
+void setZOrder() {
+ super.setZOrder();
+ if (radioParent != null) radioParent.addSubview(view);
+}
}

Back to the top