iup_scroll_box.e 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. class IUP_SCROLL_BOX
  2. -- Creates a native container that allows its child to be scrolled.
  3. --
  4. -- The box allows the application to create a virtual space for the dialog that
  5. -- is actually larger than the visible area. The current size of the box
  6. -- defines the visible area. The natural size of the child (and its children)
  7. -- defines the virtual space size. So the IupScrollBox does not depend on its
  8. -- child size or expansion, and its natural size is always 0x0.
  9. --
  10. -- The user can move the box contents by dragging the background. Also the
  11. -- mouse wheel scrolls the contents vertically.
  12. --
  13. -- The box can be created with no elements and be dynamic filled using
  14. -- append or insert.
  15. inherit
  16. IUP_CANVAS
  17. redefine
  18. set_wheel_drop_focus
  19. end
  20. IUP_WIDGET_CLIENTSIZE
  21. IUP_WIDGET_CLIENTOFFSET
  22. create {ANY}
  23. scroll_box
  24. feature {ANY}
  25. scroll_box(child: IUP_WIDGET)
  26. -- A new scroll box. child is an interface element which will receive the
  27. -- box. It can be Void.
  28. local
  29. a_scroll_box: POINTER
  30. do
  31. a_scroll_box := int_scroll_box(child.widget)
  32. set_widget(a_scroll_box)
  33. end
  34. -- Attributes
  35. set_canvas_box (state: BOOLEAN)
  36. -- (non inheritable): enable the behavior of a canvas box instead of a
  37. -- regular container. Default: "False".
  38. do
  39. iup_open.set_attribute(Current, "CANVASBOX", boolean_to_yesno(state))
  40. end
  41. set_childoffset (horizontal, vertical: INTEGER)
  42. require
  43. horizontal >= 0
  44. vertical >= 0
  45. local
  46. offset: STRING
  47. do
  48. offset := horizontal.out
  49. offset.append_string("x")
  50. offset.append_string(vertical.out)
  51. iup_open.set_attribute(Current, "CHILDOFFSET", offset)
  52. end
  53. get_childoffset: TUPLE[INTEGER, INTEGER]
  54. -- Return the offset of the child.
  55. local
  56. offset: STRING
  57. do
  58. offset := iup_open.get_attribute(Current, "CHILDOFFSET")
  59. Result := components_of_size(offset)
  60. end
  61. set_layout_drag (state: BOOLEAN)
  62. -- (non inheritable) [Windows Only]: When the scrollbar is moved
  63. -- automatically update the children layout. Default: "True". If set to
  64. -- "False" then the layout will be updated only when the mouse drag
  65. -- is released.
  66. do
  67. iup_open.set_attribute(Current, "LAYOUTDRAG", boolean_to_yesno(state))
  68. end
  69. set_wheel_drop_focus (state: BOOLEAN)
  70. -- If set to True when the wheel is used the focus control close any dropdown
  71. -- opened. The default is True.
  72. do
  73. Precursor (state)
  74. end
  75. -- Moves
  76. scroll_to_top
  77. do
  78. iup_open.set_attribute(Current, "SCROLLTO", "TOP")
  79. end
  80. scroll_to_bottom
  81. do
  82. iup_open.set_attribute(Current, "SCROLLTO", "BOTTOM")
  83. end
  84. scroll_to (x, y: INTEGER)
  85. -- Position the scroll at the given x,y coordinates relative to the box
  86. -- top-left corner.
  87. local
  88. position: STRING
  89. do
  90. position := x.out
  91. position.append_string(",")
  92. position.append_string(y.out)
  93. iup_open.set_attribute(Current, "SCROLLTO", position)
  94. end
  95. scroll_to_child (child_name: STRING)
  96. -- (write-only): position the scroll at the top-left corner of the given
  97. -- child located by its name. Use set_widget_name to associate a
  98. -- name. The child must be contained in the Scrollbox hierarchy.
  99. do
  100. iup_open.set_attribute(Current, "SCROLLTOCHILD", child_name)
  101. end
  102. scroll_to_child_widget (child_widget: IUP_WIDGET)
  103. -- (write-only): same as scroll_to_child but directly using the child
  104. -- widget.
  105. do
  106. iup_open.set_attribute_widget(Current, "SCROLLTOCHILD_HANDLE", child_widget)
  107. end
  108. feature {NONE}
  109. -- Internal
  110. int_scroll_box (wgt: POINTER): POINTER
  111. external
  112. "C inline use %"eiffel-iup.h%""
  113. alias
  114. "return IupScrollBox ($wgt);"
  115. end
  116. end
  117. -- The MIT License (MIT)
  118. -- Copyright (c) 2016, 2017, 2019, 2021 by German A. Arias
  119. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  120. -- of this software and associated documentation files (the "Software"), to deal
  121. -- in the Software without restriction, including without limitation the rights
  122. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  123. -- copies of the Software, and to permit persons to whom the Software is
  124. -- furnished to do so, subject to the following conditions:
  125. --
  126. -- The above copyright notice and this permission notice shall be included in
  127. -- all copies or substantial portions of the Software.
  128. --
  129. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  130. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  131. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  132. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  133. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  134. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  135. -- SOFTWARE.