Add dependencies
[clutter-gtk] / clutter-gtk / gtk-clutter-scrollable.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include "gtk-clutter-scrollable.h"
6
7 #define I_(str) (g_intern_static_string ((str)))
8
9 /**
10  * SECTION:gtk-clutter-scrollable
11  * @short_description: Interface for scrollable actors
12  *
13  * #GtkClutterScrollable is an interface for scrollable actors, reusing
14  * the #GtkAdjustment objects from GTK+ do drive the scrolling.
15  *
16  * #GtkClutterScrollable is available since Clutter-GTK 0.10
17  */
18
19 static void
20 gtk_clutter_scrollable_base_init (gpointer g_iface)
21 {
22   static gboolean is_initialized = FALSE;
23
24   if (G_UNLIKELY (!is_initialized))
25     {
26       GParamSpec *pspec;
27
28       /**
29        * GtkClutterScrollable:hadjustment:
30        *
31        * The #GtkAdjustment that determines the value of the
32        * horizontal position for this scrollable actor.
33        *
34        * Since: 0.10
35        */
36       pspec = g_param_spec_object ("hadjustment",
37                                    "Horizontal adjustment",
38                                    "The GtkAdjustment that determines "
39                                    "the value of the horizontal position "
40                                    "for this scrollable actor",
41                                    GTK_TYPE_ADJUSTMENT,
42                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
43       g_object_interface_install_property (g_iface, pspec);
44
45       /**
46        * GtkClutterScrollable:vadjustment:
47        *
48        * The #GtkAdjustment that determines the value of the
49        * vertical position for this scrollable actor.
50        *
51        * Since: 0.10
52        */
53       pspec = g_param_spec_object ("vadjustment",
54                                    "Vertical adjustment",
55                                    "The GtkAdjustment that determines "
56                                    "the value of the vertical position "
57                                    "for this scrollable actor",
58                                    GTK_TYPE_ADJUSTMENT,
59                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
60       g_object_interface_install_property (g_iface, pspec);
61
62       is_initialized = TRUE;
63     }
64 }
65
66 GType
67 gtk_clutter_scrollable_get_type (void)
68 {
69   static GType scrollable_type = 0;
70
71   if (G_UNLIKELY (!scrollable_type))
72     {
73       const GTypeInfo scrollable_info =
74       {
75         sizeof (GtkClutterScrollableIface),
76         (GBaseInitFunc)     gtk_clutter_scrollable_base_init,
77         (GBaseFinalizeFunc) NULL,
78       };
79
80       scrollable_type = g_type_register_static (G_TYPE_INTERFACE,
81                                                 I_("GtkClutterScrollable"),
82                                                 &scrollable_info, 0);
83     }
84
85   return scrollable_type;
86 }
87
88 /**
89  * gtk_clutter_scrollable_set_adjustments:
90  * @scrollable: a #GtkClutterScrollable
91  * @h_adjust: a #GtkAdjustment, or %NULL
92  * @v_adjust: a #GtkAdjustment, or %NULL
93  *
94  * Sets the horizontal and vertical adjustments used to determine
95  * the position of the scrollable actor.
96  *
97  * Since: 0.10
98  */
99 void
100 gtk_clutter_scrollable_set_adjustments (GtkClutterScrollable *scrollable,
101                                         GtkAdjustment        *h_adjust,
102                                         GtkAdjustment        *v_adjust)
103 {
104   GtkClutterScrollableIface *iface;
105
106   g_return_if_fail (GTK_CLUTTER_IS_SCROLLABLE (scrollable));
107   g_return_if_fail (h_adjust == NULL || GTK_IS_ADJUSTMENT (h_adjust));
108
109   iface = GTK_CLUTTER_SCROLLABLE_GET_IFACE (scrollable);
110   if (iface->set_adjustments)
111     iface->set_adjustments (scrollable, h_adjust, v_adjust);
112 }
113
114 /**
115  * gtk_clutter_scrollable_get_adjustments:
116  * @scrollable: a #GtkClutterScrollable
117  * @h_adjust: return location for a #GtkAdjustment, or %NULL
118  * @v_adjust: return location for a #GtkAdjustment, or %NULL
119  *
120  * Retrieves the horizontal and vertical adjustments used to
121  * determine the position of the scrollable actor.
122  *
123  * Since: 0.10
124  */
125 void
126 gtk_clutter_scrollable_get_adjustments (GtkClutterScrollable  *scrollable,
127                                         GtkAdjustment        **h_adjust,
128                                         GtkAdjustment        **v_adjust)
129 {
130   GtkClutterScrollableIface *iface;
131
132   g_return_if_fail (GTK_CLUTTER_IS_SCROLLABLE (scrollable));
133
134   iface = GTK_CLUTTER_SCROLLABLE_GET_IFACE (scrollable);
135   if (iface->get_adjustments)
136     iface->get_adjustments (scrollable, h_adjust, v_adjust);
137 }