~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageBarButton.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// WelcomePageBarButton.cs
 
3
//
 
4
// Author:
 
5
//       lluis <${AuthorEmail}>
 
6
//
 
7
// Copyright (c) 2012 lluis
 
8
//
 
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:
 
15
//
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
//
 
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
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using Gtk;
 
28
using MonoDevelop.Core;
 
29
using System.Xml.Linq;
 
30
 
 
31
namespace MonoDevelop.Ide.WelcomePage
 
32
{
 
33
        public class WelcomePageBarButton: EventBox
 
34
        {
 
35
                Gtk.Image image;
 
36
                Gtk.Label label;
 
37
 
 
38
                Gdk.Pixbuf imageNormal, imageHover;
 
39
                bool mouseOver;
 
40
                string actionLink;
 
41
                private static Gdk.Cursor hand_cursor = new Gdk.Cursor(Gdk.CursorType.Hand1);
 
42
 
 
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; }
 
49
 
 
50
                public WelcomePageBarButton (string title, string href, string iconResource = null)
 
51
                {
 
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;
 
56
 
 
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);
 
63
                        }
 
64
 
 
65
                        HBox box = new HBox ();
 
66
                        box.Spacing = Styles.WelcomeScreen.Links.IconTextSpacing;
 
67
                        image = new Image ();
 
68
                        label = new Label ();
 
69
                        box.PackStart (image, false, false, 0);
 
70
                        if (imageNormal == null)
 
71
                                image.NoShowAll = true;
 
72
                        box.PackStart (label, false, false, 0);
 
73
                        box.ShowAll ();
 
74
                        Add (box);
 
75
 
 
76
                        Update ();
 
77
 
 
78
                        Events |= (Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask | Gdk.EventMask.ButtonReleaseMask);
 
79
                }
 
80
 
 
81
                protected void SetImage (Gdk.Pixbuf normal, Gdk.Pixbuf hover)
 
82
                {
 
83
                        imageHover = hover;
 
84
                        imageNormal = normal;
 
85
 
 
86
                        if (imageNormal == null) {
 
87
                                image.NoShowAll = true;
 
88
                                image.Hide ();
 
89
                        } else {
 
90
                                image.NoShowAll = false;
 
91
                                ShowAll ();
 
92
                        }
 
93
 
 
94
                        Update ();
 
95
                }
 
96
 
 
97
                protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
 
98
                {
 
99
                        GdkWindow.Cursor = hand_cursor;
 
100
                        mouseOver = true;
 
101
                        Update ();
 
102
                        return base.OnEnterNotifyEvent (evnt);
 
103
                }
 
104
                
 
105
                protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
 
106
                {
 
107
                        GdkWindow.Cursor = null;
 
108
                        mouseOver = false;
 
109
                        Update ();
 
110
                        return base.OnLeaveNotifyEvent (evnt);
 
111
                }
 
112
 
 
113
                protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
 
114
                {
 
115
                        if (evnt.Button == 1 && new Gdk.Rectangle (0, 0, Allocation.Width, Allocation.Height).Contains ((int)evnt.X, (int)evnt.Y)) {
 
116
                                OnClicked ();
 
117
                                return true;
 
118
                        }
 
119
                        return base.OnButtonReleaseEvent (evnt);
 
120
                }
 
121
 
 
122
                protected virtual void OnClicked ()
 
123
                {
 
124
                        WelcomePageSection.DispatchLink (actionLink);
 
125
                }
 
126
 
 
127
                protected void Update ()
 
128
                {
 
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);
 
133
                }
 
134
        }
 
135
}
 
136