iup_detach_box.e 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. class IUP_DETACH_BOX
  2. -- Creates a detachable void container.
  3. --
  4. -- Dragging and dropping this element, it creates a new dialog composed by
  5. -- its child or elements arranged in it (for example, a child like IUP_VBOX or
  6. -- IUP_HBOX). During the drag, the ESC key can be pressed to cancel the action.
  7. inherit
  8. IUP_CONTAINER
  9. redefine
  10. execute_detached,
  11. execute_restored
  12. end
  13. IUP_WIDGET_EXPAND
  14. IUP_WIDGET_WID
  15. IUP_WIDGET_FONT
  16. IUP_WIDGET_SIZE
  17. IUP_WIDGET_RASTERSIZE
  18. IUP_WIDGET_USERSIZE
  19. IUP_WIDGET_CLIENTSIZE
  20. IUP_WIDGET_CLIENTOFFSET
  21. IUP_WIDGET_POSITION
  22. IUP_WIDGET_MAXMIN_SIZE
  23. IUP_WIDGET_CHILD
  24. IUP_WIDGET_NAME
  25. IUP_WIDGET_CUSTOM_ATTRIBUTES
  26. create {ANY}
  27. detach_box_empty,
  28. detach_box
  29. feature {ANY}
  30. detach_box_empty
  31. -- Create an empty detach box.
  32. local
  33. p, a_detach_box: POINTER
  34. do
  35. a_detach_box := int_detach_box (p)
  36. set_widget(a_detach_box)
  37. end
  38. detach_box (child: IUP_WIDGET)
  39. -- Create a new detach box containing the widget.
  40. local
  41. a_detach_box: POINTER
  42. do
  43. a_detach_box := int_detach_box (child.widget)
  44. set_widget(a_detach_box)
  45. end
  46. -- Attributes
  47. set_bar_size (size: INTEGER)
  48. -- (non inheritable): controls the size of the bar handler. To
  49. -- completely hide the bar set BARSIZE to 0. Default: 10.
  50. require
  51. size >= 0
  52. do
  53. iup_open.set_attribute(Current, "BARSIZE", size.out)
  54. end
  55. get_bar_size: INTEGER
  56. -- Return the size of the bar.
  57. local
  58. str: STRING
  59. do
  60. str := iup_open.get_attribute(Current, "BARSIZE")
  61. Result := str.to_integer
  62. end
  63. set_rgb_color (red, green, blue: INTEGER)
  64. -- Changes the color of the bar grip affordance. The value should be
  65. -- given in "R G B" color style. Default: "160 160 160". When SHOWGRIP =
  66. -- NO, this attribute sets the background color of the bar handler.
  67. do
  68. iup_open.set_attribute(Current, "COLOR", rgb_to_string(red, green, blue))
  69. end
  70. get_rgb_color: TUPLE[INTEGER, INTEGER, INTEGER]
  71. -- Return the RGB values of the bar color.
  72. do
  73. Result := iup_open.get_rgb(Current, "COLOR")
  74. end
  75. set_vertical_orientation
  76. -- (creation only): Sets a vertical orientation of the bar handler. The
  77. -- direction of the resize is perpendicular to the orientation.
  78. -- This is the default value.
  79. do
  80. iup_open.set_attribute(Current, "ORIENTATION", "VERTICAL")
  81. end
  82. set_horizontal_orientation
  83. -- (creation only): Sets an horizontal orientation of the bar handler.
  84. -- The direction of the resize is perpendicular to the orientation.
  85. do
  86. iup_open.set_attribute(Current, "ORIENTATION", "HORIZONTAL")
  87. end
  88. is_vertical: BOOLEAN
  89. local
  90. str: STRING
  91. do
  92. str := iup_open.get_attribute(Current, "ORIENTATION")
  93. if str.is_equal("VERTICAL") then
  94. Result := True
  95. else
  96. Result := False
  97. end
  98. end
  99. get_old_parent_widget: IUP_WIDGET
  100. -- (read only): returns the previous parent of the detached element.
  101. -- Only valid after the element was detached.
  102. do
  103. Result := iup_open.get_attribute_widget(Current, "OLDPARENT_HANDLE")
  104. end
  105. get_old_brother_widget: IUP_WIDGET
  106. -- (read only): returns the previous reference child of the detached
  107. -- element. Only valid after the element was detached. See iup_reparent
  108. -- for a reference child definition.
  109. do
  110. Result := iup_open.get_attribute_widget(Current, "OLDBROTHER_HANDLE")
  111. end
  112. detach_widget
  113. -- (write-only): detach the box by creating a new dialog and placing the
  114. -- detachbox as the child of the new dialog. The DETACHED callback is
  115. -- called, use it to configure the new dialog. The handler is hidden, the
  116. -- USERSIZE of the detachbox is set to the CURRENTSIZE of the child, and
  117. -- the PARENTDIALOG of the new dialog is set to old dialog. To re-parent
  118. -- the child we need to map the dialog before doing it, so to force a
  119. -- dialog resize its size is reset before its is shown, to control the
  120. -- dialog size use the child size. The new dialog is show at the current
  121. -- cursor position, and the USERSIZE of the detachbox is reset.
  122. do
  123. iup_open.set_attribute_null(Current, "DETACH")
  124. end
  125. restore_widget (name: STRING)
  126. -- (write-only): restore the box to its previous place (parent and
  127. -- brother) and destroys the new dialog. Value can be the
  128. -- string "NULL" or can be the name of a new parent when the control will
  129. -- be appended. Use set_widget_name to associate an IUP_WIDGET to a
  130. -- name. The handler is shown (if restored to inside a IUP_ZBOX, the
  131. -- application must update the IUP_ZBOX child visibility manually).
  132. do
  133. if name.is_equal("NULL") then
  134. iup_open.set_attribute_null(Current, "RESTORE")
  135. else
  136. iup_open.set_attribute(Current, "RESTORE", name)
  137. end
  138. end
  139. set_restore_when_closed (state: BOOLEAN)
  140. -- Automatically restore the box to its original position when the new
  141. -- dialog is closed. Default: "False".
  142. do
  143. iup_open.set_attribute(Current, "RESTOREWHENCLOSED", boolean_to_yesno(state))
  144. end
  145. set_show_grip (state: BOOLEAN)
  146. -- (non inheritable): Shows the bar grip affordance. Default: YES. When
  147. -- set to NO, the BARSIZE is set to 5 (if greater than 5). To completely
  148. -- hide the bar set BARSIZE to 0.
  149. do
  150. iup_open.set_attribute(Current, "SHOWGRIP", boolean_to_yesno(state))
  151. end
  152. is_show_grip: BOOLEAN
  153. -- Return the state of show grip.
  154. local
  155. str: STRING
  156. do
  157. str := iup_open.get_attribute(Current, "SHOWGRIP")
  158. Result := yesno_to_boolean(str)
  159. end
  160. -- Callback
  161. set_cb_detached (act: detachable FUNCTION[TUPLE[IUP_DETACH_BOX, IUP_DIALOG, INTEGER, INTEGER], STRING])
  162. -- Callback called when the box is detached.
  163. -- ih: identifier of the element that activated the event.
  164. -- new_parent: identifier of the future parent of the box. At this point
  165. -- only the PARENTDIALOG attribute was set.
  166. -- x, y: dropped position.
  167. --
  168. -- Returns: IUP_IGNORE will be processed, in order to cancel the detach
  169. -- action.
  170. local
  171. operation: INTEGER
  172. do
  173. cb_detached := act
  174. if cb_detached /= Void then
  175. operation := 1
  176. else
  177. operation := 0
  178. end
  179. iup_open.set_callback (Current, "DETACHED_CB", "NONEEDED", operation)
  180. end
  181. set_cb_restored (act: detachable FUNCTION[TUPLE[IUP_DETACH_BOX, IUP_WIDGET, INTEGER, INTEGER], STRING])
  182. -- Callback called when the box is restored if RESTOREWHENCLOSED=Yes.
  183. --
  184. -- ih: identifier of the element that activated the event.
  185. -- old_parent: identifier of the original parent of the box.
  186. -- x, y: always 0,0.
  187. --
  188. -- Returns: IUP_IGNORE will be processed, in order to cancel the
  189. -- detach action.
  190. local
  191. operation: INTEGER
  192. do
  193. cb_restored := act
  194. if cb_restored /= Void then
  195. operation := 1
  196. else
  197. operation := 0
  198. end
  199. iup_open.set_callback (Current, "RESTORED_CB", "NONEEDED", operation)
  200. end
  201. feature {IUP}
  202. -- Callback
  203. execute_detached (new_parent: IUP_DIALOG; x, y: INTEGER): STRING
  204. do
  205. if attached cb_detached as int_cb then
  206. Result := int_cb.item([Current, new_parent, x, y])
  207. else
  208. Result := "IUP_DEFAULT"
  209. end
  210. end
  211. execute_restored (old_parent: IUP_WIDGET; x, y: INTEGER): STRING
  212. do
  213. if attached cb_restored as int_cb then
  214. Result := int_cb.item([Current, old_parent, x, y])
  215. else
  216. Result := "IUP_DEFAULT"
  217. end
  218. end
  219. feature {NONE}
  220. -- For callbacks
  221. cb_detached: detachable FUNCTION[TUPLE[IUP_DETACH_BOX, IUP_DIALOG, INTEGER, INTEGER], STRING]
  222. cb_restored: detachable FUNCTION[TUPLE[IUP_DETACH_BOX, IUP_WIDGET, INTEGER, INTEGER], STRING]
  223. -- Internals
  224. int_detach_box (child: POINTER): POINTER
  225. external
  226. "C inline use %"eiffel-iup.h%""
  227. alias
  228. "return IupDetachBox ($child);"
  229. end
  230. -- Validations
  231. is_valid_orientation (value: STRING): BOOLEAN
  232. do
  233. if value.is_equal("HORIZONTAL") or
  234. value.is_equal("VERTICAL") then
  235. Result := True
  236. else
  237. Result := False
  238. end
  239. end
  240. end
  241. -- The MIT License (MIT)
  242. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  243. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  244. -- of this software and associated documentation files (the "Software"), to deal
  245. -- in the Software without restriction, including without limitation the rights
  246. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  247. -- copies of the Software, and to permit persons to whom the Software is
  248. -- furnished to do so, subject to the following conditions:
  249. --
  250. -- The above copyright notice and this permission notice shall be included in
  251. -- all copies or substantial portions of the Software.
  252. --
  253. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  254. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  255. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  256. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  257. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  258. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  259. -- SOFTWARE.