iup_widget_text_selection.e 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. deferred class IUP_WIDGET_TEXT_SELECTION
  2. -- Commands to handle the attributes related with selection.
  3. inherit
  4. IUP_WIDGET_INTERNALS
  5. insert
  6. IUP_INTERFACE
  7. feature {ANY}
  8. set_selection (col1, col2: INTEGER)
  9. -- Selection interval in characters. Where col1 and col2 are integer
  10. -- numbers corresponding to the selection's interval. col2 correspond to
  11. -- the character after the last selected character.
  12. -- The first position is "1".
  13. -- In Windows, when changing the selection the caret position is also
  14. -- changed.
  15. local
  16. str: STRING
  17. do
  18. str := col1.to_string
  19. str.append_string(":")
  20. str.append_string(col2.to_string)
  21. iup_open.set_attribute(Current, "SELECTION", str)
  22. end
  23. get_selection: TUPLE[INTEGER, INTEGER]
  24. -- Selection interval in characters. Returns "0, 0" if there is no
  25. -- selection.
  26. local
  27. str: STRING
  28. tup: TUPLE[INTEGER, INTEGER]
  29. do
  30. str := iup_open.get_attribute(Current, "SELECTION")
  31. if not str.is_empty then
  32. Result := components_of(str, ':')
  33. else
  34. Result := [0.to_integer_32, 0.to_integer_32]
  35. end
  36. end
  37. set_selection_pos (col1, col2: INTEGER)
  38. -- (non inheritable): Same as SELECTION but using a zero based character
  39. -- index. Useful for indexing the VALUE string. See the Notes above if
  40. -- using UTF-8 strings in GTK.
  41. local
  42. str: STRING
  43. do
  44. create str.copy(col1.to_string)
  45. str.append_string(":")
  46. str.append_string(col2.to_string)
  47. iup_open.set_attribute(Current, "SELECTIONPOS", str)
  48. end
  49. get_selection_pos: TUPLE[INTEGER, INTEGER]
  50. -- (non inheritable): Same as SELECTION but using a zero based character
  51. -- index. Returns "0, 0" if there is no selection.
  52. local
  53. str: STRING
  54. tup: TUPLE[INTEGER, INTEGER]
  55. do
  56. str := iup_open.get_attribute(Current, "SELECTIONPOS")
  57. if not str.is_empty then
  58. Result := components_of(str, ':')
  59. else
  60. Result := [0.to_integer_32, 0.to_integer_32]
  61. end
  62. end
  63. end
  64. -- The MIT License (MIT)
  65. -- Copyright (c) 2016, 2019 by German A. Arias
  66. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  67. -- of this software and associated documentation files (the "Software"), to deal
  68. -- in the Software without restriction, including without limitation the rights
  69. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  70. -- copies of the Software, and to permit persons to whom the Software is
  71. -- furnished to do so, subject to the following conditions:
  72. --
  73. -- The above copyright notice and this permission notice shall be included in
  74. -- all copies or substantial portions of the Software.
  75. --
  76. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  77. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  78. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  79. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  80. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  81. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  82. -- SOFTWARE.