iup_split.e 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. class IUP_SPLIT
  2. -- Creates a void container that split its client area in two. Allows the
  3. -- provided controls to be enclosed in a box that allows expanding and
  4. -- contracting the element size in one direction, but when one is expanded the
  5. -- other is contracted.
  6. --
  7. -- It does not have a native representation, but it contains also a IUP_CANVAS
  8. -- to implement the bar handler.
  9. inherit
  10. IUP_CONTAINER
  11. redefine
  12. execute_valuechanged
  13. end
  14. IUP_WIDGET_EXPAND
  15. IUP_WIDGET_WID
  16. IUP_WIDGET_FONT
  17. IUP_WIDGET_SIZE
  18. IUP_WIDGET_RASTERSIZE
  19. IUP_WIDGET_USERSIZE
  20. IUP_WIDGET_CLIENTSIZE
  21. IUP_WIDGET_CLIENTOFFSET
  22. IUP_WIDGET_POSITION
  23. IUP_WIDGET_MAXMIN_SIZE
  24. IUP_WIDGET_CHILD
  25. IUP_WIDGET_NAME
  26. IUP_WIDGET_CUSTOM_ATTRIBUTES
  27. create {ANY}
  28. split_empty,
  29. split
  30. feature {ANY}
  31. split_empty
  32. -- Create an empty sbox.
  33. local
  34. p, a_split: POINTER
  35. do
  36. a_split := int_split (p, p)
  37. set_widget(a_split)
  38. end
  39. split (child1, child2: IUP_WIDGET)
  40. -- Create a new split containing the widgets.
  41. local
  42. a_split: POINTER
  43. do
  44. a_split := int_split (child1.widget, child2.widget)
  45. set_widget(a_split)
  46. end
  47. -- Attributes
  48. set_auto_hide (state: BOOLEAN)
  49. -- (non inheritable): if the child client area is smaller than the bar
  50. -- size, then automatically hide the child. Default: False.
  51. do
  52. iup_open.set_attribute(Current, "AUTOHIDE", boolean_to_yesno(state))
  53. end
  54. is_auto_hide: BOOLEAN
  55. -- Return the state of AUTOHIDE.
  56. local
  57. str: STRING
  58. do
  59. str := iup_open.get_attribute(Current, "AUTOHIDE")
  60. Result := yesno_to_boolean(str)
  61. end
  62. set_bar_size (size: INTEGER)
  63. -- (non inheritable): controls the size of the bar handler. Default: 5.
  64. require
  65. size >= 0
  66. do
  67. iup_open.set_attribute(Current, "BARSIZE", size.out)
  68. end
  69. get_bar_size: INTEGER
  70. -- Return the size of the bar.
  71. local
  72. str: STRING
  73. do
  74. str := iup_open.get_attribute(Current, "BARSIZE")
  75. Result := str.to_integer
  76. end
  77. set_rgb_color (red, green, blue: INTEGER)
  78. -- Changes the color of the bar grip affordance. The value should be given
  79. -- in "R G B" color style. Default: "192 192 192".
  80. do
  81. iup_open.set_attribute(Current, "COLOR", rgb_to_string(red, green, blue))
  82. end
  83. get_rgb_color: TUPLE[INTEGER, INTEGER, INTEGER]
  84. -- Return the RGB values of the bar grip color.
  85. do
  86. Result := iup_open.get_rgb(Current, "COLOR")
  87. end
  88. set_horizontal_orientation
  89. -- (creation only): Indicates an horizontal orientation of the bar
  90. -- handler. The direction of the resize is perpendicular to the
  91. -- orientation.
  92. do
  93. iup_open.set_attribute(Current, "ORIENTATION", "HORIZONTAL")
  94. end
  95. set_vertical_orientation
  96. -- (creation only): Indicates the orientation of the bar handler. The
  97. -- direction of the resize is perpendicular to the orientation. This is
  98. -- the default value.
  99. do
  100. iup_open.set_attribute(Current, "ORIENTATION", "VERTICAL")
  101. end
  102. is_horizontal: BOOLEAN
  103. local
  104. str: STRING
  105. do
  106. str := iup_open.get_attribute(Current, "ORIENTATION")
  107. if str.is_equal("HORIZONTAL") then
  108. Result := True
  109. else
  110. Result := False
  111. end
  112. end
  113. is_vertical: BOOLEAN
  114. local
  115. str: STRING
  116. do
  117. str := iup_open.get_attribute(Current, "ORIENTATION")
  118. if str.is_equal("VERTICAL") then
  119. Result := True
  120. else
  121. Result := False
  122. end
  123. end
  124. set_layout_drag (state: BOOLEAN)
  125. -- (non inheritable): When the bar is moved automatically update the
  126. -- children layout. Default: True. If set to False then the layout will be
  127. -- updated only when the mouse drag is released.
  128. do
  129. iup_open.set_attribute(Current, "LAYOUTDRAG", boolean_to_yesno(state))
  130. end
  131. is_layout_drag: BOOLEAN
  132. -- Return the state of LAYOUTDRAG.
  133. local
  134. str: STRING
  135. do
  136. str := iup_open.get_attribute(Current, "LAYOUTDRAG")
  137. Result := yesno_to_boolean(str)
  138. end
  139. set_min_and_max (min: INTEGER; max: INTEGER)
  140. -- (non inheritable): sets minimum and maximum crop values for VALUE. The
  141. -- min value can not be less than 0, and the max value can not be larger
  142. -- than 1000. This will constrain the interactive change of the bar
  143. -- handler. Default: "0:1000".
  144. require
  145. non_negative: min >= 0
  146. max >= 0
  147. less: min <= 1000
  148. max <= 1000
  149. min <= max
  150. local
  151. size: STRING
  152. do
  153. size := min.out
  154. size.append_string(":")
  155. size.append_string(max.out)
  156. iup_open.set_attribute(Current, "MINMAX", size)
  157. end
  158. get_min_and_max: TUPLE[INTEGER, INTEGER]
  159. -- Return the minmax size.
  160. local
  161. size: STRING
  162. do
  163. size := iup_open.get_attribute(Current, "MINMAX")
  164. Result := components_of_size(size)
  165. end
  166. set_show_grip (value: STRING)
  167. -- (non inheritable): Shows the bar grip affordance. Default: YES. When
  168. -- set to NO, the BARSIZE is set to 3. When set to NO if COLOR is defined
  169. -- then it is used to fill the grip area (since 3.11.1). If set to
  170. -- "LINES" then instead of the traditional grip appearance, it will be
  171. -- two parallel lines
  172. require
  173. is_valid_showgrip(value)
  174. do
  175. iup_open.set_attribute(Current, "SHOWGRIP", value)
  176. end
  177. get_show_grip: STRING
  178. -- Return the value of SHOWGRIP.
  179. do
  180. Result := iup_open.get_attribute(Current, "SHOWGRIP")
  181. end
  182. set_value (value: INTEGER)
  183. -- (non inheritable): The proportion of the left or top (child1) client
  184. -- area relative to the full available area. It is an integer between 0
  185. -- and 1000. If not defined, the Native size of the two children
  186. -- will define its initial size.
  187. require
  188. value >= 0
  189. value <= 1000
  190. do
  191. iup_open.set_attribute(Current, "VALUE", value.out)
  192. end
  193. get_value: STRING
  194. -- Return the value of VALUE.
  195. do
  196. Result := iup_open.get_attribute(Current, "VALUE")
  197. end
  198. -- Callback
  199. set_cb_value_changed (act: detachable FUNCTION[TUPLE[IUP_SPLIT], STRING])
  200. local
  201. operation: INTEGER
  202. do
  203. cb_valuechanged := act
  204. if cb_valuechanged /= Void then
  205. operation := 1
  206. else
  207. operation := 0
  208. end
  209. iup_open.set_callback (Current, "VALUECHANGED_CB", "NONEEDED", operation)
  210. end
  211. -- Validations
  212. is_valid_showgrip (value: STRING): BOOLEAN
  213. do
  214. if is_yes_no(value) or
  215. value.is_equal("LINES") then
  216. Result := True
  217. else
  218. Result := False
  219. end
  220. end
  221. feature {IUP} -- Internal handle of callbacks
  222. execute_valuechanged: STRING
  223. do
  224. if attached cb_valuechanged as int_cb then
  225. Result := int_cb.item([Current])
  226. else
  227. Result := "IUP_DEFAULT"
  228. end
  229. end
  230. feature {NONE}
  231. -- For callback
  232. cb_valuechanged: detachable FUNCTION[TUPLE[IUP_SPLIT], STRING]
  233. -- Internal
  234. int_split (child1, child2: POINTER): POINTER
  235. external
  236. "C inline use %"eiffel-iup.h%""
  237. alias
  238. "return IupSplit ($child1, $child2);"
  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.