]> Pileus Git - ~andy/gtk/blob - tests/testvolumebutton.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testvolumebutton.c
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, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <gtk/gtk.h>
19
20 static void
21 value_changed (GtkWidget *button,
22                gdouble volume,
23                gpointer user_data)
24 {
25   g_message ("volume changed to %f", volume);
26 }
27
28 static void
29 toggle_orientation (GtkWidget *button,
30                     GtkWidget *scalebutton)
31 {
32   if (gtk_orientable_get_orientation (GTK_ORIENTABLE (scalebutton)) ==
33       GTK_ORIENTATION_HORIZONTAL)
34     {
35       gtk_orientable_set_orientation (GTK_ORIENTABLE (scalebutton),
36                                         GTK_ORIENTATION_VERTICAL);
37     }
38   else
39     {
40       gtk_orientable_set_orientation (GTK_ORIENTABLE (scalebutton),
41                                         GTK_ORIENTATION_HORIZONTAL);
42     }
43 }
44
45 static void
46 response_cb (GtkDialog *dialog,
47              gint       arg1,
48              gpointer   user_data)
49 {
50   gtk_widget_destroy (GTK_WIDGET (dialog));
51 }
52
53 static gboolean
54 show_error (gpointer data)
55 {
56   GtkWindow *window = (GtkWindow *) data;
57   GtkWidget *dialog;
58
59   g_message ("showing error");
60
61   dialog = gtk_message_dialog_new (window,
62                                    GTK_DIALOG_MODAL,
63                                    GTK_MESSAGE_INFO,
64                                    GTK_BUTTONS_CLOSE,
65                                    "This should have unbroken the grab");
66   g_signal_connect (G_OBJECT (dialog),
67                     "response",
68                     G_CALLBACK (response_cb), NULL);
69   gtk_widget_show (dialog);
70
71   return G_SOURCE_REMOVE;
72 }
73
74 int
75 main (int    argc,
76       char **argv)
77 {
78   GtkWidget *window;
79   GtkWidget *button;
80   GtkWidget *button2;
81   GtkWidget *button3;
82   GtkWidget *box;
83
84   gtk_init (&argc, &argv);
85
86   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
87   button = gtk_volume_button_new ();
88   button2 = gtk_volume_button_new ();
89   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
90
91   g_signal_connect (G_OBJECT (button), "value-changed",
92                     G_CALLBACK (value_changed),
93                     NULL);
94
95   gtk_container_add (GTK_CONTAINER (window), box);
96   gtk_container_add (GTK_CONTAINER (box), button);
97   gtk_container_add (GTK_CONTAINER (box), button2);
98
99   button3 = gtk_button_new_with_label ("Toggle orientation");
100   gtk_container_add (GTK_CONTAINER (box), button3);
101
102   g_signal_connect (G_OBJECT (button3), "clicked",
103                     G_CALLBACK (toggle_orientation),
104                     button);
105   g_signal_connect (G_OBJECT (button3), "clicked",
106                     G_CALLBACK (toggle_orientation),
107                     button2);
108
109   gtk_widget_show_all (window);
110   gtk_button_clicked (GTK_BUTTON (button));
111   g_timeout_add (4000, (GSourceFunc) show_error, window);
112
113   gtk_main ();
114
115   return 0;
116 }