[gtk/wip/matthiasc/popup: 2/4] testpopup: Use a GtkPopup
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/popup: 2/4] testpopup: Use a GtkPopup
- Date: Sun, 24 Feb 2019 13:21:14 +0000 (UTC)
commit d4b9a04ee1e88b748c1cdde96cdd47bb06f9a146
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Feb 24 08:17:58 2019 -0500
testpopup: Use a GtkPopup
gtk/gtk.h | 1 +
gtk/meson.build | 1 +
tests/testpopup.c | 41 +++++++++++++----------------------------
3 files changed, 15 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 62a3bb3d7f..533c249f93 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -165,6 +165,7 @@
#include <gtk/gtkpicture.h>
#include <gtk/gtkpopover.h>
#include <gtk/gtkpopovermenu.h>
+#include <gtk/gtkpopup.h>
#include <gtk/gtkprintcontext.h>
#include <gtk/gtkprintoperation.h>
#include <gtk/gtkprintoperationpreview.h>
diff --git a/gtk/meson.build b/gtk/meson.build
index 33b723041b..a11cf4515c 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -297,6 +297,7 @@ gtk_public_sources = files([
'gtkpicture.c',
'gtkpopover.c',
'gtkpopovermenu.c',
+ 'gtkpopup.c',
'gtkprintcontext.c',
'gtkprintoperation.c',
'gtkprintoperationpreview.c',
diff --git a/tests/testpopup.c b/tests/testpopup.c
index b496fe5eae..ba49c81036 100644
--- a/tests/testpopup.c
+++ b/tests/testpopup.c
@@ -11,41 +11,19 @@ draw_popup (GtkDrawingArea *da,
cairo_paint (cr);
}
-static void
-place_popup (GtkEventControllerMotion *motion,
- gdouble x,
- gdouble y,
- GtkWidget *popup)
-{
- gint width, height, win_x, win_y;
- GtkWidget *widget;
-
- widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (motion));
-
- gtk_window_get_size (GTK_WINDOW (popup), &width, &height);
- gtk_window_get_position (GTK_WINDOW (widget), &win_x, &win_y);
- gtk_window_move (GTK_WINDOW (popup),
- (int) win_x + x - width / 2,
- (int) win_y + y - height / 2);
-}
-
static gboolean
-on_map (GtkWidget *parent)
+create_popup (GtkWidget *parent,
+ GtkWidget *label)
{
GtkWidget *popup, *da;
- GtkEventController *motion;
- popup = gtk_window_new (GTK_WINDOW_POPUP);
+ popup = gtk_popup_new ();
+ gtk_popup_set_relative_to (GTK_POPUP (popup), label);
da = gtk_drawing_area_new ();
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), draw_popup, NULL, NULL);
gtk_container_add (GTK_CONTAINER (popup), da);
gtk_widget_set_size_request (GTK_WIDGET (popup), 20, 20);
- gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
-
- motion = gtk_event_controller_motion_new ();
- gtk_widget_add_controller (parent, motion);
- g_signal_connect (motion, "motion", G_CALLBACK (place_popup), popup);
gtk_widget_show (popup);
@@ -56,13 +34,20 @@ int
main (int argc, char *argv[])
{
GtkWidget *window;
+ GtkWidget *label;
gtk_init ();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), 300, 200);
+
+ label = gtk_label_new ("x");
+ gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_container_add (GTK_CONTAINER (window), label);
- g_signal_connect (window, "destroy", gtk_main_quit, NULL);
- g_signal_connect (window, "map", G_CALLBACK (on_map), NULL);
+ g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (window, "map", G_CALLBACK (create_popup), label);
gtk_widget_show (window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]