Mercurial > projects > dwt-mac
annotate dwt/widgets/ColorDialog.d @ 156:969e7de37c3d default tip
Fixes to get dwt to work with dmd and ldc
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 08 Jul 2009 21:56:44 +0200 |
parents | c74ba20de292 |
children |
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; |
61
c74ba20de292
Fix: The application responds to events now
Jacob Carlborg <doob@me.com>
parents:
53
diff
changeset
|
29 import objc = dwt.internal.objc.runtime; |
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
|
30 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
|
31 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
|
32 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
|
33 |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
34 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
35 * 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
|
36 * 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
|
37 * <dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
38 * <dt><b>Styles:</b></dt> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
39 * <dd>(none)</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
40 * <dt><b>Events:</b></dt> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
41 * <dd>(none)</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
42 * </dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
43 * <p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
44 * 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
|
45 * within the DWT implementation. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
46 * </p> |
45 | 47 * |
48 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a> | |
49 * @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
|
50 */ |
3 | 51 public class ColorDialog : Dialog { |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
52 RGB rgb; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
53 |
53 | 54 /** |
55 * Constructs a new instance of this class given only its parent. | |
56 * | |
57 * @param parent a composite control which will be the parent of the new instance | |
58 * | |
59 * @exception IllegalArgumentException <ul> | |
60 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
61 * </ul> | |
62 * @exception DWTException <ul> | |
63 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
64 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
65 * </ul> | |
66 * | |
67 * @see DWT | |
68 * @see Widget#checkSubclass | |
69 * @see Widget#getStyle | |
70 */ | |
71 public this(Shell parent) { | |
72 this(parent, DWT.APPLICATION_MODAL); | |
73 } | |
74 | |
75 /** | |
76 * Constructs a new instance of this class given its parent | |
77 * and a style value describing its behavior and appearance. | |
78 * <p> | |
79 * The style value is either one of the style constants defined in | |
80 * class <code>DWT</code> which is applicable to instances of this | |
81 * class, or must be built by <em>bitwise OR</em>'ing together | |
82 * (that is, using the <code>int</code> "|" operator) two or more | |
83 * of those <code>DWT</code> style constants. The class description | |
84 * lists the style constants that are applicable to the class. | |
85 * Style bits are also inherited from superclasses. | |
86 * </p> | |
87 * | |
88 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
89 * @param style the style of control to construct | |
90 * | |
91 * @exception IllegalArgumentException <ul> | |
92 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
93 * </ul> | |
94 * @exception DWTException <ul> | |
95 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
96 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
97 * </ul> | |
98 * | |
99 * @see DWT | |
100 * @see Widget#checkSubclass | |
101 * @see Widget#getStyle | |
102 */ | |
103 public this(Shell parent, int style) { | |
45 | 104 super (parent, checkStyle (parent, style)); |
53 | 105 checkSubclass (); |
106 } | |
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
|
107 |
45 | 108 void changeColor(objc.id id, objc.SEL sel, objc.id sender) { |
53 | 109 //TODO |
110 } | |
111 | |
112 /** | |
113 * Returns the currently selected color in the receiver. | |
114 * | |
115 * @return the RGB value for the selected color, may be null | |
116 * | |
117 * @see PaletteData#getRGBs | |
118 */ | |
119 public RGB getRGB() { | |
120 return rgb; | |
121 } | |
122 | |
123 /** | |
124 * Makes the receiver visible and brings it to the front | |
125 * of the display. | |
126 * | |
127 * @return the selected color, or null if the dialog was | |
128 * cancelled, no color was selected, or an error | |
129 * occurred | |
130 * | |
131 * @exception DWTException <ul> | |
132 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
133 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
134 * </ul> | |
135 */ | |
136 public RGB open() { | |
137 NSColorPanel panel = NSColorPanel.sharedColorPanel(); | |
138 if (rgb !is null) { | |
139 NSColor color = NSColor.colorWithDeviceRed(rgb.red / 255f, rgb.green / 255f, rgb.blue / 255f, 1); | |
140 panel.setColor(color); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
141 } |
53 | 142 SWTPanelDelegate delegate_ = cast(SWTPanelDelegate)(new SWTPanelDelegate()).alloc().init(); |
143 void* jniRef = OS.NewGlobalRef(this); | |
144 if (jniRef is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
145 OS.object_setInstanceVariable(delegate_.id, Display.SWT_OBJECT, jniRef); | |
146 panel.setDelegate(delegate_); | |
147 rgb = null; | |
148 panel.orderFront(null); | |
45 | 149 NSApplication.sharedApplication().runModalForWindow(panel); |
53 | 150 panel.setDelegate(null); |
151 delegate_.release(); | |
152 NSColor color = panel.color(); | |
153 if (color !is null) { | |
154 color = color.colorUsingColorSpaceName(OS.NSCalibratedRGBColorSpace); | |
155 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
|
156 } |
53 | 157 return rgb; |
158 } | |
159 | |
160 /** | |
161 * Sets the receiver's selected color to be the argument. | |
162 * | |
163 * @param rgb the new RGB value for the selected color, may be | |
164 * null to let the platform select a default when | |
165 * open() is called | |
166 * @see PaletteData#getRGBs | |
167 */ | |
168 public void setRGB(RGB rgb) { | |
169 this.rgb = rgb; | |
170 } | |
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
|
171 |
45 | 172 void windowWillClose(objc.id id, objc.SEL sel, objc.id sender) { |
53 | 173 NSApplication.sharedApplication().stop(null); |
174 } | |
175 } |