iup_drop.e 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. class IUP_DROP
  2. -- Class used to display a dropdown list or a popup menu at IUP_MATRIX. How
  3. -- this will be displayed depend on the IUP_MATRIX callback that will be used
  4. -- to append its items. See IUP_MATRIX documentation.
  5. inherit
  6. IUP_WIDGET
  7. insert
  8. IUP_INTERFACE
  9. create {IUP}
  10. drop_widget
  11. feature {IUP}
  12. drop_widget (p: POINTER)
  13. do
  14. set_widget(p)
  15. end
  16. feature {ANY}
  17. --- Operations
  18. set_value (id: INTEGER)
  19. -- Set the list current value, id starts at 1.
  20. -- The default is always "1".
  21. require
  22. id >= 0
  23. do
  24. iup_open.set_int(Current, "VALUE", id)
  25. end
  26. get_previous_value: STRING
  27. -- The previously value in the cell where the drop is displayed.
  28. do
  29. Result := iup_open.get_attribute(Current, "PREVIOUSVALUE")
  30. end
  31. append_items (items: ARRAY[STRING])
  32. -- Append items at dropdown list or menu in the same order.
  33. local
  34. i: INTEGER
  35. s: STRING
  36. iterator: ITERATOR[STRING]
  37. do
  38. i := 1
  39. iterator := items.new_iterator
  40. from
  41. iterator.start
  42. until
  43. iterator.is_off
  44. loop
  45. s := iterator.item
  46. iup_open.set_attribute(Current, i.out, s)
  47. iterator.next
  48. i := i + 1
  49. end
  50. iup_open.set_attribute_null(Current, i.out)
  51. end
  52. set_image_at (image: STRING; id_item: INTEGER)
  53. -- Image to be set at the correspondent menu item.
  54. -- id starts at 1. Only works when the drop is displayed like
  55. -- a popup menu. Ignored if id is out of bounds.
  56. require
  57. valid_id: id_item > 0
  58. do
  59. iup_open.set_attribute_id(Current, "IMAGE", id_item, image)
  60. end
  61. end
  62. -- The MIT License (MIT)
  63. -- Copyright (c) 2017, 2022 by German A. Arias
  64. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  65. -- of this software and associated documentation files (the "Software"), to deal
  66. -- in the Software without restriction, including without limitation the rights
  67. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  68. -- copies of the Software, and to permit persons to whom the Software is
  69. -- furnished to do so, subject to the following conditions:
  70. --
  71. -- The above copyright notice and this permission notice shall be included in
  72. -- all copies or substantial portions of the Software.
  73. --
  74. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  75. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  76. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  77. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  78. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  79. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  80. -- SOFTWARE.