mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-06-19 08:47:50 +00:00
gtk: Switch to generic collections in some classes
This commit is contained in:
parent
df751f87ce
commit
6850b343ca
|
@ -23,7 +23,7 @@
|
||||||
namespace Gtk {
|
namespace Gtk {
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
public partial class IconTheme {
|
public partial class IconTheme {
|
||||||
|
@ -117,7 +117,7 @@ namespace Gtk {
|
||||||
{
|
{
|
||||||
IntPtr icon_name_as_native = GLib.Marshaller.StringToPtrGStrdup (icon_name);
|
IntPtr icon_name_as_native = GLib.Marshaller.StringToPtrGStrdup (icon_name);
|
||||||
IntPtr raw_ret = gtk_icon_theme_get_icon_sizes(Handle, icon_name_as_native);
|
IntPtr raw_ret = gtk_icon_theme_get_icon_sizes(Handle, icon_name_as_native);
|
||||||
ArrayList result = new ArrayList ();
|
var result = new List<int> ();
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int size = Marshal.ReadInt32 (raw_ret, offset);
|
int size = Marshal.ReadInt32 (raw_ret, offset);
|
||||||
while (size != 0) {
|
while (size != 0) {
|
||||||
|
@ -127,7 +127,7 @@ namespace Gtk {
|
||||||
}
|
}
|
||||||
GLib.Marshaller.Free (icon_name_as_native);
|
GLib.Marshaller.Free (icon_name_as_native);
|
||||||
GLib.Marshaller.Free (raw_ret);
|
GLib.Marshaller.Free (raw_ret);
|
||||||
return (int[]) result.ToArray (typeof (int));
|
return result.ToArray ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
gtk/Image.cs
14
gtk/Image.cs
|
@ -22,7 +22,7 @@
|
||||||
namespace Gtk {
|
namespace Gtk {
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
public partial class Image {
|
public partial class Image {
|
||||||
|
@ -33,13 +33,13 @@ namespace Gtk {
|
||||||
public Image (Gtk.IconSet icon_set, Gtk.IconSize size) : base (IntPtr.Zero)
|
public Image (Gtk.IconSet icon_set, Gtk.IconSize size) : base (IntPtr.Zero)
|
||||||
{
|
{
|
||||||
if (GetType () != typeof (Image)) {
|
if (GetType () != typeof (Image)) {
|
||||||
ArrayList vals = new ArrayList();
|
var vals = new List<GLib.Value> ();
|
||||||
ArrayList names = new ArrayList();
|
var names = new List<string> ();
|
||||||
names.Add ("icon_set");
|
names.Add ("icon_set");
|
||||||
vals.Add (new GLib.Value (icon_set));
|
vals.Add (new GLib.Value (icon_set));
|
||||||
names.Add ("icon_size");
|
names.Add ("icon_size");
|
||||||
vals.Add (new GLib.Value ((int)size));
|
vals.Add (new GLib.Value ((int)size));
|
||||||
CreateNativeObject ((string[])names.ToArray (typeof (string)), (GLib.Value[])vals.ToArray (typeof (GLib.Value)));
|
CreateNativeObject (names.ToArray (), vals.ToArray ());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Raw = gtk_image_new_from_icon_set(icon_set.Handle, (int) size);
|
Raw = gtk_image_new_from_icon_set(icon_set.Handle, (int) size);
|
||||||
|
@ -51,13 +51,13 @@ namespace Gtk {
|
||||||
public Image (string stock_id, Gtk.IconSize size) : base (IntPtr.Zero)
|
public Image (string stock_id, Gtk.IconSize size) : base (IntPtr.Zero)
|
||||||
{
|
{
|
||||||
if (GetType () != typeof (Image)) {
|
if (GetType () != typeof (Image)) {
|
||||||
ArrayList vals = new ArrayList();
|
var vals = new List<GLib.Value> ();
|
||||||
ArrayList names = new ArrayList();
|
var names = new List<string> ();
|
||||||
names.Add ("stock");
|
names.Add ("stock");
|
||||||
vals.Add (new GLib.Value (stock_id));
|
vals.Add (new GLib.Value (stock_id));
|
||||||
names.Add ("icon_size");
|
names.Add ("icon_size");
|
||||||
vals.Add (new GLib.Value ((int)size));
|
vals.Add (new GLib.Value ((int)size));
|
||||||
CreateNativeObject ((string[])names.ToArray (typeof (string)), (GLib.Value[])vals.ToArray (typeof (GLib.Value)));
|
CreateNativeObject (names.ToArray (), vals.ToArray ());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (stock_id);
|
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (stock_id);
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace Gtk {
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
@ -107,7 +108,7 @@ namespace Gtk {
|
||||||
if (tna != null)
|
if (tna != null)
|
||||||
list_only = tna.ListOnly;
|
list_only = tna.ListOnly;
|
||||||
|
|
||||||
ArrayList minfos = new ArrayList ();
|
var minfos = new List<MemberInfo> ();
|
||||||
|
|
||||||
foreach (PropertyInfo pi in type.GetProperties ())
|
foreach (PropertyInfo pi in type.GetProperties ())
|
||||||
foreach (TreeNodeValueAttribute attr in pi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false))
|
foreach (TreeNodeValueAttribute attr in pi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false))
|
||||||
|
@ -199,12 +200,12 @@ namespace Gtk {
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Gtk.TreeIter handling
|
#region Gtk.TreeIter handling
|
||||||
ArrayList gc_handles = new ArrayList ();
|
IList<GCHandle> gc_handles = new List<GCHandle> ();
|
||||||
|
|
||||||
protected override void Dispose (bool disposing)
|
protected override void Dispose (bool disposing)
|
||||||
{
|
{
|
||||||
// Free all the GCHandles pointing to the iters since they won't be garbage collected
|
// Free all the GCHandles pointing to the iters since they won't be garbage collected
|
||||||
foreach (System.Runtime.InteropServices.GCHandle handle in gc_handles)
|
foreach (GCHandle handle in gc_handles)
|
||||||
handle.Free ();
|
handle.Free ();
|
||||||
|
|
||||||
base.Dispose (disposing);
|
base.Dispose (disposing);
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
namespace Gtk {
|
namespace Gtk {
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
public partial class Widget {
|
public partial class Widget {
|
||||||
|
@ -134,10 +134,11 @@ namespace Gtk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* As gtk_binding_entry_add_signall only allows passing long, double and string parameters to the specified signal, we cannot pass a pointer to the BindingInvoker directly
|
/* As gtk_binding_entry_add_signall only allows passing long, double and string parameters
|
||||||
* to the signal. Instead, the signal takes the index of the BindingInvoker in binding_invokers.
|
* to the specified signal, we cannot pass a pointer to the BindingInvoker directly to the signal.
|
||||||
*/
|
* Instead, the signal takes the index of the BindingInvoker in binding_invokers.
|
||||||
static ArrayList binding_invokers;
|
*/
|
||||||
|
static IList<BindingInvoker> binding_invokers;
|
||||||
|
|
||||||
static void BindingMarshal_cb (IntPtr raw_closure, IntPtr return_val, uint n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
|
static void BindingMarshal_cb (IntPtr raw_closure, IntPtr return_val, uint n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
|
||||||
{
|
{
|
||||||
|
@ -148,7 +149,7 @@ namespace Gtk {
|
||||||
inst_and_params [idx] = (GLib.Value) Marshal.PtrToStructure (new IntPtr (param_values.ToInt64 () + idx * gvalue_size), typeof (GLib.Value));
|
inst_and_params [idx] = (GLib.Value) Marshal.PtrToStructure (new IntPtr (param_values.ToInt64 () + idx * gvalue_size), typeof (GLib.Value));
|
||||||
|
|
||||||
Widget w = inst_and_params [0].Val as Widget;
|
Widget w = inst_and_params [0].Val as Widget;
|
||||||
BindingInvoker invoker = binding_invokers [(int) (long) inst_and_params [1]] as BindingInvoker;
|
BindingInvoker invoker = binding_invokers [(int) (long) inst_and_params [1]];
|
||||||
invoker.Invoke (w);
|
invoker.Invoke (w);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
GLib.ExceptionManager.RaiseUnhandledException (e, false);
|
GLib.ExceptionManager.RaiseUnhandledException (e, false);
|
||||||
|
@ -197,7 +198,7 @@ namespace Gtk {
|
||||||
RegisterSignal (signame, gtype, GLib.Signal.Flags.RunLast | GLib.Signal.Flags.Action, GLib.GType.None, new GLib.GType[] {GLib.GType.Long}, BindingDelegate);
|
RegisterSignal (signame, gtype, GLib.Signal.Flags.RunLast | GLib.Signal.Flags.Action, GLib.GType.None, new GLib.GType[] {GLib.GType.Long}, BindingDelegate);
|
||||||
|
|
||||||
if (binding_invokers == null)
|
if (binding_invokers == null)
|
||||||
binding_invokers = new ArrayList ();
|
binding_invokers = new List<BindingInvoker> ();
|
||||||
|
|
||||||
foreach (BindingAttribute attr in attrs) {
|
foreach (BindingAttribute attr in attrs) {
|
||||||
System.Reflection.MethodInfo mi = t.GetMethod (attr.Handler, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
|
System.Reflection.MethodInfo mi = t.GetMethod (attr.Handler, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
|
||||||
|
@ -206,7 +207,10 @@ namespace Gtk {
|
||||||
|
|
||||||
GtkBindingArg arg = new GtkBindingArg ();
|
GtkBindingArg arg = new GtkBindingArg ();
|
||||||
arg.arg_type = GLib.GType.Long.Val;
|
arg.arg_type = GLib.GType.Long.Val;
|
||||||
int binding_invoker_idx = binding_invokers.Add (new BindingInvoker (mi, attr.Parms));
|
|
||||||
|
var bi = new BindingInvoker (mi, attr.Parms);
|
||||||
|
binding_invokers.Add (bi);
|
||||||
|
int binding_invoker_idx = binding_invokers.IndexOf (bi);
|
||||||
#if WIN64LONGS
|
#if WIN64LONGS
|
||||||
arg.data.long_data = binding_invoker_idx;
|
arg.data.long_data = binding_invoker_idx;
|
||||||
#else
|
#else
|
||||||
|
@ -296,15 +300,11 @@ namespace Gtk {
|
||||||
Path (out len, out path, out path_reversed);
|
Path (out len, out path, out path_reversed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static IDictionary<IntPtr, Delegate> destroy_handlers;
|
||||||
// Code from custom code for Gtk.Object in 2.x
|
static IDictionary<IntPtr, Delegate> DestroyHandlers {
|
||||||
// Object is gone in 3.x
|
|
||||||
|
|
||||||
static Hashtable destroy_handlers;
|
|
||||||
static Hashtable DestroyHandlers {
|
|
||||||
get {
|
get {
|
||||||
if (destroy_handlers == null)
|
if (destroy_handlers == null)
|
||||||
destroy_handlers = new Hashtable ();
|
destroy_handlers = new Dictionary<IntPtr, Delegate> ();
|
||||||
return destroy_handlers;
|
return destroy_handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ namespace Gtk {
|
||||||
[GLib.DefaultSignalHandler(Type=typeof(Gtk.Widget), ConnectionMethod="OverrideDestroyed")]
|
[GLib.DefaultSignalHandler(Type=typeof(Gtk.Widget), ConnectionMethod="OverrideDestroyed")]
|
||||||
protected virtual void OnDestroyed ()
|
protected virtual void OnDestroyed ()
|
||||||
{
|
{
|
||||||
if (DestroyHandlers.Contains (Handle)) {
|
if (DestroyHandlers.ContainsKey (Handle)) {
|
||||||
EventHandler handler = (EventHandler) DestroyHandlers [Handle];
|
EventHandler handler = (EventHandler) DestroyHandlers [Handle];
|
||||||
handler (this, EventArgs.Empty);
|
handler (this, EventArgs.Empty);
|
||||||
DestroyHandlers.Remove (Handle);
|
DestroyHandlers.Remove (Handle);
|
||||||
|
|
Loading…
Reference in a new issue