1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| public class Gtk.CellRendererButton : Gtk.CellRenderer
{
private const int BUTTON_WIDTH = 13;
public signal void clicked ();
public Gtk.Button button
{
get;
construct;
}
private int indicator_size
{
get;
set;
default = BUTTON_WIDTH;
}
public bool inconsistent
{
get;
set;
default = false;
}
public bool activatable
{
get;
set;
default = true;
}
public string label
{
get
{
return this.button.label;
}
set
{
this.button.label = value;
}
}
construct
{
this.button = new Gtk.Button ();
}
public override void get_size (Gtk.Widget widget,
Gdk.Rectangle? cell_area,
out int x_offset, out int y_offset,
out int width, out int height)
{
int calc_width;
int calc_height;
calc_width = (int)(this.xpad * 2 + this.indicator_size);
calc_height = (int)(this.ypad * 2 + this.indicator_size);
if (&width != null)
{
width = calc_width;
}
if (&height != null)
{
height = calc_height;
}
if (cell_area != null)
{
if (&x_offset != null)
{
x_offset = (int)((widget.get_direction () == Gtk.TextDirection.RTL) ?
(1.0 - this.xalign) : this.xalign) * (cell_area.width - calc_width);
x_offset = int.max (x_offset, 0);
}
if (&y_offset != null)
{
y_offset = (int)(this.yalign * (cell_area.height - calc_height));
y_offset = int.max (y_offset, 0);
}
}
}
public override bool activate (Gdk.Event event, Gtk.Widget widget,
string path, Gdk.Rectangle background_area,
Gdk.Rectangle cell_area,
Gtk.CellRendererState flags)
{
this.clicked ();
return true;
}
public override void render (Gdk.Window window, Gtk.Widget widget,
Gdk.Rectangle background_area,
Gdk.Rectangle cell_area,
Gdk.Rectangle expose_area,
Gtk.CellRendererState flags)
{
int width, height;
int x_offset, y_offset;
Gtk.ShadowType shadow;
Gtk.StateType state = 0;
this.get_size (widget, cell_area, out x_offset, out y_offset,
out width, out height);
width -= (int)this.xpad * 2;
height -= (int)this.ypad * 2;
if (width > 0 && height > 0)
{
shadow = Gtk.ShadowType.IN;
if (!this.sensitive)
{
state = Gtk.StateType.INSENSITIVE;
}
else if ((flags & Gtk.CellRendererState.SELECTED) == Gtk.CellRendererState.SELECTED)
{
if (widget.has_focus)
{
state = Gtk.StateType.SELECTED;
}
else
{
state = Gtk.StateType.ACTIVE;
}
}
else
{
if (this.activatable)
{
state = Gtk.StateType.NORMAL;
}
else
{
state = Gtk.StateType.INSENSITIVE;
}
}
Gtk._button_paint (this.button, cell_area, state, shadow, "button", "defaultbutton");
}
}
} |
Partager