diff options
author | Tadej Borovšak <tadeboro@gmail.com> | 2010-10-18 00:21:39 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2010-10-22 11:03:45 +0200 |
commit | 55196a705f00564a44647bfc97981db0a783369a (patch) | |
tree | 101187f418d74b2cb16929f0dcd4ce2ed4575e44 /gtk | |
parent | 86b3c1b65e6fefc6f686279b1bc15b10895b61fe (diff) | |
download | gtk+-55196a705f00564a44647bfc97981db0a783369a.tar.gz |
Add GtkScrollable interface
The GtkScrollable interface provides "hadjustment" and "vadjustment"
properties that are used by GtkScrolledWindow. It replaces
the ::set_scroll_adjustment signal. The scrollable interface
also has ::min-display-width/height properties that can be
used to control the minimally visible part inside a scrolled window.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/gtk.h | 1 | ||||
-rw-r--r-- | gtk/gtk.symbols | 17 | ||||
-rw-r--r-- | gtk/gtkiconview.c | 434 | ||||
-rw-r--r-- | gtk/gtkiconview.h | 5 | ||||
-rw-r--r-- | gtk/gtklayout.c | 337 | ||||
-rw-r--r-- | gtk/gtklayout.h | 8 | ||||
-rw-r--r-- | gtk/gtkscrollable.c | 327 | ||||
-rw-r--r-- | gtk/gtkscrollable.h | 61 | ||||
-rw-r--r-- | gtk/gtkscrolledwindow.c | 98 | ||||
-rw-r--r-- | gtk/gtktextview.c | 375 | ||||
-rw-r--r-- | gtk/gtktextview.h | 10 | ||||
-rw-r--r-- | gtk/gtktoolpalette.c | 201 | ||||
-rw-r--r-- | gtk/gtktoolpalette.h | 8 | ||||
-rw-r--r-- | gtk/gtktreeprivate.h | 2 | ||||
-rw-r--r-- | gtk/gtktreeview.c | 205 | ||||
-rw-r--r-- | gtk/gtktreeview.h | 9 | ||||
-rw-r--r-- | gtk/gtkviewport.c | 92 | ||||
-rw-r--r-- | gtk/gtkviewport.h | 10 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 51 | ||||
-rw-r--r-- | gtk/gtkwidget.h | 9 | ||||
-rw-r--r-- | gtk/tests/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/tests/treeview-scrolling.c | 2 |
23 files changed, 1355 insertions, 911 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 2f77957b06..5d6892bdc0 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -271,6 +271,7 @@ gtk_public_h_sources = \ gtkruler.h \ gtkscale.h \ gtkscalebutton.h \ + gtkscrollable.h \ gtkscrollbar.h \ gtkscrolledwindow.h \ gtkselection.h \ @@ -544,6 +545,7 @@ gtk_base_c_sources = \ gtkruler.c \ gtkscale.c \ gtkscalebutton.c \ + gtkscrollable.c \ gtkscrollbar.c \ gtkscrolledwindow.c \ gtkselection.c \ @@ -154,6 +154,7 @@ #include <gtk/gtkruler.h> #include <gtk/gtkscale.h> #include <gtk/gtkscalebutton.h> +#include <gtk/gtkscrollable.h> #include <gtk/gtkscrollbar.h> #include <gtk/gtkscrolledwindow.h> #include <gtk/gtkselection.h> diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 6def240fd9..3abfd5e59a 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2887,6 +2887,20 @@ gtk_scale_button_get_popup #endif #endif +#if IN_HEADER(__GTK_SCROLLABLE_H__) +#if IN_FILE(__GTK_SCROLLABLE_C__) +gtk_scrollable_get_hadjustment +gtk_scrollable_get_type G_GNUC_CONST +gtk_scrollable_get_vadjustment +gtk_scrollable_set_hadjustment +gtk_scrollable_set_vadjustment +gtk_scrollable_get_min_display_width +gtk_scrollable_set_min_display_width +gtk_scrollable_get_min_display_height +gtk_scrollable_set_min_display_height +#endif +#endif + #if IN_HEADER(__GTK_SCROLLBAR_H__) #if IN_FILE(__GTK_SCROLLBAR_C__) gtk_scrollbar_get_type G_GNUC_CONST @@ -4019,7 +4033,6 @@ gtk_tree_view_set_enable_tree_lines gtk_tree_view_set_expander_column gtk_tree_view_set_fixed_height_mode gtk_tree_view_set_grid_lines -gtk_tree_view_set_hadjustment gtk_tree_view_set_headers_clickable gtk_tree_view_set_headers_visible gtk_tree_view_set_hover_expand @@ -4038,7 +4051,6 @@ gtk_tree_view_set_show_expanders gtk_tree_view_set_tooltip_row gtk_tree_view_set_tooltip_cell gtk_tree_view_set_tooltip_column -gtk_tree_view_set_vadjustment gtk_tree_view_unset_rows_drag_dest gtk_tree_view_unset_rows_drag_source gtk_tree_view_columns_autosize @@ -4287,7 +4299,6 @@ gtk_widget_set_parent gtk_widget_set_parent_window gtk_widget_set_receives_default gtk_widget_set_redraw_on_allocate -gtk_widget_set_scroll_adjustments gtk_widget_set_sensitive gtk_widget_set_size_request gtk_widget_set_state diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c index 81cc67f483..7651763655 100644 --- a/gtk/gtkiconview.c +++ b/gtk/gtkiconview.c @@ -39,6 +39,7 @@ #include "gtkentry.h" #include "gtkcombobox.h" #include "gtktextbuffer.h" +#include "gtkscrollable.h" #include "gtksizerequest.h" #include "gtktreednd.h" #include "gtkprivate.h" @@ -134,6 +135,8 @@ struct _GtkIconViewPrivate GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; + gint min_display_width; + gint min_display_height; guint layout_idle_id; @@ -238,7 +241,13 @@ enum PROP_MARGIN, PROP_REORDERABLE, PROP_TOOLTIP_COLUMN, - PROP_ITEM_PADDING + PROP_ITEM_PADDING, + + /* For scrollable interface */ + PROP_HADJUSTMENT, + PROP_VADJUSTMENT, + PROP_MIN_DISPLAY_WIDTH, + PROP_MIN_DISPLAY_HEIGHT }; /* GObject vfuncs */ @@ -288,9 +297,6 @@ static void gtk_icon_view_forall (GtkContainer gpointer callback_data); /* GtkIconView vfuncs */ -static void gtk_icon_view_set_adjustments (GtkIconView *icon_view, - GtkAdjustment *hadj, - GtkAdjustment *vadj); static void gtk_icon_view_real_select_all (GtkIconView *icon_view); static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view); static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view); @@ -298,6 +304,15 @@ static void gtk_icon_view_real_toggle_cursor_item (GtkIconView static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view); /* Internal functions */ +static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view); +static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view); +static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view, + GtkAdjustment *adjustment); +static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view, + GtkAdjustment *adjustment); +static void gtk_icon_view_accessible_set_adjustment (GtkIconView *icon_view, + GtkOrientation orientation, + GtkAdjustment *adjustment); static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment, GtkIconView *icon_view); static void gtk_icon_view_layout (GtkIconView *icon_view); @@ -485,7 +500,8 @@ G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER, G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT, gtk_icon_view_cell_layout_init) G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - gtk_icon_view_buildable_init)) + gtk_icon_view_buildable_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL)) static void gtk_icon_view_class_init (GtkIconViewClass *klass) @@ -533,7 +549,6 @@ gtk_icon_view_class_init (GtkIconViewClass *klass) container_class->remove = gtk_icon_view_remove; container_class->forall = gtk_icon_view_forall; - klass->set_scroll_adjustments = gtk_icon_view_set_adjustments; klass->select_all = gtk_icon_view_real_select_all; klass->unselect_all = gtk_icon_view_real_unselect_all; klass->select_cursor_item = gtk_icon_view_real_select_cursor_item; @@ -782,6 +797,11 @@ gtk_icon_view_class_init (GtkIconViewClass *klass) 0, G_MAXINT, 6, GTK_PARAM_READWRITE)); + /* Scrollable interface properties */ + g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment"); + g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment"); + g_object_class_override_property (gobject_class, PROP_MIN_DISPLAY_WIDTH, "min-display-width"); + g_object_class_override_property (gobject_class, PROP_MIN_DISPLAY_HEIGHT, "min-display-height"); /* Style properties */ @@ -802,25 +822,6 @@ gtk_icon_view_class_init (GtkIconViewClass *klass) /* Signals */ /** - * GtkIconView::set-scroll-adjustments - * @horizontal: the horizontal #GtkAdjustment - * @vertical: the vertical #GtkAdjustment - * - * Set the scroll adjustments for the icon view. Usually scrolled containers - * like #GtkScrolledWindow will emit this signal to connect two instances - * of #GtkScrollbar to the scroll directions of the #GtkIconView. - */ - widget_class->set_scroll_adjustments_signal = - g_signal_new (I_("set-scroll-adjustments"), - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments), - NULL, NULL, - _gtk_marshal_VOID__OBJECT_OBJECT, - G_TYPE_NONE, 2, - GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); - - /** * GtkIconView::item-activated: * @iconview: the object on which the signal is emitted * @path: the #GtkTreePath for the activated item @@ -1118,8 +1119,6 @@ gtk_icon_view_init (GtkIconView *icon_view) gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE); - gtk_icon_view_set_adjustments (icon_view, NULL, NULL); - icon_view->priv->cell_list = NULL; icon_view->priv->n_cells = 0; icon_view->priv->cursor_cell = -1; @@ -1134,6 +1133,9 @@ gtk_icon_view_init (GtkIconView *icon_view) icon_view->priv->margin = 6; icon_view->priv->item_padding = 6; + icon_view->priv->min_display_width = -1; + icon_view->priv->min_display_height = -1; + icon_view->priv->draw_focus = TRUE; } @@ -1207,6 +1209,19 @@ gtk_icon_view_set_property (GObject *object, gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value)); break; + case PROP_HADJUSTMENT: + gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value)); + break; + case PROP_VADJUSTMENT: + gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value)); + break; + case PROP_MIN_DISPLAY_WIDTH: + icon_view->priv->min_display_width = g_value_get_int (value); + break; + case PROP_MIN_DISPLAY_HEIGHT: + icon_view->priv->min_display_height = g_value_get_int (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1272,6 +1287,19 @@ gtk_icon_view_get_property (GObject *object, g_value_set_int (value, icon_view->priv->item_padding); break; + case PROP_HADJUSTMENT: + g_value_set_object (value, icon_view->priv->hadjustment); + break; + case PROP_VADJUSTMENT: + g_value_set_object (value, icon_view->priv->vadjustment); + break; + case PROP_MIN_DISPLAY_WIDTH: + g_value_set_int (value, icon_view->priv->min_display_width); + break; + case PROP_MIN_DISPLAY_HEIGHT: + g_value_set_int (value, icon_view->priv->min_display_height); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1491,8 +1519,6 @@ gtk_icon_view_size_allocate (GtkWidget *widget, { GtkIconView *icon_view = GTK_ICON_VIEW (widget); - GtkAdjustment *hadjustment, *vadjustment; - gtk_widget_set_allocation (widget, allocation); if (gtk_widget_get_realized (widget)) @@ -1509,26 +1535,12 @@ gtk_icon_view_size_allocate (GtkWidget *widget, gtk_icon_view_allocate_children (icon_view); - hadjustment = icon_view->priv->hadjustment; - vadjustment = icon_view->priv->vadjustment; - - hadjustment->page_size = allocation->width; - hadjustment->page_increment = allocation->width * 0.9; - hadjustment->step_increment = allocation->width * 0.1; - hadjustment->lower = 0; - hadjustment->upper = MAX (allocation->width, icon_view->priv->width); - - if (hadjustment->value > hadjustment->upper - hadjustment->page_size) - gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size); - - vadjustment->page_size = allocation->height; - vadjustment->page_increment = allocation->height * 0.9; - vadjustment->step_increment = allocation->height * 0.1; - vadjustment->lower = 0; - vadjustment->upper = MAX (allocation->height, icon_view->priv->height); + /* Delay signal emission */ + g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment)); + g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment)); - if (vadjustment->value > vadjustment->upper - vadjustment->page_size) - gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size); + gtk_icon_view_set_hadjustment_values (icon_view); + gtk_icon_view_set_vadjustment_values (icon_view); if (gtk_widget_get_realized (widget) && icon_view->priv->scroll_to_path) @@ -1544,11 +1556,10 @@ gtk_icon_view_size_allocate (GtkWidget *widget, icon_view->priv->scroll_to_col_align); gtk_tree_path_free (path); } - else - { - gtk_adjustment_changed (hadjustment); - gtk_adjustment_changed (vadjustment); - } + + /* Emit any pending signals now */ + g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment)); + g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment)); } static gboolean @@ -2515,62 +2526,6 @@ gtk_icon_view_unselect_all_internal (GtkIconView *icon_view) /* GtkIconView signals */ static void -gtk_icon_view_set_adjustments (GtkIconView *icon_view, - GtkAdjustment *hadj, - GtkAdjustment *vadj) -{ - gboolean need_adjust = FALSE; - - if (hadj) - g_return_if_fail (GTK_IS_ADJUSTMENT (hadj)); - else - hadj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - if (vadj) - g_return_if_fail (GTK_IS_ADJUSTMENT (vadj)); - else - vadj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - - if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj)) - { - g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, icon_view); - g_object_unref (icon_view->priv->hadjustment); - } - - if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj)) - { - g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, icon_view); - g_object_unref (icon_view->priv->vadjustment); - } - - if (icon_view->priv->hadjustment != hadj) - { - icon_view->priv->hadjustment = hadj; - g_object_ref_sink (icon_view->priv->hadjustment); - - g_signal_connect (icon_view->priv->hadjustment, "value-changed", - G_CALLBACK (gtk_icon_view_adjustment_changed), - icon_view); - need_adjust = TRUE; - } - - if (icon_view->priv->vadjustment != vadj) - { - icon_view->priv->vadjustment = vadj; - g_object_ref_sink (icon_view->priv->vadjustment); - - g_signal_connect (icon_view->priv->vadjustment, "value-changed", - G_CALLBACK (gtk_icon_view_adjustment_changed), - icon_view); - need_adjust = TRUE; - } - - if (need_adjust) - gtk_icon_view_adjustment_changed (NULL, icon_view); -} - -static void gtk_icon_view_real_select_all (GtkIconView *icon_view) { gtk_icon_view_select_all (icon_view); @@ -2675,17 +2630,161 @@ gtk_icon_view_process_updates (GtkIconView *icon_view) } static void +gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view) +{ + GtkAllocation allocation; + GtkAdjustment *adj = icon_view->priv->hadjustment; + gdouble old_page_size; + gdouble old_upper; + gdouble old_value; + gdouble new_value; + gdouble new_upper; + + gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation); + + old_value = gtk_adjustment_get_value (adj); + old_upper = gtk_adjustment_get_upper (adj); + old_page_size = gtk_adjustment_get_page_size (adj); + new_upper = MAX (allocation.width, icon_view->priv->width); + + g_object_set (adj, + "lower", 0.0, + "upper", new_upper, + "page-size", (gdouble)allocation.width, + "step-increment", allocation.width * 0.1, + "page-increment", allocation.width * 0.9, + NULL); + + if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL) + { + /* Make sure no scrolling occurs for RTL locales also (if possible) */ + /* Quick explanation: + * In LTR locales, leftmost portion of visible rectangle should stay + * fixed, which means left edge of scrollbar thumb should remain fixed + * and thus adjustment's value should stay the same. + * + * In RTL locales, we want to keep rightmost portion of visible + * rectangle fixed. This means right edge of thumb should remain fixed. + * In this case, upper - value - page_size should remain constant. + */ + new_value = (new_upper - allocation.width) - + (old_upper - old_value - old_page_size); + new_value = CLAMP (new_value, 0, new_upper - allocation.width); + } + else + new_value = CLAMP (old_value, 0, new_upper - allocation.width); + + if (new_value != old_value) + gtk_adjustment_set_value (adj, new_value); +} + +static void +gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view) +{ + GtkAllocation allocation; + GtkAdjustment *adj = icon_view->priv->vadjustment; + gdouble old_value; + gdouble new_value; + gdouble new_upper; + + gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation); + + old_value = gtk_adjustment_get_value (adj); + new_upper = MAX (allocation.height, icon_view->priv->height); + + g_object_set (adj, + "lower", 0.0, + "upper", new_upper, + "page-size", (gdouble)allocation.height, + "step-increment", allocation.height * 0.1, + "page-increment", allocation.height * 0.9, + NULL); + + new_value = CLAMP (old_value, 0, new_upper - allocation.height); + if (new_value != old_value) + gtk_adjustment_set_value (adj, new_value); +} + +static void +gtk_icon_view_set_hadjustment (GtkIconView *icon_view, + GtkAdjustment *adjustment) +{ + GtkIconViewPrivate *priv = icon_view->priv; + + if (adjustment && priv->hadjustment == adjustment) + return; + + if (priv->hadjustment != NULL) + { + g_signal_handlers_disconnect_matched (priv->hadjustment, + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, icon_view); + g_object_unref (priv->hadjustment); + } + + if (!adjustment) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, + 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view); + priv->hadjustment = g_object_ref_sink (adjustment); + gtk_icon_view_set_hadjustment_values (icon_view); + + gtk_icon_view_accessible_set_adjustment (icon_view, + GTK_ORIENTATION_HORIZONTAL, + priv->hadjustment); + + g_object_notify (G_OBJECT (icon_view), "hadjustment"); +} + +static void +gtk_icon_view_set_vadjustment (GtkIconView *icon_view, + GtkAdjustment *adjustment) +{ + GtkIconViewPrivate *priv = icon_view->priv; + + if (adjustment && priv->vadjustment == adjustment) + return; + + if (priv->vadjustment != NULL) + { + g_signal_handlers_disconnect_matched (priv->vadjustment, + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, icon_view); + g_object_unref (priv->vadjustment); + } + + if (!adjustment) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, + 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view); + priv->vadjustment = g_object_ref_sink (adjustment); + gtk_icon_view_set_vadjustment_values (icon_view); + + gtk_icon_view_accessible_set_adjustment (icon_view, + GTK_ORIENTATION_VERTICAL, + priv->vadjustment); + + g_object_notify (G_OBJECT (icon_view), "vadjustment"); +} + +static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment, - GtkIconView *icon_view) + GtkIconView *icon_view) { + GtkIconViewPrivate *priv = icon_view->priv; + if (gtk_widget_get_realized (GTK_WIDGET (icon_view))) { - gdk_window_move (icon_view->priv->bin_window, - - icon_view->priv->hadjustment->value, - - icon_view->priv->vadjustment->value); + gdk_window_move (priv->bin_window, + - priv->hadjustment->value, + - priv->vadjustment->value); if (icon_view->priv->doing_rubberband) - gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view)); + gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view)); gtk_icon_view_process_updates (icon_view); } @@ -9124,60 +9223,53 @@ gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment, } static void -gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget, - GtkAdjustment *hadj, - GtkAdjustment *vadj) +gtk_icon_view_accessible_set_adjustment (GtkIconView *icon_view, + GtkOrientation orientation, + GtkAdjustment *adjustment) { AtkObject *atk_obj; GtkIconViewAccessiblePrivate *priv; + GtkAdjustment **old_adj_ptr; - atk_obj = gtk_widget_get_accessible (widget); + atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view)); priv = gtk_icon_view_accessible_get_priv (atk_obj); - if (priv->old_hadj != hadj) + /* Adjustments are set for the first time in constructor and priv is not + * initialized at that time, so skip this first setting. */ + if (!priv) + return; + + if (orientation == GTK_ORIENTATION_HORIZONTAL) { - if (priv->old_hadj) - { - g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj), - (gpointer *)&priv->old_hadj); - - g_signal_handlers_disconnect_by_func (priv->old_hadj, - (gpointer) gtk_icon_view_accessible_adjustment_changed, - widget); - } - priv->old_hadj = hadj; - if (priv->old_hadj) - { - g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), - (gpointer *)&priv->old_hadj); - g_signal_connect (hadj, - "value-changed", - G_CALLBACK (gtk_icon_view_accessible_adjustment_changed), - widget); - } + if (priv->old_hadj == adjustment) + return; + + old_adj_ptr = &priv->old_hadj; + } + else + { + if (priv->old_vadj == adjustment) + return; + + old_adj_ptr = &priv->old_vadj; } - if (priv->old_vadj != vadj) + + /* Disconnect signal handlers */ + if (*old_adj_ptr) { - if (priv->old_vadj) - { - g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj), - (gpointer *)&priv->old_vadj); - - g_signal_handlers_disconnect_by_func (priv->old_vadj, - (gpointer) gtk_icon_view_accessible_adjustment_changed, - widget); - } - priv->old_vadj = vadj; - if (priv->old_vadj) - { - g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), - (gpointer *)&priv->old_vadj); - g_signal_connect (vadj, - "value-changed", - G_CALLBACK (gtk_icon_view_accessible_adjustment_changed), - widget); - } + g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr), + (gpointer *)&priv->old_hadj); + g_signal_handlers_disconnect_by_func (*old_adj_ptr, + gtk_icon_view_accessible_adjustment_changed, + icon_view); } + + /* Connect signal */ + *old_adj_ptr = adjustment; + g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr); + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_icon_view_accessible_adjustment_changed), + icon_view); } static void @@ -9480,27 +9572,13 @@ gtk_icon_view_accessible_initialize (AtkObject *accessible, icon_view = GTK_ICON_VIEW (data); if (icon_view->priv->hadjustment) - { - priv->old_hadj = icon_view->priv->hadjustment; - g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj); - g_signal_connect (icon_view->priv->hadjustment, - "value-changed", - G_CALLBACK (gtk_icon_view_accessible_adjustment_changed), - icon_view); - } + gtk_icon_view_accessible_set_adjustment (icon_view, + GTK_ORIENTATION_HORIZONTAL, + icon_view->priv->hadjustment); if (icon_view->priv->vadjustment) - { - priv->old_vadj = icon_view->priv->vadjustment; - g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj); - g_signal_connect (icon_view->priv->vadjustment, - "value-changed", - G_CALLBACK (gtk_icon_view_accessible_adjustment_changed), - icon_view); - } - g_signal_connect_after (data, - "set-scroll-adjustments", - G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments), - NULL); + gtk_icon_view_accessible_set_adjustment (icon_view, + GTK_ORIENTATION_VERTICAL, + icon_view->priv->vadjustment); g_signal_connect (data, "notify", G_CALLBACK (gtk_icon_view_accessible_notify_gtk), diff --git a/gtk/gtkiconview.h b/gtk/gtkiconview.h index 76409fbdf4..485a0df6b8 100644 --- a/gtk/gtkiconview.h +++ b/gtk/gtkiconview.h @@ -89,10 +89,6 @@ struct _GtkIconViewClass { GtkContainerClass parent_class; - void (* set_scroll_adjustments) (GtkIconView *icon_view, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - void (* item_activated) (GtkIconView *icon_view, GtkTreePath *path); void (* selection_changed) (GtkIconView *icon_view); @@ -156,7 +152,6 @@ void gtk_icon_view_set_item_padding (GtkIconView *icon_view, gint item_padding); gint gtk_icon_view_get_item_padding (GtkIconView *icon_view); - GtkTreePath * gtk_icon_view_get_path_at_pos (GtkIconView *icon_view, gint x, gint y); diff --git a/gtk/gtklayout.c b/gtk/gtklayout.c index 930e98d272..1a4a536d55 100644 --- a/gtk/gtklayout.c +++ b/gtk/gtklayout.c @@ -30,6 +30,8 @@ #include "config.h" +#undef GTK_DISABLE_DEPRECATED + #include "gtklayout.h" #include "gdkconfig.h" @@ -37,6 +39,7 @@ #include "gtkprivate.h" #include "gtkintl.h" #include "gtkmarshalers.h" +#include "gtkscrollable.h" typedef struct _GtkLayoutChild GtkLayoutChild; @@ -49,6 +52,9 @@ struct _GtkLayoutPrivate GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; + gint min_display_width; + gint min_display_height; + /* Properties */ GdkVisibilityState visibility; @@ -72,6 +78,8 @@ enum { PROP_0, PROP_HADJUSTMENT, PROP_VADJUSTMENT, + PROP_MIN_DISPLAY_WIDTH, + PROP_MIN_DISPLAY_HEIGHT, PROP_WIDTH, PROP_HEIGHT }; @@ -90,9 +98,6 @@ static void gtk_layout_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static GObject *gtk_layout_constructor (GType type, - guint n_properties, - GObjectConstructParam *properties); static void gtk_layout_finalize (GObject *object); static void gtk_layout_realize (GtkWidget *widget); static void gtk_layout_unrealize (GtkWidget *widget); @@ -111,9 +116,6 @@ static void gtk_layout_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); -static void gtk_layout_set_adjustments (GtkLayout *layout, - GtkAdjustment *hadj, - GtkAdjustment *vadj); static void gtk_layout_set_child_property (GtkContainer *container, GtkWidget *child, guint property_id, @@ -131,11 +133,11 @@ static void gtk_layout_adjustment_changed (GtkAdjustment *adjustment, static void gtk_layout_style_set (GtkWidget *widget, GtkStyle *old_style); -static void gtk_layout_set_adjustment_upper (GtkAdjustment *adj, - gdouble upper, - gboolean always_emit_changed); +static void gtk_layout_set_hadjustment_values (GtkLayout *layout); +static void gtk_layout_set_vadjustment_values (GtkLayout *layout); -G_DEFINE_TYPE (GtkLayout, gtk_layout, GTK_TYPE_CONTAINER) +G_DEFINE_TYPE_WITH_CODE (GtkLayout, gtk_layout, GTK_TYPE_CONTAINER, + G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL)) /* Public interface */ @@ -195,6 +197,8 @@ gtk_layout_get_bin_window (GtkLayout *layout) * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details. * * Return value: (transfer none): horizontal scroll adjustment + * + * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment() **/ GtkAdjustment* gtk_layout_get_hadjustment (GtkLayout *layout) @@ -215,6 +219,8 @@ gtk_layout_get_hadjustment (GtkLayout *layout) * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details. * * Return value: (transfer none): vertical scroll adjustment + * + * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment() **/ GtkAdjustment* gtk_layout_get_vadjustment (GtkLayout *layout) @@ -224,73 +230,59 @@ gtk_layout_get_vadjustment (GtkLayout *layout) return layout->priv->vadjustment; } -static GtkAdjustment * -new_default_adjustment (void) +static void +gtk_layout_set_hadjustment_values (GtkLayout *layout) { - return gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + GtkLayoutPrivate *priv = layout->priv; + GtkAllocation allocation; + GtkAdjustment *adj = priv->hadjustment; + gdouble old_value; + gdouble new_value; + gdouble new_upper; + + gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation); + + old_value = gtk_adjustment_get_value (adj); + new_upper = MAX (allocation.width, priv->width); + + g_object_set (adj, + "lower", 0.0, + "upper", new_upper, + "page-size", (gdouble)allocation.width, + "step-increment", allocation.width * 0.1, + "page-increment", allocation.width * 0.9, + NULL); + + new_value = CLAMP (old_value, 0, new_upper - allocation.width); + if (new_value != old_value) + gtk_adjustment_set_value (adj, new_value); } -static void -gtk_layout_set_adjustments (GtkLayout *layout, - GtkAdjustment *hadj, - GtkAdjustment *vadj) +static void +gtk_layout_set_vadjustment_values (GtkLayout *layout) { - GtkLayoutPrivate *priv = layout->priv; - gboolean need_adjust = FALSE; - - if (hadj) - g_return_if_fail (GTK_IS_ADJUSTMENT (hadj)); - else if (priv->hadjustment) - hadj = new_default_adjustment (); - if (vadj) - g_return_if_fail (GTK_IS_ADJUSTMENT (vadj)); - else if (priv->vadjustment) - vadj = new_default_adjustment (); - - if (priv->hadjustment && (priv->hadjustment != hadj)) - { - g_signal_handlers_disconnect_by_func (priv->hadjustment, - gtk_layout_adjustment_changed, - layout); - g_object_unref (priv->hadjustment); - } - - if (priv->vadjustment && (priv->vadjustment != vadj)) - { - g_signal_handlers_disconnect_by_func (priv->vadjustment, - gtk_layout_adjustment_changed, - layout); - g_object_unref (priv->vadjustment); - } - - if (priv->hadjustment != hadj) - { - priv->hadjustment = hadj; - g_object_ref_sink (priv->hadjustment); - gtk_layout_set_adjustment_upper (priv->hadjustment, priv->width, FALSE); - - g_signal_connect (priv->hadjustment, "value-changed", - G_CALLBACK (gtk_layout_adjustment_changed), - layout); - need_adjust = TRUE; - } - - if (priv->vadjustment != vadj) - { - priv->vadjustment = vadj; - g_object_ref_sink (priv->vadjustment); - gtk_layout_set_adjustment_upper (priv->vadjustment, priv->height, FALSE); - - g_signal_connect (priv->vadjustment, "value-changed", - G_CALLBACK (gtk_layout_adjustment_changed), - layout); - need_adjust = TRUE; - } - - /* vadj or hadj can be NULL while constructing; don't emit a signal - then */ - if (need_adjust && vadj && hadj) - gtk_layout_adjustment_changed (NULL, layout); + GtkAllocation allocation; + GtkAdjustment *adj = layout->priv->vadjustment; + gdouble old_value; + gdouble new_value; + gdouble new_upper; + + gtk_widget_get_allocation (GTK_WIDGET (layout), &allocation); + + old_value = gtk_adjustment_get_value (adj); + new_upper = MAX (allocation.height, layout->priv->height); + + g_object_set (adj, + "lower", 0.0, + "upper", new_upper, + "page-size", (gdouble)allocation.height, + "step-increment", allocation.height * 0.1, + "page-increment", allocation.height * 0.9, + NULL); + + new_value = CLAMP (old_value, 0, new_upper - allocation.height); + if (new_value != old_value) + gtk_adjustment_set_value (adj, new_value); } static void @@ -313,22 +305,43 @@ gtk_layout_finalize (GObject *object) * Sets the horizontal scroll adjustment for the layout. * * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details. - * + * + * Deprecated: 3.0: Use gtk_scrollable_set_hadjustment() **/ -void +void gtk_layout_set_hadjustment (GtkLayout *layout, - GtkAdjustment *adjustment) + GtkAdjustment *adjustment) { GtkLayoutPrivate *priv; g_return_if_fail (GTK_IS_LAYOUT (layout)); + g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment)); priv = layout->priv; - gtk_layout_set_adjustments (layout, adjustment, priv->vadjustment); + if (adjustment && priv->hadjustment == adjustment) + return; + + if (priv->hadjustment != NULL) + { + g_signal_handlers_disconnect_by_func (priv->hadjustment, + gtk_layout_adjustment_changed, + layout); + g_object_unref (priv->hadjustment); + } + + if (adjustment == NULL) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_layout_adjustment_changed), layout); + priv->hadjustment = g_object_ref_sink (adjustment); + gtk_layout_set_hadjustment_values (layout); + g_object_notify (G_OBJECT (layout), "hadjustment"); } - + + /** * gtk_layout_set_vadjustment: * @layout: a #GtkLayout @@ -337,19 +350,39 @@ gtk_layout_set_hadjustment (GtkLayout *layout, * Sets the vertical scroll adjustment for the layout. * * See #GtkScrolledWindow, #GtkScrollbar, #GtkAdjustment for details. - * + * + * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment() **/ -void +void gtk_layout_set_vadjustment (GtkLayout *layout, - GtkAdjustment *adjustment) + GtkAdjustment *adjustment) { GtkLayoutPrivate *priv; g_return_if_fail (GTK_IS_LAYOUT (layout)); + g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment)); priv = layout->priv; - gtk_layout_set_adjustments (layout, priv->hadjustment, adjustment); + if (adjustment && priv->vadjustment == adjustment) + return; + + if (priv->vadjustment != NULL) + { + g_signal_handlers_disconnect_by_func (priv->vadjustment, + gtk_layout_adjustment_changed, + layout); + g_object_unref (priv->vadjustment); + } + + if (adjustment == NULL) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_layout_adjustment_changed), layout); + priv->vadjustment = g_object_ref_sink (adjustment); + gtk_layout_set_vadjustment_values (layout); + g_object_notify (G_OBJECT (layout), "vadjustment"); } @@ -472,34 +505,6 @@ gtk_layout_move (GtkLayout *layout, gtk_layout_move_internal (layout, child_widget, TRUE, x, TRUE, y); } -static void -gtk_layout_set_adjustment_upper (GtkAdjustment *adj, - gdouble upper, - gboolean always_emit_changed) -{ - gboolean changed = FALSE; - gboolean value_changed = FALSE; - - gdouble min = MAX (0., upper - adj->page_size); - - if (upper != adj->upper) - { - adj->upper = upper; - changed = TRUE; - } - - if (adj->value > min) - { - adj->value = min; - value_changed = TRUE; - } - - if (changed || always_emit_changed) - gtk_adjustment_changed (adj); - if (value_changed) - gtk_adjustment_value_changed (adj); -} - /** * gtk_layout_set_size: * @layout: a #GtkLayout @@ -535,11 +540,6 @@ gtk_layout_set_size (GtkLayout *layout, } g_object_thaw_notify (G_OBJECT (layout)); - if (priv->hadjustment) - gtk_layout_set_adjustment_upper (priv->hadjustment, priv->width, FALSE); - if (priv->vadjustment) - gtk_layout_set_adjustment_upper (priv->vadjustment, priv->height, FALSE); - if (gtk_widget_get_realized (widget)) { GtkAllocation allocation; @@ -549,6 +549,9 @@ gtk_layout_set_size (GtkLayout *layout, height = MAX (height, allocation.height); gdk_window_resize (priv->bin_window, width, height); } + + gtk_layout_set_hadjustment_values (layout); + gtk_layout_set_vadjustment_values (layout); } /** @@ -594,7 +597,6 @@ gtk_layout_class_init (GtkLayoutClass *class) gobject_class->set_property = gtk_layout_set_property; gobject_class->get_property = gtk_layout_get_property; gobject_class->finalize = gtk_layout_finalize; - gobject_class->constructor = gtk_layout_constructor; container_class->set_child_property = gtk_layout_set_child_property; container_class->get_child_property = gtk_layout_get_child_property; @@ -619,21 +621,19 @@ gtk_layout_class_init (GtkLayoutClass *class) 0, GTK_PARAM_READWRITE)); - g_object_class_install_property (gobject_class, - PROP_HADJUSTMENT, - g_param_spec_object ("hadjustment", - P_("Horizontal adjustment"), - P_("The GtkAdjustment for the horizontal position"), - GTK_TYPE_ADJUSTMENT, - GTK_PARAM_READWRITE)); - - g_object_class_install_property (gobject_class, - PROP_VADJUSTMENT, - g_param_spec_object ("vadjustment", - P_("Vertical adjustment"), - P_("The GtkAdjustment for the vertical position"), - GTK_TYPE_ADJUSTMENT, - GTK_PARAM_READWRITE)); + /* Scrollable interface */ + g_object_class_override_property (gobject_class, + PROP_HADJUSTMENT, + "hadjustment"); + g_object_class_override_property (gobject_class, + PROP_VADJUSTMENT, + "vadjustment"); + g_object_class_override_property (gobject_class, + PROP_MIN_DISPLAY_WIDTH, + "min-display-width"); + g_object_class_override_property (gobject_class, + PROP_MIN_DISPLAY_HEIGHT, + "min-display-height"); g_object_class_install_property (gobject_class, PROP_WIDTH, @@ -665,28 +665,6 @@ gtk_layout_class_init (GtkLayoutClass *class) container_class->remove = gtk_layout_remove; container_class->forall = gtk_layout_forall; - class->set_scroll_adjustments = gtk_layout_set_adjustments; - - /** - * GtkLayout::set-scroll-adjustments - * @horizontal: the horizontal #GtkAdjustment - * @vertical: the vertical #GtkAdjustment - * - * Set the scroll adjustments for the layout. Usually scrolled containers - * like #GtkScrolledWindow will emit this signal to connect two instances - * of #GtkScrollbar to the scroll directions of the #GtkLayout. - */ - widget_class->set_scroll_adjustments_signal = - g_signal_new (I_("set-scroll-adjustments"), - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkLayoutClass, set_scroll_adjustments), - NULL, NULL, - _gtk_marshal_VOID__OBJECT_OBJECT, - G_TYPE_NONE, 2, - GTK_TYPE_ADJUSTMENT, - GTK_TYPE_ADJUSTMENT); - g_type_class_add_private (class, sizeof (GtkLayoutPrivate)); } @@ -707,6 +685,12 @@ gtk_layout_get_property (GObject *object, case PROP_VADJUSTMENT: g_value_set_object (value, priv->vadjustment); break; + case PROP_MIN_DISPLAY_WIDTH: + g_value_set_int (value, priv->min_display_width); + break; + case PROP_MIN_DISPLAY_HEIGHT: + g_value_set_int (value, priv->min_display_height); + break; case PROP_WIDTH: g_value_set_uint (value, priv->width); break; @@ -738,6 +722,12 @@ gtk_layout_set_property (GObject *object, gtk_layout_set_vadjustment (layout, (GtkAdjustment*) g_value_get_object (value)); break; + case PROP_MIN_DISPLAY_WIDTH: + priv->min_display_width = g_value_get_int (value); + break; + case PROP_MIN_DISPLAY_HEIGHT: + priv->min_display_height = g_value_get_int (value); + break; case PROP_WIDTH: gtk_layout_set_size (layout, g_value_get_uint (value), priv->height); @@ -821,6 +811,8 @@ gtk_layout_init (GtkLayout *layout) priv->hadjustment = NULL; priv->vadjustment = NULL; + priv->min_display_width = -1; + priv->min_display_height = -1; priv->bin_window = NULL; @@ -831,32 +823,6 @@ gtk_layout_init (GtkLayout *layout) priv->freeze_count = 0; } -static GObject * -gtk_layout_constructor (GType type, - guint n_properties, - GObjectConstructParam *properties) -{ - GtkLayoutPrivate *priv; - GtkLayout *layout; - GObject *object; - GtkAdjustment *hadj, *vadj; - - object = G_OBJECT_CLASS (gtk_layout_parent_class)->constructor (type, - n_properties, - properties); - - layout = GTK_LAYOUT (object); - priv = layout->priv; - - hadj = priv->hadjustment ? priv->hadjustment : new_default_adjustment (); - vadj = priv->vadjustment ? priv->vadjustment : new_default_adjustment (); - - if (!priv->hadjustment || !priv->vadjustment) - gtk_layout_set_adjustments (layout, hadj, vadj); - - return object; -} - /* Widget methods */ @@ -1010,17 +976,8 @@ gtk_layout_size_allocate (GtkWidget *widget, MAX (priv->height, allocation->height)); } - priv->hadjustment->page_size = allocation->width; - priv->hadjustment->page_increment = allocation->width * 0.9; - priv->hadjustment->lower = 0; - /* set_adjustment_upper() emits ::changed */ - gtk_layout_set_adjustment_upper (priv->hadjustment, MAX (allocation->width, priv->width), TRUE); - - priv->vadjustment->page_size = allocation->height; - priv->vadjustment->page_increment = allocation->height * 0.9; - priv->vadjustment->lower = 0; - priv->vadjustment->upper = MAX (allocation->height, priv->height); - gtk_layout_set_adjustment_upper (priv->vadjustment, MAX (allocation->height, priv->height), TRUE); + gtk_layout_set_hadjustment_values (layout); + gtk_layout_set_vadjustment_values (layout); } static gboolean diff --git a/gtk/gtklayout.h b/gtk/gtklayout.h index d29e7331ab..5c4f8b284e 100644 --- a/gtk/gtklayout.h +++ b/gtk/gtklayout.h @@ -66,10 +66,6 @@ struct _GtkLayoutClass { GtkContainerClass parent_class; - void (*set_scroll_adjustments) (GtkLayout *layout, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - /* Padding for future expansion */ void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); @@ -98,6 +94,8 @@ void gtk_layout_get_size (GtkLayout *layout, guint *width, guint *height); +#ifndef GTK_DISABLE_DEPRECATED + GtkAdjustment* gtk_layout_get_hadjustment (GtkLayout *layout); GtkAdjustment* gtk_layout_get_vadjustment (GtkLayout *layout); void gtk_layout_set_hadjustment (GtkLayout *layout, @@ -105,6 +103,8 @@ void gtk_layout_set_hadjustment (GtkLayout *layout, void gtk_layout_set_vadjustment (GtkLayout *layout, GtkAdjustment *adjustment); +#endif + G_END_DECLS #endif /* __GTK_LAYOUT_H__ */ diff --git a/gtk/gtkscrollable.c b/gtk/gtkscrollable.c new file mode 100644 index 0000000000..33744456f2 --- /dev/null +++ b/gtk/gtkscrollable.c @@ -0,0 +1,327 @@ +/* gtkscrollable.c + * Copyright (C) 2008 Tadej Borovšak <tadeboro@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:gtkscrollable + * @Short_Description: An interface for scrollable widgets + * @Title: GtkScrollable + * + * #GtkScrollable is interface that is implemented by widgets with native + * scrolling ability. + * + * To implement this interface, all one needs to do is to override + * #GtkScrollable:hadjustment and #GtkScrollable:vadjustment properties. + * + * <refsect2> + * <title>Creating a scrollable widget</title> + * <para> + * There are some common things all scrollable widgets will need to do. + * + * <orderedlist> + * <listitem> + * <para> + * When parent sets adjustments, widget needs to populate adjustment's + * #GtkAdjustment:lower, #GtkAdjustment:upper, + * #GtkAdjustment:step-increment, #GtkAdjustment:page-increment and + * #GtkAdjustment:page-size properties and connect to + * #GtkAdjustment::value-changed signal. + * </para> + * </listitem> + * <listitem> + * <para> + * When parent allocates space to child, scrollable widget needs to update + * properties listed under 1 with new values. + * </para> + * </listitem> + * <listitem> + * <para> + * When any of the adjustments emits #GtkAdjustment::value-changed signal, + * scrollable widget needs to scroll it's contents. + * </para> + * </listitem> + * </orderedlist> + * </para> + * </refsect2> + */ + +#include "config.h" + +#include "gtkscrollable.h" +#include "gtkprivate.h" +#include "gtkintl.h" + +G_DEFINE_INTERFACE (GtkScrollable, gtk_scrollable, G_TYPE_OBJECT) + +static void +gtk_scrollable_default_init (GtkScrollableInterface *iface) +{ + GParamSpec *pspec; + + /** + * GtkScrollable:hadjustment: + * + * Horizontal #GtkAdjustment of scrollable widget. This adjustment is + * shared between scrollable widget and it's parent. + * + * Since: 3.0 + */ + pspec = g_param_spec_object ("hadjustment", + P_("Horizontal adjustment"), + P_("Horizontal adjustment that is shared " + "between scrollable widget and it's " + "controller"), + GTK_TYPE_ADJUSTMENT, + GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT); + g_object_interface_install_property (iface, pspec); + + /** + * GtkScrollable:vadjustment: + * + * Verical #GtkAdjustment of scrollable widget. This adjustment is shared + * between scrollable widget and it's parent. + * + * Since: 3.0 + */ + pspec = g_param_spec_object ("vadjustment", + P_("Vertical adjustment"), + P_("Vertical adjustment that is shared " + "between scrollable widget and it's " + "controller"), + GTK_TYPE_ADJUSTMENT, + GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT); + g_object_interface_install_property (iface, pspec); + + + /** + * GtkScrollable:min-display-width: + * + * Minimum width to display in the parent scrolled window, this + * can be greater or less than the scrollable widget's real minimum + * width. + * + * Since: 3.0 + */ + pspec = g_param_spec_int ("min-display-width", + P_("Minimum Display Width"), + P_("Minimum width to display in the parent scrolled window"), + -1, G_MAXINT, -1, + GTK_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); + + + /** + * GtkScrollable:min-display-height: + * + * Minimum height to display in the parent scrolled window, this + * can be greater or less than the scrollable widget's real minimum + * height. + * + * Since: 3.0 + */ + pspec = g_param_spec_int ("min-display-height", + P_("Minimum Display Height"), + P_("Minimum height to display in the parent scrolled window"), + -1, G_MAXINT, -1, + GTK_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); + +} + +/** + * gtk_scrollable_get_hadjustment: + * @scrollable: a #GtkScrollable + * + * Retrieves the #GtkAdjustment, used for horizontal scrolling. + * + * Return value: (transfer none): horizontal #GtkAdjustment. + * + * Since: 3.0 + **/ +GtkAdjustment * +gtk_scrollable_get_hadjustment (GtkScrollable *scrollable) +{ + GtkAdjustment *adj = NULL; + + g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL); + + g_object_get (scrollable, "hadjustment", &adj, NULL); + + /* Horrid hack; g_object_get() returns a new reference but + * that contradicts the memory management conventions + * for accessors. + */ + if (adj) + g_object_unref (adj); + + return adj; +} + +/** + * gtk_scrollable_set_hadjustment: + * @scrollable: a #GtkScrollable + * @hadjustment: (allow-none): a #GtkAdjustment + * + * Sets the horizontal adjustment of the #GtkScrollable. + * + * Since: 3.0 + **/ +void +gtk_scrollable_set_hadjustment (GtkScrollable *scrollable, + GtkAdjustment *hadjustment) +{ + g_return_if_fail (GTK_IS_SCROLLABLE (scrollable)); + g_return_if_fail (hadjustment == NULL || GTK_IS_ADJUSTMENT (hadjustment)); + + g_object_set (scrollable, "hadjustment", hadjustment, NULL); +} + +/** + * gtk_scrollable_get_vadjustment: + * @scrollable: a #GtkScrollable + * + * Retrieves the #GtkAdjustment, used for vertical scrolling. + * + * Return value: (transfer none): vertical #GtkAdjustment. + * + * Since: 3.0 + **/ +GtkAdjustment * +gtk_scrollable_get_vadjustment (GtkScrollable *scrollable) +{ + GtkAdjustment *adj = NULL; + + g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL); + + g_object_get (scrollable, "vadjustment", &adj, NULL); + + /* Horrid hack; g_object_get() returns a new reference but + * that contradicts the memory management conventions + * for accessors. + */ + if (adj) + g_object_unref (adj); + + return adj; +} + +/** + * gtk_scrollable_set_vadjustment: + * @scrollable: a #GtkScrollable + * @vadjustment: (allow-none): a #GtkAdjustment + * + * Sets the vertical adjustment of the #GtkScrollable. + * + * Since: 3.0 + **/ +void +gtk_scrollable_set_vadjustment (GtkScrollable *scrollable, + GtkAdjustment *vadjustment) +{ + g_return_if_fail (GTK_IS_SCROLLABLE (scrollable)); + g_return_if_fail (vadjustment == NULL || GTK_IS_ADJUSTMENT (vadjustment)); + + g_object_set (scrollable, "vadjustment", vadjustment, NULL); +} + + +/** + * gtk_scrollable_get_min_display_width: + * @scrollable: a #GtkScrollable + * + * Retrieves the minimum width of content to display in the + * parent scrolled window. + * + * Return value: The minimum display width. + * + * Since: 3.0 + **/ +gint +gtk_scrollable_get_min_display_width (GtkScrollable *scrollable) +{ + gint width; + + g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL); + + g_object_get (scrollable, "min-display-width", &width, NULL); + + return width; +} + +/** + * gtk_scrollable_set_min_display_width: + * @scrollable: a #GtkScrollable + * @width: the minimum width of scrollable content to display + * + * Sets the minimum width of content to display in the parent scrolled window, + * this can be greater or less than the scrollable widget's real minimum + * width. + * + * Since: 3.0 + **/ +void +gtk_scrollable_set_min_display_width (GtkScrollable *scrollable, + gint width) +{ + g_return_if_fail (GTK_IS_SCROLLABLE (scrollable)); + + g_object_set (scrollable, "min-display-width", width, NULL); +} + +/** + * gtk_scrollable_get_min_display_height: + * @scrollable: a #GtkScrollable + * + * Retrieves the minimum height of content to display in the + * parent scrolled window. + * + * Return value: The minimum display height. + * + * Since: 3.0 + **/ +gint +gtk_scrollable_get_min_display_height (GtkScrollable *scrollable) +{ + gint height; + + g_return_val_if_fail (GTK_IS_SCROLLABLE (scrollable), NULL); + + g_object_get (scrollable, "min-display-height", &height, NULL); + + return height; +} + +/** + * gtk_scrollable_set_min_display_height: + * @scrollable: a #GtkScrollable + * @height: the minimum height of scrollable content to display + * + * Sets the minimum height of content to display in the parent scrolled window, + * this can be greater or less than the scrollable widget's real minimum + * height. + * + * Since: 3.0 + **/ +void +gtk_scrollable_set_min_display_height (GtkScrollable *scrollable, + gint height) +{ + g_return_if_fail (GTK_IS_SCROLLABLE (scrollable)); + + g_object_set (scrollable, "min-display-height", height, NULL); +} diff --git a/gtk/gtkscrollable.h b/gtk/gtkscrollable.h new file mode 100644 index 0000000000..ce881a009e --- /dev/null +++ b/gtk/gtkscrollable.h @@ -0,0 +1,61 @@ +/* gtkscrollable.h + * Copyright (C) 2008 Tadej Borovšak <tadeboro@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only <gtk/gtk.h> can be included directly." +#endif + +#ifndef __GTK_SCROLLABLE_H__ +#define __GTK_SCROLLABLE_H__ + +#include <gtk/gtkadjustment.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_SCROLLABLE (gtk_scrollable_get_type ()) +#define GTK_SCROLLABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SCROLLABLE, GtkScrollable)) +#define GTK_IS_SCROLLABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SCROLLABLE)) +#define GTK_SCROLLABLE_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_SCROLLABLE, GtkScrollableInterface)) + +typedef struct _GtkScrollable GtkScrollable; /* Dummy */ +typedef struct _GtkScrollableInterface GtkScrollableInterface; + +struct _GtkScrollableInterface +{ + GTypeInterface base_iface; +}; + +/* Public API */ +GType gtk_scrollable_get_type (void) G_GNUC_CONST; +GtkAdjustment *gtk_scrollable_get_hadjustment (GtkScrollable *scrollable); +void gtk_scrollable_set_hadjustment (GtkScrollable *scrollable, + GtkAdjustment *hadjustment); +GtkAdjustment *gtk_scrollable_get_vadjustment (GtkScrollable *scrollable); +void gtk_scrollable_set_vadjustment (GtkScrollable *scrollable, + GtkAdjustment *vadjustment); +gint gtk_scrollable_get_min_display_width (GtkScrollable *scrollable); +void gtk_scrollable_set_min_display_width (GtkScrollable *scrollable, + gint width); +gint gtk_scrollable_get_min_display_height (GtkScrollable *scrollable); +void gtk_scrollable_set_min_display_height (GtkScrollable *scrollable, + gint height); + +G_END_DECLS + +#endif /* __GTK_SCROLLABLE_H__ */ diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index 191c3c3921..483a348757 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -29,6 +29,7 @@ #include <gdk/gdkkeysyms.h> #include "gtkbindings.h" #include "gtkmarshalers.h" +#include "gtkscrollable.h" #include "gtkscrolledwindow.h" #include "gtkwindow.h" #include "gtktypeutils.h" @@ -40,7 +41,7 @@ * SECTION:gtkscrolledwindow * @Short_description: Adds scrollbars to its child widget * @Title: GtkScrolledWindow - * @See_also: #GtkViewport, #GtkAdjustment, #GtkWidgetClass + * @See_also: #GtkScrollable, #GtkViewport, #GtkAdjustment * * #GtkScrolledWindow is a #GtkBin subclass: it's a container * the accepts a single child widget. #GtkScrolledWindow adds scrollbars @@ -48,16 +49,7 @@ * child widget. * * The scrolled window can work in two ways. Some widgets have native - * scrolling support; these widgets have "slots" for #GtkAdjustment - * objects. - * <footnote><para>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.)</para></footnote> + * scrolling support; these widgets implement the #GtkScrollable interface. * Widgets with native scroll support include #GtkTreeView, #GtkTextView, * and #GtkLayout. * @@ -549,7 +541,7 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, else { GtkAdjustment *old_adjustment; - + old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)); if (old_adjustment == hadjustment) return; @@ -568,10 +560,8 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window); child = gtk_bin_get_child (bin); - if (child) - gtk_widget_set_scroll_adjustments (child, - gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), - gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar))); + if (GTK_IS_SCROLLABLE (child)) + gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), hadjustment); g_object_notify (G_OBJECT (scrolled_window), "hadjustment"); } @@ -585,7 +575,7 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, */ void gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window, - GtkAdjustment *vadjustment) + GtkAdjustment *vadjustment) { GtkScrolledWindowPrivate *priv; GtkBin *bin; @@ -633,10 +623,8 @@ gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window, gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window); child = gtk_bin_get_child (bin); - if (child) - gtk_widget_set_scroll_adjustments (child, - gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), - gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar))); + if (GTK_IS_SCROLLABLE (child)) + gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), vadjustment); g_object_notify (G_OBJECT (scrolled_window), "vadjustment"); } @@ -1853,6 +1841,7 @@ gtk_scrolled_window_add (GtkContainer *container, GtkScrolledWindow *scrolled_window; GtkBin *bin; GtkWidget *child_widget; + GtkAdjustment *hadj, *vadj; bin = GTK_BIN (container); child_widget = gtk_bin_get_child (bin); @@ -1864,12 +1853,14 @@ gtk_scrolled_window_add (GtkContainer *container, _gtk_bin_set_child (bin, child); gtk_widget_set_parent (child, GTK_WIDGET (bin)); - /* this is a temporary message */ - if (!gtk_widget_set_scroll_adjustments (child, - gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), - gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))) + hadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->hscrollbar)); + vadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->vscrollbar)); + + if (GTK_IS_SCROLLABLE (child)) + g_object_set (child, "hadjustment", hadj, "vadjustment", vadj, NULL); + else g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget " - "use gtk_scrolled_window_add_with_viewport() instead"); + "use gtk_scrolled_window_add_with_viewport() instead"); } static void @@ -1879,8 +1870,8 @@ gtk_scrolled_window_remove (GtkContainer *container, g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container)); g_return_if_fail (child != NULL); g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child); - - gtk_widget_set_scroll_adjustments (child, NULL, NULL); + + g_object_set (child, "hadjustment", NULL, "vadjustment", NULL, NULL); /* chain parent class handler to remove child */ GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child); @@ -1905,9 +1896,8 @@ gtk_scrolled_window_remove (GtkContainer *container, * 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. + * A widget supports scrolling natively if it implements the + * #GtkScrollable interface. */ void gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window, @@ -1935,7 +1925,7 @@ gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window, { viewport = gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window), - gtk_scrolled_window_get_vadjustment (scrolled_window)); + gtk_scrolled_window_get_vadjustment (scrolled_window)); gtk_container_add (GTK_CONTAINER (scrolled_window), viewport); } @@ -2025,9 +2015,20 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget, } else { - /* Always ask for at least enough to fit the scrollbars */ - minimum_req.width += vscrollbar_requisition.width; - natural_req.width += vscrollbar_requisition.width; + gint min_display_width = + gtk_scrollable_get_min_display_width (GTK_SCROLLABLE (child)); + + if (min_display_width > 0) + { + minimum_req.width += min_display_width; + natural_req.width += min_display_width; + extra_width = -1; + } + else + { + minimum_req.width += vscrollbar_requisition.width; + natural_req.width += vscrollbar_requisition.width; + } } } else /* GTK_ORIENTATION_VERTICAL */ @@ -2043,9 +2044,20 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget, } else { - /* Always ask for at least enough to fit the scrollbars */ - minimum_req.height += hscrollbar_requisition.height; - natural_req.height += hscrollbar_requisition.height; + gint min_display_height = + gtk_scrollable_get_min_display_height (GTK_SCROLLABLE (child)); + + if (min_display_height > 0) + { + minimum_req.height += min_display_height; + natural_req.height += min_display_height; + extra_height = -1; + } + else + { + minimum_req.height += vscrollbar_requisition.height; + natural_req.height += vscrollbar_requisition.height; + } } } } @@ -2064,14 +2076,14 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget, { minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height); natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height); - if (!extra_height || priv->vscrollbar_policy == GTK_POLICY_ALWAYS) + if (!extra_width || priv->vscrollbar_policy == GTK_POLICY_ALWAYS) extra_width = scrollbar_spacing + vscrollbar_requisition.width; } - minimum_req.width += extra_width; - minimum_req.height += extra_height; - natural_req.width += extra_width; - natural_req.height += extra_height; + minimum_req.width += MAX (0, extra_width); + minimum_req.height += MAX (0, extra_height); + natural_req.width += MAX (0, extra_width); + natural_req.height += MAX (0, extra_height); if (priv->shadow_type != GTK_SHADOW_NONE) { diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 30dce18e2d..a8012818d5 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -49,6 +49,7 @@ #include "gtktextutil.h" #include "gtkwidgetprivate.h" #include "gtkwindow.h" +#include "gtkscrollable.h" /* How scrolling, validation, exposes, etc. work. @@ -128,6 +129,8 @@ struct _GtkTextViewPrivate GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; + gint min_display_width; + gint min_display_height; gint xoffset; /* Offsets between widget coordinates and buffer coordinates */ gint yoffset; @@ -222,7 +225,6 @@ struct _GtkTextPendingScroll enum { - SET_SCROLL_ADJUSTMENTS, POPULATE_POPUP, MOVE_CURSOR, PAGE_HORIZONTALLY, @@ -258,7 +260,11 @@ enum PROP_BUFFER, PROP_OVERWRITE, PROP_ACCEPTS_TAB, - PROP_IM_MODULE + PROP_IM_MODULE, + PROP_HADJUSTMENT, + PROP_VADJUSTMENT, + PROP_MIN_DISPLAY_WIDTH, + PROP_MIN_DISPLAY_HEIGHT }; static void gtk_text_view_finalize (GObject *object); @@ -347,9 +353,6 @@ static void gtk_text_view_drag_data_received (GtkWidget *widget, guint info, guint time); -static void gtk_text_view_set_scroll_adjustments (GtkTextView *text_view, - GtkAdjustment *hadj, - GtkAdjustment *vadj); static gboolean gtk_text_view_popup_menu (GtkWidget *widget); static void gtk_text_view_move_cursor (GtkTextView *text_view, @@ -438,9 +441,6 @@ static void gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view, gint x, gint y); -static GtkAdjustment* get_hadjustment (GtkTextView *text_view); -static GtkAdjustment* get_vadjustment (GtkTextView *text_view); - static void gtk_text_view_do_popup (GtkTextView *text_view, GdkEventButton *event); @@ -457,6 +457,13 @@ static void gtk_text_view_update_adjustments (GtkTextView *text_view); static void gtk_text_view_invalidate (GtkTextView *text_view); static void gtk_text_view_flush_first_validate (GtkTextView *text_view); +static void gtk_text_view_set_hadjustment (GtkTextView *text_view, + GtkAdjustment *adjustment); +static void gtk_text_view_set_vadjustment (GtkTextView *text_view, + GtkAdjustment *adjustment); +static void gtk_text_view_set_hadjustment_values (GtkTextView *text_view); +static void gtk_text_view_set_vadjustment_values (GtkTextView *text_view); + static void gtk_text_view_update_im_spot_location (GtkTextView *text_view); /* Container methods */ @@ -532,7 +539,8 @@ static gint text_window_get_height (GtkTextWindow *win); static guint signals[LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (GtkTextView, gtk_text_view, GTK_TYPE_CONTAINER) +G_DEFINE_TYPE_WITH_CODE (GtkTextView, gtk_text_view, GTK_TYPE_CONTAINER, + G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL)) static void add_move_binding (GtkBindingSet *binding_set, @@ -615,7 +623,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass) klass->copy_clipboard = gtk_text_view_copy_clipboard; klass->paste_clipboard = gtk_text_view_paste_clipboard; klass->toggle_overwrite = gtk_text_view_toggle_overwrite; - klass->set_scroll_adjustments = gtk_text_view_set_scroll_adjustments; /* * Properties @@ -767,6 +774,12 @@ gtk_text_view_class_init (GtkTextViewClass *klass) NULL, GTK_PARAM_READWRITE)); + /* GtkScrollable interface */ + g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment"); + g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment"); + g_object_class_override_property (gobject_class, PROP_MIN_DISPLAY_WIDTH, "min-display-width"); + g_object_class_override_property (gobject_class, PROP_MIN_DISPLAY_HEIGHT, "min-display-height"); + /* * Style properties */ @@ -1021,27 +1034,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass) G_TYPE_NONE, 0); /** - * GtkTextView::set-scroll-adjustments - * @horizontal: the horizontal #GtkAdjustment - * @vertical: the vertical #GtkAdjustment - * - * Set the scroll adjustments for the text view. Usually scrolled containers - * like #GtkScrolledWindow will emit this signal to connect two instances - * of #GtkScrollbar to the scroll directions of the #GtkTextView. - */ - signals[SET_SCROLL_ADJUSTMENTS] = - g_signal_new (I_("set-scroll-adjustments"), - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkTextViewClass, set_scroll_adjustments), - NULL, NULL, - _gtk_marshal_VOID__OBJECT_OBJECT, - G_TYPE_NONE, 2, - GTK_TYPE_ADJUSTMENT, - GTK_TYPE_ADJUSTMENT); - widget_class->set_scroll_adjustments_signal = signals[SET_SCROLL_ADJUSTMENTS]; - - /** * GtkTextView::populate-popup: * @entry: The text view on which the signal is emitted * @menu: the menu that is being populated @@ -1402,6 +1394,9 @@ gtk_text_view_init (GtkTextView *text_view) priv->pending_place_cursor_button = 0; + priv->min_display_width = -1; + priv->min_display_height = -1; + /* We handle all our own redrawing */ gtk_widget_set_redraw_on_allocate (widget, FALSE); } @@ -1913,7 +1908,7 @@ gtk_text_view_scroll_to_iter (GtkTextView *text_view, if (scroll_inc != 0) { - retval = set_adjustment_clamped (get_vadjustment (text_view), + retval = set_adjustment_clamped (text_view->priv->vadjustment, current_y_scroll + scroll_inc); DV (g_print (" vert increment %d\n", scroll_inc)); @@ -1950,7 +1945,7 @@ gtk_text_view_scroll_to_iter (GtkTextView *text_view, if (scroll_inc != 0) { - retval = set_adjustment_clamped (get_hadjustment (text_view), + retval = set_adjustment_clamped (text_view->priv->hadjustment, current_x_scroll + scroll_inc); DV (g_print (" horiz increment %d\n", scroll_inc)); @@ -2079,33 +2074,6 @@ gtk_text_view_flush_scroll (GtkTextView *text_view) } static void -gtk_text_view_set_adjustment_upper (GtkAdjustment *adj, gdouble upper) -{ - if (upper != adj->upper) - { - gdouble min = MAX (0.0, upper - adj->page_size); - gboolean value_changed = FALSE; - - adj->upper = upper; - - if (adj->value > min) - { - adj->value = min; - value_changed = TRUE; - } - - gtk_adjustment_changed (adj); - DV(g_print(">Changed adj upper to %g ("G_STRLOC")\n", upper)); - - if (value_changed) - { - DV(g_print(">Changed adj value because upper decreased ("G_STRLOC")\n")); - gtk_adjustment_value_changed (adj); - } - } -} - -static void gtk_text_view_update_adjustments (GtkTextView *text_view) { GtkTextViewPrivate *priv; @@ -2129,28 +2097,8 @@ gtk_text_view_update_adjustments (GtkTextView *text_view) priv->width = width; priv->height = height; - gtk_text_view_set_adjustment_upper (get_hadjustment (text_view), - MAX (SCREEN_WIDTH (text_view), width)); - gtk_text_view_set_adjustment_upper (get_vadjustment (text_view), - MAX (SCREEN_HEIGHT (text_view), height)); - - /* hadj/vadj exist since we called get_hadjustment/get_vadjustment above */ - - /* Set up the step sizes; we'll say that a page is - our allocation minus one step, and a step is - 1/10 of our allocation. */ - priv->hadjustment->step_increment = - SCREEN_WIDTH (text_view) / 10.0; - priv->hadjustment->page_increment = - SCREEN_WIDTH (text_view) * 0.9; - - priv->vadjustment->step_increment = - SCREEN_HEIGHT (text_view) / 10.0; - priv->vadjustment->page_increment = - SCREEN_HEIGHT (text_view) * 0.9; - - gtk_adjustment_changed (get_hadjustment (text_view)); - gtk_adjustment_changed (get_vadjustment (text_view)); + gtk_text_view_set_hadjustment_values (text_view); + gtk_text_view_set_vadjustment_values (text_view); } } @@ -3145,6 +3093,22 @@ gtk_text_view_set_property (GObject *object, gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module); break; + case PROP_HADJUSTMENT: + gtk_text_view_set_hadjustment (text_view, g_value_get_object (value)); + break; + + case PROP_VADJUSTMENT: + gtk_text_view_set_vadjustment (text_view, g_value_get_object (value)); + break; + + case PROP_MIN_DISPLAY_WIDTH: + priv->min_display_width = g_value_get_int (value); + break; + + case PROP_MIN_DISPLAY_HEIGHT: + priv->min_display_height = g_value_get_int (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -3225,6 +3189,22 @@ gtk_text_view_get_property (GObject *object, g_value_set_string (value, priv->im_module); break; + case PROP_HADJUSTMENT: + g_value_set_object (value, priv->hadjustment); + break; + + case PROP_VADJUSTMENT: + g_value_set_object (value, priv->vadjustment); + break; + + case PROP_MIN_DISPLAY_WIDTH: + g_value_set_int (value, priv->min_display_width); + break; + + case PROP_MIN_DISPLAY_HEIGHT: + g_value_set_int (value, priv->min_display_height); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -3464,8 +3444,6 @@ gtk_text_view_size_allocate (GtkWidget *widget, GtkAllocation widget_allocation; GtkTextView *text_view; GtkTextViewPrivate *priv; - GtkTextIter first_para; - gint y; gint width, height; GdkRectangle text_rect; GdkRectangle left_rect; @@ -3596,44 +3574,9 @@ gtk_text_view_size_allocate (GtkWidget *widget, /* Note that this will do some layout validation */ gtk_text_view_allocate_children (text_view); - /* Ensure h/v adj exist */ - get_hadjustment (text_view); - get_vadjustment (text_view); - - priv->hadjustment->page_size = SCREEN_WIDTH (text_view); - priv->hadjustment->page_increment = SCREEN_WIDTH (text_view) * 0.9; - priv->hadjustment->step_increment = SCREEN_WIDTH (text_view) * 0.1; - priv->hadjustment->lower = 0; - priv->hadjustment->upper = MAX (SCREEN_WIDTH (text_view), - priv->width); - - if (priv->hadjustment->value > priv->hadjustment->upper - priv->hadjustment->page_size) - gtk_adjustment_set_value (priv->hadjustment, MAX (0, priv->hadjustment->upper - priv->hadjustment->page_size)); - - gtk_adjustment_changed (priv->hadjustment); - - priv->vadjustment->page_size = SCREEN_HEIGHT (text_view); - priv->vadjustment->page_increment = SCREEN_HEIGHT (text_view) * 0.9; - priv->vadjustment->step_increment = SCREEN_HEIGHT (text_view) * 0.1; - priv->vadjustment->lower = 0; - priv->vadjustment->upper = MAX (SCREEN_HEIGHT (text_view), - priv->height); - - /* Now adjust the value of the adjustment to keep the cursor at the - * same place in the buffer - */ - gtk_text_view_get_first_para_iter (text_view, &first_para); - gtk_text_layout_get_line_yrange (priv->layout, &first_para, &y, NULL); - - y += priv->first_para_pixels; - - if (y > priv->vadjustment->upper - priv->vadjustment->page_size) - y = MAX (0, priv->vadjustment->upper - priv->vadjustment->page_size); - - if (y != priv->yoffset) - gtk_adjustment_set_value (priv->vadjustment, y); - - gtk_adjustment_changed (priv->vadjustment); + /* Update adjustments */ + gtk_text_view_set_hadjustment_values (text_view); + gtk_text_view_set_vadjustment_values (text_view); /* The GTK resize loop processes all the pending exposes right * after doing the resize stuff, so the idle sizer won't have a @@ -3912,14 +3855,14 @@ changed_handler (GtkTextLayout *layout, { priv->yoffset += new_first_para_top - old_first_para_top; - get_vadjustment (text_view)->value = priv->yoffset; + text_view->priv->vadjustment->value = priv->yoffset; yoffset_changed = TRUE; } if (yoffset_changed) { DV(g_print ("Changing scroll position (%s)\n", G_STRLOC)); - gtk_adjustment_value_changed (get_vadjustment (text_view)); + gtk_adjustment_value_changed (text_view->priv->vadjustment); } /* FIXME be smarter about which anchored widgets we update */ @@ -5508,15 +5451,15 @@ gtk_text_view_move_viewport (GtkTextView *text_view, case GTK_SCROLL_STEPS: case GTK_SCROLL_PAGES: case GTK_SCROLL_ENDS: - adjustment = get_vadjustment (text_view); + adjustment = text_view->priv->vadjustment; break; case GTK_SCROLL_HORIZONTAL_STEPS: case GTK_SCROLL_HORIZONTAL_PAGES: case GTK_SCROLL_HORIZONTAL_ENDS: - adjustment = get_hadjustment (text_view); + adjustment = text_view->priv->hadjustment; break; default: - adjustment = get_vadjustment (text_view); + adjustment = text_view->priv->vadjustment; break; } @@ -7296,13 +7239,43 @@ gtk_text_view_drag_data_received (GtkWidget *widget, * Returns: (transfer none): pointer to the horizontal #GtkAdjustment * * Since: 2.22 + * + * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment() **/ GtkAdjustment* gtk_text_view_get_hadjustment (GtkTextView *text_view) { g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL); - return get_hadjustment (text_view); + return text_view->priv->hadjustment; +} + +static void +gtk_text_view_set_hadjustment (GtkTextView *text_view, + GtkAdjustment *adjustment) +{ + GtkTextViewPrivate *priv = text_view->priv; + + if (adjustment && priv->hadjustment == adjustment) + return; + + if (priv->hadjustment != NULL) + { + g_signal_handlers_disconnect_by_func (priv->hadjustment, + gtk_text_view_value_changed, + text_view); + g_object_unref (priv->hadjustment); + } + + if (adjustment == NULL) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_text_view_value_changed), text_view); + priv->hadjustment = g_object_ref_sink (adjustment); + gtk_text_view_set_hadjustment_values (text_view); + + g_object_notify (G_OBJECT (text_view), "hadjustment"); } /** @@ -7320,89 +7293,103 @@ gtk_text_view_get_vadjustment (GtkTextView *text_view) { g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL); - return get_vadjustment (text_view); + return text_view->priv->vadjustment; } -static GtkAdjustment* -get_hadjustment (GtkTextView *text_view) +static void +gtk_text_view_set_vadjustment (GtkTextView *text_view, + GtkAdjustment *adjustment) { - if (text_view->priv->hadjustment == NULL) - gtk_text_view_set_scroll_adjustments (text_view, - NULL, /* forces creation */ - text_view->priv->vadjustment); + GtkTextViewPrivate *priv = text_view->priv; - return text_view->priv->hadjustment; + if (adjustment && priv->vadjustment == adjustment) + return; + + if (priv->vadjustment != NULL) + { + g_signal_handlers_disconnect_by_func (priv->vadjustment, + gtk_text_view_value_changed, + text_view); + g_object_unref (priv->vadjustment); + } + + if (adjustment == NULL) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_text_view_value_changed), text_view); + priv->vadjustment = g_object_ref_sink (adjustment); + gtk_text_view_set_vadjustment_values (text_view); + + g_object_notify (G_OBJECT (text_view), "vadjustment"); } -static GtkAdjustment* -get_vadjustment (GtkTextView *text_view) +static void +gtk_text_view_set_hadjustment_values (GtkTextView *text_view) { - if (text_view->priv->vadjustment == NULL) - gtk_text_view_set_scroll_adjustments (text_view, - text_view->priv->hadjustment, - NULL); /* forces creation */ - return text_view->priv->vadjustment; -} + GtkTextViewPrivate *priv; + gint screen_width; + gdouble old_value; + gdouble new_value; + gdouble new_upper; + priv = text_view->priv; + + screen_width = SCREEN_WIDTH (text_view); + old_value = gtk_adjustment_get_value (priv->hadjustment); + new_upper = MAX (screen_width, priv->width); + + g_object_set (priv->hadjustment, + "lower", 0.0, + "upper", new_upper, + "page-size", (gdouble)screen_width, + "step-increment", screen_width * 0.1, + "page-increment", screen_width * 0.9, + NULL); + + new_value = CLAMP (old_value, 0, new_upper - screen_width); + if (new_value != old_value) + gtk_adjustment_set_value (priv->hadjustment, new_value); +} static void -gtk_text_view_set_scroll_adjustments (GtkTextView *text_view, - GtkAdjustment *hadj, - GtkAdjustment *vadj) +gtk_text_view_set_vadjustment_values (GtkTextView *text_view) { - GtkTextViewPrivate *priv = text_view->priv; - gboolean need_adjust = FALSE; + GtkTextViewPrivate *priv; + GtkTextIter first_para; + gint screen_height; + gint y; + gdouble old_value; + gdouble new_value; + gdouble new_upper; - if (hadj) - g_return_if_fail (GTK_IS_ADJUSTMENT (hadj)); - else - hadj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - if (vadj) - g_return_if_fail (GTK_IS_ADJUSTMENT (vadj)); - else - vadj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + priv = text_view->priv; - if (priv->hadjustment && (priv->hadjustment != hadj)) - { - g_signal_handlers_disconnect_by_func (priv->hadjustment, - gtk_text_view_value_changed, - text_view); - g_object_unref (priv->hadjustment); - } + screen_height = SCREEN_HEIGHT (text_view); + old_value = gtk_adjustment_get_value (priv->vadjustment); + new_upper = MAX (screen_height, priv->height); - if (priv->vadjustment && (priv->vadjustment != vadj)) - { - g_signal_handlers_disconnect_by_func (priv->vadjustment, - gtk_text_view_value_changed, - text_view); - g_object_unref (priv->vadjustment); - } + g_object_set (priv->vadjustment, + "lower", 0.0, + "upper", new_upper, + "page-size", (gdouble)screen_height, + "step-increment", screen_height * 0.1, + "page-increment", screen_height * 0.9, + NULL); - if (priv->hadjustment != hadj) - { - priv->hadjustment = hadj; - g_object_ref_sink (priv->hadjustment); - - g_signal_connect (priv->hadjustment, "value-changed", - G_CALLBACK (gtk_text_view_value_changed), - text_view); - need_adjust = TRUE; - } + /* Now adjust the value of the adjustment to keep the cursor at the + * same place in the buffer */ + gtk_text_view_ensure_layout (text_view); + gtk_text_view_get_first_para_iter (text_view, &first_para); + gtk_text_layout_get_line_yrange (priv->layout, &first_para, &y, NULL); - if (priv->vadjustment != vadj) - { - priv->vadjustment = vadj; - g_object_ref_sink (priv->vadjustment); - - g_signal_connect (priv->vadjustment, "value-changed", - G_CALLBACK (gtk_text_view_value_changed), - text_view); - need_adjust = TRUE; - } + y += priv->first_para_pixels; + + new_value = CLAMP (y, 0, new_upper - screen_height); + if (new_value != old_value) + gtk_adjustment_set_value (priv->vadjustment, new_value); + } - if (need_adjust) - gtk_text_view_value_changed (NULL, text_view); -} /* FIXME this adjust_allocation is a big cut-and-paste from * GtkCList, needs to be some "official" way to do this diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h index 21760303ba..4e64b33e15 100644 --- a/gtk/gtktextview.h +++ b/gtk/gtktextview.h @@ -73,10 +73,6 @@ struct _GtkTextViewClass { GtkContainerClass parent_class; - void (* set_scroll_adjustments) (GtkTextView *text_view, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - void (* populate_popup) (GtkTextView *text_view, GtkMenu *menu); @@ -182,8 +178,10 @@ void gtk_text_view_window_to_buffer_coords (GtkTextView *text_view, gint *buffer_x, gint *buffer_y); -GtkAdjustment* gtk_text_view_get_hadjustment (GtkTextView *text_view); -GtkAdjustment* gtk_text_view_get_vadjustment (GtkTextView *text_view); +#ifndef GTK_DISABLE_DEPRECATED +GtkAdjustment* gtk_text_view_get_hadjustment (GtkTextView *text_view); +GtkAdjustment* gtk_text_view_get_vadjustment (GtkTextView *text_view); +#endif GdkWindow* gtk_text_view_get_window (GtkTextView *text_view, GtkTextWindowType win); diff --git a/gtk/gtktoolpalette.c b/gtk/gtktoolpalette.c index 397608e00a..0359fcfc45 100644 --- a/gtk/gtktoolpalette.c +++ b/gtk/gtktoolpalette.c @@ -28,6 +28,7 @@ #include "gtkmarshalers.h" #include "gtkprivate.h" +#include "gtkscrollable.h" #include "gtkintl.h" #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR @@ -120,6 +121,10 @@ enum PROP_ICON_SIZE_SET, PROP_ORIENTATION, PROP_TOOLBAR_STYLE, + PROP_HADJUSTMENT, + PROP_VADJUSTMENT, + PROP_MIN_DISPLAY_WIDTH, + PROP_MIN_DISPLAY_HEIGHT }; enum @@ -145,6 +150,8 @@ struct _GtkToolPalettePrivate GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; + gint min_display_width; + gint min_display_height; GtkIconSize icon_size; gboolean icon_size_set; @@ -177,10 +184,17 @@ static const GtkTargetEntry dnd_targets[] = { "application/x-gtk-tool-palette-group", GTK_TARGET_SAME_APP, 0 }, }; +static void gtk_tool_palette_set_hadjustment (GtkToolPalette *palette, + GtkAdjustment *adjustment); +static void gtk_tool_palette_set_vadjustment (GtkToolPalette *palette, + GtkAdjustment *adjustment); + + G_DEFINE_TYPE_WITH_CODE (GtkToolPalette, gtk_tool_palette, GTK_TYPE_CONTAINER, - G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)); + G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL) + G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL)) static void gtk_tool_palette_init (GtkToolPalette *palette) @@ -197,6 +211,8 @@ gtk_tool_palette_init (GtkToolPalette *palette) palette->priv->orientation = DEFAULT_ORIENTATION; palette->priv->style = DEFAULT_TOOLBAR_STYLE; palette->priv->style_set = FALSE; + palette->priv->min_display_width = -1; + palette->priv->min_display_height = -1; palette->priv->text_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH); } @@ -258,6 +274,22 @@ gtk_tool_palette_set_property (GObject *object, } break; + case PROP_HADJUSTMENT: + gtk_tool_palette_set_hadjustment (palette, g_value_get_object (value)); + break; + + case PROP_VADJUSTMENT: + gtk_tool_palette_set_vadjustment (palette, g_value_get_object (value)); + break; + + case PROP_MIN_DISPLAY_WIDTH: + palette->priv->min_display_width = g_value_get_int (value); + break; + + case PROP_MIN_DISPLAY_HEIGHT: + palette->priv->min_display_height = g_value_get_int (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -290,6 +322,22 @@ gtk_tool_palette_get_property (GObject *object, g_value_set_enum (value, gtk_tool_palette_get_style (palette)); break; + case PROP_HADJUSTMENT: + g_value_set_object (value, palette->priv->hadjustment); + break; + + case PROP_VADJUSTMENT: + g_value_set_object (value, palette->priv->vadjustment); + break; + + case PROP_MIN_DISPLAY_WIDTH: + g_value_set_int (value, palette->priv->min_display_width); + break; + + case PROP_MIN_DISPLAY_HEIGHT: + g_value_set_int (value, palette->priv->min_display_height); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -703,33 +751,47 @@ gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment, } static void -gtk_tool_palette_set_scroll_adjustments (GtkWidget *widget, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment) +gtk_tool_palette_set_adjustment (GtkToolPalette *palette, + GtkOrientation orientation, + GtkAdjustment *adjustment) { - GtkToolPalette *palette = GTK_TOOL_PALETTE (widget); + GtkAdjustment **adj_ptr; - if (hadjustment) - g_object_ref_sink (hadjustment); - if (vadjustment) - g_object_ref_sink (vadjustment); + if (orientation == GTK_ORIENTATION_HORIZONTAL) + { + if (adjustment && palette->priv->hadjustment == adjustment) + return; - if (palette->priv->hadjustment) - g_object_unref (palette->priv->hadjustment); - if (palette->priv->vadjustment) - g_object_unref (palette->priv->vadjustment); + adj_ptr = &palette->priv->hadjustment; + } + else + { + if (adjustment && palette->priv->vadjustment == adjustment) + return; - palette->priv->hadjustment = hadjustment; - palette->priv->vadjustment = vadjustment; + adj_ptr = &palette->priv->vadjustment; + } - if (palette->priv->hadjustment) - g_signal_connect (palette->priv->hadjustment, "value-changed", - G_CALLBACK (gtk_tool_palette_adjustment_value_changed), - palette); - if (palette->priv->vadjustment) - g_signal_connect (palette->priv->vadjustment, "value-changed", - G_CALLBACK (gtk_tool_palette_adjustment_value_changed), - palette); + /* Disconnect handler */ + if (*adj_ptr) + { + g_signal_handlers_disconnect_by_func (*adj_ptr, + gtk_tool_palette_adjustment_value_changed, + palette); + g_object_unref (*adj_ptr); + } + + /* Ensure adjustment */ + if (!adjustment) + adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, + 0.0, 0.0, 0.0)); + + /* Connect signal handler */ + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_tool_palette_adjustment_value_changed), + palette); + *adj_ptr = g_object_ref_sink (adjustment); + /* FIXME: Adjustment should probably have it's values updated now */ } static void @@ -952,38 +1014,17 @@ gtk_tool_palette_class_init (GtkToolPaletteClass *cls) cclass->set_child_property = gtk_tool_palette_set_child_property; cclass->get_child_property = gtk_tool_palette_get_child_property; - cls->set_scroll_adjustments = gtk_tool_palette_set_scroll_adjustments; - /* Handle screen-changed so we can update our GtkSettings. */ wclass->screen_changed = gtk_tool_palette_screen_changed; - /** - * GtkToolPalette::set-scroll-adjustments: - * @widget: the GtkToolPalette that received the signal - * @hadjustment: The horizontal adjustment - * @vadjustment: The vertical adjustment - * - * Set the scroll adjustments for the viewport. - * Usually scrolled containers like GtkScrolledWindow will emit this - * signal to connect two instances of GtkScrollbar to the scroll - * directions of the GtkToolpalette. - * - * Since: 2.20 - */ - wclass->set_scroll_adjustments_signal = - g_signal_new ("set-scroll-adjustments", - G_TYPE_FROM_CLASS (oclass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkToolPaletteClass, set_scroll_adjustments), - NULL, NULL, - _gtk_marshal_VOID__OBJECT_OBJECT, - G_TYPE_NONE, 2, - GTK_TYPE_ADJUSTMENT, - GTK_TYPE_ADJUSTMENT); - g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation"); + g_object_class_override_property (oclass, PROP_HADJUSTMENT, "hadjustment"); + g_object_class_override_property (oclass, PROP_VADJUSTMENT, "vadjustment"); + g_object_class_override_property (oclass, PROP_MIN_DISPLAY_WIDTH, "min-display-width"); + g_object_class_override_property (oclass, PROP_MIN_DISPLAY_HEIGHT, "min-display-height"); + /** * GtkToolPalette:icon-size: * @@ -1908,6 +1949,8 @@ _gtk_tool_palette_set_expanding_child (GtkToolPalette *palette, * Returns: (transfer none): the horizontal adjustment of @palette * * Since: 2.20 + * + * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment() */ GtkAdjustment* gtk_tool_palette_get_hadjustment (GtkToolPalette *palette) @@ -1917,6 +1960,35 @@ gtk_tool_palette_get_hadjustment (GtkToolPalette *palette) return palette->priv->hadjustment; } +static void +gtk_tool_palette_set_hadjustment (GtkToolPalette *palette, + GtkAdjustment *adjustment) +{ + GtkToolPalettePrivate *priv = palette->priv; + + if (adjustment && priv->hadjustment == adjustment) + return; + + if (priv->hadjustment != NULL) + { + g_signal_handlers_disconnect_by_func (priv->hadjustment, + gtk_tool_palette_adjustment_value_changed, + palette); + g_object_unref (priv->hadjustment); + } + + if (adjustment != NULL) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, + 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_tool_palette_adjustment_value_changed), + palette); + priv->hadjustment = g_object_ref_sink (adjustment); + /* FIXME: Adjustment should probably have it's values updated now */ + g_object_notify (G_OBJECT (palette), "hadjustment"); +} + /** * gtk_tool_palette_get_vadjustment: * @palette: a #GtkToolPalette @@ -1926,6 +1998,8 @@ gtk_tool_palette_get_hadjustment (GtkToolPalette *palette) * Returns: (transfer none): the vertical adjustment of @palette * * Since: 2.20 + * + * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment() */ GtkAdjustment* gtk_tool_palette_get_vadjustment (GtkToolPalette *palette) @@ -1935,6 +2009,35 @@ gtk_tool_palette_get_vadjustment (GtkToolPalette *palette) return palette->priv->vadjustment; } +static void +gtk_tool_palette_set_vadjustment (GtkToolPalette *palette, + GtkAdjustment *adjustment) +{ + GtkToolPalettePrivate *priv = palette->priv; + + if (adjustment && priv->vadjustment == adjustment) + return; + + if (priv->vadjustment != NULL) + { + g_signal_handlers_disconnect_by_func (priv->vadjustment, + gtk_tool_palette_adjustment_value_changed, + palette); + g_object_unref (priv->vadjustment); + } + + if (adjustment != NULL) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, + 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_tool_palette_adjustment_value_changed), + palette); + priv->vadjustment = g_object_ref_sink (adjustment); + /* FIXME: Adjustment should probably have it's values updated now */ + g_object_notify (G_OBJECT (palette), "vadjustment"); +} + GtkSizeGroup * _gtk_tool_palette_get_size_group (GtkToolPalette *palette) { diff --git a/gtk/gtktoolpalette.h b/gtk/gtktoolpalette.h index 4a0e9f99f4..7870c55967 100644 --- a/gtk/gtktoolpalette.h +++ b/gtk/gtktoolpalette.h @@ -72,10 +72,6 @@ struct _GtkToolPaletteClass { GtkContainerClass parent_class; - void (*set_scroll_adjustments) (GtkWidget *widget, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - /* Padding for future expansion */ void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); @@ -130,9 +126,13 @@ void gtk_tool_palette_add_drag_dest (GtkToolPa GtkToolPaletteDragTargets targets, GdkDragAction actions); +#ifndef GTK_DISABLE_DEPRECATED + GtkAdjustment* gtk_tool_palette_get_hadjustment (GtkToolPalette *palette); GtkAdjustment* gtk_tool_palette_get_vadjustment (GtkToolPalette *palette); +#endif + G_CONST_RETURN GtkTargetEntry* gtk_tool_palette_get_drag_target_item (void) G_GNUC_CONST; G_CONST_RETURN GtkTargetEntry* gtk_tool_palette_get_drag_target_group (void) G_GNUC_CONST; diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h index 8b18e7fbad..0519db7a0a 100644 --- a/gtk/gtktreeprivate.h +++ b/gtk/gtktreeprivate.h @@ -102,6 +102,8 @@ struct _GtkTreeViewPrivate /* Adjustments */ GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; + gint min_display_width; + gint min_display_height; /* Sub windows */ GdkWindow *bin_window; diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index 6dc0bfaf10..df809d7bf6 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -44,6 +44,7 @@ #include "gtkframe.h" #include "gtktreemodelsort.h" #include "gtktooltip.h" +#include "gtkscrollable.h" #include "gtkprivate.h" #include "gtkwidgetprivate.h" @@ -145,7 +146,9 @@ enum { PROP_RUBBER_BANDING, PROP_ENABLE_GRID_LINES, PROP_ENABLE_TREE_LINES, - PROP_TOOLTIP_COLUMN + PROP_TOOLTIP_COLUMN, + PROP_MIN_DISPLAY_WIDTH, + PROP_MIN_DISPLAY_HEIGHT }; /* object signals */ @@ -249,9 +252,10 @@ static void gtk_tree_view_drag_data_received (GtkWidget *widget, guint time); /* tree_model signals */ -static void gtk_tree_view_set_adjustments (GtkTreeView *tree_view, - GtkAdjustment *hadj, - GtkAdjustment *vadj); +static void gtk_tree_view_set_hadjustment (GtkTreeView *tree_view, + GtkAdjustment *adjustment); +static void gtk_tree_view_set_vadjustment (GtkTreeView *tree_view, + GtkAdjustment *adjustment); static gboolean gtk_tree_view_real_move_cursor (GtkTreeView *tree_view, GtkMovementStep step, gint count); @@ -488,7 +492,8 @@ static guint tree_view_signals [LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE_WITH_CODE (GtkTreeView, gtk_tree_view, GTK_TYPE_CONTAINER, G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - gtk_tree_view_buildable_init)) + gtk_tree_view_buildable_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL)) static void gtk_tree_view_class_init (GtkTreeViewClass *class) @@ -546,7 +551,6 @@ gtk_tree_view_class_init (GtkTreeViewClass *class) container_class->forall = gtk_tree_view_forall; container_class->set_focus_child = gtk_tree_view_set_focus_child; - class->set_scroll_adjustments = gtk_tree_view_set_adjustments; class->move_cursor = gtk_tree_view_real_move_cursor; class->select_all = gtk_tree_view_real_select_all; class->unselect_all = gtk_tree_view_real_unselect_all; @@ -566,21 +570,10 @@ gtk_tree_view_class_init (GtkTreeViewClass *class) GTK_TYPE_TREE_MODEL, GTK_PARAM_READWRITE)); - g_object_class_install_property (o_class, - PROP_HADJUSTMENT, - g_param_spec_object ("hadjustment", - P_("Horizontal Adjustment"), - P_("Horizontal Adjustment for the widget"), - GTK_TYPE_ADJUSTMENT, - GTK_PARAM_READWRITE)); - - g_object_class_install_property (o_class, - PROP_VADJUSTMENT, - g_param_spec_object ("vadjustment", - P_("Vertical Adjustment"), - P_("Vertical Adjustment for the widget"), - GTK_TYPE_ADJUSTMENT, - GTK_PARAM_READWRITE)); + g_object_class_override_property (o_class, PROP_HADJUSTMENT, "hadjustment"); + g_object_class_override_property (o_class, PROP_VADJUSTMENT, "vadjustment"); + g_object_class_override_property (o_class, PROP_MIN_DISPLAY_WIDTH, "min-display-width"); + g_object_class_override_property (o_class, PROP_MIN_DISPLAY_HEIGHT, "min-display-height"); g_object_class_install_property (o_class, PROP_HEADERS_VISIBLE, @@ -857,26 +850,6 @@ gtk_tree_view_class_init (GtkTreeViewClass *class) /* Signals */ /** - * GtkTreeView::set-scroll-adjustments - * @horizontal: the horizontal #GtkAdjustment - * @vertical: the vertical #GtkAdjustment - * - * Set the scroll adjustments for the tree view. Usually scrolled containers - * like #GtkScrolledWindow will emit this signal to connect two instances - * of #GtkScrollbar to the scroll directions of the #GtkTreeView. - */ - widget_class->set_scroll_adjustments_signal = - g_signal_new (I_("set-scroll-adjustments"), - G_TYPE_FROM_CLASS (o_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkTreeViewClass, set_scroll_adjustments), - NULL, NULL, - _gtk_marshal_VOID__OBJECT_OBJECT, - G_TYPE_NONE, 2, - GTK_TYPE_ADJUSTMENT, - GTK_TYPE_ADJUSTMENT); - - /** * GtkTreeView::row-activated: * @tree_view: the object on which the signal is emitted * @path: the #GtkTreePath for the activated row @@ -1337,7 +1310,6 @@ gtk_tree_view_init (GtkTreeView *tree_view) tree_view->priv->fixed_height = -1; tree_view->priv->fixed_height_mode = FALSE; tree_view->priv->fixed_height_check = 0; - gtk_tree_view_set_adjustments (tree_view, NULL, NULL); tree_view->priv->selection = _gtk_tree_selection_new_with_tree_view (tree_view); tree_view->priv->enable_search = TRUE; tree_view->priv->search_column = -1; @@ -1367,6 +1339,9 @@ gtk_tree_view_init (GtkTreeView *tree_view) tree_view->priv->event_last_x = -10000; tree_view->priv->event_last_y = -10000; + + tree_view->priv->min_display_width = -1; + tree_view->priv->min_display_height = -1; } @@ -1443,6 +1418,12 @@ gtk_tree_view_set_property (GObject *object, case PROP_TOOLTIP_COLUMN: gtk_tree_view_set_tooltip_column (tree_view, g_value_get_int (value)); break; + case PROP_MIN_DISPLAY_WIDTH: + tree_view->priv->min_display_width = g_value_get_int (value); + break; + case PROP_MIN_DISPLAY_HEIGHT: + tree_view->priv->min_display_height = g_value_get_int (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1518,6 +1499,12 @@ gtk_tree_view_get_property (GObject *object, case PROP_TOOLTIP_COLUMN: g_value_set_int (value, tree_view->priv->tooltip_column); break; + case PROP_MIN_DISPLAY_WIDTH: + g_value_set_int (value, tree_view->priv->min_display_width); + break; + case PROP_MIN_DISPLAY_HEIGHT: + g_value_set_int (value, tree_view->priv->min_display_height); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -8112,67 +8099,6 @@ gtk_tree_view_set_focus_child (GtkContainer *container, GTK_CONTAINER_CLASS (gtk_tree_view_parent_class)->set_focus_child (container, child); } -static void -gtk_tree_view_set_adjustments (GtkTreeView *tree_view, - GtkAdjustment *hadj, - GtkAdjustment *vadj) -{ - gboolean need_adjust = FALSE; - - g_return_if_fail (GTK_IS_TREE_VIEW (tree_view)); - - if (hadj) - g_return_if_fail (GTK_IS_ADJUSTMENT (hadj)); - else - hadj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - if (vadj) - g_return_if_fail (GTK_IS_ADJUSTMENT (vadj)); - else - vadj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - - if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj)) - { - g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment, - gtk_tree_view_adjustment_changed, - tree_view); - g_object_unref (tree_view->priv->hadjustment); - } - - if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj)) - { - g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment, - gtk_tree_view_adjustment_changed, - tree_view); - g_object_unref (tree_view->priv->vadjustment); - } - - if (tree_view->priv->hadjustment != hadj) - { - tree_view->priv->hadjustment = hadj; - g_object_ref_sink (tree_view->priv->hadjustment); - - g_signal_connect (tree_view->priv->hadjustment, "value-changed", - G_CALLBACK (gtk_tree_view_adjustment_changed), - tree_view); - need_adjust = TRUE; - } - - if (tree_view->priv->vadjustment != vadj) - { - tree_view->priv->vadjustment = vadj; - g_object_ref_sink (tree_view->priv->vadjustment); - - g_signal_connect (tree_view->priv->vadjustment, "value-changed", - G_CALLBACK (gtk_tree_view_adjustment_changed), - tree_view); - need_adjust = TRUE; - } - - if (need_adjust) - gtk_tree_view_adjustment_changed (NULL, tree_view); -} - - static gboolean gtk_tree_view_real_move_cursor (GtkTreeView *tree_view, GtkMovementStep step, @@ -10929,15 +10855,14 @@ gtk_tree_view_get_selection (GtkTreeView *tree_view) * * Return value: (transfer none): A #GtkAdjustment object, or %NULL * if none is currently being used. + * + * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment() **/ GtkAdjustment * gtk_tree_view_get_hadjustment (GtkTreeView *tree_view) { g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL); - if (tree_view->priv->hadjustment == NULL) - gtk_tree_view_set_hadjustment (tree_view, NULL); - return tree_view->priv->hadjustment; } @@ -10947,16 +10872,40 @@ gtk_tree_view_get_hadjustment (GtkTreeView *tree_view) * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL * * Sets the #GtkAdjustment for the current horizontal aspect. + * + * Deprecated: 3.0: Use gtk_scrollable_set_hadjustment() **/ void gtk_tree_view_set_hadjustment (GtkTreeView *tree_view, - GtkAdjustment *adjustment) + GtkAdjustment *adjustment) { + GtkTreeViewPrivate *priv = tree_view->priv; + g_return_if_fail (GTK_IS_TREE_VIEW (tree_view)); + g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment)); - gtk_tree_view_set_adjustments (tree_view, - adjustment, - tree_view->priv->vadjustment); + if (adjustment && priv->hadjustment == adjustment) + return; + + if (priv->hadjustment != NULL) + { + g_signal_handlers_disconnect_by_func (priv->hadjustment, + gtk_tree_view_adjustment_changed, + tree_view); + g_object_unref (priv->hadjustment); + } + + if (adjustment == NULL) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, + 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_tree_view_adjustment_changed), tree_view); + priv->hadjustment = g_object_ref_sink (adjustment); + /* FIXME: Adjustment should probably be populated here with fresh values, but + * internal details are too complicated for me to decipher right now. + */ + gtk_tree_view_adjustment_changed (NULL, tree_view); g_object_notify (G_OBJECT (tree_view), "hadjustment"); } @@ -10969,15 +10918,14 @@ gtk_tree_view_set_hadjustment (GtkTreeView *tree_view, * * Return value: (transfer none): A #GtkAdjustment object, or %NULL * if none is currently being used. + * + * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment() **/ GtkAdjustment * gtk_tree_view_get_vadjustment (GtkTreeView *tree_view) { g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL); - if (tree_view->priv->vadjustment == NULL) - gtk_tree_view_set_vadjustment (tree_view, NULL); - return tree_view->priv->vadjustment; } @@ -10987,17 +10935,40 @@ gtk_tree_view_get_vadjustment (GtkTreeView *tree_view) * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL * * Sets the #GtkAdjustment for the current vertical aspect. + * + * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment() **/ void gtk_tree_view_set_vadjustment (GtkTreeView *tree_view, - GtkAdjustment *adjustment) + GtkAdjustment *adjustment) { + GtkTreeViewPrivate *priv = tree_view->priv; + g_return_if_fail (GTK_IS_TREE_VIEW (tree_view)); + g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment)); + + if (adjustment && priv->vadjustment == adjustment) + return; - gtk_tree_view_set_adjustments (tree_view, - tree_view->priv->hadjustment, - adjustment); + if (priv->vadjustment != NULL) + { + g_signal_handlers_disconnect_by_func (priv->vadjustment, + gtk_tree_view_adjustment_changed, + tree_view); + g_object_unref (priv->vadjustment); + } + if (adjustment == NULL) + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, + 0.0, 0.0, 0.0); + + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_tree_view_adjustment_changed), tree_view); + priv->vadjustment = g_object_ref_sink (adjustment); + /* FIXME: Adjustment should probably be populated here with fresh values, but + * internal details are too complicated for me to decipher right now. + */ + gtk_tree_view_adjustment_changed (NULL, tree_view); g_object_notify (G_OBJECT (tree_view), "vadjustment"); } diff --git a/gtk/gtktreeview.h b/gtk/gtktreeview.h index 8ac2f49e9b..2dd137b893 100644 --- a/gtk/gtktreeview.h +++ b/gtk/gtktreeview.h @@ -70,9 +70,6 @@ struct _GtkTreeViewClass { GtkContainerClass parent_class; - void (* set_scroll_adjustments) (GtkTreeView *tree_view, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); void (* row_activated) (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column); @@ -150,12 +147,18 @@ GtkTreeModel *gtk_tree_view_get_model (GtkTreeView void gtk_tree_view_set_model (GtkTreeView *tree_view, GtkTreeModel *model); GtkTreeSelection *gtk_tree_view_get_selection (GtkTreeView *tree_view); + +#ifndef GTK_DISABLE_DEPRECATED + GtkAdjustment *gtk_tree_view_get_hadjustment (GtkTreeView *tree_view); void gtk_tree_view_set_hadjustment (GtkTreeView *tree_view, GtkAdjustment *adjustment); GtkAdjustment *gtk_tree_view_get_vadjustment (GtkTreeView *tree_view); void gtk_tree_view_set_vadjustment (GtkTreeView *tree_view, GtkAdjustment *adjustment); + +#endif + gboolean gtk_tree_view_get_headers_visible (GtkTreeView *tree_view); void gtk_tree_view_set_headers_visible (GtkTreeView *tree_view, gboolean headers_visible); diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c index 5988682330..1362df7c01 100644 --- a/gtk/gtkviewport.c +++ b/gtk/gtkviewport.c @@ -29,6 +29,7 @@ #include "gtkintl.h" #include "gtkmarshalers.h" #include "gtktypeutils.h" +#include "gtkscrollable.h" #include "gtkprivate.h" @@ -58,6 +59,8 @@ struct _GtkViewportPrivate { GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; + gint min_display_width; + gint min_display_height; GtkShadowType shadow_type; GdkWindow *bin_window; @@ -68,6 +71,8 @@ enum { PROP_0, PROP_HADJUSTMENT, PROP_VADJUSTMENT, + PROP_MIN_DISPLAY_WIDTH, + PROP_MIN_DISPLAY_HEIGHT, PROP_SHADOW_TYPE }; @@ -81,9 +86,6 @@ static void gtk_viewport_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gtk_viewport_set_scroll_adjustments (GtkViewport *viewport, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); static void gtk_viewport_destroy (GtkWidget *widget); static void gtk_viewport_realize (GtkWidget *widget); static void gtk_viewport_unrealize (GtkWidget *widget); @@ -106,7 +108,8 @@ static void gtk_viewport_get_preferred_height (GtkWidget *widget, gint *natural_size); -G_DEFINE_TYPE (GtkViewport, gtk_viewport, GTK_TYPE_BIN) +G_DEFINE_TYPE_WITH_CODE (GtkViewport, gtk_viewport, GTK_TYPE_BIN, + G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL)) static void gtk_viewport_class_init (GtkViewportClass *class) @@ -134,23 +137,19 @@ gtk_viewport_class_init (GtkViewportClass *class) container_class->add = gtk_viewport_add; - class->set_scroll_adjustments = gtk_viewport_set_scroll_adjustments; - - g_object_class_install_property (gobject_class, - PROP_HADJUSTMENT, - g_param_spec_object ("hadjustment", - P_("Horizontal adjustment"), - P_("The GtkAdjustment that determines the values of the horizontal position for this viewport"), - GTK_TYPE_ADJUSTMENT, - GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property (gobject_class, - PROP_VADJUSTMENT, - g_param_spec_object ("vadjustment", - P_("Vertical adjustment"), - P_("The GtkAdjustment that determines the values of the vertical position for this viewport"), - GTK_TYPE_ADJUSTMENT, - GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + /* GtkScrollable implementation */ + g_object_class_override_property (gobject_class, + PROP_HADJUSTMENT, + "hadjustment"); + g_object_class_override_property (gobject_class, + PROP_VADJUSTMENT, + "vadjustment"); + g_object_class_override_property (gobject_class, + PROP_MIN_DISPLAY_WIDTH, + "min-display-width"); + g_object_class_override_property (gobject_class, + PROP_MIN_DISPLAY_HEIGHT, + "min-display-height"); g_object_class_install_property (gobject_class, PROP_SHADOW_TYPE, @@ -161,26 +160,6 @@ gtk_viewport_class_init (GtkViewportClass *class) GTK_SHADOW_IN, GTK_PARAM_READWRITE)); - /** - * GtkViewport::set-scroll-adjustments - * @horizontal: the horizontal #GtkAdjustment - * @vertical: the vertical #GtkAdjustment - * - * Set the scroll adjustments for the viewport. Usually scrolled containers - * like #GtkScrolledWindow will emit this signal to connect two instances - * of #GtkScrollbar to the scroll directions of the #GtkViewport. - */ - widget_class->set_scroll_adjustments_signal = - g_signal_new (I_("set-scroll-adjustments"), - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkViewportClass, set_scroll_adjustments), - NULL, NULL, - _gtk_marshal_VOID__OBJECT_OBJECT, - G_TYPE_NONE, 2, - GTK_TYPE_ADJUSTMENT, - GTK_TYPE_ADJUSTMENT); - g_type_class_add_private (class, sizeof (GtkViewportPrivate)); } @@ -202,6 +181,12 @@ gtk_viewport_set_property (GObject *object, case PROP_VADJUSTMENT: gtk_viewport_set_vadjustment (viewport, g_value_get_object (value)); break; + case PROP_MIN_DISPLAY_WIDTH: + viewport->priv->min_display_width = g_value_get_int (value); + break; + case PROP_MIN_DISPLAY_HEIGHT: + viewport->priv->min_display_height = g_value_get_int (value); + break; case PROP_SHADOW_TYPE: gtk_viewport_set_shadow_type (viewport, g_value_get_enum (value)); break; @@ -228,6 +213,12 @@ gtk_viewport_get_property (GObject *object, case PROP_VADJUSTMENT: g_value_set_object (value, priv->vadjustment); break; + case PROP_MIN_DISPLAY_WIDTH: + g_value_set_int (value, priv->min_display_width); + break; + case PROP_MIN_DISPLAY_HEIGHT: + g_value_set_int (value, priv->min_display_height); + break; case PROP_SHADOW_TYPE: g_value_set_enum (value, priv->shadow_type); break; @@ -257,6 +248,8 @@ gtk_viewport_init (GtkViewport *viewport) priv->bin_window = NULL; priv->hadjustment = NULL; priv->vadjustment = NULL; + priv->min_display_width = -1; + priv->min_display_height = -1; } /** @@ -331,6 +324,8 @@ gtk_viewport_destroy (GtkWidget *widget) * Returns the horizontal adjustment of the viewport. * * Return value: (transfer none): the horizontal adjustment of @viewport. + * + * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment() **/ GtkAdjustment* gtk_viewport_get_hadjustment (GtkViewport *viewport) @@ -354,6 +349,8 @@ gtk_viewport_get_hadjustment (GtkViewport *viewport) * Returns the vertical adjustment of the viewport. * * Return value: (transfer none): the vertical adjustment of @viewport. + * + * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment() **/ GtkAdjustment* gtk_viewport_get_vadjustment (GtkViewport *viewport) @@ -537,6 +534,8 @@ viewport_set_adjustment (GtkViewport *viewport, * @adjustment: (allow-none): a #GtkAdjustment. * * Sets the horizontal adjustment of the viewport. + * + * Deprecated: 3.0: Use gtk_scrollable_set_hadjustment() **/ void gtk_viewport_set_hadjustment (GtkViewport *viewport, @@ -557,6 +556,8 @@ gtk_viewport_set_hadjustment (GtkViewport *viewport, * @adjustment: (allow-none): a #GtkAdjustment. * * Sets the vertical adjustment of the viewport. + * + * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment() **/ void gtk_viewport_set_vadjustment (GtkViewport *viewport, @@ -571,15 +572,6 @@ gtk_viewport_set_vadjustment (GtkViewport *viewport, g_object_notify (G_OBJECT (viewport), "vadjustment"); } -static void -gtk_viewport_set_scroll_adjustments (GtkViewport *viewport, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment) -{ - gtk_viewport_set_hadjustment (viewport, hadjustment); - gtk_viewport_set_vadjustment (viewport, vadjustment); -} - /** * gtk_viewport_set_shadow_type: * @viewport: a #GtkViewport. diff --git a/gtk/gtkviewport.h b/gtk/gtkviewport.h index 0ceb98724b..fcc0833300 100644 --- a/gtk/gtkviewport.h +++ b/gtk/gtkviewport.h @@ -63,10 +63,6 @@ struct _GtkViewportClass { GtkBinClass parent_class; - void (*set_scroll_adjustments) (GtkViewport *viewport, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - /* Padding for future expansion */ void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); @@ -78,12 +74,18 @@ struct _GtkViewportClass GType gtk_viewport_get_type (void) G_GNUC_CONST; GtkWidget* gtk_viewport_new (GtkAdjustment *hadjustment, GtkAdjustment *vadjustment); + +#ifndef GTK_DISABLE_DEPRECATED + GtkAdjustment* gtk_viewport_get_hadjustment (GtkViewport *viewport); GtkAdjustment* gtk_viewport_get_vadjustment (GtkViewport *viewport); void gtk_viewport_set_hadjustment (GtkViewport *viewport, GtkAdjustment *adjustment); void gtk_viewport_set_vadjustment (GtkViewport *viewport, GtkAdjustment *adjustment); + +#endif + void gtk_viewport_set_shadow_type (GtkViewport *viewport, GtkShadowType type); GtkShadowType gtk_viewport_get_shadow_type (GtkViewport *viewport); diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index a681dd3375..8dee82cbe8 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -859,7 +859,6 @@ gtk_widget_class_init (GtkWidgetClass *klass) klass->destroy = gtk_widget_real_destroy; klass->activate_signal = 0; - klass->set_scroll_adjustments_signal = 0; klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed; klass->show = gtk_widget_real_show; klass->show_all = gtk_widget_show; @@ -5979,56 +5978,6 @@ gtk_widget_activate (GtkWidget *widget) return FALSE; } -/** - * gtk_widget_set_scroll_adjustments: - * @widget: a #GtkWidget - * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL - * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL - * - * For widgets that support scrolling, sets the scroll adjustments and - * returns %TRUE. For widgets that don't support scrolling, does - * nothing and returns %FALSE. Widgets that don't support scrolling - * can be scrolled by placing them in a #GtkViewport, which does - * support scrolling. - * - * Return value: %TRUE if the widget supports scrolling - **/ -gboolean -gtk_widget_set_scroll_adjustments (GtkWidget *widget, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment) -{ - guint signal_id; - GSignalQuery query; - - g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - - if (hadjustment) - g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE); - if (vadjustment) - g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE); - - signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal; - if (!signal_id) - return FALSE; - - g_signal_query (signal_id, &query); - if (!query.signal_id || - !g_type_is_a (query.itype, GTK_TYPE_WIDGET) || - query.return_type != G_TYPE_NONE || - query.n_params != 2 || - query.param_types[0] != GTK_TYPE_ADJUSTMENT || - query.param_types[1] != GTK_TYPE_ADJUSTMENT) - { - g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature", - G_OBJECT_TYPE_NAME (widget), query.signal_name); - return FALSE; - } - - g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment); - return TRUE; -} - static void gtk_widget_reparent_subwindows (GtkWidget *widget, GdkWindow *new_window) diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index c7faeece8f..576f085c01 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -131,10 +131,6 @@ struct _GtkWidget * @activate_signal: The signal to emit when a widget of this class is * activated, gtk_widget_activate() handles the emission. * Implementation of this signal is optional. - * @set_scroll_adjustments_signal: This signal is emitted when a widget of - * this class is added to a scrolling aware parent, - * gtk_widget_set_scroll_adjustments() handles the emission. - * Implementation of this signal is optional. * @adjust_size_request: Convert an initial size request from a widget's * #GtkSizeRequest virtual method implementations into a size request to * be used by parent containers in laying out the widget. @@ -171,8 +167,6 @@ struct _GtkWidgetClass guint activate_signal; - guint set_scroll_adjustments_signal; - /* seldomly overidden */ void (*dispatch_child_properties_changed) (GtkWidget *widget, guint n_pspecs, @@ -499,9 +493,6 @@ gboolean gtk_widget_send_focus_change (GtkWidget *widget, GdkEvent *event); gboolean gtk_widget_activate (GtkWidget *widget); -gboolean gtk_widget_set_scroll_adjustments (GtkWidget *widget, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); void gtk_widget_reparent (GtkWidget *widget, GtkWidget *new_parent); diff --git a/gtk/tests/Makefile.am b/gtk/tests/Makefile.am index 49a9dcb9ca..c492ce65e4 100644 --- a/gtk/tests/Makefile.am +++ b/gtk/tests/Makefile.am @@ -37,7 +37,7 @@ TEST_PROGS += treeview treeview_SOURCES = treeview.c treeview_LDADD = $(progs_ldadd) -#TEST_PROGS += treeview-scrolling +TEST_PROGS += treeview-scrolling treeview_scrolling_SOURCES = treeview-scrolling.c treeview_scrolling_LDADD = $(progs_ldadd) diff --git a/gtk/tests/treeview-scrolling.c b/gtk/tests/treeview-scrolling.c index ade22289ad..d3afe04728 100644 --- a/gtk/tests/treeview-scrolling.c +++ b/gtk/tests/treeview-scrolling.c @@ -125,6 +125,8 @@ scroll_fixture_setup (ScrollFixture *fixture, fixture->tree_view = gtk_tree_view_new_with_model (model); g_object_unref (model); + gtk_scrollable_set_min_display_width (GTK_SCROLLABLE (fixture->tree_view), VIEW_WIDTH); + gtk_scrollable_set_min_display_height (GTK_SCROLLABLE (fixture->tree_view), VIEW_HEIGHT); gtk_widget_set_size_request (fixture->tree_view, VIEW_WIDTH, VIEW_HEIGHT); renderer = gtk_cell_renderer_text_new (); |