iup_get_text.e 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 := message.to_external
  36. i := int_get_text (ttl.to_external, p, maxs)
  37. create ms.from_external_copy(p)
  38. Result := [i, ms]
  39. end
  40. feature {}
  41. ttl, message: STRING
  42. maxs: INTEGER
  43. -- Internal
  44. int_get_text (title, text: POINTER; ms: INTEGER): INTEGER
  45. external "plug_in"
  46. alias "{
  47. location: "${sys}/plugins"
  48. module_name: "iup"
  49. feature_name: "IupGetText"
  50. }"
  51. end
  52. end -- end IUP_GET_TEXT
  53. -- The MIT License (MIT)
  54. -- Copyright (c) 2016, 2017 by German A. Arias
  55. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  56. -- of this software and associated documentation files (the "Software"), to deal
  57. -- in the Software without restriction, including without limitation the rights
  58. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  59. -- copies of the Software, and to permit persons to whom the Software is
  60. -- furnished to do so, subject to the following conditions:
  61. --
  62. -- The above copyright notice and this permission notice shall be included in
  63. -- all copies or substantial portions of the Software.
  64. --
  65. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  66. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  67. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  68. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  69. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  70. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  71. -- SOFTWARE.