iup_widget_text_spin.e 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. deferred class IUP_WIDGET_TEXT_SPIN
  2. -- Commands to handle the attributes related with spin.
  3. -- In Windows, the increment is multiplied by 5 after 2 seconds and multiplied
  4. -- by 20 after 5 seconds of a spin button pressed. In GTK, the increment change
  5. -- is progressively accelerated when a spin button is pressed.
  6. inherit
  7. IUP_WIDGET_INTERNALS
  8. feature {ANY}
  9. set_spin (state: BOOLEAN)
  10. -- (non inheritable, creation only): enables a spin control attached
  11. -- to the element. Default: False. The spin increments and decrements
  12. -- an integer number. The editing in the element is still available.
  13. do
  14. iup_open.set_attribute(Current, "SPIN", boolean_to_yesno(state))
  15. end
  16. set_spin_value (value: INTEGER)
  17. -- (non inheritable): the current value of the spin. The value is
  18. -- limited to the minimum and maximum values.
  19. do
  20. iup_open.set_attribute(Current, "SPINVALUE", value.out)
  21. end
  22. get_spin_value: INTEGER
  23. -- Return the spin value.
  24. local
  25. str: STRING
  26. do
  27. str := iup_open.get_attribute(Current, "SPINVALUE")
  28. if str.is_integer then
  29. Result := str.to_integer
  30. end
  31. end
  32. set_spin_max (value: INTEGER)
  33. -- (non inheritable): the maximum value. Default: 100.
  34. do
  35. iup_open.set_attribute(Current, "SPINMAX", value.out)
  36. end
  37. set_spin_min (value: INTEGER)
  38. -- (non inheritable): the minimum value. Default: 0.
  39. do
  40. iup_open.set_attribute(Current, "SPINMIN", value.out)
  41. end
  42. set_spin_increment (value: INTEGER)
  43. -- (non inheritable): the increment value. Default: 1.
  44. do
  45. iup_open.set_attribute(Current, "SPININC", value.out)
  46. end
  47. set_spin_right_alignment
  48. -- (creation only): set spin at right position. This is the default
  49. -- value. In GTK is always right.
  50. do
  51. iup_open.set_attribute(Current, "SPINALIGN", "RIGHT")
  52. end
  53. set_spin_left_alignment
  54. -- (creation only): set spin at left position. In GTK is always
  55. -- right.
  56. do
  57. iup_open.set_attribute(Current, "SPINALIGN", "LEFT")
  58. end
  59. set_spin_wrap (state: BOOLEAN)
  60. -- (creation only): if the position reach a limit it continues from the
  61. -- opposite limit. Default: False.
  62. do
  63. iup_open.set_attribute(Current, "SPINWRAP", boolean_to_yesno(state))
  64. end
  65. set_spin_auto (state: BOOLEAN)
  66. -- (creation only): enables the automatic update of the text contents.
  67. -- Default: True. Use SPINAUTO=False and the VALUE attribute during
  68. -- SPIN_CB to control the text contents when the spin is incremented.
  69. do
  70. iup_open.set_attribute(Current, "SPINAUTO", boolean_to_yesno(state))
  71. end
  72. -- Callback
  73. set_cb_spin (act: detachable FUNCTION[TUPLE[IUP_WIDGET, INTEGER], STRING])
  74. -- Called each time the user clicks in the buttons. It will increment 1
  75. -- and decrement -1 by default. Holding the Shift key will set a factor
  76. -- of 2, holding Ctrl a factor of 10, and both a factor of 100.
  77. local
  78. operation: INTEGER
  79. do
  80. cb_spin := act
  81. if cb_spin /= Void then
  82. operation := 1
  83. else
  84. operation := 0
  85. end
  86. iup_open.set_callback (Current, "SPIN_CB", "NONEEDED", operation)
  87. end
  88. feature {IUP}
  89. execute_spin (inc: INTEGER): STRING
  90. do
  91. if attached cb_spin as int_cb then
  92. Result := int_cb.item([Current, inc])
  93. else
  94. Result := "IUP_DEFAULT"
  95. end
  96. end
  97. feature {NONE}
  98. -- For callback
  99. cb_spin: detachable FUNCTION[TUPLE[IUP_WIDGET, INTEGER], STRING]
  100. end
  101. -- The MIT License (MIT)
  102. -- Copyright (c) 2016, 2019, 2020 by German A. Arias
  103. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  104. -- of this software and associated documentation files (the "Software"), to deal
  105. -- in the Software without restriction, including without limitation the rights
  106. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  107. -- copies of the Software, and to permit persons to whom the Software is
  108. -- furnished to do so, subject to the following conditions:
  109. --
  110. -- The above copyright notice and this permission notice shall be included in
  111. -- all copies or substantial portions of the Software.
  112. --
  113. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  114. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  115. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  116. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  117. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  118. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  119. -- SOFTWARE.