summaryrefslogtreecommitdiff
path: root/test/test-eel-image-table.c
blob: f47771783ff2d7f83c83ae873791cfdd0a1c82e0 (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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#include <stdlib.h>
#include <gtk/gtk.h>

#include <eel/eel-image-table.h>

#include "test.h"

static const char pixbuf_name[] = "/usr/share/pixmaps/mate-about-logo.png";

static const char *names[] =
{
	"Tomaso Albinoni",
	"Isaac Alb�niz",
	"Georges Bizet",
	"Luigi Boccherini",
	"Alexander Borodin",
	"Johannes Brahms",
	"Max Bruch",
	"Anton Bruckner",
	"Fr�d�ric Chopin",
	"Aaron Copland",
	"John Corigliano",
	"Claude Debussy",
	"L�o Delibes",
	"Anton�n Dvor�k",
	"Edward Elgar",
	"Manuel de Falla",
	"George Gershwin",
	"Alexander Glazunov",
	"Mikhail Glinka",
	"Enrique Granados",
	"Edvard Grieg",
	"Joseph Haydn",
	"Scott Joplin",
	"Franz Liszt",
	"Gustav Mahler",
	"Igor Markevitch",
	"Felix Mendelssohn",
	"Modest Mussorgsky",
	"Sergei Prokofiev",
	"Giacomo Puccini",
	"Maurice Ravel",
	"Ottorino Respighi",
	"Joaquin Rodrigo",
	"Gioachino Rossini",
	"Domenico Scarlatti",
	"Franz Schubert",
	"Robert Schumann",
	"Jean Sibelius",
	"Bedrich Smetana",
	"Johann Strauss",
	"Igor Stravinsky",
	"Giuseppe Verdi",
	"Antonio Vivaldi",
	"Richard Wagner",
};

static GtkWidget *
labeled_image_new (const char *text,
		   const char *icon_name)
{
	GtkWidget *image;
	GdkPixbuf *pixbuf = NULL;

	if (icon_name) {
		float sizes[] = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
					1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0 };
		pixbuf = test_pixbuf_new_named (icon_name, sizes[random () % G_N_ELEMENTS (sizes)]);
	}

	image = eel_labeled_image_new (text, pixbuf);

	eel_gdk_pixbuf_unref_if_not_null (pixbuf);

	return image;
}


static void
image_table_child_enter_callback (GtkWidget *image_table,
			       GtkWidget *item,
			       gpointer callback_data)
{
#if 0
	char *text;

	g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table));
	g_return_if_fail (EEL_IS_LABELED_IMAGE (item));

	text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item));

	g_print ("%s(%s)\n", G_STRFUNC, text);
#endif
}

static void
image_table_child_leave_callback (GtkWidget *image_table,
			       GtkWidget *item,
			       gpointer callback_data)
{
#if 0
	char *text;

	g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table));
	g_return_if_fail (EEL_IS_LABELED_IMAGE (item));

	text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item));

	g_print ("%s(%s)\n", G_STRFUNC, text);
#endif
}

static void
image_table_child_pressed_callback (GtkWidget *image_table,
			       GtkWidget *item,
			       gpointer callback_data)
{
	char *text;

	g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table));
	g_return_if_fail (EEL_IS_LABELED_IMAGE (item));

	text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item));

	g_print ("%s(%s)\n", G_STRFUNC, text);
}

static void
image_table_child_released_callback (GtkWidget *image_table,
				  GtkWidget *item,
				  gpointer callback_data)
{
	char *text;

	g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table));
	g_return_if_fail (EEL_IS_LABELED_IMAGE (item));

	text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item));

	g_print ("%s(%s)\n", G_STRFUNC, text);
}

static void
image_table_child_clicked_callback (GtkWidget *image_table,
				 GtkWidget *item,
				 gpointer callback_data)
{
	char *text;

	g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table));
	g_return_if_fail (EEL_IS_LABELED_IMAGE (item));

	text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item));

	g_print ("%s(%s)\n", G_STRFUNC, text);
}

static int
foo_timeout (gpointer callback_data)
{
	static int recursion_count = 0;
	g_return_val_if_fail (GTK_IS_WINDOW (callback_data), FALSE);

	recursion_count++;

	g_print ("%s(%d)\n", G_STRFUNC, recursion_count);
	gtk_widget_queue_resize (GTK_WIDGET (callback_data));

	recursion_count--;

	return FALSE;
}

static void
image_table_size_allocate (GtkWidget *image_table,
			   GtkAllocation *allocation,
			   gpointer callback_data)
{
	static int recursion_count = 0;
	GtkAllocation w_allocation;

	g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table));
	g_return_if_fail (allocation != NULL);
	g_return_if_fail (GTK_IS_WINDOW (callback_data));

	recursion_count++;

	if (0) g_timeout_add (0, foo_timeout, callback_data);

	/*gtk_widget_queue_resize (GTK_WIDGET (callback_data));*/

	gtk_widget_get_allocation (GTK_WIDGET (image_table), &w_allocation);
	if (0) gtk_widget_size_allocate (GTK_WIDGET (image_table),
					 &w_allocation);

	g_print ("%s(%d)\n", G_STRFUNC, recursion_count);

	recursion_count--;
}

static GtkWidget *
image_table_new_scrolled (void)
{
	GtkWidget *scrolled;
	GtkWidget *viewport;
	GtkWidget *window;
	GtkWidget *image_table;
	int i;

	window = test_window_new ("Image Table Test", 10);

	gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);

	/* Scrolled window */
	scrolled = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
					GTK_POLICY_NEVER,
					GTK_POLICY_AUTOMATIC);
	gtk_container_add (GTK_CONTAINER (window), scrolled);

	/* Viewport */
 	viewport = gtk_viewport_new (NULL, NULL);
	gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_OUT);
	gtk_container_add (GTK_CONTAINER (scrolled), viewport);

	image_table = eel_image_table_new (FALSE);

	if (0) g_signal_connect (image_table,
			    "size_allocate",
			    G_CALLBACK (image_table_size_allocate),
			    window);

	eel_wrap_table_set_x_justification (EEL_WRAP_TABLE (image_table),
						 EEL_JUSTIFICATION_MIDDLE);
	eel_wrap_table_set_y_justification (EEL_WRAP_TABLE (image_table),
						 EEL_JUSTIFICATION_END);

	gtk_container_add (GTK_CONTAINER (viewport), image_table);

	g_signal_connect (image_table,
			    "child_enter",
			    G_CALLBACK (image_table_child_enter_callback),
			    NULL);

	g_signal_connect (image_table,
			    "child_leave",
			    G_CALLBACK (image_table_child_leave_callback),
			    NULL);

	g_signal_connect (image_table,
			    "child_pressed",
			    G_CALLBACK (image_table_child_pressed_callback),
			    NULL);

	g_signal_connect (image_table,
			    "child_released",
			    G_CALLBACK (image_table_child_released_callback),
			    NULL);

	g_signal_connect (image_table,
			    "child_clicked",
			    G_CALLBACK (image_table_child_clicked_callback),
			    NULL);

	for (i = 0; i < 100; i++) {
		char *text;
		GtkWidget *image;

		text = g_strdup_printf ("%s %d",
					names[random () % G_N_ELEMENTS (names)],
					i);
		image = labeled_image_new (text, pixbuf_name);
		g_free (text);

		gtk_container_add (GTK_CONTAINER (image_table), image);
		gtk_widget_show (image);
	}

	gtk_widget_show (viewport);
	gtk_widget_show (scrolled);
	gtk_widget_show (image_table);

	return window;
}

int
main (int argc, char* argv[])
{
	GtkWidget *window = NULL;

	test_init (&argc, &argv);

	window = image_table_new_scrolled ();

	gtk_widget_show (window);

	gtk_main ();

	return 0;
}