iup_link.e 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. class IUP_LINK
  2. -- Creates a label that displays an underlined clickable text. It inherits from
  3. -- IUP_LABEL. When the cursor is over the text, it is changed to the HAND
  4. -- cursor. By default the text color (fore ground color) is the global
  5. -- attribute LINKFGCOLOR.
  6. --
  7. -- If the callback is not defined the iup_help function is called with the given
  8. -- URL.
  9. --
  10. -- The IUP_LABEL callbacks BUTTON_CB, ENTERWINDOW_CB and LEAVEWINDOW_CB are
  11. -- used internally.
  12. inherit
  13. IUP_LABEL
  14. redefine
  15. execute_click
  16. end
  17. create {ANY}
  18. link
  19. feature {ANY}
  20. link (url, title: STRING)
  21. -- Make a link widget.
  22. --
  23. -- url: the destination address of the link. Can be any text. If IupHelp
  24. -- is used should be a valid URL. It can be Void. It will set the URL
  25. -- attribute.
  26. -- title: Text to be shown on the link. It can be Void. It will set the
  27. -- TITLE attribute.
  28. local
  29. a_link: POINTER
  30. do
  31. a_link := int_link (get_pointer(url.to_c), get_pointer(title.to_c))
  32. set_widget(a_link)
  33. end
  34. -- Attributes
  35. set_url (state: BOOLEAN)
  36. -- If set to "False" disables the link. The default value is "True".
  37. do
  38. iup_open.set_attribute(Current, "URL", boolean_to_yesno(state))
  39. end
  40. -- Callbacks
  41. set_cb_click (act: detachable FUNCTION[TUPLE[IUP_LINK, STRING], STRING])
  42. -- Action generated when the link is activated.
  43. -- ih: identifier of the element that activated the event.
  44. -- url: the destination address of the link.
  45. --
  46. -- Returns: IUP_CLOSE will be processed. If returns IUP_DEFAULT or it is
  47. -- not defined, the iup_help function will be called.
  48. local
  49. operation: INTEGER
  50. do
  51. cb_click := act
  52. if cb_click /= Void then
  53. operation := 1
  54. else
  55. operation := 0
  56. end
  57. iup_open.set_callback (Current, "ACTION", "Fns", operation)
  58. end
  59. feature {IUP}
  60. execute_click (url: STRING): STRING
  61. do
  62. if attached cb_click as int_cb then
  63. Result := int_cb.item([Current, url])
  64. else
  65. Result := "IUP_DEFAULT"
  66. end
  67. end
  68. feature {NONE}
  69. -- For callback
  70. cb_click: detachable FUNCTION[TUPLE[IUP_LINK, STRING], STRING]
  71. -- Internals
  72. int_link (url, title: POINTER): POINTER
  73. external
  74. "C inline use %"eiffel-iup.h%""
  75. alias
  76. "return IupLink ($url, $title);"
  77. end
  78. end
  79. -- The MIT License (MIT)
  80. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  81. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  82. -- of this software and associated documentation files (the "Software"), to deal
  83. -- in the Software without restriction, including without limitation the rights
  84. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  85. -- copies of the Software, and to permit persons to whom the Software is
  86. -- furnished to do so, subject to the following conditions:
  87. --
  88. -- The above copyright notice and this permission notice shall be included in
  89. -- all copies or substantial portions of the Software.
  90. --
  91. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  92. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  93. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  94. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  95. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  96. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  97. -- SOFTWARE.