[gtk+] Add an expander-in-dialog example
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Add an expander-in-dialog example
- Date: Thu, 24 Jun 2010 04:37:40 +0000 (UTC)
commit 686294cb3baa6649f52907983fdaf1efae23c305
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jun 24 00:35:24 2010 -0400
Add an expander-in-dialog example
To show how I expect this kind of construction to work, makes it
easier to find the code the next time I need it somewhere.
tests/Makefile.am | 5 +++
tests/testexpander.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 960909a..71659c1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -95,6 +95,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testactions \
testgrouping \
testtooltips \
+ testexpander \
testvolumebutton
if OS_UNIX
@@ -178,6 +179,7 @@ testgrouping_DEPENDENCIES = $(TEST_DEPS)
testtooltips_DEPENDENCIES = $(TEST_DEPS)
testvolumebutton_DEPENDENCIES = $(TEST_DEPS)
testwindows_DEPENDENCIES = $(TEST_DEPS)
+testexpander_DEPENDENCIES = $(TEST_DEPS)
flicker_LDADD = $(LDADDS)
simple_LDADD = $(LDADDS)
@@ -251,6 +253,7 @@ testgrouping_LDADD = $(LDADDS)
testtooltips_LDADD = $(LDADDS)
testvolumebutton_LDADD = $(LDADDS)
testwindows_LDADD = $(LDADDS)
+testexpander_LDADD = $(LDADDS)
testentrycompletion_SOURCES = \
prop-editor.c \
@@ -359,6 +362,8 @@ testoffscreenwindow_SOURCES = \
testwindows_SOURCES = \
testwindows.c
+testexpander_SOURCES = testexpander.c
+
EXTRA_DIST += \
prop-editor.h \
testgtk.1 \
diff --git a/tests/testexpander.c b/tests/testexpander.c
new file mode 100644
index 0000000..c0f6cfe
--- /dev/null
+++ b/tests/testexpander.c
@@ -0,0 +1,88 @@
+#include <gtk/gtk.h>
+
+static void
+expander_cb (GtkExpander *expander, GParamSpec *pspec, GtkWindow *dialog)
+{
+ gtk_window_set_resizable (dialog, gtk_expander_get_expanded (expander));
+}
+
+static void
+do_not_expand (GtkWidget *child, gpointer data)
+{
+ gtk_container_child_set (GTK_CONTAINER (gtk_widget_get_parent (child)), child,
+ "expand", FALSE, "fill", FALSE, NULL);
+}
+
+static void
+response_cb (GtkDialog *dialog, gint response_id)
+{
+ gtk_main_quit ();
+}
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *dialog;
+ GtkWidget *area;
+ GtkWidget *box;
+ GtkWidget *expander;
+ GtkWidget *sw;
+ GtkWidget *tv;
+ GtkTextBuffer *buffer;
+
+ gtk_init (&argc, &argv);
+
+ dialog = gtk_message_dialog_new_with_markup (NULL,
+ 0,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "<big><b>%s</b></big>",
+ "Something went wrong");
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "Here are some more details "
+ "but not the full story.");
+
+ area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
+ /* make the hbox expand */
+ box = gtk_widget_get_parent (area);
+ gtk_container_child_set (GTK_CONTAINER (gtk_widget_get_parent (box)), box,
+ "expand", TRUE, "fill", TRUE, NULL);
+ /* make the labels not expand */
+ gtk_container_foreach (GTK_CONTAINER (area), do_not_expand, NULL);
+
+ expander = gtk_expander_new ("Details:");
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_NEVER,
+ GTK_POLICY_AUTOMATIC);
+
+ tv = gtk_text_view_new ();
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (tv), FALSE);
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), GTK_WRAP_WORD);
+ gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer),
+ "Finally, the full story with all details. "
+ "And all the inside information, including "
+ "error codes, etc etc. Pages of information, "
+ "you might have to scroll down to read it all, "
+ "or even resize the window - it works !\n"
+ "A second paragraph will contain even more "
+ "innuendo, just to make you scroll down or "
+ "resize the window. Do it already !", -1);
+ gtk_container_add (GTK_CONTAINER (sw), tv);
+ gtk_container_add (GTK_CONTAINER (expander), sw);
+ gtk_box_pack_end (GTK_BOX (area), expander, TRUE, TRUE, 0);
+ gtk_widget_show_all (expander);
+ g_signal_connect (expander, "notify::expanded",
+ G_CALLBACK (expander_cb), dialog);
+
+ g_signal_connect (dialog, "response", G_CALLBACK (response_cb), NULL);
+
+ gtk_window_present (GTK_WINDOW (dialog));
+
+ gtk_main ();
+
+ return 0;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]