comparison dwt/widgets/Spinner.d @ 240:ce446666f5a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Mon, 12 May 2008 19:13:01 +0200
parents 380bad9f6852
children 5a30aa9820f3
comparison
equal deleted inserted replaced
239:06a1f6829310 240:ce446666f5a2
61 static final int INNER_BORDER = 2; 61 static final int INNER_BORDER = 2;
62 static final int MIN_ARROW_WIDTH = 6; 62 static final int MIN_ARROW_WIDTH = 6;
63 int lastEventTime = 0; 63 int lastEventTime = 0;
64 GdkEventKey* gdkEventKey; 64 GdkEventKey* gdkEventKey;
65 int fixStart = -1, fixEnd = -1; 65 int fixStart = -1, fixEnd = -1;
66
67 /**
68 * The maximum number of characters that can be entered
69 * into a text widget.
70 * <p>
71 * Note that this value is platform dependent, based upon
72 * the native widget implementation.
73 * </p>
74 */
75 public const static int LIMIT = 0x7FFFFFFF;
66 76
67 /** 77 /**
68 * Constructs a new instance of this class given its parent 78 * Constructs a new instance of this class given its parent
69 * and a style value describing its behavior and appearance. 79 * and a style value describing its behavior and appearance.
70 * <p> 80 * <p>
388 checkWidget (); 398 checkWidget ();
389 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); 399 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle);
390 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); 400 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle);
391 auto value = adjustment.step_increment; 401 auto value = adjustment.step_increment;
392 for (int i = 0; i < digits; i++) value *= 10; 402 for (int i = 0; i < digits; i++) value *= 10;
393 return cast(int) (value + 0.5); 403 return cast(int) (value > 0 ? value + 0.5 : value - 0.5);
394 } 404 }
395 405
396 /** 406 /**
397 * Returns the maximum value which the receiver will allow. 407 * Returns the maximum value which the receiver will allow.
398 * 408 *
407 checkWidget (); 417 checkWidget ();
408 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); 418 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle);
409 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); 419 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle);
410 auto value = adjustment.upper; 420 auto value = adjustment.upper;
411 for (int i = 0; i < digits; i++) value *= 10; 421 for (int i = 0; i < digits; i++) value *= 10;
412 return cast(int) (value + 0.5); 422 return cast(int) (value > 0 ? value + 0.5 : value - 0.5);
413 } 423 }
414 424
415 /** 425 /**
416 * Returns the minimum value which the receiver will allow. 426 * Returns the minimum value which the receiver will allow.
417 * 427 *
426 checkWidget (); 436 checkWidget ();
427 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); 437 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle);
428 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); 438 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle);
429 auto value = adjustment.lower; 439 auto value = adjustment.lower;
430 for (int i = 0; i < digits; i++) value *= 10; 440 for (int i = 0; i < digits; i++) value *= 10;
431 return cast(int) (value + 0.5); 441 return cast(int) (value > 0 ? value + 0.5 : value - 0.5);
432 } 442 }
433 443
434 /** 444 /**
435 * Returns the amount that the receiver's position will be 445 * Returns the amount that the receiver's position will be
436 * modified by when the page up/down keys are pressed. 446 * modified by when the page up/down keys are pressed.
446 checkWidget (); 456 checkWidget ();
447 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); 457 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle);
448 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); 458 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle);
449 auto value = adjustment.page_increment; 459 auto value = adjustment.page_increment;
450 for (int i = 0; i < digits; i++) value *= 10; 460 for (int i = 0; i < digits; i++) value *= 10;
451 return cast(int) (value + 0.5); 461 return cast(int) (value > 0 ? value + 0.5 : value - 0.5);
452 } 462 }
453 463
454 /** 464 /**
455 * Returns the <em>selection</em>, which is the receiver's position. 465 * Returns the <em>selection</em>, which is the receiver's position.
456 * 466 *
465 checkWidget (); 475 checkWidget ();
466 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); 476 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle);
467 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); 477 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle);
468 auto value = adjustment.value; 478 auto value = adjustment.value;
469 for (int i = 0; i < digits; i++) value *= 10; 479 for (int i = 0; i < digits; i++) value *= 10;
470 return cast(int) (value + 0.5); 480 return cast(int) (value > 0 ? value + 0.5 : value - 0.5);
481 }
482
483 public String getText () {
484 checkWidget ();
485 auto str = OS.gtk_entry_get_text (handle);
486 return tango.stdc.stringz.fromStringz(str).dup;
487 }
488
489 public int getTextLimit () {
490 checkWidget ();
491 int limit = OS.gtk_entry_get_max_length (handle);
492 return limit is 0 ? 0xFFFF : limit;
471 } 493 }
472 494
473 /** 495 /**
474 * Returns the number of decimal places used by the receiver. 496 * Returns the number of decimal places used by the receiver.
475 * 497 *
644 if (gdkEventKey is cast(GdkEventKey*)-1) result = 1; 666 if (gdkEventKey is cast(GdkEventKey*)-1) result = 1;
645 gdkEventKey = null; 667 gdkEventKey = null;
646 return result; 668 return result;
647 } 669 }
648 670
671 override int /*long*/ gtk_populate_popup (GtkWidget* widget, GtkWidget* menu) {
672 if ((style & DWT.RIGHT_TO_LEFT) !is 0) {
673 OS.gtk_widget_set_direction (menu, OS.GTK_TEXT_DIR_RTL);
674 display.doSetDirectionProc( menu, OS.GTK_TEXT_DIR_RTL);
675 }
676 return 0;
677 }
678
649 override int /*long*/ gtk_value_changed (int adjustment) { 679 override int /*long*/ gtk_value_changed (int adjustment) {
650 postEvent (DWT.Selection); 680 postEvent (DWT.Selection);
651 return 0; 681 return 0;
652 } 682 }
653 683
656 OS.g_signal_connect_closure (handle, OS.changed.ptr, display.closures [CHANGED], true); 686 OS.g_signal_connect_closure (handle, OS.changed.ptr, display.closures [CHANGED], true);
657 OS.g_signal_connect_closure (handle, OS.insert_text.ptr, display.closures [INSERT_TEXT], false); 687 OS.g_signal_connect_closure (handle, OS.insert_text.ptr, display.closures [INSERT_TEXT], false);
658 OS.g_signal_connect_closure (handle, OS.delete_text.ptr, display.closures [DELETE_TEXT], false); 688 OS.g_signal_connect_closure (handle, OS.delete_text.ptr, display.closures [DELETE_TEXT], false);
659 OS.g_signal_connect_closure (handle, OS.value_changed.ptr, display.closures [VALUE_CHANGED], false); 689 OS.g_signal_connect_closure (handle, OS.value_changed.ptr, display.closures [VALUE_CHANGED], false);
660 OS.g_signal_connect_closure (handle, OS.activate.ptr, display.closures [ACTIVATE], false); 690 OS.g_signal_connect_closure (handle, OS.activate.ptr, display.closures [ACTIVATE], false);
691 OS.g_signal_connect_closure (handle, OS.populate_popup.ptr, display.closures [POPULATE_POPUP], false);
661 auto imContext = imContext (); 692 auto imContext = imContext ();
662 if (imContext !is null) { 693 if (imContext !is null) {
663 OS.g_signal_connect_closure (imContext, OS.commit.ptr, display.closures [COMMIT], false); 694 OS.g_signal_connect_closure (imContext, OS.commit.ptr, display.closures [COMMIT], false);
664 int id = OS.g_signal_lookup (OS.commit.ptr, OS.gtk_im_context_get_type ()); 695 int id = OS.g_signal_lookup (OS.commit.ptr, OS.gtk_im_context_get_type ());
665 int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; 696 int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
833 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 864 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
834 * </ul> 865 * </ul>
835 */ 866 */
836 public void setMaximum (int value) { 867 public void setMaximum (int value) {
837 checkWidget (); 868 checkWidget ();
838 if (value < 0) return;
839 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); 869 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle);
840 double newValue = value; 870 double newValue = value;
841 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); 871 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle);
842 for (int i = 0; i < digits; i++) newValue /= 10; 872 for (int i = 0; i < digits; i++) newValue /= 10;
843 if (newValue <= adjustment.lower) return; 873 if (newValue <= adjustment.lower) return;
859 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 889 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
860 * </ul> 890 * </ul>
861 */ 891 */
862 public void setMinimum (int value) { 892 public void setMinimum (int value) {
863 checkWidget (); 893 checkWidget ();
864 if (value < 0) return;
865 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle); 894 auto adjustment = OS.gtk_spin_button_get_adjustment (cast(GtkSpinButton*)handle);
866 double newValue = value; 895 double newValue = value;
867 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); 896 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle);
868 for (int i = 0; i < digits; i++) newValue /= 10; 897 for (int i = 0; i < digits; i++) newValue /= 10;
869 if (newValue >= adjustment.upper) return; 898 if (newValue >= adjustment.upper) return;
915 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle); 944 int digits = OS.gtk_spin_button_get_digits (cast(GtkSpinButton*)handle);
916 for (int i = 0; i < digits; i++) newValue /= 10; 945 for (int i = 0; i < digits; i++) newValue /= 10;
917 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); 946 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
918 OS.gtk_spin_button_set_value (cast(GtkSpinButton*)handle, newValue); 947 OS.gtk_spin_button_set_value (cast(GtkSpinButton*)handle, newValue);
919 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); 948 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
949 }
950
951 public void setTextLimit (int limit) {
952 checkWidget ();
953 if (limit is 0) error (DWT.ERROR_CANNOT_BE_ZERO);
954 OS.gtk_entry_set_max_length (handle, limit);
920 } 955 }
921 956
922 /** 957 /**
923 * Sets the number of decimal places used by the receiver. 958 * Sets the number of decimal places used by the receiver.
924 * <p> 959 * <p>
987 * 1022 *
988 * @since 3.2 1023 * @since 3.2
989 */ 1024 */
990 public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) { 1025 public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
991 checkWidget (); 1026 checkWidget ();
992 if (minimum < 0) return;
993 if (maximum <= minimum) return; 1027 if (maximum <= minimum) return;
994 if (digits < 0) return; 1028 if (digits < 0) return;
995 if (increment < 1) return; 1029 if (increment < 1) return;
996 if (pageIncrement < 1) return; 1030 if (pageIncrement < 1) return;
997 selection = Math.min (Math.max (minimum, selection), maximum); 1031 selection = Math.min (Math.max (minimum, selection), maximum);
1050 if (index !is -1 ) { 1084 if (index !is -1 ) {
1051 string = string.substring( 0, index ) ~ string.substring( index + 1 ); 1085 string = string.substring( 0, index ) ~ string.substring( index + 1 );
1052 } 1086 }
1053 index = 0; 1087 index = 0;
1054 } 1088 }
1089 if (string.length > 0) {
1090 auto adjustment = OS.gtk_spin_button_get_adjustment (handle);
1091 if (adjustment.lower < 0 && string.charAt (0) is '-') index++;
1092 }
1055 while (index < string.length) { 1093 while (index < string.length) {
1056 if (!CharacterIsDigit (string.charAt(index))) break; 1094 if (!CharacterIsDigit (string.charAt(index))) break;
1057 index++; 1095 index++;
1058 } 1096 }
1059 event.doit = index is string.length; 1097 event.doit = index is string.length;