diff options
author | Jasmine Hassan <[email protected]> | 2012-11-04 15:58:07 +0200 |
---|---|---|
committer | Jasmine Hassan <[email protected]> | 2012-11-13 06:25:03 +0200 |
commit | 4822b93ad236a03564af286f8a65984e9020f53c (patch) | |
tree | 594c0059f26d471cbeffb6fe2bb5abf1ef9470e7 /eel | |
parent | 7dd50ac5969408e7f1fd1d452c13537a45731c58 (diff) | |
download | caja-4822b93ad236a03564af286f8a65984e9020f53c.tar.bz2 caja-4822b93ad236a03564af286f8a65984e9020f53c.tar.xz |
[eel] add wrap_table_child_visible_in, replace eel_gtk_viewport_*_rect
Not upstream, as wrap-table have been removed, and the said functions are
marked for removal from eel-gtk-extensions
Diffstat (limited to 'eel')
-rw-r--r-- | eel/eel-wrap-table.c | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/eel/eel-wrap-table.c b/eel/eel-wrap-table.c index f7e8a6ad..36c6c718 100644 --- a/eel/eel-wrap-table.c +++ b/eel/eel-wrap-table.c @@ -98,6 +98,8 @@ static EelDimensions wrap_table_irect_max_dimensions (const EelDimensions *o static EelDimensions wrap_table_get_max_child_dimensions (const EelWrapTable *wrap_table); static EelDimensions wrap_table_get_content_dimensions (const EelWrapTable *wrap_table); static EelIRect wrap_table_get_content_bounds (const EelWrapTable *wrap_table); +static gboolean wrap_table_child_visible_in (GtkWidget *child, + GtkWidget *scrolled); static gboolean wrap_table_child_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data); @@ -744,23 +746,55 @@ wrap_table_get_content_bounds (const EelWrapTable *wrap_table) return content_bounds; } +/** + * wrap_table_child_visible_in + * + * Get child position relative to parent, then determine whether + * the whole child rectangle is visible in the scrolled window + **/ +static gboolean +wrap_table_child_visible_in (GtkWidget *child, GtkWidget *scrolled) +{ + gint x, y; + GtkAllocation child_alloc, scroll_alloc; + + gtk_widget_translate_coordinates (child, scrolled, 0, 0, &x, &y); + gtk_widget_get_allocation(child, &child_alloc); + gtk_widget_get_allocation(scrolled, &scroll_alloc); + + return (x >= 0 && y >= 0) + && x + child_alloc.width <= scroll_alloc.width + && y + child_alloc.height <= scroll_alloc.height; +} + static gboolean wrap_table_child_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data) { - GtkWidget *parent, *pparent; - GtkAllocation allocation; + gint x, y; + GtkWidget *container, *viewport; + GtkAdjustment *hadj, *vadj; + + container = gtk_widget_get_parent (widget); + if (container) + { + viewport = gtk_widget_get_parent (container); + } + g_assert (container && viewport); + g_assert (GTK_IS_VIEWPORT (viewport)); + g_return_val_if_fail (gtk_widget_get_realized (viewport), FALSE); + + if (!wrap_table_child_visible_in (widget, viewport)) + { + hadj = gtk_viewport_get_hadjustment (GTK_VIEWPORT (viewport)); + vadj = gtk_viewport_get_vadjustment (GTK_VIEWPORT (viewport)); - parent = gtk_widget_get_parent (widget); - if (parent) - pparent = gtk_widget_get_parent (parent); - g_assert (parent && pparent); - g_assert (GTK_IS_VIEWPORT (pparent)); + gtk_widget_translate_coordinates (widget, container, 0, 0, &x, &y); - gtk_widget_get_allocation (widget, &allocation); - eel_gtk_viewport_scroll_to_rect (GTK_VIEWPORT (pparent), - &allocation); + gtk_adjustment_set_value (hadj, MIN (x, hadj->upper - hadj->page_size)); + gtk_adjustment_set_value (vadj, MIN (y, vadj->upper - vadj->page_size)); + } return FALSE; } @@ -977,16 +1011,12 @@ void eel_wrap_table_set_homogeneous (EelWrapTable *wrap_table, gboolean homogeneous) { - g_return_if_fail (EEL_IS_WRAP_TABLE (wrap_table)); - - if (wrap_table->details->homogeneous == homogeneous) + if (EEL_IS_WRAP_TABLE (wrap_table) && + wrap_table->details->homogeneous != homogeneous) { - return; + wrap_table->details->homogeneous = homogeneous; + gtk_widget_queue_resize (GTK_WIDGET (wrap_table)); } - - wrap_table->details->homogeneous = homogeneous; - - gtk_widget_queue_resize (GTK_WIDGET (wrap_table)); } /** |