|
Packit |
1470ea |
#include <gtk/gtk.h>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
activate (GtkApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
/* Declare variables */
|
|
Packit |
1470ea |
GtkWidget *window;
|
|
Packit |
1470ea |
GtkWidget *scrolled_window;
|
|
Packit |
1470ea |
GtkWidget *image;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a window with a title, and a default size */
|
|
Packit |
1470ea |
window = gtk_application_window_new (app);
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (window), "ScrolledWindow Example");
|
|
Packit |
1470ea |
gtk_window_set_default_size (GTK_WINDOW (window), 220, 200);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create the scrolled window. Usually NULL is passed for both parameters so
|
|
Packit |
1470ea |
* that it creates the horizontal/vertical adjustments automatically. Setting
|
|
Packit |
1470ea |
* the scrollbar policy to automatic allows the scrollbars to only show up
|
|
Packit |
1470ea |
* when needed.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
Packit |
1470ea |
/* Set the border width */
|
|
Packit |
1470ea |
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10);
|
|
Packit |
1470ea |
/* Extract our desired image from a file that we have */
|
|
Packit |
1470ea |
image = gtk_image_new_from_file ("gnome-image.png");
|
|
Packit |
1470ea |
/* And add it to the scrolled window */
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (scrolled_window), image);
|
|
Packit |
1470ea |
/* Set the policy of the horizontal and vertical scrollbars to automatic.
|
|
Packit |
1470ea |
* What this means is that the scrollbars are only present if needed.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
Packit |
1470ea |
GTK_POLICY_AUTOMATIC,
|
|
Packit |
1470ea |
GTK_POLICY_AUTOMATIC);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (window), scrolled_window);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_widget_show_all (window);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
int
|
|
Packit |
1470ea |
main (int argc, char **argv)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkApplication *app;
|
|
Packit |
1470ea |
int status;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
|
Packit |
1470ea |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
Packit |
1470ea |
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit |
1470ea |
g_object_unref (app);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|