iup_spin.e 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. class IUP_SPIN
  2. -- This functions will create a control set with a vertical box containing two
  3. -- buttons, one with an up arrow and the other with a down arrow, to be used to
  4. -- increment and decrement values.
  5. inherit
  6. IUP_WIDGET
  7. redefine
  8. execute_spin
  9. end
  10. IUP_WIDGET_CHILD
  11. IUP_WIDGET_NAME
  12. IUP_WIDGET_CUSTOM_ATTRIBUTES
  13. create {ANY}
  14. spin
  15. feature {ANY}
  16. spin
  17. -- New spin.
  18. local
  19. a_spin: POINTER
  20. do
  21. a_spin := int_spin
  22. set_widget(a_spin)
  23. end
  24. -- Callback
  25. set_cb_spin (act: detachable FUNCTION[TUPLE[IUP_SPIN, INTEGER], STRING])
  26. -- Called each time the user clicks in the buttons. It will increment 1
  27. -- and decrement -1 by default. Holding the Shift key will set a factor
  28. -- of 2, holding Ctrl a factor of 10, and both a factor of 100.
  29. local
  30. operation: INTEGER
  31. do
  32. cb_spin := act
  33. if cb_spin /= Void then
  34. operation := 1
  35. else
  36. operation := 0
  37. end
  38. iup_open.set_callback (Current, "SPIN_CB", "NONEEDED", operation)
  39. end
  40. feature {IUP}
  41. execute_spin (inc: INTEGER): STRING
  42. do
  43. if attached cb_spin as int_cb then
  44. Result := int_cb.item([Current, inc])
  45. else
  46. Result := "IUP_DEFAULT"
  47. end
  48. end
  49. feature {NONE}
  50. -- For callback
  51. cb_spin: detachable FUNCTION[TUPLE[IUP_SPIN, INTEGER], STRING]
  52. -- Internal
  53. int_spin: POINTER
  54. external
  55. "C inline use %"eiffel-iup.h%""
  56. alias
  57. "return IupSpin();"
  58. end
  59. end
  60. -- The MIT License (MIT)
  61. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  62. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  63. -- of this software and associated documentation files (the "Software"), to deal
  64. -- in the Software without restriction, including without limitation the rights
  65. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  66. -- copies of the Software, and to permit persons to whom the Software is
  67. -- furnished to do so, subject to the following conditions:
  68. --
  69. -- The above copyright notice and this permission notice shall be included in
  70. -- all copies or substantial portions of the Software.
  71. --
  72. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  73. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  74. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  75. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  76. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  77. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  78. -- SOFTWARE.