iup_zbox.e 5.6 KB

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