From 9ad00bd8617ecd89d6d794f9da579896ed828923 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Mon, 7 Aug 2006 15:00:16 +0000 Subject: [PATCH] 2006-08-07 Mike Kestner * gtk/Gtk.metadata : markup for new Clipboard Rich text funcs. * gtk/Clipboard.custom : manually implement RequestRichText and WaitForRichText methods to deal with array marshaling and delegate persistence. svn path=/trunk/gtk-sharp/; revision=63430 --- ChangeLog | 7 +++ doc/en/Gtk/Clipboard+RichTextReceivedFunc.xml | 26 +++++++++ doc/en/Gtk/Clipboard.xml | 57 ++++++++++++++++++- gtk/Clipboard.custom | 49 ++++++++++++++++ gtk/Gtk.metadata | 3 + 5 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 doc/en/Gtk/Clipboard+RichTextReceivedFunc.xml diff --git a/ChangeLog b/ChangeLog index c5afdc1e5..b8b7b5708 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-08-07 Mike Kestner + + * gtk/Gtk.metadata : markup for new Clipboard Rich text funcs. + * gtk/Clipboard.custom : manually implement RequestRichText and + WaitForRichText methods to deal with array marshaling and delegate + persistence. + 2006-08-04 Mike Kestner * gtk/Gtk.metadata : a few tweaks to the 2.10 API found in doc/ diff --git a/doc/en/Gtk/Clipboard+RichTextReceivedFunc.xml b/doc/en/Gtk/Clipboard+RichTextReceivedFunc.xml new file mode 100644 index 000000000..8e50a5f06 --- /dev/null +++ b/doc/en/Gtk/Clipboard+RichTextReceivedFunc.xml @@ -0,0 +1,26 @@ + + + + gtk-sharp + 2.10.0.0 + + + System.Delegate + + + + + + + + System.Void + + + the sending clipboard. + format of the contents. + the contents as rich text. + Clipboard RichTextReceived Callback Delegate. + Provides the clipboard contents as rich text. See . + + + diff --git a/doc/en/Gtk/Clipboard.xml b/doc/en/Gtk/Clipboard.xml index 8cb7d227a..27ea4e7bd 100644 --- a/doc/en/Gtk/Clipboard.xml +++ b/doc/en/Gtk/Clipboard.xml @@ -21,8 +21,7 @@ GLib.Object - - + @@ -494,5 +493,59 @@ + + + Method + + System.Boolean + + + + + + a . + Tests if Rich Text is available for pasting. + if , rich text is available. + This method is slightly faster that since it doesn't retrieve the actual text. Uses the main loop, so events and timeouts may be dispatched during the wait. + + + + + + Method + + System.Byte[] + + + + + + + To be added. + To be added. + Requests contents as Rich Text. + a byte array holding the contents. + Uses the main loop, so events and timeouts may be dispatched during the wait. + + + + + + Method + + System.Void + + + + + + + a . + callback to invoke when data is prepared. + Requests the contents as Rich Text asynchronously. + + + + diff --git a/gtk/Clipboard.custom b/gtk/Clipboard.custom index ebf2a2496..4ae21f6fc 100644 --- a/gtk/Clipboard.custom +++ b/gtk/Clipboard.custom @@ -66,3 +66,52 @@ { Text = text; } + + [DllImport("libgtk-win32-2.0-0.dll")] + static extern IntPtr gtk_clipboard_wait_for_rich_text (IntPtr raw, IntPtr buffer, out IntPtr format, out UIntPtr length); + + public byte[] WaitForRichText(Gtk.TextBuffer buffer, out Gdk.Atom format) + { + UIntPtr length; + IntPtr format_as_native; + IntPtr raw_ret = gtk_clipboard_wait_for_rich_text (Handle, buffer == null ? IntPtr.Zero : buffer.Handle, out format_as_native, out length); + format = format_as_native == IntPtr.Zero ? null : (Gdk.Atom) GLib.Opaque.GetOpaque (format_as_native, typeof (Gdk.Atom), false); + if (raw_ret == IntPtr.Zero) + return new byte [0]; + int sz = (int) (uint) length; + byte[] ret = new byte [sz]; + Marshal.Copy (ret, 0, raw_ret, sz); + return ret; + } + + public delegate void RichTextReceivedFunc (Gtk.Clipboard clipboard, Gdk.Atom format, byte[] text); + + static RichTextReceivedFuncNative rt_rcvd_marshaler; + + [GLib.CDeclCallback] + delegate void RichTextReceivedFuncNative (IntPtr clipboard, IntPtr format, IntPtr text, UIntPtr length, IntPtr data); + + + void RichTextReceivedCallback (IntPtr clipboard_ptr, IntPtr format_ptr, IntPtr text_ptr, UIntPtr length, IntPtr data) + { + Gtk.Clipboard clipboard = GLib.Object.GetObject(clipboard_ptr) as Gtk.Clipboard; + Gdk.Atom format = format_ptr == IntPtr.Zero ? null : (Gdk.Atom) GLib.Opaque.GetOpaque (format_ptr, typeof (Gdk.Atom), false); + int sz = (int) (uint) length; + byte[] text = new byte [sz]; + Marshal.Copy (text, 0, text_ptr, sz); + GCHandle gch = (GCHandle) data; + RichTextReceivedFunc cb = gch.Target as RichTextReceivedFunc; + cb (clipboard, format, text); + gch.Free (); + } + + [DllImport("libgtk-win32-2.0-0.dll")] + static extern void gtk_clipboard_request_rich_text(IntPtr raw, IntPtr buffer, RichTextReceivedFuncNative cb, IntPtr user_data); + + public void RequestRichText (Gtk.TextBuffer buffer, RichTextReceivedFunc cb) + { + if (rt_rcvd_marshaler == null) + rt_rcvd_marshaler = new RichTextReceivedFuncNative (RichTextReceivedCallback); + gtk_clipboard_request_rich_text (Handle, buffer == null ? IntPtr.Zero : buffer.Handle, rt_rcvd_marshaler, (IntPtr) GCHandle.Alloc (cb)); + } + diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 69e2b7f48..9b15486b1 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -44,6 +44,7 @@ 1 1 true + 1 1 1 1 @@ -232,6 +233,8 @@ 1 1 true + 1 + 1 out 1 out