Mercurial > projects > dwt-mac
annotate dwt/widgets/ColorDialog.d @ 53:6914d8d302de
Updated ColorDialog to 3.514
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 08 Dec 2008 21:23:00 +0100 |
parents | d8635bb48c7c |
children | c74ba20de292 |
rev | line source |
---|---|
45 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
7 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
8 * Contributors: |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
10 * |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
11 * Port to the D programming language: |
45 | 12 * Jacob Carlborg <doob@me.com> |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
13 *******************************************************************************/ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
14 module dwt.widgets.ColorDialog; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
15 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
16 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
17 import dwt.DWT; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
18 import dwt.DWTException; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
19 import dwt.graphics.PaletteData; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
20 import dwt.graphics.RGB; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
21 import dwt.internal.cocoa.NSApplication; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
22 import dwt.internal.cocoa.NSColor; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
23 import dwt.internal.cocoa.NSColorPanel; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
24 import dwt.internal.cocoa.OS; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
25 import dwt.internal.cocoa.SWTPanelDelegate; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
26 |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
27 import dwt.dwthelper.utils; |
53 | 28 import dwt.internal.objc.cocoa.Cocoa; |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
29 import dwt.widgets.Dialog; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
30 import dwt.widgets.Display; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
31 import dwt.widgets.Shell; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
32 |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
33 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
34 * Instances of this class allow the user to select a color |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
35 * from a predefined set of available colors. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
36 * <dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
37 * <dt><b>Styles:</b></dt> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
38 * <dd>(none)</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
39 * <dt><b>Events:</b></dt> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
40 * <dd>(none)</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
41 * </dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
42 * <p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
43 * IMPORTANT: This class is intended to be subclassed <em>only</em> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
44 * within the DWT implementation. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
45 * </p> |
45 | 46 * |
47 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a> | |
48 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
49 */ |
3 | 50 public class ColorDialog : Dialog { |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
51 RGB rgb; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
52 |
53 | 53 /** |
54 * Constructs a new instance of this class given only its parent. | |
55 * | |
56 * @param parent a composite control which will be the parent of the new instance | |
57 * | |
58 * @exception IllegalArgumentException <ul> | |
59 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
60 * </ul> | |
61 * @exception DWTException <ul> | |
62 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
63 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
64 * </ul> | |
65 * | |
66 * @see DWT | |
67 * @see Widget#checkSubclass | |
68 * @see Widget#getStyle | |
69 */ | |
70 public this(Shell parent) { | |
71 this(parent, DWT.APPLICATION_MODAL); | |
72 } | |
73 | |
74 /** | |
75 * Constructs a new instance of this class given its parent | |
76 * and a style value describing its behavior and appearance. | |
77 * <p> | |
78 * The style value is either one of the style constants defined in | |
79 * class <code>DWT</code> which is applicable to instances of this | |
80 * class, or must be built by <em>bitwise OR</em>'ing together | |
81 * (that is, using the <code>int</code> "|" operator) two or more | |
82 * of those <code>DWT</code> style constants. The class description | |
83 * lists the style constants that are applicable to the class. | |
84 * Style bits are also inherited from superclasses. | |
85 * </p> | |
86 * | |
87 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
88 * @param style the style of control to construct | |
89 * | |
90 * @exception IllegalArgumentException <ul> | |
91 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
92 * </ul> | |
93 * @exception DWTException <ul> | |
94 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
95 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
96 * </ul> | |
97 * | |
98 * @see DWT | |
99 * @see Widget#checkSubclass | |
100 * @see Widget#getStyle | |
101 */ | |
102 public this(Shell parent, int style) { | |
45 | 103 super (parent, checkStyle (parent, style)); |
53 | 104 checkSubclass (); |
105 } | |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
106 |
45 | 107 void changeColor(objc.id id, objc.SEL sel, objc.id sender) { |
53 | 108 //TODO |
109 } | |
110 | |
111 /** | |
112 * Returns the currently selected color in the receiver. | |
113 * | |
114 * @return the RGB value for the selected color, may be null | |
115 * | |
116 * @see PaletteData#getRGBs | |
117 */ | |
118 public RGB getRGB() { | |
119 return rgb; | |
120 } | |
121 | |
122 /** | |
123 * Makes the receiver visible and brings it to the front | |
124 * of the display. | |
125 * | |
126 * @return the selected color, or null if the dialog was | |
127 * cancelled, no color was selected, or an error | |
128 * occurred | |
129 * | |
130 * @exception DWTException <ul> | |
131 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
132 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
133 * </ul> | |
134 */ | |
135 public RGB open() { | |
136 NSColorPanel panel = NSColorPanel.sharedColorPanel(); | |
137 if (rgb !is null) { | |
138 NSColor color = NSColor.colorWithDeviceRed(rgb.red / 255f, rgb.green / 255f, rgb.blue / 255f, 1); | |
139 panel.setColor(color); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
140 } |
53 | 141 SWTPanelDelegate delegate_ = cast(SWTPanelDelegate)(new SWTPanelDelegate()).alloc().init(); |
142 void* jniRef = OS.NewGlobalRef(this); | |
143 if (jniRef is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
144 OS.object_setInstanceVariable(delegate_.id, Display.SWT_OBJECT, jniRef); | |
145 panel.setDelegate(delegate_); | |
146 rgb = null; | |
147 panel.orderFront(null); | |
45 | 148 NSApplication.sharedApplication().runModalForWindow(panel); |
53 | 149 panel.setDelegate(null); |
150 delegate_.release(); | |
151 NSColor color = panel.color(); | |
152 if (color !is null) { | |
153 color = color.colorUsingColorSpaceName(OS.NSCalibratedRGBColorSpace); | |
154 rgb = new RGB(cast(int)(color.redComponent() * 255), cast(int)(color.greenComponent() * 255), cast(int)(color.blueComponent() * 255)); | |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
155 } |
53 | 156 return rgb; |
157 } | |
158 | |
159 /** | |
160 * Sets the receiver's selected color to be the argument. | |
161 * | |
162 * @param rgb the new RGB value for the selected color, may be | |
163 * null to let the platform select a default when | |
164 * open() is called | |
165 * @see PaletteData#getRGBs | |
166 */ | |
167 public void setRGB(RGB rgb) { | |
168 this.rgb = rgb; | |
169 } | |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
7
diff
changeset
|
170 |
45 | 171 void windowWillClose(objc.id id, objc.SEL sel, objc.id sender) { |
53 | 172 NSApplication.sharedApplication().stop(null); |
173 } | |
174 } |