1 From d315979dd99131157d6dd48dbd4851e0a1828efc Mon Sep 17 00:00:00 2001
2 From: Priit Laes <plaes@plaes.org>
3 Date: Thu, 27 Aug 2009 08:41:11 +0000
4 Subject: Restore ColoredCellRendererPixbuf [Jorn Baayen]
6 Gtk+'s stock CellRendererPixbuf does not look nice.
8 * libmuine/Makefile.am, libmuine/rb-cell-renderer-pixbuf.c,
9 libmuine/rb-cell-renderer-pixbuf.h, src/ColoredCellRendererPixbuf.cs,
10 src/Makefile.am, src/PlaylistWindow.cs
12 diff --git a/libmuine/Makefile.am b/libmuine/Makefile.am
13 index e5cc7af..93892fb 100644
14 --- a/libmuine/Makefile.am
15 +++ b/libmuine/Makefile.am
16 @@ -19,6 +19,8 @@ libmuine_la_SOURCES = \
18 pointer-list-model.c \
19 pointer-list-model.h \
20 + rb-cell-renderer-pixbuf.c \
21 + rb-cell-renderer-pixbuf.h \
25 diff --git a/libmuine/rb-cell-renderer-pixbuf.c b/libmuine/rb-cell-renderer-pixbuf.c
27 index 0000000..42cff41
29 +++ b/libmuine/rb-cell-renderer-pixbuf.c
31 +/* rbcellrendererpixbuf.c
33 + * arch-tag: Implementation of Rhythmbox pixbuf GtkTreeView cell renderer
35 + * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
36 + * Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org>
38 + * This library is free software; you can redistribute it and/or
39 + * modify it under the terms of the GNU Library General Public
40 + * License as published by the Free Software Foundation; either
41 + * version 2 of the License, or (at your option) any later version.
43 + * This library is distributed in the hope that it will be useful,
44 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
45 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
46 + * Library General Public License for more details.
48 + * You should have received a copy of the GNU Library General Public
49 + * License along with this library; if not, write to the
50 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
51 + * Boston, MA 02111-1307, USA.
58 +#include "rb-cell-renderer-pixbuf.h"
61 +static void rb_cell_renderer_pixbuf_get_property (GObject *object,
65 +static void rb_cell_renderer_pixbuf_set_property (GObject *object,
67 + const GValue *value,
69 +static void rb_cell_renderer_pixbuf_init (RBCellRendererPixbuf *celltext);
70 +static void rb_cell_renderer_pixbuf_class_init (RBCellRendererPixbufClass *class);
71 +static void rb_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
73 + GdkRectangle *rectangle,
78 +static void rb_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
81 + GdkRectangle *background_area,
82 + GdkRectangle *cell_area,
83 + GdkRectangle *expose_area,
94 +rb_cell_renderer_pixbuf_get_type (void)
96 + static GType cell_pixbuf_type = 0;
98 + if (!cell_pixbuf_type)
100 + static const GTypeInfo cell_pixbuf_info =
102 + sizeof (RBCellRendererPixbufClass),
103 + NULL, /* base_init */
104 + NULL, /* base_finalize */
105 + (GClassInitFunc) rb_cell_renderer_pixbuf_class_init,
106 + NULL, /* class_finalize */
107 + NULL, /* class_data */
108 + sizeof (RBCellRendererPixbuf),
109 + 0, /* n_preallocs */
110 + (GInstanceInitFunc) rb_cell_renderer_pixbuf_init,
114 + cell_pixbuf_type = g_type_register_static (GTK_TYPE_CELL_RENDERER, "RBCellRendererPixbuf", &cell_pixbuf_info, 0);
117 + return cell_pixbuf_type;
121 +rb_cell_renderer_pixbuf_init (RBCellRendererPixbuf *UNUSED(cellpixbuf))
126 +rb_cell_renderer_pixbuf_class_init (RBCellRendererPixbufClass *class)
128 + GObjectClass *object_class = G_OBJECT_CLASS (class);
129 + GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
131 + object_class->get_property = rb_cell_renderer_pixbuf_get_property;
132 + object_class->set_property = rb_cell_renderer_pixbuf_set_property;
134 + cell_class->get_size = rb_cell_renderer_pixbuf_get_size;
135 + cell_class->render = rb_cell_renderer_pixbuf_render;
137 + g_object_class_install_property (object_class,
139 + g_param_spec_object ("pixbuf",
141 + "The pixbuf to render.",
144 + G_PARAM_WRITABLE));
148 +rb_cell_renderer_pixbuf_get_property (GObject *object,
153 + RBCellRendererPixbuf *cellpixbuf = RB_CELL_RENDERER_PIXBUF (object);
158 + g_value_set_object (value,
159 + cellpixbuf->pixbuf ? G_OBJECT (cellpixbuf->pixbuf) : NULL);
162 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
169 +rb_cell_renderer_pixbuf_set_property (GObject *object,
171 + const GValue *value,
175 + RBCellRendererPixbuf *cellpixbuf = RB_CELL_RENDERER_PIXBUF (object);
180 + pixbuf = (GdkPixbuf*) g_value_get_object (value);
182 + g_object_ref (G_OBJECT (pixbuf));
183 + if (cellpixbuf->pixbuf)
184 + g_object_unref (G_OBJECT (cellpixbuf->pixbuf));
185 + cellpixbuf->pixbuf = pixbuf;
188 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
194 + * rb_cell_renderer_pixbuf_new:
196 + * Creates a new #RBCellRendererPixbuf. Adjust rendering
197 + * parameters using object properties. Object properties can be set
198 + * globally (with g_object_set()). Also, with #RBTreeViewColumn, you
199 + * can bind a property to a value in a #RBTreeModel. For example, you
200 + * can bind the "pixbuf" property on the cell renderer to a pixbuf value
201 + * in the model, thus rendering a different image in each row of the
204 + * Return value: the new cell renderer
207 +rb_cell_renderer_pixbuf_new (void)
209 + return GTK_CELL_RENDERER (g_object_new (rb_cell_renderer_pixbuf_get_type (), NULL));
213 +eel_create_colorized_pixbuf (GdkPixbuf *src,
219 + int width, height, has_alpha, src_row_stride, dst_row_stride;
220 + guchar *target_pixels;
221 + guchar *original_pixels;
226 + g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
227 + g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
228 + && gdk_pixbuf_get_n_channels (src) == 3)
229 + || (gdk_pixbuf_get_has_alpha (src)
230 + && gdk_pixbuf_get_n_channels (src) == 4), NULL);
231 + g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
233 + dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
234 + gdk_pixbuf_get_has_alpha (src),
235 + gdk_pixbuf_get_bits_per_sample (src),
236 + gdk_pixbuf_get_width (src),
237 + gdk_pixbuf_get_height (src));
239 + has_alpha = gdk_pixbuf_get_has_alpha (src);
240 + width = gdk_pixbuf_get_width (src);
241 + height = gdk_pixbuf_get_height (src);
242 + src_row_stride = gdk_pixbuf_get_rowstride (src);
243 + dst_row_stride = gdk_pixbuf_get_rowstride (dest);
244 + target_pixels = gdk_pixbuf_get_pixels (dest);
245 + original_pixels = gdk_pixbuf_get_pixels (src);
247 + for (i = 0; i < height; i++) {
248 + pixdest = target_pixels + i*dst_row_stride;
249 + pixsrc = original_pixels + i*src_row_stride;
250 + for (j = 0; j < width; j++) {
251 + *pixdest++ = *pixsrc++ ? red_value : 0;
252 + *pixdest++ = *pixsrc++ ? green_value : 0;
253 + *pixdest++ = *pixsrc++ ? blue_value : 0;
255 + *pixdest++ = *pixsrc++;
263 +rb_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
264 + GtkWidget *UNUSED(widget),
265 + GdkRectangle *cell_area,
271 + RBCellRendererPixbuf *cellpixbuf = (RBCellRendererPixbuf *) cell;
272 + gint pixbuf_width = 0;
273 + gint pixbuf_height = 0;
277 + if (cellpixbuf->pixbuf)
279 + pixbuf_width = gdk_pixbuf_get_width (cellpixbuf->pixbuf);
280 + pixbuf_height = gdk_pixbuf_get_height (cellpixbuf->pixbuf);
283 + calc_width = (gint) GTK_CELL_RENDERER (cellpixbuf)->xpad * 2 + pixbuf_width;
284 + calc_height = (gint) GTK_CELL_RENDERER (cellpixbuf)->ypad * 2 + pixbuf_height;
286 + if (x_offset) *x_offset = 0;
287 + if (y_offset) *y_offset = 0;
289 + if (cell_area && pixbuf_width > 0 && pixbuf_height > 0)
293 + *x_offset = GTK_CELL_RENDERER (cellpixbuf)->xalign * (cell_area->width - calc_width - (2 * GTK_CELL_RENDERER (cellpixbuf)->xpad));
294 + *x_offset = MAX (*x_offset, 0) + GTK_CELL_RENDERER (cellpixbuf)->xpad;
298 + *y_offset = GTK_CELL_RENDERER (cellpixbuf)->yalign * (cell_area->height - calc_height - (2 * GTK_CELL_RENDERER (cellpixbuf)->ypad));
299 + *y_offset = MAX (*y_offset, 0) + GTK_CELL_RENDERER (cellpixbuf)->ypad;
304 + *width = calc_width;
307 + *height = calc_height;
311 +rb_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
314 + GdkRectangle *UNUSED(background_area),
315 + GdkRectangle *cell_area,
316 + GdkRectangle *UNUSED(expose_area),
320 + RBCellRendererPixbuf *cellpixbuf = (RBCellRendererPixbuf *) cell;
322 + GdkRectangle pix_rect;
323 + GdkRectangle draw_rect;
324 + GtkStateType state;
326 + if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
328 + if (GTK_WIDGET_HAS_FOCUS (widget))
329 + state = GTK_STATE_SELECTED;
331 + state = GTK_STATE_ACTIVE;
335 + if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
336 + state = GTK_STATE_INSENSITIVE;
338 + state = GTK_STATE_NORMAL;
341 + if (!cellpixbuf->pixbuf)
344 + pixbuf = eel_create_colorized_pixbuf (cellpixbuf->pixbuf,
345 + widget->style->text[state].red,
346 + widget->style->text[state].green,
347 + widget->style->text[state].blue);
352 + rb_cell_renderer_pixbuf_get_size (cell, widget, cell_area,
358 + pix_rect.x += cell_area->x;
359 + pix_rect.y += cell_area->y;
360 + pix_rect.width -= cell->xpad * 2;
361 + pix_rect.height -= cell->ypad * 2;
363 + if (gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
364 + gdk_draw_pixbuf (window,
365 + widget->style->black_gc,
367 + /* pixbuf 0, 0 is at pix_rect.x, pix_rect.y */
368 + draw_rect.x - pix_rect.x,
369 + draw_rect.y - pix_rect.y,
374 + GDK_RGB_DITHER_NORMAL,
377 + g_object_unref (pixbuf);
379 diff --git a/libmuine/rb-cell-renderer-pixbuf.h b/libmuine/rb-cell-renderer-pixbuf.h
381 index 0000000..6d42fce
383 +++ b/libmuine/rb-cell-renderer-pixbuf.h
385 +/* rbcellrendererpixbuf.h
387 + * arch-tag: Header for Rhythmbox pixbuf GtkTreeView cell renderer
389 + * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
390 + * Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org>
392 + * This library is free software; you can redistribute it and/or
393 + * modify it under the terms of the GNU Library General Public
394 + * License as published by the Free Software Foundation; either
395 + * version 2 of the License, or (at your option) any later version.
397 + * This library is distributed in the hope that it will be useful,
398 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
399 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
400 + * Library General Public License for more details.
402 + * You should have received a copy of the GNU Library General Public
403 + * License along with this library; if not, write to the
404 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
405 + * Boston, MA 02111-1307, USA.
408 +#ifndef __RB_CELL_RENDERER_PIXBUF_H__
409 +#define __RB_CELL_RENDERER_PIXBUF_H__
411 +#include <gtk/gtk.h>
415 +#endif /* __cplusplus */
417 +#define RB_TYPE_CELL_RENDERER_PIXBUF (rb_cell_renderer_pixbuf_get_type ())
418 +#define RB_CELL_RENDERER_PIXBUF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RB_TYPE_CELL_RENDERER_PIXBUF, RBCellRendererPixbuf))
419 +#define RB_CELL_RENDERER_PIXBUF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RB_TYPE_CELL_RENDERER_PIXBUF, RBCellRendererPixbufClass))
420 +#define RB_IS_CELL_RENDERER_PIXBUF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RB_TYPE_CELL_RENDERER_PIXBUF))
421 +#define RB_IS_CELL_RENDERER_PIXBUF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RB_TYPE_CELL_RENDERER_PIXBUF))
422 +#define RB_CELL_RENDERER_PIXBUF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RB_TYPE_CELL_RENDERER_PIXBUF, RBCellRendererPixbufClass))
424 +typedef struct _RBCellRendererPixbuf RBCellRendererPixbuf;
425 +typedef struct _RBCellRendererPixbufClass RBCellRendererPixbufClass;
427 +struct _RBCellRendererPixbuf
429 + GtkCellRenderer parent;
434 +struct _RBCellRendererPixbufClass
436 + GtkCellRendererClass parent_class;
439 +GType rb_cell_renderer_pixbuf_get_type (void);
440 +GtkCellRenderer *rb_cell_renderer_pixbuf_new (void);
444 +#endif /* __cplusplus */
446 +#endif /* __RB_CELL_RENDERER_PIXBUF_H__ */
447 diff --git a/src/ColoredCellRendererPixbuf.cs b/src/ColoredCellRendererPixbuf.cs
449 index 0000000..72c92a5
451 +++ b/src/ColoredCellRendererPixbuf.cs
454 + * Copyright (C) 2004 Jorn Baayen <jorn.baayen@gmail.com>
456 + * This program is free software; you can redistribute it and/or
457 + * modify it under the terms of the GNU General Public License as
458 + * published by the Free Software Foundation; either version 2 of the
459 + * License, or (at your option) any later version.
461 + * This program is distributed in the hope that it will be useful,
462 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
463 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
464 + * General Public License for more details.
466 + * You should have received a copy of the GNU General Public
467 + * License along with this program; if not, write to the
468 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
469 + * Boston, MA 02111-1307, USA.
473 +using System.Runtime.InteropServices;
480 + /// This renderer is similar to <see cref="Gtk.CellRendererPixbuf" />.
482 + public class ColoredCellRendererPixbuf : Gtk.CellRenderer
485 + [DllImport ("libmuine")]
486 + private static extern IntPtr rb_cell_renderer_pixbuf_new ();
489 + /// Create a new <see cref="ColoredCellRendererPixbuf" />
492 + public ColoredCellRendererPixbuf () : base (IntPtr.Zero)
494 + base.Raw = rb_cell_renderer_pixbuf_new ();
495 + System.Console.WriteLine("hi");
499 + ~ColoredCellRendererPixbuf ()
505 + // Properties :: Pixbuf (set;)
507 + /// The <see cref="Gdk.Pixbuf" /> to be used.
509 + /// <param name="value">
510 + /// A <see cref="Gdk.Pixbuf" />.
512 + public Gdk.Pixbuf Pixbuf {
513 + set { SetProperty ("pixbuf", new GLib.Value (value)); }
517 diff --git a/src/Makefile.am b/src/Makefile.am
518 index 76e91f0..b2269b1 100644
519 --- a/src/Makefile.am
520 +++ b/src/Makefile.am
521 @@ -26,6 +26,7 @@ MUINE_CSFILES = \
522 $(srcdir)/HandleView.cs \
523 $(srcdir)/HandleModel.cs \
524 $(srcdir)/StockIcons.cs \
525 + $(srcdir)/ColoredCellRendererPixbuf.cs \
526 $(srcdir)/CoverDatabase.cs \
527 $(srcdir)/CoverGetter.cs \
528 $(srcdir)/MusicBrainz.cs \
529 diff --git a/src/PlaylistWindow.cs b/src/PlaylistWindow.cs
530 index 88104d0..ab1edbd 100644
531 --- a/src/PlaylistWindow.cs
532 +++ b/src/PlaylistWindow.cs
533 @@ -166,9 +166,9 @@ namespace Muine
534 [Glade.Widget] private Box menu_bar_box ;
535 [Glade.Widget] private ScrolledWindow scrolledwindow;
537 - private Gdk.Pixbuf empty_pixbuf ;
538 - private CellRendererPixbuf pixbuf_renderer;
539 - private CellRendererText text_renderer ;
540 + private Gdk.Pixbuf empty_pixbuf ;
541 + private CellRendererText text_renderer ;
542 + private ColoredCellRendererPixbuf pixbuf_renderer;
544 // Widgets :: Containers
545 [Glade.Widget] private Container volume_button_container;
546 @@ -896,8 +896,11 @@ namespace Muine
548 playlist.Selection.Mode = SelectionMode.Multiple;
550 + /* Stock Cell Renderer
551 pixbuf_renderer = new Gtk.CellRendererPixbuf ();
552 pixbuf_renderer.FollowState = true;
554 + pixbuf_renderer = new ColoredCellRendererPixbuf ();
556 text_renderer = new Gtk.CellRendererText ();
557 text_renderer.Ellipsize = Pango.EllipsizeMode.End;
558 @@ -2262,7 +2265,11 @@ namespace Muine
559 (TreeViewColumn col, CellRenderer cell, TreeModel model,
563 Gtk.CellRendererPixbuf r = (Gtk.CellRendererPixbuf) cell;
565 + ColoredCellRendererPixbuf r = (ColoredCellRendererPixbuf) cell;
567 IntPtr handle = playlist.Model.HandleFromIter (iter);
569 if (handle == playlist.Model.Playing) {