~ubuntu-branches/ubuntu/utopic/rhythmbox/utopic-proposed

« back to all changes in this revision

Viewing changes to widgets/rb-cell-renderer-pixbuf.c

Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
1
2
/* rbcellrendererpixbuf.c
2
3
 *
3
4
 * arch-tag: Implementation of Rhythmbox pixbuf GtkTreeView cell renderer
24
25
#include <config.h>
25
26
#include <libgnome/gnome-i18n.h>
26
27
#include <stdlib.h>
 
28
#include <gtk/gtktreeview.h>
 
29
#include <gtk/gtkiconfactory.h>
27
30
 
28
31
#include "rb-cell-renderer-pixbuf.h"
29
32
#include "rb-cut-and-paste-code.h"
52
55
                                                GdkRectangle               *cell_area,
53
56
                                                GdkRectangle               *expose_area,
54
57
                                                guint                       flags);
55
 
 
 
58
static gboolean rb_cell_renderer_pixbuf_activate (GtkCellRenderer     *cell,
 
59
                                                  GdkEvent            *event, 
 
60
                                                  GtkWidget           *widget,
 
61
                                                  const gchar         *path,
 
62
                                                  GdkRectangle        *background_area,
 
63
                                                  GdkRectangle        *cell_area,
 
64
                                                  GtkCellRendererState flags);
56
65
 
57
66
enum {
58
67
        PROP_ZERO,
59
68
        PROP_PIXBUF
60
69
};
61
70
 
 
71
enum
 
72
{
 
73
        PIXBUF_CLICKED,
 
74
        LAST_SIGNAL
 
75
};
 
76
 
 
77
static guint rb_cell_renderer_pixbuf_signals [LAST_SIGNAL] = { 0 };
62
78
 
63
79
GtkType
64
80
rb_cell_renderer_pixbuf_get_type (void)
89
105
static void
90
106
rb_cell_renderer_pixbuf_init (RBCellRendererPixbuf *cellpixbuf)
91
107
{
 
108
 
 
109
        /* set the renderer able to be activated */
 
110
        GTK_CELL_RENDERER (cellpixbuf)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
92
111
}
93
112
 
94
113
static void
102
121
 
103
122
        cell_class->get_size = rb_cell_renderer_pixbuf_get_size;
104
123
        cell_class->render = rb_cell_renderer_pixbuf_render;
 
124
        cell_class->activate = rb_cell_renderer_pixbuf_activate;
105
125
 
106
126
        g_object_class_install_property (object_class,
107
127
                                         PROP_PIXBUF,
111
131
                                                              GDK_TYPE_PIXBUF,
112
132
                                                              G_PARAM_READABLE |
113
133
                                                              G_PARAM_WRITABLE));
 
134
 
 
135
        rb_cell_renderer_pixbuf_signals[PIXBUF_CLICKED] =
 
136
                g_signal_new ("pixbuf-clicked",
 
137
                              G_OBJECT_CLASS_TYPE (object_class),
 
138
                              G_SIGNAL_RUN_FIRST,
 
139
                              G_STRUCT_OFFSET (RBCellRendererPixbufClass, pixbuf_clicked),
 
140
                              NULL, NULL,
 
141
                              g_cclosure_marshal_VOID__STRING,
 
142
                              G_TYPE_NONE,
 
143
                              1,
 
144
                              G_TYPE_STRING);
114
145
}
115
146
 
116
147
static void
237
268
 
238
269
{
239
270
  RBCellRendererPixbuf *cellpixbuf = (RBCellRendererPixbuf *) cell;
240
 
  GdkPixbuf *pixbuf;
241
271
  GdkRectangle pix_rect;
242
272
  GdkRectangle draw_rect;
243
273
  GtkStateType state;
260
290
  if (!cellpixbuf->pixbuf)
261
291
    return;
262
292
 
263
 
  pixbuf = eel_create_colorized_pixbuf (cellpixbuf->pixbuf,
264
 
                                        widget->style->text[state].red,
265
 
                                        widget->style->text[state].green,
266
 
                                        widget->style->text[state].blue);
267
 
 
268
 
  if (!pixbuf)
269
 
    return;
270
 
 
271
293
  rb_cell_renderer_pixbuf_get_size (cell, widget, cell_area,
272
294
                                     &pix_rect.x,
273
295
                                     &pix_rect.y,
280
302
  pix_rect.height -= cell->ypad * 2;
281
303
  
282
304
  if (gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
283
 
    gdk_pixbuf_render_to_drawable_alpha (pixbuf,
 
305
    gdk_pixbuf_render_to_drawable_alpha (cellpixbuf->pixbuf,
284
306
                                         window,
285
307
                                         /* pixbuf 0, 0 is at pix_rect.x, pix_rect.y */
286
308
                                         draw_rect.x - pix_rect.x,
293
315
                                         0,
294
316
                                         GDK_RGB_DITHER_NORMAL,
295
317
                                         0, 0);
296
 
 
297
 
  g_object_unref (pixbuf);
 
318
}
 
319
 
 
320
 
 
321
static gboolean
 
322
rb_cell_renderer_pixbuf_activate (GtkCellRenderer *cell,
 
323
                                  GdkEvent *event, 
 
324
                                  GtkWidget *widget,
 
325
                                  const gchar *path,
 
326
                                  GdkRectangle *background_area,
 
327
                                  GdkRectangle *cell_area,
 
328
                                  GtkCellRendererState flags)
 
329
{
 
330
        int mouse_x, mouse_y, icon_width;
 
331
        RBCellRendererPixbuf *cellpixbuf = (RBCellRendererPixbuf *) cell;
 
332
 
 
333
        g_return_val_if_fail (RB_IS_CELL_RENDERER_PIXBUF (cellpixbuf), FALSE);
 
334
 
 
335
        gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, NULL);
 
336
        gtk_widget_get_pointer (widget, &mouse_x, &mouse_y);
 
337
        gtk_tree_view_widget_to_tree_coords (GTK_TREE_VIEW (widget),
 
338
                                             mouse_x,
 
339
                                             mouse_y,
 
340
                                             &mouse_x,
 
341
                                             &mouse_y);
 
342
 
 
343
        /* ensure the user clicks within the good cell */
 
344
        if (mouse_x - cell_area->x >= 0
 
345
            && mouse_x - cell_area->x <= cell_area->width) {
 
346
                g_signal_emit (G_OBJECT (cellpixbuf), rb_cell_renderer_pixbuf_signals [PIXBUF_CLICKED], 0, path);
 
347
        }
 
348
        return TRUE;
298
349
}