iup_zbox.e 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. class IUP_ZBOX
  2. -- Creates a void container for composing elements in hidden layers with only
  3. -- one layer visible. It is a box that piles up the children it contains,
  4. -- only the one child is visible.
  5. --
  6. -- It does not have a native representation.
  7. --
  8. -- Zbox works by changing the VISIBLE attribute of its children, so if any of
  9. -- the grand children has its VISIBLE attribute directly defined then Zbox
  10. -- will NOT change its state.
  11. --
  12. -- IMPORTANT: Each element must have a name defined by "set_widget_name".
  13. inherit
  14. IUP_CONTAINER
  15. IUP_WIDGET_CUSTOM_ATTRIBUTES
  16. IUP_WIDGET_EXPAND
  17. IUP_WIDGET_SIZE
  18. IUP_WIDGET_RASTERSIZE
  19. IUP_WIDGET_USERSIZE
  20. IUP_WIDGET_WID
  21. IUP_WIDGET_FONT
  22. IUP_WIDGET_CLIENTSIZE
  23. IUP_WIDGET_CLIENTOFFSET
  24. IUP_WIDGET_POSITION
  25. IUP_WIDGET_MAXMIN_SIZE
  26. IUP_WIDGET_CHILD
  27. IUP_WIDGET_NAME
  28. IUP_WIDGET_CHILDSIZEALL
  29. create {ANY}
  30. zbox_empty,
  31. zbox
  32. feature {ANY}
  33. zbox_empty
  34. -- Create an empty zbox
  35. local
  36. p, a_zbox: POINTER
  37. do
  38. a_zbox := int_zbox_empty (p)
  39. set_widget(a_zbox)
  40. end
  41. zbox (col: ARRAY[IUP_WIDGET])
  42. -- Create a new zbox containing the list of widgets
  43. local
  44. i: INTEGER; arg: ARRAY[POINTER]; s: IUP_WIDGET; a_zbox: POINTER
  45. do
  46. i := col.count
  47. create arg.make_filled(default_pointer, 1, i + 1)
  48. i := 0
  49. across
  50. col as ic
  51. loop
  52. i := i + 1
  53. s := ic.item
  54. arg.put(s.widget, i)
  55. end
  56. a_zbox := int_zbox (get_pointer(arg.to_c))
  57. set_widget(a_zbox)
  58. end
  59. -- Attributes
  60. set_alignment (value: STRING)
  61. -- (non inheritable): Defines the alignment of the visible child. Possible
  62. -- values: "NORTH", "SOUTH", "WEST", "EAST", "NE", "SE", "NW", "SW",
  63. -- "ACENTER". Default: "NW".
  64. require
  65. is_valid: is_valid_alignment(value)
  66. do
  67. iup_open.set_attribute(Current, "ALIGNMENT", value)
  68. end
  69. get_alignment: STRING
  70. -- Return the value of the alignment.
  71. do
  72. Result := iup_open.get_attribute(Current, "ALIGNMENT")
  73. end
  74. set_value (name: STRING)
  75. -- (non inheritable): The visible child accessed by its name. The value
  76. -- passed must be the name of one of the children contained in the zbox.
  77. -- Use set_widget_name to associate a child to a name. When the
  78. -- value is changed the selected child is made visible and all other
  79. -- children are made invisible, regardless their previous visible state.
  80. do
  81. iup_open.set_attribute(Current, "VALUE", name)
  82. end
  83. get_value: STRING
  84. -- Return the name of the visible child.
  85. do
  86. Result := iup_open.get_attribute(Current, "VALUE")
  87. end
  88. set_value_widget (wgt: IUP_WIDGET)
  89. -- (non inheritable): The visible child accessed by its handle. The
  90. -- value passed must be the handle of a child contained in the zbox.
  91. -- When the zbox is created, the first element inserted is set as the
  92. -- visible child.
  93. do
  94. iup_open.set_attribute_widget(Current, "VALUE_HANDLE", wgt)
  95. end
  96. get_value_widget: IUP_WIDGET
  97. -- Return the IUP_WIDGET that is visible.
  98. do
  99. Result := iup_open.get_attribute_widget(Current, "VALUE_HANDLE")
  100. end
  101. set_value_position (pos: INTEGER)
  102. -- (non inheritable): The visible child accessed by its position. The
  103. -- value passed must be the index of a child contained in the zbox,
  104. -- starting at 0. When the zbox is created, the first element inserted
  105. -- is set as the visible child.
  106. require
  107. pos >= 0
  108. do
  109. iup_open.set_attribute(Current, "VALUEPOS", pos.out)
  110. end
  111. get_value_position: INTEGER
  112. -- Return the position of the visible child.
  113. local
  114. str: STRING
  115. do
  116. str := iup_open.get_attribute(Current, "VALUEPOS")
  117. Result := str.to_integer
  118. end
  119. -- Validations
  120. is_valid_alignment (value: STRING): BOOLEAN
  121. do
  122. if value.is_equal("NORTH") or
  123. value.is_equal("SOUTH") or
  124. value.is_equal("WEST") or
  125. value.is_equal("EAST") or
  126. value.is_equal("NE") or
  127. value.is_equal("SE") or
  128. value.is_equal("NW") or
  129. value.is_equal("SW") or
  130. value.is_equal("ACENTER") then
  131. Result := True
  132. else
  133. Result := False
  134. end
  135. end
  136. feature {NONE}
  137. -- Internals
  138. int_zbox_empty (arguments: POINTER): POINTER
  139. external
  140. "C inline use %"eiffel-iup.h%""
  141. alias
  142. "return IupZbox ($arguments);"
  143. end
  144. int_zbox (arguments: POINTER): POINTER
  145. external
  146. "C inline use %"eiffel-iup.h%""
  147. alias
  148. "return IupZboxv ($arguments);"
  149. end
  150. end -- class IUP_ZBOX
  151. -- The MIT License (MIT)
  152. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  153. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  154. -- of this software and associated documentation files (the "Software"), to deal
  155. -- in the Software without restriction, including without limitation the rights
  156. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  157. -- copies of the Software, and to permit persons to whom the Software is
  158. -- furnished to do so, subject to the following conditions:
  159. --
  160. -- The above copyright notice and this permission notice shall be included in
  161. -- all copies or substantial portions of the Software.
  162. --
  163. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  164. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  165. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  166. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  167. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  168. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  169. -- SOFTWARE.