~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Components/HeaderBox.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// HeaderBox.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using Gtk;
 
28
 
 
29
namespace MonoDevelop.Components
 
30
{
 
31
        public class HeaderBox: Bin
 
32
        {
 
33
                Gtk.Widget child;
 
34
                int topMargin;
 
35
                int bottomMargin;
 
36
                int leftMargin;
 
37
                int rightMargin;
 
38
                
 
39
                int topPadding;
 
40
                int bottomPadding;
 
41
                int leftPadding;
 
42
                int rightPadding;
 
43
                
 
44
                public HeaderBox ()
 
45
                {
 
46
                }
 
47
                
 
48
                public HeaderBox (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
 
49
                {
 
50
                        SetMargins (topMargin, bottomMargin, leftMargin, rightMargin);
 
51
                }
 
52
                
 
53
                public void SetMargins (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
 
54
                {
 
55
                        this.topMargin = topMargin;
 
56
                        this.bottomMargin = bottomMargin;
 
57
                        this.leftMargin = leftMargin;
 
58
                        this.rightMargin = rightMargin;
 
59
                }
 
60
                
 
61
                public void SetPadding (int topPadding, int bottomPadding, int leftPadding, int rightPadding)
 
62
                {
 
63
                        this.topPadding = topPadding;
 
64
                        this.bottomPadding = bottomPadding;
 
65
                        this.leftPadding = leftPadding;
 
66
                        this.rightPadding = rightPadding;
 
67
                }
 
68
                
 
69
                public bool GradientBackround { get; set; }
 
70
 
 
71
                protected override void OnAdded (Widget widget)
 
72
                {
 
73
                        base.OnAdded (widget);
 
74
                        child = widget;
 
75
                }
 
76
 
 
77
                protected override void OnSizeRequested (ref Requisition requisition)
 
78
                {
 
79
                        if (child != null) {
 
80
                                requisition = child.SizeRequest ();
 
81
                                requisition.Width += leftMargin + rightMargin + leftPadding + rightPadding;
 
82
                                requisition.Height += topMargin + bottomMargin + topPadding + bottomPadding;
 
83
                        } else {
 
84
                                requisition.Width = 0;
 
85
                                requisition.Height = 0;
 
86
                        }
 
87
                }
 
88
 
 
89
                protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 
90
                {
 
91
                        base.OnSizeAllocated (allocation);
 
92
                        if (allocation.Width > leftMargin + rightMargin + leftPadding + rightPadding) {
 
93
                                allocation.X += leftMargin + leftPadding;
 
94
                                allocation.Width -= leftMargin + rightMargin + leftPadding + rightPadding;
 
95
                        }
 
96
                        if (allocation.Height > topMargin + bottomMargin + topPadding + bottomPadding) {
 
97
                                allocation.Y += topMargin + topPadding;
 
98
                                allocation.Height -= topMargin + bottomMargin + topPadding + bottomPadding;
 
99
                        }
 
100
                        if (child != null)
 
101
                                child.SizeAllocate (allocation);
 
102
                }
 
103
 
 
104
                protected override bool OnExposeEvent (Gdk.EventExpose evnt)
 
105
                {
 
106
                        Gdk.Rectangle rect;
 
107
                        
 
108
                        if (GradientBackround) {
 
109
                                rect = new Gdk.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
 
110
                                HslColor gcol = Style.Background (Gtk.StateType.Normal);
 
111
                                
 
112
                                using (Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow)) {
 
113
                                        cr.NewPath ();
 
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);
 
119
                                        cr.ClosePath ();
 
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);
 
123
                                        gcol.L -= 0.1;
 
124
                                        if (gcol.L < 0) gcol.L = 0;
 
125
                                        pat.AddColorStop (1, gcol);
 
126
                                        cr.Pattern = pat;
 
127
                                        cr.FillPreserve ();
 
128
                                }
 
129
                        }
 
130
                        
 
131
                        bool res = base.OnExposeEvent (evnt);
 
132
                        
 
133
                        Gdk.GC borderColor = Style.DarkGC (Gtk.StateType.Normal);
 
134
                        
 
135
                        rect = Allocation;
 
136
                        for (int n=0; n<topMargin; n++)
 
137
                                GdkWindow.DrawLine (borderColor, rect.X, rect.Y + n, rect.Right - 1, rect.Y + n);
 
138
                        
 
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);
 
141
                        
 
142
                        for (int n=0; n<leftMargin; n++)
 
143
                                GdkWindow.DrawLine (borderColor, rect.X + n, rect.Y, rect.X + n, rect.Bottom - 1);
 
144
                        
 
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);
 
147
                        
 
148
                        return res;
 
149
                }
 
150
        }
 
151
}
 
152