5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
31
using System.Collections.Generic;
33
namespace Xwt.GtkBackend
35
class BoxBackend: WidgetBackend, IBoxBackend
39
Widget = new CustomContainer () { Backend = this };
43
new CustomContainer Widget {
44
get { return (CustomContainer)base.Widget; }
45
set { base.Widget = value; }
48
public void Add (IWidgetBackend widget)
50
WidgetBackend wb = (WidgetBackend) widget;
51
Widget.Add (wb.Frontend, GetWidget (widget));
54
public void Remove (IWidgetBackend widget)
56
Widget.Remove (GetWidget (widget));
59
public void SetAllocation (IWidgetBackend[] widgets, Rectangle[] rects)
62
for (int n=0; n<widgets.Length; n++) {
63
var w = GetWidget (widgets[n]);
64
if (Widget.SetAllocation (w, rects[n]))
67
if (changed && !Widget.IsReallocating)
68
Widget.QueueResize ();
72
class CustomContainer: Gtk.Container, IGtkContainer
74
public BoxBackend Backend;
75
public bool IsReallocating;
76
Dictionary<Gtk.Widget, WidgetData> children = new Dictionary<Gtk.Widget, WidgetData> ();
80
public Rectangle Rect;
84
public CustomContainer ()
86
GtkWorkarounds.FixContainerLeak (this);
87
WidgetFlags |= Gtk.WidgetFlags.NoWindow;
90
public void ReplaceChild (Gtk.Widget oldWidget, Gtk.Widget newWidget)
92
WidgetData r = children [oldWidget];
95
children [newWidget] = r;
98
public bool SetAllocation (Gtk.Widget w, Rectangle rect)
101
children.TryGetValue (w, out r);
102
if (r.Rect != rect) {
110
public void Add (Widget w, Gtk.Widget gw)
112
children.Add (gw, new WidgetData () { Widget = w, Rect = new Rectangle (0,0,0,0) });
116
protected override void OnAdded (Gtk.Widget widget)
118
widget.Parent = this;
121
protected override void OnRemoved (Gtk.Widget widget)
123
children.Remove (widget);
128
protected override void OnUnrealized ()
130
base.OnUnrealized ();
133
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
135
base.OnSizeAllocated (allocation);
136
if (Backend.IsPreallocating)
139
IsReallocating = true;
140
((IWidgetSurface)Backend.Frontend).Reallocate ();
142
IsReallocating = false;
144
foreach (var cr in children) {
145
var r = cr.Value.Rect;
146
cr.Key.SizeAllocate (new Gdk.Rectangle (allocation.X + (int)r.X, allocation.Y + (int)r.Y, (int)r.Width, (int)r.Height));
150
protected override void ForAll (bool includeInternals, Gtk.Callback callback)
152
base.ForAll (includeInternals, callback);
153
foreach (var c in children.Keys.ToArray ())