updated on Sun Jan 15 04:04:02 UTC 2012
[aur-mirror.git] / muine / use-coloredcellrendererpixbuf.patch
blob97b7a72106c9b9140c5fc2144de6460cc268cbd1
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
11 ---
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 = \
17 player-gst.c \
18 pointer-list-model.c \
19 pointer-list-model.h \
20 + rb-cell-renderer-pixbuf.c \
21 + rb-cell-renderer-pixbuf.h \
22 db.c \
23 db.h \
24 mm-keys.c \
25 diff --git a/libmuine/rb-cell-renderer-pixbuf.c b/libmuine/rb-cell-renderer-pixbuf.c
26 new file mode 100644
27 index 0000000..42cff41
28 --- a/dev/null
29 +++ b/libmuine/rb-cell-renderer-pixbuf.c
30 @@ -0,0 +1,348 @@
31 +/* rbcellrendererpixbuf.c
32 + *
33 + * arch-tag: Implementation of Rhythmbox pixbuf GtkTreeView cell renderer
34 + *
35 + * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
36 + * Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org>
37 + *
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.
42 + *
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.
47 + *
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.
52 + */
54 +#include <config.h>
55 +#include <stdlib.h>
56 +#include <stdio.h>
58 +#include "rb-cell-renderer-pixbuf.h"
59 +#include "macros.h"
61 +static void rb_cell_renderer_pixbuf_get_property (GObject *object,
62 + guint param_id,
63 + GValue *value,
64 + GParamSpec *pspec);
65 +static void rb_cell_renderer_pixbuf_set_property (GObject *object,
66 + guint param_id,
67 + const GValue *value,
68 + GParamSpec *pspec);
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,
72 + GtkWidget *widget,
73 + GdkRectangle *rectangle,
74 + gint *x_offset,
75 + gint *y_offset,
76 + gint *width,
77 + gint *height);
78 +static void rb_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
79 + GdkWindow *window,
80 + GtkWidget *widget,
81 + GdkRectangle *background_area,
82 + GdkRectangle *cell_area,
83 + GdkRectangle *expose_area,
84 + guint flags);
87 +enum {
88 + PROP_ZERO,
89 + PROP_PIXBUF
90 +};
93 +GType
94 +rb_cell_renderer_pixbuf_get_type (void)
96 + static GType cell_pixbuf_type = 0;
98 + if (!cell_pixbuf_type)
99 + {
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,
111 + NULL
112 + };
114 + cell_pixbuf_type = g_type_register_static (GTK_TYPE_CELL_RENDERER, "RBCellRendererPixbuf", &cell_pixbuf_info, 0);
117 + return cell_pixbuf_type;
120 +static void
121 +rb_cell_renderer_pixbuf_init (RBCellRendererPixbuf *UNUSED(cellpixbuf))
125 +static void
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,
138 + PROP_PIXBUF,
139 + g_param_spec_object ("pixbuf",
140 + "Pixbuf Object",
141 + "The pixbuf to render.",
142 + GDK_TYPE_PIXBUF,
143 + G_PARAM_READABLE |
144 + G_PARAM_WRITABLE));
147 +static void
148 +rb_cell_renderer_pixbuf_get_property (GObject *object,
149 + guint param_id,
150 + GValue *value,
151 + GParamSpec *pspec)
153 + RBCellRendererPixbuf *cellpixbuf = RB_CELL_RENDERER_PIXBUF (object);
155 + switch (param_id)
157 + case PROP_PIXBUF:
158 + g_value_set_object (value,
159 + cellpixbuf->pixbuf ? G_OBJECT (cellpixbuf->pixbuf) : NULL);
160 + break;
161 + default:
162 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
163 + break;
168 +static void
169 +rb_cell_renderer_pixbuf_set_property (GObject *object,
170 + guint param_id,
171 + const GValue *value,
172 + GParamSpec *pspec)
174 + GdkPixbuf *pixbuf;
175 + RBCellRendererPixbuf *cellpixbuf = RB_CELL_RENDERER_PIXBUF (object);
177 + switch (param_id)
179 + case PROP_PIXBUF:
180 + pixbuf = (GdkPixbuf*) g_value_get_object (value);
181 + if (pixbuf)
182 + g_object_ref (G_OBJECT (pixbuf));
183 + if (cellpixbuf->pixbuf)
184 + g_object_unref (G_OBJECT (cellpixbuf->pixbuf));
185 + cellpixbuf->pixbuf = pixbuf;
186 + break;
187 + default:
188 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
189 + break;
193 +/**
194 + * rb_cell_renderer_pixbuf_new:
195 + *
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
202 + * #RBTreeView.
203 + *
204 + * Return value: the new cell renderer
205 + **/
206 +GtkCellRenderer *
207 +rb_cell_renderer_pixbuf_new (void)
209 + return GTK_CELL_RENDERER (g_object_new (rb_cell_renderer_pixbuf_get_type (), NULL));
212 +static GdkPixbuf *
213 +eel_create_colorized_pixbuf (GdkPixbuf *src,
214 + int red_value,
215 + int green_value,
216 + int blue_value)
218 + int i, j;
219 + int width, height, has_alpha, src_row_stride, dst_row_stride;
220 + guchar *target_pixels;
221 + guchar *original_pixels;
222 + guchar *pixsrc;
223 + guchar *pixdest;
224 + GdkPixbuf *dest;
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;
254 + if (has_alpha) {
255 + *pixdest++ = *pixsrc++;
256 + }
259 + return dest;
262 +static void
263 +rb_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
264 + GtkWidget *UNUSED(widget),
265 + GdkRectangle *cell_area,
266 + gint *x_offset,
267 + gint *y_offset,
268 + gint *width,
269 + gint *height)
271 + RBCellRendererPixbuf *cellpixbuf = (RBCellRendererPixbuf *) cell;
272 + gint pixbuf_width = 0;
273 + gint pixbuf_height = 0;
274 + gint calc_width;
275 + gint calc_height;
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)
291 + if (x_offset)
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;
296 + if (y_offset)
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;
303 + if (calc_width)
304 + *width = calc_width;
306 + if (height)
307 + *height = calc_height;
310 +static void
311 +rb_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
312 + GdkWindow *window,
313 + GtkWidget *widget,
314 + GdkRectangle *UNUSED(background_area),
315 + GdkRectangle *cell_area,
316 + GdkRectangle *UNUSED(expose_area),
317 + guint flags)
320 + RBCellRendererPixbuf *cellpixbuf = (RBCellRendererPixbuf *) cell;
321 + GdkPixbuf *pixbuf;
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;
330 + else
331 + state = GTK_STATE_ACTIVE;
333 + else
335 + if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
336 + state = GTK_STATE_INSENSITIVE;
337 + else
338 + state = GTK_STATE_NORMAL;
341 + if (!cellpixbuf->pixbuf)
342 + return;
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);
349 + if (!pixbuf)
350 + return;
352 + rb_cell_renderer_pixbuf_get_size (cell, widget, cell_area,
353 + &pix_rect.x,
354 + &pix_rect.y,
355 + &pix_rect.width,
356 + &pix_rect.height);
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,
366 + pixbuf,
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,
370 + draw_rect.x,
371 + draw_rect.y,
372 + draw_rect.width,
373 + draw_rect.height,
374 + GDK_RGB_DITHER_NORMAL,
375 + 0, 0);
377 + g_object_unref (pixbuf);
379 diff --git a/libmuine/rb-cell-renderer-pixbuf.h b/libmuine/rb-cell-renderer-pixbuf.h
380 new file mode 100644
381 index 0000000..6d42fce
382 --- a/dev/null
383 +++ b/libmuine/rb-cell-renderer-pixbuf.h
384 @@ -0,0 +1,62 @@
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.
406 + */
408 +#ifndef __RB_CELL_RENDERER_PIXBUF_H__
409 +#define __RB_CELL_RENDERER_PIXBUF_H__
411 +#include <gtk/gtk.h>
413 +#ifdef __cplusplus
414 +extern "C" {
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;
431 + GdkPixbuf *pixbuf;
434 +struct _RBCellRendererPixbufClass
436 + GtkCellRendererClass parent_class;
439 +GType rb_cell_renderer_pixbuf_get_type (void);
440 +GtkCellRenderer *rb_cell_renderer_pixbuf_new (void);
442 +#ifdef __cplusplus
444 +#endif /* __cplusplus */
446 +#endif /* __RB_CELL_RENDERER_PIXBUF_H__ */
447 diff --git a/src/ColoredCellRendererPixbuf.cs b/src/ColoredCellRendererPixbuf.cs
448 new file mode 100644
449 index 0000000..72c92a5
450 --- a/dev/null
451 +++ b/src/ColoredCellRendererPixbuf.cs
452 @@ -0,0 +1,64 @@
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.
470 + */
472 +using System;
473 +using System.Runtime.InteropServices;
475 +namespace Muine
477 + /// <summary>
478 + /// </summary>
479 + /// <remarks>
480 + /// This renderer is similar to <see cref="Gtk.CellRendererPixbuf" />.
481 + /// </remarks>
482 + public class ColoredCellRendererPixbuf : Gtk.CellRenderer
484 + // Constructor
485 + [DllImport ("libmuine")]
486 + private static extern IntPtr rb_cell_renderer_pixbuf_new ();
488 + /// <summary>
489 + /// Create a new <see cref="ColoredCellRendererPixbuf" />
490 + /// object.
491 + /// </summary>
492 + public ColoredCellRendererPixbuf () : base (IntPtr.Zero)
494 + base.Raw = rb_cell_renderer_pixbuf_new ();
495 + System.Console.WriteLine("hi");
498 + // Destructor
499 + ~ColoredCellRendererPixbuf ()
501 + Dispose ();
504 + // Properties
505 + // Properties :: Pixbuf (set;)
506 + /// <summary>
507 + /// The <see cref="Gdk.Pixbuf" /> to be used.
508 + /// </summary>
509 + /// <param name="value">
510 + /// A <see cref="Gdk.Pixbuf" />.
511 + /// </param>
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;
553 + */
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,
560 TreeIter iter)
562 + /*
563 Gtk.CellRendererPixbuf r = (Gtk.CellRendererPixbuf) cell;
564 + */
565 + ColoredCellRendererPixbuf r = (ColoredCellRendererPixbuf) cell;
567 IntPtr handle = playlist.Model.HandleFromIter (iter);
569 if (handle == playlist.Model.Playing) {
571 cgit v0.9.0.2