iup_widget_text_selection.e 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. deferred class IUP_WIDGET_TEXT_SELECTION
  2. -- Commands to handle the attributes related with selection.
  3. inherit
  4. IUP_WIDGET_INTERNALS
  5. feature {ANY}
  6. set_selection (col1, col2: INTEGER)
  7. -- Selection interval in characters. Where col1 and col2 are integer
  8. -- numbers corresponding to the selection's interval. col2 correspond to
  9. -- the character after the last selected character.
  10. -- The first position is "1".
  11. -- In Windows, when changing the selection the caret position is also
  12. -- changed.
  13. local
  14. str: STRING
  15. do
  16. str := col1.out
  17. str.append_string(":")
  18. str.append_string(col2.out)
  19. iup_open.set_attribute(Current, "SELECTION", str)
  20. end
  21. get_selection: TUPLE[INTEGER, INTEGER]
  22. -- Selection interval in characters. Returns "0, 0" if there is no
  23. -- selection.
  24. local
  25. str: STRING
  26. do
  27. str := iup_open.get_attribute(Current, "SELECTION")
  28. if not str.is_empty then
  29. Result := components_of(str, ':')
  30. else
  31. Result := [0, 0]
  32. end
  33. end
  34. set_selection_pos (col1, col2: INTEGER)
  35. -- (non inheritable): Same as SELECTION but using a zero based character
  36. -- index. Useful for indexing the VALUE string. See the Notes above if
  37. -- using UTF-8 strings in GTK.
  38. local
  39. str: STRING
  40. do
  41. create str.make_from_string(col1.out)
  42. str.append_string(":")
  43. str.append_string(col2.out)
  44. iup_open.set_attribute(Current, "SELECTIONPOS", str)
  45. end
  46. get_selection_pos: TUPLE[INTEGER, INTEGER]
  47. -- (non inheritable): Same as SELECTION but using a zero based character
  48. -- index. Returns "0, 0" if there is no selection.
  49. local
  50. str: STRING
  51. do
  52. str := iup_open.get_attribute(Current, "SELECTIONPOS")
  53. if not str.is_empty then
  54. Result := components_of(str, ':')
  55. else
  56. Result := [0, 0]
  57. end
  58. end
  59. end
  60. -- The MIT License (MIT)
  61. -- Copyright (c) 2016, 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.