1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
// Container.cs - customizations to Gtk.Container
//
// Authors: Mike Kestner <mkestner@ximian.com>
//
// Copyright (c) 2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace Gtk {
using System;
using System.Collections;
using System.Runtime.InteropServices;
public partial class Container : IEnumerable {
[DllImport("gtksharpglue-3")]
static extern void gtksharp_container_child_get_property (IntPtr container, IntPtr child, IntPtr property, ref GLib.Value value);
public GLib.Value ChildGetProperty (Gtk.Widget child, string property_name) {
GLib.Value value = new GLib.Value ();
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (property_name);
gtksharp_container_child_get_property (Handle, child.Handle, native, ref value);
GLib.Marshaller.Free (native);
return value;
}
public IEnumerator GetEnumerator ()
{
return Children.GetEnumerator ();
}
class ChildAccumulator {
public ArrayList Children = new ArrayList ();
public void Add (Gtk.Widget widget)
{
Children.Add (widget);
}
}
public IEnumerable AllChildren {
get {
ChildAccumulator acc = new ChildAccumulator ();
Forall (new Gtk.Callback (acc.Add));
return acc.Children;
}
}
[DllImport (Global.GtkNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool gtk_container_get_focus_chain (IntPtr raw, out IntPtr list_ptr);
[DllImport (Global.GtkNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern void gtk_container_set_focus_chain (IntPtr raw, IntPtr list_ptr);
public Widget[] FocusChain {
get {
IntPtr list_ptr;
bool success = gtk_container_get_focus_chain (Handle, out list_ptr);
if (!success)
return new Widget [0];
GLib.List list = new GLib.List (list_ptr);
Widget[] result = new Widget [list.Count];
for (int i = 0; i < list.Count; i++)
result [i] = list [i] as Widget;
return result;
}
set {
GLib.List list = new GLib.List (IntPtr.Zero);
foreach (Widget val in value)
list.Append (val.Handle);
gtk_container_set_focus_chain (Handle, list.Handle);
}
}
[DllImport("gtksharpglue-3")]
static extern void gtksharp_container_base_forall (IntPtr handle, bool include_internals, IntPtr cb, IntPtr data);
[DllImport("gtksharpglue-3")]
static extern void gtksharp_container_override_forall (IntPtr gtype, ForallDelegate cb);
[DllImport("gtksharpglue-3")]
static extern void gtksharp_container_invoke_gtk_callback (IntPtr cb, IntPtr handle, IntPtr data);
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
delegate void ForallDelegate (IntPtr container, bool include_internals, IntPtr cb, IntPtr data);
static ForallDelegate ForallOldCallback;
static ForallDelegate ForallCallback;
public struct CallbackInvoker {
IntPtr cb;
IntPtr data;
internal CallbackInvoker (IntPtr cb, IntPtr data)
{
this.cb = cb;
this.data = data;
}
internal IntPtr Data {
get {
return data;
}
}
internal IntPtr Callback {
get {
return cb;
}
}
public void Invoke (Widget w)
{
gtksharp_container_invoke_gtk_callback (cb, w.Handle, data);
}
}
static void ForallOld_cb (IntPtr container, bool include_internals, IntPtr cb, IntPtr data)
{
try {
//GtkContainer's unmanaged dispose calls forall, but by that time the managed object is gone
//so it couldn't do anything useful, and resurrecting it would cause a resurrection cycle.
//In that case, just chain to the native base in case it can do something.
Container obj = (Container) GLib.Object.TryGetObject (container);
if (obj != null) {
CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, invoker);
} else {
gtksharp_container_base_forall (container, include_internals, cb, data);
}
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
static void OverrideForallOld (GLib.GType gtype)
{
if (ForallOldCallback == null)
ForallOldCallback = new ForallDelegate (ForallOld_cb);
gtksharp_container_override_forall (gtype.Val, ForallOldCallback);
}
[Obsolete ("Override the ForAll(bool,Gtk.Callback) method instead")]
[GLib.DefaultSignalHandler (Type=typeof(Gtk.Container), ConnectionMethod="OverrideForallOld")]
protected virtual void ForAll (bool include_internals, CallbackInvoker invoker)
{
gtksharp_container_base_forall (Handle, include_internals, invoker.Callback, invoker.Data);
}
static void Forall_cb (IntPtr container, bool include_internals, IntPtr cb, IntPtr data)
{
try {
//GtkContainer's unmanaged dispose calls forall, but by that time the managed object is gone
//so it couldn't do anything useful, and resurrecting it would cause a resurrection cycle.
//In that case, just chain to the native base in case it can do something.
Container obj = (Container) GLib.Object.TryGetObject (container);
if (obj != null) {
CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, new Gtk.Callback (invoker.Invoke));
} else {
gtksharp_container_base_forall (container, include_internals, cb, data);
}
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
static void OverrideForall (GLib.GType gtype)
{
if (ForallCallback == null)
ForallCallback = new ForallDelegate (Forall_cb);
gtksharp_container_override_forall (gtype.Val, ForallCallback);
}
[GLib.DefaultSignalHandler (Type=typeof(Gtk.Container), ConnectionMethod="OverrideForall")]
protected virtual void ForAll (bool include_internals, Gtk.Callback callback)
{
CallbackInvoker invoker;
try {
invoker = (CallbackInvoker)callback.Target;
} catch {
throw new ApplicationException ("ForAll can only be called as \"base.ForAll()\". Use Forall() or Foreach().");
}
gtksharp_container_base_forall (Handle, include_internals, invoker.Callback, invoker.Data);
}
// Compatibility code for old ChildType() virtual method
static IntPtr ObsoleteChildType_cb (IntPtr raw)
{
try {
Container obj = GLib.Object.GetObject (raw, false) as Container;
GLib.GType gtype = obj.ChildType ();
return gtype.Val;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return GLib.GType.Invalid.Val;
}
static ChildTypeNativeDelegate ObsoleteChildTypeVMCallback;
static void OverrideObsoleteChildType (GLib.GType gtype)
{
if (ObsoleteChildTypeVMCallback == null)
ObsoleteChildTypeVMCallback = new ChildTypeNativeDelegate (ObsoleteChildType_cb);
OverrideChildType (gtype, ObsoleteChildTypeVMCallback); // -> autogenerated method
}
[Obsolete ("Replaced by OnChildType for implementations and SupportedChildType for callers.")]
[GLib.DefaultSignalHandler (Type=typeof(Gtk.Container), ConnectionMethod="OverrideObsoleteChildType")]
public virtual GLib.GType ChildType() {
return InternalChildType (); // -> autogenerated method
}
public class ContainerChild {
protected Container parent;
protected Widget child;
public ContainerChild (Container parent, Widget child)
{
this.parent = parent;
this.child = child;
}
public Container Parent {
get {
return parent;
}
}
public Widget Child {
get {
return child;
}
}
}
public virtual ContainerChild this [Widget w] {
get {
return new ContainerChild (this, w);
}
}
}
}
|