1 /* testvolumebutton.c
2  * Copyright (C) 2007  Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 #include <gtk/gtk.h>
21 
22 static void
value_changed(GtkWidget * button,gdouble volume,gpointer user_data)23 value_changed (GtkWidget *button,
24                gdouble volume,
25                gpointer user_data)
26 {
27   g_message ("volume changed to %f", volume);
28 }
29 
30 static void
toggle_orientation(GtkWidget * button,GtkWidget * scalebutton)31 toggle_orientation (GtkWidget *button,
32                     GtkWidget *scalebutton)
33 {
34   if (gtk_orientable_get_orientation (GTK_ORIENTABLE (scalebutton)) ==
35       GTK_ORIENTATION_HORIZONTAL)
36     {
37       gtk_orientable_set_orientation (GTK_ORIENTABLE (scalebutton),
38                                         GTK_ORIENTATION_VERTICAL);
39     }
40   else
41     {
42       gtk_orientable_set_orientation (GTK_ORIENTABLE (scalebutton),
43                                         GTK_ORIENTATION_HORIZONTAL);
44     }
45 }
46 
47 static void
response_cb(GtkDialog * dialog,gint arg1,gpointer user_data)48 response_cb (GtkDialog *dialog,
49              gint       arg1,
50              gpointer   user_data)
51 {
52   gtk_widget_destroy (GTK_WIDGET (dialog));
53 }
54 
55 static gboolean
show_error(gpointer data)56 show_error (gpointer data)
57 {
58   GtkWindow *window = (GtkWindow *) data;
59   GtkWidget *dialog;
60 
61   g_message ("showing error");
62 
63   dialog = gtk_message_dialog_new (window,
64                                    GTK_DIALOG_MODAL,
65                                    GTK_MESSAGE_INFO,
66                                    GTK_BUTTONS_CLOSE,
67                                    "This should have unbroken the grab");
68   g_signal_connect (G_OBJECT (dialog),
69                     "response",
70                     G_CALLBACK (response_cb), NULL);
71   gtk_widget_show (dialog);
72 
73   return FALSE;
74 }
75 
76 int
main(int argc,char ** argv)77 main (int    argc,
78       char **argv)
79 {
80   GtkWidget *window;
81   GtkWidget *button;
82   GtkWidget *button2;
83   GtkWidget *button3;
84   GtkWidget *box;
85 
86   gtk_init (&argc, &argv);
87 
88   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
89   button = gtk_volume_button_new ();
90   button2 = gtk_volume_button_new ();
91   box = gtk_hbox_new (FALSE, 0);
92 
93   g_signal_connect (G_OBJECT (button), "value-changed",
94                     G_CALLBACK (value_changed),
95                     NULL);
96 
97   gtk_container_add (GTK_CONTAINER (window), box);
98   gtk_container_add (GTK_CONTAINER (box), button);
99   gtk_container_add (GTK_CONTAINER (box), button2);
100 
101   button3 = gtk_button_new_with_label ("Toggle orientation");
102   gtk_container_add (GTK_CONTAINER (box), button3);
103 
104   g_signal_connect (G_OBJECT (button3), "clicked",
105                     G_CALLBACK (toggle_orientation),
106                     button);
107   g_signal_connect (G_OBJECT (button3), "clicked",
108                     G_CALLBACK (toggle_orientation),
109                     button2);
110 
111   gtk_widget_show_all (window);
112   gtk_button_clicked (GTK_BUTTON (button));
113   g_timeout_add (4000, (GSourceFunc) show_error, window);
114 
115   gtk_main ();
116 
117   return 0;
118 }
119