diff --git a/ChangeLog b/ChangeLog index 3919d4b58..3abe6d506 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-01-28 Dan Winship + + * glib/Object.cs (AddNotification, RemoveNotification): methods to + subscribe to the "notify" signal (with property details). [#71684] + + * glib/GLibSharp.voidObjectIntPtrSignal.cs: autogenerated, for + notifications + + * glib/NotifyHandler.cs: sort of autogenerated + 2005-01-28 Mike Kestner * gtk/Dialog.custom : add a params array for button info to the ctor. diff --git a/doc/ChangeLog b/doc/ChangeLog index b17931498..cdc25ec53 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2005-01-28 Dan Winship + + * en/GLib/NotifyArgs.xml: + * en/GLib/NotifyHandler.xml: + * en/GLib/Object.xml (AddNotification, RemoveNotification): document + 2005-01-18 Dan Winship * en/GLib/Marshaller.xml (StringFormat): document diff --git a/doc/en/GLib/NotifyArgs.xml b/doc/en/GLib/NotifyArgs.xml new file mode 100644 index 000000000..66046d4dd --- /dev/null +++ b/doc/en/GLib/NotifyArgs.xml @@ -0,0 +1,48 @@ + + + + glib-sharp + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] + 2.0.0.0 + neutral + + + Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. + + Event data. + + The method results in the invocation of delegates which pass event data via this class. + + + + GLib.SignalArgs + + + + + + + Constructor + + + + Public Constructor. + A new + + + + + + Property + + System.String + + + + The property that changed + a + + + + + \ No newline at end of file diff --git a/doc/en/GLib/NotifyHandler.xml b/doc/en/GLib/NotifyHandler.xml new file mode 100644 index 000000000..dbd70584f --- /dev/null +++ b/doc/en/GLib/NotifyHandler.xml @@ -0,0 +1,38 @@ + + + + glib-sharp + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] + 2.0.0.0 + neutral + + + Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. + + Represents a method that will handle a property notification event + + The handler is provided an value that contains + the event data (). + + + + System.Delegate + + + + System.ICloneable + + + System.Runtime.Serialization.ISerializable + + + + + + System.Void + + + + + + \ No newline at end of file diff --git a/doc/en/GLib/Object.xml b/doc/en/GLib/Object.xml index 6561df867..8a852e2b1 100644 --- a/doc/en/GLib/Object.xml +++ b/doc/en/GLib/Object.xml @@ -401,5 +401,69 @@ This method is called by the generated classes by the Gtk# framework. + + + Method + + System.Void + + + + + + + Request property-change notifications + the property to watch (the underlying GObject property name, not the managed wrapper property) + a to invoke when changes + This connects to the GObject "notify" signal with a detail argument of , to receive notifications when that property changes. + + + + + Method + + System.Void + + + + + + Request property-change notifications for all GObject properties + a to invoke when a GObject property changes + This connects to the GObject "notify" signal with no detail argument, to receive notifications when any property changes. + + + + + Method + + System.Void + + + + + + + Cancels property-change notifictions for the indicated property + the property + the + This disconnects from notifications for . + + + + + Method + + System.Void + + + + + + Cancels property-change notifications + the + This disconnects from generic property change notifications. (This only affects notifications created with the corresponding generic version of . It does not remove notifications for specific properties.) + + \ No newline at end of file diff --git a/glib/GLibSharp.voidObjectIntPtrSignal.cs b/glib/GLibSharp.voidObjectIntPtrSignal.cs new file mode 100644 index 000000000..6097a85ab --- /dev/null +++ b/glib/GLibSharp.voidObjectIntPtrSignal.cs @@ -0,0 +1,50 @@ +// copied from gtk/generated/GtkSharp.voidObjectIntPtrSignal.cs and renamespaced + +// This file was generated by the Gtk# code generator. +// Any changes made will be lost if regenerated. + +namespace GLibSharp { + + using System; + using System.Runtime.InteropServices; + + internal delegate void voidObjectIntPtrDelegate(IntPtr arg0, IntPtr arg1, int key); + + internal class voidObjectIntPtrSignal : GLib.SignalCallback { + + private static voidObjectIntPtrDelegate _Delegate; + + private static void voidObjectIntPtrCallback(IntPtr arg0, IntPtr arg1, int key) + { + if (!_Instances.Contains(key)) + throw new Exception("Unexpected signal key " + key); + + voidObjectIntPtrSignal inst = (voidObjectIntPtrSignal) _Instances[key]; + GLib.SignalArgs args = (GLib.SignalArgs) Activator.CreateInstance (inst._argstype); + args.Args = new object[1]; + args.Args[0] = arg1; + object[] argv = new object[2]; + argv[0] = inst._obj; + argv[1] = args; + inst._handler.DynamicInvoke(argv); + } + + public voidObjectIntPtrSignal(GLib.Object obj, string name, Delegate eh, Type argstype, int connect_flags) : base(obj, eh, argstype) + { + if (_Delegate == null) { + _Delegate = new voidObjectIntPtrDelegate(voidObjectIntPtrCallback); + } + Connect (name, _Delegate, connect_flags); + } + + protected override void Dispose (bool disposing) + { + _Instances.Remove(_key); + if(_Instances.Count == 0) + _Delegate = null; + + Disconnect (); + base.Dispose (disposing); + } + } +} diff --git a/glib/Makefile.am b/glib/Makefile.am index c2404ea34..141df3813 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -19,6 +19,7 @@ sources = \ EnumWrapper.cs \ FileUtils.cs \ GException.cs \ + GLibSharp.voidObjectIntPtrSignal.cs \ GString.cs \ Idle.cs \ IWrapper.cs \ @@ -31,6 +32,7 @@ sources = \ Markup.cs \ Marshaller.cs \ MissingIntPtrCtorException.cs \ + NotifyHandler.cs \ Object.cs \ ObjectManager.cs \ Opaque.cs \ diff --git a/glib/NotifyHandler.cs b/glib/NotifyHandler.cs new file mode 100644 index 000000000..f8f20ae5f --- /dev/null +++ b/glib/NotifyHandler.cs @@ -0,0 +1,35 @@ +// 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. + +namespace GLib { + + using System; + using System.Runtime.InteropServices; + + public delegate void NotifyHandler (object o, NotifyArgs args); + + public class NotifyArgs : GLib.SignalArgs { + [DllImport("libgobject-2.0-0.dll")] + static extern IntPtr g_param_spec_get_name (IntPtr pspec); + + public string Property { + get { + IntPtr raw_ret = g_param_spec_get_name ((IntPtr) Args[0]); + return Marshal.PtrToStringAnsi (raw_ret); + } + } + } +} diff --git a/glib/Object.cs b/glib/Object.cs index 13e933804..4ae68b2a7 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -280,6 +280,50 @@ namespace GLib { } } + void ConnectNotification (string signal, NotifyHandler handler) + { + if (AfterHandlers[signal] == null) + AfterSignals[signal] = new GLibSharp.voidObjectIntPtrSignal (this, signal, handler, typeof (NotifyArgs), 1); + else + ((GLib.SignalCallback) AfterSignals[signal]).AddDelegate (handler); + AfterHandlers.AddHandler (signal, handler); + } + + public void AddNotification (string property, NotifyHandler handler) + { + ConnectNotification ("notify::" + property, handler); + } + + public void AddNotification (NotifyHandler handler) + { + ConnectNotification ("notify", handler); + } + + void DisconnectNotification (string signal, NotifyHandler handler) + { + GLib.SignalCallback cb = AfterSignals[signal] as GLib.SignalCallback; + AfterHandlers.RemoveHandler (signal, handler); + + if (cb == null) + return; + cb.RemoveDelegate (handler); + + if (AfterHandlers[signal] == null) { + AfterSignals.Remove (signal); + cb.Dispose (); + } + } + + public void RemoveNotification (string property, NotifyHandler handler) + { + DisconnectNotification ("notify::" + property, handler); + } + + public void RemoveNotification (NotifyHandler handler) + { + DisconnectNotification ("notify", handler); + } + public override int GetHashCode () { return Handle.GetHashCode ();