iup_list_dialog.e 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. class IUP_LIST_DIALOG
  2. -- Shows a modal dialog to select items from a simple or multiple selection
  3. -- list.
  4. --
  5. -- The dialog uses a global attribute called "PARENTDIALOG" as the parent
  6. -- dialog if it is defined. It also uses a global attribute called "ICON" as
  7. -- the dialog icon if it is defined.
  8. inherit
  9. IUP_WIDGET
  10. create {ANY}
  11. list_dialog_simple,
  12. list_dialog_multiple
  13. feature {ANY}
  14. list_dialog_simple (title: STRING; list: ARRAY[STRING];
  15. op, max_col, max_lin: INTEGER)
  16. -- Create a dialog for simple selection.
  17. --
  18. -- title: Text for the dialog’s title.
  19. -- list: List of options.
  20. -- op: Initial selected item. Starts at 1 (note that this index is
  21. -- different from the return value, kept for compatibility reasons).
  22. -- max_col: number of visible columns in the list.
  23. -- max_lin: number of visible lines in the list.
  24. do
  25. t := 1
  26. ttl := title
  27. l := list
  28. o := op
  29. mc := max_col
  30. ml := max_lin
  31. convert_to_native(list)
  32. end
  33. list_dialog_multiple (title: STRING; list: ARRAY[STRING];
  34. max_col, max_lin: INTEGER)
  35. -- Create a dialog for multiple selection.
  36. --
  37. -- title: Text for the dialog’s title.
  38. -- list: List of options.
  39. -- max_col: number of visible columns in the list.
  40. -- max_lin: number of visible lines in the list.
  41. do
  42. t := 2
  43. ttl := title
  44. l := list
  45. o := 0
  46. mc := max_col
  47. ml := max_lin
  48. convert_to_native(list)
  49. end
  50. launch: TUPLE[INTEGER, STRING]
  51. -- Show the dialog. If is a dialog for simple selection, the tuple
  52. -- return an integer with the index of the selected item (starts
  53. -- at 0), or -1 if the user cancels the operation. Also return the
  54. -- item itself, or an empty string if the user cancel the operation.
  55. -- If is a dialog of multiple selection, the function returns -1 when
  56. -- the user cancels the operation and an empty string. If the user
  57. -- does not cancel the operation the function returns 1 and the string
  58. -- parameter will have value 1 for the options selected by the user
  59. -- and value 0 for non-selected options (for example: "0010011100").
  60. local
  61. i: INTEGER
  62. so: STRING
  63. marks: ARRAY[INTEGER]
  64. do
  65. create marks.make_filled(0, 1, l.count)
  66. i := int_list_dialog (t, get_pointer(ttl.to_c),
  67. l.count, get_pointer(arg.to_c), o, mc, ml,
  68. get_pointer(marks.to_c))
  69. if i.is_equal(-1) then
  70. Result := [i, ""]
  71. else
  72. if t.is_equal(1) then
  73. Result := [i, l.item(i)]
  74. else
  75. so := ""
  76. across
  77. marks as ic
  78. loop
  79. so.append_string(ic.item.out)
  80. end
  81. Result := [i, so]
  82. end
  83. end
  84. end
  85. feature {NONE}
  86. t, o, mc, ml: INTEGER
  87. ttl: STRING
  88. l: ARRAY[STRING]
  89. arg: ARRAY[POINTER]
  90. -- Internals
  91. int_list_dialog (type: INTEGER; title: POINTER; size: INTEGER; list: POINTER; op, max_col, max_lin: INTEGER; marks: POINTER): INTEGER
  92. external
  93. "C inline use %"eiffel-iup.h%""
  94. alias
  95. "return IupListDialog ($type, $title, $size, $list, $op, $max_col, $max_lin, $marks);"
  96. end
  97. convert_to_native (col: ARRAY[STRING])
  98. local
  99. i: INTEGER; s: STRING
  100. do
  101. i := col.count
  102. create arg.make_filled(default_pointer, 1, i + 1)
  103. i := 0
  104. across
  105. col as ic
  106. loop
  107. i := i + 1
  108. s := ic.item
  109. arg.put(get_pointer(s.to_c), i)
  110. end
  111. end
  112. end -- class IUP_LIST_DIALOG
  113. -- The MIT License (MIT)
  114. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  115. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  116. -- of this software and associated documentation files (the "Software"), to deal
  117. -- in the Software without restriction, including without limitation the rights
  118. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  119. -- copies of the Software, and to permit persons to whom the Software is
  120. -- furnished to do so, subject to the following conditions:
  121. --
  122. -- The above copyright notice and this permission notice shall be included in
  123. -- all copies or substantial portions of the Software.
  124. --
  125. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  126. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  127. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  128. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  129. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  130. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  131. -- SOFTWARE.