2
// WelcomePageBarButton.cs
5
// lluis <${AuthorEmail}>
7
// Copyright (c) 2012 lluis
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using MonoDevelop.Core;
29
using System.Xml.Linq;
31
namespace MonoDevelop.Ide.WelcomePage
33
public class WelcomePageBarButton: EventBox
38
Gdk.Pixbuf imageNormal, imageHover;
41
private static Gdk.Cursor hand_cursor = new Gdk.Cursor(Gdk.CursorType.Hand1);
43
public string FontFamily { get; set; }
44
public string HoverColor { get; set; }
45
public string Color { get; set; }
46
public int FontSize { get; set; }
47
protected string Text { get; set; }
48
protected bool Bold { get; set; }
50
public WelcomePageBarButton (string title, string href, string iconResource = null)
52
FontFamily = Platform.IsMac ? Styles.WelcomeScreen.FontFamilyMac : Styles.WelcomeScreen.FontFamilyWindows;
53
HoverColor = Styles.WelcomeScreen.Links.HoverColor;
54
Color = Styles.WelcomeScreen.Links.Color;
55
FontSize = Styles.WelcomeScreen.Links.FontSize;
57
VisibleWindow = false;
58
this.Text = GettextCatalog.GetString (title);
59
this.actionLink = href;
60
if (!string.IsNullOrEmpty (iconResource)) {
61
imageHover = Gdk.Pixbuf.LoadFromResource (iconResource);
62
imageNormal = ImageService.MakeTransparent (imageHover, 0.7);
65
HBox box = new HBox ();
66
box.Spacing = Styles.WelcomeScreen.Links.IconTextSpacing;
69
box.PackStart (image, false, false, 0);
70
if (imageNormal == null)
71
image.NoShowAll = true;
72
box.PackStart (label, false, false, 0);
78
Events |= (Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask | Gdk.EventMask.ButtonReleaseMask);
81
protected void SetImage (Gdk.Pixbuf normal, Gdk.Pixbuf hover)
86
if (imageNormal == null) {
87
image.NoShowAll = true;
90
image.NoShowAll = false;
97
protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
99
GdkWindow.Cursor = hand_cursor;
102
return base.OnEnterNotifyEvent (evnt);
105
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
107
GdkWindow.Cursor = null;
110
return base.OnLeaveNotifyEvent (evnt);
113
protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
115
if (evnt.Button == 1 && new Gdk.Rectangle (0, 0, Allocation.Width, Allocation.Height).Contains ((int)evnt.X, (int)evnt.Y)) {
119
return base.OnButtonReleaseEvent (evnt);
122
protected virtual void OnClicked ()
124
WelcomePageSection.DispatchLink (actionLink);
127
protected void Update ()
129
if (imageNormal != null)
130
image.Pixbuf = mouseOver ? imageHover : imageNormal;
131
var color = mouseOver ? HoverColor : Color;
132
label.Markup = WelcomePageSection.FormatText (FontFamily, FontSize, Bold, color, Text);