~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Components.DockToolbars/FixedPanel.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// FixedPanel.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.Collections;
 
31
using Gtk;
 
32
using Gdk;
 
33
 
 
34
namespace MonoDevelop.Components.DockToolbars
 
35
{
 
36
        public enum Placement
 
37
        {
 
38
                Top, Bottom, Left, Right
 
39
        }
 
40
 
 
41
        public class FixedPanel: Container
 
42
        {
 
43
                ArrayList widgets = new ArrayList ();
 
44
                Placement placement = Placement.Top;
 
45
                
 
46
                public FixedPanel ()
 
47
                {
 
48
                        WidgetFlags |= WidgetFlags.NoWindow;
 
49
                }
 
50
                
 
51
                public Placement Placement {
 
52
                        get { return placement; }
 
53
                        set { placement = value; }
 
54
                }
 
55
                
 
56
                public override GLib.GType ChildType ()
 
57
                {
 
58
                        return Widget.GType;
 
59
                }
 
60
                
 
61
                public void Put (Widget w, int x, int y)
 
62
                {
 
63
                        WidgetPosition wpos = new WidgetPosition ();
 
64
                        wpos.X = x;
 
65
                        wpos.Y = y;
 
66
                        wpos.Widget = w;
 
67
                        widgets.Add (wpos);
 
68
                        w.Parent = this;
 
69
                        QueueResize ();
 
70
                }
 
71
                
 
72
                public void Move (Widget w, int x, int y)
 
73
                {
 
74
                        int n = GetWidgetPosition (w);
 
75
                        if (n != -1) {
 
76
                                WidgetPosition wpos = (WidgetPosition) widgets [n];
 
77
                                if (wpos.X == x && wpos.Y == y) return; 
 
78
                                wpos.X = x;
 
79
                                wpos.Y = y;
 
80
                                QueueResize ();
 
81
                        }
 
82
                }
 
83
                
 
84
                public bool GetPosition (Widget w, out int x, out int y)
 
85
                {
 
86
                        int n = GetWidgetPosition (w);
 
87
                        if (n != -1) {
 
88
                                WidgetPosition wpos = (WidgetPosition) widgets [n];
 
89
                                x = wpos.X;
 
90
                                y = wpos.Y;
 
91
                                return true;
 
92
                        }
 
93
                        x = y = 0;
 
94
                        return false;
 
95
                }
 
96
                
 
97
                public int GetChildWidth (Widget w)
 
98
                {
 
99
        //              ResizeChildren ();
 
100
                        if (placement == Placement.Top || placement == Placement.Bottom)
 
101
                                return w.Allocation.Width;
 
102
                        else
 
103
                                return w.Allocation.Height;
 
104
                }
 
105
                
 
106
                public int GetChildHeight (Widget w)
 
107
                {
 
108
                        if (placement == Placement.Top || placement == Placement.Bottom)
 
109
                                return w.Allocation.Height;
 
110
                        else
 
111
                                return w.Allocation.Width;
 
112
                }
 
113
                
 
114
                public int PanelWidth {
 
115
                        get {
 
116
                                if (placement == Placement.Top || placement == Placement.Bottom)
 
117
                                        return Allocation.Width;
 
118
                                else
 
119
                                        return Allocation.Height;
 
120
                        }
 
121
                }
 
122
                
 
123
                public void WindowToPanel (int x, int y, int w, int h, out int rx, out int ry)
 
124
                {
 
125
                        switch (placement) {
 
126
                                case Placement.Top:
 
127
                                        rx = x - Allocation.X;
 
128
                                        ry = y - Allocation.Y;
 
129
                                        break;
 
130
                                case Placement.Bottom:
 
131
                                        rx = x - Allocation.X;
 
132
                                        ry = Allocation.Bottom - y - h - 1;
 
133
                                        break;
 
134
                                case Placement.Left:
 
135
                                        rx = y - Allocation.Y;
 
136
                                        ry = x - Allocation.X;
 
137
                                        break;
 
138
                                default:
 
139
                                        rx = y - Allocation.Y;
 
140
                                        ry = Allocation.Right - x - w - 1;
 
141
                                        break;
 
142
                        }
 
143
                }
 
144
                
 
145
                public void PanelToWindow (int x, int y, int w, int h, out int rx, out int ry, out int rw, out int rh)
 
146
                {
 
147
                        switch (placement) {
 
148
                                case Placement.Top:
 
149
                                        rx = x + Allocation.X;
 
150
                                        ry = y + Allocation.Y;
 
151
                                        rw = w;
 
152
                                        rh = h;
 
153
                                        break;
 
154
                                case Placement.Bottom:
 
155
                                        rx = x + Allocation.X;
 
156
                                        ry = Allocation.Bottom - y - h - 1;
 
157
                                        rw = w;
 
158
                                        rh = h;
 
159
                                        break;
 
160
                                case Placement.Left:
 
161
                                        rx = y + Allocation.X;
 
162
                                        ry = x + Allocation.Y;
 
163
                                        rw = h;
 
164
                                        rh = w;
 
165
                                        break;
 
166
                                default:
 
167
                                        rx = Allocation.Right - y - h - 1;
 
168
                                        ry = x + Allocation.Y;
 
169
                                        rw = h;
 
170
                                        rh = w;
 
171
                                        break;
 
172
                        }
 
173
                }
 
174
                
 
175
                protected override void OnAdded (Widget w)
 
176
                {
 
177
                        Put (w, 0, 0);
 
178
                }
 
179
                
 
180
                protected override void OnRemoved (Widget w)
 
181
                {
 
182
                        int i = GetWidgetPosition (w);
 
183
                        if (i != -1) {
 
184
                                widgets.RemoveAt (i);
 
185
                                w.Unparent ();
 
186
                                QueueResize ();
 
187
                        }
 
188
                }
 
189
                
 
190
                int GetWidgetPosition (Widget w)
 
191
                {
 
192
                        for (int n=0; n<widgets.Count; n++)
 
193
                                if (((WidgetPosition)widgets[n]).Widget == w)
 
194
                                        return n;
 
195
                        return -1;
 
196
                }
 
197
                
 
198
                protected override void OnSizeRequested (ref Requisition req)
 
199
                {
 
200
                        req.Width = req.Height = 0;
 
201
                        foreach (WidgetPosition pos in widgets) {
 
202
                                Requisition wreq = pos.Widget.SizeRequest ();
 
203
                                if (placement == Placement.Top || placement == Placement.Bottom) {
 
204
                                        if (pos.X + wreq.Width > req.Width)
 
205
                                                req.Width = pos.X + wreq.Width;
 
206
                                        if (pos.Y + wreq.Height > req.Height)
 
207
                                                req.Height = pos.Y + wreq.Height;
 
208
                                } else {
 
209
                                        if (pos.Y + wreq.Width > req.Width)
 
210
                                                req.Width = pos.Y + wreq.Width;
 
211
                                        if (pos.X + wreq.Height > req.Height)
 
212
                                                req.Height = pos.X + wreq.Height;
 
213
                                }
 
214
                        }
 
215
                        if (placement == Placement.Top || placement == Placement.Bottom)
 
216
                                req.Width = 0;
 
217
                        else
 
218
                                req.Height = 0;
 
219
                }
 
220
 
 
221
                protected override void OnSizeAllocated (Gdk.Rectangle rect)
 
222
                {
 
223
                        base.OnSizeAllocated (rect);
 
224
                        foreach (WidgetPosition pos in widgets) {
 
225
                                Requisition req = pos.Widget.ChildRequisition;
 
226
                                Rectangle crect = new Rectangle (pos.X, pos.Y, req.Width, req.Height);
 
227
                                switch (placement) {
 
228
                                        case Placement.Top:
 
229
                                                break;
 
230
                                        case Placement.Bottom:
 
231
                                                crect.Y = Allocation.Height - crect.Y - crect.Height;
 
232
                                                break;
 
233
                                        case Placement.Left: {
 
234
                                                int t = crect.X; crect.X=crect.Y; crect.Y=t;
 
235
                                                break;
 
236
                                                }
 
237
                                        case Placement.Right: {
 
238
                                                int t = crect.X; crect.X=crect.Y; crect.Y=t;
 
239
                                                crect.X = Allocation.Width - crect.X - crect.Width;
 
240
                                                break;
 
241
                                                }
 
242
                                }
 
243
                                crect.X += Allocation.X;
 
244
                                crect.Y += Allocation.Y;
 
245
                                pos.Widget.SizeAllocate (crect);
 
246
                        }
 
247
                }
 
248
                
 
249
                protected override void ForAll (bool include_internals, Gtk.Callback callback)
 
250
                {
 
251
                        WidgetPosition[] positions = (WidgetPosition[]) widgets.ToArray (typeof (WidgetPosition));
 
252
                        foreach (WidgetPosition pos in positions)
 
253
                                callback (pos.Widget);
 
254
                }
 
255
        }
 
256
 
 
257
        class WidgetPosition
 
258
        {
 
259
                public int X;
 
260
                public int Y;
 
261
                public Widget Widget;
 
262
        }
 
263
}