~ubuntu-branches/ubuntu/trusty/rawstudio/trusty-proposed

« back to all changes in this revision

Viewing changes to src/eog-pixbuf-cell-renderer.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-10-18 17:58:00 UTC
  • mfrom: (2.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081018175800-r1s7ke1xwy9wxv5b
Tags: 1.1.1-1
MergingĀ upstreamĀ versionĀ 1.1.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
                                             GdkRectangle *expose_area,
44
44
                                             GtkCellRendererState flags);
45
45
 
 
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;
 
50
 
 
51
static gint
 
52
placement_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
 
53
{
 
54
        return GPOINTER_TO_INT(a)-GPOINTER_TO_INT(b);
 
55
}
 
56
 
 
57
static void
 
58
placement_free(gpointer data)
 
59
{
 
60
        g_slice_free(BangPosition, data);
 
61
}
 
62
 
 
63
/**
 
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
 
71
 * easily exist.
 
72
 */
 
73
gboolean
 
74
eog_pixbuf_cell_renderer_get_bang_position(GtkIconView *iconview, GdkPixbuf *pixbuf, BangPosition *bp)
 
75
{
 
76
        BangPosition *bp_;
 
77
        gboolean result = FALSE;
 
78
 
 
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))
 
82
        {
 
83
                *bp = *bp_;
 
84
                result = TRUE;
 
85
        }
 
86
        g_static_mutex_unlock (&placement_lock);
 
87
 
 
88
        return result;
 
89
}
 
90
 
46
91
static void
47
92
eog_pixbuf_cell_renderer_class_init (EogPixbufCellRendererClass *klass)
48
93
{
143
188
        pixbuf = cellpixbuf->pixbuf;
144
189
        GdkRectangle pix_rect;
145
190
        cairo_t *cr;
146
 
        
 
191
        BangPosition *bp;
 
192
        gpointer key;
 
193
 
147
194
        gtk_cell_renderer_pixbuf_get_size (cell, widget, cell_area,
148
195
                &pix_rect.x,
149
196
                &pix_rect.y,
155
202
        pix_rect.width  -= cell->xpad * 2;
156
203
        pix_rect.height -= cell->ypad * 2;
157
204
 
 
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();
 
210
 
 
211
        if (g_timer_elapsed(placement_age, NULL) > PLACEMENT_TTL)
 
212
        {
 
213
                g_tree_destroy(placement);
 
214
                placement = g_tree_new_full(placement_cmp, NULL, NULL, placement_free);
 
215
                g_timer_start(placement_age);
 
216
        }
 
217
 
 
218
        key = GINT_TO_POINTER(GPOINTER_TO_INT(pixbuf)^GPOINTER_TO_INT(widget));
 
219
        bp = g_tree_lookup(placement, key);
 
220
        if (bp)
 
221
        {
 
222
                bp->drawable = GDK_DRAWABLE (window);
 
223
                bp->x = pix_rect.x;
 
224
                bp->y = pix_rect.y;
 
225
        }
 
226
        else
 
227
        {
 
228
                bp = g_slice_new(BangPosition);
 
229
                bp->drawable = GDK_DRAWABLE (window);
 
230
                bp->x = pix_rect.x;
 
231
                bp->y = pix_rect.y;
 
232
                g_tree_insert(placement, key, bp);
 
233
        }
 
234
        g_static_mutex_unlock (&placement_lock);
 
235
 
158
236
        if ((flags & (GTK_CELL_RENDERER_SELECTED|GTK_CELL_RENDERER_PRELIT)) != 0) {
159
237
                gint radius = 5;
160
238
                gint x, y, w, h;