iup_text_spin.e 4.3 KB

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