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 Mono.Addins.Gui
45
Gdk.Color customColor;
51
public HeaderBox (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
53
SetMargins (topMargin, bottomMargin, leftMargin, rightMargin);
56
public void Replace (Gtk.Bin parent)
58
Gtk.Widget c = parent.Child;
64
public void SetMargins (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
66
this.topMargin = topMargin;
67
this.bottomMargin = bottomMargin;
68
this.leftMargin = leftMargin;
69
this.rightMargin = rightMargin;
72
public void SetPadding (int topPadding, int bottomPadding, int leftPadding, int rightPadding)
74
this.topPadding = topPadding;
75
this.bottomPadding = bottomPadding;
76
this.leftPadding = leftPadding;
77
this.rightPadding = rightPadding;
80
public bool GradientBackround { get; set; }
82
public Gdk.Color BackgroundColor {
83
get { return customColor; }
84
set { customColor = value; useCustomColor = true; }
87
public void ResetBackgroundColor ()
89
useCustomColor = false;
92
protected override void OnAdded (Widget widget)
94
base.OnAdded (widget);
98
protected override void OnSizeRequested (ref Requisition requisition)
101
requisition = child.SizeRequest ();
102
requisition.Width += leftMargin + rightMargin + leftPadding + rightPadding;
103
requisition.Height += topMargin + bottomMargin + topPadding + bottomPadding;
105
requisition.Width = 0;
106
requisition.Height = 0;
110
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
112
base.OnSizeAllocated (allocation);
113
if (allocation.Width > leftMargin + rightMargin + leftPadding + rightPadding) {
114
allocation.X += leftMargin + leftPadding;
115
allocation.Width -= leftMargin + rightMargin + leftPadding + rightPadding;
117
if (allocation.Height > topMargin + bottomMargin + topPadding + bottomPadding) {
118
allocation.Y += topMargin + topPadding;
119
allocation.Height -= topMargin + bottomMargin + topPadding + bottomPadding;
122
child.SizeAllocate (allocation);
125
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
129
if (GradientBackround) {
130
rect = new Gdk.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
131
HslColor gcol = useCustomColor ? customColor : Parent.Style.Background (Gtk.StateType.Normal);
133
using (Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow)) {
135
cr.MoveTo (rect.X, rect.Y);
136
cr.RelLineTo (rect.Width, 0);
137
cr.RelLineTo (0, rect.Height);
138
cr.RelLineTo (-rect.Width, 0);
139
cr.RelLineTo (0, -rect.Height);
141
Cairo.Gradient pat = new Cairo.LinearGradient (rect.X, rect.Y, rect.X, rect.Y + rect.Height - 1);
142
Cairo.Color color1 = gcol;
143
pat.AddColorStop (0, color1);
145
if (gcol.L < 0) gcol.L = 0;
146
pat.AddColorStop (1, gcol);
152
bool res = base.OnExposeEvent (evnt);
154
Gdk.GC borderColor = Parent.Style.DarkGC (Gtk.StateType.Normal);
157
for (int n=0; n<topMargin; n++)
158
GdkWindow.DrawLine (borderColor, rect.X, rect.Y + n, rect.Left + rect.Width - 1, rect.Y + n);
160
for (int n=0; n<bottomMargin; n++)
161
GdkWindow.DrawLine (borderColor, rect.X, rect.Top + rect.Height - 1 - n, rect.Left + rect.Width - 1, rect.Top + rect.Height - 1 - n);
163
for (int n=0; n<leftMargin; n++)
164
GdkWindow.DrawLine (borderColor, rect.X + n, rect.Y, rect.X + n, rect.Top + rect.Height - 1);
166
for (int n=0; n<rightMargin; n++)
167
GdkWindow.DrawLine (borderColor, rect.Left + rect.Width - 1 - n, rect.Y, rect.Left + rect.Width - 1 - n, rect.Top + rect.Height - 1);