[gtk/wip/matthiasc/popup2: 33/37] testpopup: popup on demand



commit 6e5400fb4ff573cf51a6a5006fabf8d4697b5641
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 17 14:08:10 2019 -0400

    testpopup: popup on demand
    
    Add a button to show the popup.

 tests/testpopup.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/tests/testpopup.c b/tests/testpopup.c
index 7b0ff49ca9..421f9aed53 100644
--- a/tests/testpopup.c
+++ b/tests/testpopup.c
@@ -31,41 +31,55 @@ add_content (GtkWidget *parent)
 
   gtk_widget_grab_default (button);
 
-  return box;
+  return entry;
 }
 
-static gboolean
+static GtkWidget *
 create_popup (GtkWidget *parent)
 {
   GtkWidget *popup;
 
   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");
 
   add_content (popup);
 
-  gtk_widget_show (popup);
+  return popup;
+}
 
-  return FALSE;
+static void
+toggle_popup (GtkToggleButton *button, GtkWidget *popup)
+{
+  gtk_widget_set_visible (popup, !gtk_widget_get_visible (popup));
 }
 
 int
 main (int argc, char *argv[])
 {
   GtkWidget *window;
-  GtkWidget *label;
+  GtkWidget *entry;
+  GtkWidget *box;
+  GtkWidget *popup;
+  GtkWidget *button;
 
   gtk_init ();
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size (GTK_WINDOW (window), 300, 200);
 
-  label = add_content (window);
+  entry = add_content (window);
+  box = gtk_widget_get_parent (entry);
+
+  popup = create_popup (entry);
+
+  button = gtk_toggle_button_new_with_mnemonic ("_Popup");
+  g_signal_connect (button, "toggled", G_CALLBACK (toggle_popup), popup);
+  gtk_container_add (GTK_CONTAINER (box), button);
 
   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]