iup_flat_scroll_box.e 6.0 KB

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