Debian Codegraph @

demos/gtk-demo/spinner.c

raw
1 /* Spinner
2 *
3 * GtkSpinner allows to show that background activity is on-going.
4 *
5 */
6
7 #include <glib/gi18n.h>
8 #include <gtk/gtk.h>
9
10 static GtkWidget *spinner_sensitive = NULL;
11 static GtkWidget *spinner_unsensitive = NULL;
12
13 static void
14 on_play_clicked (GtkButton *button, gpointer user_data)
15 {
16 gtk_spinner_start (GTK_SPINNER (spinner_sensitive));
17 gtk_spinner_start (GTK_SPINNER (spinner_unsensitive));
18 }
19
20 static void
21 on_stop_clicked (GtkButton *button, gpointer user_data)
22 {
23 gtk_spinner_stop (GTK_SPINNER (spinner_sensitive));
24 gtk_spinner_stop (GTK_SPINNER (spinner_unsensitive));
25 }
26
27 GtkWidget *
28 do_spinner (GtkWidget *do_widget)
29 {
30 static GtkWidget *window = NULL;
31 GtkWidget *content_area;
32 GtkWidget *vbox;
33 GtkWidget *hbox;
34 GtkWidget *button;
35 GtkWidget *spinner;
36
37 if (!window)
38 {
39 window = gtk_dialog_new_with_buttons ("Spinner",
40 GTK_WINDOW (do_widget),
41 0,
42 _("_Close"),
43 GTK_RESPONSE_NONE,
44 NULL);
45 gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
46
47 g_signal_connect (window, "response",
48 G_CALLBACK (gtk_widget_destroy), NULL);
49 g_signal_connect (window, "destroy",
50 G_CALLBACK (gtk_widget_destroyed), &window);
51
52 content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
53
54 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
55 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
56 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
57
58 /* Sensitive */
59 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
60 spinner = gtk_spinner_new ();
61 gtk_container_add (GTK_CONTAINER (hbox), spinner);
62 gtk_container_add (GTK_CONTAINER (hbox), gtk_entry_new ());
63 gtk_container_add (GTK_CONTAINER (vbox), hbox);
64 spinner_sensitive = spinner;
65
66 /* Disabled */
67 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
68 spinner = gtk_spinner_new ();
69 gtk_container_add (GTK_CONTAINER (hbox), spinner);
70 gtk_container_add (GTK_CONTAINER (hbox), gtk_entry_new ());
71 gtk_container_add (GTK_CONTAINER (vbox), hbox);
72 spinner_unsensitive = spinner;
73 gtk_widget_set_sensitive (hbox, FALSE);
74
75 button = gtk_button_new_with_label (_("Play"));
76 g_signal_connect (G_OBJECT (button), "clicked",
77 G_CALLBACK (on_play_clicked), spinner);
78 gtk_container_add (GTK_CONTAINER (vbox), button);
79
80 button = gtk_button_new_with_label (_("Stop"));
81 g_signal_connect (G_OBJECT (button), "clicked",
82 G_CALLBACK (on_stop_clicked), spinner);
83 gtk_container_add (GTK_CONTAINER (vbox), button);
84
85 /* Start by default to test for:
86 * https://bugzilla.gnome.org/show_bug.cgi?id=598496 */
87 on_play_clicked (NULL, NULL);
88 }
89
90 if (!gtk_widget_get_visible (window))
91 gtk_widget_show_all (window);
92 else
93 gtk_widget_destroy (window);
94
95 return window;
96 }