summaryrefslogtreecommitdiff
path: root/test/test.c
blob: 46d9f93b012e17679f61150c50de0f7bc80fa57e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "test.h"

#include <eel/eel-preferences.h>

void
test_init (int *argc,
	   char ***argv)
{
	gtk_init (argc, argv);
	gdk_rgb_init ();
	gnome_vfs_init ();

	eel_make_warnings_and_criticals_stop_in_debugger ();
}

int
test_quit (int exit_code)
{
        /* gnome_vfs_shutdown (); */

	if (gtk_main_level () > 0) {
		gtk_main_quit ();
	}

	return exit_code;
}

void
test_delete_event (GtkWidget *widget,
		   GdkEvent *event,
		   gpointer callback_data)
{
	test_quit (0);
}

GtkWidget *
test_window_new (const char *title, guint border_width)
{
	GtkWidget *window;

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	
	if (title != NULL) {
		gtk_window_set_title (GTK_WINDOW (window), title);
	}

	g_signal_connect (window, "delete_event",
                          G_CALLBACK (test_delete_event), NULL);
	
	gtk_container_set_border_width (GTK_CONTAINER (window), border_width);
	
	return window;
}

void
test_gtk_widget_set_background_image (GtkWidget *widget,
				      const char *image_name)
{
	EelBackground *background;
	char *uri;

	g_return_if_fail (GTK_IS_WIDGET (widget));
	g_return_if_fail (image_name != NULL);

	background = eel_get_widget_background (widget);
	
	uri = g_strdup_printf ("file://%s/%s", NAUTILUS_DATADIR, image_name);

	eel_background_set_image_uri (background, uri);

	g_free (uri);
}

void
test_gtk_widget_set_background_color (GtkWidget *widget,
				      const char *color_spec)
{
	EelBackground *background;

	g_return_if_fail (GTK_IS_WIDGET (widget));
	g_return_if_fail (color_spec != NULL);

	background = eel_get_widget_background (widget);
	
	eel_background_set_color (background, color_spec);
}

GdkPixbuf *
test_pixbuf_new_named (const char *name, float scale)
{
	GdkPixbuf *pixbuf;
	char *path;

	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (scale >= 0.0, NULL);

	if (name[0] == '/') {
		path = g_strdup (name);
	} else {
		path = g_strdup_printf ("%s/%s", NAUTILUS_DATADIR, name);
	}

	pixbuf = gdk_pixbuf_new_from_file (path, NULL);

	g_free (path);

	g_return_val_if_fail (pixbuf != NULL, NULL);
	
	if (scale != 1.0) {
		GdkPixbuf *scaled;
		float width = gdk_pixbuf_get_width (pixbuf) * scale;
		float height = gdk_pixbuf_get_width (pixbuf) * scale;

		scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);

		g_object_unref (pixbuf);

		g_return_val_if_fail (scaled != NULL, NULL);

		pixbuf = scaled;
	}

	return pixbuf;
}

GtkWidget *
test_label_new (const char *text,
		gboolean with_background,
		int num_sizes_larger)
{
	GtkWidget *label;

	if (text == NULL) {
		text = "Foo";
	}
	
	label = gtk_label_new (text);

	return label;
}

void 
test_window_set_title_with_pid (GtkWindow *window,
				const char *title)
{
	char *tmp;
	
	g_return_if_fail (GTK_IS_WINDOW (window));

	tmp = g_strdup_printf ("%lu: %s", (gulong) getpid (), title);
	gtk_window_set_title (GTK_WINDOW (window), tmp);
	g_free (tmp);
}

void
test_pixbuf_draw_rectangle_tiled (GdkPixbuf *pixbuf,
				  const char *tile_name,
				  int x0,
				  int y0,
				  int x1,
				  int y1,
				  int opacity)
{
	ArtIRect area;
	GdkPixbuf *tile_pixbuf;

	g_return_if_fail (eel_gdk_pixbuf_is_valid (pixbuf));
	g_return_if_fail (tile_name != NULL);
 	g_return_if_fail (opacity > EEL_OPACITY_FULLY_TRANSPARENT);
 	g_return_if_fail (opacity <= EEL_OPACITY_FULLY_OPAQUE);

	tile_pixbuf = test_pixbuf_new_named (tile_name, 1.0);

 	g_return_if_fail (tile_pixbuf != NULL);

	if (x0 == -1 && y0 == -1 && x1 == -1 && y1 == -1) {
		EelDimensions dimensions;
		dimensions = eel_gdk_pixbuf_get_dimensions (pixbuf);
		area = eel_art_irect_assign_dimensions (0, 0, dimensions);
	} else {
		g_return_if_fail (x0 >= 0);
		g_return_if_fail (y0 >= 0);
		g_return_if_fail (x1 > x0);
		g_return_if_fail (y1 > y0);

		area.x0 = x0;
		area.y0 = y0;
		area.x1 = x1;
		area.y1 = y1;
	}
	
	eel_gdk_pixbuf_draw_to_pixbuf_tiled (tile_pixbuf,
					     pixbuf,
					     area,
					     gdk_pixbuf_get_width (tile_pixbuf),
					     gdk_pixbuf_get_height (tile_pixbuf),
					     0,
					     0,
					     opacity,
					     GDK_INTERP_NEAREST);

	g_object_unref (tile_pixbuf);
}