Mercurial > projects > dwt-mac
comparison dwt/widgets/Scale.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | e831403a80a9 |
children | cfa563df4fdd |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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 * |
15 | 15 |
16 import dwt.DWT; | 16 import dwt.DWT; |
17 import dwt.DWTException; | 17 import dwt.DWTException; |
18 import dwt.events.SelectionListener; | 18 import dwt.events.SelectionListener; |
19 import dwt.graphics.Point; | 19 import dwt.graphics.Point; |
20 import dwt.internal.cocoa.NSControl; | |
20 import dwt.internal.cocoa.NSRect; | 21 import dwt.internal.cocoa.NSRect; |
22 import dwt.internal.cocoa.NSSize; | |
21 import dwt.internal.cocoa.NSSlider; | 23 import dwt.internal.cocoa.NSSlider; |
22 import dwt.internal.cocoa.SWTSlider; | 24 import dwt.internal.cocoa.SWTSlider; |
23 | 25 |
24 /** | 26 /** |
25 * Instances of the receiver represent a selectable user | 27 * Instances of the receiver represent a selectable user |
36 * </p><p> | 38 * </p><p> |
37 * <p> | 39 * <p> |
38 * IMPORTANT: This class is intended to be subclassed <em>only</em> | 40 * IMPORTANT: This class is intended to be subclassed <em>only</em> |
39 * within the DWT implementation. | 41 * within the DWT implementation. |
40 * </p> | 42 * </p> |
43 * | |
44 * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a> | |
45 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | |
46 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
41 */ | 47 */ |
42 public class Scale : Control { | 48 public class Scale : Control { |
43 int increment = 1; | 49 int increment = 1; |
44 int pageIncrement = 10; | 50 int pageIncrement = 10; |
45 | 51 |
112 } | 118 } |
113 | 119 |
114 public Point computeSize (int wHint, int hHint, bool changed) { | 120 public Point computeSize (int wHint, int hHint, bool changed) { |
115 checkWidget(); | 121 checkWidget(); |
116 NSSlider widget = cast(NSSlider)view; | 122 NSSlider widget = cast(NSSlider)view; |
117 NSRect oldRect = widget.frame(); | 123 NSSize size = widget.cell().cellSizeForBounds(widget.bounds()); |
118 widget.sizeToFit(); | 124 int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT; |
119 NSRect newRect = widget.frame(); | 125 if ((style & DWT.HORIZONTAL) !is 0) { |
120 widget.setFrame (oldRect); | 126 height = cast(int)Math.ceil(size.height); |
121 int width = 0, height = 0; | |
122 if ((style & DWT.HORIZONTAL) !is 0) { | |
123 height = cast(int)newRect.width; | |
124 width = height * 10; | 127 width = height * 10; |
125 } else { | 128 } else { |
126 width = cast(int)newRect.width; | 129 width = cast(int)Math.ceil(size.width); |
127 height = width * 10; | 130 height = width * 10; |
128 } | 131 } |
129 if (wHint !is DWT.DEFAULT) width = wHint; | 132 if (wHint !is DWT.DEFAULT) width = wHint; |
130 if (hHint !is DWT.DEFAULT) height = hHint; | 133 if (hHint !is DWT.DEFAULT) height = hHint; |
131 return new Point (width, height); | 134 return new Point (width, height); |
132 } | 135 } |
133 | 136 |
134 void createHandle () { | 137 void createHandle () { |
135 NSSlider widget = cast(NSSlider)new SWTSlider().alloc(); | 138 NSSlider widget = cast(NSSlider)new SWTSlider().alloc(); |
136 NSRect rect = new NSRect(); | 139 NSRect rect = new NSRect(); |
137 if ((style & DWT.HORIZONTAL) !is 0) { | |
138 rect.width = 1; | 140 rect.width = 1; |
139 } else { | |
140 rect.height = 1; | 141 rect.height = 1; |
141 } | |
142 widget.initWithFrame(rect); | 142 widget.initWithFrame(rect); |
143 widget.setMaxValue(100); | 143 widget.setMaxValue(100); |
144 widget.setTag(jniRef); | |
145 view = widget; | 144 view = widget; |
146 parent.contentView().addSubview_(widget); | 145 } |
147 } | 146 |
147 void deregister() { | |
148 super.deregister(); | |
149 display.removeWidget(((NSControl)view).cell()); | |
150 } | |
151 | |
148 | 152 |
149 /** | 153 /** |
150 * Returns the amount that the receiver's value will be | 154 * Returns the amount that the receiver's value will be |
151 * modified by when the up/down (or right/left) arrows | 155 * modified by when the up/down (or right/left) arrows |
152 * are pressed. | 156 * are pressed. |
229 // value = maximum - value + minimum; | 233 // value = maximum - value + minimum; |
230 // } | 234 // } |
231 return cast(int)(cast(NSSlider)view).doubleValue(); | 235 return cast(int)(cast(NSSlider)view).doubleValue(); |
232 } | 236 } |
233 | 237 |
238 void register() { | |
239 super.register(); | |
240 display.addWidget(((NSControl)view).cell(), this); | |
241 } | |
242 | |
234 /** | 243 /** |
235 * Removes the listener from the collection of listeners who will | 244 * Removes the listener from the collection of listeners who will |
236 * be notified when the user changes the receiver's value. | 245 * be notified when the user changes the receiver's value. |
237 * | 246 * |
238 * @param listener the listener which should no longer be notified | 247 * @param listener the listener which should no longer be notified |
288 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 297 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
289 * </ul> | 298 * </ul> |
290 */ | 299 */ |
291 public void setMaximum (int value) { | 300 public void setMaximum (int value) { |
292 checkWidget(); | 301 checkWidget(); |
293 if (value < 0) return; | 302 int minimum = (int)((NSSlider)view).minValue(); |
294 (cast(NSSlider)view).setMaxValue(value); | 303 if (value <= minimum) return; |
295 } | 304 } |
296 | 305 |
297 /** | 306 /** |
298 * Sets the minimum value that the receiver will allow. This new | 307 * Sets the minimum value that the receiver will allow. This new |
299 * value will be ignored if it is negative or is not less than the receiver's | 308 * value will be ignored if it is negative or is not less than the receiver's |
307 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 316 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
308 * </ul> | 317 * </ul> |
309 */ | 318 */ |
310 public void setMinimum (int value) { | 319 public void setMinimum (int value) { |
311 checkWidget(); | 320 checkWidget(); |
312 if (value < 0) return; | 321 int maximum = (int)((NSSlider)view).maxValue(); |
313 (cast(NSSlider)view).setMinValue(value); | 322 if (!(0 <= value && value < maximum)) return; |
314 } | 323 } |
315 | 324 |
316 /** | 325 /** |
317 * Sets the amount that the receiver's value will be | 326 * Sets the amount that the receiver's value will be |
318 * modified by when the page increment/decrement areas | 327 * modified by when the page increment/decrement areas |