summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/cocoa
diff options
context:
space:
mode:
authorCarolyn MacLeod <Carolyn_MacLeod@ca.ibm.com>2012-03-07 16:17:05 -0500
committerCarolyn MacLeod <Carolyn_MacLeod@ca.ibm.com>2012-03-07 16:17:05 -0500
commit4cf183f94d4d4d275955b891045c44c32b075e0a (patch)
treec838e3ad4e10341221c5dbd6882a73e439f6d3a0 /bundles/org.eclipse.swt/Eclipse SWT/cocoa
parent0baf41d40f3dd8716522c72f50e1eb2c9697bedd (diff)
downloadeclipse.platform.swt-4cf183f94d4d4d275955b891045c44c32b075e0a.tar.gz
eclipse.platform.swt-4cf183f94d4d4d275955b891045c44c32b075e0a.tar.xz
eclipse.platform.swt-4cf183f94d4d4d275955b891045c44c32b075e0a.zip
Bug 212023 - limitation of SWT ColorDialog
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/cocoa')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java
index 908cc57869..6810c32d96 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java
@@ -34,6 +34,7 @@ import org.eclipse.swt.internal.cocoa.*;
*/
public class ColorDialog extends Dialog {
RGB rgb;
+ RGB [] rgbs;
boolean selected;
/**
@@ -106,6 +107,19 @@ public RGB getRGB() {
}
/**
+ * Returns an array of <code>RGB</code>s which are the list of
+ * custom colors selected by the user in the receiver, or null
+ * if no custom colors were selected.
+ *
+ * @return the array of RGBs, which may be null
+ *
+ * @since 3.8
+ */
+public RGB[] getRGBs() {
+ return rgbs;
+}
+
+/**
* Makes the receiver visible and brings it to the front
* of the display.
*
@@ -127,6 +141,33 @@ public RGB open() {
NSColor color = NSColor.colorWithDeviceRed(rgb.red / 255f, rgb.green / 255f, rgb.blue / 255f, 1);
panel.setColor(color);
}
+ NSString appName = Display.getApplicationName();
+ NSColorList colorList = NSColorList.colorListNamed(appName);
+ if (colorList == null) {
+ colorList = (NSColorList)new NSColorList().alloc();
+ colorList.initWithName(appName);
+ panel.attachColorList(colorList);
+ } else {
+ colorList.retain();
+ }
+ if (rgbs != null) {
+ NSArray keys = colorList.allKeys();
+ int length = keys.count();
+ for (int i=length-1; i>=0; i--) {
+ colorList.removeColorWithKey(new NSString(keys.objectAtIndex(i)));
+ }
+ for (int i=0; i<rgbs.length; i++) {
+ RGB rgb = rgbs [i];
+ if (rgb != null) {
+ NSColor color = NSColor.colorWithDeviceRed(rgb.red / 255f, rgb.green / 255f, rgb.blue / 255f, 1);
+ NSString key = appName;
+ if (i > 0) {
+ key = key.stringByAppendingString(NSString.stringWith(" "+i));
+ }
+ colorList.insertColor(color, key, i);
+ }
+ }
+ }
SWTPanelDelegate delegate = (SWTPanelDelegate)new SWTPanelDelegate().alloc().init();
int /*long*/ jniRef = OS.NewGlobalRef(this);
if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
@@ -148,6 +189,15 @@ public RGB open() {
rgb = new RGB((int)(handle[0] * 255), (int)(handle[1] * 255), (int)(handle[2] * 255));
}
}
+ NSArray keys = colorList.allKeys();
+ int length = keys.count();
+ rgbs = new RGB[length];
+ for (int i=0; i<length; i++) {
+ NSString key = new NSString(keys.objectAtIndex(i));
+ float /*double*/ [] handle = display.getNSColorRGB(colorList.colorWithKey(key));
+ rgbs[i] = new RGB((int)(handle[0] * 255), (int)(handle[1] * 255), (int)(handle[2] * 255));
+ }
+ colorList.release();
return rgb;
}
@@ -163,6 +213,19 @@ public void setRGB(RGB rgb) {
this.rgb = rgb;
}
+/**
+ * Sets the receiver's list of custom colors to be the given array
+ * of <code>RGB</code>s, which may be null to let the platform select
+ * a default when open() is called.
+ *
+ * @param rgbs the array of RGBs, which may be null
+ *
+ * @since 3.8
+ */
+public void setRGBs(RGB[] rgbs) {
+ this.rgbs = rgbs;
+}
+
void windowWillClose(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
NSApplication.sharedApplication().stop(null);
}