[gtk+/popovers] texthandle: Update child visibility of handles within scrollables



commit 671875dd6e81affe041949e012ee9a400c820fa4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jan 22 16:41:00 2014 +0100

    texthandle: Update child visibility of handles within scrollables
    
    If the rect a handle points to starts falling outside of the parent
    scrollable allocation, the handle will be automatically hidden, and
    shown again when the rectangle is visible too.

 gtk/gtktexthandle.c |   42 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtktexthandle.c b/gtk/gtktexthandle.c
index 145797d..0f05d5a 100644
--- a/gtk/gtktexthandle.c
+++ b/gtk/gtktexthandle.c
@@ -252,6 +252,40 @@ _gtk_text_handle_ensure_widget (GtkTextHandle         *handle,
 }
 
 static void
+_handle_update_child_visible (GtkTextHandle         *handle,
+                              GtkTextHandlePosition  pos)
+{
+  HandleWindow *handle_window;
+  GtkTextHandlePrivate *priv;
+  cairo_rectangle_int_t rect;
+  GtkAllocation allocation;
+  GtkWidget *parent;
+
+  priv = handle->priv;
+  handle_window = &priv->windows[pos];
+
+  if (!priv->parent_scrollable)
+    {
+      gtk_widget_set_child_visible (handle_window->widget, TRUE);
+      return;
+    }
+
+  parent = gtk_widget_get_parent (GTK_WIDGET (priv->parent_scrollable));
+  rect = handle_window->pointing_to;
+
+  gtk_widget_translate_coordinates (priv->parent, parent,
+                                    rect.x, rect.y, &rect.x, &rect.y);
+
+  gtk_widget_get_allocation (GTK_WIDGET (parent), &allocation);
+
+  if (rect.x < 0 || rect.x + rect.width > allocation.width ||
+      rect.y < 0 || rect.y + rect.height > allocation.height)
+    gtk_widget_set_child_visible (handle_window->widget, FALSE);
+  else
+    gtk_widget_set_child_visible (handle_window->widget, TRUE);
+}
+
+static void
 _gtk_text_handle_update (GtkTextHandle         *handle,
                          GtkTextHandlePosition  pos)
 {
@@ -273,9 +307,13 @@ _gtk_text_handle_update (GtkTextHandle         *handle,
       GtkWidget *window;
 
       _gtk_text_handle_ensure_widget (handle, pos);
+      _gtk_text_handle_get_size (handle, &width, &height);
       rect.x = handle_window->pointing_to.x;
       rect.y = handle_window->pointing_to.y;
-      _gtk_text_handle_get_size (handle, &width, &height);
+      rect.width = width;
+      rect.height = 0;
+
+      _handle_update_child_visible (handle, pos);
 
       window = gtk_widget_get_parent (handle_window->widget);
       gtk_widget_translate_coordinates (priv->parent, window,
@@ -290,8 +328,6 @@ _gtk_text_handle_update (GtkTextHandle         *handle,
         }
 
       height += handle_window->pointing_to.height;
-      rect.width = width;
-      rect.height = 0;
       rect.x -= rect.width / 2;
 
       gtk_widget_set_size_request (handle_window->widget, width, height);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]