};
static void gtk_scrolled_window_destroy (GtkObject *object);
-static void gtk_scrolled_window_finalize (GObject *object);
static void gtk_scrolled_window_set_property (GObject *object,
guint prop_id,
const GValue *value,
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
- gobject_class->finalize = gtk_scrolled_window_finalize;
gobject_class->set_property = gtk_scrolled_window_set_property;
gobject_class->get_property = gtk_scrolled_window_get_property;
gtk_scrolled_window_update_real_placement (scrolled_window);
}
+/**
+ * gtk_scrolled_window_new:
+ * @hadjustment: (allow-none): horizontal adjustment
+ * @vadjustment: (allow-none): vertical adjustment
+ *
+ * Creates a new scrolled window.
+ *
+ * The two arguments are the scrolled window's adjustments; these will be
+ * shared with the scrollbars and the child widget to keep the bars in sync
+ * with the child. Usually you want to pass %NULL for the adjustments, which
+ * will cause the scrolled window to create them for you.
+ *
+ * Returns: a new scrolled window
+ */
GtkWidget*
gtk_scrolled_window_new (GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
return scrolled_window;
}
+/**
+ * gtk_scrolled_window_set_hadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @hadjustment: horizontal scroll adjustment
+ *
+ * Sets the #GtkAdjustment for the horizontal scrollbar.
+ */
void
gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
GtkAdjustment *hadjustment)
g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
}
+/**
+ * gtk_scrolled_window_set_vadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @vadjustment: vertical scroll adjustment
+ *
+ * Sets the #GtkAdjustment for the vertical scrollbar.
+ */
void
gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
GtkAdjustment *vadjustment)
g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
}
+/**
+ * gtk_scrolled_window_get_hadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Returns the horizontal scrollbar's adjustment, used to connect the
+ * horizontal scrollbar to the child widget's horizontal scroll
+ * functionality.
+ *
+ * Returns: the horizontal #GtkAdjustment
+ */
GtkAdjustment*
gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
{
NULL);
}
+/**
+ * gtk_scrolled_window_get_vadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Returns the vertical scrollbar's adjustment, used to connect the
+ * vertical scrollbar to the child widget's vertical scroll
+ * functionality.
+ *
+ * Returns: the vertical #GtkAdjustment
+ */
GtkAdjustment*
gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
{
return scrolled_window->vscrollbar;
}
+/**
+ * gtk_scrolled_window_set_policy:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @hscrollbar_policy: policy for horizontal bar
+ * @vscrollbar_policy: policy for vertical bar
+ *
+ * Sets the scrollbar policy for the horizontal and vertical scrollbars.
+ *
+ * The policy determines when the scrollbar should appear; it is a value
+ * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
+ * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
+ * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
+ * if needed (that is, if the slider part of the bar would be smaller
+ * than the trough - the display is larger than the page size).
+ */
void
gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
GtkPolicyType hscrollbar_policy,
/**
* gtk_scrolled_window_get_policy:
* @scrolled_window: a #GtkScrolledWindow
- * @hscrollbar_policy: location to store the policy for the horizontal scrollbar, or %NULL.
- * @vscrollbar_policy: location to store the policy for the horizontal scrollbar, or %NULL.
+ * @hscrollbar_policy: location to store the policy for the horizontal
+ * scrollbar, or %NULL.
+ * @vscrollbar_policy: location to store the policy for the vertical
+ * scrollbar, or %NULL.
*
* Retrieves the current policy values for the horizontal and vertical
* scrollbars. See gtk_scrolled_window_set_policy().
- **/
+ */
void
gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
GtkPolicyType *hscrollbar_policy,
*
* Sets the placement of the contents with respect to the scrollbars
* for the scrolled window.
+ *
* The default is %GTK_CORNER_TOP_LEFT, meaning the child is
* in the top left, with the scrollbars underneath and to the right.
* Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
*
* See also gtk_scrolled_window_get_placement() and
* gtk_scrolled_window_unset_placement().
- **/
+ */
void
gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
GtkCornerType window_placement)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
- gtk_widget_unparent (scrolled_window->hscrollbar);
- gtk_widget_unparent (scrolled_window->vscrollbar);
- gtk_widget_destroy (scrolled_window->hscrollbar);
- gtk_widget_destroy (scrolled_window->vscrollbar);
+ if (scrolled_window->hscrollbar)
+ {
+ g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
+ gtk_scrolled_window_adjustment_changed,
+ scrolled_window);
+ gtk_widget_unparent (scrolled_window->hscrollbar);
+ gtk_widget_destroy (scrolled_window->hscrollbar);
+ g_object_unref (scrolled_window->hscrollbar);
+ scrolled_window->hscrollbar = NULL;
+ }
+ if (scrolled_window->vscrollbar)
+ {
+ g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)),
+ gtk_scrolled_window_adjustment_changed,
+ scrolled_window);
+ gtk_widget_unparent (scrolled_window->vscrollbar);
+ gtk_widget_destroy (scrolled_window->vscrollbar);
+ g_object_unref (scrolled_window->vscrollbar);
+ scrolled_window->vscrollbar = NULL;
+ }
GTK_OBJECT_CLASS (gtk_scrolled_window_parent_class)->destroy (object);
}
-static void
-gtk_scrolled_window_finalize (GObject *object)
-{
- GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
-
- g_object_unref (scrolled_window->hscrollbar);
- g_object_unref (scrolled_window->vscrollbar);
-
- G_OBJECT_CLASS (gtk_scrolled_window_parent_class)->finalize (object);
-}
-
static void
gtk_scrolled_window_set_property (GObject *object,
guint prop_id,
break;
}
+ value = CLAMP (value, adjustment->lower, adjustment->upper - adjustment->page_size);
+
gtk_adjustment_set_value (adjustment, value);
return TRUE;
* a flag, then propagating the focus motion to the notebook.
*/
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
- if (!GTK_WIDGET_TOPLEVEL (toplevel))
+ if (!gtk_widget_is_toplevel (toplevel))
return;
g_object_ref (scrolled_window);
if (range && GTK_WIDGET_VISIBLE (range))
{
GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
- gdouble delta;
+ gdouble delta, new_value;
delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
- gtk_adjustment_set_value (adj, adj->value + delta);
+ new_value = CLAMP (adj->value + delta, adj->lower, adj->upper - adj->page_size);
+
+ gtk_adjustment_set_value (adj, new_value);
return TRUE;
}
GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
}
+/**
+ * gtk_scrolled_window_add_with_viewport:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @child: the widget you want to scroll
+ *
+ * Used to add children without native scrolling capabilities. This
+ * is simply a convenience function; it is equivalent to adding the
+ * unscrollable child to a viewport, then adding the viewport to the
+ * scrolled window. If a child has native scrolling, use
+ * gtk_container_add() instead of this function.
+ *
+ * The viewport scrolls the child by moving its #GdkWindow, and takes
+ * the size of the child to be the size of its toplevel #GdkWindow.
+ * This will be very wrong for most widgets that support native scrolling;
+ * for example, if you add a widget such as #GtkTreeView with a viewport,
+ * the whole widget will scroll, including the column headings. Thus,
+ * widgets with native scrolling support should not be used with the
+ * #GtkViewport proxy.
+ *
+ * A widget supports scrolling natively if the
+ * set_scroll_adjustments_signal field in #GtkWidgetClass is non-zero,
+ * i.e. has been filled in with a valid signal identifier.
+ */
void
gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
GtkWidget *child)
gtk_container_add (GTK_CONTAINER (viewport), child);
}
-/**
+/*
* _gtk_scrolled_window_get_spacing:
* @scrolled_window: a scrolled window
*
* the scrolled widget. Used by GtkCombo
*
* Return value: the spacing, in pixels.
- **/
+ */
gint
_gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
{