iup_spin_box.e 2.6 KB

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