5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
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
29
namespace MonoDevelop.Components
31
public class HeaderBox: Bin
48
public HeaderBox (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
50
SetMargins (topMargin, bottomMargin, leftMargin, rightMargin);
53
public void SetMargins (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
55
this.topMargin = topMargin;
56
this.bottomMargin = bottomMargin;
57
this.leftMargin = leftMargin;
58
this.rightMargin = rightMargin;
61
public void SetPadding (int topPadding, int bottomPadding, int leftPadding, int rightPadding)
63
this.topPadding = topPadding;
64
this.bottomPadding = bottomPadding;
65
this.leftPadding = leftPadding;
66
this.rightPadding = rightPadding;
69
public bool GradientBackround { get; set; }
71
protected override void OnAdded (Widget widget)
73
base.OnAdded (widget);
77
protected override void OnSizeRequested (ref Requisition requisition)
80
requisition = child.SizeRequest ();
81
requisition.Width += leftMargin + rightMargin + leftPadding + rightPadding;
82
requisition.Height += topMargin + bottomMargin + topPadding + bottomPadding;
84
requisition.Width = 0;
85
requisition.Height = 0;
89
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
91
base.OnSizeAllocated (allocation);
92
if (allocation.Width > leftMargin + rightMargin + leftPadding + rightPadding) {
93
allocation.X += leftMargin + leftPadding;
94
allocation.Width -= leftMargin + rightMargin + leftPadding + rightPadding;
96
if (allocation.Height > topMargin + bottomMargin + topPadding + bottomPadding) {
97
allocation.Y += topMargin + topPadding;
98
allocation.Height -= topMargin + bottomMargin + topPadding + bottomPadding;
101
child.SizeAllocate (allocation);
104
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
108
if (GradientBackround) {
109
rect = new Gdk.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
110
HslColor gcol = Style.Background (Gtk.StateType.Normal);
112
using (Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow)) {
114
cr.MoveTo (rect.X, rect.Y);
115
cr.RelLineTo (rect.Width, 0);
116
cr.RelLineTo (0, rect.Height);
117
cr.RelLineTo (-rect.Width, 0);
118
cr.RelLineTo (0, -rect.Height);
120
Cairo.Gradient pat = new Cairo.LinearGradient (rect.X, rect.Y, rect.X, rect.Bottom);
121
Cairo.Color color1 = gcol;
122
pat.AddColorStop (0, color1);
124
if (gcol.L < 0) gcol.L = 0;
125
pat.AddColorStop (1, gcol);
131
bool res = base.OnExposeEvent (evnt);
133
Gdk.GC borderColor = Style.DarkGC (Gtk.StateType.Normal);
136
for (int n=0; n<topMargin; n++)
137
GdkWindow.DrawLine (borderColor, rect.X, rect.Y + n, rect.Right - 1, rect.Y + n);
139
for (int n=0; n<bottomMargin; n++)
140
GdkWindow.DrawLine (borderColor, rect.X, rect.Bottom - n - 1, rect.Right - 1, rect.Bottom - n - 1);
142
for (int n=0; n<leftMargin; n++)
143
GdkWindow.DrawLine (borderColor, rect.X + n, rect.Y, rect.X + n, rect.Bottom - 1);
145
for (int n=0; n<rightMargin; n++)
146
GdkWindow.DrawLine (borderColor, rect.Right - n - 1, rect.Y, rect.Right - n - 1, rect.Bottom - 1);