/src/wrappers/gtk/library/gtk_scrolled_window.e

http://github.com/tybor/Liberty · Specman e · 477 lines · 200 code · 96 blank · 181 comment · 2 complexity · 2d85e1b958b48a41a2132df3feca6c64 MD5 · raw file

  1. indexing
  2. description: "A container that adds scrollbars to its child widget"
  3. copyright: "[
  4. Copyright (C) 2006 Paolo Redaelli, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. class GTK_SCROLLED_WINDOW
  19. -- A container the accepts a single child widget. GtkScrolledWindow
  20. -- adds scrollbars to the child widget and optionally draws a
  21. -- beveled frame around the child widget.
  22. -- The scrolled window can work in two ways. Some widgets have
  23. -- native scrolling support; these widgets have "slots" for
  24. -- GtkAdjustment objects. Widgets with native scroll support
  25. -- include GtkTreeView, GtkTextView, and GtkLayout.
  26. -- For widgets that lack native scrolling support, the GtkViewport
  27. -- widget acts as an adaptor class, implementing scrollability for
  28. -- child widgets that lack their own scrolling capabilities. Use
  29. -- GtkViewport to scroll child widgets such as GtkTable, GtkBox,
  30. -- and so on.
  31. -- If a widget has native scrolling abilities, it can be added to
  32. -- the GtkScrolledWindow with `add'. If a widget does not, you must
  33. -- first add the widget to a GtkViewport, then add the GtkViewport
  34. -- to the scrolled window. The convenience function
  35. -- gtk_scrolled_window_add_with_viewport() does exactly this, so
  36. -- you can ignore the presence of the viewport.
  37. -- The position of the scrollbars is controlled by the scroll
  38. -- adjustments. See GtkAdjustment for the fields in an adjustment -
  39. -- for GtkScrollbar, used by GtkScrolledWindow, the "value" field
  40. -- represents the position of the scrollbar, which must be between
  41. -- the "lower" field and "upper - page_size." The "page_size" field
  42. -- represents the size of the visible scrollable area. The
  43. -- "step_increment" and "page_increment" fields are used when the
  44. -- user asks to step down (using the small stepper arrows) or page
  45. -- down (using for example the PageDown key).
  46. -- If a GtkScrolledWindow doesn't behave quite as you would like,
  47. -- or doesn't have exactly the right layout, it's very possible to
  48. -- set up your own scrolling with GtkScrollbar and for example a
  49. -- GtkTable.
  50. inherit
  51. GTK_BIN
  52. -- GtkScrolledWindow implements AtkImplementorIface interface.
  53. insert
  54. GTK_POLICY_TYPE
  55. GTK_CORNER_TYPE
  56. GTK_SHADOW_TYPE
  57. creation make, make_default, from_external_pointer
  58. feature {} -- Creation
  59. make_default is
  60. -- Creates a new scrolled window. The adjustments will be
  61. -- created with it.
  62. require gtk_initialized: gtk.is_initialized
  63. do
  64. from_external_pointer (gtk_scrolled_window_new (default_pointer,default_pointer))
  65. end
  66. make (an_horizontal_adjustment, a_vertical_adjustment: GTK_ADJUSTMENT) is
  67. -- Creates a new scrolled window. The two arguments are the
  68. -- scrolled window's adjustments; these will be shared with
  69. -- the scrollbars and the child widget to keep the bars in
  70. -- sync with the child. Usually you want to pass `Void' for
  71. -- the adjustments, which will cause the scrolled window to
  72. -- create them for you.
  73. -- `an_horizontal_adjustment' : Horizontal adjustment.
  74. -- `a_vertical_adjustment': Vertical adjustment.
  75. do
  76. from_external_pointer (gtk_scrolled_window_new (null_or(an_horizontal_adjustment), null_or(a_vertical_adjustment)))
  77. end
  78. feature -- Adjustments
  79. horizontal_adjustment: GTK_ADJUSTMENT is
  80. -- the horizontal scrollbar's adjustment, used to connect the
  81. -- horizontal scrollbar to the child widget's horizontal
  82. -- scroll functionality.
  83. local factory: G_OBJECT_EXPANDED_FACTORY [GTK_ADJUSTMENT]
  84. do
  85. Result := factory.wrapper_or_void (gtk_scrolled_window_get_hadjustment (handle))
  86. end
  87. vertical_adjustment: GTK_ADJUSTMENT is
  88. -- the vertical scrollbar's adjustment, used to connect the
  89. -- vertical scrollbar to the child widget's vertical
  90. -- scroll functionality.
  91. local factory: G_OBJECT_EXPANDED_FACTORY [GTK_ADJUSTMENT]
  92. do
  93. Result := factory.wrapper_or_void (gtk_scrolled_window_get_vadjustment (handle))
  94. end
  95. set_horizontal_adjustment (an_adjustment: GTK_ADJUSTMENT) is
  96. -- Sets the GtkAdjustment for the horizontal scrollbar.
  97. require
  98. adjustment_not_void: an_adjustment /= Void
  99. do
  100. gtk_scrolled_window_set_hadjustment (handle, an_adjustment.handle)
  101. ensure adjustment_set: an_adjustment = horizontal_adjustment
  102. end
  103. set_vertical_adjustment (an_adjustment: GTK_ADJUSTMENT) is
  104. -- Sets the GtkAdjustment for the vertical scrollbar.
  105. require
  106. adjustment_not_void: an_adjustment /= Void
  107. do
  108. gtk_scrolled_window_set_vadjustment (handle, an_adjustment.handle)
  109. ensure adjustment_set: an_adjustment = vertical_adjustment
  110. end
  111. feature -- TODO: Scrollbars
  112. -- gtk_scrolled_window_get_hscrollbar ()
  113. -- GtkWidget* gtk_scrolled_window_get_hscrollbar
  114. -- (GtkScrolledWindow *scrolled_window);
  115. -- Returns the horizontal scrollbar of scrolled_window.
  116. -- scrolled_window : a GtkScrolledWindow
  117. -- Returns : the horizontal scrollbar of the scrolled window, or NULL if it does not have one.
  118. -- Since 2.8
  119. -- gtk_scrolled_window_get_vscrollbar ()
  120. -- GtkWidget* gtk_scrolled_window_get_vscrollbar
  121. -- (GtkScrolledWindow *scrolled_window);
  122. -- Returns the vertical scrollbar of scrolled_window.
  123. -- scrolled_window : a GtkScrolledWindow
  124. -- Returns : the vertical scrollbar of the scrolled window, or NULL if it does not have one.
  125. -- Since 2.8
  126. set_policy (an_horizontal_policy, a_vertical_policy: INTEGER) is
  127. -- Sets the scrollbar policy for the horizontal and vertical
  128. -- scrollbars. The policy determines when the scrollbar
  129. -- should appear; it is a value from the GtkPolicyType
  130. -- enumeration. If `GTK_POLICY_ALWAYS', the scrollbar is
  131. -- always present; if `GTK_POLICY_NEVER', the scrollbar is
  132. -- never present; if `GTK_POLICY_AUTOMATIC', the scrollbar is
  133. -- present only if needed (that is, if the slider part of the
  134. -- bar would be smaller than the trough - the display is
  135. -- larger than the page size).
  136. require
  137. valid_horizontal_policy: is_valid_gtk_policy (an_horizontal_policy)
  138. valid_vertical_policy: is_valid_gtk_policy (a_vertical_policy)
  139. do
  140. gtk_scrolled_window_set_policy (handle, an_horizontal_policy, a_vertical_policy)
  141. ensure -- TODO: h and v policy_set
  142. end
  143. feature
  144. add_with_viewport (a_child: GTK_WIDGET) is
  145. -- Adds children without native scrolling capabilities. This
  146. -- is simply a convenience function; it is equivalent to
  147. -- adding the unscrollable child to a viewport, then adding
  148. -- the viewport to the scrolled window. If a child has native
  149. -- scrolling, use `add' instead of this function.
  150. -- The viewport scrolls the child by moving its GdkWindow,
  151. -- and takes the size of the child to be the size of its
  152. -- toplevel GdkWindow. This will be very wrong for most
  153. -- widgets that support native scrolling; for example, if you
  154. -- add a widget such as GtkTreeView with a viewport, the
  155. -- whole widget will scroll, including the column
  156. -- headings. Thus, widgets with native scrolling support
  157. -- should not be used with the GtkViewport proxy.
  158. -- A widget supports scrolling natively if the
  159. -- set_scroll_adjustments_signal field in GtkWidgetClass is
  160. -- non-zero, i.e. has been filled in with a valid signal
  161. -- identifier.
  162. -- TODO: wrap GTK_VIEWPORT
  163. require
  164. child_not_void: a_child /= Void
  165. do
  166. gtk_scrolled_window_add_with_viewport (handle, a_child.handle)
  167. end
  168. set_placement (a_window_placement: INTEGER) is
  169. -- Determines the location of the child widget with respect
  170. -- to the scrollbars. The default is `gtk_corner_top_left',
  171. -- meaning the child is in the top left, with the scrollbars
  172. -- underneath and to the right. Other values in GtkCornerType
  173. -- are `gtk_corner_top_right', `gtk_corner_bottom_left', and
  174. -- `gtk_corner_bottom_right'.
  175. require
  176. valid_placement: is_valid_gtk_corner_type (a_window_placement)
  177. do
  178. gtk_scrolled_window_set_placement (handle, a_window_placement)
  179. ensure placement_set: a_window_placement = placement
  180. end
  181. set_shadow_type (a_type: INTEGER) is
  182. -- Changes the type of shadow drawn around the contents of
  183. -- scrolled_window.
  184. require
  185. valid_shadow: is_valid_gtk_shadow_type(a_type)
  186. do
  187. gtk_scrolled_window_set_shadow_type (handle, a_type)
  188. ensure value_set: shadow_type = a_type
  189. end
  190. placement: INTEGER is
  191. -- The placement of the scrollbars for the scrolled
  192. -- window. See `set_placement'.
  193. do
  194. Result := gtk_scrolled_window_get_placement (handle)
  195. ensure valid: is_valid_gtk_corner_type (Result)
  196. end
  197. horizontal_policy: INTEGER is
  198. -- The current policy values for the horizontal
  199. -- scrollbar. See `set_policy'.
  200. do
  201. gtk_scrolled_window_get_policy (handle, $Result, default_pointer)
  202. ensure valid: is_valid_gtk_policy (Result)
  203. end
  204. vertical_policy: INTEGER is
  205. -- The current policy values for the vertical scrollbar. See
  206. -- `set_policy'.
  207. do
  208. gtk_scrolled_window_get_policy (handle, default_pointer, $Result)
  209. ensure valid: is_valid_gtk_policy (Result)
  210. end
  211. policies: TUPLE [INTEGER,INTEGER] is
  212. -- The current policy values for the horizontal
  213. -- scrollbar. See `set_policy'.
  214. local hpol, vpol: INTEGER
  215. do
  216. gtk_scrolled_window_get_policy (handle, $hpol,$vpol)
  217. create Result.make_2 (hpol,vpol)
  218. ensure
  219. valid_horizontal: is_valid_gtk_policy (Result.item_1)
  220. valid_vertical: is_valid_gtk_policy (Result.item_1)
  221. end
  222. shadow_type: INTEGER is
  223. -- The shadow type of the scrolled window. See
  224. -- `set_shadow_type'.
  225. do
  226. Result := gtk_scrolled_window_get_shadow_type (handle)
  227. ensure valid: is_valid_gtk_shadow_type (Result)
  228. end
  229. feature -- Properties
  230. -- "hadjustment" GtkAdjustment : Read / Write / Construct
  231. -- "hscrollbar-policy" GtkPolicyType : Read / Write
  232. -- "shadow-type" GtkShadowType : Read / Write
  233. -- "vadjustment" GtkAdjustment : Read / Write / Construct
  234. -- "vscrollbar-policy" GtkPolicyType : Read / Write
  235. -- "window-placement" GtkCornerType : Read / Write
  236. -- Style Properties
  237. -- "scrollbar-spacing" gint : Read
  238. -- Property Details
  239. -- The "hadjustment" property
  240. -- "hadjustment" GtkAdjustment : Read / Write / Construct
  241. -- The GtkAdjustment for the horizontal position.
  242. -- The "hscrollbar-policy" property
  243. -- "hscrollbar-policy" GtkPolicyType : Read / Write
  244. -- When the horizontal scrollbar is displayed.
  245. -- Default value: GTK_POLICY_ALWAYS
  246. -- The "shadow-type" property
  247. -- "shadow-type" GtkShadowType : Read / Write
  248. -- Style of bevel around the contents.
  249. -- Default value: GTK_SHADOW_NONE
  250. -- The "vadjustment" property
  251. -- "vadjustment" GtkAdjustment : Read / Write / Construct
  252. -- The GtkAdjustment for the vertical position.
  253. -- The "vscrollbar-policy" property
  254. -- "vscrollbar-policy" GtkPolicyType : Read / Write
  255. -- When the vertical scrollbar is displayed.
  256. -- Default value: GTK_POLICY_ALWAYS
  257. -- The "window-placement" property
  258. -- "window-placement" GtkCornerType : Read / Write
  259. -- Where the contents are located with respect to the scrollbars.
  260. -- Default value: GTK_CORNER_TOP_LEFT
  261. -- Style Property Details
  262. -- The "scrollbar-spacing" style property
  263. -- "scrollbar-spacing" gint : Read
  264. -- Number of pixels between the scrollbars and the scrolled window.
  265. -- Allowed values: >= 0
  266. -- Default value: 3
  267. feature -- scroll-child signal
  268. scroll_child_signal_name: STRING is "scroll-child"
  269. -- "scroll-child"
  270. -- void user_function (GtkScrolledWindow *scrolledwindow,
  271. -- GtkScrollType *arg1,
  272. -- gboolean arg2,
  273. -- gpointer user_data) : Run last / Action
  274. enable_on_scroll_child is
  275. -- Connects "scroll-child" signal to `on_scroll_child' feature.
  276. do
  277. connect (Current, scroll_child_signal_name, $on_scroll_child)
  278. end
  279. on_scroll_child: INTEGER is
  280. -- Built-in scroll-child signal handler; empty by design; redefine it.
  281. -- The `scroll-child' signal is emitted on the drag source
  282. -- when a drag is started. A typical reason to connect to this
  283. -- signal is to set up a custom drag icon with
  284. -- gtk_drag_source_set_icon().
  285. do
  286. end
  287. connect_agent_to_scroll_child_signal (a_function: FUNCTION[ANY, TUPLE [INTEGER, BOOLEAN, GTK_SCROLLED_WINDOW],
  288. BOOLEAN]) is
  289. -- scrolledwindow : the object which received the signal.
  290. -- arg1 :
  291. -- arg2 :
  292. require
  293. valid_function: a_function /= Void
  294. wrapper_is_stored: is_eiffel_wrapper_stored
  295. local
  296. scroll_child_callback: SCROLL_CHILD_CALLBACK
  297. do
  298. create scroll_child_callback.make
  299. scroll_child_callback.connect (Current, a_function)
  300. end
  301. feature -- Signals
  302. -- "move-focus-out"
  303. -- void user_function (GtkScrolledWindow *scrolledwindow,
  304. -- GtkDirectionType *arg1,
  305. -- gpointer user_data) : Run last / Action
  306. -- Signal Details
  307. -- The "move-focus-out" signal
  308. -- void user_function (GtkScrolledWindow *scrolledwindow,
  309. -- GtkDirectionType *arg1,
  310. -- gpointer user_data) : Run last / Action
  311. -- scrolledwindow : the object which received the signal.
  312. -- arg1 :
  313. -- user_data : user data set when the signal handler was connected.
  314. -- GtkViewport, GtkAdjustment, GtkWidgetClass
  315. -- [5] The scrolled window installs GtkAdjustment objects in the child window's slots using the set_scroll_adjustments_signal, found in GtkWidgetClass. (Conceptually, these widgets implement a "Scrollable" interface; because GTK+ 1.2 lacked interface support in the object system, this interface is hackily implemented as a signal in GtkWidgetClass. The GTK+ 2.0 object system would allow a clean implementation, but it wasn't worth breaking the API.)
  316. feature -- size
  317. struct_size: INTEGER is
  318. external "C inline use <gtk/gtk.h>"
  319. alias "sizeof(GtkScrolledWindow)"
  320. end
  321. feature {} -- External calls
  322. gtk_scrolled_window_new (a_hadjustment, a_vadjustment: POINTER): POINTER is -- GtkWidget*
  323. external "C use <gtk/gtk.h>"
  324. end
  325. gtk_scrolled_window_get_hadjustment (a_scrolled_window: POINTER): POINTER is -- GtkAdjustment*
  326. external "C use <gtk/gtk.h>"
  327. end
  328. gtk_scrolled_window_get_vadjustment (a_scrolled_window: POINTER): POINTER is -- GtkAdjustment*
  329. external "C use <gtk/gtk.h>"
  330. end
  331. gtk_scrolled_window_get_hscrollbar (a_scrolled_window: POINTER): POINTER is -- GtkWidget*
  332. external "C use <gtk/gtk.h>"
  333. end
  334. gtk_scrolled_window_get_vscrollbar (a_scrolled_window: POINTER): POINTER is -- GtkWidget*
  335. external "C use <gtk/gtk.h>"
  336. end
  337. gtk_scrolled_window_set_policy (a_scrolled_window: POINTER; hscrollbar_policy, vscrollbar_policy: INTEGER) is
  338. require
  339. valid_horizontal_policy: is_valid_gtk_policy (hscrollbar_policy)
  340. valid_vorizontal_policy: is_valid_gtk_policy (vscrollbar_policy)
  341. external "C use <gtk/gtk.h>"
  342. end
  343. gtk_scrolled_window_add_with_viewport(a_scrolled_window, a_child_gtkwidget: POINTER) is
  344. external "C use <gtk/gtk.h>"
  345. end
  346. gtk_scrolled_window_set_placement (a_scrolled_window: POINTER; window_placement: INTEGER) is
  347. require
  348. valid_placement: is_valid_gtk_corner_type (window_placement)
  349. external "C use <gtk/gtk.h>"
  350. end
  351. gtk_scrolled_window_set_shadow_type (a_scrolled_window: POINTER; a_shadow_type: INTEGER) is
  352. require
  353. valid_shadow_type: is_valid_gtk_shadow_type (a_shadow_type)
  354. external "C use <gtk/gtk.h>"
  355. end
  356. gtk_scrolled_window_set_hadjustment (a_scrolled_window, an_hadjustment: POINTER) is
  357. external "C use <gtk/gtk.h>"
  358. end
  359. gtk_scrolled_window_set_vadjustment (a_scrolled_window, a_vadjustment: POINTER) is
  360. external "C use <gtk/gtk.h>"
  361. end
  362. gtk_scrolled_window_get_placement (a_scrolled_window: POINTER): INTEGER is
  363. external "C use <gtk/gtk.h>"
  364. ensure
  365. valid_result: is_valid_gtk_corner_type (Result)
  366. end
  367. gtk_scrolled_window_get_policy (a_scrolled_window, a_hscrollbar_policy_pointer, a_vscrollbar_policy_pointer: POINTER) is
  368. external "C use <gtk/gtk.h>"
  369. end
  370. gtk_scrolled_window_get_shadow_type (a_scrolled_window: POINTER): INTEGER is
  371. external "C use <gtk/gtk.h>"
  372. ensure valid_result: is_valid_gtk_shadow_type (Result)
  373. end
  374. -- GtkScrolledWindow struct has no public fields; it should only be
  375. -- accessed using the functions above. Nevertheless the original GTK+
  376. -- documentation still provides this detail:
  377. -- typedef struct {
  378. -- GtkWidget *hscrollbar;
  379. -- GtkWidget *vscrollbar;
  380. -- } GtkScrolledWindow;
  381. end -- class GTK_SCROLLED_WINDOW