Ryujinx-GtkSharp/gtk/Container.custom
Dan Winship 9d04b4dd06 Redo child property handling; now we generate classes to hold
the
        child properties for a given widget in a container, and generate
        the child properties as properties on those classes.
        
        * parser/gapi2xml.pl (addPropElem): don't prepend "child_" to
        child prop names any more

        * generator/ClassBase.cs (ClassBase): keep childprops separate
        from properties
        (GenChildProperties): create a subclass of Gtk.ContainerChild
        containing the container type's child properties, and override
the
        Container indexer to return that type.

        * generator/ObjectGen.cs (Generate): call GenChildProperties

        * generator/Property.cs:
        * generator/ChildProperty.cs: Simplify these a bunch, since
        * child
        properties are now represented as C# properties as well. Also
add
        [GLib.Property(cname)] and [Gtk.ChildProperty(cname)]
attributes.

        * glib/Makefile.am (sources): add PropertyAttribute.cs

        * glib/PropertyAttribute.cs: attribute used to label
        GObject properties

        * gtk/Makefile.am (sources): add ChildPropertyAttribute.cs

        * gtk/gtk-api.raw: regenerate for parser changes (remove
        "Child"/"child_" from child property names).

        * gtk/ChildPropertyAttribute.cs: attribute used to label
        GtkContainer child properties

        * gtk/Container.custom: define the ContainerChild class, and an
        indexer to return instances of it.

        * doc/en/Gtk/: update for container child property change

svn path=/trunk/gtk-sharp/; revision=36284
2004-11-18 20:31:22 +00:00

218 lines
5.8 KiB
Plaintext

// Container.custom - 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.
[DllImport("gtksharpglue-2.0")]
static extern void gtksharp_container_child_get_property (IntPtr container, IntPtr child, string property, ref GLib.Value value);
public GLib.Value ChildGetProperty (Gtk.Widget child, string property_name) {
GLib.Value value = new GLib.Value ();
gtksharp_container_child_get_property (Handle, child.Handle, property_name, ref value);
return value;
}
[DllImport("libgtk-win32-2.0-0.dll")]
static extern IntPtr gtk_container_get_children (IntPtr raw);
public Widget[] Children {
get {
IntPtr list_ptr = gtk_container_get_children (Handle);
if (list_ptr == IntPtr.Zero)
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;
}
}
[DllImport("libgtk-win32-2.0-0.dll")]
static extern bool gtk_container_get_focus_chain (IntPtr raw, out IntPtr list_ptr);
[DllImport("libgtk-win32-2.0-0.dll")]
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-2.0")]
static extern IntPtr gtksharp_container_get_focus_child(IntPtr raw);
[DllImport("libgtk-win32-2.0-0.dll")]
static extern void gtk_container_set_focus_child(IntPtr raw, IntPtr child);
public Gtk.Widget FocusChild {
get {
IntPtr raw_ret = gtksharp_container_get_focus_child (Handle);
Gtk.Widget ret;
if (raw_ret == IntPtr.Zero)
ret = null;
else
ret = (Gtk.Widget) GLib.Object.GetObject (raw_ret);
return ret;
}
set {
gtk_container_set_focus_child (Handle, value.Handle);
}
}
[DllImport("gtksharpglue-2.0")]
static extern void gtksharp_container_base_forall (IntPtr handle, bool include_internals, IntPtr cb, IntPtr data);
[DllImport("gtksharpglue-2.0")]
static extern void gtksharp_container_override_forall (GLib.GType gtype, ForallDelegate cb);
[DllImport("gtksharpglue-2.0")]
static extern void gtksharp_container_invoke_gtk_callback (IntPtr cb, IntPtr handle, IntPtr data);
delegate void ForallDelegate (IntPtr container, bool include_internals, IntPtr cb, IntPtr data);
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 Forall_cb (IntPtr container, bool include_internals, IntPtr cb, IntPtr data)
{
Container obj = GLib.Object.GetObject (container, false) as Container;
CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, invoker);
}
static void OverrideForall (GLib.GType gtype)
{
if (ForallCallback == null)
ForallCallback = new ForallDelegate (Forall_cb);
gtksharp_container_override_forall (gtype, ForallCallback);
}
[GLib.DefaultSignalHandler (Type=typeof(Gtk.Container), ConnectionMethod="OverrideForall")]
protected virtual void ForAll (bool include_internals, CallbackInvoker invoker)
{
gtksharp_container_base_forall (Handle, include_internals, invoker.Callback, invoker.Data);
}
[DllImport("gtksharpglue-2.0")]
static extern IntPtr gtksharp_container_base_child_type(IntPtr raw);
[DllImport("gtksharpglue-2.0")]
static extern void gtksharp_container_override_child_type (GLib.GType type, ChildTypeDelegate cb);
delegate IntPtr ChildTypeDelegate (IntPtr raw);
static ChildTypeDelegate ChildTypeCallback;
static IntPtr ChildType_cb (IntPtr raw)
{
Container obj = GLib.Object.GetObject (raw, false) as Container;
GLib.GType gtype = obj.ChildType ();
return gtype.Val;
}
static void OverrideChildType (GLib.GType gtype)
{
if (ChildTypeCallback == null)
ChildTypeCallback = new ChildTypeDelegate (ChildType_cb);
gtksharp_container_override_child_type (gtype, ChildTypeCallback);
}
[GLib.DefaultSignalHandler (Type=typeof(Gtk.Container), ConnectionMethod="OverrideChildType")]
public virtual GLib.GType ChildType() {
IntPtr raw_ret = gtksharp_container_base_child_type(Handle);
GLib.GType ret = new GLib.GType(raw_ret);
return ret;
}
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);
}
}