iup_frame.e 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. class IUP_FRAME
  2. -- Creates a native container, which draws a frame with a title around
  3. -- its child.
  4. inherit
  5. IUP_CONTAINER
  6. redefine
  7. execute_map,
  8. execute_unmap,
  9. execute_destroy,
  10. execute_focus
  11. end
  12. IUP_WIDGET_BGCOLOR
  13. IUP_WIDGET_FGCOLOR
  14. IUP_WIDGET_EXPAND
  15. IUP_WIDGET_TITLE
  16. IUP_WIDGET_ACTIVE
  17. IUP_WIDGET_FONT
  18. IUP_WIDGET_SCREENPOSITION
  19. IUP_WIDGET_POSITION
  20. IUP_WIDGET_CLIENTSIZE
  21. IUP_WIDGET_CLIENTOFFSET
  22. IUP_WIDGET_MAXMIN_SIZE
  23. IUP_WIDGET_SIZE
  24. IUP_WIDGET_RASTERSIZE
  25. IUP_WIDGET_USERSIZE
  26. IUP_WIDGET_ZORDER
  27. IUP_WIDGET_VISIBLE
  28. IUP_WIDGET_CHILD
  29. IUP_WIDGET_NAME
  30. IUP_WIDGET_CUSTOM_ATTRIBUTES
  31. create {ANY}
  32. frame_empty,
  33. frame
  34. feature {ANY}
  35. frame_empty
  36. -- Create an empty frame
  37. local
  38. p, a_frame: POINTER
  39. do
  40. a_frame := int_frame (p)
  41. set_widget(a_frame)
  42. end
  43. frame (child: IUP_WIDGET)
  44. -- Create a new frame containing the widget.
  45. local
  46. a_frame: POINTER
  47. do
  48. a_frame := int_frame (child.widget)
  49. set_widget(a_frame)
  50. end
  51. -- Attributes
  52. set_childoffset (horizontal, vertical: INTEGER)
  53. require
  54. horizontal >= 0
  55. vertical >= 0
  56. local
  57. offset: STRING
  58. do
  59. offset := horizontal.out
  60. offset.append_string("x")
  61. offset.append_string(vertical.out)
  62. iup_open.set_attribute(Current, "CHILDOFFSET", offset)
  63. end
  64. get_childoffset: TUPLE[INTEGER, INTEGER]
  65. -- Return the offset of the child.
  66. local
  67. offset: STRING
  68. do
  69. offset := iup_open.get_attribute(Current, "CHILDOFFSET")
  70. Result := components_of_size(offset)
  71. end
  72. set_sunken (state: BOOLEAN)
  73. -- When not using a title, the frame line defines a sunken area (lowered
  74. -- area). Default: False.
  75. do
  76. iup_open.set_attribute(Current, "SUNKEN", boolean_to_yesno(state))
  77. end
  78. -- Callbacks
  79. set_cb_map (act: detachable FUNCTION[TUPLE[IUP_FRAME], STRING])
  80. -- Called right after an element is mapped and its attributes updated.
  81. local
  82. operation: INTEGER
  83. do
  84. cb_map := act
  85. if cb_map /= Void then
  86. operation := 1
  87. else
  88. operation := 0
  89. end
  90. iup_open.set_callback (Current, "MAP_CB", "NONEEDED", operation)
  91. end
  92. set_cb_unmap (act: detachable FUNCTION[TUPLE[IUP_FRAME], STRING])
  93. -- Called right before an element is unmapped.
  94. local
  95. operation: INTEGER
  96. do
  97. cb_unmap := act
  98. if cb_unmap /= Void then
  99. operation := 1
  100. else
  101. operation := 0
  102. end
  103. iup_open.set_callback (Current, "UNMAP_CB", "NONEEDED", operation)
  104. end
  105. set_cb_destroy (act: detachable FUNCTION[TUPLE[IUP_FRAME], STRING])
  106. -- Called right before an element is destroyed.
  107. local
  108. operation: INTEGER
  109. do
  110. cb_destroy := act
  111. if cb_destroy /= Void then
  112. operation := 1
  113. else
  114. operation := 0
  115. end
  116. iup_open.set_callback (Current, "DESTROY_CB", "NONEEDED", operation)
  117. end
  118. set_cb_focus (act: detachable FUNCTION[TUPLE[IUP_FRAME, INTEGER], STRING])
  119. -- Called when a child of the container gets or looses the focus. It is
  120. -- called only if PROPAGATEFOCUS is defined in the child.
  121. local
  122. operation: INTEGER
  123. do
  124. cb_focus := act
  125. if cb_focus /= Void then
  126. operation := 1
  127. else
  128. operation := 0
  129. end
  130. iup_open.set_callback (Current, "FOCUS_CB", "NONEEDED", operation)
  131. end
  132. feature {ANY}
  133. execute_map: STRING
  134. do
  135. if attached cb_map as int_cb then
  136. Result := int_cb.item([Current])
  137. else
  138. Result := "IUP_DEFAULT"
  139. end
  140. end
  141. execute_unmap: STRING
  142. do
  143. if attached cb_unmap as int_cb then
  144. Result := int_cb.item([Current])
  145. else
  146. Result := "IUP_DEFAULT"
  147. end
  148. end
  149. execute_destroy: STRING
  150. do
  151. if attached cb_destroy as int_cb then
  152. Result := int_cb.item([Current])
  153. else
  154. Result := "IUP_DEFAULT"
  155. end
  156. end
  157. execute_focus (focus: INTEGER): STRING
  158. do
  159. if attached cb_focus as int_cb then
  160. Result := int_cb.item([Current, focus])
  161. else
  162. Result := "IUP_DEFAULT"
  163. end
  164. end
  165. feature {NONE}
  166. -- For callbacks
  167. cb_map: detachable FUNCTION[TUPLE[IUP_FRAME], STRING]
  168. cb_unmap: detachable FUNCTION[TUPLE[IUP_FRAME], STRING]
  169. cb_destroy: detachable FUNCTION[TUPLE[IUP_FRAME], STRING]
  170. cb_focus: detachable FUNCTION[TUPLE[IUP_FRAME, INTEGER], STRING]
  171. -- Internals
  172. int_frame (child: POINTER): POINTER
  173. external
  174. "C inline use %"eiffel-iup.h%""
  175. alias
  176. "return IupFrame ($child);"
  177. end
  178. end
  179. -- The MIT License (MIT)
  180. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  181. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  182. -- of this software and associated documentation files (the "Software"), to deal
  183. -- in the Software without restriction, including without limitation the rights
  184. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  185. -- copies of the Software, and to permit persons to whom the Software is
  186. -- furnished to do so, subject to the following conditions:
  187. --
  188. -- The above copyright notice and this permission notice shall be included in
  189. -- all copies or substantial portions of the Software.
  190. --
  191. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  192. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  193. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  194. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  195. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  196. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  197. -- SOFTWARE.