Mercurial > projects > dwt-mac
comparison dwt/widgets/Spinner.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 * |
20 import dwt.events.VerifyListener; | 20 import dwt.events.VerifyListener; |
21 import dwt.graphics.Point; | 21 import dwt.graphics.Point; |
22 import dwt.graphics.Rectangle; | 22 import dwt.graphics.Rectangle; |
23 import dwt.internal.cocoa.NSAttributedString; | 23 import dwt.internal.cocoa.NSAttributedString; |
24 import dwt.internal.cocoa.NSCell; | 24 import dwt.internal.cocoa.NSCell; |
25 import dwt.internal.cocoa.NSCharacterSet; | |
26 import dwt.internal.cocoa.NSEvent; | |
27 import dwt.internal.cocoa.NSFont; | |
25 import dwt.internal.cocoa.NSMutableDictionary; | 28 import dwt.internal.cocoa.NSMutableDictionary; |
29 import dwt.internal.cocoa.NSNumber; | |
30 import dwt.internal.cocoa.NSNumberFormatter; | |
26 import dwt.internal.cocoa.NSRect; | 31 import dwt.internal.cocoa.NSRect; |
27 import dwt.internal.cocoa.NSSize; | 32 import dwt.internal.cocoa.NSSize; |
28 import dwt.internal.cocoa.NSStepper; | 33 import dwt.internal.cocoa.NSStepper; |
29 import dwt.internal.cocoa.NSString; | 34 import dwt.internal.cocoa.NSString; |
30 import dwt.internal.cocoa.NSTextField; | 35 import dwt.internal.cocoa.NSTextField; |
36 import dwt.internal.cocoa.NSView; | |
31 import dwt.internal.cocoa.OS; | 37 import dwt.internal.cocoa.OS; |
32 import dwt.internal.cocoa.SWTStepper; | 38 import dwt.internal.cocoa.SWTStepper; |
33 import dwt.internal.cocoa.SWTTextField; | 39 import dwt.internal.cocoa.SWTTextField; |
34 import dwt.internal.cocoa.SWTView; | 40 import dwt.internal.cocoa.SWTView; |
35 | 41 |
48 * <dd>Selection, Modify, Verify</dd> | 54 * <dd>Selection, Modify, Verify</dd> |
49 * </dl> | 55 * </dl> |
50 * </p><p> | 56 * </p><p> |
51 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | 57 * IMPORTANT: This class is <em>not</em> intended to be subclassed. |
52 * </p> | 58 * </p> |
59 * | |
60 * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a> | |
61 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | |
62 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
53 * | 63 * |
54 * @since 3.1 | 64 * @since 3.1 |
55 */ | 65 */ |
56 public class Spinner : Composite { | 66 public class Spinner : Composite { |
57 NSTextField textView; | 67 NSTextField textView; |
68 NSNumberFormatter textFormatter; | |
58 NSStepper buttonView; | 69 NSStepper buttonView; |
59 int pageIncrement = 10; | 70 int pageIncrement = 10; |
60 int digits = 0; | 71 int digits = 0; |
61 | 72 |
62 static int GAP = 0; | 73 static int GAP = 0; |
92 */ | 103 */ |
93 public this (Composite parent, int style) { | 104 public this (Composite parent, int style) { |
94 super (parent, checkStyle (style)); | 105 super (parent, checkStyle (style)); |
95 } | 106 } |
96 | 107 |
108 bool acceptsFirstResponder(int /*long*/ id, int /*long*/ sel) { | |
109 if (id is view.id) return false; | |
110 return super.acceptsFirstResponder (id, sel); | |
111 } | |
112 | |
97 /** | 113 /** |
98 * Adds the listener to the collection of listeners who will | 114 * Adds the listener to the collection of listeners who will |
99 * be notified when the receiver's text is modified, by sending | 115 * be notified when the receiver's text is modified, by sending |
100 * it one of the messages defined in the <code>ModifyListener</code> | 116 * it one of the messages defined in the <code>ModifyListener</code> |
101 * interface. | 117 * interface. |
196 public Point computeSize (int wHint, int hHint, bool changed) { | 212 public Point computeSize (int wHint, int hHint, bool changed) { |
197 checkWidget (); | 213 checkWidget (); |
198 float width = 0, height = 0; | 214 float width = 0, height = 0; |
199 String string = Double.toString (buttonView.maxValue ()); | 215 String string = Double.toString (buttonView.maxValue ()); |
200 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (1); | 216 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (1); |
201 dict.setObject(textView.font (), OS.NSFontAttributeName ()); | 217 dict.setObject(textView.font (), OS.NSFontAttributeName); |
202 int length = string.length (); | 218 int length = string.length (); |
203 char [] chars = new char [length]; | 219 char [] chars = new char [length]; |
204 string.getChars (0, length, chars, 0); | 220 string.getChars (0, length, chars, 0); |
205 NSString nsString = NSString.stringWithCharacters (chars, length); | 221 NSString nsString = NSString.stringWithCharacters (chars, length); |
206 NSAttributedString str = (cast(NSAttributedString) new NSAttributedString ().alloc ()).initWithString_attributes_ (nsString, dict); | 222 NSAttributedString str = (cast(NSAttributedString) new NSAttributedString ().alloc ()).initWithString (nsString, dict); |
207 NSSize size = str.size (); | 223 NSSize size = str.size (); |
208 str.release (); | 224 str.release (); |
209 width = size.width; | 225 width = (int)/*64*/size.width; |
210 height = size.height; | 226 height = (int)/*64*/size.height; |
211 NSRect frameRect = textView.frame(); | 227 NSRect frameRect = textView.frame(); |
212 NSCell cell = new NSCell (textView.cell ()); | 228 NSCell cell = new NSCell (textView.cell ()); |
213 NSRect cellRect = cell.drawingRectForBounds(frameRect); | 229 NSRect cellRect = cell.drawingRectForBounds(frameRect); |
214 width += frameRect.width - cellRect.width; | 230 width += frameRect.width - cellRect.width; |
215 height += frameRect.height - cellRect.height; | 231 height += frameRect.height - cellRect.height; |
217 NSRect oldRect = buttonView.frame (); | 233 NSRect oldRect = buttonView.frame (); |
218 buttonView.sizeToFit(); | 234 buttonView.sizeToFit(); |
219 NSRect newRect = buttonView.frame (); | 235 NSRect newRect = buttonView.frame (); |
220 buttonView.setFrame (oldRect); | 236 buttonView.setFrame (oldRect); |
221 width += newRect.width; | 237 width += newRect.width; |
222 height = Math.max (height, newRect.height); | 238 height = Math.max (height, (int)/*64*/newRect.height); |
223 if (wHint !is DWT.DEFAULT) width = wHint; | 239 if (wHint !is DWT.DEFAULT) width = wHint; |
224 if (hHint !is DWT.DEFAULT) height = hHint; | 240 if (hHint !is DWT.DEFAULT) height = hHint; |
225 Rectangle trim = computeTrim (0, 0, cast(int) width, cast(int) height); | 241 Rectangle trim = computeTrim (0, 0, cast(int) width, cast(int) height); |
226 return new Point (trim.width, trim.height); | 242 return new Point (trim.width, trim.height); |
227 } | 243 } |
253 // OS.CFRelease (ptr [0]); | 269 // OS.CFRelease (ptr [0]); |
254 // copyToClipboard (buffer); | 270 // copyToClipboard (buffer); |
255 } | 271 } |
256 | 272 |
257 void createHandle () { | 273 void createHandle () { |
258 SWTView widget = cast(SWTView)new SWTView().alloc(); | 274 NSView widget = cast(NSView)new SWTView().alloc(); |
259 widget.initWithFrame(new NSRect()); | 275 widget.initWithFrame(new NSRect()); |
260 // widget.setDrawsBackground(false); | 276 // widget.setDrawsBackground(false); |
261 widget.setTag(jniRef); | |
262 NSStepper buttonWidget = cast(NSStepper)new SWTStepper().alloc(); | 277 NSStepper buttonWidget = cast(NSStepper)new SWTStepper().alloc(); |
263 buttonWidget.initWithFrame(new NSRect()); | 278 buttonWidget.initWithFrame(new NSRect()); |
264 buttonWidget.setValueWraps((style & DWT.WRAP) !is 0); | 279 buttonWidget.setValueWraps((style & DWT.WRAP) !is 0); |
265 buttonWidget.setTarget(buttonWidget); | 280 buttonWidget.setTarget(buttonWidget); |
266 buttonWidget.setAction(OS.sel_sendSelection); | 281 buttonWidget.setAction(OS.sel_sendSelection); |
267 buttonWidget.setTag(jniRef); | |
268 NSTextField textWidget = cast(NSTextField)new SWTTextField().alloc(); | 282 NSTextField textWidget = cast(NSTextField)new SWTTextField().alloc(); |
269 textWidget.initWithFrame(new NSRect()); | 283 textWidget.initWithFrame(new NSRect()); |
270 // textWidget.setTarget(widget); | 284 // textWidget.setTarget(widget); |
271 textWidget.setTag(jniRef); | |
272 textWidget.setEditable((style & DWT.READ_ONLY) is 0); | 285 textWidget.setEditable((style & DWT.READ_ONLY) is 0); |
273 widget.addSubview_(textWidget); | 286 textFormatter = new NSNumberFormatter(); |
274 widget.addSubview_(buttonWidget); | 287 textFormatter.alloc().init(); //.autorelease(); |
288 textFormatter.setNumberStyle(OS.NSNumberFormatterDecimalStyle); | |
289 //textWidget.cell().setFormatter(textFormatter); | |
290 widget.addSubview(textWidget); | |
291 widget.addSubview(buttonWidget); | |
275 buttonView = buttonWidget; | 292 buttonView = buttonWidget; |
276 textView = textWidget; | 293 textView = textWidget; |
277 view = widget; | 294 view = widget; |
278 parent.contentView().addSubview_(widget); | |
279 setSelection (0, false, true, false); | 295 setSelection (0, false, true, false); |
280 } | 296 } |
281 | 297 |
282 /** | 298 /** |
283 * Cuts the selected text. | 299 * Cuts the selected text. |
301 // if (buffer !is null) { | 317 // if (buffer !is null) { |
302 // copyToClipboard (buffer); | 318 // copyToClipboard (buffer); |
303 // } | 319 // } |
304 } | 320 } |
305 | 321 |
322 void deregister () { | |
323 super.deregister (); | |
324 if (textView !is null) { | |
325 display.removeWidget (textView); | |
326 display.removeWidget (textView.cell()); | |
327 } | |
328 | |
329 if (buttonView !is null) { | |
330 display.removeWidget (buttonView); | |
331 display.removeWidget (buttonView.cell()); | |
332 } | |
333 } | |
334 | |
306 void enableWidget (bool enabled) { | 335 void enableWidget (bool enabled) { |
307 buttonView.setEnabled(enabled); | 336 buttonView.setEnabled(enabled); |
308 textView.setEnabled(enabled); | 337 textView.setEnabled(enabled); |
309 } | 338 } |
310 | 339 |
340 NSView focusView () { | |
341 return textView; | |
342 } | |
343 | |
311 /** | 344 /** |
312 * Returns the number of decimal places used by the receiver. | 345 * Returns the number of decimal places used by the receiver. |
313 * | 346 * |
314 * @return the digits | 347 * @return the digits |
315 * | 348 * |
398 public int getSelection () { | 431 public int getSelection () { |
399 checkWidget (); | 432 checkWidget (); |
400 return cast(int)(cast(NSStepper)buttonView).doubleValue(); | 433 return cast(int)(cast(NSStepper)buttonView).doubleValue(); |
401 } | 434 } |
402 | 435 |
403 int getSelectionText () { | 436 int getSelectionText (bool[] parseFail) { |
437 String string = textView.stringValue().getString(); | |
438 try { | |
439 int value; | |
440 if (digits > 0) { | |
441 String decimalSeparator = textFormatter.decimalSeparator().getString(); | |
442 int index = string.indexOf (decimalSeparator); | |
443 if (index !is -1) { | |
444 int startIndex = string.startsWith ("+") || string.startsWith ("-") ? 1 : 0; | |
445 String wholePart = startIndex !is index ? string.substring (startIndex, index) : "0"; | |
446 String decimalPart = string.substring (index + 1); | |
447 if (decimalPart.length () > digits) { | |
448 decimalPart = decimalPart.substring (0, digits); | |
449 } else { | |
450 int i = digits - decimalPart.length (); | |
451 for (int j = 0; j < i; j++) { | |
452 decimalPart = decimalPart + "0"; | |
453 } | |
454 } | |
455 int wholeValue = Integer.parseInt (wholePart); | |
456 int decimalValue = Integer.parseInt (decimalPart); | |
457 for (int i = 0; i < digits; i++) wholeValue *= 10; | |
458 value = wholeValue + decimalValue; | |
459 if (string.startsWith ("-")) value = -value; | |
460 } else { | |
461 value = Integer.parseInt (string); | |
462 for (int i = 0; i < digits; i++) value *= 10; | |
463 } | |
464 } else { | |
465 value = Integer.parseInt (string); | |
466 } | |
467 int max = getMaximum(); | |
468 int min = getMinimum(); | |
469 if (min <= value && value <= max) return value; | |
470 } catch (NumberFormatException e) { | |
471 } | |
472 parseFail [0] = true; | |
404 return -1; | 473 return -1; |
474 } | |
475 | |
476 void keyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { | |
477 NSEvent event = new NSEvent(theEvent); | |
478 NSString chars = event.charactersIgnoringModifiers(); | |
479 | |
480 int delta = 0; | |
481 int keyChar = 0; | |
482 | |
483 if (chars.length() !is 1) return; | |
484 | |
485 keyChar = chars.characterAtIndex(0); | |
486 | |
487 switch (keyChar) { | |
488 case OS.NSEnterCharacter: /* KP Enter */ | |
489 case OS.NSNewlineCharacter: /* Return */ | |
490 postEvent (DWT.DefaultSelection); | |
491 return; | |
492 case OS.NSPageUpFunctionKey: delta = pageIncrement; break; | |
493 case OS.NSPageDownFunctionKey: delta = -pageIncrement; break; | |
494 case OS.NSDownArrowFunctionKey: delta = -getIncrement(); break; | |
495 case OS.NSUpArrowFunctionKey: delta = getIncrement(); break; | |
496 | |
497 default: { | |
498 NSCharacterSet numbers = new NSCharacterSet(NSCharacterSet.decimalDigitCharacterSet().id); | |
499 bool isANumber = numbers.characterIsMember((short) keyChar); | |
500 bool isSeparator = (keyChar is textFormatter.decimalSeparator().characterAtIndex(0)); | |
501 bool isMathSymbol = (keyChar is 0x2d || keyChar is 0x2b); // Minus sign, plus sign | |
502 if (isANumber || (isSeparator && digits > 0) || isMathSymbol) super.keyDown(id, sel, theEvent); | |
503 } | |
504 } | |
505 | |
506 if (delta !is 0) { | |
507 bool [] parseFail = new bool [1]; | |
508 int value = getSelectionText (parseFail); | |
509 if (parseFail [0]) { | |
510 value = (int)buttonView.doubleValue(); | |
511 } | |
512 int newValue = value + delta; | |
513 int max = (int)buttonView.maxValue(); | |
514 int min = (int)buttonView.minValue(); | |
515 if ((style & DWT.WRAP) !is 0) { | |
516 if (newValue > max) newValue = min; | |
517 if (newValue < min) newValue = max; | |
518 } | |
519 newValue = Math.min (Math.max (min, newValue), max); | |
520 if (value !is newValue) setSelection (newValue, true, true, true); | |
521 return; | |
522 } else { | |
523 bool [] parseFail = new bool [1]; | |
524 int value = getSelectionText (parseFail); | |
525 if (!parseFail [0]) { | |
526 int pos = (int)buttonView.doubleValue(); | |
527 if (pos !is value) setSelection (value, true, false, true); | |
528 } | |
529 } | |
405 } | 530 } |
406 | 531 |
407 /** | 532 /** |
408 * Pastes text from clipboard. | 533 * Pastes text from clipboard. |
409 * <p> | 534 * <p> |
423 // short [] selection = new short [2]; | 548 // short [] selection = new short [2]; |
424 // if (OS.GetControlData (textHandle, cast(short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) !is OS.noErr) return; | 549 // 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); | 550 // setText (text, selection [0], selection [1], true); |
426 } | 551 } |
427 | 552 |
553 void register () { | |
554 super.register (); | |
555 if (textView !is null) { | |
556 display.addWidget (textView, this); | |
557 display.addWidget (textView.cell(), this); | |
558 } | |
559 | |
560 if (buttonView !is null) { | |
561 display.addWidget (buttonView, this); | |
562 display.addWidget (buttonView.cell(), this); | |
563 } | |
564 } | |
565 | |
428 void releaseHandle () { | 566 void releaseHandle () { |
429 super.releaseHandle(); | 567 super.releaseHandle(); |
430 if (buttonView !is null) { | 568 if (textFormatter !is null) textFormatter.release(); |
431 buttonView.setTag(-1); | 569 if (buttonView !is null) buttonView.release(); |
432 buttonView.release(); | 570 if (textView !is null) textView.release(); |
433 } | 571 textFormatter = null; |
434 if (textView !is null) { | |
435 textView.setTag(-1); | |
436 textView.release(); | |
437 } | |
438 buttonView = null; | 572 buttonView = null; |
439 textView = null; | 573 textView = null; |
440 } | 574 } |
441 | 575 |
442 /** | 576 /** |
510 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | 644 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); |
511 if (eventTable is null) return; | 645 if (eventTable is null) return; |
512 eventTable.unhook (DWT.Verify, listener); | 646 eventTable.unhook (DWT.Verify, listener); |
513 } | 647 } |
514 | 648 |
649 void resized () { | |
650 super.resized (); | |
651 buttonView.sizeToFit(); | |
652 NSRect buttonFrame = buttonView.bounds(); | |
653 NSRect frame = view.frame(); | |
654 buttonFrame.x = frame.width - buttonFrame.width; | |
655 buttonFrame.y = 0; | |
656 frame.x = 0; | |
657 frame.y = 0; | |
658 frame.width -= buttonFrame.width + GAP; | |
659 textView.setFrame(frame); | |
660 buttonView.setFrame(buttonFrame); | |
661 } | |
662 | |
515 void sendSelection () { | 663 void sendSelection () { |
516 setSelection (getSelection(), false, true, true); | 664 setSelection (getSelection(), false, true, true); |
517 } | |
518 | |
519 int setBounds (int x, int y, int width, int height, bool move, bool resize) { | |
520 int result = super.setBounds(x, y, width, height, move, resize); | |
521 if ((result & RESIZED) !is 0) { | |
522 buttonView.sizeToFit(); | |
523 NSRect buttonFrame = buttonView.bounds(); | |
524 NSRect frame = view.frame(); | |
525 buttonFrame.x = frame.width - buttonFrame.width; | |
526 buttonFrame.y = 0; | |
527 frame.x = 0; | |
528 frame.y = 0; | |
529 frame.width -= buttonFrame.width + GAP; | |
530 textView.setFrame(frame); | |
531 buttonView.setFrame(buttonFrame); | |
532 } | |
533 return result; | |
534 } | 665 } |
535 | 666 |
536 /** | 667 /** |
537 * Sets the number of decimal places used by the receiver. | 668 * Sets the number of decimal places used by the receiver. |
538 * <p> | 669 * <p> |
554 * </ul> | 685 * </ul> |
555 */ | 686 */ |
556 public void setDigits (int value) { | 687 public void setDigits (int value) { |
557 checkWidget (); | 688 checkWidget (); |
558 if (value < 0) error (DWT.ERROR_INVALID_ARGUMENT); | 689 if (value < 0) error (DWT.ERROR_INVALID_ARGUMENT); |
559 // if (value is digits) return; | 690 if (value is digits) return; |
560 // digits = value; | 691 digits = value; |
561 // int pos = OS.GetControl32BitValue (buttonHandle); | 692 int pos = (int)buttonView.doubleValue(); |
562 // setSelection (pos, false, true, false); | 693 textFormatter.setMaximumFractionDigits(digits); |
694 setSelection (pos, false, true, false); | |
695 } | |
696 | |
697 void setFont(NSFont font) { | |
698 textView.setFont(font); | |
563 } | 699 } |
564 | 700 |
565 /** | 701 /** |
566 * Sets the amount that the receiver's value will be | 702 * Sets the amount that the receiver's value will be |
567 * modified by when the up/down arrows are pressed to | 703 * modified by when the up/down arrows are pressed to |
598 if (value < 0) return; | 734 if (value < 0) return; |
599 int min = getMinimum (); | 735 int min = getMinimum (); |
600 if (value <= min) return; | 736 if (value <= min) return; |
601 int pos = getSelection(); | 737 int pos = getSelection(); |
602 buttonView.setMaxValue(value); | 738 buttonView.setMaxValue(value); |
739 textFormatter.setMaximum(NSNumber.numberWithInt(value)); | |
603 if (pos > value) setSelection (value, true, true, false); | 740 if (pos > value) setSelection (value, true, true, false); |
604 } | 741 } |
605 | 742 |
606 /** | 743 /** |
607 * Sets the minimum value that the receiver will allow. This new | 744 * Sets the minimum value that the receiver will allow. This new |
608 * value will be ignored if it is negative or is not less than the receiver's | 745 * value will be ignored if it is not less than the receiver's |
609 * current maximum value. If the new minimum is applied then the receiver's | 746 * current maximum value. If the new minimum is applied then the receiver's |
610 * selection value will be adjusted if necessary to fall within its new range. | 747 * selection value will be adjusted if necessary to fall within its new range. |
611 * | 748 * |
612 * @param value the new minimum, which must be nonnegative and less than the current maximum | 749 * @param value the new minimum, which must be less than the current maximum |
613 * | 750 * |
614 * @exception DWTException <ul> | 751 * @exception DWTException <ul> |
615 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 752 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
616 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 753 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
617 * </ul> | 754 * </ul> |
621 if (value < 0) return; | 758 if (value < 0) return; |
622 int max = getMaximum(); | 759 int max = getMaximum(); |
623 if (value >= max) return; | 760 if (value >= max) return; |
624 int pos = getSelection(); | 761 int pos = getSelection(); |
625 buttonView.setMinValue(value); | 762 buttonView.setMinValue(value); |
763 textFormatter.setMinimum(NSNumber.numberWithInt(value)); | |
626 if (pos < value) setSelection (value, true, true, false); | 764 if (pos < value) setSelection (value, true, true, false); |
627 } | 765 } |
628 | 766 |
629 /** | 767 /** |
630 * Sets the amount that the receiver's position will be | 768 * Sets the amount that the receiver's position will be |
670 (cast(NSStepper)buttonView).setDoubleValue(value); | 808 (cast(NSStepper)buttonView).setDoubleValue(value); |
671 } | 809 } |
672 if (setText) { | 810 if (setText) { |
673 String string = String.valueOf (value); | 811 String string = String.valueOf (value); |
674 if (digits > 0) { | 812 if (digits > 0) { |
675 String decimalSeparator = ".";//getDecimalSeparator (); | 813 String decimalSeparator = textFormatter.decimalSeparator().getString(); |
676 int index = string.length () - digits; | 814 int index = string.length () - digits; |
677 StringBuffer buffer = new StringBuffer (); | 815 StringBuffer buffer = new StringBuffer (); |
678 if (index > 0) { | 816 if (index > 0) { |
679 buffer.append (string.substring (0, index)); | 817 buffer.append (string.substring (0, index)); |
680 buffer.append (decimalSeparator); | 818 buffer.append (decimalSeparator); |
687 } | 825 } |
688 string = buffer.toString (); | 826 string = buffer.toString (); |
689 } | 827 } |
690 NSCell cell = new NSCell(textView.cell()); | 828 NSCell cell = new NSCell(textView.cell()); |
691 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 829 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
692 int length = cell.title().length(); | 830 int length = (int)/*64*/cell.title().length(); |
693 string = verifyText (string, 0, length, null); | 831 string = verifyText (string, 0, length, null); |
694 if (string is null) return; | 832 if (string is null) return; |
695 } | 833 } |
696 cell.setTitle(NSString.stringWith(string)); | 834 textView.setStringValue(NSString.stringWith(string)); |
697 // short [] selection = new short [] {0, cast(short)string.length ()}; | |
698 // OS.SetControlData (textHandle, cast(short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection); | |
699 sendEvent (DWT.Modify); | 835 sendEvent (DWT.Modify); |
700 } | 836 } |
701 if (notify) postEvent (DWT.Selection); | 837 if (notify) postEvent (DWT.Selection); |
702 } | 838 } |
703 | 839 |
738 buttonView.setMaxValue(maximum); | 874 buttonView.setMaxValue(maximum); |
739 buttonView.setMinValue(minimum); | 875 buttonView.setMinValue(minimum); |
740 setSelection (selection, true, true, false); | 876 setSelection (selection, true, true, false); |
741 } | 877 } |
742 | 878 |
879 void textDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { | |
880 postEvent (DWT.Modify); | |
881 } | |
882 | |
883 void textDidEndEditing(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { | |
884 bool [] parseFail = new bool [1]; | |
885 int value = getSelectionText (parseFail); | |
886 if (parseFail [0]) { | |
887 value = (int)buttonView.doubleValue(); | |
888 setSelection (value, false, true, false); | |
889 } | |
890 } | |
891 | |
743 String verifyText (String string, int start, int end, Event keyEvent) { | 892 String verifyText (String string, int start, int end, Event keyEvent) { |
744 Event event = new Event (); | 893 Event event = new Event (); |
745 event.text = string; | 894 event.text = string; |
746 event.start = start; | 895 event.start = start; |
747 event.end = end; | 896 event.end = end; |