comparison dwt/widgets/ColorDialog.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents 642f460a0908
children 6914d8d302de
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
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 * 10 *
11 * Port to the D programming language: 11 * Port to the D programming language:
12 * Jacob Carlborg <jacob.carlborg@gmail.com> 12 * Jacob Carlborg <doob@me.com>
13 *******************************************************************************/ 13 *******************************************************************************/
14 module dwt.widgets.ColorDialog; 14 module dwt.widgets.ColorDialog;
15 15
16 16
17 import dwt.DWT; 17 import dwt.DWT;
19 import dwt.graphics.PaletteData; 19 import dwt.graphics.PaletteData;
20 import dwt.graphics.RGB; 20 import dwt.graphics.RGB;
21 import dwt.internal.cocoa.NSApplication; 21 import dwt.internal.cocoa.NSApplication;
22 import dwt.internal.cocoa.NSColor; 22 import dwt.internal.cocoa.NSColor;
23 import dwt.internal.cocoa.NSColorPanel; 23 import dwt.internal.cocoa.NSColorPanel;
24 import dwt.internal.cocoa.NSString;
25 import dwt.internal.cocoa.OS; 24 import dwt.internal.cocoa.OS;
26 import dwt.internal.cocoa.SWTPanelDelegate; 25 import dwt.internal.cocoa.SWTPanelDelegate;
27 26
28 import dwt.dwthelper.utils; 27 import dwt.dwthelper.utils;
29 import dwt.internal.cocoa.NSInteger; 28 import dwt.internal.cocoa.NSInteger;
42 * </dl> 41 * </dl>
43 * <p> 42 * <p>
44 * IMPORTANT: This class is intended to be subclassed <em>only</em> 43 * IMPORTANT: This class is intended to be subclassed <em>only</em>
45 * within the DWT implementation. 44 * within the DWT implementation.
46 * </p> 45 * </p>
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>
47 */ 49 */
48 public class ColorDialog : Dialog { 50 public class ColorDialog : Dialog {
49 RGB rgb; 51 RGB rgb;
50 52
51 /** 53 /**
96 * @see DWT 98 * @see DWT
97 * @see Widget#checkSubclass 99 * @see Widget#checkSubclass
98 * @see Widget#getStyle 100 * @see Widget#getStyle
99 */ 101 */
100 public this(Shell parent, int style) { 102 public this(Shell parent, int style) {
101 super(parent, style); 103 super (parent, checkStyle (parent, style));
102 checkSubclass (); 104 checkSubclass ();
103 } 105 }
104 106
105 void changeColor(int sender) { 107 void changeColor(objc.id id, objc.SEL sel, objc.id sender) {
106 //TODO 108 //TODO
107 } 109 }
108 110
109 /** 111 /**
110 * Returns the currently selected color in the receiver. 112 * Returns the currently selected color in the receiver.
137 panel.setColor(color); 139 panel.setColor(color);
138 } 140 }
139 SWTPanelDelegate delegate_ = cast(SWTPanelDelegate)(new SWTPanelDelegate()).alloc().init(); 141 SWTPanelDelegate delegate_ = cast(SWTPanelDelegate)(new SWTPanelDelegate()).alloc().init();
140 NSInteger jniRef = OS.NewGlobalRef(this); 142 NSInteger jniRef = OS.NewGlobalRef(this);
141 if (jniRef is 0) DWT.error(DWT.ERROR_NO_HANDLES); 143 if (jniRef is 0) DWT.error(DWT.ERROR_NO_HANDLES);
142 delegate_.setTag(jniRef); 144 OS.object_setInstanceVariable(delegate_.id_, Display.DWT_OBJECT, jniRef);
143 panel.setDelegate(delegate_); 145 panel.setDelegate(delegate_);
144 rgb = null; 146 rgb = null;
145 panel.orderFront(null); 147 panel.orderFront(null);
146 NSApplication.sharedApplication().runModalForWindow_(panel); 148 NSApplication.sharedApplication().runModalForWindow(panel);
147 panel.setDelegate(null); 149 panel.setDelegate(null);
148 delegate_.release(); 150 delegate_.release();
149 OS.DeleteGlobalRef(jniRef); 151 OS.DeleteGlobalRef(jniRef);
150 NSColor color = panel.color(); 152 NSColor color = panel.color();
151 if (color !is null) { 153 if (color !is null) {
152 color = color.colorUsingColorSpaceName_(NSString.stringWith("NSCalibratedRGBColorSpace")); 154 color = color.colorUsingColorSpaceName(OS.NSCalibratedRGBColorSpace);
153 rgb = new RGB(cast(int)(color.redComponent() * 255), cast(int)(color.greenComponent() * 255), cast(int)(color.blueComponent() * 255)); 155 rgb = new RGB(cast(int)(color.redComponent() * 255), cast(int)(color.greenComponent() * 255), cast(int)(color.blueComponent() * 255));
154 } 156 }
155 return rgb; 157 return rgb;
156 } 158 }
157 159
165 */ 167 */
166 public void setRGB(RGB rgb) { 168 public void setRGB(RGB rgb) {
167 this.rgb = rgb; 169 this.rgb = rgb;
168 } 170 }
169 171
170 void windowWillClose(int sender) { 172 void windowWillClose(objc.id id, objc.SEL sel, objc.id sender) {
171 NSApplication.sharedApplication().stop(null); 173 NSApplication.sharedApplication().stop(null);
172 } 174 }
173 } 175 }