[gtk/wip/matthiasc/popup: 56/63] testpopup: Add a default widget
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/popup: 56/63] testpopup: Add a default widget
- Date: Mon, 4 Mar 2019 04:34:36 +0000 (UTC)
commit 6867a7852bf14130942a6310d8ef083a6692d16c
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 3 20:07:11 2019 -0500
testpopup: Add a default widget
tests/testpopup.c | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/tests/testpopup.c b/tests/testpopup.c
index ed669eddf3..ba27eb6070 100644
--- a/tests/testpopup.c
+++ b/tests/testpopup.c
@@ -1,20 +1,38 @@
#include <gtk/gtk.h>
+static void
+clicked (GtkButton *button)
+{
+ g_print ("Yes!\n");
+}
+
static gboolean
-create_popup (GtkWidget *parent,
- GtkWidget *label)
+create_popup (GtkWidget *parent)
{
- GtkWidget *popup, *box;
+ GtkWidget *popup, *box, *label, *entry, *button;
popup = gtk_popup_new ();
- gtk_popup_set_relative_to (GTK_POPUP (popup), label);
+ 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");
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
- gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("Test"));
- gtk_container_add (GTK_CONTAINER (box), gtk_entry_new ());
+
+ label = gtk_label_new_with_mnemonic ("_Test");
+ entry = gtk_entry_new ();
+ button = gtk_button_new_with_label ("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);
+
+ 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 (popup), box);
+ gtk_widget_grab_default (button);
+
gtk_widget_show (popup);
return FALSE;
@@ -37,7 +55,7 @@ main (int argc, char *argv[])
gtk_container_add (GTK_CONTAINER (window), label);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
- g_signal_connect (window, "map", G_CALLBACK (create_popup), label);
+ 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]