[gtk/wip/matthiasc/popup2: 9/29] Add a way to enumerate popups
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/popup2: 9/29] Add a way to enumerate popups
- Date: Sun, 17 Mar 2019 13:29:31 +0000 (UTC)
commit 4430d8d35b5b8da3daec8d3883ba0b0b9b8da264
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Feb 25 00:02:00 2019 -0500
Add a way to enumerate popups
This is temporary. The ultimate goal is for popups to
appear in the tree as children of the widget they are
attached to.
gtk/gtkpopup.c | 39 +++++++++++++++++++++++++++++++++++++++
gtk/gtkpopup.h | 3 +++
2 files changed, 42 insertions(+)
---
diff --git a/gtk/gtkpopup.c b/gtk/gtkpopup.c
index bdff7a1707..3c9ab3cdda 100644
--- a/gtk/gtkpopup.c
+++ b/gtk/gtkpopup.c
@@ -30,6 +30,8 @@
#include "gtktypebuiltins.h"
#include "gdk/gdkeventsprivate.h"
+static GListStore *popup_list = NULL;
+
typedef struct {
GdkDisplay *display;
GskRenderer *renderer;
@@ -88,7 +90,10 @@ gtk_popup_move_resize (GtkPopup *popup)
{
GtkPopupPrivate *priv = gtk_popup_get_instance_private (popup);
GdkRectangle rect;
+ GtkRequisition req;
+ gtk_widget_get_preferred_size (GTK_WIDGET (popup), NULL, &req);
+ gdk_surface_resize (priv->surface, req.width, req.height);
rect.x = 0;
rect.y = 0;
rect.width = gtk_widget_get_width (priv->relative_to);
@@ -279,6 +284,20 @@ gtk_popup_unmap (GtkWidget *widget)
static void
gtk_popup_dispose (GObject *object)
{
+ guint i;
+
+ for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (popup_list)); i++)
+ {
+ gpointer item = g_list_model_get_item (G_LIST_MODEL (popup_list), i);
+ if (item == object)
+ {
+ g_list_store_remove (popup_list, i);
+ break;
+ }
+ else
+ g_object_unref (item);
+ }
+
G_OBJECT_CLASS (gtk_popup_parent_class)->dispose (object);
}
@@ -288,6 +307,13 @@ gtk_popup_finalize (GObject *object)
G_OBJECT_CLASS (gtk_popup_parent_class)->finalize (object);
}
+static void
+gtk_popup_constructed (GObject *object)
+{
+ g_list_store_append (popup_list, object);
+ g_object_unref (object);
+}
+
static void
gtk_popup_measure (GtkWidget *widget,
GtkOrientation orientation,
@@ -388,6 +414,10 @@ gtk_popup_class_init (GtkPopupClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkBindingSet *binding_set;
+ if (popup_list == NULL)
+ popup_list = g_list_store_new (GTK_TYPE_WIDGET);
+
+ object_class->constructed = gtk_popup_constructed;
object_class->dispose = gtk_popup_dispose;
object_class->finalize = gtk_popup_finalize;
object_class->set_property = gtk_popup_set_property;
@@ -523,3 +553,12 @@ gtk_popup_set_is_active (GtkPopup *popup,
gtk_widget_has_focus (priv->focus_widget) != active)
do_focus_change (priv->focus_widget, active);
}
+
+GListModel *
+gtk_popup_get_popups (void)
+{
+ if (popup_list == NULL)
+ popup_list = g_list_store_new (GTK_TYPE_WIDGET);
+
+ return G_LIST_MODEL (popup_list);
+}
diff --git a/gtk/gtkpopup.h b/gtk/gtkpopup.h
index a316741933..ac745cfd64 100644
--- a/gtk/gtkpopup.h
+++ b/gtk/gtkpopup.h
@@ -59,6 +59,9 @@ GDK_AVAILABLE_IN_ALL
void gtk_popup_set_relative_to (GtkPopup *popup,
GtkWidget *relative_to);
+GDK_AVAILABLE_IN_ALL
+GListModel * gtk_popup_get_popups (void);
+
G_END_DECLS
#endif /* __GTK_POPUP_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]