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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Components.Docking/DockBar.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:
32
32
using System;
33
33
using Gtk;
34
34
using System.Collections.Generic;
 
35
using MonoDevelop.Ide.Gui;
35
36
 
36
37
namespace MonoDevelop.Components.Docking
37
38
{
42
43
                DockFrame frame;
43
44
                Label filler;
44
45
                bool alwaysVisible;
45
 
                
 
46
                bool showBorder = true;
 
47
 
46
48
                internal DockBar (DockFrame frame, Gtk.PositionType position)
47
49
                {
48
 
                        frame.ShadedContainer.Add (this);
49
50
                        VisibleWindow = false;
50
51
                        this.frame = frame;
51
52
                        this.position = position;
54
55
                                box = new HBox ();
55
56
                        else
56
57
                                box = new VBox ();
57
 
                        
58
 
                        uint sizePadding = 1;
59
 
                        uint startPadding = 6;
60
 
                        switch (Frame.CompactGuiLevel) {
61
 
                                case 1: sizePadding = 2; break;
62
 
                                case 4: startPadding = 3; break;
63
 
                                case 5: startPadding = 0; sizePadding = 0; break;
64
 
                        }
65
 
                        
66
 
                        switch (position) {
67
 
                                case PositionType.Top: al.BottomPadding = sizePadding; al.LeftPadding = al.RightPadding = startPadding; break;
68
 
                                case PositionType.Bottom: al.TopPadding = sizePadding; al.LeftPadding = al.RightPadding = startPadding; break;
69
 
                                case PositionType.Left: al.RightPadding = sizePadding; al.TopPadding = al.BottomPadding = startPadding; break;
70
 
                                case PositionType.Right: al.LeftPadding = sizePadding; al.TopPadding = al.BottomPadding = startPadding; break;
71
 
                        }
72
 
                        
73
 
                        box.Spacing = 3;
 
58
 
74
59
                        al.Add (box);
75
60
                        Add (al);
76
61
                        
93
78
                        get { return this.alwaysVisible; }
94
79
                        set { this.alwaysVisible = value; UpdateVisibility (); }
95
80
                }
96
 
                
 
81
 
 
82
                public bool AlignToEnd { get; set; }
 
83
 
 
84
                public bool ShowBorder {
 
85
                        get { return showBorder; }
 
86
                        set { showBorder = value; QueueResize (); }
 
87
                }
97
88
                
98
89
                internal Gtk.Orientation Orientation {
99
90
                        get {
112
103
                                return frame;
113
104
                        }
114
105
                }
 
106
 
 
107
                DateTime hoverActivationDelay;
 
108
 
 
109
                void DisableHoverActivation ()
 
110
                {
 
111
                        // Temporarily disables hover activation of items in this bar
 
112
                        // Useful to avoid accidental triggers when the bar items
 
113
                        // are reallocated
 
114
                        hoverActivationDelay = DateTime.Now + TimeSpan.FromSeconds (1.5);
 
115
                }
 
116
 
 
117
                internal bool HoverActivationEnabled {
 
118
                        get { return DateTime.Now >= hoverActivationDelay; }
 
119
                }
115
120
                
116
121
                internal DockBarItem AddItem (DockItem item, int size)
117
122
                {
 
123
                        DisableHoverActivation ();
118
124
                        DockBarItem it = new DockBarItem (this, item, size);
119
125
                        box.PackStart (it, false, false, 0);
120
126
                        it.ShowAll ();
126
132
                
127
133
                void OnItemVisibilityChanged (object o, EventArgs args)
128
134
                {
 
135
                        DisableHoverActivation ();
129
136
                        UpdateVisibility ();
130
137
                }
131
138
                
149
156
                
150
157
                internal void RemoveItem (DockBarItem it)
151
158
                {
 
159
                        DisableHoverActivation ();
152
160
                        box.Remove (it);
153
161
                        it.Shown -= OnItemVisibilityChanged;
154
162
                        it.Hidden -= OnItemVisibilityChanged;
155
163
                        UpdateVisibility ();
156
164
                }
157
 
                
 
165
 
158
166
                internal void UpdateTitle (DockItem item)
159
167
                {
160
168
                        foreach (Widget w in box.Children) {
166
174
                        }
167
175
                }
168
176
                
 
177
                internal void UpdateStyle (DockItem item)
 
178
                {
 
179
                }
 
180
 
 
181
                protected override void OnSizeRequested (ref Requisition requisition)
 
182
                {
 
183
                        base.OnSizeRequested (ref requisition);
 
184
 
 
185
                        if (ShowBorder) {
 
186
                                // Add space for the separator
 
187
                                if (Orientation == Gtk.Orientation.Vertical)
 
188
                                        requisition.Width++;
 
189
                                else
 
190
                                        requisition.Height++;
 
191
                        }
 
192
                }
 
193
 
 
194
                protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 
195
                {
 
196
                        base.OnSizeAllocated (allocation);
 
197
                        if (ShowBorder && Child != null) {
 
198
                                switch (Position) {
 
199
                                case PositionType.Left: allocation.Width--; break;
 
200
                                case PositionType.Right: allocation.X++; allocation.Width--; break;
 
201
                                case PositionType.Top: allocation.Height--; break;
 
202
                                case PositionType.Bottom: allocation.Y++; allocation.Height--; break;
 
203
                                }
 
204
                                Child.SizeAllocate (allocation);
 
205
                        }
 
206
                }
 
207
 
169
208
                protected override bool OnExposeEvent (Gdk.EventExpose evnt)
170
209
                {
171
 
                        frame.ShadedContainer.DrawBackground (this);
172
 
                        return base.OnExposeEvent (evnt);
 
210
                        var alloc = Allocation;
 
211
                        using (var ctx = Gdk.CairoHelper.Create (GdkWindow)) {
 
212
                                ctx.Rectangle (alloc.X, alloc.Y, alloc.X + alloc.Width, alloc.Y + alloc.Height);
 
213
                                Cairo.LinearGradient gr;
 
214
                                if (Orientation == Gtk.Orientation.Vertical)
 
215
                                        gr = new Cairo.LinearGradient (alloc.X, alloc.Y, alloc.X + alloc.Width, alloc.Y);
 
216
                                else
 
217
                                        gr = new Cairo.LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Y + alloc.Height);
 
218
                                using (gr) {
 
219
                                        gr.AddColorStop (0, Styles.DockBarBackground1);
 
220
                                        gr.AddColorStop (1, Styles.DockBarBackground2);
 
221
                                        ctx.Pattern = gr;
 
222
                                }
 
223
                                ctx.Fill ();
 
224
 
 
225
                                // Light shadow
 
226
                                double offs = ShowBorder ? 1.5 : 0.5;
 
227
                                switch (Position) {
 
228
                                case PositionType.Left:ctx.MoveTo (alloc.X + alloc.Width - offs, alloc.Y); ctx.RelLineTo (0, Allocation.Height); break;
 
229
                                case PositionType.Right: ctx.MoveTo (alloc.X + offs, alloc.Y); ctx.RelLineTo (0, Allocation.Height); break;
 
230
                                case PositionType.Top: ctx.MoveTo (alloc.X, alloc.Y + alloc.Height - offs); ctx.RelLineTo (Allocation.Width, 0); break;
 
231
                                case PositionType.Bottom: ctx.MoveTo (alloc.X, alloc.Y + offs); ctx.RelLineTo (Allocation.Width, 0); break;
 
232
                                }
 
233
                                ctx.LineWidth = 1;
 
234
                                ctx.Color = Styles.DockBarSeparatorColorLight;
 
235
                                ctx.Stroke ();
 
236
                        }
 
237
 
 
238
                        if (Child != null)
 
239
                                PropagateExpose (Child, evnt);
 
240
 
 
241
                        if (ShowBorder) {
 
242
                                using (var ctx = Gdk.CairoHelper.Create (GdkWindow)) {
 
243
                                        ctx.LineWidth = 1;
 
244
 
 
245
                                        // Dark separator
 
246
                                        switch (Position) {
 
247
                                        case PositionType.Left:ctx.MoveTo (alloc.X + alloc.Width - 0.5, alloc.Y); ctx.RelLineTo (0, Allocation.Height); break;
 
248
                                        case PositionType.Right: ctx.MoveTo (alloc.X + 0.5, alloc.Y); ctx.RelLineTo (0, Allocation.Height); break;
 
249
                                        case PositionType.Top: ctx.MoveTo (alloc.X, alloc.Y + alloc.Height + 0.5); ctx.RelLineTo (Allocation.Width, 0); break;
 
250
                                        case PositionType.Bottom: ctx.MoveTo (alloc.X, alloc.Y + 0.5); ctx.RelLineTo (Allocation.Width, 0); break;
 
251
                                        }
 
252
                                        ctx.Color = Styles.DockSeparatorColor.ToCairoColor ();
 
253
                                        ctx.Stroke ();
 
254
                                }
 
255
                        }
 
256
                        return true;
173
257
                }
174
258
        }
175
259
}