iup_submenu.e 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. class IUP_SUBMENU
  2. -- Creates a menu item that, when selected, opens another menu.
  3. -- In Motif and GTK, the text font will be affected by the dialog font when the
  4. -- menu is mapped.
  5. inherit
  6. IUP_MENU_ELEMENT
  7. redefine
  8. execute_map,
  9. execute_unmap,
  10. execute_destroy,
  11. execute_highlight
  12. end
  13. IUP_WIDGET_TITLE
  14. IUP_WIDGET_ACTIVE
  15. IUP_WIDGET_NAME
  16. create {ANY}
  17. submenu
  18. feature {ANY}
  19. submenu (title: STRING; menu: IUP_MENU)
  20. -- A new submenu.
  21. -- title: String containing the text to be shown on the item. It can be
  22. -- Void.
  23. -- menu: child menu identifier.
  24. local
  25. a_submenu, a: POINTER
  26. do
  27. if title /= Void then
  28. a := get_pointer(title.to_c)
  29. end
  30. a_submenu := int_submenu(a, menu.widget)
  31. set_widget(a_submenu)
  32. end
  33. -- Attributes
  34. set_image (name: STRING)
  35. -- [Windows and GTK Only] (non inheritable): Image name of the submenu
  36. -- image. In Windows, an item in a menu bar cannot have a check mark.
  37. -- Ignored if submenu in a menu bar. A recommended size would be 16x16 to
  38. -- fit the image in the menu item. In Windows, if larger than the check
  39. -- mark area it will be cropped.
  40. do
  41. iup_open.set_attribute(Current, "IMAGE", name)
  42. end
  43. -- Callbacks
  44. -- Common
  45. set_cb_map (act: detachable FUNCTION[TUPLE[IUP_SUBMENU], STRING])
  46. -- Called right after an element is mapped and its attributes updated.
  47. local
  48. operation: INTEGER
  49. do
  50. cb_map := act
  51. if cb_map /= Void then
  52. operation := 1
  53. else
  54. operation := 0
  55. end
  56. iup_open.set_callback (Current, "MAP_CB", "NONEEDED", operation)
  57. end
  58. set_cb_unmap (act: detachable FUNCTION[TUPLE[IUP_SUBMENU], STRING])
  59. -- Called right before an element is unmapped.
  60. local
  61. operation: INTEGER
  62. do
  63. cb_unmap := act
  64. if cb_unmap /= Void then
  65. operation := 1
  66. else
  67. operation := 0
  68. end
  69. iup_open.set_callback (Current, "UNMAP_CB", "NONEEDED", operation)
  70. end
  71. set_cb_destroy (act: detachable FUNCTION[TUPLE[IUP_SUBMENU], STRING])
  72. -- Called right before an element is destroyed.
  73. local
  74. operation: INTEGER
  75. do
  76. cb_destroy := act
  77. if cb_destroy /= Void then
  78. operation := 1
  79. else
  80. operation := 0
  81. end
  82. iup_open.set_callback (Current, "DESTROY_CB", "NONEEDED", operation)
  83. end
  84. -- Extra
  85. set_cb_highlight (act: detachable FUNCTION[TUPLE[IUP_SUBMENU], STRING])
  86. -- Action generated when the item is highlighted.
  87. local
  88. operation: INTEGER
  89. do
  90. cb_highlight := act
  91. if cb_highlight /= Void then
  92. operation := 1
  93. else
  94. operation := 0
  95. end
  96. iup_open.set_callback (Current, "HIGHLIGHT_CB", "NONEEDED", operation)
  97. end
  98. feature {ANY}
  99. -- Common callbacks
  100. execute_map: STRING
  101. do
  102. if attached cb_map as int_cb then
  103. Result := int_cb.item([Current])
  104. else
  105. Result := "IUP_DEFAULT"
  106. end
  107. end
  108. execute_unmap: STRING
  109. do
  110. if attached cb_unmap as int_cb then
  111. Result := int_cb.item([Current])
  112. else
  113. Result := "IUP_DEFAULT"
  114. end
  115. end
  116. execute_destroy: STRING
  117. do
  118. if attached cb_destroy as int_cb then
  119. Result := int_cb.item([Current])
  120. else
  121. Result := "IUP_DEFAULT"
  122. end
  123. end
  124. -- Extra
  125. execute_highlight: STRING
  126. do
  127. if attached cb_highlight as int_cb then
  128. Result := int_cb.item([Current])
  129. else
  130. Result := "IUP_DEFAULT"
  131. end
  132. end
  133. feature {NONE}
  134. -- For callbacks
  135. cb_map: detachable FUNCTION[TUPLE[IUP_SUBMENU], STRING]
  136. cb_unmap: detachable FUNCTION[TUPLE[IUP_SUBMENU], STRING]
  137. cb_destroy: detachable FUNCTION[TUPLE[IUP_SUBMENU], STRING]
  138. cb_highlight: detachable FUNCTION[TUPLE[IUP_SUBMENU], STRING]
  139. -- Internals
  140. int_submenu(title, menu: POINTER): POINTER
  141. external
  142. "C inline use %"eiffel-iup.h%""
  143. alias
  144. "return IupSubmenu ($title, $menu);"
  145. end
  146. end
  147. -- The MIT License (MIT)
  148. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  149. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  150. -- of this software and associated documentation files (the "Software"), to deal
  151. -- in the Software without restriction, including without limitation the rights
  152. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  153. -- copies of the Software, and to permit persons to whom the Software is
  154. -- furnished to do so, subject to the following conditions:
  155. --
  156. -- The above copyright notice and this permission notice shall be included in
  157. -- all copies or substantial portions of the Software.
  158. --
  159. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  160. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  161. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  162. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  163. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  164. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  165. -- SOFTWARE.