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
using Xwt.CairoBackend;
31
namespace Xwt.GtkBackend
52
public HeaderBox (IntPtr p): base (p)
56
public HeaderBox (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
58
SetMargins (topMargin, bottomMargin, leftMargin, rightMargin);
61
public void SetBorderColor (Color color)
67
public void SetMargins (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
69
this.topMargin = topMargin;
70
this.bottomMargin = bottomMargin;
71
this.leftMargin = leftMargin;
72
this.rightMargin = rightMargin;
75
public void SetPadding (int topPadding, int bottomPadding, int leftPadding, int rightPadding)
77
this.topPadding = topPadding;
78
this.bottomPadding = bottomPadding;
79
this.leftPadding = leftPadding;
80
this.rightPadding = rightPadding;
83
public bool GradientBackround { get; set; }
84
public bool DrawBackground { get; set; }
86
protected override void OnAdded (Gtk.Widget widget)
88
base.OnAdded (widget);
92
protected override void OnSizeRequested (ref Requisition requisition)
95
requisition = child.SizeRequest ();
96
requisition.Width += leftMargin + rightMargin + leftPadding + rightPadding;
97
requisition.Height += topMargin + bottomMargin + topPadding + bottomPadding;
99
requisition.Width = 0;
100
requisition.Height = 0;
104
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
106
base.OnSizeAllocated (allocation);
107
if (allocation.Width > leftMargin + rightMargin + leftPadding + rightPadding) {
108
allocation.X += leftMargin + leftPadding;
109
allocation.Width -= leftMargin + rightMargin + leftPadding + rightPadding;
111
if (allocation.Height > topMargin + bottomMargin + topPadding + bottomPadding) {
112
allocation.Y += topMargin + topPadding;
113
allocation.Height -= topMargin + bottomMargin + topPadding + bottomPadding;
116
child.SizeAllocate (allocation);
119
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
123
if (DrawBackground) {
124
GdkWindow.DrawRectangle (Style.BackgroundGC (Gtk.StateType.Normal), true, Allocation.X, Allocation.Y, Allocation.Width - 1, Allocation.Height - 1);
127
if (GradientBackround) {
128
rect = new Gdk.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
129
Color gcol = Util.ToXwtColor (Style.Background (Gtk.StateType.Normal));
131
using (Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow)) {
133
cr.MoveTo (rect.X, rect.Y);
134
cr.RelLineTo (rect.Width, 0);
135
cr.RelLineTo (0, rect.Height);
136
cr.RelLineTo (-rect.Width, 0);
137
cr.RelLineTo (0, -rect.Height);
139
Cairo.Gradient pat = new Cairo.LinearGradient (rect.X, rect.Y, rect.X, rect.Bottom);
140
Cairo.Color color1 = gcol.ToCairoColor ();
141
pat.AddColorStop (0, color1);
143
pat.AddColorStop (1, gcol.ToCairoColor ());
149
bool res = base.OnExposeEvent (evnt);
153
borderColor = new Gdk.GC (GdkWindow);
154
borderColor.RgbFgColor = Util.ToGdkColor (color.Value);
157
borderColor = Style.DarkGC (Gtk.StateType.Normal);
160
for (int n=0; n<topMargin; n++)
161
GdkWindow.DrawLine (borderColor, rect.X, rect.Y + n, rect.Right, rect.Y + n);
163
for (int n=0; n<bottomMargin; n++)
164
GdkWindow.DrawLine (borderColor, rect.X, rect.Bottom - n, rect.Right, rect.Bottom - n);
166
for (int n=0; n<leftMargin; n++)
167
GdkWindow.DrawLine (borderColor, rect.X + n, rect.Y, rect.X + n, rect.Bottom);
169
for (int n=0; n<rightMargin; n++)
170
GdkWindow.DrawLine (borderColor, rect.Right - n, rect.Y, rect.Right - n, rect.Bottom);
173
borderColor.Dispose ();