[gtk/wip/matthiasc/popup2: 17/51] testpopup: Use a GtkPopup
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/popup2: 17/51] testpopup: Use a GtkPopup
- Date: Mon, 18 Mar 2019 12:46:36 +0000 (UTC)
commit 50044688f2e22ed3c918efcf0d41878b5fa68252
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 | 73 +++++++++++++++++++++++++++++--------------------------
3 files changed, 40 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 34fff24a3f..6b1930cf26 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 714c0eab65..bc1fc703c2 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -296,6 +296,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..7b0ff49ca9 100644
--- a/tests/testpopup.c
+++ b/tests/testpopup.c
@@ -1,51 +1,50 @@
#include <gtk/gtk.h>
static void
-draw_popup (GtkDrawingArea *da,
- cairo_t *cr,
- int width,
- int height,
- gpointer data)
+clicked (GtkButton *button)
{
- cairo_set_source_rgb (cr, 1, 0, 0);
- cairo_paint (cr);
+ g_print ("Yes!\n");
}
-static void
-place_popup (GtkEventControllerMotion *motion,
- gdouble x,
- gdouble y,
- GtkWidget *popup)
+static GtkWidget *
+add_content (GtkWidget *parent)
{
- gint width, height, win_x, win_y;
- GtkWidget *widget;
+ GtkWidget *box, *label, *entry, *button;
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (box, GTK_ALIGN_CENTER);
+
+ label = gtk_label_new_with_mnemonic ("_Test");
+ entry = gtk_entry_new ();
+ button = gtk_button_new_with_mnemonic ("_Yes!");
+ g_signal_connect (button, "clicked", G_CALLBACK (clicked), NULL);
+
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+ gtk_widget_set_can_default (button, TRUE);
+ gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
- widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (motion));
+ gtk_container_add (GTK_CONTAINER (box), label);
+ gtk_container_add (GTK_CONTAINER (box), entry);
+ gtk_container_add (GTK_CONTAINER (box), button);
+ gtk_container_add (GTK_CONTAINER (parent), box);
- 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);
+ gtk_widget_grab_default (button);
+
+ return box;
}
static gboolean
-on_map (GtkWidget *parent)
+create_popup (GtkWidget *parent)
{
- GtkWidget *popup, *da;
- GtkEventController *motion;
-
- popup = gtk_window_new (GTK_WINDOW_POPUP);
- 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);
+ GtkWidget *popup;
- gtk_widget_set_size_request (GTK_WIDGET (popup), 20, 20);
- gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
+ popup = gtk_popup_new ();
+ gtk_popup_set_relative_to (GTK_POPUP (popup), parent);
+ gtk_style_context_add_class (gtk_widget_get_style_context (popup), "background");
+ gtk_style_context_add_class (gtk_widget_get_style_context (popup), "frame");
- motion = gtk_event_controller_motion_new ();
- gtk_widget_add_controller (parent, motion);
- g_signal_connect (motion, "motion", G_CALLBACK (place_popup), popup);
+ add_content (popup);
gtk_widget_show (popup);
@@ -56,13 +55,17 @@ 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 = add_content (window);
- 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_swapped (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]