7
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
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.
30
using System.Collections;
34
namespace MonoDevelop.Components.DockToolbars
38
Top, Bottom, Left, Right
41
public class FixedPanel: Container
43
ArrayList widgets = new ArrayList ();
44
Placement placement = Placement.Top;
48
WidgetFlags |= WidgetFlags.NoWindow;
51
public Placement Placement {
52
get { return placement; }
53
set { placement = value; }
56
public override GLib.GType ChildType ()
61
public void Put (Widget w, int x, int y)
63
WidgetPosition wpos = new WidgetPosition ();
72
public void Move (Widget w, int x, int y)
74
int n = GetWidgetPosition (w);
76
WidgetPosition wpos = (WidgetPosition) widgets [n];
77
if (wpos.X == x && wpos.Y == y) return;
84
public bool GetPosition (Widget w, out int x, out int y)
86
int n = GetWidgetPosition (w);
88
WidgetPosition wpos = (WidgetPosition) widgets [n];
97
public int GetChildWidth (Widget w)
100
if (placement == Placement.Top || placement == Placement.Bottom)
101
return w.Allocation.Width;
103
return w.Allocation.Height;
106
public int GetChildHeight (Widget w)
108
if (placement == Placement.Top || placement == Placement.Bottom)
109
return w.Allocation.Height;
111
return w.Allocation.Width;
114
public int PanelWidth {
116
if (placement == Placement.Top || placement == Placement.Bottom)
117
return Allocation.Width;
119
return Allocation.Height;
123
public void WindowToPanel (int x, int y, int w, int h, out int rx, out int ry)
127
rx = x - Allocation.X;
128
ry = y - Allocation.Y;
130
case Placement.Bottom:
131
rx = x - Allocation.X;
132
ry = Allocation.Bottom - y - h - 1;
135
rx = y - Allocation.Y;
136
ry = x - Allocation.X;
139
rx = y - Allocation.Y;
140
ry = Allocation.Right - x - w - 1;
145
public void PanelToWindow (int x, int y, int w, int h, out int rx, out int ry, out int rw, out int rh)
149
rx = x + Allocation.X;
150
ry = y + Allocation.Y;
154
case Placement.Bottom:
155
rx = x + Allocation.X;
156
ry = Allocation.Bottom - y - h - 1;
161
rx = y + Allocation.X;
162
ry = x + Allocation.Y;
167
rx = Allocation.Right - y - h - 1;
168
ry = x + Allocation.Y;
175
protected override void OnAdded (Widget w)
180
protected override void OnRemoved (Widget w)
182
int i = GetWidgetPosition (w);
184
widgets.RemoveAt (i);
190
int GetWidgetPosition (Widget w)
192
for (int n=0; n<widgets.Count; n++)
193
if (((WidgetPosition)widgets[n]).Widget == w)
198
protected override void OnSizeRequested (ref Requisition req)
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;
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;
215
if (placement == Placement.Top || placement == Placement.Bottom)
221
protected override void OnSizeAllocated (Gdk.Rectangle rect)
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);
230
case Placement.Bottom:
231
crect.Y = Allocation.Height - crect.Y - crect.Height;
233
case Placement.Left: {
234
int t = crect.X; crect.X=crect.Y; crect.Y=t;
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;
243
crect.X += Allocation.X;
244
crect.Y += Allocation.Y;
245
pos.Widget.SizeAllocate (crect);
249
protected override void ForAll (bool include_internals, Gtk.Callback callback)
251
WidgetPosition[] positions = (WidgetPosition[]) widgets.ToArray (typeof (WidgetPosition));
252
foreach (WidgetPosition pos in positions)
253
callback (pos.Widget);
261
public Widget Widget;