iup_get_text.e 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. class IUP_GET_TEXT
  2. -- Shows a modal dialog to edit a multiline text. The text parameter must be
  3. -- large enough to contain the user input. The returned string is limited to
  4. -- maxsize characters.
  5. --
  6. -- The dialog uses a global attribute called "PARENTDIALOG" as the parent
  7. -- dialog if it is defined. It also uses a global attribute called "ICON" as
  8. -- the dialog icon if it is defined.
  9. inherit
  10. IUP_WIDGET
  11. create {ANY}
  12. get_text_with_initial
  13. feature {ANY}
  14. get_text_with_initial (title, text: STRING; maxsize: INTEGER)
  15. -- Create a message box:
  16. --
  17. -- title: The dialog title.
  18. -- text: initial value of the text. It must have room for the edited
  19. -- string with at least maxsize lenght.
  20. -- maxsize: the max size lenght.
  21. do
  22. create message.make(maxsize)
  23. message.append_string(text)
  24. ttl := title
  25. maxs := maxsize
  26. end
  27. launch: TUPLE[INTEGER, STRING]
  28. -- Show the dialog. Return a tuple with an integer, a non zero value if
  29. -- the OK button is pressed, and the edited string.
  30. local
  31. ms: STRING
  32. p: POINTER
  33. i: INTEGER
  34. do
  35. p := get_pointer(message.to_c)
  36. i := int_get_text (get_pointer(ttl.to_c), p, maxs)
  37. create ms.make_from_c(p)
  38. Result := [i, ms]
  39. end
  40. feature {NONE}
  41. ttl, message: STRING
  42. maxs: INTEGER
  43. -- Internal
  44. int_get_text (title, text: POINTER; ms: INTEGER): INTEGER
  45. external
  46. "C inline use %"eiffel-iup.h%""
  47. alias
  48. "return IupGetText ($title, $text, $ms);"
  49. end
  50. end -- end IUP_GET_TEXT
  51. -- The MIT License (MIT)
  52. -- Copyright (c) 2016, 2017, 2019 by German A. Arias
  53. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  54. -- of this software and associated documentation files (the "Software"), to deal
  55. -- in the Software without restriction, including without limitation the rights
  56. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  57. -- copies of the Software, and to permit persons to whom the Software is
  58. -- furnished to do so, subject to the following conditions:
  59. --
  60. -- The above copyright notice and this permission notice shall be included in
  61. -- all copies or substantial portions of the Software.
  62. --
  63. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  64. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  65. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  66. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  67. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  68. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  69. -- SOFTWARE.