2017-08-11 15:54:15 +00:00
|
|
|
/* gtkemojichooser.c: An Emoji chooser widget
|
|
|
|
* Copyright 2017, Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkemojichooser.h"
|
|
|
|
|
2017-11-05 15:12:35 +00:00
|
|
|
#include "gtkadjustmentprivate.h"
|
2017-08-11 15:54:15 +00:00
|
|
|
#include "gtkbox.h"
|
|
|
|
#include "gtkbutton.h"
|
|
|
|
#include "gtkcssprovider.h"
|
|
|
|
#include "gtkentry.h"
|
2020-04-14 12:40:08 +00:00
|
|
|
#include "gtkflowboxprivate.h"
|
2017-08-11 15:54:15 +00:00
|
|
|
#include "gtkstack.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkgesturelongpress.h"
|
|
|
|
#include "gtkpopover.h"
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkprivate.h"
|
2019-02-20 15:32:12 +00:00
|
|
|
#include "gtksearchentryprivate.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtkstylecontext.h"
|
2019-02-20 15:32:12 +00:00
|
|
|
#include "gtktext.h"
|
2020-03-17 04:07:37 +00:00
|
|
|
#include "gtknative.h"
|
2020-04-14 01:43:27 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2020-02-04 23:47:42 +00:00
|
|
|
#include "gdk/gdkprofilerprivate.h"
|
2020-10-04 02:26:56 +00:00
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtkprivate.h"
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-02-03 11:49:36 +00:00
|
|
|
/**
|
2020-02-09 00:21:57 +00:00
|
|
|
* SECTION:gtkemojichooser
|
2020-02-03 11:49:36 +00:00
|
|
|
* @Title: GtkEmojiChooser
|
|
|
|
* @Short_description: A popover to choose an Emoji character
|
|
|
|
*
|
|
|
|
* The #GtkEmojiChooser popover is used by text widgets such as #GtkEntry or
|
|
|
|
* #GtkTextView to offer users a convenient way to insert Emoji characters.
|
|
|
|
*
|
2020-05-11 16:47:20 +00:00
|
|
|
* GtkEmojiChooser emits the #GtkEmojiChooser::emoji-picked signal when an
|
2020-02-03 11:49:36 +00:00
|
|
|
* Emoji is selected.
|
2020-02-19 17:13:55 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* popover
|
|
|
|
* ╰── box.emoji-toolbar
|
2020-09-05 11:43:03 +00:00
|
|
|
* ├── button.image-button.emoji-section
|
2020-02-19 17:13:55 +00:00
|
|
|
* ├── ...
|
|
|
|
* ╰── button.image-button.emoji-section
|
|
|
|
* ]|
|
|
|
|
*
|
|
|
|
* Every #GtkEmojiChooser consists of a main node called popover.
|
|
|
|
* The contents of the popover are largely implementation defined
|
|
|
|
* and supposed to inherit general styles.
|
|
|
|
* The bottom toolbar used to switch between different emoji categories
|
|
|
|
* consists of buttons with the .emoji-section style class and gets the
|
|
|
|
* .emoji-toolbar style class itself.
|
|
|
|
*
|
2020-02-03 11:49:36 +00:00
|
|
|
*/
|
|
|
|
|
2018-05-17 15:37:26 +00:00
|
|
|
#define BOX_SPACE 6
|
|
|
|
|
2020-03-17 04:07:37 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:35:13 +00:00
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_child_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkEmojiChooserChild *child = (GtkEmojiChooserChild *)object;
|
|
|
|
|
|
|
|
g_clear_pointer (&child->variations, gtk_widget_unparent);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_emoji_chooser_child_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:07:37 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2020-03-18 01:48:45 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_emoji_chooser_child_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
GtkEmojiChooserChild *child = (GtkEmojiChooserChild *)widget;
|
|
|
|
|
|
|
|
if (child->variations && gtk_widget_is_visible (child->variations))
|
|
|
|
{
|
|
|
|
if (gtk_widget_child_focus (child->variations, direction))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_WIDGET_CLASS (gtk_emoji_chooser_child_parent_class)->focus (widget, direction);
|
|
|
|
}
|
|
|
|
|
2020-04-14 01:44:09 +00:00
|
|
|
static void scroll_to_child (GtkWidget *child);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_emoji_chooser_child_grab_focus (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_widget_grab_focus_self (widget);
|
|
|
|
scroll_to_child (widget);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-03-18 20:52:52 +00:00
|
|
|
static void show_variations (GtkEmojiChooser *chooser,
|
|
|
|
GtkWidget *child);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_child_popup_menu (GtkWidget *widget,
|
|
|
|
const char *action_name,
|
2020-06-18 07:47:16 +00:00
|
|
|
GVariant *parameters)
|
2020-03-18 20:52:52 +00:00
|
|
|
{
|
|
|
|
GtkWidget *chooser;
|
|
|
|
|
|
|
|
chooser = gtk_widget_get_ancestor (widget, GTK_TYPE_EMOJI_CHOOSER);
|
|
|
|
|
|
|
|
show_variations (GTK_EMOJI_CHOOSER (chooser), widget);
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:07:37 +00:00
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_child_class_init (GtkEmojiChooserChildClass *class)
|
|
|
|
{
|
2020-06-02 14:35:13 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
2020-03-17 04:07:37 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2020-06-02 14:35:13 +00:00
|
|
|
|
|
|
|
object_class->dispose = gtk_emoji_chooser_child_dispose;
|
2020-03-17 04:07:37 +00:00
|
|
|
widget_class->size_allocate = gtk_emoji_chooser_child_size_allocate;
|
2020-03-18 01:48:45 +00:00
|
|
|
widget_class->focus = gtk_emoji_chooser_child_focus;
|
2020-04-14 01:44:09 +00:00
|
|
|
widget_class->grab_focus = gtk_emoji_chooser_child_grab_focus;
|
2020-03-18 20:52:52 +00:00
|
|
|
|
|
|
|
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_emoji_chooser_child_popup_menu);
|
|
|
|
|
|
|
|
gtk_widget_class_add_binding_action (widget_class,
|
|
|
|
GDK_KEY_F10, GDK_SHIFT_MASK,
|
|
|
|
"menu.popup",
|
|
|
|
NULL);
|
|
|
|
gtk_widget_class_add_binding_action (widget_class,
|
|
|
|
GDK_KEY_Menu, 0,
|
|
|
|
"menu.popup",
|
|
|
|
NULL);
|
|
|
|
|
2020-03-17 04:07:37 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, "emoji");
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *heading;
|
|
|
|
GtkWidget *button;
|
2020-10-04 02:26:56 +00:00
|
|
|
int group;
|
2017-08-11 15:54:15 +00:00
|
|
|
gunichar label;
|
|
|
|
gboolean empty;
|
|
|
|
} EmojiSection;
|
|
|
|
|
|
|
|
struct _GtkEmojiChooser
|
|
|
|
{
|
|
|
|
GtkPopover parent_instance;
|
|
|
|
|
|
|
|
GtkWidget *search_entry;
|
|
|
|
GtkWidget *stack;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
|
2018-02-27 10:45:34 +00:00
|
|
|
int emoji_max_width;
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
EmojiSection recent;
|
|
|
|
EmojiSection people;
|
|
|
|
EmojiSection body;
|
|
|
|
EmojiSection nature;
|
|
|
|
EmojiSection food;
|
|
|
|
EmojiSection travel;
|
|
|
|
EmojiSection activities;
|
|
|
|
EmojiSection objects;
|
|
|
|
EmojiSection symbols;
|
|
|
|
EmojiSection flags;
|
|
|
|
|
|
|
|
GVariant *data;
|
2019-05-04 02:12:02 +00:00
|
|
|
GtkWidget *box;
|
|
|
|
GVariantIter *iter;
|
|
|
|
guint populate_idle;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
GSettings *settings;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkEmojiChooserClass {
|
|
|
|
GtkPopoverClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
EMOJI_PICKED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkEmojiChooser, gtk_emoji_chooser, GTK_TYPE_POPOVER)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = GTK_EMOJI_CHOOSER (object);
|
|
|
|
|
2019-05-04 02:12:02 +00:00
|
|
|
if (chooser->populate_idle)
|
|
|
|
g_source_remove (chooser->populate_idle);
|
|
|
|
|
2020-02-12 19:23:01 +00:00
|
|
|
g_clear_pointer (&chooser->data, g_variant_unref);
|
|
|
|
g_clear_object (&chooser->settings);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_emoji_chooser_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-04-14 01:43:27 +00:00
|
|
|
scroll_to_section (EmojiSection *section)
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser;
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
GtkAllocation alloc = { 0, 0, 0, 0 };
|
|
|
|
|
2020-04-14 01:43:27 +00:00
|
|
|
chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (section->box, GTK_TYPE_EMOJI_CHOOSER));
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
|
|
|
|
if (section->heading)
|
|
|
|
gtk_widget_get_allocation (section->heading, &alloc);
|
2018-05-17 15:37:26 +00:00
|
|
|
gtk_adjustment_animate_to_value (adj, alloc.y - BOX_SPACE);
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 01:44:09 +00:00
|
|
|
static void
|
|
|
|
scroll_to_child (GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser;
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
GtkAllocation alloc;
|
2020-05-17 21:08:01 +00:00
|
|
|
double pos;
|
2020-04-14 01:44:09 +00:00
|
|
|
double value;
|
|
|
|
double page_size;
|
|
|
|
|
|
|
|
chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (child, GTK_TYPE_EMOJI_CHOOSER));
|
|
|
|
|
|
|
|
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (child, &alloc);
|
|
|
|
|
|
|
|
value = gtk_adjustment_get_value (adj);
|
|
|
|
page_size = gtk_adjustment_get_page_size (adj);
|
|
|
|
|
|
|
|
gtk_widget_translate_coordinates (child, gtk_widget_get_parent (chooser->recent.box), 0, 0, NULL, &pos);
|
|
|
|
|
|
|
|
if (pos < value)
|
|
|
|
gtk_adjustment_animate_to_value (adj, pos);
|
|
|
|
else if (pos + alloc.height >= value + page_size)
|
|
|
|
gtk_adjustment_animate_to_value (adj, value + ((pos + alloc.height) - (value + page_size)));
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
static void
|
|
|
|
add_emoji (GtkWidget *box,
|
|
|
|
gboolean prepend,
|
2017-08-13 19:16:11 +00:00
|
|
|
GVariant *item,
|
2017-11-19 23:03:07 +00:00
|
|
|
gunichar modifier,
|
|
|
|
GtkEmojiChooser *chooser);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
#define MAX_RECENT (7*3)
|
|
|
|
|
2017-08-13 19:16:11 +00:00
|
|
|
static void
|
|
|
|
populate_recent_section (GtkEmojiChooser *chooser)
|
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
GVariant *item;
|
|
|
|
GVariantIter iter;
|
2018-05-17 15:48:34 +00:00
|
|
|
gboolean empty = FALSE;
|
2017-08-13 19:16:11 +00:00
|
|
|
|
|
|
|
variant = g_settings_get_value (chooser->settings, "recent-emoji");
|
|
|
|
g_variant_iter_init (&iter, variant);
|
|
|
|
while ((item = g_variant_iter_next_value (&iter)))
|
|
|
|
{
|
|
|
|
GVariant *emoji_data;
|
|
|
|
gunichar modifier;
|
|
|
|
|
|
|
|
emoji_data = g_variant_get_child_value (item, 0);
|
|
|
|
g_variant_get_child (item, 1, "u", &modifier);
|
2017-11-19 23:03:07 +00:00
|
|
|
add_emoji (chooser->recent.box, FALSE, emoji_data, modifier, chooser);
|
2017-08-13 19:16:11 +00:00
|
|
|
g_variant_unref (emoji_data);
|
|
|
|
g_variant_unref (item);
|
2018-05-17 15:48:34 +00:00
|
|
|
empty = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-05-04 16:19:43 +00:00
|
|
|
gtk_widget_set_visible (chooser->recent.box, !empty);
|
|
|
|
gtk_widget_set_sensitive (chooser->recent.button, !empty);
|
|
|
|
|
2017-08-13 19:16:11 +00:00
|
|
|
g_variant_unref (variant);
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
static void
|
|
|
|
add_recent_item (GtkEmojiChooser *chooser,
|
2017-08-13 19:16:11 +00:00
|
|
|
GVariant *item,
|
|
|
|
gunichar modifier)
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
|
|
|
GList *children, *l;
|
|
|
|
int i;
|
|
|
|
GVariantBuilder builder;
|
2020-05-09 12:26:52 +00:00
|
|
|
GtkWidget *child;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
g_variant_ref (item);
|
|
|
|
|
2020-10-04 02:26:56 +00:00
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a((ausasu)u)"));
|
|
|
|
g_variant_builder_add (&builder, "(@(ausasu)u)", item, modifier);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
children = NULL;
|
|
|
|
for (child = gtk_widget_get_last_child (chooser->recent.box);
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_prev_sibling (child))
|
|
|
|
children = g_list_prepend (children, child);
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
for (l = children, i = 1; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
GVariant *item2 = g_object_get_data (G_OBJECT (l->data), "emoji-data");
|
2017-08-13 19:16:11 +00:00
|
|
|
gunichar modifier2 = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (l->data), "modifier"));
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2017-08-13 19:16:11 +00:00
|
|
|
if (modifier == modifier2 && g_variant_equal (item, item2))
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_flow_box_remove (GTK_FLOW_BOX (chooser->recent.box), l->data);
|
2017-08-11 15:54:15 +00:00
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (i >= MAX_RECENT)
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_flow_box_remove (GTK_FLOW_BOX (chooser->recent.box), l->data);
|
2017-08-11 15:54:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-04 02:26:56 +00:00
|
|
|
g_variant_builder_add (&builder, "(@(ausasu)u)", item2, modifier2);
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
|
2017-11-19 23:03:07 +00:00
|
|
|
add_emoji (chooser->recent.box, TRUE, item, modifier, chooser);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2018-05-17 15:48:34 +00:00
|
|
|
/* Enable recent */
|
|
|
|
gtk_widget_show (chooser->recent.box);
|
|
|
|
gtk_widget_set_sensitive (chooser->recent.button, TRUE);
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
g_settings_set_value (chooser->settings, "recent-emoji", g_variant_builder_end (&builder));
|
|
|
|
|
|
|
|
g_variant_unref (item);
|
|
|
|
}
|
|
|
|
|
2020-10-02 03:35:06 +00:00
|
|
|
static gboolean
|
|
|
|
should_close (GtkEmojiChooser *chooser)
|
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
GdkSeat *seat;
|
|
|
|
GdkDevice *device;
|
|
|
|
GdkModifierType state;
|
|
|
|
|
|
|
|
display = gtk_widget_get_display (GTK_WIDGET (chooser));
|
|
|
|
seat = gdk_display_get_default_seat (display);
|
|
|
|
device = gdk_seat_get_keyboard (seat);
|
|
|
|
state = gdk_device_get_modifier_state (device);
|
|
|
|
|
|
|
|
return (state & GDK_CONTROL_MASK) == 0;
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
static void
|
|
|
|
emoji_activated (GtkFlowBox *box,
|
|
|
|
GtkFlowBoxChild *child,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = data;
|
|
|
|
char *text;
|
|
|
|
GtkWidget *label;
|
|
|
|
GVariant *item;
|
2017-08-13 19:16:11 +00:00
|
|
|
gunichar modifier;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-10-02 03:35:06 +00:00
|
|
|
if (should_close (chooser))
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (chooser));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
|
|
|
popover = gtk_widget_get_ancestor (GTK_WIDGET (box), GTK_TYPE_POPOVER);
|
|
|
|
if (popover != GTK_WIDGET (chooser))
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (popover));
|
|
|
|
}
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-05-03 00:53:40 +00:00
|
|
|
label = gtk_flow_box_child_get_child (child);
|
2017-08-11 15:54:15 +00:00
|
|
|
text = g_strdup (gtk_label_get_label (GTK_LABEL (label)));
|
|
|
|
|
|
|
|
item = (GVariant*) g_object_get_data (G_OBJECT (child), "emoji-data");
|
2017-08-13 19:16:11 +00:00
|
|
|
modifier = (gunichar) GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (child), "modifier"));
|
|
|
|
add_recent_item (chooser, item, modifier);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
g_signal_emit (data, signals[EMOJI_PICKED], 0, text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
2017-11-20 03:40:07 +00:00
|
|
|
static gboolean
|
|
|
|
has_variations (GVariant *emoji_data)
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
2017-08-13 19:16:11 +00:00
|
|
|
GVariant *codes;
|
|
|
|
int i;
|
|
|
|
gboolean has_variations;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2017-08-13 19:16:11 +00:00
|
|
|
has_variations = FALSE;
|
|
|
|
codes = g_variant_get_child_value (emoji_data, 0);
|
|
|
|
for (i = 0; i < g_variant_n_children (codes); i++)
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
2017-08-13 19:16:11 +00:00
|
|
|
gunichar code;
|
|
|
|
g_variant_get_child (codes, i, "u", &code);
|
|
|
|
if (code == 0)
|
|
|
|
{
|
|
|
|
has_variations = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
2017-08-13 19:16:11 +00:00
|
|
|
g_variant_unref (codes);
|
2017-11-20 03:40:07 +00:00
|
|
|
|
|
|
|
return has_variations;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_variations (GtkEmojiChooser *chooser,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkWidget *popover;
|
|
|
|
GtkWidget *view;
|
|
|
|
GtkWidget *box;
|
|
|
|
GVariant *emoji_data;
|
|
|
|
GtkWidget *parent_popover;
|
|
|
|
gunichar modifier;
|
2020-03-17 04:07:37 +00:00
|
|
|
GtkEmojiChooserChild *ch = (GtkEmojiChooserChild *)child;
|
2017-11-20 03:40:07 +00:00
|
|
|
|
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
|
|
|
|
emoji_data = (GVariant*) g_object_get_data (G_OBJECT (child), "emoji-data");
|
|
|
|
if (!emoji_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!has_variations (emoji_data))
|
2017-08-13 19:16:11 +00:00
|
|
|
return;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
parent_popover = gtk_widget_get_ancestor (child, GTK_TYPE_POPOVER);
|
2020-06-02 14:35:13 +00:00
|
|
|
g_clear_pointer (&ch->variations, gtk_widget_unparent);
|
2020-03-17 04:07:37 +00:00
|
|
|
popover = ch->variations = gtk_popover_new ();
|
2020-03-18 01:48:45 +00:00
|
|
|
gtk_popover_set_autohide (GTK_POPOVER (popover), TRUE);
|
2020-02-24 12:21:46 +00:00
|
|
|
gtk_widget_set_parent (popover, child);
|
2017-08-11 15:54:15 +00:00
|
|
|
view = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (view, "view");
|
2017-08-11 15:54:15 +00:00
|
|
|
box = gtk_flow_box_new ();
|
|
|
|
gtk_flow_box_set_homogeneous (GTK_FLOW_BOX (box), TRUE);
|
|
|
|
gtk_flow_box_set_min_children_per_line (GTK_FLOW_BOX (box), 6);
|
|
|
|
gtk_flow_box_set_max_children_per_line (GTK_FLOW_BOX (box), 6);
|
|
|
|
gtk_flow_box_set_activate_on_single_click (GTK_FLOW_BOX (box), TRUE);
|
|
|
|
gtk_flow_box_set_selection_mode (GTK_FLOW_BOX (box), GTK_SELECTION_NONE);
|
2017-12-31 04:24:22 +00:00
|
|
|
g_object_set (box, "accept-unpaired-release", TRUE, NULL);
|
2020-05-02 02:22:20 +00:00
|
|
|
gtk_popover_set_child (GTK_POPOVER (popover), view);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (view), box);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
g_signal_connect (box, "child-activated", G_CALLBACK (emoji_activated), parent_popover);
|
|
|
|
|
2018-10-11 10:27:17 +00:00
|
|
|
add_emoji (box, FALSE, emoji_data, 0, chooser);
|
2017-08-13 19:16:11 +00:00
|
|
|
for (modifier = 0x1f3fb; modifier <= 0x1f3ff; modifier++)
|
2018-10-11 10:27:17 +00:00
|
|
|
add_emoji (box, FALSE, emoji_data, modifier, chooser);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
gtk_popover_popup (GTK_POPOVER (popover));
|
|
|
|
}
|
|
|
|
|
2017-11-19 21:18:28 +00:00
|
|
|
static void
|
|
|
|
long_pressed_cb (GtkGesture *gesture,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = data;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
box = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
child = GTK_WIDGET (gtk_flow_box_get_child_at_pos (GTK_FLOW_BOX (box), x, y));
|
|
|
|
show_variations (chooser, child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pressed_cb (GtkGesture *gesture,
|
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = data;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
box = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
child = GTK_WIDGET (gtk_flow_box_get_child_at_pos (GTK_FLOW_BOX (box), x, y));
|
|
|
|
show_variations (chooser, child);
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
static void
|
|
|
|
add_emoji (GtkWidget *box,
|
|
|
|
gboolean prepend,
|
2017-08-13 19:16:11 +00:00
|
|
|
GVariant *item,
|
2017-11-19 23:03:07 +00:00
|
|
|
gunichar modifier,
|
|
|
|
GtkEmojiChooser *chooser)
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
GtkWidget *label;
|
|
|
|
PangoAttrList *attrs;
|
2017-08-13 19:16:11 +00:00
|
|
|
GVariant *codes;
|
2017-08-11 15:54:15 +00:00
|
|
|
char text[64];
|
|
|
|
char *p = text;
|
2017-08-13 19:16:11 +00:00
|
|
|
int i;
|
2017-12-18 03:09:08 +00:00
|
|
|
PangoLayout *layout;
|
|
|
|
PangoRectangle rect;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2017-08-13 19:16:11 +00:00
|
|
|
codes = g_variant_get_child_value (item, 0);
|
|
|
|
for (i = 0; i < g_variant_n_children (codes); i++)
|
|
|
|
{
|
|
|
|
gunichar code;
|
|
|
|
|
|
|
|
g_variant_get_child (codes, i, "u", &code);
|
|
|
|
if (code == 0)
|
|
|
|
code = modifier;
|
|
|
|
if (code != 0)
|
|
|
|
p += g_unichar_to_utf8 (code, p);
|
|
|
|
}
|
2017-09-24 16:15:41 +00:00
|
|
|
g_variant_unref (codes);
|
2018-12-04 02:46:09 +00:00
|
|
|
p += g_unichar_to_utf8 (0xFE0F, p); /* U+FE0F is the Emoji variation selector */
|
2017-09-24 16:15:41 +00:00
|
|
|
p[0] = 0;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2018-02-27 10:45:34 +00:00
|
|
|
label = gtk_label_new (text);
|
2017-08-11 15:54:15 +00:00
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_scale_new (PANGO_SCALE_X_LARGE));
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (label), attrs);
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
|
2017-12-18 03:09:08 +00:00
|
|
|
layout = gtk_label_get_layout (GTK_LABEL (label));
|
|
|
|
pango_layout_get_extents (layout, &rect, NULL);
|
|
|
|
|
|
|
|
/* Check for fallback rendering that generates too wide items */
|
2018-07-19 21:57:19 +00:00
|
|
|
if (pango_layout_get_unknown_glyphs_count (layout) > 0 ||
|
|
|
|
rect.width >= 1.5 * chooser->emoji_max_width)
|
2017-12-18 03:09:08 +00:00
|
|
|
{
|
2020-02-20 18:21:59 +00:00
|
|
|
g_object_ref_sink (label);
|
|
|
|
g_object_unref (label);
|
2017-12-18 03:09:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:07:37 +00:00
|
|
|
child = g_object_new (GTK_TYPE_EMOJI_CHOOSER_CHILD, NULL);
|
2017-08-11 15:54:15 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (child), "emoji-data",
|
2017-08-13 19:16:11 +00:00
|
|
|
g_variant_ref (item),
|
2017-08-11 15:54:15 +00:00
|
|
|
(GDestroyNotify)g_variant_unref);
|
2017-08-13 19:16:11 +00:00
|
|
|
if (modifier != 0)
|
|
|
|
g_object_set_data (G_OBJECT (child), "modifier", GUINT_TO_POINTER (modifier));
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-05-03 00:53:40 +00:00
|
|
|
gtk_flow_box_child_set_child (GTK_FLOW_BOX_CHILD (child), label);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_flow_box_insert (GTK_FLOW_BOX (box), child, prepend ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
2020-10-04 02:26:56 +00:00
|
|
|
GBytes *
|
|
|
|
get_emoji_data (void)
|
|
|
|
{
|
|
|
|
GBytes *bytes;
|
|
|
|
const char *lang;
|
|
|
|
char q[10];
|
|
|
|
char *path;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
lang = pango_language_to_string (gtk_get_default_language ());
|
|
|
|
if (strchr (lang, '-'))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; lang[i] != '-' && i < 9; i++)
|
|
|
|
q[i] = lang[i];
|
|
|
|
q[i] = '\0';
|
|
|
|
lang = q;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = g_strconcat ("/org/gtk/libgtk/emoji/", lang, ".data", NULL);
|
|
|
|
bytes = g_resources_lookup_data (path, 0, &error);
|
|
|
|
if (bytes)
|
|
|
|
{
|
|
|
|
g_debug ("Found emoji data for %s in resource %s", lang, path);
|
|
|
|
g_free (path);
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_error_matches (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
GMappedFile *file;
|
|
|
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
filename = g_strconcat ("/usr/share/gtk-4.0/emoji/", lang, ".gresource", NULL);
|
|
|
|
file = g_mapped_file_new (filename, FALSE, NULL);
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
GBytes *data;
|
|
|
|
GResource *resource;
|
|
|
|
|
|
|
|
data = g_mapped_file_get_bytes (file);
|
|
|
|
g_mapped_file_unref (file);
|
|
|
|
|
|
|
|
resource = g_resource_new_from_data (data, NULL);
|
|
|
|
g_bytes_unref (data);
|
|
|
|
|
|
|
|
g_debug ("Registering resource for Emoji data for %s from file %s", lang, filename);
|
|
|
|
g_resources_register (resource);
|
|
|
|
g_resource_unref (resource);
|
|
|
|
|
|
|
|
bytes = g_resources_lookup_data (path, 0, NULL);
|
|
|
|
if (bytes)
|
|
|
|
{
|
|
|
|
g_debug ("Found emoji data for %s in resource %s", lang, path);
|
|
|
|
g_free (path);
|
|
|
|
g_free (filename);
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
return g_resources_lookup_data ("/org/gtk/libgtk/emoji/en.data", 0, NULL);
|
|
|
|
}
|
|
|
|
|
2019-05-04 02:12:02 +00:00
|
|
|
static gboolean
|
|
|
|
populate_emoji_chooser (gpointer data)
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
2019-05-04 02:12:02 +00:00
|
|
|
GtkEmojiChooser *chooser = data;
|
2017-08-11 15:54:15 +00:00
|
|
|
GVariant *item;
|
2020-08-19 22:49:34 +00:00
|
|
|
gint64 start, now;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
start = GDK_PROFILER_CURRENT_TIME;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2019-05-04 02:12:02 +00:00
|
|
|
if (!chooser->data)
|
|
|
|
{
|
2020-10-04 02:26:56 +00:00
|
|
|
GBytes *bytes;
|
|
|
|
|
|
|
|
bytes = get_emoji_data ();
|
|
|
|
|
|
|
|
chooser->data = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE ("a(ausasu)"), bytes, TRUE));
|
2019-05-04 02:12:02 +00:00
|
|
|
g_bytes_unref (bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!chooser->iter)
|
|
|
|
{
|
|
|
|
chooser->iter = g_variant_iter_new (chooser->data);
|
|
|
|
chooser->box = chooser->people.box;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((item = g_variant_iter_next_value (chooser->iter)))
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
2020-10-04 02:26:56 +00:00
|
|
|
guint group;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-10-04 02:26:56 +00:00
|
|
|
g_variant_get_child (item, 3, "u", &group);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-10-04 02:26:56 +00:00
|
|
|
if (group == chooser->people.group)
|
|
|
|
chooser->box = chooser->people.box;
|
|
|
|
else if (group == chooser->body.group)
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->box = chooser->body.box;
|
2020-10-04 02:26:56 +00:00
|
|
|
else if (group == chooser->nature.group)
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->box = chooser->nature.box;
|
2020-10-04 02:26:56 +00:00
|
|
|
else if (group == chooser->food.group)
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->box = chooser->food.box;
|
2020-10-04 02:26:56 +00:00
|
|
|
else if (group == chooser->travel.group)
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->box = chooser->travel.box;
|
2020-10-04 02:26:56 +00:00
|
|
|
else if (group == chooser->activities.group)
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->box = chooser->activities.box;
|
2020-10-04 02:26:56 +00:00
|
|
|
else if (group == chooser->objects.group)
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->box = chooser->objects.box;
|
2020-10-04 02:26:56 +00:00
|
|
|
else if (group == chooser->symbols.group)
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->box = chooser->symbols.box;
|
2020-10-04 02:26:56 +00:00
|
|
|
else if (group == chooser->flags.group)
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->box = chooser->flags.box;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2019-05-04 02:12:02 +00:00
|
|
|
add_emoji (chooser->box, FALSE, item, 0, chooser);
|
2017-10-17 06:49:06 +00:00
|
|
|
g_variant_unref (item);
|
2019-05-04 02:12:02 +00:00
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
now = GDK_PROFILER_CURRENT_TIME;
|
|
|
|
if (now > start + 2000000) /* 2 ms */
|
2020-02-04 23:47:42 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
gdk_profiler_add_mark (start, (now - start), "emojichooser", "populate");
|
2020-02-04 23:47:42 +00:00
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
2017-08-15 02:43:01 +00:00
|
|
|
|
2019-05-04 02:12:02 +00:00
|
|
|
g_variant_iter_free (chooser->iter);
|
|
|
|
chooser->iter = NULL;
|
|
|
|
chooser->box = NULL;
|
|
|
|
chooser->populate_idle = 0;
|
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
gdk_profiler_end_mark (start, "emojichooser", "populate (finish)");
|
2020-02-04 23:47:42 +00:00
|
|
|
|
2019-05-04 16:19:43 +00:00
|
|
|
return G_SOURCE_REMOVE;
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
adj_value_changed (GtkAdjustment *adj,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = data;
|
|
|
|
double value = gtk_adjustment_get_value (adj);
|
2017-09-04 18:56:47 +00:00
|
|
|
EmojiSection const *sections[] = {
|
|
|
|
&chooser->recent,
|
|
|
|
&chooser->people,
|
|
|
|
&chooser->body,
|
|
|
|
&chooser->nature,
|
|
|
|
&chooser->food,
|
|
|
|
&chooser->travel,
|
|
|
|
&chooser->activities,
|
|
|
|
&chooser->objects,
|
|
|
|
&chooser->symbols,
|
|
|
|
&chooser->flags,
|
|
|
|
};
|
|
|
|
EmojiSection const *select_section = sections[0];
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
/* Figure out which section the current scroll position is within */
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (sections); ++i)
|
|
|
|
{
|
|
|
|
EmojiSection const *section = sections[i];
|
|
|
|
GtkAllocation alloc;
|
|
|
|
|
2019-05-04 16:19:43 +00:00
|
|
|
if (!gtk_widget_get_visible (section->box))
|
|
|
|
continue;
|
|
|
|
|
2017-09-04 18:56:47 +00:00
|
|
|
if (section->heading)
|
|
|
|
gtk_widget_get_allocation (section->heading, &alloc);
|
|
|
|
else
|
|
|
|
gtk_widget_get_allocation (section->box, &alloc);
|
|
|
|
|
2018-05-17 15:37:26 +00:00
|
|
|
if (value < alloc.y - BOX_SPACE)
|
2017-09-04 18:56:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
select_section = section;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Un/Check the section buttons accordingly */
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (sections); ++i)
|
|
|
|
{
|
|
|
|
EmojiSection const *section = sections[i];
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2017-09-04 18:56:47 +00:00
|
|
|
if (section == select_section)
|
|
|
|
gtk_widget_set_state_flags (section->button, GTK_STATE_FLAG_CHECKED, FALSE);
|
|
|
|
else
|
|
|
|
gtk_widget_unset_state_flags (section->button, GTK_STATE_FLAG_CHECKED);
|
|
|
|
}
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 04:28:53 +00:00
|
|
|
static gboolean
|
|
|
|
match_tokens (const char **term_tokens,
|
|
|
|
const char **hit_tokens)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
gboolean matched;
|
|
|
|
|
|
|
|
matched = TRUE;
|
|
|
|
|
|
|
|
for (i = 0; term_tokens[i]; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; hit_tokens[j]; j++)
|
|
|
|
if (g_str_has_prefix (hit_tokens[j], term_tokens[i]))
|
|
|
|
goto one_matched;
|
|
|
|
|
|
|
|
matched = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
one_matched:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return matched;
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
static gboolean
|
|
|
|
filter_func (GtkFlowBoxChild *child,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
EmojiSection *section = data;
|
|
|
|
GtkEmojiChooser *chooser;
|
|
|
|
GVariant *emoji_data;
|
|
|
|
const char *text;
|
|
|
|
const char *name;
|
2020-04-15 02:29:25 +00:00
|
|
|
const char **keywords;
|
2020-04-15 04:28:53 +00:00
|
|
|
char **term_tokens;
|
|
|
|
char **name_tokens;
|
2017-08-11 15:54:15 +00:00
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (GTK_WIDGET (child), GTK_TYPE_EMOJI_CHOOSER));
|
2019-02-20 15:32:12 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (chooser->search_entry));
|
2017-08-11 15:54:15 +00:00
|
|
|
emoji_data = (GVariant *) g_object_get_data (G_OBJECT (child), "emoji-data");
|
|
|
|
|
2017-08-13 11:49:13 +00:00
|
|
|
if (text[0] == 0)
|
2017-08-11 15:54:15 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!emoji_data)
|
|
|
|
goto out;
|
|
|
|
|
2020-04-15 04:28:53 +00:00
|
|
|
term_tokens = g_str_tokenize_and_fold (text, "en", NULL);
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
g_variant_get_child (emoji_data, 1, "&s", &name);
|
2020-04-15 04:28:53 +00:00
|
|
|
name_tokens = g_str_tokenize_and_fold (name, "en", NULL);
|
2020-04-15 05:19:09 +00:00
|
|
|
g_variant_get_child (emoji_data, 2, "^a&s", &keywords);
|
2020-04-15 04:28:53 +00:00
|
|
|
|
|
|
|
res = match_tokens ((const char **)term_tokens, (const char **)name_tokens) ||
|
|
|
|
match_tokens ((const char **)term_tokens, keywords);
|
|
|
|
|
|
|
|
g_strfreev (term_tokens);
|
|
|
|
g_strfreev (name_tokens);
|
2020-04-15 02:29:25 +00:00
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
out:
|
|
|
|
if (res)
|
|
|
|
section->empty = FALSE;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
invalidate_section (EmojiSection *section)
|
|
|
|
{
|
|
|
|
section->empty = TRUE;
|
|
|
|
gtk_flow_box_invalidate_filter (GTK_FLOW_BOX (section->box));
|
|
|
|
}
|
|
|
|
|
2017-08-13 13:27:37 +00:00
|
|
|
static void
|
|
|
|
update_headings (GtkEmojiChooser *chooser)
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
|
|
|
gtk_widget_set_visible (chooser->people.heading, !chooser->people.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->people.box, !chooser->people.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_widget_set_visible (chooser->body.heading, !chooser->body.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->body.box, !chooser->body.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_widget_set_visible (chooser->nature.heading, !chooser->nature.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->nature.box, !chooser->nature.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_widget_set_visible (chooser->food.heading, !chooser->food.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->food.box, !chooser->food.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_widget_set_visible (chooser->travel.heading, !chooser->travel.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->travel.box, !chooser->travel.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_widget_set_visible (chooser->activities.heading, !chooser->activities.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->activities.box, !chooser->activities.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_widget_set_visible (chooser->objects.heading, !chooser->objects.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->objects.box, !chooser->objects.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_widget_set_visible (chooser->symbols.heading, !chooser->symbols.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->symbols.box, !chooser->symbols.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_widget_set_visible (chooser->flags.heading, !chooser->flags.empty);
|
2017-08-30 12:36:56 +00:00
|
|
|
gtk_widget_set_visible (chooser->flags.box, !chooser->flags.empty);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
if (chooser->recent.empty && chooser->people.empty &&
|
|
|
|
chooser->body.empty && chooser->nature.empty &&
|
|
|
|
chooser->food.empty && chooser->travel.empty &&
|
|
|
|
chooser->activities.empty && chooser->objects.empty &&
|
|
|
|
chooser->symbols.empty && chooser->flags.empty)
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (chooser->stack), "empty");
|
|
|
|
else
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (chooser->stack), "list");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
search_changed (GtkEntry *entry,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = data;
|
|
|
|
|
|
|
|
invalidate_section (&chooser->recent);
|
|
|
|
invalidate_section (&chooser->people);
|
|
|
|
invalidate_section (&chooser->body);
|
|
|
|
invalidate_section (&chooser->nature);
|
|
|
|
invalidate_section (&chooser->food);
|
|
|
|
invalidate_section (&chooser->travel);
|
|
|
|
invalidate_section (&chooser->activities);
|
|
|
|
invalidate_section (&chooser->objects);
|
|
|
|
invalidate_section (&chooser->symbols);
|
|
|
|
invalidate_section (&chooser->flags);
|
|
|
|
|
2017-08-13 13:27:37 +00:00
|
|
|
update_headings (chooser);
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 16:55:52 +00:00
|
|
|
static void
|
|
|
|
stop_search (GtkEntry *entry,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (data));
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
static void
|
|
|
|
setup_section (GtkEmojiChooser *chooser,
|
2020-10-04 02:26:56 +00:00
|
|
|
EmojiSection *section,
|
|
|
|
int group,
|
|
|
|
const char *icon)
|
2017-08-11 15:54:15 +00:00
|
|
|
{
|
2020-10-04 02:26:56 +00:00
|
|
|
section->group = group;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2018-07-19 21:24:11 +00:00
|
|
|
gtk_button_set_icon_name (GTK_BUTTON (section->button), icon);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-04-14 19:03:57 +00:00
|
|
|
gtk_flow_box_disable_move_cursor (GTK_FLOW_BOX (section->box));
|
2017-08-11 15:54:15 +00:00
|
|
|
gtk_flow_box_set_filter_func (GTK_FLOW_BOX (section->box), filter_func, section, NULL);
|
2020-04-14 01:43:27 +00:00
|
|
|
g_signal_connect_swapped (section->button, "clicked", G_CALLBACK (scroll_to_section), section);
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_init (GtkEmojiChooser *chooser)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj;
|
2019-02-20 15:32:12 +00:00
|
|
|
GtkText *text;
|
2017-08-13 19:16:11 +00:00
|
|
|
|
2019-04-02 19:22:48 +00:00
|
|
|
chooser->settings = g_settings_new ("org.gtk.gtk4.Settings.EmojiChooser");
|
2017-08-11 15:54:15 +00:00
|
|
|
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (chooser));
|
|
|
|
|
2019-02-20 15:32:12 +00:00
|
|
|
text = gtk_search_entry_get_text_widget (GTK_SEARCH_ENTRY (chooser->search_entry));
|
|
|
|
gtk_text_set_input_hints (text, GTK_INPUT_HINT_NO_EMOJI);
|
|
|
|
|
2018-02-27 10:45:34 +00:00
|
|
|
/* Get a reasonable maximum width for an emoji. We do this to
|
|
|
|
* skip overly wide fallback rendering for certain emojis the
|
|
|
|
* font does not contain and therefore end up being rendered
|
2018-07-19 21:57:19 +00:00
|
|
|
* as multiply glyphs.
|
|
|
|
*/
|
2018-02-27 10:45:34 +00:00
|
|
|
{
|
|
|
|
PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET (chooser), "🙂");
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
PangoRectangle rect;
|
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_scale_new (PANGO_SCALE_X_LARGE));
|
|
|
|
pango_layout_set_attributes (layout, attrs);
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
|
|
|
|
pango_layout_get_extents (layout, &rect, NULL);
|
|
|
|
chooser->emoji_max_width = rect.width;
|
|
|
|
|
|
|
|
g_object_unref (layout);
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
|
|
|
|
g_signal_connect (adj, "value-changed", G_CALLBACK (adj_value_changed), chooser);
|
|
|
|
|
2020-10-04 02:26:56 +00:00
|
|
|
setup_section (chooser, &chooser->recent, -1, "emoji-recent-symbolic");
|
|
|
|
setup_section (chooser, &chooser->people, 0, "emoji-people-symbolic");
|
|
|
|
setup_section (chooser, &chooser->body, 1, "emoji-body-symbolic");
|
|
|
|
setup_section (chooser, &chooser->nature, 3, "emoji-nature-symbolic");
|
|
|
|
setup_section (chooser, &chooser->food, 4, "emoji-food-symbolic");
|
|
|
|
setup_section (chooser, &chooser->travel, 5, "emoji-travel-symbolic");
|
|
|
|
setup_section (chooser, &chooser->activities, 6, "emoji-activities-symbolic");
|
|
|
|
setup_section (chooser, &chooser->objects, 7, "emoji-objects-symbolic");
|
|
|
|
setup_section (chooser, &chooser->symbols, 8, "emoji-symbols-symbolic");
|
|
|
|
setup_section (chooser, &chooser->flags, 9, "emoji-flags-symbolic");
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2017-08-13 19:16:11 +00:00
|
|
|
populate_recent_section (chooser);
|
2017-09-02 17:47:47 +00:00
|
|
|
|
2019-05-04 02:12:02 +00:00
|
|
|
chooser->populate_idle = g_idle_add (populate_emoji_chooser, chooser);
|
2019-05-07 18:41:22 +00:00
|
|
|
g_source_set_name_by_id (chooser->populate_idle, "[gtk] populate_emoji_chooser");
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_show (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = GTK_EMOJI_CHOOSER (widget);
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
|
2017-08-30 17:55:59 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_emoji_chooser_parent_class)->show (widget);
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
|
|
|
|
gtk_adjustment_set_value (adj, 0);
|
2019-05-04 16:19:43 +00:00
|
|
|
adj_value_changed (adj, chooser);
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2019-02-20 15:32:12 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (chooser->search_entry), "");
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 12:40:08 +00:00
|
|
|
static EmojiSection *
|
|
|
|
find_next_section (GtkEmojiChooser *chooser,
|
|
|
|
GtkWidget *box,
|
|
|
|
gboolean down)
|
|
|
|
{
|
|
|
|
EmojiSection *next;
|
|
|
|
|
|
|
|
if (box == chooser->recent.box)
|
|
|
|
next = down ? &chooser->people : NULL;
|
|
|
|
else if (box == chooser->people.box)
|
|
|
|
next = down ? &chooser->body : &chooser->recent;
|
|
|
|
else if (box == chooser->body.box)
|
|
|
|
next = down ? &chooser->nature : &chooser->people;
|
|
|
|
else if (box == chooser->nature.box)
|
|
|
|
next = down ? &chooser->food : &chooser->body;
|
|
|
|
else if (box == chooser->food.box)
|
|
|
|
next = down ? &chooser->travel : &chooser->nature;
|
|
|
|
else if (box == chooser->travel.box)
|
|
|
|
next = down ? &chooser->activities : &chooser->food;
|
|
|
|
else if (box == chooser->activities.box)
|
|
|
|
next = down ? &chooser->objects : &chooser->travel;
|
|
|
|
else if (box == chooser->objects.box)
|
|
|
|
next = down ? &chooser->symbols : &chooser->activities;
|
|
|
|
else if (box == chooser->symbols.box)
|
|
|
|
next = down ? &chooser->flags : &chooser->objects;
|
|
|
|
else if (box == chooser->flags.box)
|
|
|
|
next = down ? NULL : &chooser->symbols;
|
|
|
|
else
|
|
|
|
next = NULL;
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2020-04-14 01:43:27 +00:00
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_scroll_section (GtkWidget *widget,
|
|
|
|
const char *action_name,
|
|
|
|
GVariant *parameter)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = GTK_EMOJI_CHOOSER (widget);
|
|
|
|
int direction = g_variant_get_int32 (parameter);
|
|
|
|
GtkWidget *focus;
|
|
|
|
GtkWidget *box;
|
|
|
|
EmojiSection *next;
|
|
|
|
|
|
|
|
focus = gtk_root_get_focus (gtk_widget_get_root (widget));
|
|
|
|
if (focus == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gtk_widget_is_ancestor (focus, chooser->search_entry))
|
|
|
|
box = chooser->recent.box;
|
|
|
|
else
|
|
|
|
box = gtk_widget_get_ancestor (focus, GTK_TYPE_FLOW_BOX);
|
|
|
|
|
2020-04-14 12:40:08 +00:00
|
|
|
next = find_next_section (chooser, box, direction > 0);
|
2020-04-14 01:43:27 +00:00
|
|
|
|
|
|
|
if (next)
|
|
|
|
{
|
|
|
|
gtk_widget_child_focus (next->box, GTK_DIR_TAB_FORWARD);
|
2020-04-14 12:40:08 +00:00
|
|
|
scroll_to_section (next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
keynav_failed (GtkWidget *box,
|
|
|
|
GtkDirectionType direction,
|
|
|
|
GtkEmojiChooser *chooser)
|
|
|
|
{
|
|
|
|
EmojiSection *next;
|
|
|
|
GtkWidget *focus;
|
|
|
|
GtkWidget *child;
|
|
|
|
GtkWidget *sibling;
|
|
|
|
int i;
|
|
|
|
int column;
|
|
|
|
|
|
|
|
focus = gtk_root_get_focus (gtk_widget_get_root (box));
|
|
|
|
if (focus == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
child = gtk_widget_get_ancestor (focus, GTK_TYPE_EMOJI_CHOOSER_CHILD);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (sibling = gtk_widget_get_first_child (box);
|
|
|
|
sibling != child;
|
|
|
|
sibling = gtk_widget_get_next_sibling (sibling))
|
|
|
|
i++;
|
|
|
|
|
|
|
|
column = i % 7;
|
|
|
|
|
|
|
|
if (direction == GTK_DIR_DOWN)
|
|
|
|
{
|
|
|
|
next = find_next_section (chooser, box, TRUE);
|
|
|
|
if (next == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (sibling = gtk_widget_get_first_child (next->box);
|
|
|
|
sibling;
|
|
|
|
sibling = gtk_widget_get_next_sibling (sibling), i++)
|
|
|
|
{
|
|
|
|
if (i == column)
|
|
|
|
{
|
|
|
|
gtk_widget_grab_focus (sibling);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2020-04-14 01:43:27 +00:00
|
|
|
}
|
2020-04-14 12:40:08 +00:00
|
|
|
else if (direction == GTK_DIR_UP)
|
|
|
|
{
|
|
|
|
next = find_next_section (chooser, box, FALSE);
|
|
|
|
if (next == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
child = NULL;
|
|
|
|
for (sibling = gtk_widget_get_first_child (next->box);
|
|
|
|
sibling;
|
|
|
|
sibling = gtk_widget_get_next_sibling (sibling), i++)
|
|
|
|
{
|
|
|
|
if ((i % 7) == column)
|
|
|
|
child = sibling;
|
|
|
|
}
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
gtk_widget_grab_focus (child);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2020-04-14 01:43:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 22:31:08 +00:00
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkEmojiChooser *chooser = GTK_EMOJI_CHOOSER (widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_emoji_chooser_parent_class)->map (widget);
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (chooser->search_entry);
|
|
|
|
}
|
|
|
|
|
2017-08-11 15:54:15 +00:00
|
|
|
static void
|
|
|
|
gtk_emoji_chooser_class_init (GtkEmojiChooserClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_emoji_chooser_finalize;
|
|
|
|
widget_class->show = gtk_emoji_chooser_show;
|
2020-08-24 22:31:08 +00:00
|
|
|
widget_class->map = gtk_emoji_chooser_map;
|
2017-08-11 15:54:15 +00:00
|
|
|
|
2020-02-03 11:49:36 +00:00
|
|
|
/**
|
|
|
|
* GtkEmojiChooser::emoji-picked:
|
|
|
|
* @chooser: the #GtkEmojiChooser
|
|
|
|
* @text: the Unicode sequence for the picked Emoji, in UTF-8
|
|
|
|
*
|
|
|
|
* The ::emoji-picked signal is emitted when the user selects an
|
|
|
|
* Emoji.
|
|
|
|
*/
|
2017-08-11 15:54:15 +00:00
|
|
|
signals[EMOJI_PICKED] = g_signal_new ("emoji-picked",
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_STRING|G_SIGNAL_TYPE_STATIC_SCOPE);
|
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkemojichooser.ui");
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, search_entry);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, scrolled_window);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, recent.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, recent.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, people.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, people.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, people.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, body.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, body.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, body.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, nature.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, nature.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, nature.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, food.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, food.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, food.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, travel.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, travel.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, travel.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, activities.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, activities.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, activities.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, objects.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, objects.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, objects.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, symbols.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, symbols.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, symbols.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, flags.box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, flags.heading);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkEmojiChooser, flags.button);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, emoji_activated);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, search_changed);
|
2019-05-04 16:55:52 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, stop_search);
|
2018-03-09 01:10:52 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, pressed_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, long_pressed_cb);
|
2020-04-14 12:40:08 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, keynav_failed);
|
2020-04-14 01:43:27 +00:00
|
|
|
|
2020-04-20 02:50:35 +00:00
|
|
|
/**
|
|
|
|
* GtkEmojiChooser|scroll.section:
|
|
|
|
* @direction: 1 to scroll forward, -1 to scroll back
|
|
|
|
*
|
|
|
|
* Scrolls to the next or previous section.
|
|
|
|
*/
|
2020-04-14 01:43:27 +00:00
|
|
|
gtk_widget_class_install_action (widget_class, "scroll.section", "i",
|
|
|
|
gtk_emoji_chooser_scroll_section);
|
|
|
|
|
|
|
|
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_n, GDK_CONTROL_MASK,
|
|
|
|
"scroll.section", "i", 1);
|
|
|
|
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_p, GDK_CONTROL_MASK,
|
|
|
|
"scroll.section", "i", -1);
|
2017-08-11 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 11:49:36 +00:00
|
|
|
/**
|
|
|
|
* gtk_emoji_chooser_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkEmojiChooser.
|
|
|
|
*
|
2020-05-11 16:47:20 +00:00
|
|
|
* Returns: a new #GtkEmojiChooser
|
2020-02-03 11:49:36 +00:00
|
|
|
*/
|
2017-08-11 15:54:15 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_emoji_chooser_new (void)
|
|
|
|
{
|
|
|
|
return GTK_WIDGET (g_object_new (GTK_TYPE_EMOJI_CHOOSER, NULL));
|
|
|
|
}
|