1
// AbstractMenuButtonArgs.cs
3
// Copyright (C) 2008 GNOME Do
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
27
using Docky.Utilities;
30
using Do.Interface.CairoUtils;
33
namespace Docky.Interface.Menus
35
public abstract class AbstractMenuButtonArgs : AbstractMenuArgs
37
const string FormatString = "{0}";
38
const int WidthBuffer = 4;
39
const int Height = 22;
44
public bool Dark { get; set; }
46
public virtual double IconOpacity {
50
public override Gtk.Widget Widget {
53
widget = BuildWidget ();
58
protected virtual string Description { get; set; }
60
protected virtual string Icon { get; set; }
62
protected virtual bool UseTooltip { get; set; }
64
public AbstractMenuButtonArgs ()
69
public AbstractMenuButtonArgs (string description, string icon)
71
Description = GLib.Markup.EscapeText (Catalog.GetString (description));
77
DrawingArea button = new DrawingArea ();
79
button.ExposeEvent += HandleExposeEvent;
80
button.EnterNotifyEvent += HandleEnterNotifyEvent;
81
button.LeaveNotifyEvent += HandleLeaveNotifyEvent;
82
button.ButtonReleaseEvent += HandleButtonReleaseEvent;
84
button.AddEvents ((int) (EventMask.EnterNotifyMask | EventMask.LeaveNotifyMask | EventMask.ButtonReleaseMask));
85
button.HeightRequest = Height;
87
button.SetCompositeColormap ();
89
button.TooltipText = Description;
94
void HandleButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
100
void HandleLeaveNotifyEvent(object o, LeaveNotifyEventArgs args)
102
(o as Widget).QueueDraw ();
106
void HandleEnterNotifyEvent(object o, EnterNotifyEventArgs args)
108
(o as Widget).QueueDraw ();
112
void HandleExposeEvent(object o, ExposeEventArgs args)
114
using (Context cr = CairoHelper.Create (args.Event.Window)) {
115
Gdk.Rectangle area = args.Event.Area;
117
LinearGradient lg = new LinearGradient (area.X, area.Y, area.X, area.Y + area.Height);
119
Cairo.Color background = (Dark) ? DockPopupMenu.BackgroundColor.ShadeColor (.7) : DockPopupMenu.BackgroundColor;
121
Cairo.Color high = background
123
.SetMinimumValue (25)
124
.ConvertToCairo (background.A);
126
lg.AddColorStop (0, high);
127
lg.AddColorStop (1, background);
129
lg.AddColorStop (0, background);
130
lg.AddColorStop (1, background);
136
int width = area.Width - WidthBuffer * 2 - 25;
138
TextRenderContext renderContext = new TextRenderContext (cr, string.Format (FormatString, Description), width);
140
renderContext.LeftCenteredPoint = new Gdk.Point (area.X + WidthBuffer + 25, area.Y + area.Height / 2);
141
renderContext.Alignment = Pango.Alignment.Left;
142
renderContext.EllipsizeMode = Pango.EllipsizeMode.End;
144
DockServices.DrawingService.TextPathAtPoint (renderContext);
146
cr.Color = new Cairo.Color (1, 1, 1);
149
Gdk.Pixbuf pbuf = GetPixbuf (Height - 8);
150
CairoHelper.SetSourcePixbuf (cr, pbuf, WidthBuffer, (Height - pbuf.Height) / 2);
151
cr.PaintWithAlpha (IconOpacity);
156
protected virtual Gdk.Pixbuf GetPixbuf (int size)
158
return IconProvider.PixbufFromIconName (Icon, size);
161
public abstract void Action ();
163
public AbstractMenuButtonArgs AsDark ()
169
public override void Dispose ()