[gtksourceview] completioncontainer: calculate maximum size based on window position.



commit da6c9d7e3c7583ed5efdd74f55e418875a3a7a19
Author: Christian Hergert <christian hergert me>
Date:   Thu Aug 29 12:19:23 2013 -0700

    completioncontainer: calculate maximum size based on window position.
    
    We can only do this if the window has been realized and we have it's
    offset compared to the origin.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706467

 gtksourceview/gtksourcecompletioncontainer.c |   34 ++++++++++++++++++++++----
 gtksourceview/gtksourcecompletioninfo.c      |    4 +-
 2 files changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletioncontainer.c b/gtksourceview/gtksourcecompletioncontainer.c
index 87a042c..2a305f8 100644
--- a/gtksourceview/gtksourcecompletioncontainer.c
+++ b/gtksourceview/gtksourcecompletioncontainer.c
@@ -35,8 +35,8 @@
 
 #include "gtksourcecompletioncontainer.h"
 
-#define MAX_WIDTH  350
-#define MAX_HEIGHT 180
+#define UNREALIZED_WIDTH  350
+#define MAX_HEIGHT        180
 
 struct _GtkSourceCompletionContainerPrivate
 {
@@ -46,6 +46,30 @@ struct _GtkSourceCompletionContainerPrivate
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceCompletionContainer, _gtk_source_completion_container, GTK_TYPE_BIN);
 
+static gint
+get_max_width (GtkSourceCompletionContainer *container)
+{
+       if (gtk_widget_get_realized (GTK_WIDGET (container)))
+       {
+               GtkWidget *toplevel;
+               GdkWindow *window;
+               GdkScreen *screen;
+               gint max_width;
+               gint xorigin;
+
+               toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
+               window = gtk_widget_get_window (toplevel);
+               screen = gdk_window_get_screen (window);
+
+               gdk_window_get_origin (window, &xorigin, NULL);
+               max_width = gdk_screen_get_width (screen) - xorigin;
+
+               return MAX (max_width, UNREALIZED_WIDTH);
+       }
+
+       return UNREALIZED_WIDTH;
+}
+
 /* gtk_container_add() is overridden. This function calls the GtkBin's add(). */
 static void
 bin_container_add (GtkContainer *container,
@@ -124,7 +148,7 @@ static void
 check_scrolled_window (GtkSourceCompletionContainer *container,
                       GtkRequisition                child_size)
 {
-       if (child_size.width <= MAX_WIDTH &&
+       if (child_size.width <= get_max_width (container) &&
            child_size.height <= MAX_HEIGHT)
        {
                remove_scrolled_window (container);
@@ -168,7 +192,7 @@ _gtk_source_completion_container_get_preferred_width (GtkWidget *widget,
                width += get_vertical_scrollbar_width ();
        }
 
-       width = MIN (width, MAX_WIDTH);
+       width = MIN (width, get_max_width (container));
 
        if (min_width != NULL)
        {
@@ -257,7 +281,7 @@ _gtk_source_completion_container_get_preferred_height (GtkWidget *widget,
 
        check_scrolled_window (container, nat_size);
 
-       if (MAX_WIDTH < nat_size.width)
+       if (get_max_width (container) < nat_size.width)
        {
                scrollbar_height = get_horizontal_scrollbar_height ();
                total_height += scrollbar_height;
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index 3e95624..53e2288 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -461,6 +461,8 @@ move_to_iter (GtkSourceCompletionInfo *window,
        get_iter_pos (view, iter, &x, &y, &height);
        gtk_window_get_size (GTK_WINDOW (window), &w, &h);
 
+       x += window->priv->xoffset;
+
        oy = y;
        compensate_for_gravity (window, &cx, &cy, w, h);
 
@@ -489,8 +491,6 @@ move_to_iter (GtkSourceCompletionInfo *window,
                overlapup = TRUE;
        }
 
-       x += window->priv->xoffset;
-
        /* Make sure that text is still readable */
        move_overlap (&y, h, oy, cy, height, overlapup);
 


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