Merge branch 'tests-cleanup' into 'master'

Tests cleanup

See merge request GNOME/gtk!1894
This commit is contained in:
Matthias Clasen 2020-05-13 22:19:55 +00:00
commit c1658903b7
11 changed files with 0 additions and 945 deletions

View File

@ -17,12 +17,9 @@ gtk_tests = [
['testappchooserbutton'],
['testassistant'],
['testbaseline'],
['testbox'],
['testbuttons'],
['testcalendar'],
['testclipboard2'],
['testcolorchooser'],
['testcolorchooser2'],
['testcombo'],
['testcombochange'],
['testcellrenderertext'],
@ -37,7 +34,6 @@ gtk_tests = [
['testfilechooser'],
['testfilechooserbutton'],
['testflowbox'],
['testfontchooser'],
['testfontoptions'],
['testframe'],
['testfullscreen'],
@ -52,7 +48,6 @@ gtk_tests = [
['testhover'],
['testiconview'],
['testiconview-keynav'],
['testicontheme'],
['testinfobar'],
['testkineticscrolling'],
['testlist'],
@ -73,7 +68,6 @@ gtk_tests = [
['testselectionmode'],
['testsounds'],
['testspinbutton'],
['testtoolbar2'],
['testtreechanging'],
['testtreednd'],
['testtreeedit'],
@ -89,19 +83,16 @@ gtk_tests = [
['testgrouping'],
['testtooltips'],
['testexpand'],
['testexpander'],
['testvolumebutton'],
['testscrolledwindow'],
['testscrolledge'],
['testscrolltofocus'],
['testcellarea'],
['testswitch'],
['testnoscreen'],
['testtreepos'],
['testsensitive'],
['testtextview'],
['testtextview2'],
['testpixbuf-scale'],
['testgmenu'],
['testlogout'],
['teststack'],

View File

@ -1,139 +0,0 @@
#include <gtk/gtk.h>
static void
edit_widget (GtkWidget *button)
{
GtkWidget *dialog;
GtkWidget *grid;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *check;
dialog = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "dialog"));
if (!dialog)
{
dialog = gtk_dialog_new_with_buttons ("",
GTK_WINDOW (gtk_widget_get_root (button)),
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
NULL, NULL);
grid = gtk_grid_new ();
g_object_set (grid,
"margin-start", 20,
"margin-end", 20,
"margin-top", 20,
"margin-bottom", 20,
"row-spacing", 10,
"column-spacing", 10,
NULL);
gtk_box_append (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), grid);
label = gtk_label_new ("Label:");
gtk_widget_set_halign (label, GTK_ALIGN_END);
entry = gtk_entry_new ();
g_object_bind_property (button, "label",
entry, "text",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), entry, 1, 0, 1, 1);
label = gtk_label_new ("Visible:");
gtk_widget_set_halign (label, GTK_ALIGN_END);
check = gtk_check_button_new ();
g_object_bind_property (button, "visible",
check, "active",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), check, 1, 1, 1, 1);
g_object_set_data (G_OBJECT (button), "dialog", dialog);
}
gtk_window_present (GTK_WINDOW (dialog));
}
static GtkWidget *
test_widget (const gchar *label)
{
GtkWidget *w;
w = gtk_button_new_with_label (label);
g_signal_connect (w, "clicked", G_CALLBACK (edit_widget), NULL);
return w;
}
static void
spacing_changed (GtkSpinButton *spin, GtkBox *box)
{
gint spacing;
spacing = gtk_spin_button_get_value_as_int (spin);
gtk_box_set_spacing (box, spacing);
}
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *box;
GtkWidget *check;
GtkWidget *b;
GtkWidget *label;
GtkWidget *spin;
gtk_init ();
window = gtk_window_new ();
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_window_set_child (GTK_WINDOW (window), vbox);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_append (GTK_BOX (box), test_widget ("1"));
gtk_box_append (GTK_BOX (box), test_widget ("2"));
gtk_box_append (GTK_BOX (box), test_widget ("3"));
gtk_box_append (GTK_BOX (box), test_widget ("4"));
gtk_box_append (GTK_BOX (box), test_widget ("5"));
gtk_box_append (GTK_BOX (box), test_widget ("6"));
gtk_box_append (GTK_BOX (vbox), box);
check = gtk_check_button_new_with_label ("Homogeneous");
g_object_bind_property (box, "homogeneous",
check, "active",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
gtk_widget_set_margin_start (check, 10);
gtk_widget_set_margin_end (check, 10);
gtk_widget_set_margin_top (check, 10);
gtk_widget_set_margin_bottom (check, 10);
gtk_widget_set_halign (check, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox), check);
b = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_widget_set_margin_start (b, 10);
gtk_widget_set_margin_end (b, 10);
gtk_widget_set_margin_top (b, 10);
gtk_widget_set_margin_bottom (b, 10);
gtk_widget_set_halign (b, GTK_ALIGN_CENTER);
label = gtk_label_new ("Spacing:");
gtk_widget_set_halign (label, GTK_ALIGN_END);
gtk_box_append (GTK_BOX (b), label);
spin = gtk_spin_button_new_with_range (0, 10, 1);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin), TRUE);
gtk_widget_set_halign (spin, GTK_ALIGN_START);
g_signal_connect (spin, "value-changed",
G_CALLBACK (spacing_changed), box);
gtk_box_append (GTK_BOX (b), spin);
gtk_box_append (GTK_BOX (vbox), b);
gtk_widget_show (window);
while (TRUE)
g_main_context_iteration (NULL, TRUE);
return 0;
}

View File

@ -1,108 +0,0 @@
#include <gtk/gtk.h>
static void
color_changed (GObject *o, GParamSpec *pspect, gpointer data)
{
GdkRGBA color;
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (o), &color);
g_print ("color changed: %g %g %g %g\n",
color.red, color.green, color.blue, color.alpha);
}
static gboolean done = FALSE;
static void
dialog_response (GtkDialog *dialog, gint response)
{
GdkRGBA color;
switch (response)
{
case GTK_RESPONSE_OK:
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &color);
g_print ("color accepted: %g %g %g %g\n",
color.red, color.green, color.blue, color.alpha);
break;
default:
g_print ("canceled\n");
break;
}
done = TRUE;
g_main_context_wakeup (NULL);
}
int
main (int argc, char *argv[])
{
GtkWidget *dialog;
gint i;
gtk_init ();
dialog = gtk_color_chooser_dialog_new ("Select a color", NULL);
for (i = 1; i < argc; i++)
{
if (g_strcmp0 (argv[i], "--no-alpha") == 0)
{
g_print ("turning alpha off\n");
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (dialog), FALSE);
}
else if (g_strcmp0 (argv[i], "--edit") == 0)
{
g_print ("starting in edit mode\n");
g_object_set (dialog, "show-editor", TRUE, NULL);
}
else if (g_strcmp0 (argv[i], "--palette") == 0)
{
const gchar *c[9] = { "red", "maroon", "yellow", "green", "blue", "magenta", "DarkOliveGreen4", "khaki2", "thistle1" };
GdkRGBA color;
GdkRGBA colors[9*9];
gint k,j;
gdouble f[5] = { 0.2, 0.35, 0.5, 0.65, 0.8 };
g_print ("setting custom palette\n");
for (k = 0; k < 9; k++)
{
gdk_rgba_parse (&color, c[k]);
for (j = 0; j < 5; j++)
{
colors[i*9 + j].red = f[j]*color.red;
colors[i*9 + j].green = f[j]*color.green;
colors[i*9 + j].blue = f[j]*color.blue;
colors[i*9 + j].alpha = 1;
}
for (j = 5; j < 9; j++)
{
colors[i*9 + j].red = f[9-j]*color.red + (1-f[9-j]);
colors[i*9 + j].green = f[9-j]*color.green + (1-f[9-j]);
colors[i*9 + j].blue = f[9-j]*color.blue + (1-f[9-j]);
colors[i*9 + j].alpha = 1;
}
}
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (dialog),
GTK_ORIENTATION_VERTICAL,
9, 9*9,
colors);
}
else if (g_strcmp0 (argv[i], "--no-palette") == 0)
{
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (dialog),
GTK_ORIENTATION_VERTICAL, 0, 0, NULL);
}
}
g_signal_connect (dialog, "notify::color", G_CALLBACK (color_changed), NULL);
g_signal_connect (dialog, "response", G_CALLBACK (dialog_response), NULL);
gtk_widget_show (dialog);
while (!done)
g_main_context_iteration (NULL, TRUE);
return 0;
}

View File

@ -1,60 +0,0 @@
#include <gtk/gtk.h>
static void rgba_changed (GtkColorChooser *chooser, GParamSpec *pspec, gpointer data);
static void
text_activated (GtkEntry *entry, gpointer data)
{
GtkColorChooser *chooser = data;
GdkRGBA rgba;
const char *text;
text = gtk_editable_get_text (GTK_EDITABLE (entry));
g_signal_handlers_block_by_func (entry, rgba_changed, entry);
if (gdk_rgba_parse (&rgba, text))
gtk_color_chooser_set_rgba (chooser, &rgba);
g_signal_handlers_unblock_by_func (entry, rgba_changed, entry);
}
static void
rgba_changed (GtkColorChooser *chooser, GParamSpec *pspec, gpointer data)
{
GtkWidget *entry = data;
GdkRGBA color;
char *s;
gtk_color_chooser_get_rgba (chooser, &color);
s = gdk_rgba_to_string (&color);
g_signal_handlers_block_by_func (entry, text_activated, chooser);
gtk_editable_set_text (GTK_EDITABLE (entry), s);
g_signal_handlers_unblock_by_func (entry, text_activated, chooser);
g_free (s);
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *chooser;
GtkWidget *entry;
GtkBuilder *builder;
gtk_init ();
builder = gtk_builder_new_from_file ("testcolorchooser2.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
chooser = GTK_WIDGET (gtk_builder_get_object (builder, "chooser"));
entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
g_signal_connect (chooser, "notify::rgba", G_CALLBACK (rgba_changed), entry);
g_signal_connect (entry, "activate", G_CALLBACK (text_activated), chooser);
gtk_widget_show (window);
while (TRUE)
g_main_context_iteration (NULL, TRUE);
return 0;
}

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<child>
<object class="GtkBox">
<property name="visible">1</property>
<property name="orientation">horizontal</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="spacing">10</property>
<child>
<object class="GtkEntry" id="entry">
<property name="visible">1</property>
<property name="valign">start</property>
<property name="text">unknown</property>
<property name="width-chars">25</property>
<property name="max-width-chars">25</property>
</object>
</child>
<child>
<object class="GtkColorChooserWidget" id="chooser">
<property name="visible">1</property>
<property name="show-editor">1</property>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -1,81 +0,0 @@
#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
response_cb (GtkDialog *dialog, gint response_id, gpointer data)
{
gboolean *done = data;
*done = TRUE;
g_main_context_wakeup (NULL);
}
int
main (int argc, char *argv[])
{
GtkWidget *dialog;
GtkWidget *area;
GtkWidget *expander;
GtkWidget *sw;
GtkWidget *tv;
GtkTextBuffer *buffer;
gboolean done = FALSE;
gtk_init ();
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));
expander = gtk_expander_new ("Details:");
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
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_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), tv);
gtk_expander_set_child (GTK_EXPANDER (expander), sw);
gtk_widget_set_hexpand (expander, TRUE);
gtk_widget_set_vexpand (expander, TRUE);
gtk_box_append (GTK_BOX (area), expander);
g_signal_connect (expander, "notify::expanded",
G_CALLBACK (expander_cb), dialog);
g_signal_connect (dialog, "response", G_CALLBACK (response_cb), &done);
gtk_window_present (GTK_WINDOW (dialog));
while (!done)
g_main_context_iteration (NULL, TRUE);
return 0;
}

View File

@ -1,101 +0,0 @@
/* testfontchooser.c
* Copyright (C) 2011 Alberto Ruiz <aruiz@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
static void
notify_font_cb (GtkFontChooser *fontchooser, GParamSpec *pspec, gpointer data)
{
PangoFontFamily *family;
PangoFontFace *face;
g_debug ("Changed font name %s", gtk_font_chooser_get_font (fontchooser));
family = gtk_font_chooser_get_font_family (fontchooser);
face = gtk_font_chooser_get_font_face (fontchooser);
if (family)
{
g_debug (" Family: %s is-monospace:%s",
pango_font_family_get_name (family),
pango_font_family_is_monospace (family) ? "true" : "false");
}
else
g_debug (" No font family!");
if (face)
g_debug (" Face description: %s", pango_font_face_get_face_name (face));
else
g_debug (" No font face!");
}
static void
notify_preview_text_cb (GObject *fontchooser, GParamSpec *pspec, gpointer data)
{
g_debug ("Changed preview text %s", gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (fontchooser)));
}
static void
font_activated_cb (GtkFontChooser *chooser, const gchar *font_name, gpointer data)
{
g_debug ("font-activated: %s", font_name);
}
static void
quit_cb (GtkWidget *widget,
gpointer data)
{
gboolean *done = data;
*done = TRUE;
g_main_context_wakeup (NULL);
}
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *fontchooser;
gboolean done = FALSE;
gtk_init ();
fontchooser = gtk_font_chooser_widget_new ();
window = gtk_window_new ();
gtk_widget_set_size_request (window, 600, 600);
gtk_window_set_child (GTK_WINDOW (window), fontchooser);
gtk_widget_show (window);
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
g_signal_connect (fontchooser, "notify::font",
G_CALLBACK (notify_font_cb), NULL);
g_signal_connect (fontchooser, "notify::preview-text",
G_CALLBACK (notify_preview_text_cb), NULL);
g_signal_connect (fontchooser, "font-activated",
G_CALLBACK (font_activated_cb), NULL);
gtk_font_chooser_set_font (GTK_FONT_CHOOSER (fontchooser), "Sans 45");
gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (fontchooser), "[user@host ~]$ &>>");
gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (fontchooser), FALSE);
while (!done)
g_main_context_iteration (NULL, TRUE);
return 0;
}

View File

@ -1,163 +0,0 @@
/* testicontheme.c
* Copyright (C) 2002, 2003 Red Hat, Inc.
* Authors: Alexander Larsson, Owen Taylor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
static void
usage (void)
{
g_print ("usage: test-icon-theme lookup <theme name> <icon name> [size] [scale]\n"
" or\n"
"usage: test-icon-theme list <theme name> [context]\n"
" or\n"
"usage: test-icon-theme display <theme name> <icon name> [size] [scale]\n"
);
}
static void
quit_cb (GtkWidget *widget,
gpointer data)
{
gboolean *done = data;
*done = TRUE;
g_main_context_wakeup (NULL);
}
int
main (int argc, char *argv[])
{
GtkIconTheme *icon_theme;
char *themename;
int size = 48;
int scale = 1;
GtkIconLookupFlags flags;
GtkTextDirection direction;
gtk_init ();
if (argc < 3)
{
usage ();
return 1;
}
flags = 0;
if (g_getenv ("RTL"))
direction = GTK_TEXT_DIR_RTL;
else if (g_getenv ("LTR"))
direction = GTK_TEXT_DIR_LTR;
else
direction = GTK_TEXT_DIR_NONE;
themename = argv[2];
icon_theme = gtk_icon_theme_new ();
gtk_icon_theme_set_theme_name (icon_theme, themename);
if (strcmp (argv[1], "display") == 0)
{
GtkIconPaintable *icon;
GtkWidget *window, *image;
gboolean done = FALSE;
if (argc < 4)
{
g_object_unref (icon_theme);
usage ();
return 1;
}
if (argc >= 5)
size = atoi (argv[4]);
if (argc >= 6)
scale = atoi (argv[5]);
icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], NULL, size, scale, direction, flags);
if (!icon)
{
g_print ("Icon '%s' not found\n", argv[3]);
return 1;
}
window = gtk_window_new ();
image = gtk_image_new ();
gtk_image_set_from_paintable (GTK_IMAGE (image), GDK_PAINTABLE (icon));
g_object_unref (icon);
gtk_window_set_child (GTK_WINDOW (window), image);
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
gtk_widget_show (window);
while (!done)
g_main_context_iteration (NULL, TRUE);
}
else if (strcmp (argv[1], "list") == 0)
{
char **icons;
int i;
icons = gtk_icon_theme_get_icon_names (icon_theme);
for (i = 0; icons[i]; i++)
g_print ("%s\n", icons[i]);
g_strfreev (icons);
}
else if (strcmp (argv[1], "lookup") == 0)
{
GFile *file;
GtkIconPaintable *icon;
if (argc < 4)
{
g_object_unref (icon_theme);
usage ();
return 1;
}
if (argc >= 5)
size = atoi (argv[4]);
if (argc >= 6)
scale = atoi (argv[5]);
icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], NULL, size, scale, direction, flags);
file = gtk_icon_paintable_get_file (icon);
g_print ("icon for %s at %dx%d@%dx is %s\n", argv[3], size, size, scale,
file ? g_file_get_uri (file) : "<none>");
g_print ("texture size: %dx%d\n", gdk_paintable_get_intrinsic_width (GDK_PAINTABLE (icon)), gdk_paintable_get_intrinsic_height (GDK_PAINTABLE (icon)));
g_object_unref (icon);
}
else
{
g_object_unref (icon_theme);
usage ();
return 1;
}
g_object_unref (icon_theme);
return 0;
}

View File

@ -1,50 +0,0 @@
/* testnoscreen.c
* Copyright (C) 2011 Red Hat, Inc.
* Authors: Matthias Clasen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
/* Very limited test to ensure that creating widgets works
* before opening a display connection
*/
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;
GdkDisplay *display;
gboolean has_display;
gdk_set_allowed_backends ("x11");
g_unsetenv ("DISPLAY");
has_display = gtk_init_check ();
g_assert (!has_display);
window = gtk_window_new ();
button = gtk_button_new ();
gtk_window_set_child (GTK_WINDOW (window), button);
display = gdk_display_open (NULL);
gtk_window_set_display (GTK_WINDOW (window), display);
gtk_widget_show (window);
while (TRUE)
g_main_context_iteration (NULL, TRUE);
return 0;
}

View File

@ -1,160 +0,0 @@
#include "config.h"
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
GdkInterpType interp_type = GDK_INTERP_BILINEAR;
int overall_alpha = 255;
GdkPixbuf *pixbuf;
GtkWidget *darea;
static void
set_interp_type (GtkWidget *widget, gpointer data)
{
guint types[] = { GDK_INTERP_NEAREST,
GDK_INTERP_BILINEAR,
GDK_INTERP_TILES,
GDK_INTERP_HYPER };
interp_type = types[gtk_combo_box_get_active (GTK_COMBO_BOX (widget))];
gtk_widget_queue_draw (darea);
}
static void
overall_changed_cb (GtkAdjustment *adjustment, gpointer data)
{
if (gtk_adjustment_get_value (adjustment) != overall_alpha)
{
overall_alpha = gtk_adjustment_get_value (adjustment);
gtk_widget_queue_draw (darea);
}
}
static void
draw_func (GtkDrawingArea *area,
cairo_t *cr,
int width,
int height,
gpointer data)
{
GdkPixbuf *dest;
dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
gdk_pixbuf_composite_color (pixbuf, dest,
0, 0, width, height,
0, 0,
(double) width / gdk_pixbuf_get_width (pixbuf),
(double) height / gdk_pixbuf_get_height (pixbuf),
interp_type, overall_alpha,
0, 0, 16, 0xaaaaaa, 0x555555);
gdk_cairo_set_source_pixbuf (cr, dest, 0, 0);
cairo_paint (cr);
g_object_unref (dest);
}
static void
quit_cb (GtkWidget *widget,
gpointer data)
{
gboolean *done = data;
*done = TRUE;
g_main_context_wakeup (NULL);
}
int
main(int argc, char **argv)
{
GtkWidget *window, *vbox;
GtkWidget *combo_box;
GtkWidget *hbox, *label, *hscale;
GtkAdjustment *adjustment;
GtkRequisition scratch_requisition;
const gchar *creator;
GError *error;
gboolean done = FALSE;
gtk_init ();
if (argc != 2) {
fprintf (stderr, "Usage: testpixbuf-scale FILE\n");
exit (1);
}
error = NULL;
pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
if (!pixbuf) {
fprintf (stderr, "Cannot load image: %s\n",
error->message);
g_error_free (error);
exit(1);
}
creator = gdk_pixbuf_get_option (pixbuf, "tEXt::Software");
if (creator)
g_print ("%s was created by '%s'\n", argv[1], creator);
window = gtk_window_new ();
g_signal_connect (window, "destroy",
G_CALLBACK (quit_cb), &done);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_window_set_child (GTK_WINDOW (window), vbox);
combo_box = gtk_combo_box_text_new ();
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "NEAREST");
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "BILINEAR");
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "TILES");
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "HYPER");
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 1);
g_signal_connect (combo_box, "changed",
G_CALLBACK (set_interp_type),
NULL);
gtk_widget_set_halign (combo_box, GTK_ALIGN_START);
gtk_box_append (GTK_BOX (vbox), combo_box);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_box_append (GTK_BOX (vbox), hbox);
label = gtk_label_new ("Overall Alpha:");
gtk_box_append (GTK_BOX (hbox), label);
adjustment = gtk_adjustment_new (overall_alpha, 0, 255, 1, 10, 0);
g_signal_connect (adjustment, "value_changed",
G_CALLBACK (overall_changed_cb), NULL);
hscale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjustment);
gtk_scale_set_digits (GTK_SCALE (hscale), 0);
gtk_widget_set_hexpand (hscale, TRUE);
gtk_box_append (GTK_BOX (hbox), hscale);
/* Compute the size without the drawing area, so we know how big to make the default size */
gtk_widget_get_preferred_size ( (vbox),
&scratch_requisition, NULL);
darea = gtk_drawing_area_new ();
gtk_widget_set_hexpand (darea, TRUE);
gtk_box_append (GTK_BOX (vbox), darea);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (darea), draw_func, NULL, NULL);
gtk_window_set_default_size (GTK_WINDOW (window),
gdk_pixbuf_get_width (pixbuf),
scratch_requisition.height + gdk_pixbuf_get_height (pixbuf));
gtk_widget_show (window);
while (!done)
g_main_context_iteration (NULL, TRUE);
return 0;
}

View File

@ -1,45 +0,0 @@
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *box;
GtkWidget *frame;
GtkWidget *box3;
GtkWidget *view;
GtkWidget *button;
gtk_init ();
window = gtk_window_new ();
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_window_set_child (GTK_WINDOW (window), box);
frame = gtk_frame_new (NULL);
gtk_box_append (GTK_BOX (box), frame);
view = gtk_text_view_new ();
gtk_widget_set_vexpand (view, TRUE);
gtk_box_append (GTK_BOX (box), view);
box3 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_margin_start (box3, 10);
gtk_widget_set_margin_end (box3, 10);
gtk_widget_set_margin_top (box3, 10);
gtk_widget_set_margin_bottom (box3, 10);
gtk_widget_add_css_class (box3, GTK_STYLE_CLASS_LINKED);
button = gtk_button_new_from_icon_name ("document-new-symbolic");
gtk_box_append (GTK_BOX (box3), button);
button = gtk_button_new_from_icon_name ("document-open-symbolic");
gtk_box_append (GTK_BOX (box3), button);
button = gtk_button_new_from_icon_name ("document-save-symbolic");
gtk_box_append (GTK_BOX (box3), button);
gtk_frame_set_child (GTK_FRAME (frame), box3);
gtk_widget_show (GTK_WIDGET (window));
while (TRUE)
g_main_context_iteration (NULL, TRUE);
return 0;
}