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