[gtk/emoji-chooser-fixes: 1/2] emojichooser: Make the variation picker work again



commit 4d7f0f330b41b3a7b50a00cb701123bb8aec2d74
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Mar 17 00:07:37 2020 -0400

    emojichooser: Make the variation picker work again
    
    We can't attach popovers to unsuspecting widget anymore.

 gtk/gtkemojichooser.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c
index 66915d31c9..121b1b697f 100644
--- a/gtk/gtkemojichooser.c
+++ b/gtk/gtkemojichooser.c
@@ -35,6 +35,7 @@
 #include "gtksearchentryprivate.h"
 #include "gtkstylecontext.h"
 #include "gtktext.h"
+#include "gtknative.h"
 #include "gdk/gdkprofilerprivate.h"
 
 /**
@@ -68,6 +69,49 @@
 
 #define BOX_SPACE 6
 
+GType gtk_emoji_chooser_child_get_type (void);
+
+#define GTK_TYPE_EMOJI_CHOOSER_CHILD (gtk_emoji_chooser_child_get_type ())
+
+typedef struct
+{
+  GtkFlowBoxChild parent;
+  GtkWidget *variations;
+} GtkEmojiChooserChild;
+
+typedef struct
+{
+  GtkFlowBoxChildClass parent_class;
+} GtkEmojiChooserChildClass;
+
+G_DEFINE_TYPE (GtkEmojiChooserChild, gtk_emoji_chooser_child, GTK_TYPE_FLOW_BOX_CHILD)
+
+static void
+gtk_emoji_chooser_child_init (GtkEmojiChooserChild *child)
+{
+}
+
+static void
+gtk_emoji_chooser_child_size_allocate (GtkWidget *widget,
+                                       int        width,
+                                       int        height,
+                                       int        baseline)
+{
+  GtkEmojiChooserChild *child = (GtkEmojiChooserChild *)widget;
+
+  GTK_WIDGET_CLASS (gtk_emoji_chooser_child_parent_class)->size_allocate (widget, width, height, baseline);
+  if (child->variations)
+    gtk_native_check_resize (GTK_NATIVE (child->variations));
+}
+
+static void
+gtk_emoji_chooser_child_class_init (GtkEmojiChooserChildClass *class)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+  widget_class->size_allocate = gtk_emoji_chooser_child_size_allocate;
+  gtk_widget_class_set_css_name (widget_class, "emoji");
+}
+
 typedef struct {
   GtkWidget *box;
   GtkWidget *heading;
@@ -293,6 +337,7 @@ show_variations (GtkEmojiChooser *chooser,
   GVariant *emoji_data;
   GtkWidget *parent_popover;
   gunichar modifier;
+  GtkEmojiChooserChild *ch = (GtkEmojiChooserChild *)child;
 
   if (!child)
     return;
@@ -305,7 +350,7 @@ show_variations (GtkEmojiChooser *chooser,
     return;
 
   parent_popover = gtk_widget_get_ancestor (child, GTK_TYPE_POPOVER);
-  popover = gtk_popover_new ();
+  popover = ch->variations = gtk_popover_new ();
   gtk_widget_set_parent (popover, child);
   view = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
   gtk_widget_add_css_class (view, "view");
@@ -419,7 +464,7 @@ add_emoji (GtkWidget    *box,
       return;
     }
 
-  child = g_object_new (GTK_TYPE_FLOW_BOX_CHILD, "css-name", "emoji", NULL);
+  child = g_object_new (GTK_TYPE_EMOJI_CHOOSER_CHILD, NULL);
   g_object_set_data_full (G_OBJECT (child), "emoji-data",
                           g_variant_ref (item),
                           (GDestroyNotify)g_variant_unref);


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