2004-04-21 17:52:33 +00:00
|
|
|
/* Expander
|
|
|
|
*
|
|
|
|
* GtkExpander allows to provide additional content that is initially hidden.
|
|
|
|
* This is also known as "disclosure triangle".
|
|
|
|
*
|
2015-06-28 13:23:28 +00:00
|
|
|
* This example also shows how to make the window resizable only if the expander
|
|
|
|
* is expanded.
|
2004-04-21 17:52:33 +00:00
|
|
|
*/
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
#include <glib/gi18n.h>
|
2004-04-21 17:52:33 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2022-10-29 14:36:29 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2004-04-21 17:52:33 +00:00
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
2015-06-20 01:59:15 +00:00
|
|
|
static void
|
2020-07-24 13:54:49 +00:00
|
|
|
response_cb (GtkDialog *dialog, int response_id)
|
2015-06-20 01:59:15 +00:00
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2015-06-20 01:59:15 +00:00
|
|
|
window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
expander_cb (GtkExpander *expander, GParamSpec *pspec, GtkWindow *dialog)
|
|
|
|
{
|
|
|
|
gtk_window_set_resizable (dialog, gtk_expander_get_expanded (expander));
|
|
|
|
}
|
|
|
|
|
2004-04-21 17:52:33 +00:00
|
|
|
GtkWidget *
|
|
|
|
do_expander (GtkWidget *do_widget)
|
|
|
|
{
|
2015-06-20 01:59:15 +00:00
|
|
|
GtkWidget *toplevel;
|
|
|
|
GtkWidget *area;
|
2004-04-21 17:52:33 +00:00
|
|
|
GtkWidget *expander;
|
2019-05-01 21:12:36 +00:00
|
|
|
GtkWidget *label;
|
2015-06-20 01:59:15 +00:00
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *tv;
|
|
|
|
GtkTextBuffer *buffer;
|
2020-08-09 20:46:38 +00:00
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
GtkTextTag *tag;
|
|
|
|
GdkPaintable *paintable;
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2004-04-21 17:52:33 +00:00
|
|
|
if (!window)
|
2015-06-20 01:59:15 +00:00
|
|
|
{
|
2019-05-20 04:47:50 +00:00
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (do_widget));
|
2015-06-20 01:59:15 +00:00
|
|
|
window = gtk_message_dialog_new_with_markup (GTK_WINDOW (toplevel),
|
|
|
|
0,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
"<big><b>%s</b></big>",
|
|
|
|
"Something went wrong");
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (window),
|
|
|
|
"Here are some more details "
|
|
|
|
"but not the full story.");
|
|
|
|
|
|
|
|
area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (window));
|
|
|
|
|
2019-05-01 21:12:36 +00:00
|
|
|
label = gtk_widget_get_last_child (area);
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), FALSE);
|
2019-05-01 21:12:36 +00:00
|
|
|
gtk_widget_set_vexpand (label, FALSE);
|
|
|
|
|
2015-06-20 01:59:15 +00:00
|
|
|
expander = gtk_expander_new ("Details:");
|
2019-05-01 21:12:36 +00:00
|
|
|
gtk_widget_set_vexpand (expander, TRUE);
|
2020-06-24 15:25:09 +00:00
|
|
|
sw = gtk_scrolled_window_new ();
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (sw), 100);
|
2020-04-17 03:25:06 +00:00
|
|
|
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2019-05-01 21:12:36 +00:00
|
|
|
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (sw), TRUE);
|
2020-08-09 20:46:38 +00:00
|
|
|
gtk_widget_set_vexpand (sw, TRUE);
|
2015-06-20 01:59:15 +00:00
|
|
|
|
|
|
|
tv = gtk_text_view_new ();
|
2020-08-09 20:46:38 +00:00
|
|
|
|
|
|
|
g_object_set (tv,
|
|
|
|
"left-margin", 10,
|
|
|
|
"right-margin", 10,
|
|
|
|
"top-margin", 10,
|
|
|
|
"bottom-margin", 10,
|
|
|
|
NULL);
|
|
|
|
|
2015-06-20 01:59:15 +00:00
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
|
|
|
|
gtk_text_view_set_editable (GTK_TEXT_VIEW (tv), FALSE);
|
2020-08-09 20:46:38 +00:00
|
|
|
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (tv), FALSE);
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), GTK_WRAP_WORD);
|
2020-08-09 20:46:38 +00:00
|
|
|
gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (tv), 2);
|
|
|
|
gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (tv), 2);
|
|
|
|
|
|
|
|
gtk_text_buffer_set_text (buffer,
|
2015-06-20 01:59:15 +00:00
|
|
|
"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 "
|
2020-08-09 20:46:38 +00:00
|
|
|
"resize the window.\n"
|
|
|
|
"Do it already!\n", -1);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &start);
|
2020-08-13 20:46:38 +00:00
|
|
|
paintable = GDK_PAINTABLE (gdk_texture_new_from_resource ("/cursors/images/gtk_logo_cursor.png"));
|
2020-08-09 20:46:38 +00:00
|
|
|
gtk_text_buffer_insert_paintable (buffer, &start, paintable);
|
|
|
|
g_object_unref (paintable);
|
|
|
|
gtk_text_iter_backward_char (&start);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &end);
|
|
|
|
tag = gtk_text_buffer_create_tag (buffer, NULL,
|
|
|
|
"pixels-above-lines", 200,
|
|
|
|
"justification", GTK_JUSTIFY_RIGHT,
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_apply_tag (buffer, tag, &start, &end);
|
|
|
|
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), tv);
|
2020-05-13 08:50:41 +00:00
|
|
|
gtk_expander_set_child (GTK_EXPANDER (expander), sw);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (area), expander);
|
2015-06-20 01:59:15 +00:00
|
|
|
g_signal_connect (expander, "notify::expanded",
|
|
|
|
G_CALLBACK (expander_cb), window);
|
|
|
|
|
|
|
|
g_signal_connect (window, "response", G_CALLBACK (response_cb), NULL);
|
2004-04-21 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2004-04-21 17:52:33 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2004-04-21 17:52:33 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|