Mercurial > projects > dwt-mac
comparison dwt/widgets/ProgressBar.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 * |
34 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. | 34 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. |
35 * </p><p> | 35 * </p><p> |
36 * IMPORTANT: This class is intended to be subclassed <em>only</em> | 36 * IMPORTANT: This class is intended to be subclassed <em>only</em> |
37 * within the DWT implementation. | 37 * within the DWT implementation. |
38 * </p> | 38 * </p> |
39 * | |
40 * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a> | |
41 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | |
42 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
39 */ | 43 */ |
40 public class ProgressBar : Control { | 44 public class ProgressBar : Control { |
41 | 45 |
42 /** | 46 /** |
43 * Constructs a new instance of this class given its parent | 47 * Constructs a new instance of this class given its parent |
98 if (hHint !is DWT.DEFAULT) height = hHint; | 102 if (hHint !is DWT.DEFAULT) height = hHint; |
99 return new Point (width, height); | 103 return new Point (width, height); |
100 } | 104 } |
101 | 105 |
102 void createHandle () { | 106 void createHandle () { |
103 SWTProgressIndicator widget = cast(SWTProgressIndicator)new SWTProgressIndicator().alloc(); | 107 NSProgressIndicator widget = cast(NSProgressIndicator)new SWTProgressIndicator().alloc(); |
104 widget.initWithFrame(new NSRect()); | 108 widget.initWithFrame(new NSRect()); |
105 widget.setUsesThreadedAnimation(false); | 109 widget.setUsesThreadedAnimation(false); |
106 widget.setIndeterminate((style & DWT.INDETERMINATE) !is 0); | 110 widget.setIndeterminate((style & DWT.INDETERMINATE) !is 0); |
107 if ((style & DWT.INDETERMINATE) !is 0) widget.startAnimation(null); | 111 if ((style & DWT.INDETERMINATE) !is 0) widget.startAnimation(null); |
108 widget.setTag(jniRef); | |
109 view = widget; | 112 view = widget; |
110 parent.contentView().addSubview_(widget); | |
111 } | 113 } |
112 | 114 |
113 /** | 115 /** |
114 * Returns the maximum value which the receiver will allow. | 116 * Returns the maximum value which the receiver will allow. |
115 * | 117 * |
153 public int getSelection () { | 155 public int getSelection () { |
154 checkWidget(); | 156 checkWidget(); |
155 return cast(int)(cast(NSProgressIndicator)view).doubleValue(); | 157 return cast(int)(cast(NSProgressIndicator)view).doubleValue(); |
156 } | 158 } |
157 | 159 |
160 /** | |
161 * Returns the state of the receiver. The value will be one of: | |
162 * <ul> | |
163 * <li>{@link DWT#NORMAL}</li> | |
164 * <li>{@link DWT#ERROR}</li> | |
165 * <li>{@link DWT#PAUSED}</li> | |
166 * </ul> | |
167 * | |
168 * @return the state | |
169 * | |
170 * @exception DWTException <ul> | |
171 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
172 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
173 * </ul> | |
174 * | |
175 * @since 3.4 | |
176 */ | |
158 public int getState () { | 177 public int getState () { |
159 checkWidget (); | 178 checkWidget (); |
160 return DWT.NORMAL; | 179 return DWT.NORMAL; |
161 } | 180 } |
162 | 181 |
173 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 192 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
174 * </ul> | 193 * </ul> |
175 */ | 194 */ |
176 public void setMaximum (int value) { | 195 public void setMaximum (int value) { |
177 checkWidget(); | 196 checkWidget(); |
178 if (value < 0) return; | 197 int minimum = (int)((NSProgressIndicator)view).minValue(); |
179 (cast(NSProgressIndicator)view).setMaxValue(value); | 198 if (value <= minimum) return; |
199 int selection = (int)((NSProgressIndicator)view).doubleValue(); | |
200 int newSelection = Math.min (selection, value); | |
201 if (selection !is newSelection) { | |
202 ((NSProgressIndicator)view).setDoubleValue(newSelection); | |
203 } | |
180 } | 204 } |
181 | 205 |
182 /** | 206 /** |
183 * Sets the minimum value that the receiver will allow. This new | 207 * Sets the minimum value that the receiver will allow. This new |
184 * value will be ignored if it is negative or is not less than the receiver's | 208 * value will be ignored if it is negative or is not less than the receiver's |
192 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 216 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
193 * </ul> | 217 * </ul> |
194 */ | 218 */ |
195 public void setMinimum (int value) { | 219 public void setMinimum (int value) { |
196 checkWidget(); | 220 checkWidget(); |
197 if (value < 0) return; | 221 int maximum = (int)((NSProgressIndicator)view).maxValue(); |
198 (cast(NSProgressIndicator)view).setMinValue(value); | 222 if (!(0 <= value && value < maximum)) return; |
223 int selection = (int)((NSProgressIndicator)view).doubleValue(); | |
224 int newSelection = Math.max (selection, value); | |
225 if (selection !is newSelection) { | |
226 ((NSProgressIndicator)view).setDoubleValue(newSelection); | |
227 } | |
199 } | 228 } |
200 | 229 |
201 /** | 230 /** |
202 * Sets the single 'selection' that is the receiver's | 231 * Sets the single 'selection' that is the receiver's |
203 * position to the argument which must be greater than or equal | 232 * position to the argument which must be greater than or equal |
213 public void setSelection (int value) { | 242 public void setSelection (int value) { |
214 checkWidget(); | 243 checkWidget(); |
215 (cast(NSProgressIndicator)view).setDoubleValue(value); | 244 (cast(NSProgressIndicator)view).setDoubleValue(value); |
216 } | 245 } |
217 | 246 |
247 /** | |
248 * Sets the state of the receiver. The state must be one of these values: | |
249 * <ul> | |
250 * <li>{@link DWT#NORMAL}</li> | |
251 * <li>{@link DWT#ERROR}</li> | |
252 * <li>{@link DWT#PAUSED}</li> | |
253 * </ul> | |
254 * | |
255 * @param state the new state | |
256 * | |
257 * @exception DWTException <ul> | |
258 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
259 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
260 * </ul> | |
261 * | |
262 * @since 3.4 | |
263 */ | |
218 public void setState (int state) { | 264 public void setState (int state) { |
219 checkWidget (); | 265 checkWidget (); |
220 //NOT IMPLEMENTED | 266 //NOT IMPLEMENTED |
221 } | 267 } |
222 } | 268 } |