Mercurial > projects > dwt-mac
comparison dwt/widgets/Spinner.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 1a8b3cb347e0 |
children | d8635bb48c7c |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
201 dict.setObject(textView.font (), OS.NSFontAttributeName ()); | 201 dict.setObject(textView.font (), OS.NSFontAttributeName ()); |
202 int length = string.length (); | 202 int length = string.length (); |
203 char [] chars = new char [length]; | 203 char [] chars = new char [length]; |
204 string.getChars (0, length, chars, 0); | 204 string.getChars (0, length, chars, 0); |
205 NSString nsString = NSString.stringWithCharacters (chars, length); | 205 NSString nsString = NSString.stringWithCharacters (chars, length); |
206 NSAttributedString str = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString_attributes_ (nsString, dict); | 206 NSAttributedString str = (cast(NSAttributedString) new NSAttributedString ().alloc ()).initWithString_attributes_ (nsString, dict); |
207 NSSize size = str.size (); | 207 NSSize size = str.size (); |
208 str.release (); | 208 str.release (); |
209 width = size.width; | 209 width = size.width; |
210 height = size.height; | 210 height = size.height; |
211 NSRect frameRect = textView.frame(); | 211 NSRect frameRect = textView.frame(); |
220 buttonView.setFrame (oldRect); | 220 buttonView.setFrame (oldRect); |
221 width += newRect.width; | 221 width += newRect.width; |
222 height = Math.max (height, newRect.height); | 222 height = Math.max (height, newRect.height); |
223 if (wHint !is DWT.DEFAULT) width = wHint; | 223 if (wHint !is DWT.DEFAULT) width = wHint; |
224 if (hHint !is DWT.DEFAULT) height = hHint; | 224 if (hHint !is DWT.DEFAULT) height = hHint; |
225 Rectangle trim = computeTrim (0, 0, (int) width, (int) height); | 225 Rectangle trim = computeTrim (0, 0, cast(int) width, cast(int) height); |
226 return new Point (trim.width, trim.height); | 226 return new Point (trim.width, trim.height); |
227 } | 227 } |
228 | 228 |
229 /** | 229 /** |
230 * Copies the selected text. | 230 * Copies the selected text. |
238 * </ul> | 238 * </ul> |
239 */ | 239 */ |
240 public void copy () { | 240 public void copy () { |
241 checkWidget (); | 241 checkWidget (); |
242 // short [] selection = new short [2]; | 242 // short [] selection = new short [2]; |
243 // if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) !is OS.noErr) return; | 243 // if (OS.GetControlData (textHandle, cast(short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) !is OS.noErr) return; |
244 // if (selection [0] is selection [1]) return; | 244 // if (selection [0] is selection [1]) return; |
245 // int [] actualSize = new int [1]; | 245 // int [] actualSize = new int [1]; |
246 // int [] ptr = new int [1]; | 246 // int [] ptr = new int [1]; |
247 // if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize) !is OS.noErr) return; | 247 // if (OS.GetControlData (textHandle, cast(short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize) !is OS.noErr) return; |
248 // CFRange range = new CFRange (); | 248 // CFRange range = new CFRange (); |
249 // range.location = selection [0]; | 249 // range.location = selection [0]; |
250 // range.length = selection [1] - selection [0]; | 250 // range.length = selection [1] - selection [0]; |
251 // char [] buffer= new char [range.length]; | 251 // char [] buffer= new char [range.length]; |
252 // OS.CFStringGetCharacters (ptr [0], range, buffer); | 252 // OS.CFStringGetCharacters (ptr [0], range, buffer); |
253 // OS.CFRelease (ptr [0]); | 253 // OS.CFRelease (ptr [0]); |
254 // copyToClipboard (buffer); | 254 // copyToClipboard (buffer); |
255 } | 255 } |
256 | 256 |
257 void createHandle () { | 257 void createHandle () { |
258 SWTView widget = (SWTView)new SWTView().alloc(); | 258 SWTView widget = cast(SWTView)new SWTView().alloc(); |
259 widget.initWithFrame(new NSRect()); | 259 widget.initWithFrame(new NSRect()); |
260 // widget.setDrawsBackground(false); | 260 // widget.setDrawsBackground(false); |
261 widget.setTag(jniRef); | 261 widget.setTag(jniRef); |
262 NSStepper buttonWidget = (NSStepper)new SWTStepper().alloc(); | 262 NSStepper buttonWidget = cast(NSStepper)new SWTStepper().alloc(); |
263 buttonWidget.initWithFrame(new NSRect()); | 263 buttonWidget.initWithFrame(new NSRect()); |
264 buttonWidget.setValueWraps((style & DWT.WRAP) !is 0); | 264 buttonWidget.setValueWraps((style & DWT.WRAP) !is 0); |
265 buttonWidget.setTarget(buttonWidget); | 265 buttonWidget.setTarget(buttonWidget); |
266 buttonWidget.setAction(OS.sel_sendSelection); | 266 buttonWidget.setAction(OS.sel_sendSelection); |
267 buttonWidget.setTag(jniRef); | 267 buttonWidget.setTag(jniRef); |
268 NSTextField textWidget = (NSTextField)new SWTTextField().alloc(); | 268 NSTextField textWidget = cast(NSTextField)new SWTTextField().alloc(); |
269 textWidget.initWithFrame(new NSRect()); | 269 textWidget.initWithFrame(new NSRect()); |
270 // textWidget.setTarget(widget); | 270 // textWidget.setTarget(widget); |
271 textWidget.setTag(jniRef); | 271 textWidget.setTag(jniRef); |
272 textWidget.setEditable((style & DWT.READ_ONLY) is 0); | 272 textWidget.setEditable((style & DWT.READ_ONLY) is 0); |
273 widget.addSubview_(textWidget); | 273 widget.addSubview_(textWidget); |
293 */ | 293 */ |
294 public void cut () { | 294 public void cut () { |
295 checkWidget (); | 295 checkWidget (); |
296 if ((style & DWT.READ_ONLY) !is 0) return; | 296 if ((style & DWT.READ_ONLY) !is 0) return; |
297 // short [] selection = new short [2]; | 297 // short [] selection = new short [2]; |
298 // if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) !is OS.noErr) return; | 298 // if (OS.GetControlData (textHandle, cast(short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) !is OS.noErr) return; |
299 // if (selection [0] is selection [1]) return; | 299 // if (selection [0] is selection [1]) return; |
300 // char [] buffer = setText ("", selection [0], selection [1], true); | 300 // char [] buffer = setText ("", selection [0], selection [1], true); |
301 // if (buffer !is null) { | 301 // if (buffer !is null) { |
302 // copyToClipboard (buffer); | 302 // copyToClipboard (buffer); |
303 // } | 303 // } |
334 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 334 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
335 * </ul> | 335 * </ul> |
336 */ | 336 */ |
337 public int getIncrement () { | 337 public int getIncrement () { |
338 checkWidget (); | 338 checkWidget (); |
339 return (int)buttonView.increment(); | 339 return cast(int)buttonView.increment(); |
340 } | 340 } |
341 | 341 |
342 /** | 342 /** |
343 * Returns the maximum value which the receiver will allow. | 343 * Returns the maximum value which the receiver will allow. |
344 * | 344 * |
349 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 349 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
350 * </ul> | 350 * </ul> |
351 */ | 351 */ |
352 public int getMaximum () { | 352 public int getMaximum () { |
353 checkWidget (); | 353 checkWidget (); |
354 return (int)buttonView.maxValue(); | 354 return cast(int)buttonView.maxValue(); |
355 } | 355 } |
356 | 356 |
357 /** | 357 /** |
358 * Returns the minimum value which the receiver will allow. | 358 * Returns the minimum value which the receiver will allow. |
359 * | 359 * |
364 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 364 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
365 * </ul> | 365 * </ul> |
366 */ | 366 */ |
367 public int getMinimum () { | 367 public int getMinimum () { |
368 checkWidget (); | 368 checkWidget (); |
369 return (int)buttonView.minValue(); | 369 return cast(int)buttonView.minValue(); |
370 } | 370 } |
371 | 371 |
372 /** | 372 /** |
373 * Returns the amount that the receiver's position will be | 373 * Returns the amount that the receiver's position will be |
374 * modified by when the page up/down keys are pressed. | 374 * modified by when the page up/down keys are pressed. |
395 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 395 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
396 * </ul> | 396 * </ul> |
397 */ | 397 */ |
398 public int getSelection () { | 398 public int getSelection () { |
399 checkWidget (); | 399 checkWidget (); |
400 return (int)((NSStepper)buttonView).doubleValue(); | 400 return cast(int)(cast(NSStepper)buttonView).doubleValue(); |
401 } | 401 } |
402 | 402 |
403 int getSelectionText () { | 403 int getSelectionText () { |
404 return -1; | 404 return -1; |
405 } | 405 } |
419 public void paste () { | 419 public void paste () { |
420 checkWidget (); | 420 checkWidget (); |
421 if ((style & DWT.READ_ONLY) !is 0) return; | 421 if ((style & DWT.READ_ONLY) !is 0) return; |
422 // String text = getClipboardText (); | 422 // String text = getClipboardText (); |
423 // short [] selection = new short [2]; | 423 // short [] selection = new short [2]; |
424 // if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) !is OS.noErr) return; | 424 // if (OS.GetControlData (textHandle, cast(short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) !is OS.noErr) return; |
425 // setText (text, selection [0], selection [1], true); | 425 // setText (text, selection [0], selection [1], true); |
426 } | 426 } |
427 | 427 |
428 void releaseHandle () { | 428 void releaseHandle () { |
429 super.releaseHandle(); | 429 super.releaseHandle(); |
665 setSelection (value, true, true, false); | 665 setSelection (value, true, true, false); |
666 } | 666 } |
667 | 667 |
668 void setSelection (int value, bool setPos, bool setText, bool notify) { | 668 void setSelection (int value, bool setPos, bool setText, bool notify) { |
669 if (setPos) { | 669 if (setPos) { |
670 ((NSStepper)buttonView).setDoubleValue(value); | 670 (cast(NSStepper)buttonView).setDoubleValue(value); |
671 } | 671 } |
672 if (setText) { | 672 if (setText) { |
673 String string = String.valueOf (value); | 673 String string = String.valueOf (value); |
674 if (digits > 0) { | 674 if (digits > 0) { |
675 String decimalSeparator = ".";//getDecimalSeparator (); | 675 String decimalSeparator = ".";//getDecimalSeparator (); |
692 int length = cell.title().length(); | 692 int length = cell.title().length(); |
693 string = verifyText (string, 0, length, null); | 693 string = verifyText (string, 0, length, null); |
694 if (string is null) return; | 694 if (string is null) return; |
695 } | 695 } |
696 cell.setTitle(NSString.stringWith(string)); | 696 cell.setTitle(NSString.stringWith(string)); |
697 // short [] selection = new short [] {0, (short)string.length ()}; | 697 // short [] selection = new short [] {0, cast(short)string.length ()}; |
698 // OS.SetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection); | 698 // OS.SetControlData (textHandle, cast(short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection); |
699 sendEvent (DWT.Modify); | 699 sendEvent (DWT.Modify); |
700 } | 700 } |
701 if (notify) postEvent (DWT.Selection); | 701 if (notify) postEvent (DWT.Selection); |
702 } | 702 } |
703 | 703 |