]> Pileus Git - ~andy/gtk/blob - tests/testexpander.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testexpander.c
1 #include <gtk/gtk.h>
2
3 static void
4 expander_cb (GtkExpander *expander, GParamSpec *pspec, GtkWindow *dialog)
5 {
6   gtk_window_set_resizable (dialog, gtk_expander_get_expanded (expander));
7 }
8
9 static void
10 do_not_expand (GtkWidget *child, gpointer data)
11 {
12   gtk_container_child_set (GTK_CONTAINER (gtk_widget_get_parent (child)), child,
13                            "expand", FALSE, "fill", FALSE, NULL);
14 }
15
16 static void
17 response_cb (GtkDialog *dialog, gint response_id)
18 {
19   gtk_main_quit ();
20 }
21
22 int
23 main (int argc, char *argv[])
24 {
25   GtkWidget *dialog;
26   GtkWidget *area;
27   GtkWidget *box;
28   GtkWidget *expander;
29   GtkWidget *sw;
30   GtkWidget *tv;
31   GtkTextBuffer *buffer;
32
33   gtk_init (&argc, &argv);
34
35   dialog = gtk_message_dialog_new_with_markup (NULL,
36                        0,
37                        GTK_MESSAGE_ERROR,
38                        GTK_BUTTONS_CLOSE,
39                        "<big><b>%s</b></big>",
40                        "Something went wrong");
41   gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
42                                             "Here are some more details "
43                                             "but not the full story.");
44
45   area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
46   /* make the hbox expand */
47   box = gtk_widget_get_parent (area);
48   gtk_container_child_set (GTK_CONTAINER (gtk_widget_get_parent (box)), box,
49                            "expand", TRUE, "fill", TRUE, NULL);
50   /* make the labels not expand */
51   gtk_container_foreach (GTK_CONTAINER (area), do_not_expand, NULL);
52
53   expander = gtk_expander_new ("Details:");
54   sw = gtk_scrolled_window_new (NULL, NULL);
55   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
56   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
57                                   GTK_POLICY_NEVER,
58                                   GTK_POLICY_AUTOMATIC);
59
60   tv = gtk_text_view_new ();
61   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
62   gtk_text_view_set_editable (GTK_TEXT_VIEW (tv), FALSE);
63   gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), GTK_WRAP_WORD);
64   gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer),
65                             "Finally, the full story with all details. "
66                             "And all the inside information, including "
67                             "error codes, etc etc. Pages of information, "
68                             "you might have to scroll down to read it all, "
69                             "or even resize the window - it works !\n"
70                             "A second paragraph will contain even more "
71                             "innuendo, just to make you scroll down or "
72                             "resize the window. Do it already !", -1);
73   gtk_container_add (GTK_CONTAINER (sw), tv);
74   gtk_container_add (GTK_CONTAINER (expander), sw);
75   gtk_box_pack_end (GTK_BOX (area), expander, TRUE, TRUE, 0);
76   gtk_widget_show_all (expander);
77   g_signal_connect (expander, "notify::expanded",
78                     G_CALLBACK (expander_cb), dialog);
79
80   g_signal_connect (dialog, "response", G_CALLBACK (response_cb), NULL);
81
82   gtk_window_present (GTK_WINDOW (dialog));
83
84   gtk_main ();
85
86   return 0;
87 }
88