44
47
namespace MonoDevelop.Ide.WelcomePage
46
class WelcomePageWidget : Gtk.EventBox
49
public class WelcomePageWidget : Gtk.EventBox
48
Gdk.Pixbuf bgPixbuf, logoPixbuf;
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; }
57
protected double OverdrawOpacity {
58
get { return Background.OverdrawOpacity; }
59
set { Background.OverdrawOpacity = value; }
62
protected int OverdrawOffset {
63
get { return Background.OverdrawOffset; }
64
set { Background.OverdrawOffset = value; }
67
WelcomePageWidgetBackground Background { get; set; }
69
public bool ShowScrollbars { get; set; }
51
71
public WelcomePageWidget ()
53
logoPixbuf = WelcomePageBranding.GetLogoImage ();
54
bgPixbuf = WelcomePageBranding.GetTopBorderImage ();
56
Gdk.Color color = Gdk.Color.Zero;
57
if (!Gdk.Color.Parse (WelcomePageBranding.BackgroundColor, ref color))
59
ModifyBg (StateType.Normal, color);
73
ShowScrollbars = true;
74
VisibleWindow = false;
76
BackgroundColor = "white";
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);
65
colBox = new Gtk.HBox (false, WelcomePageBranding.Spacing);
66
mainAlignment.Add (colBox);
83
background.Add (mainAlignment);
85
BuildContent (mainAlignment);
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 };
96
this.Add (background);
98
if (LogoImage != null) {
99
var logoHeight = LogoHeight;
100
mainAlignment.SetPadding ((uint)(logoHeight + Styles.WelcomeScreen.Spacing), 0, (uint)Styles.WelcomeScreen.Spacing, 0);
72
105
IdeApp.Workbench.GuiLocked += OnLock;
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;
99
colBox.PackStart (colWidget, false, false, 0);
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);
107
switch (el.Name.LocalName) {
109
w = new WelcomePageLinksList (el);
111
case "RecentProjects":
112
w = new WelcomePageRecentProjectsList (el);
115
w = new WelcomePageNewsFeed (el);
118
throw new InvalidOperationException ("Unknown welcome page element '" + el.Name + "'");
121
AddSection (colWidget, title, w);
126
static readonly string headerFormat =
127
"<span size=\"" + WelcomePageBranding.HeaderTextSize + "\" foreground=\""
128
+ WelcomePageBranding.HeaderTextColor + "\">{0}</span>";
130
void AddSection (VBox col, string title, Widget w)
132
var a = new Alignment (0f, 0f, 1f, 1f);
135
if (string.IsNullOrEmpty (title)) {
136
col.PackStart (a, false, false, 0);
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);
147
protected override bool OnExposeEvent (EventExpose evnt)
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);
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);
162
foreach (Widget widget in Children)
163
PropagateExpose (widget, evnt);
119
protected virtual void BuildContent (Container parent)
168
124
protected override void OnDestroyed ()
171
127
IdeApp.Workbench.GuiLocked -= OnLock;
172
128
IdeApp.Workbench.GuiUnlocked -= OnUnlock;
131
public class WelcomePageWidgetBackground : Gtk.EventBox
133
public WelcomePageWidget Owner { get; set; }
135
public double OverdrawOpacity { get; set; }
136
public int OverdrawOffset { get; set; }
138
protected override void OnRealized ()
140
Gdk.Color color = Gdk.Color.Zero;
141
if (!Gdk.Color.Parse (Owner.BackgroundColor, ref color))
143
ModifyBg (StateType.Normal, color);
148
void DrawOverdraw (Cairo.Context context, double opacity)
150
if (Owner.BackgroundImage == null)
153
context.RenderTiled (Owner.BackgroundImage, Allocation, new Gdk.Rectangle (Allocation.X, Allocation.Y + OverdrawOffset, Allocation.Width, Allocation.Height - OverdrawOffset), opacity);
156
void DrawBackground (Cairo.Context context, Gdk.Rectangle area)
158
if (Owner.BackgroundImage == null)
161
context.RenderTiled (Owner.BackgroundImage, Allocation, Allocation, 1);
164
protected override bool OnExposeEvent (EventExpose evnt)
166
using (var context = Gdk.CairoHelper.Create (evnt.Window)) {
167
context.Color = new Cairo.Color (1, 1, 1);
168
context.Operator = Cairo.Operator.Source;
170
context.Operator = Cairo.Operator.Over;
171
DrawBackground (context, evnt.Area);
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);
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);
186
foreach (Widget widget in Children)
187
PropagateExpose (widget, evnt);
189
if (OverdrawOpacity > 0) {
190
using (var context = Gdk.CairoHelper.Create (evnt.Window)) {
191
DrawOverdraw (context, OverdrawOpacity);
b'\\ No newline at end of file'