~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins.Gui/Mono.Addins.Gui/HeaderBox.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+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 Mono.Addins.Gui
 
30
{
 
31
        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
                bool useCustomColor;
 
45
                Gdk.Color customColor;
 
46
                
 
47
                public HeaderBox ()
 
48
                {
 
49
                }
 
50
                
 
51
                public HeaderBox (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
 
52
                {
 
53
                        SetMargins (topMargin, bottomMargin, leftMargin, rightMargin);
 
54
                }
 
55
                
 
56
                public void Replace (Gtk.Bin parent)
 
57
                {
 
58
                        Gtk.Widget c = parent.Child;
 
59
                        parent.Remove (c);
 
60
                        Add (c);
 
61
                        parent.Add (this);
 
62
                }
 
63
                
 
64
                public void SetMargins (int topMargin, int bottomMargin, int leftMargin, int rightMargin)
 
65
                {
 
66
                        this.topMargin = topMargin;
 
67
                        this.bottomMargin = bottomMargin;
 
68
                        this.leftMargin = leftMargin;
 
69
                        this.rightMargin = rightMargin;
 
70
                }
 
71
                
 
72
                public void SetPadding (int topPadding, int bottomPadding, int leftPadding, int rightPadding)
 
73
                {
 
74
                        this.topPadding = topPadding;
 
75
                        this.bottomPadding = bottomPadding;
 
76
                        this.leftPadding = leftPadding;
 
77
                        this.rightPadding = rightPadding;
 
78
                }
 
79
                
 
80
                public bool GradientBackround { get; set; }
 
81
                
 
82
                public Gdk.Color BackgroundColor {
 
83
                        get { return customColor; }
 
84
                        set { customColor = value; useCustomColor = true; }
 
85
                }
 
86
                
 
87
                public void ResetBackgroundColor ()
 
88
                {
 
89
                        useCustomColor = false;
 
90
                }
 
91
 
 
92
                protected override void OnAdded (Widget widget)
 
93
                {
 
94
                        base.OnAdded (widget);
 
95
                        child = widget;
 
96
                }
 
97
 
 
98
                protected override void OnSizeRequested (ref Requisition requisition)
 
99
                {
 
100
                        if (child != null) {
 
101
                                requisition = child.SizeRequest ();
 
102
                                requisition.Width += leftMargin + rightMargin + leftPadding + rightPadding;
 
103
                                requisition.Height += topMargin + bottomMargin + topPadding + bottomPadding;
 
104
                        } else {
 
105
                                requisition.Width = 0;
 
106
                                requisition.Height = 0;
 
107
                        }
 
108
                }
 
109
 
 
110
                protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 
111
                {
 
112
                        base.OnSizeAllocated (allocation);
 
113
                        if (allocation.Width > leftMargin + rightMargin + leftPadding + rightPadding) {
 
114
                                allocation.X += leftMargin + leftPadding;
 
115
                                allocation.Width -= leftMargin + rightMargin + leftPadding + rightPadding;
 
116
                        }
 
117
                        if (allocation.Height > topMargin + bottomMargin + topPadding + bottomPadding) {
 
118
                                allocation.Y += topMargin + topPadding;
 
119
                                allocation.Height -= topMargin + bottomMargin + topPadding + bottomPadding;
 
120
                        }
 
121
                        if (child != null)
 
122
                                child.SizeAllocate (allocation);
 
123
                }
 
124
 
 
125
                protected override bool OnExposeEvent (Gdk.EventExpose evnt)
 
126
                {
 
127
                        Gdk.Rectangle rect;
 
128
                        
 
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);
 
132
                                
 
133
                                using (Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow)) {
 
134
                                        cr.NewPath ();
 
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);
 
140
                                        cr.ClosePath ();
 
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);
 
144
                                        gcol.L -= 0.1;
 
145
                                        if (gcol.L < 0) gcol.L = 0;
 
146
                                        pat.AddColorStop (1, gcol);
 
147
                                        cr.Pattern = pat;
 
148
                                        cr.FillPreserve ();
 
149
                                }
 
150
                        }
 
151
                        
 
152
                        bool res = base.OnExposeEvent (evnt);
 
153
                        
 
154
                        Gdk.GC borderColor = Parent.Style.DarkGC (Gtk.StateType.Normal);
 
155
                        
 
156
                        rect = Allocation;
 
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);
 
159
                        
 
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);
 
162
                        
 
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);
 
165
                        
 
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);
 
168
                        
 
169
                        return res;
 
170
                }
 
171
        }
 
172
}
 
173