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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageWidget.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:
29
29
//
30
30
 
31
31
using System;
 
32
using System.Collections.Generic;
32
33
using System.IO;
33
34
using System.Xml;
 
35
using System.Linq;
34
36
using Gdk;
35
37
using Gtk;
36
38
using Mono.Addins;
37
39
using MonoDevelop.Core;
 
40
using MonoDevelop.Components;
38
41
using MonoDevelop.Ide;
39
42
using MonoDevelop.Projects;
40
43
using MonoDevelop.Ide.Desktop;
43
46
 
44
47
namespace MonoDevelop.Ide.WelcomePage
45
48
{
46
 
        class WelcomePageWidget : Gtk.EventBox
 
49
        public class WelcomePageWidget : Gtk.EventBox
47
50
        {
48
 
                Gdk.Pixbuf bgPixbuf, logoPixbuf;
49
 
                Gtk.HBox colBox;
50
 
                
 
51
                public Gdk.Pixbuf LogoImage { get; set; }
 
52
                public int LogoHeight { get; set; }
 
53
                public Gdk.Pixbuf TopBorderImage { get; set; }
 
54
                public Gdk.Pixbuf BackgroundImage { get; set; }
 
55
                public string BackgroundColor { get; set; }
 
56
 
 
57
                protected double OverdrawOpacity {
 
58
                        get { return Background.OverdrawOpacity; }
 
59
                        set { Background.OverdrawOpacity = value; }
 
60
                }
 
61
 
 
62
                protected int OverdrawOffset {
 
63
                        get { return Background.OverdrawOffset; }
 
64
                        set { Background.OverdrawOffset = value; }
 
65
                }
 
66
 
 
67
                WelcomePageWidgetBackground Background { get; set; }
 
68
 
 
69
                public bool ShowScrollbars { get; set; }
 
70
 
51
71
                public WelcomePageWidget ()
52
72
                {
53
 
                        logoPixbuf = WelcomePageBranding.GetLogoImage ();
54
 
                        bgPixbuf = WelcomePageBranding.GetTopBorderImage ();
55
 
                        
56
 
                        Gdk.Color color = Gdk.Color.Zero;
57
 
                        if (!Gdk.Color.Parse (WelcomePageBranding.BackgroundColor, ref color))
58
 
                                color = Style.White;
59
 
                        ModifyBg (StateType.Normal, color);
60
 
                        
 
73
                        ShowScrollbars = true;
 
74
                        VisibleWindow = false;
 
75
 
 
76
                        BackgroundColor = "white";
 
77
                        LogoHeight = 90;
 
78
 
 
79
                        var background = new WelcomePageWidgetBackground ();
 
80
                        Background = background;
 
81
                        background.Owner = this;
61
82
                        var mainAlignment = new Gtk.Alignment (0f, 0f, 1f, 1f);
62
 
                        mainAlignment.SetPadding ((uint) (WelcomePageBranding.LogoHeight + WelcomePageBranding.Spacing), 0, (uint) WelcomePageBranding.Spacing, 0);
63
 
                        this.Add (mainAlignment);
64
 
                        
65
 
                        colBox = new Gtk.HBox (false, WelcomePageBranding.Spacing);
66
 
                        mainAlignment.Add (colBox);
67
 
                        
68
 
                        BuildContent ();
69
 
                        
 
83
                        background.Add (mainAlignment);
 
84
 
 
85
                        BuildContent (mainAlignment);
 
86
 
 
87
                        if (ShowScrollbars) {
 
88
                                var scroller = new ScrolledWindow ();
 
89
                                scroller.AddWithViewport (background);
 
90
                                ((Gtk.Viewport)scroller.Child).ShadowType = ShadowType.None;
 
91
                                scroller.ShadowType = ShadowType.None;
 
92
                                scroller.FocusChain = new Widget[] { background };
 
93
                                scroller.Show ();
 
94
                                Add (scroller);
 
95
                        } else
 
96
                                this.Add (background);
 
97
 
 
98
                        if (LogoImage != null) {
 
99
                                var logoHeight = LogoHeight;
 
100
                                mainAlignment.SetPadding ((uint)(logoHeight + Styles.WelcomeScreen.Spacing), 0, (uint)Styles.WelcomeScreen.Spacing, 0);
 
101
                        }
 
102
 
70
103
                        ShowAll ();
71
104
 
72
105
                        IdeApp.Workbench.GuiLocked += OnLock;
82
115
                {
83
116
                        Sensitive = true;
84
117
                }
85
 
                
86
 
                void BuildContent ()
87
 
                {
88
 
                        foreach (var col in WelcomePageBranding.Content.Root.Elements ("Column")) {
89
 
                                var colWidget = new Gtk.VBox (false, WelcomePageBranding.Spacing);
90
 
                                var widthAtt = col.Attribute ("minWidth");
91
 
                                if (widthAtt != null) {
92
 
                                        int width = (int) widthAtt;
93
 
                                        colWidget.SizeRequested += delegate (object o, SizeRequestedArgs args) {
94
 
                                                var req = args.Requisition;
95
 
                                                req.Width = Math.Max (req.Width, width);
96
 
                                                args.Requisition = req;
97
 
                                        };
98
 
                                }
99
 
                                colBox.PackStart (colWidget, false, false, 0);
100
 
                                
101
 
                                foreach (var el in col.Elements ()) {
102
 
                                        string title = (string) (el.Attribute ("title") ?? el.Attribute ("_title"));
103
 
                                        if (!string.IsNullOrEmpty (title))
104
 
                                                title = GettextCatalog.GetString (title);
105
 
                                        
106
 
                                        Widget w;
107
 
                                        switch (el.Name.LocalName) {
108
 
                                        case "Links":
109
 
                                                w = new WelcomePageLinksList (el);
110
 
                                                break;
111
 
                                        case "RecentProjects":
112
 
                                                w = new WelcomePageRecentProjectsList (el);
113
 
                                                break;
114
 
                                        case "NewsFeed":
115
 
                                                w = new WelcomePageNewsFeed (el);
116
 
                                                break;
117
 
                                        default:
118
 
                                                throw new InvalidOperationException ("Unknown welcome page element '" + el.Name + "'");
119
 
                                        }
120
 
                                        
121
 
                                        AddSection (colWidget, title, w);
122
 
                                }
123
 
                        }
124
 
                }
125
 
                
126
 
                static readonly string headerFormat =
127
 
                        "<span size=\"" + WelcomePageBranding.HeaderTextSize + "\" foreground=\""
128
 
                        + WelcomePageBranding.HeaderTextColor + "\">{0}</span>";
129
 
                
130
 
                void AddSection (VBox col, string title, Widget w)
131
 
                {
132
 
                        var a = new Alignment (0f, 0f, 1f, 1f);
133
 
                        a.Add (w);
134
 
                        
135
 
                        if (string.IsNullOrEmpty (title)) {
136
 
                                col.PackStart (a, false, false, 0);
137
 
                                return;
138
 
                        }
139
 
                        
140
 
                        var box = new VBox (false, 2);
141
 
                        var label = new Gtk.Label () { Markup = string.Format (headerFormat, title), Xalign = (uint) 0 };
142
 
                        box.PackStart (label, false, false, 0);
143
 
                        box.PackStart (a, false, false, 0);
144
 
                        col.PackStart (box, false, false, 0);
145
 
                }
146
 
                
147
 
                protected override bool OnExposeEvent (EventExpose evnt)
148
 
                {
149
 
                        //draw the background
150
 
                        if (logoPixbuf != null) {
151
 
                                var gc = Style.BackgroundGC (State);
152
 
                                var lRect = new Rectangle (Allocation.X, Allocation.Y, logoPixbuf.Width, logoPixbuf.Height);
153
 
                                if (evnt.Region.RectIn (lRect) != OverlapType.Out)
154
 
                                        evnt.Window.DrawPixbuf (gc, logoPixbuf, 0, 0, lRect.X, lRect.Y, lRect.Width, lRect.Height, RgbDither.None, 0, 0);
155
 
                                
156
 
                                var bgRect = new Rectangle (Allocation.X + logoPixbuf.Width, Allocation.Y, Allocation.Width - logoPixbuf.Width, bgPixbuf.Height);
157
 
                                if (evnt.Region.RectIn (bgRect) != OverlapType.Out)
158
 
                                        for (int x = bgRect.X; x < bgRect.Right; x += bgPixbuf.Width)
159
 
                                                evnt.Window.DrawPixbuf (gc, bgPixbuf, 0, 0, x, bgRect.Y, bgPixbuf.Width, bgRect.Height, RgbDither.None, 0, 0);
160
 
                        }
161
 
                        
162
 
                        foreach (Widget widget in Children)
163
 
                                PropagateExpose (widget, evnt);
164
 
                        
165
 
                        return true;
166
 
                }
 
118
 
 
119
                protected virtual void BuildContent (Container parent)
 
120
                {
 
121
                }
 
122
 
167
123
                
168
124
                protected override void OnDestroyed ()
169
125
                {
171
127
                        IdeApp.Workbench.GuiLocked -= OnLock;
172
128
                        IdeApp.Workbench.GuiUnlocked -= OnUnlock;
173
129
                }
 
130
 
 
131
                public class WelcomePageWidgetBackground : Gtk.EventBox
 
132
                {
 
133
                        public WelcomePageWidget Owner { get; set; }
 
134
 
 
135
                        public double OverdrawOpacity { get; set; }
 
136
                        public int OverdrawOffset { get; set; }
 
137
 
 
138
                        protected override void OnRealized ()
 
139
                        {
 
140
                                Gdk.Color color = Gdk.Color.Zero;
 
141
                                if (!Gdk.Color.Parse (Owner.BackgroundColor, ref color))
 
142
                                        color = Style.White;
 
143
                                ModifyBg (StateType.Normal, color);
 
144
 
 
145
                                base.OnRealized ();
 
146
                        }
 
147
 
 
148
                        void DrawOverdraw (Cairo.Context context, double opacity)
 
149
                        {
 
150
                                if (Owner.BackgroundImage == null)
 
151
                                        return;
 
152
 
 
153
                                context.RenderTiled (Owner.BackgroundImage, Allocation, new Gdk.Rectangle (Allocation.X, Allocation.Y + OverdrawOffset, Allocation.Width, Allocation.Height - OverdrawOffset), opacity);
 
154
                        }
 
155
 
 
156
                        void DrawBackground (Cairo.Context context, Gdk.Rectangle area)
 
157
                        {
 
158
                                if (Owner.BackgroundImage == null)
 
159
                                        return;
 
160
 
 
161
                                context.RenderTiled (Owner.BackgroundImage, Allocation, Allocation, 1);
 
162
                        }
 
163
 
 
164
                        protected override bool OnExposeEvent (EventExpose evnt)
 
165
                        {
 
166
                                using (var context = Gdk.CairoHelper.Create (evnt.Window)) {
 
167
                                        context.Color = new Cairo.Color (1, 1, 1);
 
168
                                        context.Operator = Cairo.Operator.Source;
 
169
                                        context.Paint ();
 
170
                                        context.Operator = Cairo.Operator.Over;
 
171
                                        DrawBackground (context, evnt.Area);
 
172
                                }
 
173
 
 
174
                                if (Owner.LogoImage != null) {
 
175
                                        var gc = Style.BackgroundGC (State);
 
176
                                        var lRect = new Rectangle (Allocation.X, Allocation.Y, Owner.LogoImage.Width, Owner.LogoImage.Height);
 
177
                                        if (evnt.Region.RectIn (lRect) != OverlapType.Out)
 
178
                                                evnt.Window.DrawPixbuf (gc, Owner.LogoImage, 0, 0, lRect.X, lRect.Y, lRect.Width, lRect.Height, RgbDither.None, 0, 0);
 
179
                                        
 
180
                                        var bgRect = new Rectangle (Allocation.X + Owner.LogoImage.Width, Allocation.Y, Allocation.Width - Owner.LogoImage.Width, Owner.TopBorderImage.Height);
 
181
                                        if (evnt.Region.RectIn (bgRect) != OverlapType.Out)
 
182
                                                for (int x = bgRect.X; x < bgRect.Right; x += Owner.TopBorderImage.Width)
 
183
                                                        evnt.Window.DrawPixbuf (gc, Owner.TopBorderImage, 0, 0, x, bgRect.Y, Owner.TopBorderImage.Width, bgRect.Height, RgbDither.None, 0, 0);
 
184
                                }
 
185
                                
 
186
                                foreach (Widget widget in Children)
 
187
                                        PropagateExpose (widget, evnt);
 
188
 
 
189
                                if (OverdrawOpacity > 0) {
 
190
                                        using (var context = Gdk.CairoHelper.Create (evnt.Window)) {
 
191
                                                DrawOverdraw (context, OverdrawOpacity);
 
192
                                        }
 
193
                                }
 
194
                                
 
195
                                return true;
 
196
                        }
 
197
                }
174
198
        }
175
 
}
 
 
b'\\ No newline at end of file'
 
199
}