iup_flat_scroll_box.e 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. class IUP_FLAT_SCROLL_BOX
  2. -- Creates a native container that allows its child to be scrolled. It inherits
  3. -- from IUP_CANVAS. The difference from IUP_SCROLL_BOX is that its scrollbars
  4. -- are drawn.
  5. --
  6. -- The box allows the application to create a virtual space for the dialog that
  7. -- is actually larger than the visible area. The current size of the box
  8. -- defines the visible area. The natural size of the child (and its children)
  9. -- defines the virtual space size.
  10. --
  11. -- So the IUP_FLAT_SCROLL_BOX does not depend on its child size or expansion,
  12. -- and its natural size is always 0x0, except for the first time when it
  13. -- expands to the child natural size.
  14. --
  15. -- The user can move the box contents by dragging the background. Also the
  16. -- mouse wheel scrolls the contents vertically.
  17. --
  18. -- The box can be created with no elements and be dynamic filled using "append"
  19. -- or "insert".
  20. inherit
  21. IUP_CANVAS
  22. redefine
  23. set_rgb_background_color,
  24. set_border,
  25. set_can_focus,
  26. set_scroll_bar,
  27. set_wheel_drop_focus
  28. end
  29. IUP_WIDGET_CLIENTSIZE
  30. IUP_WIDGET_CLIENTOFFSET
  31. IUP_WIDGET_FLAT_SCROLL_BOX
  32. create {ANY}
  33. flat_scroll_box_empty,
  34. flat_scroll_box
  35. feature {ANY}
  36. -- Creation
  37. flat_scroll_box_empty
  38. -- An empty flat scroll box.
  39. local
  40. a_flat_scroll_box, p: POINTER
  41. do
  42. a_flat_scroll_box := int_flat_scroll_box (p)
  43. set_widget(a_flat_scroll_box)
  44. end
  45. flat_scroll_box (child: IUP_WIDGET)
  46. -- Create a flat scroll box with the child.
  47. --
  48. -- child: Identifier of an interface element which will receive the flat
  49. -- scroll box around.
  50. local
  51. a_flat_scroll_box: POINTER
  52. do
  53. a_flat_scroll_box := int_flat_scroll_box (child.widget)
  54. set_widget(a_flat_scroll_box)
  55. end
  56. -- Redefinitions
  57. set_rgb_background_color (red: INTEGER; green: INTEGER; blue: INTEGER)
  58. -- Will always use the background color of the native parent.
  59. do
  60. Precursor (red, green, blue)
  61. end
  62. set_border (state: BOOLEAN)
  63. -- (creation only): it is always "False".
  64. do
  65. Precursor (state)
  66. end
  67. set_can_focus (state: BOOLEAN)
  68. -- (creation only) (non inheritable): enables the focus traversal of the
  69. -- control. In Windows the canvas will respect CANFOCUS differently to
  70. -- some other controls. Default: False.
  71. do
  72. Precursor (state)
  73. end
  74. -- Attributes
  75. set_canvas_box (state: BOOLEAN)
  76. -- (non inheritable): enable the behavior of a canvas box instead of a
  77. -- regular container. Default: "False".
  78. do
  79. iup_open.set_attribute(Current, "CANVASBOX", boolean_to_yesno(state))
  80. end
  81. set_child_offset (horizontal, vertical: INTEGER)
  82. -- Allow to specify a position offset for the child. Available for native
  83. -- containers only. It will not affect the natural size, and allows to
  84. -- position controls outside the client area. Horizontal and vertical are
  85. -- integer values in pixels. Default: 0x0.
  86. local
  87. str: STRING
  88. do
  89. create str.make_from_string(horizontal.out)
  90. str.append_string("x")
  91. str.append_string(vertical.out)
  92. iup_open.set_attribute(Current, "CHILDOFFSET", str)
  93. end
  94. get_child_offset: TUPLE[INTEGER, INTEGER]
  95. local
  96. offset: STRING
  97. do
  98. offset := iup_open.get_attribute(Current, "CHILDOFFSET")
  99. Result := components_of_size(offset)
  100. end
  101. set_layout_drag (state: BOOLEAN)
  102. -- (non inheritable): When the scrollbar is moved automatically update
  103. -- the children layout. Default: "True". If set to "False" then the
  104. -- layout will be updated only when the mouse drag is released.
  105. do
  106. iup_open.set_attribute(Current, "LAYOUTDRAG", boolean_to_yesno(state))
  107. end
  108. set_scroll_bar (state: BOOLEAN)
  109. -- Is always "False". So the IUP_CANVAS native scrollbars
  110. -- are hidden. See the FLATSCROLLBAR attribute bellow. YAUTOHIDE and
  111. -- XAUTOHIDE will be always "True".
  112. do
  113. Precursor (state)
  114. end
  115. set_wheel_drop_focus (state: BOOLEAN)
  116. -- If set to True when the wheel is used the focus control close any dropdown
  117. -- opened. The default is True.
  118. do
  119. Precursor (state)
  120. end
  121. -- Operations
  122. scroll_to (x, y: INTEGER)
  123. -- Position the scroll at the given x,y coordinates relative to the box
  124. -- top-left corner.
  125. local
  126. str: STRING
  127. do
  128. str := x.out
  129. str.append_string(",")
  130. str.append_string(y.out)
  131. iup_open.set_attribute(Current, "SCROLLTO", str)
  132. end
  133. scroll_to_top
  134. do
  135. iup_open.set_attribute(Current, "SCROLLTO", "TOP")
  136. end
  137. scroll_to_bottom
  138. do
  139. iup_open.set_attribute(Current, "SCROLLTO", "BOTTOM")
  140. end
  141. scroll_to_child (name: STRING)
  142. -- Position the scroll at the top-left corner of the given child located
  143. -- by its name. Use set_widget_name to associate an image to a name.
  144. -- The child must be contained in the Scrollbox hierarchy.
  145. do
  146. iup_open.set_attribute(Current, "SCROLLTOCHILD", name)
  147. end
  148. scroll_to_child_widget (control: IUP_WIDGET)
  149. -- Scroll to the given control.
  150. do
  151. iup_open.set_attribute_widget(Current, "SCROLLTOCHILD_HANDLE", control)
  152. end
  153. feature {NONE}
  154. -- Internals
  155. int_flat_scroll_box (wgt: POINTER): POINTER
  156. external
  157. "C inline use %"eiffel-iup.h%""
  158. alias
  159. "return IupFlatScrollBox ($wgt);"
  160. end
  161. end
  162. -- The MIT License (MIT)
  163. -- Copyright (c) 2017, 2019, 2021 by German A. Arias
  164. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  165. -- of this software and associated documentation files (the "Software"), to deal
  166. -- in the Software without restriction, including without limitation the rights
  167. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  168. -- copies of the Software, and to permit persons to whom the Software is
  169. -- furnished to do so, subject to the following conditions:
  170. --
  171. -- The above copyright notice and this permission notice shall be included in
  172. -- all copies or substantial portions of the Software.
  173. --
  174. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  175. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  176. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  177. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  178. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  179. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  180. -- SOFTWARE.