2 /* Gnome Music Player Client (GMPC)
3 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
4 * Project homepage: http://gmpclient.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 private const bool use_transition_sbv
= Gmpc
.use_transition
;
27 private const string some_unique_name_sbv
= Config
.VERSION
;
29 public class MyCellRenderer
: Gtk
.CellRenderer
31 private CellRendererPixbuf cr_pb
= new Gtk
.CellRendererPixbuf();
32 private CellRendererText cr_text
= new Gtk
.CellRendererText();
33 public string icon_name
36 cr_pb
.icon_name
= value
;
39 public string stock_id
42 cr_pb
.stock_id
= value
;
46 public int weight
{ set { cr_text
.weight
= value
;}}
47 public bool weight_set
{ set { cr_text
.weight_set
= value
;}}
49 public uint stock_size
52 return cr_pb
.stock_size
;
55 cr_pb
.stock_size
= value
;
65 private bool _show_text
= true;
75 public int image_width
81 public new
float xalign
87 /* dumb constructor */
88 public MyCellRenderer () {}
90 public override Gtk
.SizeRequestMode
get_request_mode()
92 return Gtk
.SizeRequestMode
.CONSTANT_SIZE
;
95 public override void get_preferred_width(Gtk
.Widget widget
,
101 cr_pb
.get_preferred_width(widget
, out ms
, out ns
);
105 cr_text
.get_preferred_width(widget
, out tms
, out tns
);
109 if(&min_size
!= null) min_size
= ms
;
110 if(&nat_size
!= null) nat_size
= ns
;
111 stdout
.printf("get preferred width: %d %d\n", ms
, ns
);
114 /* get_size method, always request a 50x50 area */
115 public override void get_size (Gtk
.Widget widget
,
116 Gdk
.Rectangle? cell_area
,
130 stdout
.printf("get size\n");
132 cr_pb
.get_size(widget
, null, out x_o
, out y_o
, out w
, out h
);
134 cr_text
.get_size(widget
, null, out tx_o
, out ty_o
, out tw
, out th
);
135 /* The bindings miss the nullable property, so we need to check if the
138 if (&x_offset
!= null) x_offset
= 0;
139 if (&y_offset
!= null) y_offset
= 0;
140 if (&width
!= null) width
= image_width
+6+tw
;
141 if (&height
!= null) height
= int.max(h
, th
);
146 public override void render (Cairo
.Context ct
,
148 Gdk
.Rectangle background_area
,
149 Gdk
.Rectangle cell_area
,
150 Gtk
.CellRendererState flags
)
156 cr_pb
.get_size(widget
, null, out x_o
, out y_o
, out w
, out h
);
157 Gdk
.Rectangle ca
= Gdk
.Rectangle();
160 ca
.width
= w
+6;//cell_area.height;
161 ca
.height
= cell_area
.height
;
163 if(cr_pb
.icon_name
!= null || cr_pb
.stock_id
!= null )
165 cr_pb
.render(ct
, widget
, background_area
, ca
, flags
);
168 ca
.width
= cell_area
.width
-ca
.width
;
172 ca
.width
= cell_area
.width
;
175 cr_text
.render(ct
, widget
, background_area
, ca
, flags
);
179 if((flags&Gtk.CellRendererState.SELECTED) == Gtk.CellRendererState.SELECTED)
181 double cax = background_area.width*0.9;
182 double bld = background_area.width*0.1;
183 if(!show_text) cax = background_area.x+image_width+3;
185 ct.move_to(background_area.x+cax, background_area.y);
186 ct.line_to(background_area.x+cax+bld, background_area.y+background_area.height/2);
187 ct.line_to(background_area.x+cax, background_area.y+background_area.height);
188 ct.line_to(background_area.x+cax+bld, background_area.y+background_area.height);
189 ct.line_to(background_area.x+cax+bld, background_area.y);
190 ct.line_to(background_area.x+cax, background_area.y);
191 Gdk.cairo_set_source_color(ct, widget.style.bg[Gtk.StateType.NORMAL]);