2
// Copyright (C) 2009 Jason Smith, Robert Dyer, Chris Szikszoy
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
23
using System.Text.RegularExpressions;
32
using Docky.CairoHelper;
36
public abstract class IconDockItem : AbstractDockItem
38
public event EventHandler IconUpdated;
43
get { return string.IsNullOrEmpty (remote_icon) ? icon : remote_icon; }
45
// if we set this, clear the forced pixbuf
46
if (forced_pixbuf != null)
52
using (Gtk.IconInfo info = Gtk.IconTheme.Default.LookupIcon (icon, 48, Gtk.IconLookupFlags.ForceSvg)) {
53
if (info != null && info.Filename != null && info.Filename.EndsWith (".svg")) {
55
ScalableRendering = true;
57
ScalableRendering = false;
67
protected Pixbuf ForcePixbuf {
68
get { return forced_pixbuf; }
70
if (forced_pixbuf == value)
72
forced_pixbuf = value;
77
List<IconEmblem> Emblems;
79
protected void SetIconFromGIcon (GLib.Icon gIcon)
81
Icon = DockServices.Drawing.IconFromGIcon (gIcon);
84
protected void SetIconFromPixbuf (Pixbuf pbuf)
89
public IconDockItem ()
91
Emblems = new List<IconEmblem> ();
95
public void AddEmblem (IconEmblem emblem)
97
// remove current emblems at this position
98
if (Emblems.Any (e => e.Position == emblem.Position))
99
Emblems.RemoveAll (e => e.Position == emblem.Position);
100
// add the new emblem
101
Emblems.Add (emblem);
103
emblem.Changed += delegate {
108
public void RemoveEmblem (IconEmblem emblem)
110
if (Emblems.Contains (emblem)) {
111
Emblems.Remove (emblem);
116
public void SetRemoteIcon (string icon)
124
protected override void PaintIconSurface (DockySurface surface)
128
if (forced_pixbuf == null)
129
pbuf = DockServices.Drawing.LoadIcon (Icon, surface.Width, surface.Height);
131
pbuf = DockServices.Drawing.ARScale (surface.Width, surface.Height, forced_pixbuf.Copy ());
133
pbuf = ProcessPixbuf (pbuf);
135
Gdk.CairoHelper.SetSourcePixbuf (surface.Context,
137
(surface.Width - pbuf.Width) / 2,
138
(surface.Height - pbuf.Height) / 2);
139
surface.Context.Paint ();
142
foreach (IconEmblem emblem in Emblems) {
143
Pixbuf p = emblem.GetPixbuf (surface.Width, surface.Height);
145
switch (emblem.Position) {
147
x = surface.Width - p.Width;
151
x = surface.Width - p.Width;
152
y = surface.Height - p.Height;
156
y = surface.Height - p.Height;
162
Gdk.CairoHelper.SetSourcePixbuf (surface.Context, p, x, y);
163
surface.Context.Paint ();
170
PostProcessIconSurface (surface);
171
} catch (Exception e) {
172
Log<IconDockItem>.Error (e.Message);
173
Log<IconDockItem>.Debug (e.StackTrace);
177
protected virtual Gdk.Pixbuf ProcessPixbuf (Gdk.Pixbuf pbuf)
182
protected virtual void PostProcessIconSurface (DockySurface surface)
186
protected void OnIconUpdated ()
188
if (IconUpdated != null)
189
IconUpdated (this, EventArgs.Empty);