comparison dwt/widgets/Scale.d @ 75:1926e6c4bf87

Ported dwt.widgets.Scale
author Jacob Carlborg <doob@me.com>
date Wed, 24 Dec 2008 12:17:03 +0100
parents cfa563df4fdd
children 63a09873578e
comparison
equal deleted inserted replaced
74:8e8040261b20 75:1926e6c4bf87
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 <doob@me.com>
10 *******************************************************************************/ 13 *******************************************************************************/
11 module dwt.widgets.Scale; 14 module dwt.widgets.Scale;
12 15
13 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
14 17
20 import dwt.internal.cocoa.NSControl; 23 import dwt.internal.cocoa.NSControl;
21 import dwt.internal.cocoa.NSRect; 24 import dwt.internal.cocoa.NSRect;
22 import dwt.internal.cocoa.NSSize; 25 import dwt.internal.cocoa.NSSize;
23 import dwt.internal.cocoa.NSSlider; 26 import dwt.internal.cocoa.NSSlider;
24 import dwt.internal.cocoa.SWTSlider; 27 import dwt.internal.cocoa.SWTSlider;
28
29 import dwt.widgets.Composite;
30 import dwt.widgets.Control;
31 import dwt.widgets.TypedListener;
25 32
26 /** 33 /**
27 * Instances of the receiver represent a selectable user 34 * Instances of the receiver represent a selectable user
28 * interface object that present a range of continuous 35 * interface object that present a range of continuous
29 * numeric values. 36 * numeric values.
133 if (hHint !is DWT.DEFAULT) height = hHint; 140 if (hHint !is DWT.DEFAULT) height = hHint;
134 return new Point (width, height); 141 return new Point (width, height);
135 } 142 }
136 143
137 void createHandle () { 144 void createHandle () {
138 NSSlider widget = cast(NSSlider)new SWTSlider().alloc(); 145 NSSlider widget = cast(NSSlider)(new SWTSlider()).alloc();
139 NSRect rect = NSRect(); 146 NSRect rect = NSRect();
140 rect.width = 1; 147 rect.width = 1;
141 rect.height = 1; 148 rect.height = 1;
142 widget.initWithFrame(rect); 149 widget.initWithFrame(rect);
143 widget.setMaxValue(100); 150 widget.setMaxValue(100);
144 view = widget; 151 view = widget;
145 } 152 }
146 153
147 void deregister() { 154 void deregister() {
148 super.deregister(); 155 super.deregister();
149 display.removeWidget(((NSControl)view).cell()); 156 display.removeWidget((cast(NSControl)view).cell());
150 } 157 }
151 158
152 159
153 /** 160 /**
154 * Returns the amount that the receiver's value will be 161 * Returns the amount that the receiver's value will be
235 return cast(int)(cast(NSSlider)view).doubleValue(); 242 return cast(int)(cast(NSSlider)view).doubleValue();
236 } 243 }
237 244
238 void register() { 245 void register() {
239 super.register(); 246 super.register();
240 display.addWidget(((NSControl)view).cell(), this); 247 display.addWidget((cast(NSControl)view).cell(), this);
241 } 248 }
242 249
243 /** 250 /**
244 * Removes the listener from the collection of listeners who will 251 * Removes the listener from the collection of listeners who will
245 * be notified when the user changes the receiver's value. 252 * be notified when the user changes the receiver's value.
297 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 304 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
298 * </ul> 305 * </ul>
299 */ 306 */
300 public void setMaximum (int value) { 307 public void setMaximum (int value) {
301 checkWidget(); 308 checkWidget();
302 int minimum = (int)((NSSlider)view).minValue(); 309 int minimum = cast(int)(cast(NSSlider)view).minValue();
303 if (value <= minimum) return; 310 if (value <= minimum) return;
304 } 311 }
305 312
306 /** 313 /**
307 * Sets the minimum value that the receiver will allow. This new 314 * Sets the minimum value that the receiver will allow. This new
316 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 323 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
317 * </ul> 324 * </ul>
318 */ 325 */
319 public void setMinimum (int value) { 326 public void setMinimum (int value) {
320 checkWidget(); 327 checkWidget();
321 int maximum = (int)((NSSlider)view).maxValue(); 328 int maximum = cast(int)(cast(NSSlider)view).maxValue();
322 if (!(0 <= value && value < maximum)) return; 329 if (!(0 <= value && value < maximum)) return;
323 } 330 }
324 331
325 /** 332 /**
326 * Sets the amount that the receiver's value will be 333 * Sets the amount that the receiver's value will be