diff --git a/ChangeLog b/ChangeLog index 51916faf8..84a92c1eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-06-23 Mike Kestner + + * generator/ReturnValue.cs : support owned and elements_owned for lists. + * glib/List.cs : add ctor overloads for memory mgmt. + * glib/ListBase.cs : add ctor overloads for memory mgmt. Dispose + elements if specified. + * glib/SList.cs : add ctor overloads for memory mgmt. + * gnome/Gnome.metadata : unhide and generate a List prop. + * gnomevfs/Gnomevfs.metadata : unhide and generate a List prop. + * gtk/FileChooser.custom : new. add hidden props. + * gtk/FileChooserButton.custom : new. impl hidden props. + * gtk/FileChooserDialog.custom : remove some List props and use the + GLib.Marshaller for the remaining ones.. + * gtk/FileChooserWidget.custom : remove some List props and use the + GLib.Marshaller for the remaining ones.. + * gtk/Gtk.metadata : unhide and let the generator do some List props. + 2005-06-23 Mike Kestner * gconf/GConf/Client.cs : support add/remove of a single notify handle diff --git a/doc/en/GLib/List.xml b/doc/en/GLib/List.xml index 98ffd1906..76de9f725 100644 --- a/doc/en/GLib/List.xml +++ b/doc/en/GLib/List.xml @@ -123,5 +123,23 @@ + + + Constructor + + + + + + + + Pointer to the native list. + The type of the elements contained in the list. + if the native list needs to be released on Dispose. + if the list elements need to be released on Dispose. + Creates a List. + This type is only recommended for marshaling GList parameters and return values in bindings. + + diff --git a/doc/en/GLib/ListBase.xml b/doc/en/GLib/ListBase.xml index f819dba51..d3314b297 100644 --- a/doc/en/GLib/ListBase.xml +++ b/doc/en/GLib/ListBase.xml @@ -199,7 +199,11 @@ an object of type Identifies the list as one that needs to be freed. Only set this to true if you want the object to release the associated native list when it is disposed. - + + + System.Obsolete(Message="Replaced by owned parameter on ctor.", IsError=False) + + Method diff --git a/doc/en/GLib/SList.xml b/doc/en/GLib/SList.xml index c01c9a005..516bd2b06 100644 --- a/doc/en/GLib/SList.xml +++ b/doc/en/GLib/SList.xml @@ -64,5 +64,23 @@ + + + Constructor + + + + + + + + Pointer to the native list. + The type if the elements contained in the list. + if the native list should be released on Dispose. + if the elements should be released on Dispose. + Creates an SList. + This type should only be used for marshaling GSList parameters and return values in bindings. + + diff --git a/doc/en/Gtk/FileChooser.xml b/doc/en/Gtk/FileChooser.xml index b6519a259..f5be1c523 100644 --- a/doc/en/Gtk/FileChooser.xml +++ b/doc/en/Gtk/FileChooser.xml @@ -726,5 +726,65 @@ + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + + + + Property + + Gtk.FileFilter[] + + + To be added. + To be added. + To be added. + + + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + diff --git a/doc/en/Gtk/FileChooserButton.xml b/doc/en/Gtk/FileChooserButton.xml index 854d1958e..d6a764c83 100644 --- a/doc/en/Gtk/FileChooserButton.xml +++ b/doc/en/Gtk/FileChooserButton.xml @@ -693,5 +693,65 @@ To be added. + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + + + + Property + + Gtk.FileFilter[] + + + To be added. + To be added. + To be added. + + + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + - \ No newline at end of file + diff --git a/generator/ReturnValue.cs b/generator/ReturnValue.cs index 5fd0d4737..26af3cc5c 100644 --- a/generator/ReturnValue.cs +++ b/generator/ReturnValue.cs @@ -2,7 +2,7 @@ // // Author: Mike Kestner // -// Copyright (c) 2004 Novell, Inc. +// Copyright (c) 2004-2005 Novell, Inc. // // This program is free software; you can redistribute it and/or // modify it under the terms of version 2 of the GNU General Public @@ -25,6 +25,7 @@ namespace GtkSharp.Generation { using System.Xml; public class ReturnValue { + private XmlElement elem; @@ -51,9 +52,30 @@ namespace GtkSharp.Generation { } } + string ElementCType { + get { + if (elem != null && elem.HasAttribute ("element_type")) + return elem.GetAttribute ("element_type"); + + return String.Empty; + } + } + + bool ElementsOwned { + get { + if (elem != null && elem.GetAttribute ("elements_owned") == "true") + return true; + + return false; + } + } + string ElementType { get { - return elem == null ? String.Empty : elem.GetAttribute("element_type"); + if (ElementCType.Length > 0) + return SymbolTable.Table.GetCSType (ElementCType); + + return String.Empty; } } @@ -104,12 +126,13 @@ namespace GtkSharp.Generation { { if (IGen == null) return String.Empty; - if (Owned) - var += ", true"; - else if (ElementType != String.Empty) { + + if (ElementType != String.Empty) { string type_str = "typeof (" + ElementType + ")"; - return String.Format ("({0}[]) GLib.Marshaller.ListToArray ({1}, {2})", ElementType, IGen.FromNativeReturn (var + ", " + type_str), type_str); - } + string args = type_str + ", " + (Owned ? "true" : "false") + ", " + (ElementsOwned ? "true" : "false"); + return String.Format ("({0}[]) GLib.Marshaller.ListToArray ({1}, {2})", ElementType, IGen.FromNativeReturn (var + ", " + args), type_str); + } else if (Owned) + var += ", true"; return IGen.FromNativeReturn (var); } diff --git a/glib/List.cs b/glib/List.cs index 73a730c30..41d1c0dbf 100644 --- a/glib/List.cs +++ b/glib/List.cs @@ -91,17 +91,13 @@ namespace GLib { return g_list_nth_data (Handle, n); } + public List (IntPtr raw) : this (raw, null) {} - public List (IntPtr raw) : base (raw) - { - } + public List (System.Type element_type) : this (IntPtr.Zero, element_type) {} - public List (System.Type element_type) : base (IntPtr.Zero, element_type) - { - } + public List (IntPtr raw, System.Type element_type) : this (raw, element_type, false, false) {} + + public List (IntPtr raw, System.Type element_type, bool owned, bool elements_owned) : base (raw, element_type, owned, elements_owned) {} - public List (IntPtr raw, System.Type element_type) : base (raw, element_type) - { - } } } diff --git a/glib/ListBase.cs b/glib/ListBase.cs index 3666f796e..27cf05900 100644 --- a/glib/ListBase.cs +++ b/glib/ListBase.cs @@ -31,6 +31,7 @@ namespace GLib { private IntPtr list_ptr = IntPtr.Zero; private int length = -1; private bool managed = false; + private bool elements_owned = false; protected System.Type element_type = null; abstract internal IntPtr NthData (uint index); @@ -41,19 +42,12 @@ namespace GLib { abstract internal IntPtr Append (IntPtr current, IntPtr raw); abstract internal IntPtr Prepend (IntPtr current, IntPtr raw); - private ListBase () - { - } - - internal ListBase (IntPtr list, System.Type element_type) + internal ListBase (IntPtr list, System.Type element_type, bool owned, bool elements_owned) { list_ptr = list; this.element_type = element_type; - } - - internal ListBase (IntPtr list) - { - list_ptr = list; + managed = owned; + this.elements_owned = elements_owned; } ~ListBase () @@ -61,6 +55,7 @@ namespace GLib { Dispose (false); } + [Obsolete ("Replaced by owned parameter on ctor.")] public bool Managed { set { managed = value; } } @@ -71,18 +66,6 @@ namespace GLib { } } - internal IntPtr Raw { - get { - return list_ptr; - } - set { - if (managed && list_ptr != IntPtr.Zero) - FreeList (); - - list_ptr = value; - } - } - public void Append (IntPtr raw) { list_ptr = Append (list_ptr, raw); @@ -172,14 +155,15 @@ namespace GLib { public void Empty () { - for (uint i = 0; i < Count; i++) - { - if (typeof (GLib.Object).IsAssignableFrom (element_type)) - g_object_unref (NthData (i)); - else - g_free (NthData (i)); - } - FreeList (); + if (elements_owned) + for (uint i = 0; i < Count; i++) + if (typeof (GLib.Object).IsAssignableFrom (element_type)) + g_object_unref (NthData (i)); + else + g_free (NthData (i)); + + if (managed) + FreeList (); } private class ListEnumerator : IEnumerator @@ -231,10 +215,7 @@ namespace GLib { protected virtual void Dispose (bool disposing) { - if (!managed) - return; - - FreeList (); + Empty (); } void FreeList () diff --git a/glib/SList.cs b/glib/SList.cs index 49e87bb30..1eab04691 100644 --- a/glib/SList.cs +++ b/glib/SList.cs @@ -92,16 +92,12 @@ namespace GLib { return g_slist_nth_data (Handle, n); } - public SList (IntPtr raw) : base (raw) - { - } + public SList (IntPtr raw) : this (raw, null) {} - public SList (System.Type element_type) : base (IntPtr.Zero, element_type) - { - } + public SList (System.Type element_type) : this (IntPtr.Zero, element_type) {} - public SList (IntPtr raw, System.Type element_type) : base (raw, element_type) - { - } + public SList (IntPtr raw, System.Type element_type) : this (raw, element_type, false, false) {} + + public SList (IntPtr raw, System.Type element_type, bool owned, bool elements_owned) : base (raw, element_type, false, false) {} } } diff --git a/gnome/Gnome.metadata b/gnome/Gnome.metadata index 9919144cf..5ecf9a9b5 100644 --- a/gnome/Gnome.metadata +++ b/gnome/Gnome.metadata @@ -150,7 +150,9 @@ LineTo LineToMoving MoveTo - Gnome.CanvasPathDef + GnomeCanvasPathDef* + true + true private const-gchar* 1 diff --git a/gnomevfs/Gnomevfs.metadata b/gnomevfs/Gnomevfs.metadata index 54b2dabfd..61239c5e9 100644 --- a/gnomevfs/Gnomevfs.metadata +++ b/gnomevfs/Gnomevfs.metadata @@ -16,7 +16,9 @@ - Gnome.Vfs.MimeApplication + GnomeVFSMimeApplication* + true + true 1 diff --git a/gtk/FileChooser.custom b/gtk/FileChooser.custom new file mode 100644 index 000000000..a5b42635f --- /dev/null +++ b/gtk/FileChooser.custom @@ -0,0 +1,24 @@ +// Gtk.FileChooser.custom - Gtk FileChooser customizations +// +// Authors: Mike Kestner +// +// 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. + + + string[] Filenames { get; } + string[] ShortcutFolders { get; } + diff --git a/gtk/FileChooserButton.custom b/gtk/FileChooserButton.custom new file mode 100644 index 000000000..f18e302b0 --- /dev/null +++ b/gtk/FileChooserButton.custom @@ -0,0 +1,43 @@ +// Gtk.FileChooserButton.custom - Gtk FileChooserButton customizations +// +// Authors: Mike Kestner +// +// Copyright (c) 2005 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 ("libgtk-win32-2.0-0.dll")] + static extern IntPtr gtk_file_chooser_get_filenames (IntPtr raw); + + public string[] Filenames { + get { + IntPtr raw_ret = gtk_file_chooser_get_filenames (Handle); + GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString), true, true); + return (string[]) GLib.Marshaller.ListToArray (list, typeof (string)); + } + } + + [DllImport ("libgtk-win32-2.0-0.dll")] + static extern IntPtr gtk_file_chooser_list_shortcut_folders (IntPtr raw); + + public string[] ShortcutFolders { + get { + IntPtr raw_ret = gtk_file_chooser_list_shortcut_folders (Handle); + GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString), true, true); + return (string[]) GLib.Marshaller.ListToArray (list, typeof (string)); + } + } + diff --git a/gtk/FileChooserDialog.custom b/gtk/FileChooserDialog.custom index cf987555b..68f55432b 100644 --- a/gtk/FileChooserDialog.custom +++ b/gtk/FileChooserDialog.custom @@ -2,8 +2,10 @@ // // Authors: Todd Berman // Jeroen Zwartepoorte +// Mike Kestner // // Copyright (c) 2004 Todd Berman, Jeroen Zwartepoorte +// Copyright (c) 2005 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 @@ -66,80 +68,23 @@ [DllImport ("libgtk-win32-2.0-0.dll")] static extern IntPtr gtk_file_chooser_get_filenames (IntPtr raw); + public string[] Filenames { get { IntPtr raw_ret = gtk_file_chooser_get_filenames (Handle); - if (raw_ret == IntPtr.Zero) - return new string[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString)); - string[] result = new string [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (string) list [i]; - list.Empty (); - return result; - } - } - - [DllImport ("libgtk-win32-2.0-0.dll")] - static extern IntPtr gtk_file_chooser_get_uris (IntPtr raw); - public string[] Uris { - get { - IntPtr raw_ret = gtk_file_chooser_get_uris (Handle); - if (raw_ret == IntPtr.Zero) - return new string[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (string)); - string[] result = new string [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (string) list [i]; - list.Empty (); - return result; - } - } - - [DllImport ("libgtk-win32-2.0-0.dll")] - static extern IntPtr gtk_file_chooser_list_filters (IntPtr raw); - public FileFilter[] Filters { - get { - IntPtr raw_ret = gtk_file_chooser_list_filters (Handle); - if (raw_ret == IntPtr.Zero) - return new FileFilter[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (FileFilter)); - FileFilter[] result = new FileFilter [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (FileFilter) list [i]; - list.Dispose (); - return result; + GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString), true, true); + return (string[]) GLib.Marshaller.ListToArray (list, typeof (string)); } } [DllImport ("libgtk-win32-2.0-0.dll")] static extern IntPtr gtk_file_chooser_list_shortcut_folders (IntPtr raw); + public string[] ShortcutFolders { get { IntPtr raw_ret = gtk_file_chooser_list_shortcut_folders (Handle); - if (raw_ret == IntPtr.Zero) - return new string[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString)); - string[] result = new string [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (string) list [i]; - list.Empty (); - return result; + GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString), true, true); + return (string[]) GLib.Marshaller.ListToArray (list, typeof (string)); } } - [DllImport ("libgtk-win32-2.0-0.dll")] - static extern IntPtr gtk_file_chooser_list_shortcut_folder_uris (IntPtr raw); - public string[] ShortcutFolderUris { - get { - IntPtr raw_ret = gtk_file_chooser_list_shortcut_folder_uris (Handle); - if (raw_ret == IntPtr.Zero) - return new string[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (string)); - string[] result = new string [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (string) list [i]; - list.Empty (); - return result; - } - } diff --git a/gtk/FileChooserWidget.custom b/gtk/FileChooserWidget.custom index 920c1fe06..f5db8a2b3 100644 --- a/gtk/FileChooserWidget.custom +++ b/gtk/FileChooserWidget.custom @@ -25,77 +25,19 @@ public string[] Filenames { get { IntPtr raw_ret = gtk_file_chooser_get_filenames (Handle); - if (raw_ret == IntPtr.Zero) - return new string[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString)); - string[] result = new string [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (string) list [i]; - list.Empty (); - return result; - } - } - - [DllImport ("libgtk-win32-2.0-0.dll")] - static extern IntPtr gtk_file_chooser_get_uris (IntPtr raw); - public string[] Uris { - get { - IntPtr raw_ret = gtk_file_chooser_get_uris (Handle); - if (raw_ret == IntPtr.Zero) - return new string[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (string)); - string[] result = new string [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (string) list [i]; - list.Empty (); - return result; - } - } - - [DllImport ("libgtk-win32-2.0-0.dll")] - static extern IntPtr gtk_file_chooser_list_filters (IntPtr raw); - public FileFilter[] Filters { - get { - IntPtr raw_ret = gtk_file_chooser_list_filters (Handle); - if (raw_ret == IntPtr.Zero) - return new FileFilter[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (FileFilter)); - FileFilter[] result = new FileFilter [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (FileFilter) list [i]; - list.Dispose (); - return result; + GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString), true, true); + return (string[]) GLib.Marshaller.ListToArray (list, typeof (string)); } } [DllImport ("libgtk-win32-2.0-0.dll")] static extern IntPtr gtk_file_chooser_list_shortcut_folders (IntPtr raw); + public string[] ShortcutFolders { get { IntPtr raw_ret = gtk_file_chooser_list_shortcut_folders (Handle); - if (raw_ret == IntPtr.Zero) - return new string[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString)); - string[] result = new string [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (string) list [i]; - list.Empty (); - return result; + GLib.SList list = new GLib.SList (raw_ret, typeof (GLib.ListBase.FilenameString), true, true); + return (string[]) GLib.Marshaller.ListToArray (list, typeof (string)); } } - [DllImport ("libgtk-win32-2.0-0.dll")] - static extern IntPtr gtk_file_chooser_list_shortcut_folder_uris (IntPtr raw); - public string[] ShortcutFolderUris { - get { - IntPtr raw_ret = gtk_file_chooser_list_shortcut_folder_uris (Handle); - if (raw_ret == IntPtr.Zero) - return new string[0]; - GLib.SList list = new GLib.SList (raw_ret, typeof (string)); - string[] result = new string [list.Count]; - for (int i = 0; i < list.Count; i++) - result [i] = (string) list [i]; - list.Empty (); - return result; - } - } diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 973e8235a..3f40fbd37 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -89,14 +89,21 @@ TextInserted gfilename* gfilename* - gfilename* 1 + gfilename* const-gfilename* const-gfilename* - 1 - 1 + gchar* + true + true + GetFilters + GtkFileFilter* + true 1 - 1 + GetShortcutFolderUris + gchar* + true + true call out 1 @@ -579,7 +586,8 @@ out 1 1 - Gtk.Window + GtkWindow* + true 1 1 1 diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 337af08bd..2759e7d86 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -52,6 +52,8 @@ customs = \ Dialog.custom \ Entry.custom \ EntryCompletion.custom \ + FileChooser.custom \ + FileChooserButton.custom \ FileChooserDialog.custom \ FileChooserWidget.custom \ FileSelection.custom \