43
43
GdkRectangle *expose_area,
44
44
GtkCellRendererState flags);
46
#define PLACEMENT_TTL 120 /* Seconds to remember */
47
static GStaticMutex placement_lock = G_STATIC_MUTEX_INIT;
48
static GTree *placement = NULL;
49
static GTimer *placement_age = NULL;
52
placement_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
54
return GPOINTER_TO_INT(a)-GPOINTER_TO_INT(b);
58
placement_free(gpointer data)
60
g_slice_free(BangPosition, data);
64
* This is an evil evil evil hack that should never be used by any sane person.
65
* eog_pixbuf_cell_renderer_render() will store the position and the drawable
66
* a pixbuf has been drawn to - this function returns this information in a
67
* BangPositon. This will allow an aggressive caller to bang the GdkDrawable
68
* directly instead of using conventional methods of setting the icon.
69
* Please understand: THE INFORMATION RETURNED CAN BE WRONG AND/OR OUTDATED!
70
* The key used in the tree is simply two XOR'ed pointers, collisions can
74
eog_pixbuf_cell_renderer_get_bang_position(GtkIconView *iconview, GdkPixbuf *pixbuf, BangPosition *bp)
77
gboolean result = FALSE;
79
g_static_mutex_lock (&placement_lock);
80
bp_ = g_tree_lookup(placement, GINT_TO_POINTER(GPOINTER_TO_INT(pixbuf)^GPOINTER_TO_INT(iconview)));
81
if (bp_ && GDK_IS_DRAWABLE(bp_->drawable))
86
g_static_mutex_unlock (&placement_lock);
47
92
eog_pixbuf_cell_renderer_class_init (EogPixbufCellRendererClass *klass)
155
202
pix_rect.width -= cell->xpad * 2;
156
203
pix_rect.height -= cell->ypad * 2;
205
g_static_mutex_lock (&placement_lock);
206
if (placement == NULL)
207
placement = g_tree_new_full(placement_cmp, NULL, NULL, placement_free);
208
if (placement_age == NULL)
209
placement_age = g_timer_new();
211
if (g_timer_elapsed(placement_age, NULL) > PLACEMENT_TTL)
213
g_tree_destroy(placement);
214
placement = g_tree_new_full(placement_cmp, NULL, NULL, placement_free);
215
g_timer_start(placement_age);
218
key = GINT_TO_POINTER(GPOINTER_TO_INT(pixbuf)^GPOINTER_TO_INT(widget));
219
bp = g_tree_lookup(placement, key);
222
bp->drawable = GDK_DRAWABLE (window);
228
bp = g_slice_new(BangPosition);
229
bp->drawable = GDK_DRAWABLE (window);
232
g_tree_insert(placement, key, bp);
234
g_static_mutex_unlock (&placement_lock);
158
236
if ((flags & (GTK_CELL_RENDERER_SELECTED|GTK_CELL_RENDERER_PRELIT)) != 0) {