[gtk+/popovers: 15/17] window: Pass GtkPositionType when positioning a popover



commit f07375b07abd6e29c048f89a1c8452d6f7896a04
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Nov 13 18:16:30 2013 +0100

    window: Pass GtkPositionType when positioning a popover
    
    This is used then to determine the directions in which the popover
    is allowed to grow, provided the v/hexpand flags are set.

 gtk/gtkpopover.c |    1 +
 gtk/gtkwindow.c  |   35 +++++++++++++++++++++++++++++------
 gtk/gtkwindow.h  |    9 +++++----
 3 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index c2dc008..566826c 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -540,6 +540,7 @@ gtk_popover_update_position (GtkPopover *popover)
 
   gtk_window_set_popover_position (priv->window,
                                    GTK_WIDGET (popover),
+                                   priv->final_position,
                                    win_x, win_y);
 
   gtk_popover_update_shape (popover);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 27c8d79..7139041 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -124,6 +124,7 @@ struct _GtkWindowPopover
 {
   GtkWidget *widget;
   GdkWindow *window;
+  GtkPositionType pos;
   gint x;
   gint y;
 };
@@ -6902,7 +6903,14 @@ popover_size_allocate (GtkWidget        *widget,
 
   if (gtk_widget_get_hexpand (widget))
     {
-      if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
+      if (popover->pos != GTK_POS_LEFT &&
+          popover->pos != GTK_POS_RIGHT)
+        {
+          allocation.width = window_alloc.width;
+          x = 0;
+        }
+      else if ((popover->pos == GTK_POS_RIGHT) ==
+               (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR))
         allocation.width = window_alloc.width - x;
       else
         {
@@ -6912,7 +6920,20 @@ popover_size_allocate (GtkWidget        *widget,
     }
 
   if (gtk_widget_get_vexpand (widget))
-    allocation.height = window_alloc.height - y;
+    {
+      if (popover->pos == GTK_POS_TOP)
+        {
+          allocation.height += allocation.y;
+          y = 0;
+        }
+      else if (popover->pos == GTK_POS_BOTTOM)
+        allocation.height = window_alloc.height - y;
+      else
+        {
+          allocation.height = window_alloc.height;
+          y = 0;
+        }
+    }
 
   gdk_window_move_resize (popover->window, x, y,
                           allocation.width, allocation.height);
@@ -11885,10 +11906,11 @@ gtk_window_remove_popover (GtkWindow *window,
 }
 
 void
-gtk_window_set_popover_position (GtkWindow     *window,
-                                 GtkWidget     *popover,
-                                 gint           x,
-                                 gint           y)
+gtk_window_set_popover_position (GtkWindow       *window,
+                                 GtkWidget       *popover,
+                                 GtkPositionType  pos,
+                                 gint             x,
+                                 gint             y)
 {
   GtkWindowPopover *data = NULL;
   GtkWindowPrivate *priv;
@@ -11909,6 +11931,7 @@ gtk_window_set_popover_position (GtkWindow     *window,
 
   data->x = x;
   data->y = y;
+  data->pos = pos;
 
   if (!data->window && gtk_widget_get_realized (GTK_WIDGET (window)))
     popover_realize (popover, data, window);
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 86af6c9..b3cf424 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -474,10 +474,11 @@ GDK_AVAILABLE_IN_3_12
 void     gtk_window_remove_popover         (GtkWindow     *window,
                                             GtkWidget     *popover);
 GDK_AVAILABLE_IN_3_12
-void     gtk_window_set_popover_position   (GtkWindow     *window,
-                                            GtkWidget     *popover,
-                                            gint           x,
-                                            gint           y);
+void     gtk_window_set_popover_position   (GtkWindow       *window,
+                                            GtkWidget       *popover,
+                                            GtkPositionType  pos,
+                                            gint             x,
+                                            gint             y);
 
 G_END_DECLS
 


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