diff --git a/ChangeLog b/ChangeLog index 78c8f614e..3842cbd76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2002-08-31 Rachel Hestilow + + Proper GList, GSList support. Read-only for now. + + * glue/list.c: Added. + * glue/Makefile.am: Add list.c + * glue/type.c: Add function gtksharp_is_object. + + * glib/ListBase.cs, List.cs: Added. + * glib/SList.cs: Inherit from ListBase. + * glib/Object.cs: Add static method "IsObject". + + * generator/Method.cs: Pass on element_type to constructor + if specified. + * generator/SymbolTable.cs: Move GList to manual types. + + * sample/GladeViewer.cs: Remove list hacks. + + * sources/Gnome.metadata: Specify element types for + CanvasPathDef.Split and IconList.GetSelection. Rename + CanvasPathDef *to methods to properly capitalized *To. + * sources/Gtk.metadata: Hide Widget.ListAccelClosures until + GClosure is handled properly. + * sources/Pango.metadata: Added. + + * sample/test/TestToolbar.cs: Compile with recent delegate changes. + 2002-08-31 Rachel Hestilow * glib/Idle.cs: Added. diff --git a/api/gnome-api.xml b/api/gnome-api.xml index 448b64fab..6708569dd 100644 --- a/api/gnome-api.xml +++ b/api/gnome-api.xml @@ -1054,7 +1054,7 @@ - + @@ -1092,21 +1092,21 @@ - + - + - + @@ -1144,7 +1144,7 @@ - + @@ -3038,7 +3038,7 @@ - + diff --git a/api/gtk-api.xml b/api/gtk-api.xml index ea91478f7..b891aee94 100644 --- a/api/gtk-api.xml +++ b/api/gtk-api.xml @@ -9525,7 +9525,7 @@ - + diff --git a/api/pango-api.xml b/api/pango-api.xml index 45e45b5b2..70a69eab3 100644 --- a/api/pango-api.xml +++ b/api/pango-api.xml @@ -351,7 +351,7 @@ - + diff --git a/generator/Method.cs b/generator/Method.cs index c514bb643..61772a417 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -21,6 +21,7 @@ namespace GtkSharp.Generation { private bool initialized = false; private string sig, isig, call; private string rettype, m_ret, s_ret; + private string element_type = null; private string name, cname, safety; private string protection = "public"; private bool is_get, is_set; @@ -146,6 +147,8 @@ namespace GtkSharp.Generation { m_ret = SymbolTable.GetMarshalReturnType(rettype); s_ret = SymbolTable.GetCSType(rettype); cname = elem.GetAttribute("cname"); + if (ret_elem.HasAttribute("element_type")) + element_type = ret_elem.GetAttribute("element_type"); bool is_shared = elem.HasAttribute("shared"); if (ret_elem.HasAttribute("array")) { @@ -390,7 +393,10 @@ namespace GtkSharp.Generation { else { sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";"); sw.Write(indent + "\t\t\t"); - sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";"); + string raw_parms = "raw_ret"; + if (element_type != null) + raw_parms += ", typeof (" + element_type + ")"; + sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, raw_parms) + ";"); } } diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index d0547444d..47314539e 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -60,7 +60,6 @@ namespace GtkSharp.Generation { simple_types.Add ("size_t", "int"); // FIXME: These ought to be handled properly. - simple_types.Add ("GList", "System.IntPtr"); simple_types.Add ("GMemChunk", "System.IntPtr"); simple_types.Add ("GTimeVal", "System.IntPtr"); simple_types.Add ("GClosure", "System.IntPtr"); @@ -74,6 +73,7 @@ namespace GtkSharp.Generation { manually_wrapped_types = new Hashtable (); manually_wrapped_types.Add ("GSList", "GLib.SList"); + manually_wrapped_types.Add ("GList", "GLib.List"); manually_wrapped_types.Add ("GValue", "GLib.Value"); } diff --git a/glib/List.cs b/glib/List.cs new file mode 100644 index 000000000..6a0b45d9c --- /dev/null +++ b/glib/List.cs @@ -0,0 +1,71 @@ +// List.cs - GList class wrapper implementation +// +// Authors: Mike Kestner +// +// (c) 2002 Mike Kestner + +namespace GLib { + + using System; + using System.Runtime.InteropServices; + + /// + /// List Class + /// + /// + /// + /// Wrapper class for GList. + /// + + public class List : ListBase { + + [DllImport("glib-2.0")] + static extern IntPtr g_list_copy (IntPtr l); + + public override object Clone () + { + return new List (g_list_copy (Handle)); + } + + [DllImport("gtksharpglue")] + static extern IntPtr gtksharp_list_get_data (IntPtr l); + + internal override IntPtr GetData (IntPtr current) + { + return gtksharp_list_get_data (current); + } + + [DllImport("gtksharpglue")] + static extern IntPtr gtksharp_list_get_next (IntPtr l); + + internal override IntPtr Next (IntPtr current) + { + return gtksharp_list_get_next (current); + } + + [DllImport("glib-2.0")] + static extern int g_list_length (IntPtr l); + + internal override int Length (IntPtr list) + { + return g_list_length (list); + } + + [DllImport("glib-2.0")] + static extern void g_list_free(IntPtr l); + + internal override void Free (IntPtr list) + { + if (list != IntPtr.Zero) + g_list_free (list); + } + + public List (IntPtr raw) : base (raw) + { + } + + public List (IntPtr raw, Type element_type) : base (raw, element_type) + { + } + } +} diff --git a/glib/ListBase.cs b/glib/ListBase.cs new file mode 100644 index 000000000..890dbb71a --- /dev/null +++ b/glib/ListBase.cs @@ -0,0 +1,176 @@ +// SList.cs - GSList class wrapper implementation +// +// Authors: Mike Kestner +// +// (c) 2002 Mike Kestner + +namespace GLib { + + using System; + using System.Collections; + using System.Runtime.InteropServices; + + /// + /// ListBase Class + /// + /// + /// + /// Base class for GList and GSList. + /// + + internal abstract class ListBase : IDisposable, ICollection, GLib.IWrapper, ICloneable { + + private IntPtr list_ptr = IntPtr.Zero; + private int length = -1; + private bool managed = false; + private Type element_type = null; + + abstract internal IntPtr GetData (IntPtr current); + abstract internal IntPtr Next (IntPtr current); + abstract internal int Length (IntPtr list); + abstract internal void Free (IntPtr list); + + protected ListBase (IntPtr list, Type element_type) + { + list_ptr = list; + this.element_type = element_type; + } + + protected ListBase (IntPtr list) + { + list_ptr = list; + } + + ~ListBase () + { + Console.WriteLine ("entering dispose"); + Dispose (); + Console.WriteLine ("leaving dispose"); + } + + public bool Managed { + set { managed = value; } + } + + /// + /// Handle Property + /// + /// + /// + /// A raw list reference for marshaling situations. + /// + + public IntPtr Handle { + get { + return list_ptr; + } + } + + internal IntPtr Raw { + get { + return list_ptr; + } + set { + if (managed && list_ptr != IntPtr.Zero) + Dispose (); + list_ptr = value; + } + } + + // ICollection + public int Count { + get { + if (length == -1) + length = Length (list_ptr); + return length; + } + } + + // Synchronization could be tricky here. Hmm. + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return null; } + } + + public void CopyTo (Array array, int index) + { + object[] orig = new object[Count]; + int i = 0; + foreach (object o in this) + orig[i] = o; + + orig.CopyTo (array, index); + } + + private class ListEnumerator : IEnumerator + { + private IntPtr current = IntPtr.Zero; + private ListBase list; + + public ListEnumerator (ListBase list) + { + this.list = list; + } + + public object Current { + get { + IntPtr data = list.GetData (current); + object ret = null; + if (list.element_type != null) + { + if (list.element_type == typeof (string)) + ret = Marshal.PtrToStringAnsi (data); + else if (list.element_type == typeof (int)) + ret = (int) data; + else if (list.element_type.IsValueType) + ret = Marshal.PtrToStructure (data, list.element_type); + else + ret = Activator.CreateInstance (list.element_type, new object[] {data}); + } + else if (Object.IsObject (data)) + ret = GLib.Object.GetObject (data); + + return ret; + } + } + + public bool MoveNext () + { + if (current == IntPtr.Zero) + current = list.list_ptr; + else + current = list.Next (current); + return (current != IntPtr.Zero); + } + + public void Reset () + { + current = IntPtr.Zero; + } + } + + // IEnumerable + public IEnumerator GetEnumerator () + { + return new ListEnumerator (this); + } + + // IDisposable + public void Dispose () + { + if (!managed) + return; + + if (list_ptr != IntPtr.Zero) + Free (list_ptr); + list_ptr = IntPtr.Zero; + length = -1; + } + + // ICloneable + abstract public object Clone (); + } +} diff --git a/glib/Object.cs b/glib/Object.cs index e64af2cd5..d304e69b8 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -237,5 +237,12 @@ namespace GLib { g_object_set_property (Raw, name, val.Handle); } + [DllImport("gtksharpglue")] + static extern bool gtksharp_is_object (IntPtr obj); + + internal static bool IsObject (IntPtr obj) + { + return gtksharp_is_object (obj); + } } } diff --git a/glib/SList.cs b/glib/SList.cs index e0f72abf7..2c5d7035e 100644 --- a/glib/SList.cs +++ b/glib/SList.cs @@ -7,7 +7,6 @@ namespace GLib { using System; - using System.Collections; using System.Runtime.InteropServices; /// @@ -18,62 +17,55 @@ namespace GLib { /// Wrapper class for GSList. /// - public class SList : ArrayList { + public class SList : ListBase { - private IntPtr list_ptr; - - [DllImport("gobject-2.0")] - static extern void g_slist_free(IntPtr l); - - ~SList () + [DllImport("glib-2.0")] + static extern IntPtr g_slist_copy (IntPtr l); + + public override object Clone () { - if (list_ptr != IntPtr.Zero) - g_slist_free (list_ptr); - } - - [DllImport("gobject-2.0")] - static extern IntPtr g_slist_append(IntPtr l, IntPtr d); - - /// - /// Handle Property - /// - /// - /// - /// A raw GSList reference for marshaling situations. - /// - - public IntPtr Handle { - get { - if (list_ptr != IntPtr.Zero) - g_slist_free (list_ptr); - - IntPtr l = IntPtr.Zero; - foreach (object o in this) { - IntPtr data = IntPtr.Zero; - if (o is GLib.Object) - l = g_slist_append (l, ((GLib.Object)o).Handle); - else - throw new Exception(); - } - - list_ptr = l; - return l; - } + return new SList (g_slist_copy (Handle)); } [DllImport("gtksharpglue")] static extern IntPtr gtksharp_slist_get_data (IntPtr l); + + internal override IntPtr GetData (IntPtr current) + { + return gtksharp_slist_get_data (current); + } + [DllImport("gtksharpglue")] static extern IntPtr gtksharp_slist_get_next (IntPtr l); - public SList (IntPtr raw) + internal override IntPtr Next (IntPtr current) { - IntPtr l = raw; - while (l != IntPtr.Zero) { - Add (gtksharp_slist_get_data (l)); - l = gtksharp_slist_get_next (l); - } + return gtksharp_slist_get_next (current); } + [DllImport("glib-2.0")] + static extern int g_slist_length (IntPtr l); + + internal override int Length (IntPtr list) + { + return g_slist_length (list); + } + + [DllImport("glib-2.0")] + static extern void g_slist_free(IntPtr l); + + internal override void Free (IntPtr list) + { + if (list != IntPtr.Zero) + g_slist_free (list); + } + + public SList (IntPtr raw) : base (raw) + { + } + + public SList (IntPtr raw, Type element_type) : base (raw, element_type) + { + } } } diff --git a/glue/Makefile.am b/glue/Makefile.am index 86f1f2d41..00b465204 100644 --- a/glue/Makefile.am +++ b/glue/Makefile.am @@ -13,6 +13,7 @@ BASESOURCES = \ style.c \ type.c \ widget.c \ + list.c \ # GNOMESOURCES = \ diff --git a/glue/list.c b/glue/list.c new file mode 100644 index 000000000..1eb58e14c --- /dev/null +++ b/glue/list.c @@ -0,0 +1,21 @@ +/* list.c : Glue to access fields in GList. + * + * Author: Rachel Hestilow + * + * 2002 Rachel Hestilow, Mike Kestner + */ + + +#include + +gpointer +gtksharp_list_get_data (GList *l) +{ + return l->data; +} + +GList* +gtksharp_list_get_next (GList *l) +{ + return l->next; +} diff --git a/glue/type.c b/glue/type.c index c28b4bb1e..5d39a2580 100644 --- a/glue/type.c +++ b/glue/type.c @@ -13,4 +13,9 @@ gtksharp_get_type_name (GObject *obj) return G_OBJECT_TYPE_NAME (obj); } +gboolean +gtksharp_is_object (gpointer obj) +{ + return G_IS_OBJECT (obj); +} diff --git a/sample/GladeViewer.cs b/sample/GladeViewer.cs index 7dcb3ce90..cf3e80682 100644 --- a/sample/GladeViewer.cs +++ b/sample/GladeViewer.cs @@ -14,12 +14,6 @@ namespace GladeSamples { public class GladeDemo { - // temporary hack until GList is wrapped - [DllImport("glib-2.0")] - static extern IntPtr g_list_nth_data (IntPtr l, int i); - [DllImport("glib-2.0")] - static extern int g_list_length (IntPtr l); - public static void Main (string[] args) { if (args.Length < 2) { @@ -44,11 +38,8 @@ namespace GladeSamples { Glade.XML.GetWidgetTree (wid) != null); Console.WriteLine ("\nList of created widgets:"); - // this is a hack, until GList is wrapped - IntPtr l = gxml.GetWidgetPrefix (""); - int len = g_list_length (l); - for (int i = 0; i < len; ++i) { - Widget w = GLib.Object.GetObject (g_list_nth_data (l, i)) as Widget; + GLib.List l = gxml.GetWidgetPrefix (""); + foreach (Widget w in l) { Console.WriteLine ("{0} {1}", w.GetType (), Glade.XML.GetWidgetName (w)); diff --git a/sample/test/TestToolbar.cs b/sample/test/TestToolbar.cs index 538b020ed..52417f2d5 100644 --- a/sample/test/TestToolbar.cs +++ b/sample/test/TestToolbar.cs @@ -25,96 +25,96 @@ namespace WidgetViewer { toolbar = new Toolbar (); toolbar.InsertStock (Stock.New, "Stock icon: New", "Toolbar/New", - new SignalFunc (set_small_icon), IntPtr.Zero, -1); + new SignalFunc (set_small_icon), -1); toolbar.InsertStock (Stock.Open, "Stock icon: Open", "Toolbar/Open", - new SignalFunc (set_large_icon), IntPtr.Zero, -1); + new SignalFunc (set_large_icon), -1); toolbar.AppendSpace (); toolbar.AppendItem ("Toggle tooltips", "toggle showing of tooltips", "Toolbar/Tooltips", new Image (Stock.DialogInfo, IconSize.LargeToolbar), - new SignalFunc (toggle_tooltips), IntPtr.Zero); + new SignalFunc (toggle_tooltips)); toolbar.AppendSpace (); toolbar.AppendItem ("Horizontal", "Horizontal layout", "Toolbar/Horizontal", new Image (Stock.GoForward, IconSize.LargeToolbar), - new SignalFunc (set_horizontal), IntPtr.Zero); + new SignalFunc (set_horizontal)); toolbar.AppendItem ("Vertical", "Vertical layout", "Toolbar/Vertical", new Image (Stock.GoUp, IconSize.LargeToolbar), - new SignalFunc (set_vertical), IntPtr.Zero); + new SignalFunc (set_vertical)); toolbar.AppendSpace (); toolbar.AppendItem ("Icons", "Only show icons", "Toolbar/IconsOnly", new Image (Stock.Home, IconSize.LargeToolbar), - new SignalFunc (set_icon_only), IntPtr.Zero); + new SignalFunc (set_icon_only)); toolbar.AppendItem ("Text", "Only show Text", "Toolbar/TextOnly", new Image (Stock.JustifyFill, IconSize.LargeToolbar), - new SignalFunc (set_text_only), IntPtr.Zero); + new SignalFunc (set_text_only)); toolbar.AppendItem ("Both", "Show both Icon & Text", "Toolbar/Both", new Image (Stock.Index, IconSize.LargeToolbar), - new SignalFunc (set_both), IntPtr.Zero); + new SignalFunc (set_both)); toolbar.AppendItem ("Both (Horizontal)", "Show Icon & Text horizontally", "Toolbar/BothHoriz", new Image (Stock.Index, IconSize.LargeToolbar), - new SignalFunc (set_both_horiz), IntPtr.Zero); + new SignalFunc (set_both_horiz)); toolbar.AppendSpace (); toolbar.InsertStock (Stock.Close, "Stock icon: Close", "Toolbar/Close", - new SignalFunc (Close_Button), IntPtr.Zero, -1); + new SignalFunc (Close_Button), -1); window.Add (toolbar); window.ShowAll (); return window; } - static void set_small_icon () + static void set_small_icon (Gtk.Object obj) { toolbar.IconSize = IconSize.SmallToolbar; } - static void set_large_icon () + static void set_large_icon (Gtk.Object obj) { toolbar.IconSize = IconSize.LargeToolbar; } - static void set_icon_only () + static void set_icon_only (Gtk.Object obj) { toolbar.ToolbarStyle = ToolbarStyle.Icons; } - static void set_text_only () + static void set_text_only (Gtk.Object obj) { toolbar.ToolbarStyle = ToolbarStyle.Text; } - static void set_horizontal () + static void set_horizontal (Gtk.Object obj) { toolbar.Orientation = Orientation.Horizontal; } - static void set_vertical () + static void set_vertical (Gtk.Object obj) { toolbar.Orientation = Orientation.Vertical; } - static void set_both () + static void set_both (Gtk.Object obj) { toolbar.ToolbarStyle = ToolbarStyle.Both; } - static void set_both_horiz () + static void set_both_horiz (Gtk.Object obj) { toolbar.ToolbarStyle = ToolbarStyle.BothHoriz; } - static void toggle_tooltips () + static void toggle_tooltips (Gtk.Object obj) { if (showTooltips == true) showTooltips = false; @@ -125,7 +125,7 @@ namespace WidgetViewer { Console.WriteLine ("Show tooltips: " + showTooltips); } - static void Close_Button () + static void Close_Button (Gtk.Object obj) { window.Destroy (); } diff --git a/sources/Gnome.metadata b/sources/Gnome.metadata index 9314b7020..b0d7dcbe6 100644 --- a/sources/Gnome.metadata +++ b/sources/Gnome.metadata @@ -167,6 +167,50 @@ + + + Moveto + + + + name + MoveTo + + + + + + Curveto + + + + name + CurveTo + + + + + + Lineto + + + + name + LineTo + + + + + + LinetoMoving + + + + name + LineToMoving + + + @@ -226,4 +270,28 @@ + + + + Split + + + + element_type + Gnome.CanvasPathDef + + + + + + GetSelection + + + + element_type + int + + + + diff --git a/sources/Gtk.metadata b/sources/Gtk.metadata index 1d941a2e5..08b20c88d 100644 --- a/sources/Gtk.metadata +++ b/sources/Gtk.metadata @@ -1262,20 +1262,15 @@ - + + ListAccelClosures + + SetChangePaletteHook - - - hidden - 1 - - - - GetSearchEqualFunc diff --git a/sources/Pango.metadata b/sources/Pango.metadata new file mode 100644 index 000000000..d45aabc67 --- /dev/null +++ b/sources/Pango.metadata @@ -0,0 +1,17 @@ + + + + + + + GetLines + + + + element_type + Pango.LayoutLine + + + + +