3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this source distribution.
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 3 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
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
29
namespace Do.Interface.Widgets
31
public class IconBox : Frame
33
const string CaptionFormat = "{0}";
34
const string HighlightFormat = "<span weight=\"bold\" underline=\"single\">{0}</span>";
36
protected bool focused, textOverlay;
38
protected string caption, icon_name, highlight;
39
protected Pixbuf empty_pixbuf;
40
protected int icon_size;
43
protected Gtk.Image image;
44
protected Label label;
45
protected Gdk.Pixbuf overlay_pixbuf;
47
protected float focused_fill_transparency = 0.4f;
48
protected float unfocused_fill_transparency = 0.1f;
49
protected float focused_frame_transparency = 0.3f;
50
protected float unfocused_frame_transparency = 0.075f;
52
public IconBox (int icon_size) : base ()
54
this.icon_size = icon_size;
55
overlay_pixbuf = IconProvider.PixbufFromIconName ("gnome-mime-text", icon_size);
59
protected virtual void Build ()
61
Alignment label_align;
66
vbox = new VBox (false, 4);
72
empty_pixbuf = new Pixbuf (Colorspace.Rgb, true, 8, icon_size, icon_size);
73
empty_pixbuf.Fill (uint.MinValue);
75
image = new Gtk.Image ();
76
vbox.PackStart (image, false, false, 0);
80
label.Ellipsize = Pango.EllipsizeMode.End;
81
label.ModifyFg (StateType.Normal, Style.White);
82
label_align = new Alignment (1.0F, 0.0F, 0, 0);
83
label_align.SetPadding (0, 2, 2, 2);
84
label_align.Add (label);
85
vbox.PackStart (label_align, false, false, 0);
89
image.SetSizeRequest (icon_size, icon_size);
90
label.SetSizeRequest (icon_size / 4 * 5, -1);
91
// SetSizeRequest (icon_size * 2, icon_size * 2);
93
DrawFrame = DrawFill = true;
94
FrameColor = FillColor = new Color (byte.MaxValue, byte.MaxValue, byte.MaxValue);
96
Realized += OnRealized;
100
public virtual void Clear ()
109
protected virtual void OnRealized (object o, EventArgs args)
114
public bool IsFocused
116
get { return focused; }
118
if (focused == value) return;
124
public virtual bool TextOverlay
126
get { return textOverlay; }
128
if (textOverlay == value)
133
FillAlpha = focused_fill_transparency;
134
FrameAlpha = focused_frame_transparency;
135
FillColor = FrameColor = new Color (0x00, 0x00, 0x00);
137
label.Ellipsize = Pango.EllipsizeMode.None;
138
label.LineWrapMode = Pango.WrapMode.WordChar;
139
label.LineWrap = true;
142
FillColor = FrameColor = new Color (0xff, 0xff, 0xff);
145
label.Ellipsize = Pango.EllipsizeMode.End;
150
public string Caption
152
get { return caption; }
154
caption = GLib.Markup.EscapeText (value ?? "");
155
caption = caption.Replace ("\n", " ");
160
private void UpdateLabel ()
162
int lines = label.Layout.LineCount;
163
label.Markup = string.Format (CaptionFormat,
164
Util.FormatCommonSubstrings (caption, highlight, HighlightFormat));
165
if (lines != label.Layout.LineCount && LinesChanged != null)
166
LinesChanged (label.Layout.LineCount, new EventArgs ());
175
if (value == null || textOverlay) return;
177
using (Gdk.Pixbuf pix = IconProvider.PixbufFromIconName (value, icon_size)) {
186
image.Pixbuf = value ?? empty_pixbuf;
190
public Do.Universe.Item DisplayObject
201
if (name == Caption && icon == this.Icon)
210
public string Highlight
213
highlight = value ?? "";
218
protected virtual void UpdateFocus ()
220
FillAlpha = focused ? focused_fill_transparency : unfocused_fill_transparency;
221
FrameAlpha = focused ? focused_frame_transparency : unfocused_frame_transparency;
224
protected override void PaintFill ()
230
// Gtk doesn't allow stacking elements, so we can't use a standard GTK interface here
231
// To work around this we will instead draw our own icon and gtk will be none the wiser.
232
// We are very clever.
236
r = (double) fillColor.Red / ushort.MaxValue;
237
g = (double) fillColor.Green / ushort.MaxValue;
238
b = (double) fillColor.Blue / ushort.MaxValue;
243
Gdk.CairoHelper.SetSourcePixbuf (cairo,
245
(int) (width / 2) - (int) (overlay_pixbuf.Width / 2) + x,
246
(int) (height / 2) - (int) (overlay_pixbuf.Height / 2) + y);
247
cairo.PaintWithAlpha (fillAlpha);
249
cairo.Color = new Cairo.Color (r, g, b, fillAlpha);
250
cairo.FillPreserve ();
255
public event EventHandler LinesChanged;