iup_normalizer.e 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. class IUP_NORMALIZER
  2. -- Creates a void container that does not affect the dialog layout. It acts by
  3. -- normalizing all the controls in a list so their natural size becomes the
  4. -- biggest natural size amongst them. All natural widths will be set to the
  5. -- biggest width, and all natural heights will be set to the biggest height.
  6. -- The controls of the list must be inside a valid container in the
  7. -- dialog.
  8. --
  9. -- It is NOT necessary to add the normalizer to a dialog hierarchy. Every time
  10. -- the NORMALIZE attribute is set, a normalization occurs. If the normalizer is
  11. -- added to a dialog hierarchy, then whenever the Natural size is calculated a
  12. -- normalization occurs, so you should add it to the hierarchy before the
  13. -- elements you want to normalize or its normalization will be not used.
  14. --
  15. -- The elements do NOT need to be children of the same parent, do NOT need to
  16. -- be mapped, and do NOT need to be in a complete hierarchy of a dialog.
  17. --
  18. -- The elements are NOT children of the normalizer. To add or remove elements
  19. -- use the add_control and delete_control attributes.
  20. --
  21. -- Notice that the set_normalizar_group (at controls) attribute can simplify a
  22. -- lot of the process of creating a normalizer, so you do not need to list
  23. -- several elements from different parts of the dialog.
  24. --
  25. -- Has the same effect as the set_normalize_size attribute of the IUP_VBOX and
  26. -- IUP_HBOX controls, but it can be used for elements with different parents,
  27. -- it changes the User size of the elements.
  28. inherit
  29. IUP_WIDGET
  30. create {ANY}
  31. normalizer_empty,
  32. normalizer
  33. feature {ANY}
  34. normalizer_empty
  35. local
  36. a_normalizer, p: POINTER
  37. do
  38. a_normalizer := int_normalizer (p)
  39. set_widget(a_normalizer)
  40. end
  41. normalizer (list: ARRAY[IUP_WIDGET])
  42. local
  43. iterator: ITERATOR[IUP_WIDGET]; i: INTEGER;
  44. arg: NATIVE_ARRAY[POINTER]; s: IUP_WIDGET; a_normalizer: POINTER
  45. do
  46. i := list.count
  47. arg := arg.calloc(i)
  48. iterator := list.new_iterator
  49. i := 0
  50. from
  51. iterator.start
  52. until
  53. iterator.is_off
  54. loop
  55. s := iterator.item
  56. arg.put(s.widget, i)
  57. iterator.next
  58. i := i + 1
  59. end
  60. a_normalizer := int_normalizerv (arg.to_external)
  61. set_widget(a_normalizer)
  62. end
  63. -- Attributes
  64. set_normalize (value: STRING)
  65. -- (non inheritable): normalization direction. Can be HORIZONTAL,
  66. -- VERTICAL or BOTH.
  67. require
  68. is_valid_normalize(value)
  69. do
  70. iup_open.set_attribute(Current, "NORMALIZE", value)
  71. end
  72. -- Operations
  73. add_control (name: STRING)
  74. -- (non inheritable, write-only): Adds a control to the normalizer. The
  75. -- value passed must be the name of an element. Use set_attribute_handle
  76. -- to associate an element to a name.
  77. do
  78. iup_open.set_attribute(Current, "ADDCONTROL", name)
  79. end
  80. add_control_widget (wgt: IUP_WIDGET)
  81. -- (non inheritable, write-only): Adds a control to the normalizer.
  82. do
  83. iup_open.set_attribute_widget(Current, "ADDCONTROL_HANDLE", wgt)
  84. end
  85. delete_control (name: STRING)
  86. -- (non inheritable, write-only): Removes a control from the normalizer.
  87. -- The value passed must be the name of an element. Use
  88. -- set_attribute_handle to associate an element to a name.
  89. do
  90. iup_open.set_attribute(Current, "DELCONTROL", name)
  91. end
  92. delete_control_widget (wgt: IUP_WIDGET)
  93. -- (non inheritable, write-only): Removes a control from the normalizer.
  94. do
  95. iup_open.set_attribute_widget(Current, "DELCONTROL_HANDLE", wgt)
  96. end
  97. feature {}
  98. -- Internal
  99. int_normalizer (arguments: POINTER): POINTER
  100. external "plug_in"
  101. alias "{
  102. location: "${sys}/plugins"
  103. module_name: "iup"
  104. feature_name: "IupNormalizer"
  105. }"
  106. end
  107. int_normalizerv (arguments: POINTER): POINTER
  108. external "plug_in"
  109. alias "{
  110. location: "${sys}/plugins"
  111. module_name: "iup"
  112. feature_name: "IupNormalizerv"
  113. }"
  114. end
  115. -- Validations
  116. is_valid_normalize (value: STRING): BOOLEAN
  117. do
  118. if value.is_equal("HORIZONTAL") or
  119. value.is_equal("VERTICAL") or
  120. value.is_equal("BOTH") then
  121. Result := True
  122. else
  123. Result := False
  124. end
  125. end
  126. end
  127. -- The MIT License (MIT)
  128. -- Copyright (c) 2016 by German A. Arias
  129. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  130. -- of this software and associated documentation files (the "Software"), to deal
  131. -- in the Software without restriction, including without limitation the rights
  132. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  133. -- copies of the Software, and to permit persons to whom the Software is
  134. -- furnished to do so, subject to the following conditions:
  135. --
  136. -- The above copyright notice and this permission notice shall be included in
  137. -- all copies or substantial portions of the Software.
  138. --
  139. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  140. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  141. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  142. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  143. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  144. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  145. -- SOFTWARE.