* generator/StructBase.cs: create a Zero static member for

use when the IntPtr is NULL.

* generator/SignalHandler.cs, generator/CallbackGen.cs: removed
call to Initialize for structs

* gtk/Clipboard.custom, gtk/ClipboardClearFunc.cs,
gtk/ClipboardGetFunc.cs,
gtk/GtkSharp.GtkClipboardClearFuncNative.cs,
gtk/GtkSharp.ClipboardGetFuncNative.cs, SelectionData.custom:
Hand-wrapped selection handling stuff, along with relevant
signals and the like.

* gnome/voidObjectAffineSVPintSignal.cs: removed Initialize
for hand-wrapped signal

* sample/GnomeHelloWorld.cs, sample/Size.cs: compare against
.Zero instead of using IsNull

* api/gtk-api.xml, sources/Gtk.metadata: metadata updates for
hiding some manually-wrapped stuff

svn path=/trunk/gtk-sharp/; revision=8912
This commit is contained in:
Vladimir Vukicevic 2002-11-10 10:03:51 +00:00
parent aaf5594b36
commit 9ad6d1b6a4
18 changed files with 942 additions and 746 deletions

View file

@ -1,3 +1,27 @@
2002-11-10 Vladimir Vukicevic <vladimir@pobox.com>
* generator/StructBase.cs: create a Zero static member for
use when the IntPtr is NULL.
* generator/SignalHandler.cs, generator/CallbackGen.cs: removed
call to Initialize for structs
* gtk/Clipboard.custom, gtk/ClipboardClearFunc.cs,
gtk/ClipboardGetFunc.cs,
gtk/GtkSharp.GtkClipboardClearFuncNative.cs,
gtk/GtkSharp.ClipboardGetFuncNative.cs, SelectionData.custom:
Hand-wrapped selection handling stuff, along with relevant
signals and the like.
* gnome/voidObjectAffineSVPintSignal.cs: removed Initialize
for hand-wrapped signal
* sample/GnomeHelloWorld.cs, sample/Size.cs: compare against
.Zero instead of using IsNull
* api/gtk-api.xml, sources/Gtk.metadata: metadata updates for
hiding some manually-wrapped stuff
2002-11-10 Alejandro S<>nchez Acosta <raciel@es.gnu.org>
* sample/tutorial: added some examples for the gtk# tutorial

View file

@ -506,22 +506,6 @@
<parameter type="GtkArg*" name="args"/>
</parameters>
</callback>
<callback name="ClipboardClearFunc" cname="GtkClipboardClearFunc">
<return-type type="void"/>
<parameters>
<parameter type="GtkClipboard*" name="clipboard"/>
<parameter type="gpointer" name="user_data_or_owner"/>
</parameters>
</callback>
<callback name="ClipboardGetFunc" cname="GtkClipboardGetFunc">
<return-type type="void"/>
<parameters>
<parameter type="GtkClipboard*" name="clipboard"/>
<parameter type="GtkSelectionData*" name="selection_data"/>
<parameter type="guint" name="info"/>
<parameter type="gpointer" name="user_data_or_owner"/>
</parameters>
</callback>
<callback name="ClipboardReceivedFunc" cname="GtkClipboardReceivedFunc">
<return-type type="void"/>
<parameters>
@ -10487,26 +10471,6 @@
<parameter type="gint" name="len"/>
</parameters>
</method>
<method name="SetWithData" cname="gtk_clipboard_set_with_data">
<return-type type="gboolean"/>
<parameters>
<parameter type="const-GtkTargetEntry*" name="targets"/>
<parameter type="guint" name="n_targets"/>
<parameter type="GtkClipboardGetFunc" name="get_func"/>
<parameter type="GtkClipboardClearFunc" name="clear_func"/>
<parameter type="gpointer" name="user_data"/>
</parameters>
</method>
<method name="SetWithOwner" cname="gtk_clipboard_set_with_owner">
<return-type type="gboolean"/>
<parameters>
<parameter type="const-GtkTargetEntry*" name="targets"/>
<parameter type="guint" name="n_targets"/>
<parameter type="GtkClipboardGetFunc" name="get_func"/>
<parameter type="GtkClipboardClearFunc" name="clear_func"/>
<parameter type="GObject*" name="owner"/>
</parameters>
</method>
<method name="WaitForContents" cname="gtk_clipboard_wait_for_contents">
<return-type type="GtkSelectionData*"/>
<parameters>
@ -10809,28 +10773,9 @@
<parameter type="gint*" name="n_atoms"/>
</parameters>
</method>
<method name="GetText" cname="gtk_selection_data_get_text">
<return-type type="guchar*"/>
</method>
<method name="GetType" cname="gtk_selection_data_get_type" shared="true">
<return-type type="GType"/>
</method>
<method name="Set" cname="gtk_selection_data_set">
<return-type type="void"/>
<parameters>
<parameter type="GdkAtom" name="type"/>
<parameter type="gint" name="format"/>
<parameter type="const-guchar*" name="data"/>
<parameter type="gint" name="length"/>
</parameters>
</method>
<method name="SetText" cname="gtk_selection_data_set_text">
<return-type type="gboolean"/>
<parameters>
<parameter type="const-gchar*" name="str"/>
<parameter type="gint" name="len"/>
</parameters>
</method>
<method name="TargetsIncludeText" cname="gtk_selection_data_targets_include_text">
<return-type type="gboolean"/>
</method>

View file

@ -107,9 +107,6 @@ namespace GtkSharp.Generation {
string cstype = parms[i].CSType;
// FIXME: Too much code copy/pasted here. Refactor?
ClassBase parm_wrapper = SymbolTable.GetClassGen (ctype);
if (parm_wrapper != null && (parm_wrapper is StructBase)) {
sw.WriteLine("\t\t\t{0}._Initialize ();", parm_name);
}
sw.WriteLine("\t\t\t_args[" + idx + "] = " + SymbolTable.FromNative (ctype, parm_name) + ";");
if ((parm_wrapper != null && ((parm_wrapper is OpaqueGen))) || SymbolTable.IsManuallyWrapped (ctype)) {
sw.WriteLine("\t\t\tif (_args[" + idx + "] == null)");

View file

@ -143,8 +143,6 @@ namespace GtkSharp.Generation {
}
sw.WriteLine("\t\t\t}");
} else {
if (wrapper != null && (wrapper is StructBase))
sw.WriteLine("\t\t\targ{0}._Initialize ();", idx);
sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";");
}
}

View file

@ -235,24 +235,26 @@ namespace GtkSharp.Generation {
protected override void GenCtors (StreamWriter sw)
{
sw.WriteLine ("\t\tbool _is_null;");
sw.WriteLine ("\t\tpublic bool IsNull {");
sw.WriteLine ("\t\t\tget { return _is_null; }");
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t\tpublic void _Initialize () {");
sw.WriteLine ("\t\t\t_is_null = false;");
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t\tpublic static {0} Zero = new {0} ();", QualifiedName);
sw.WriteLine();
sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {");
sw.WriteLine ("\t\t\t{0} self = new {0}();", QualifiedName);
sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero) {");
sw.WriteLine ("\t\t\t\tself._is_null = true;");
sw.WriteLine ("\t\t\t} else {");
sw.WriteLine ("\t\t\t\tself = ({0}) Marshal.PtrToStructure (raw, self.GetType ());", QualifiedName);
sw.WriteLine ("\t\t\t\tself._is_null = false;");
sw.WriteLine ("\t\t\t\treturn {0}.Zero;", QualifiedName);
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t\t{0} self = new {0}();", QualifiedName);
sw.WriteLine ("\t\t\tself = ({0}) Marshal.PtrToStructure (raw, self.GetType ());", QualifiedName);
sw.WriteLine ("\t\t\treturn self;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static bool operator == ({0} a, {0} b)", QualifiedName);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn a.Equals (b);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static bool operator != ({0} a, {0} b)", QualifiedName);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\treturn ! a.Equals (b);");
sw.WriteLine ("\t\t}");
sw.WriteLine();
foreach (Ctor ctor in Ctors) {

View file

@ -16,6 +16,7 @@ BASESOURCES = \
type.c \
widget.c \
list.c \
clipboard.c \
#
GNOMESOURCES = \

56
glue/clipboard.c Normal file
View file

@ -0,0 +1,56 @@
/*
* clipboard.c
*/
#include <gtk/gtk.h>
GSList *
gtksharp_clipboard_target_list_add (GSList *list, char *target, guint flags, guint info)
{
GtkTargetEntry *entry = g_new0 (GtkTargetEntry, 1);
entry->target = g_strdup (target);
entry->flags = flags;
entry->info = info;
return g_slist_prepend (list, entry);
}
GtkTargetEntry *
gtksharp_clipboard_target_list_to_array (GSList *list)
{
GtkTargetEntry *targets;
GSList *iter;
int i;
targets = g_new0 (GtkTargetEntry, g_slist_length (list));
for (iter = list, i = 0; iter; iter = iter->next, i++) {
GtkTargetEntry *t = (GtkTargetEntry *) iter->data;
targets[i].target = t->target; /* NOT COPIED */
targets[i].flags = t->flags;
targets[i].info = t->info;
}
return targets;
}
void
gtksharp_clipboard_target_array_free (GtkTargetEntry *targets)
{
g_free (targets);
}
void
gtksharp_clipboard_target_list_free (GSList *list)
{
GSList *iter;
for (iter = list; iter; iter = iter->next) {
GtkTargetEntry *t = (GtkTargetEntry *) iter->data;
g_free (t->target);
g_free (t);
}
g_slist_free (list);
}

View file

@ -27,7 +27,7 @@ namespace Gnome {
} else {
args.Args[0] = null;
}
arg2._Initialize ();
args.Args[1] = arg2;
args.Args[2] = arg3;

54
gtk/Clipboard.custom Normal file
View file

@ -0,0 +1,54 @@
public static Hashtable clipboard_objects = new Hashtable ();
private static uint clipboard_object_next_id = 0;
[DllImport("gtk-x11-2.0")]
static extern bool gtk_clipboard_set_with_data(IntPtr raw, IntPtr targets, int n_targets, GtkSharp.GtkClipboardGetFuncNative get_func, GtkSharp.GtkClipboardClearFuncNative clear_func, uint id);
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_clipboard_target_list_add (IntPtr list, string name, uint flags, uint info);
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_clipboard_target_list_to_array (IntPtr list);
[DllImport("gtksharpglue")]
static extern void gtksharp_clipboard_target_array_free (IntPtr targets);
[DllImport("gtksharpglue")]
static extern void gtksharp_clipboard_target_list_free (IntPtr list);
GtkSharp.GtkClipboardGetFuncWrapper get_func_wrapper;
GtkSharp.GtkClipboardClearFuncWrapper clear_func_wrapper;
public bool Set (Gtk.TargetEntry[] targets,
Gtk.ClipboardGetFunc get_func,
Gtk.ClipboardClearFunc clear_func,
object data)
{
uint this_id;
lock (clipboard_objects) {
this_id = clipboard_object_next_id++;
clipboard_objects[this_id] = data;
}
get_func_wrapper = new GtkSharp.GtkClipboardGetFuncWrapper (get_func);
clear_func_wrapper = new GtkSharp.GtkClipboardClearFuncWrapper (clear_func);
IntPtr list = IntPtr.Zero;
foreach (Gtk.TargetEntry t in targets) {
list = gtksharp_clipboard_target_list_add (list, t.target, t.flags, t.info);
}
IntPtr array = gtksharp_clipboard_target_list_to_array (list);
bool ret = gtk_clipboard_set_with_data (Handle, array, targets.Length, get_func_wrapper.NativeDelegate, clear_func_wrapper.NativeDelegate, this_id);
gtksharp_clipboard_target_array_free (array);
gtksharp_clipboard_target_list_free (list);
return ret;
}

View file

@ -0,0 +1,8 @@
// Generated File. Do not modify.
// <c> 2001-2002 Mike Kestner
namespace Gtk {
public delegate void ClipboardClearFunc(Gtk.Clipboard clipboard, object o);
}

8
gtk/ClipboardGetFunc.cs Normal file
View file

@ -0,0 +1,8 @@
// Generated File. Do not modify.
// <c> 2001-2002 Mike Kestner
namespace Gtk {
public delegate void ClipboardGetFunc(Gtk.Clipboard clipboard, ref Gtk.SelectionData selection_data, uint info, object o);
}

View file

@ -0,0 +1,31 @@
namespace GtkSharp {
using System;
using System.Collections;
public delegate void GtkClipboardClearFuncNative(IntPtr clipboard, uint objid);
public class GtkClipboardClearFuncWrapper : GLib.DelegateWrapper {
public void NativeCallback (IntPtr clipboard, uint objid)
{
object[] _args = new object[2];
_args[0] = (Gtk.Clipboard) GLib.Opaque.GetOpaque(clipboard);
if (_args[0] == null)
_args[0] = new Gtk.Clipboard(clipboard);
_args[1] = Gtk.Clipboard.clipboard_objects[objid];
_managed ((Gtk.Clipboard) _args[0], _args[1]);
Gtk.Clipboard.clipboard_objects.Remove (objid);
}
public GtkClipboardClearFuncNative NativeDelegate;
protected Gtk.ClipboardClearFunc _managed;
public GtkClipboardClearFuncWrapper (Gtk.ClipboardClearFunc managed) : base ()
{
NativeDelegate = new GtkClipboardClearFuncNative (NativeCallback);
_managed = managed;
}
}
}

View file

@ -0,0 +1,33 @@
namespace GtkSharp {
using System;
using System.Collections;
public delegate void GtkClipboardGetFuncNative(IntPtr clipboard, ref Gtk.SelectionData selection_data, uint info, uint obj_id);
public class GtkClipboardGetFuncWrapper : GLib.DelegateWrapper {
public void NativeCallback (IntPtr clipboard, ref Gtk.SelectionData selection_data, uint info, uint obj_id)
{
object[] _args = new object[4];
_args[0] = (Gtk.Clipboard) GLib.Opaque.GetOpaque(clipboard);
if (_args[0] == null)
_args[0] = new Gtk.Clipboard(clipboard);
_args[1] = selection_data;
_args[2] = info;
_args[3] = Gtk.Clipboard.clipboard_objects[obj_id];
_managed ((Gtk.Clipboard) _args[0], ref selection_data, (uint) _args[2], _args[3]);
}
public GtkClipboardGetFuncNative NativeDelegate;
protected Gtk.ClipboardGetFunc _managed;
public GtkClipboardGetFuncWrapper (Gtk.ClipboardGetFunc managed) : base ()
{
NativeDelegate = new GtkClipboardGetFuncNative (NativeCallback);
_managed = managed;
}
}
}

View file

@ -6,23 +6,19 @@
//
// This code is inserted after the automatically generated code.
[DllImport("gtksharpglue")]
static extern void gtksharp_object_unref_if_floating (IntPtr raw);
private static extern bool gtksharp_object_is_floating (IntPtr raw);
protected override void DisposeNative ()
{
if (_needs_unref)
base.DisposeNative ();
else
gtksharp_object_unref_if_floating (Handle);
protected override IntPtr Raw {
get {
return base.Raw;
}
set {
base.Raw = value;
if (!needs_ref && gtksharp_object_is_floating (value)) {
Ref ();
Sink ();
}
// System.Diagnostics.Debug.WriteLine ("Gtk.Object:set_Raw: object type is: " + (this as GLib.Object).GType.Name + " refcount now: " + RefCount + " needs_ref: " + needs_ref);
}
}
private bool _needs_unref = false;
public override void Ref ()
{
_needs_unref = true;
base.Ref ();
}

29
gtk/SelectionData.custom Normal file
View file

@ -0,0 +1,29 @@
[DllImport("gtk-x11-2.0")]
private static extern string gtk_selection_data_get_text (ref Gtk.SelectionData selection_data);
[DllImport("gtk-x11-2.0")]
private static extern void gtk_selection_data_set_text (ref Gtk.SelectionData selection_data, string str, int len);
public string Text {
get {
return gtk_selection_data_get_text (ref this);
}
set {
gtk_selection_data_set_text (ref this, value, value.Length);
}
}
[DllImport("gtk-x11-2.0")]
static extern void gtk_selection_data_set (ref Gtk.SelectionData raw, IntPtr type, int format, byte[] data, int length);
public byte[] Data {
get {
byte[] ret = new byte[length];
Marshal.Copy (_data, ret, 0, length);
return ret;
}
set {
gtk_selection_data_set (ref this, _type, format, value, value.Length);
}
}

View file

@ -161,7 +161,7 @@ namespace GtkSamples {
if (type != Gdk.WindowType.Child)
Console.WriteLine ("Struct field accessors appear to be broken.");
if (!ev.IsNull && ev.type == EventType.TwoButtonPress && ev.button == 1) {
if ((ev != Gdk.EventButton.Zero) && ev.type == EventType.TwoButtonPress && ev.button == 1) {
g_spawn_command_line_async ("mono " + entries[idx].program, IntPtr.Zero);
}
}

View file

@ -34,7 +34,7 @@ namespace GtkSamples {
static void Size_Allocated (object obj, SizeAllocatedArgs args)
{
Gdk.Rectangle rect = args.Allocation;
if (rect.IsNull)
if (rect == Gdk.Rectangle.Zero)
Console.WriteLine ("ERROR: Allocation is null!");
Console.WriteLine ("Size: ({0}, {1})", rect.width, rect.height);
}

View file

@ -1286,6 +1286,19 @@
</attribute>
</data>
</rule>
<rule>
<class name="GtkSelectionData">
<method>GetText</method>
<method>SetText</method>
<method>Set</method>
</class>
<data>
<attribute target="method">
<name>hidden</name>
<value>1</value>
</attribute>
</data>
</rule>
<!-- overloads -->
<rule>
@ -1854,7 +1867,7 @@
<!-- reference rules -->
<rule>
<class name="GtkWidget">
<!-- <class name="GtkWidget">
<method>GetStyle</method>
<method>GetModifierStyle</method>
<method>GetDefaultStyle</method>
@ -1870,6 +1883,7 @@
<value>1</value>
</attribute>
</data>
-->
</rule>