2006-08-07 Mike Kestner <mkestner@novell.com>

* 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
This commit is contained in:
Mike Kestner 2006-08-07 15:00:16 +00:00
parent 34e3227dfd
commit 9ad00bd861
5 changed files with 140 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2006-08-07 Mike Kestner <mkestner@novell.com>
* 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 <mkestner@novell.com>
* gtk/Gtk.metadata : a few tweaks to the 2.10 API found in doc/

View File

@ -0,0 +1,26 @@
<Type Name="Clipboard+RichTextReceivedFunc" FullName="Gtk.Clipboard+RichTextReceivedFunc">
<TypeSignature Language="C#" Value="public delegate void RichTextReceivedFunc(Gtk.Clipboard clipboard, Gdk.Atom format, byte[] text);" />
<AssemblyInfo>
<AssemblyName>gtk-sharp</AssemblyName>
<AssemblyVersion>2.10.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Delegate</BaseTypeName>
</Base>
<Parameters>
<Parameter Name="clipboard" Type="Gtk.Clipboard" />
<Parameter Name="format" Type="Gdk.Atom" />
<Parameter Name="text" Type="System.Byte[]" />
</Parameters>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Docs>
<param name="clipboard">the sending clipboard.</param>
<param name="format">format of the contents.</param>
<param name="text">the contents as rich text.</param>
<summary>Clipboard RichTextReceived Callback Delegate.</summary>
<remarks>Provides the clipboard contents as rich text. See <see cref="M:Gtk.Clipboard.RequestRichText" />.</remarks>
<since version="Gtk# 2.10" />
</Docs>
</Type>

View File

@ -21,8 +21,7 @@
<Base>
<BaseTypeName>GLib.Object</BaseTypeName>
</Base>
<Interfaces>
</Interfaces>
<Interfaces></Interfaces>
<Members>
<Member MemberName="Get">
<MemberSignature Language="C#" Value="public static Gtk.Clipboard Get (Gdk.Atom selection);" />
@ -494,5 +493,59 @@
<since version="Gtk# 2.6" />
</Docs>
</Member>
<Member MemberName="WaitIsRichTextAvailable">
<MemberSignature Language="C#" Value="public bool WaitIsRichTextAvailable (Gtk.TextBuffer buffer);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="buffer" Type="Gtk.TextBuffer" />
</Parameters>
<Docs>
<param name="buffer">a <see cref="T:Gtk.TextBuffer" />.</param>
<summary>Tests if Rich Text is available for pasting.</summary>
<returns>if <see langword="true" />, rich text is available.</returns>
<remarks>This method is slightly faster that <see cref="M:Gtk.Clipboard.WaitForRichText" /> since it doesn't retrieve the actual text. Uses the main loop, so events and timeouts may be dispatched during the wait.</remarks>
<since version="Gtk# 2.10" />
</Docs>
</Member>
<Member MemberName="WaitForRichText">
<MemberSignature Language="C#" Value="public byte[] WaitForRichText (Gtk.TextBuffer buffer, out Gdk.Atom format);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Byte[]</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="buffer" Type="Gtk.TextBuffer" />
<Parameter Name="format" Type="Gdk.Atom&amp;" RefType="out" />
</Parameters>
<Docs>
<param name="buffer">To be added.</param>
<param name="format">To be added.</param>
<summary>Requests contents as Rich Text.</summary>
<returns>a byte array holding the contents.</returns>
<remarks>Uses the main loop, so events and timeouts may be dispatched during the wait.</remarks>
<since version="Gtk# 2.10" />
</Docs>
</Member>
<Member MemberName="RequestRichText">
<MemberSignature Language="C#" Value="public void RequestRichText (Gtk.TextBuffer buffer, Gtk.Clipboard+RichTextReceivedFunc cb);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="buffer" Type="Gtk.TextBuffer" />
<Parameter Name="cb" Type="Gtk.Clipboard+RichTextReceivedFunc" />
</Parameters>
<Docs>
<param name="buffer">a <see cref="T:Gtk.TextBuffer" />.</param>
<param name="cb">callback to invoke when data is prepared.</param>
<summary>Requests the contents as Rich Text asynchronously.</summary>
<remarks />
<since version="Gtk# 2.10" />
</Docs>
</Member>
</Members>
</Type>

View File

@ -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));
}

View File

@ -44,6 +44,7 @@
<attr path="/api/namespace/boxed[@cname='GtkTreePath']/method[@name='Free']" name="deprecated">1</attr>
<attr path="/api/namespace/boxed[@cname='GtkTreeRowReference']/method[@name='Free']" name="deprecated">1</attr>
<attr path="/api/namespace/boxed[@cname='GtkTreeRowReference']/method[@name='GetPath']/return-type" name="owned">true</attr>
<attr path="/api/namespace/callback[@cname='GtkClipboardRichTextReceivedFunc']" name="hidden">1</attr>
<attr path="/api/namespace/callback[@cname='GtkItemFactoryCallback2']" name="hidden">1</attr>
<attr path="/api/namespace/callback[@cname='GtkModuleDisplayInitFunc']" name="hidden">1</attr>
<attr path="/api/namespace/callback[@cname='GtkModuleInitFunc']" name="hidden">1</attr>
@ -232,6 +233,8 @@
<attr path="/api/namespace/object[@cname='GtkClipboard']/method[@name='SetWithData']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkClipboard']/method[@name='SetWithOwner']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkClipboard']/method[@name='WaitForContents']/return-type" name="owned">true</attr>
<attr path="/api/namespace/object[@cname='GtkClipboard']/method[@name='WaitForRichText']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkClipboard']/method[@name='RequestRichText']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkColorButton']/method[@name='GetColor']/*/*[@name='color']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkColorSelection']/method[@name='GetColor']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkColorSelection']/method[@name='GetCurrentColor']/*/*[@name='color']" name="pass_as">out</attr>