2001-04-18 18:09:18 +00:00
|
|
|
/* Images
|
|
|
|
*
|
2018-06-09 21:12:00 +00:00
|
|
|
* GtkImage and GtkPicture are used to display an image; the image can be
|
|
|
|
* in a number of formats.
|
2001-04-18 18:09:18 +00:00
|
|
|
*
|
2018-06-09 21:12:00 +00:00
|
|
|
* GtkImage is the widget used to display icons or images that should be
|
|
|
|
* sized and styled like an icon, while GtkPicture is used for images
|
|
|
|
* that should be displayed as-is.
|
2001-04-18 18:09:18 +00:00
|
|
|
*
|
2018-06-09 21:12:00 +00:00
|
|
|
* This demo code shows some of the more obscure cases, in the simple
|
|
|
|
* case a call to gtk_picture_new_for_file() or
|
|
|
|
* gtk_image_new_from_icon_name() is all you need.
|
2001-04-18 18:09:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2004-12-05 12:47:42 +00:00
|
|
|
#include <glib/gstdio.h>
|
2001-04-18 18:09:18 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
static GdkPixbufLoader *pixbuf_loader = NULL;
|
|
|
|
static guint load_timeout = 0;
|
2013-01-29 20:42:16 +00:00
|
|
|
static GInputStream * image_stream = NULL;
|
2001-04-18 18:09:18 +00:00
|
|
|
|
|
|
|
static void
|
2001-05-18 16:28:30 +00:00
|
|
|
progressive_prepared_callback (GdkPixbufLoader *loader,
|
2011-09-02 03:55:47 +00:00
|
|
|
gpointer data)
|
2001-04-18 18:09:18 +00:00
|
|
|
{
|
2001-05-18 16:28:30 +00:00
|
|
|
GdkPixbuf *pixbuf;
|
2018-06-09 21:12:00 +00:00
|
|
|
GtkWidget *picture;
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2018-06-09 21:12:00 +00:00
|
|
|
picture = GTK_WIDGET (data);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
|
|
|
|
|
|
|
|
/* Avoid displaying random memory contents, since the pixbuf
|
|
|
|
* isn't filled in yet.
|
|
|
|
*/
|
|
|
|
gdk_pixbuf_fill (pixbuf, 0xaaaaaaff);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2018-06-09 21:12:00 +00:00
|
|
|
gtk_picture_set_pixbuf (GTK_PICTURE (picture), pixbuf);
|
2001-04-18 18:09:18 +00:00
|
|
|
}
|
|
|
|
|
2002-01-29 23:59:21 +00:00
|
|
|
static void
|
|
|
|
progressive_updated_callback (GdkPixbufLoader *loader,
|
2011-09-02 03:55:47 +00:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gpointer data)
|
2001-04-18 18:09:18 +00:00
|
|
|
{
|
2018-06-09 21:12:00 +00:00
|
|
|
GtkWidget *picture;
|
2014-04-13 03:39:26 +00:00
|
|
|
GdkPixbuf *pixbuf;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2018-06-09 21:12:00 +00:00
|
|
|
picture = GTK_WIDGET (data);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2017-10-23 12:47:50 +00:00
|
|
|
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
|
2018-06-09 21:12:00 +00:00
|
|
|
gtk_picture_set_pixbuf (GTK_PICTURE (picture), pixbuf);
|
2001-04-18 18:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
progressive_timeout (gpointer data)
|
|
|
|
{
|
2018-06-09 21:12:00 +00:00
|
|
|
GtkWidget *picture;
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2018-06-09 21:12:00 +00:00
|
|
|
picture = GTK_WIDGET (data);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
/* This shows off fully-paranoid error handling, so looks scary.
|
|
|
|
* You could factor out the error handling code into a nice separate
|
|
|
|
* function to make things nicer.
|
|
|
|
*/
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
if (image_stream)
|
|
|
|
{
|
2013-01-29 20:42:16 +00:00
|
|
|
gssize bytes_read;
|
2001-04-18 18:09:18 +00:00
|
|
|
guchar buf[256];
|
|
|
|
GError *error = NULL;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2013-01-29 20:42:16 +00:00
|
|
|
bytes_read = g_input_stream_read (image_stream, buf, 256, NULL, &error);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2013-01-29 20:42:16 +00:00
|
|
|
if (bytes_read < 0)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
"Failure reading image file 'alphatest.png': %s",
|
2013-01-29 20:42:16 +00:00
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
2020-05-09 14:26:22 +00:00
|
|
|
G_CALLBACK (gtk_window_destroy), NULL);
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2013-01-29 20:42:16 +00:00
|
|
|
g_object_unref (image_stream);
|
2011-09-02 03:55:47 +00:00
|
|
|
image_stream = NULL;
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
gtk_widget_show (dialog);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
load_timeout = 0;
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
return FALSE; /* uninstall the timeout */
|
|
|
|
}
|
2001-04-18 18:09:18 +00:00
|
|
|
|
|
|
|
if (!gdk_pixbuf_loader_write (pixbuf_loader,
|
2011-09-02 03:55:47 +00:00
|
|
|
buf, bytes_read,
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
"Failed to load image: %s",
|
|
|
|
error->message);
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
g_error_free (error);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
2020-05-09 14:26:22 +00:00
|
|
|
G_CALLBACK (gtk_window_destroy), NULL);
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2013-01-29 20:42:16 +00:00
|
|
|
g_object_unref (image_stream);
|
2011-09-02 03:55:47 +00:00
|
|
|
image_stream = NULL;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
gtk_widget_show (dialog);
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
load_timeout = 0;
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
return FALSE; /* uninstall the timeout */
|
|
|
|
}
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2013-01-29 20:42:16 +00:00
|
|
|
if (bytes_read == 0)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
2013-01-29 20:42:16 +00:00
|
|
|
/* Errors can happen on close, e.g. if the image
|
|
|
|
* file was truncated we'll know on close that
|
|
|
|
* it was incomplete.
|
|
|
|
*/
|
|
|
|
error = NULL;
|
|
|
|
if (!g_input_stream_close (image_stream, NULL, &error))
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
"Failed to load image: %s",
|
|
|
|
error->message);
|
|
|
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
2020-05-09 14:26:22 +00:00
|
|
|
G_CALLBACK (gtk_window_destroy), NULL);
|
2013-01-29 20:42:16 +00:00
|
|
|
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
|
|
|
g_object_unref (image_stream);
|
|
|
|
image_stream = NULL;
|
|
|
|
g_object_unref (pixbuf_loader);
|
|
|
|
pixbuf_loader = NULL;
|
|
|
|
|
|
|
|
load_timeout = 0;
|
|
|
|
|
|
|
|
return FALSE; /* uninstall the timeout */
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (image_stream);
|
2011-09-02 03:55:47 +00:00
|
|
|
image_stream = NULL;
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
/* Errors can happen on close, e.g. if the image
|
|
|
|
* file was truncated we'll know on close that
|
|
|
|
* it was incomplete.
|
|
|
|
*/
|
|
|
|
error = NULL;
|
|
|
|
if (!gdk_pixbuf_loader_close (pixbuf_loader,
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
"Failed to load image: %s",
|
|
|
|
error->message);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
g_error_free (error);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
2020-05-09 14:26:22 +00:00
|
|
|
G_CALLBACK (gtk_window_destroy), NULL);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
gtk_widget_show (dialog);
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
g_object_unref (pixbuf_loader);
|
|
|
|
pixbuf_loader = NULL;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
load_timeout = 0;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
return FALSE; /* uninstall the timeout */
|
|
|
|
}
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
g_object_unref (pixbuf_loader);
|
|
|
|
pixbuf_loader = NULL;
|
|
|
|
}
|
2001-04-18 18:09:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-11 19:12:58 +00:00
|
|
|
GError *error = NULL;
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2013-01-29 21:24:42 +00:00
|
|
|
image_stream = g_resources_open_stream ("/images/alphatest.png", 0, &error);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
|
|
|
if (image_stream == NULL)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
2013-01-29 20:42:16 +00:00
|
|
|
"%s", error->message);
|
|
|
|
g_error_free (error);
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
2020-05-09 14:26:22 +00:00
|
|
|
G_CALLBACK (gtk_window_destroy), NULL);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
gtk_widget_show (dialog);
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
load_timeout = 0;
|
2001-05-18 16:28:30 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
return FALSE; /* uninstall the timeout */
|
|
|
|
}
|
2001-04-18 18:09:18 +00:00
|
|
|
|
|
|
|
if (pixbuf_loader)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
gdk_pixbuf_loader_close (pixbuf_loader, NULL);
|
|
|
|
g_object_unref (pixbuf_loader);
|
|
|
|
}
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
pixbuf_loader = gdk_pixbuf_loader_new ();
|
2008-08-11 19:12:58 +00:00
|
|
|
|
|
|
|
g_signal_connect (pixbuf_loader, "area-prepared",
|
2018-06-09 21:12:00 +00:00
|
|
|
G_CALLBACK (progressive_prepared_callback), picture);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
|
|
|
g_signal_connect (pixbuf_loader, "area-updated",
|
2018-06-09 21:12:00 +00:00
|
|
|
G_CALLBACK (progressive_updated_callback), picture);
|
2001-04-18 18:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* leave timeout installed */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-06-09 21:12:00 +00:00
|
|
|
start_progressive_loading (GtkWidget *picture)
|
2001-04-18 18:09:18 +00:00
|
|
|
{
|
|
|
|
/* This is obviously totally contrived (we slow down loading
|
|
|
|
* on purpose to show how incremental loading works).
|
|
|
|
* The real purpose of incremental loading is the case where
|
|
|
|
* you are reading data from a slow source such as the network.
|
|
|
|
* The timeout simply simulates a slow data source by inserting
|
|
|
|
* pauses in the reading process.
|
|
|
|
*/
|
2018-06-09 21:12:00 +00:00
|
|
|
load_timeout = g_timeout_add (150, progressive_timeout, picture);
|
2019-02-05 09:19:57 +00:00
|
|
|
g_source_set_name_by_id (load_timeout, "[gtk] progressive_timeout");
|
2001-04-18 18:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-09-27 06:10:50 +00:00
|
|
|
cleanup_callback (GObject *object,
|
2011-09-02 03:55:47 +00:00
|
|
|
gpointer data)
|
2001-04-18 18:09:18 +00:00
|
|
|
{
|
|
|
|
if (load_timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (load_timeout);
|
|
|
|
load_timeout = 0;
|
|
|
|
}
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
if (pixbuf_loader)
|
|
|
|
{
|
|
|
|
gdk_pixbuf_loader_close (pixbuf_loader, NULL);
|
2002-09-29 21:24:24 +00:00
|
|
|
g_object_unref (pixbuf_loader);
|
2001-04-18 18:09:18 +00:00
|
|
|
pixbuf_loader = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (image_stream)
|
2013-01-29 20:42:16 +00:00
|
|
|
{
|
|
|
|
g_object_unref (image_stream);
|
|
|
|
image_stream = NULL;
|
|
|
|
}
|
2001-04-18 18:09:18 +00:00
|
|
|
}
|
|
|
|
|
2002-01-29 23:59:21 +00:00
|
|
|
static void
|
|
|
|
toggle_sensitivity_callback (GtkWidget *togglebutton,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
GtkWidget *child;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (user_data));
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child))
|
2002-01-29 23:59:21 +00:00
|
|
|
{
|
|
|
|
/* don't disable our toggle */
|
2020-05-09 12:26:52 +00:00
|
|
|
if (child != togglebutton)
|
|
|
|
gtk_widget_set_sensitive (child, !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (togglebutton)));
|
2002-01-29 23:59:21 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2002-01-29 23:59:21 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
GtkWidget *
|
2003-11-08 22:08:05 +00:00
|
|
|
do_images (GtkWidget *do_widget)
|
2001-04-18 18:09:18 +00:00
|
|
|
{
|
2018-02-17 23:33:17 +00:00
|
|
|
GtkWidget *video;
|
2001-04-18 18:09:18 +00:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
2018-02-17 23:33:17 +00:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *base_vbox;
|
2001-04-18 18:09:18 +00:00
|
|
|
GtkWidget *image;
|
2018-06-09 21:12:00 +00:00
|
|
|
GtkWidget *picture;
|
2001-04-18 18:09:18 +00:00
|
|
|
GtkWidget *label;
|
2002-01-29 23:59:21 +00:00
|
|
|
GtkWidget *button;
|
2018-03-31 19:59:41 +00:00
|
|
|
GdkPaintable *paintable;
|
2018-02-17 23:33:17 +00:00
|
|
|
GIcon *gicon;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
if (!window)
|
|
|
|
{
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2001-04-18 18:09:18 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Images");
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
2011-09-02 03:55:47 +00:00
|
|
|
G_CALLBACK (cleanup_callback), NULL);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2018-02-17 23:33:17 +00:00
|
|
|
base_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (base_vbox, 16);
|
|
|
|
gtk_widget_set_margin_end (base_vbox, 16);
|
|
|
|
gtk_widget_set_margin_top (base_vbox, 16);
|
|
|
|
gtk_widget_set_margin_bottom (base_vbox, 16);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), base_vbox);
|
2018-02-17 23:33:17 +00:00
|
|
|
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 16);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (base_vbox), hbox);
|
2018-02-17 23:33:17 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label),
|
2011-09-02 03:55:47 +00:00
|
|
|
"<u>Image loaded from a file</u>");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
frame = gtk_frame_new (NULL);
|
2011-09-01 17:27:14 +00:00
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name ("gtk3-demo");
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), image);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2001-05-07 15:58:47 +00:00
|
|
|
|
|
|
|
/* Animation */
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label),
|
2011-09-02 03:55:47 +00:00
|
|
|
"<u>Animation loaded from a file</u>");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-05-07 15:58:47 +00:00
|
|
|
frame = gtk_frame_new (NULL);
|
2011-09-01 17:27:14 +00:00
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2001-05-07 15:58:47 +00:00
|
|
|
|
2018-06-09 21:12:00 +00:00
|
|
|
picture = gtk_picture_new_for_resource ("/images/floppybuddy.gif");
|
2001-05-07 15:58:47 +00:00
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), picture);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2010-04-26 10:55:34 +00:00
|
|
|
/* Symbolic icon */
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label),
|
2011-09-02 03:55:47 +00:00
|
|
|
"<u>Symbolic themed icon</u>");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2010-04-26 10:55:34 +00:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
2011-09-01 17:27:14 +00:00
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2010-04-26 10:55:34 +00:00
|
|
|
|
2011-02-05 02:22:17 +00:00
|
|
|
gicon = g_themed_icon_new_with_default_fallbacks ("battery-caution-charging-symbolic");
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_gicon (gicon);
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2010-04-26 10:55:34 +00:00
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), image);
|
2001-05-07 15:58:47 +00:00
|
|
|
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2013-01-29 21:24:42 +00:00
|
|
|
/* Progressive */
|
2018-02-17 23:33:17 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label),
|
2011-09-02 03:55:47 +00:00
|
|
|
"<u>Progressive image loading</u>");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
frame = gtk_frame_new (NULL);
|
2011-09-01 17:27:14 +00:00
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
|
|
|
/* Create an empty image for now; the progressive loader
|
|
|
|
* will create the pixbuf and fill it in.
|
|
|
|
*/
|
2018-06-09 21:12:00 +00:00
|
|
|
picture = gtk_picture_new ();
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), picture);
|
2001-04-18 18:09:18 +00:00
|
|
|
|
2018-06-09 21:12:00 +00:00
|
|
|
start_progressive_loading (picture);
|
2002-01-29 23:59:21 +00:00
|
|
|
|
2018-02-17 23:33:17 +00:00
|
|
|
/* Video */
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
2018-02-17 23:33:17 +00:00
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label),
|
|
|
|
"<u>Displaying video</u>");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2018-02-17 23:33:17 +00:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2018-02-17 23:33:17 +00:00
|
|
|
|
|
|
|
video = gtk_video_new_for_resource ("/images/gtk-logo.webm");
|
|
|
|
gtk_media_stream_set_loop (gtk_video_get_media_stream (GTK_VIDEO (video)), TRUE);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), video);
|
2018-02-17 23:33:17 +00:00
|
|
|
|
2018-03-31 19:59:41 +00:00
|
|
|
/* Widget paintables */
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
2018-03-31 19:59:41 +00:00
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label),
|
|
|
|
"<u>GtkWidgetPaintable</u>");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2018-03-31 19:59:41 +00:00
|
|
|
|
|
|
|
paintable = gtk_widget_paintable_new (do_widget);
|
2018-06-09 21:12:00 +00:00
|
|
|
picture = gtk_picture_new_for_paintable (paintable);
|
|
|
|
gtk_widget_set_size_request (picture, 100, 100);
|
|
|
|
gtk_widget_set_valign (picture, GTK_ALIGN_START);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), picture);
|
2018-03-31 19:59:41 +00:00
|
|
|
|
2002-01-29 23:59:21 +00:00
|
|
|
/* Sensitivity control */
|
|
|
|
button = gtk_toggle_button_new_with_mnemonic ("_Insensitive");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (base_vbox), button);
|
2002-01-29 23:59:21 +00:00
|
|
|
|
2002-09-29 21:24:24 +00:00
|
|
|
g_signal_connect (button, "toggled",
|
2002-01-29 23:59:21 +00:00
|
|
|
G_CALLBACK (toggle_sensitivity_callback),
|
2018-02-17 23:33:17 +00:00
|
|
|
base_vbox);
|
2001-04-18 18:09:18 +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);
|
2001-04-18 18:09:18 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2001-04-18 18:09:18 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|