diff --git a/README.md b/README.md index 6315ece20..eb30863c0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://dev.azure.com/cra0zy/GtkSharp/_apis/build/status/GtkSharp.GtkSharp?branchName=develop)](https://dev.azure.com/cra0zy/GtkSharp/_build/latest?definitionId=1&branchName=develop) -GtkSharp is a C# wrapper for Gtk and its related components. The component list includes the following libraries: glib, gio, cairo, pango, atk, gdk. This is a fork of https://github.com/mono/gtk-sharp and is maintained completly separatly from that project. +GtkSharp is a C# wrapper for Gtk and its related components. The component list includes the following libraries: glib, gio, cairo, pango, atk, gdk. This is a fork of https://github.com/mono/gtk-sharp and is maintained completely separately from that project. Differences can be seen with the following table: diff --git a/Source/Libs/AtkSharp/AtkSharp.metadata b/Source/Libs/AtkSharp/AtkSharp.metadata index b01be8585..b13138c16 100644 --- a/Source/Libs/AtkSharp/AtkSharp.metadata +++ b/Source/Libs/AtkSharp/AtkSharp.metadata @@ -37,8 +37,6 @@ 1 AtkAttribute* AtkAttribute* - AtkAttribute* - AtkAttribute* diff --git a/Source/Libs/GLibSharp/GException.cs b/Source/Libs/GLibSharp/GException.cs index 4160b0bb0..0c76244dd 100644 --- a/Source/Libs/GLibSharp/GException.cs +++ b/Source/Libs/GLibSharp/GException.cs @@ -26,11 +26,15 @@ namespace GLib { public class GException : Exception { - IntPtr errptr; - - public GException (IntPtr errptr) : base () + string msg; + + public GException (IntPtr errptr) { - this.errptr = errptr; + var err = (GError)Marshal.PtrToStructure(errptr, typeof(GError)); + Domain = err.Domain; + Code = err.Code; + msg = Marshaller.Utf8PtrToString(err.Msg); + g_clear_error(ref errptr); } struct GError { @@ -39,34 +43,14 @@ namespace GLib { public IntPtr Msg; } - public int Code { - get { - GError err = (GError) Marshal.PtrToStructure (errptr, typeof (GError)); - return err.Code; - } - } + public int Code { get; private set; } - public int Domain { - get { - GError err = (GError) Marshal.PtrToStructure (errptr, typeof (GError)); - return err.Domain; - } - } + public int Domain { get; private set; } + + public override string Message => msg; - public override string Message { - get { - GError err = (GError) Marshal.PtrToStructure (errptr, typeof (GError)); - return Marshaller.Utf8PtrToString (err.Msg); - } - } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_clear_error(ref IntPtr errptr); static d_g_clear_error g_clear_error = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_clear_error")); - ~GException () - { - g_clear_error (ref errptr); - } } } - - diff --git a/Source/Libs/GLibSharp/Idle.cs b/Source/Libs/GLibSharp/Idle.cs index bbdde15f4..db65c5205 100644 --- a/Source/Libs/GLibSharp/Idle.cs +++ b/Source/Libs/GLibSharp/Idle.cs @@ -54,7 +54,7 @@ namespace GLib { { lock (this) { - Remove (); + Dispose(); } } return cont; diff --git a/Source/Libs/GLibSharp/Object.cs b/Source/Libs/GLibSharp/Object.cs index 3ab7f12f1..833b8e513 100644 --- a/Source/Libs/GLibSharp/Object.cs +++ b/Source/Libs/GLibSharp/Object.cs @@ -33,7 +33,7 @@ namespace GLib { IntPtr handle; ToggleRef tref; - bool disposed = false; + bool disposed; static uint idx = 1; static Dictionary Objects = new Dictionary(); static Dictionary> PropertiesToSet = new Dictionary>(); @@ -41,7 +41,7 @@ namespace GLib { ~Object () { if (WarnOnFinalize) - Console.Error.WriteLine ("Unexpected finalization of " + GetType() + " instance. Consider calling Dispose."); + Console.Error.WriteLine ("Unexpected finalization of " + GetType() + " instance. Consider calling Dispose. (" + handle.ToInt64 () + ")"); Dispose (false); } @@ -51,9 +51,10 @@ namespace GLib { if (disposed) return; + GC.SuppressFinalize (this); + Dispose (true); disposed = true; - GC.SuppressFinalize (this); } protected virtual void Dispose (bool disposing) @@ -70,19 +71,25 @@ namespace GLib { return; if (disposing) - tref.Dispose (); - else - tref.QueueUnref (); - - // Free all internal signals, else the garbage collector is not - // able to free the object. - if (signals != null) { - foreach (var sig in signals.Keys) - signals[sig].Free (); + tref.Dispose (); + + if (signals != null) + { + foreach (var sig in signals.Keys) + signals[sig].Free (); + } + } + else + { + if (signals != null) + QueueSignalFree (); + + tref.QueueUnref (); } signals = null; + disposed = true; } public static bool WarnOnFinalize { get; set; } @@ -807,6 +814,9 @@ namespace GLib { GLib.Marshaller.Free (native_name); } + public static List PendingSignalFrees = new List (); + static bool idle_queued; + Dictionary signals; Dictionary Signals { get { @@ -853,6 +863,34 @@ namespace GLib { sig.RemoveDelegate (handler); } + public void QueueSignalFree () + { + lock (PendingSignalFrees) { + PendingSignalFrees.AddRange (signals.Values); + if (!idle_queued){ + Timeout.Add (50, new TimeoutHandler (PerformQueuedSignalFrees)); + idle_queued = true; + } + } + } + + static bool PerformQueuedSignalFrees () + { + Signal[] qsignals; + + lock (PendingSignalFrees){ + qsignals = new Signal[PendingSignalFrees.Count]; + PendingSignalFrees.CopyTo (qsignals, 0); + PendingSignalFrees.Clear (); + idle_queued = false; + } + + foreach (Signal s in qsignals) + s.Free (); + + return false; + } + protected static void OverrideVirtualMethod (GType gtype, string name, Delegate cb) { Signal.OverrideDefaultHandler (gtype, name, cb); diff --git a/Source/Libs/GLibSharp/Signal.cs b/Source/Libs/GLibSharp/Signal.cs index 2d152434f..dd94e6c38 100644 --- a/Source/Libs/GLibSharp/Signal.cs +++ b/Source/Libs/GLibSharp/Signal.cs @@ -211,11 +211,10 @@ namespace GLib { public Delegate Handler { get { - InvocationHint hint = (InvocationHint) Marshal.PtrToStructure (g_signal_get_invocation_hint (obj.Handle), typeof (InvocationHint)); - if (hint.run_type == Flags.RunFirst) - return before_handler; - else - return after_handler; + var hint = (InvocationHint) Marshal.PtrToStructure (g_signal_get_invocation_hint (obj.Handle), typeof (InvocationHint)); + return hint.run_type.HasFlag(Flags.RunFirst) + ? before_handler + : after_handler; } } diff --git a/Source/Libs/GLibSharp/Timeout.cs b/Source/Libs/GLibSharp/Timeout.cs index 8e17e464d..4f3ca34b3 100644 --- a/Source/Libs/GLibSharp/Timeout.cs +++ b/Source/Libs/GLibSharp/Timeout.cs @@ -52,7 +52,7 @@ namespace GLib { { lock (this) { - Remove (); + Dispose(); } } return cont; diff --git a/Source/Libs/GLibSharp/ToggleRef.cs b/Source/Libs/GLibSharp/ToggleRef.cs index 20517ac99..432257f69 100644 --- a/Source/Libs/GLibSharp/ToggleRef.cs +++ b/Source/Libs/GLibSharp/ToggleRef.cs @@ -71,8 +71,12 @@ namespace GLib { g_object_unref (handle); else g_object_remove_toggle_ref (handle, ToggleNotifyCallback, (IntPtr) gch); + reference = null; - gch.Free (); + + QueueGCHandleFree (); + + handle = IntPtr.Zero; } internal void Harden () @@ -97,7 +101,8 @@ namespace GLib { reference = new WeakReference (reference); else if (!is_last_ref && reference is WeakReference) { WeakReference weak = reference as WeakReference; - reference = weak.Target; + if (weak.IsAlive) + reference = weak.Target; } } @@ -124,6 +129,37 @@ namespace GLib { } } + static List PendingGCHandleFrees = new List (); + static bool gc_idle_queued; + + public void QueueGCHandleFree () + { + lock (PendingGCHandleFrees) { + PendingGCHandleFrees.Add (gch); + if (!gc_idle_queued){ + Timeout.Add (50, new TimeoutHandler (PerformGCHandleFrees)); + gc_idle_queued = true; + } + } + } + + static bool PerformGCHandleFrees () + { + GCHandle[] handles; + + lock (PendingGCHandleFrees){ + handles = new GCHandle [PendingGCHandleFrees.Count]; + PendingGCHandleFrees.CopyTo (handles, 0); + PendingGCHandleFrees.Clear (); + gc_idle_queued = false; + } + + foreach (GCHandle r in handles) + r.Free (); + + return false; + } + static List PendingDestroys = new List (); static bool idle_queued; diff --git a/Source/Libs/GdkSharp/GdkSharp.metadata b/Source/Libs/GdkSharp/GdkSharp.metadata index 47463959f..8d937d577 100644 --- a/Source/Libs/GdkSharp/GdkSharp.metadata +++ b/Source/Libs/GdkSharp/GdkSharp.metadata @@ -76,6 +76,9 @@ false 1 1 + GdkSeat* + true + false GetSupportsComposite GetSupportsInputShapes GetSupportsShapes @@ -84,8 +87,15 @@ 1 1 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 1 + 1 + 1 1 1 true @@ -94,6 +104,7 @@ 1 1 1 + 1 1 1 1 @@ -104,6 +115,9 @@ true true true + 1 + 1 + 1 1 1 out @@ -117,10 +131,21 @@ GdkWindow* true true - 1 GdkWindow* true true + + + + + + + GdkDevice* + true + false + GdkDevice* + true + false 1 1 1 @@ -160,14 +185,10 @@ 1 1 1 - 1 - 1 - 1 GdkSeat 128 - diff --git a/Source/Libs/GdkSharp/Pixbuf.cs b/Source/Libs/GdkSharp/Pixbuf.cs index d438da592..cba3df10a 100644 --- a/Source/Libs/GdkSharp/Pixbuf.cs +++ b/Source/Libs/GdkSharp/Pixbuf.cs @@ -39,6 +39,48 @@ namespace Gdk { public partial class Pixbuf { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_gdk_pixbuf_new_from_file(IntPtr filename, out IntPtr error); + static d_gdk_pixbuf_new_from_file gdk_pixbuf_new_from_file = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), + FuncLoader.IsWindows ? "gdk_pixbuf_new_from_file_utf8" : "gdk_pixbuf_new_from_file")); + + public Pixbuf(string filename) : base(IntPtr.Zero) + { + IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup(filename); + IntPtr error = IntPtr.Zero; + Raw = gdk_pixbuf_new_from_file(native_filename, out error); + GLib.Marshaller.Free(native_filename); + if (error != IntPtr.Zero) throw new GLib.GException(error); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_gdk_pixbuf_new_from_file_at_scale(IntPtr filename, int width, int height, bool preserve_aspect_ratio, out IntPtr error); + static d_gdk_pixbuf_new_from_file_at_scale gdk_pixbuf_new_from_file_at_scale = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), + FuncLoader.IsWindows ? "gdk_pixbuf_new_from_file_at_scale_utf8" : "gdk_pixbuf_new_from_file_at_scale")); + + public Pixbuf(string filename, int width, int height, bool preserve_aspect_ratio) : base(IntPtr.Zero) + { + IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup(filename); + IntPtr error = IntPtr.Zero; + Raw = gdk_pixbuf_new_from_file_at_scale(native_filename, width, height, preserve_aspect_ratio, out error); + GLib.Marshaller.Free(native_filename); + if (error != IntPtr.Zero) throw new GLib.GException(error); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_gdk_pixbuf_new_from_file_at_size(IntPtr filename, int width, int height, out IntPtr error); + static d_gdk_pixbuf_new_from_file_at_size gdk_pixbuf_new_from_file_at_size = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), + FuncLoader.IsWindows ? "gdk_pixbuf_new_from_file_at_size_utf8" : "gdk_pixbuf_new_from_file_at_size")); + + public Pixbuf(string filename, int width, int height) : base(IntPtr.Zero) + { + IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup(filename); + IntPtr error = IntPtr.Zero; + Raw = gdk_pixbuf_new_from_file_at_size(native_filename, width, height, out error); + GLib.Marshaller.Free(native_filename); + if (error != IntPtr.Zero) throw new GLib.GException(error); + } + public Pixbuf (System.IO.Stream stream) : base (IntPtr.Zero) { using (PixbufLoader pl = new PixbufLoader (stream)) { @@ -202,12 +244,12 @@ namespace Gdk { delegate IntPtr d_gdk_pixbuf_get_pixels(IntPtr raw); static d_gdk_pixbuf_get_pixels gdk_pixbuf_get_pixels = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), "gdk_pixbuf_get_pixels")); - public IntPtr Pixels { - get { - IntPtr ret = gdk_pixbuf_get_pixels (Handle); - return ret; - } - } + public IntPtr Pixels { + get { + IntPtr ret = gdk_pixbuf_get_pixels (Handle); + return ret; + } + } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_gdk_pixbuf_get_formats(); static d_gdk_pixbuf_get_formats gdk_pixbuf_get_formats = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), "gdk_pixbuf_get_formats")); @@ -226,7 +268,8 @@ namespace Gdk { } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_gdk_pixbuf_save(IntPtr raw, IntPtr filename, IntPtr type, out IntPtr error, IntPtr dummy); - static d_gdk_pixbuf_save gdk_pixbuf_save = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), "gdk_pixbuf_save")); + static d_gdk_pixbuf_save gdk_pixbuf_save = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), + FuncLoader.IsWindows ? "gdk_pixbuf_save_utf8" : "gdk_pixbuf_save")); public unsafe bool Save(string filename, string type) { IntPtr error = IntPtr.Zero; @@ -312,7 +355,8 @@ namespace Gdk { } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_gdk_pixbuf_savev(IntPtr raw, IntPtr filename, IntPtr type, IntPtr[] option_keys, IntPtr[] option_values, out IntPtr error); - static d_gdk_pixbuf_savev gdk_pixbuf_savev = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), "gdk_pixbuf_savev")); + static d_gdk_pixbuf_savev gdk_pixbuf_savev = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), + FuncLoader.IsWindows ? "gdk_pixbuf_savev_utf8" : "gdk_pixbuf_savev")); public unsafe bool Savev(string filename, string type, string[] option_keys, string[] option_values) { IntPtr error = IntPtr.Zero; @@ -332,5 +376,3 @@ namespace Gdk { } } } - - diff --git a/Source/Libs/GdkSharp/PixbufAnimation.cs b/Source/Libs/GdkSharp/PixbufAnimation.cs index 0a950e2cb..721ebe91e 100644 --- a/Source/Libs/GdkSharp/PixbufAnimation.cs +++ b/Source/Libs/GdkSharp/PixbufAnimation.cs @@ -21,9 +21,24 @@ namespace Gdk { using System; + using System.Runtime.InteropServices; public partial class PixbufAnimation { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_gdk_pixbuf_animation_new_from_file(IntPtr filename, out IntPtr error); + static d_gdk_pixbuf_animation_new_from_file gdk_pixbuf_animation_new_from_file = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), + FuncLoader.IsWindows ? "gdk_pixbuf_animation_new_from_file_utf8" : "gdk_pixbuf_animation_new_from_file")); + + public PixbufAnimation(string filename) : base(IntPtr.Zero) + { + IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup(filename); + IntPtr error = IntPtr.Zero; + Raw = gdk_pixbuf_animation_new_from_file(native_filename, out error); + GLib.Marshaller.Free(native_filename); + if (error != IntPtr.Zero) throw new GLib.GException(error); + } + public PixbufAnimation (System.IO.Stream stream) : base (new PixbufLoader (stream).AnimationHandle) {} public PixbufAnimation (System.Reflection.Assembly assembly, string resource) : base (IntPtr.Zero) diff --git a/Source/Libs/GdkSharp/PixbufLoader.cs b/Source/Libs/GdkSharp/PixbufLoader.cs index 01d36ff35..faf2899e4 100644 --- a/Source/Libs/GdkSharp/PixbufLoader.cs +++ b/Source/Libs/GdkSharp/PixbufLoader.cs @@ -33,7 +33,7 @@ namespace Gdk { internal IntPtr PixbufHandle { get { - return gdk_pixbuf_loader_get_pixbuf (Handle); + return g_object_ref (gdk_pixbuf_loader_get_pixbuf (Handle)); } } diff --git a/Source/Libs/GioSharp/GioSharp.metadata b/Source/Libs/GioSharp/GioSharp.metadata index d3c96ce4d..a7d1b8cbc 100644 --- a/Source/Libs/GioSharp/GioSharp.metadata +++ b/Source/Libs/GioSharp/GioSharp.metadata @@ -54,6 +54,12 @@ EmitActionEnabledChanged EmitActionRemoved EmitActionStateChanged + true + true + true + true + true + true 1 GetCanRemoveSupportsType 1 diff --git a/Source/Libs/GtkSharp/Builder.cs b/Source/Libs/GtkSharp/Builder.cs index c09fff6cd..9e6234d5c 100644 --- a/Source/Libs/GtkSharp/Builder.cs +++ b/Source/Libs/GtkSharp/Builder.cs @@ -151,6 +151,16 @@ namespace Gtk { GLib.Marshaller.Free (native_name); return raw_ret; } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_g_object_ref(IntPtr raw); + static d_g_object_ref g_object_ref = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_object_ref")); + + public IntPtr GetRawOwnedObject(string name) { + IntPtr raw_ret = GetRawObject (name); + g_object_ref (raw_ret); + return raw_ret; + } public Builder (System.IO.Stream s) : this (s, null) { diff --git a/Source/Libs/GtkSharp/CssProvider.cs b/Source/Libs/GtkSharp/CssProvider.cs new file mode 100644 index 000000000..764498150 --- /dev/null +++ b/Source/Libs/GtkSharp/CssProvider.cs @@ -0,0 +1,27 @@ +namespace Gtk +{ + using System; + using System.IO; + using System.Reflection; + + public partial class CssProvider + { + public bool LoadFromResource(string resource) => LoadFromResource(Assembly.GetCallingAssembly(), resource); + + public bool LoadFromResource(Assembly assembly, string resource) + { + if (assembly == null) + assembly = Assembly.GetCallingAssembly(); + + Stream stream = assembly.GetManifestResourceStream(resource); + if (stream == null) + throw new ArgumentException("'" + resource + "' is not a valid resource name of assembly '" + assembly + "'.", nameof(resource)); + + using (var reader = new StreamReader(stream)) + { + string data = reader.ReadToEnd(); + return LoadFromData(data); + } + } + } +} diff --git a/Source/Libs/GtkSharp/GtkSharp-api.xml b/Source/Libs/GtkSharp/GtkSharp-api.xml index 39d1d8127..86f5d3f4f 100644 --- a/Source/Libs/GtkSharp/GtkSharp-api.xml +++ b/Source/Libs/GtkSharp/GtkSharp-api.xml @@ -28289,7 +28289,6 @@ - diff --git a/Source/Libs/GtkSharp/GtkSharp.metadata b/Source/Libs/GtkSharp/GtkSharp.metadata index 65bcdb2ba..eeaf32495 100644 --- a/Source/Libs/GtkSharp/GtkSharp.metadata +++ b/Source/Libs/GtkSharp/GtkSharp.metadata @@ -12,7 +12,6 @@ 1 1 1 - 1 1 1 1 @@ -50,7 +49,9 @@ 1 1 1 + 1 1 + 1 1 1 true @@ -75,7 +76,6 @@ GetEventsPending const-gchar* 1 - 1 1 1 1 @@ -104,7 +104,6 @@ CornerBottomLeft | CornerBottomRight CornerTopLeft | CornerBottomLeft CornerTopRight | CornerBottomRight - 1 1 1 1 @@ -280,7 +279,6 @@ call call GtkCellRenderer* - AttributesApplied 1 1 GdkRGBA @@ -364,6 +362,8 @@ 1 + out + out Activated ClipboardCopied ClipboardCut @@ -375,11 +375,18 @@ SelectedAll UnselectedAll + call + GtkFlowBoxChild* + false + true GtkButton* GtkButton* 1 1 1 + GdkEventSequence* + false + true 1 1 IsChildDetached @@ -454,6 +461,10 @@ SelectedAll UnselectedAll ListRowActivated + call + GtkListBoxRow* + false + true 1 1 out @@ -494,6 +505,9 @@ ShowedConnectToServer ShowEnteredLocation ShowedOtherLocations + GFile* + true + true 1 1 IsEmbedded @@ -643,7 +657,6 @@ SetIcon GetIcon Icon - out 1 out out @@ -852,6 +865,7 @@ 1 1 ProcessEvent + out out out out @@ -860,7 +874,6 @@ GetWidgetPath out GetIsRealized - out GetHasDefault GetHasFocus out @@ -904,6 +917,7 @@ out 1 out + out out 1 1 @@ -942,8 +956,6 @@ slider_detail StepperDetail - gchar* - stepper_detail 1 1 @@ -952,10 +964,6 @@ 1 1 1 - 1 - 1 - 1 - 1 1 1 1 @@ -977,7 +985,6 @@ 1 1 1 - 1 1 out @@ -1006,6 +1013,12 @@ + async + async + async + + 1 + true true @@ -1101,5 +1114,4 @@ true true - diff --git a/Source/Libs/GtkSharp/GtkSharp.targets b/Source/Libs/GtkSharp/GtkSharp.targets index 584761cb3..73d013aca 100644 --- a/Source/Libs/GtkSharp/GtkSharp.targets +++ b/Source/Libs/GtkSharp/GtkSharp.targets @@ -1,8 +1,8 @@ - https://github.com/GtkSharp/Dependencies/raw/master/gtk-3.24.20.zip - $(LOCALAPPDATA)\Gtk\3.24.20 + https://github.com/GtkSharp/Dependencies/raw/master/gtk-3.24.24.zip + $(LOCALAPPDATA)\Gtk\3.24.24 diff --git a/Source/Libs/GtkSharp/MessageDialog.cs b/Source/Libs/GtkSharp/MessageDialog.cs index 5034aa5ad..f3cce9270 100644 --- a/Source/Libs/GtkSharp/MessageDialog.cs +++ b/Source/Libs/GtkSharp/MessageDialog.cs @@ -26,7 +26,7 @@ namespace Gtk { delegate IntPtr d_gtk_message_dialog_new_with_markup(IntPtr parent_window, DialogFlags flags, MessageType type, ButtonsType bt, IntPtr msg, IntPtr args); static d_gtk_message_dialog_new_with_markup gtk_message_dialog_new_with_markup = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_message_dialog_new_with_markup")); - public MessageDialog (Gtk.Window parent_window, DialogFlags flags, MessageType type, ButtonsType bt, bool use_markup, string format, params object[] args) + public MessageDialog (Gtk.Window parent_window, DialogFlags flags, MessageType type, ButtonsType bt, bool use_markup, string format, params object[] args) : base (IntPtr.Zero) { IntPtr p = (parent_window != null) ? parent_window.Handle : IntPtr.Zero; diff --git a/Source/Libs/GtkSharp/TreePath.cs b/Source/Libs/GtkSharp/TreePath.cs index 8f3ef014b..9977b6cec 100644 --- a/Source/Libs/GtkSharp/TreePath.cs +++ b/Source/Libs/GtkSharp/TreePath.cs @@ -20,24 +20,27 @@ namespace Gtk { public partial class TreePath { - // Patch submitted by malte on bug #49518 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate IntPtr d_gtk_tree_path_get_indices(IntPtr raw); - static d_gtk_tree_path_get_indices gtk_tree_path_get_indices = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_tree_path_get_indices")); + delegate IntPtr d_gtk_tree_path_get_indices_with_depth(IntPtr raw, out int depth); + static d_gtk_tree_path_get_indices_with_depth gtk_tree_path_get_indices_with_depth = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_tree_path_get_indices_with_depth")); public int [] Indices { get { - IntPtr ptr = gtk_tree_path_get_indices(Handle); - int [] arr = new int [Depth]; - Marshal.Copy (ptr, arr, 0, Depth); + IntPtr arrPtr = gtk_tree_path_get_indices_with_depth(Handle, out int depth); + int[] arr = new int[depth]; + if (arrPtr != IntPtr.Zero) + Marshal.Copy(arrPtr, arr, 0, depth); return arr; } } - public TreePath (int[] indices) : this () + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_gtk_tree_path_new_from_indicesv(int[] indices, UIntPtr length); + static d_gtk_tree_path_new_from_indicesv gtk_tree_path_new_from_indicesv = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_tree_path_new_from_indicesv")); + + public TreePath (int[] indices) { - foreach (int i in indices) - AppendIndex (i); + Raw = gtk_tree_path_new_from_indicesv(indices, (UIntPtr)indices.Length); } public override bool Equals (object o) diff --git a/Source/Libs/GtkSharp/Widget.cs b/Source/Libs/GtkSharp/Widget.cs index 845495fba..78c74abd0 100644 --- a/Source/Libs/GtkSharp/Widget.cs +++ b/Source/Libs/GtkSharp/Widget.cs @@ -370,6 +370,7 @@ namespace Gtk { Gtk.Widget widget = o as Gtk.Widget; if (widget == null) return; + widget.OnDestroyed (); } @@ -387,20 +388,41 @@ namespace Gtk { base.CreateNativeObject (names, vals); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_g_object_ref(IntPtr raw); + static d_g_object_ref g_object_ref = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_object_ref")); + + private bool destroyed; protected override void Dispose (bool disposing) { if (Handle == IntPtr.Zero) return; + + if (disposing && !destroyed && IsToplevel) + { + //If this is a TopLevel widget, then we do not hold a ref, only a toggle ref. + //Freeing our toggle ref expects a normal ref to exist, and therefore does not check if the object still exists. + //Take a ref here and let our toggle ref unref it. + g_object_ref (Handle); + gtk_widget_destroy (Handle); + destroyed = true; + } + InternalDestroyed -= NativeDestroyHandler; + base.Dispose (disposing); } - protected override IntPtr Raw { + protected override IntPtr Raw { get { return base.Raw; } set { + if (Handle == value) + return; + base.Raw = value; + if (value != IntPtr.Zero) InternalDestroyed += NativeDestroyHandler; } @@ -409,11 +431,18 @@ namespace Gtk { delegate void d_gtk_widget_destroy(IntPtr raw); static d_gtk_widget_destroy gtk_widget_destroy = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_widget_destroy")); + public virtual void Destroy () { if (Handle == IntPtr.Zero) return; + + if (destroyed) + return; + gtk_widget_destroy (Handle); + destroyed = true; + InternalDestroyed -= NativeDestroyHandler; } } diff --git a/Source/Libs/GtkSourceSharp/GtkSourceSharp.metadata b/Source/Libs/GtkSourceSharp/GtkSourceSharp.metadata index d42891890..7310b8252 100644 --- a/Source/Libs/GtkSourceSharp/GtkSourceSharp.metadata +++ b/Source/Libs/GtkSourceSharp/GtkSourceSharp.metadata @@ -14,26 +14,51 @@ EmitChanged EmitCanRedoChanged EmitCanUndoChanged - ref - ref + out + out out ref ref + out + out out + out + out + out + out + out + out - Mark - Mark - CompletionProvider - Encoding - Encoding + + GtkSourceMark* + true + false + GtkSourceMark* + true + false + GtkSourceCompletionProvider* + GtkSourceEncoding* + true + false + GtkSourceEncoding* + true + false notify async notify async async async + + true + true + true + true + true + true + SourceView diff --git a/Source/Libs/Shared/GLibrary.cs b/Source/Libs/Shared/GLibrary.cs index e02b21398..62f810f55 100644 --- a/Source/Libs/Shared/GLibrary.cs +++ b/Source/Libs/Shared/GLibrary.cs @@ -42,7 +42,7 @@ class GLibrary if (ret == IntPtr.Zero) { - SetDllDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Gtk", "3.24.20")); + SetDllDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Gtk", "3.24.24")); ret = FuncLoader.LoadLibrary(_libraryDefinitions[library][0]); } } diff --git a/Source/Libs/Shared/Gapi.xsd b/Source/Libs/Shared/Gapi.xsd index 7ef1b8bc3..bd1eb8d1a 100644 --- a/Source/Libs/Shared/Gapi.xsd +++ b/Source/Libs/Shared/Gapi.xsd @@ -158,6 +158,7 @@ + @@ -188,6 +189,7 @@ + diff --git a/Source/Samples/Samples.csproj b/Source/Samples/Samples.csproj index 5c9986a95..a9a1f5291 100644 --- a/Source/Samples/Samples.csproj +++ b/Source/Samples/Samples.csproj @@ -1,7 +1,7 @@ WinExe - netcoreapp3.1 + net5.0 false ..\..\BuildOutput\Samples @@ -10,7 +10,9 @@ %(Filename)%(Extension) - + + Testpic + diff --git a/Source/Samples/Sections/Miscellaneous/PixbufSection.cs b/Source/Samples/Sections/Miscellaneous/PixbufSection.cs new file mode 100644 index 000000000..db74f93ea --- /dev/null +++ b/Source/Samples/Sections/Miscellaneous/PixbufSection.cs @@ -0,0 +1,95 @@ +using System; +using System.IO; +using System.Threading; +using Gdk; +using Gtk; + +namespace Samples +{ + + [Section (ContentType = typeof(PixbufDemo), Category = Category.Miscellaneous)] + class PixbufSection : ListSection + { + + public PixbufSection () + { + AddItem ($"Press button to run / stop {nameof(PixbufDemo)} :", new PixbufDemo ("Press me")); + } + + } + + class PixbufDemo : Button + { + + public PixbufDemo (string text) : base (text) { } + + private bool running = false; + + public void DispatchPendingEvents () + { + // The loop is limited to 1000 iterations as a workaround for an issue that some users + // have experienced. Sometimes EventsPending starts return 'true' for all iterations, + // causing the loop to never end. + + int n = 1000; + Gdk.Threads.Enter (); + + while (Gtk.Application.EventsPending () && --n > 0) { + Gtk.Application.RunIteration (false); + } + + Gdk.Threads.Leave (); + } + + protected override void OnPressed () + { + base.OnPressed (); + var count = 0; + + if (running) { + running = false; + + return; + } + + var startmem = GC.GetTotalMemory (true); + var testfile = "Textpic.png"; + + using var teststream = typeof(ImageSection).Assembly.GetManifestResourceStream("Testpic"); + using (var writeTestFile = new FileStream(testfile, FileMode.Create)) { + teststream.CopyTo(writeTestFile); + } + + using (var heatup = new Pixbuf (testfile)) { + ApplicationOutput.WriteLine ($"{nameof(heatup)}.{nameof(Pixbuf.ByteLength)}\t{heatup.ByteLength:N0}"); + } + + startmem = GC.GetTotalMemory (true); + ApplicationOutput.WriteLine ($"{nameof(GC.GetTotalMemory)} at start: {startmem:N}"); + running = true; + + var memAllocated = 0UL; + + while (running) { + + using (var source = new Pixbuf (typeof(ImageSection).Assembly, "Testpic")) { + memAllocated += source.ByteLength; + count++; + } + + DispatchPendingEvents (); + + if (!running) + break; + + } + + var endmem = GC.GetTotalMemory (true); + ApplicationOutput.WriteLine ($"Leak:\t{(endmem - startmem):N0}\t{nameof(memAllocated)}"); + ApplicationOutput.WriteLine ($"{nameof(GC.GetTotalMemory)} at start: {startmem:N0}\tat end: {endmem:N0}\t{nameof(Pixbuf)} created: {count}"); + + } + + } + +} \ No newline at end of file diff --git a/Source/Samples/Sections/Widgets/ImageSection.cs b/Source/Samples/Sections/Widgets/ImageSection.cs index 8cb2d01c7..d54da9425 100644 --- a/Source/Samples/Sections/Widgets/ImageSection.cs +++ b/Source/Samples/Sections/Widgets/ImageSection.cs @@ -21,29 +21,9 @@ namespace Samples public (string, Widget) CreateContainer() { - Stream GetResourceStream(Assembly assembly, string name) - { - var resources = assembly.GetManifestResourceNames(); - var resourceName = resources.SingleOrDefault(str => str == name); - - // try harder: - if (resourceName == default) { - resourceName = resources.SingleOrDefault(str => str.EndsWith(name)); - } - - if (resourceName == default) - return default; - var stream = assembly.GetManifestResourceStream(resourceName); - return stream; - } - Pixbuf image = default; - using (var stream = GetResourceStream(typeof(ImageSection).Assembly, "Testpic.png")) { - image = new Pixbuf(stream); - } - + var image = new Pixbuf(typeof(ImageSection).Assembly, "Testpic"); var container = new ImageBox(image); - return ($"{nameof(ImageBox)}:", container); } } diff --git a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/.template.config/template.json b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/.template.config/template.json index 9f4a98439..214691dda 100644 --- a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/.template.config/template.json +++ b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/.template.config/template.json @@ -18,8 +18,8 @@ "symbols": { "targetframework": { "type": "parameter", - "defaultValue": "netcoreapp2.0", - "replaces": "netcoreapp2.0" + "defaultValue": "net5.0", + "replaces": "net5.0" } }, "primaryOutputs": [ diff --git a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/GtkNamespace.csproj b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/GtkNamespace.csproj index 68d9201a0..d4b9b8b63 100644 --- a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/GtkNamespace.csproj +++ b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/GtkNamespace.csproj @@ -2,7 +2,7 @@ WinExe - netcoreapp3.1 + net5.0 @@ -13,7 +13,7 @@ - + diff --git a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.cs b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.cs index 31a98b31c..a6fc08a26 100644 --- a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.cs +++ b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.cs @@ -13,7 +13,7 @@ namespace GtkNamespace public MainWindow() : this(new Builder("MainWindow.glade")) { } - private MainWindow(Builder builder) : base(builder.GetObject("MainWindow").Handle) + private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow")) { builder.Autoconnect(this); diff --git a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.cs b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.cs index e4133f658..5f7d60f10 100644 --- a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.cs +++ b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.cs @@ -8,7 +8,7 @@ namespace GtkNamespace { public Gtk_Dialog() : this(new Builder("Gtk_Dialog.glade")) { } - private Gtk_Dialog(Builder builder) : base(builder.GetObject("Gtk_Dialog").Handle) + private Gtk_Dialog(Builder builder) : base(builder.GetRawOwnedObject("Gtk_Dialog")) { builder.Autoconnect(this); DefaultResponse = ResponseType.Cancel; diff --git a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.cs b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.cs index ca4edd24e..88c911502 100644 --- a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.cs +++ b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.cs @@ -8,7 +8,7 @@ namespace GtkNamespace { public Gtk_Widget() : this(new Builder("Gtk_Widget.glade")) { } - private Gtk_Widget(Builder builder) : base(builder.GetObject("Gtk_Widget").Handle) + private Gtk_Widget(Builder builder) : base(builder.GetRawOwnedObject("Gtk_Widget")) { builder.Autoconnect(this); } diff --git a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.cs b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.cs index e4b68797f..2b863d03c 100644 --- a/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.cs +++ b/Source/Templates/GtkSharp.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.cs @@ -8,7 +8,7 @@ namespace GtkNamespace { public Gtk_Window() : this(new Builder("Gtk_Window.glade")) { } - private Gtk_Window(Builder builder) : base(builder.GetObject("Gtk_Window").Handle) + private Gtk_Window(Builder builder) : base(builder.GetRawOwnedObject("Gtk_Window")) { builder.Autoconnect(this); } diff --git a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/.template.config/template.json b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/.template.config/template.json index dd7d589a9..019d38558 100644 --- a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/.template.config/template.json +++ b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/.template.config/template.json @@ -18,8 +18,8 @@ "symbols": { "targetframework": { "type": "parameter", - "defaultValue": "netcoreapp2.0", - "replaces": "netcoreapp2.0" + "defaultValue": "net5.0", + "replaces": "net5.0" } }, "primaryOutputs": [ diff --git a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/GtkNamespace.fsproj b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/GtkNamespace.fsproj index eaba991e2..d8991da16 100644 --- a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/GtkNamespace.fsproj +++ b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/GtkNamespace.fsproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5.0 @@ -18,7 +18,7 @@ - + diff --git a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.fs b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.fs index 316e2f848..03ffbc5d7 100644 --- a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.fs +++ b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.fs @@ -3,7 +3,7 @@ namespace GtkNamespace open Gtk type MainWindow (builder : Builder) as this = - inherit Window(builder.GetObject("MainWindow").Handle) + inherit Window(builder.GetRawOwnedObject("MainWindow")) let mutable _label1 : Label = null let mutable _button1 : Button = null diff --git a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.fs b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.fs index 369db5478..7e52fb76e 100644 --- a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.fs +++ b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.fs @@ -3,7 +3,7 @@ namespace GtkNamespace open Gtk type Gtk_Dialog (builder : Builder) as this = - inherit Dialog(builder.GetObject("Gtk_Dialog").Handle) + inherit Dialog(builder.GetRawOwnedObject("Gtk_Dialog")) do this.DefaultResponse <- ResponseType.Cancel; this.Response.Add(fun _ -> diff --git a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.fs b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.fs index 7d4d3d4ce..2812ea947 100644 --- a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.fs +++ b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.fs @@ -3,6 +3,6 @@ namespace GtkNamespace open Gtk type Gtk_Widget (builder : Builder) = - inherit Box(builder.GetObject("Gtk_Widget").Handle) + inherit Box(builder.GetRawOwnedObject("Gtk_Widget")) new() = new Gtk_Widget(new Builder("Gtk_Widget.glade")) diff --git a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.fs b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.fs index ab3fb159a..a4f3fc885 100644 --- a/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.fs +++ b/Source/Templates/GtkSharp.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.fs @@ -3,6 +3,6 @@ namespace GtkNamespace open Gtk type Gtk_Window (builder : Builder) = - inherit Window(builder.GetObject("Gtk_Window").Handle) + inherit Window(builder.GetRawOwnedObject("Gtk_Window")) new() = new Gtk_Window(new Builder("Gtk_Window.glade")) diff --git a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/.template.config/template.json b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/.template.config/template.json index bee173d46..51f775308 100644 --- a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/.template.config/template.json +++ b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/.template.config/template.json @@ -18,8 +18,8 @@ "symbols": { "targetframework": { "type": "parameter", - "defaultValue": "netcoreapp2.0", - "replaces": "netcoreapp2.0" + "defaultValue": "net5.0", + "replaces": "net5.0" } }, "primaryOutputs": [ diff --git a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/GtkNamespace.vbproj b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/GtkNamespace.vbproj index 68d9201a0..d4b9b8b63 100644 --- a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/GtkNamespace.vbproj +++ b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/GtkNamespace.vbproj @@ -2,7 +2,7 @@ WinExe - netcoreapp3.1 + net5.0 @@ -13,7 +13,7 @@ - + diff --git a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.vb b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.vb index f47a06021..5a1f6fa05 100644 --- a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.vb +++ b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.vb @@ -11,7 +11,7 @@ Namespace GtkNamespace Private _button1 As Button Public Sub New (builder as Builder) - MyBase.New(builder.GetObject("MainWindow").Handle) + MyBase.New(builder.GetRawOwnedObject("MainWindow")) builder.Autoconnect (Me) diff --git a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.vb b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.vb index 05640a7fc..e4b15f60b 100644 --- a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.vb +++ b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.vb @@ -7,7 +7,7 @@ Namespace GtkNamespace Inherits Dialog Public Sub New (builder as Builder) - MyBase.New (builder.GetObject("Gtk_Dialog").Handle) + MyBase.New (builder.GetRawOwnedObject("Gtk_Dialog")) builder.Autoconnect (Me) DefaultResponse = ResponseType.Cancel diff --git a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.vb b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.vb index 49c8ba38c..359a413e7 100644 --- a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.vb +++ b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.vb @@ -7,7 +7,7 @@ Namespace GtkNamespace Inherits Box Public Sub New (builder as Builder) - MyBase.New (builder.GetObject("Gtk_Widget").Handle) + MyBase.New (builder.GetRawOwnedObject("Gtk_Widget")) builder.Autoconnect (Me) End Sub diff --git a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.vb b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.vb index aaa3a2d5d..2e0b365f4 100644 --- a/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.vb +++ b/Source/Templates/GtkSharp.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.vb @@ -7,7 +7,7 @@ Namespace GtkNamespace Inherits Window Public Sub New (builder as Builder) - MyBase.New (builder.GetObject("Gtk_Window").Handle) + MyBase.New (builder.GetRawOwnedObject("Gtk_Window")) builder.Autoconnect (Me) End Sub diff --git a/Source/Tools/GapiCodegen/GapiCodegen.csproj b/Source/Tools/GapiCodegen/GapiCodegen.csproj index 75abe931c..653fe5d27 100644 --- a/Source/Tools/GapiCodegen/GapiCodegen.csproj +++ b/Source/Tools/GapiCodegen/GapiCodegen.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + net5.0 ..\..\..\BuildOutput\Tools false diff --git a/Source/Tools/GapiFixup/GapiFixup.csproj b/Source/Tools/GapiFixup/GapiFixup.csproj index bc0b29609..713576357 100644 --- a/Source/Tools/GapiFixup/GapiFixup.csproj +++ b/Source/Tools/GapiFixup/GapiFixup.csproj @@ -1,7 +1,7 @@ Exe - netcoreapp2.0 + net5.0 ..\..\..\BuildOutput\Tools false diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 78b98a171..54555b8bd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,5 +1,5 @@ variables: - versionbase: 3.22.25 + versionbase: 3.24.24 increment: $[counter(variables['versionbase'], 1)] version: $(versionbase).$(increment) @@ -16,9 +16,6 @@ steps: - script: echo "##vso[build.updatebuildnumber]$(version)" displayName: 'Set Build Number' - - script: sudo apt install -y monodevelop - displayName: 'Install MonoDevelop' - - script: ./build.sh --BuildTarget=FullBuild --BuildVersion=$(version) displayName: 'CAKE Script' @@ -42,10 +39,3 @@ steps: pathtoPublish: BuildOutput/Samples artifactName: Samples publishLocation: container - - - task: PublishBuildArtifacts@1 - displayName: Publish MonoDevelop Addin - inputs: - pathtoPublish: BuildOutput/Addins/MonoDevelop/MonoDevelop.GtkSharp.Addin_$(version).mpack - artifactName: MonoDevelop Addin - publishLocation: container \ No newline at end of file diff --git a/build.cake b/build.cake index 4b9bb2f60..34a6352b4 100644 --- a/build.cake +++ b/build.cake @@ -1,12 +1,12 @@ #load CakeScripts\GAssembly.cake #load CakeScripts\Settings.cake -#addin "Cake.FileHelpers&version=3.2.0" -#addin "Cake.Incubator&version=5.0.1" +#addin "Cake.FileHelpers&version=4.0.0" +#addin "Cake.Incubator&version=6.0.0" // VARS Settings.Cake = Context; -Settings.Version = Argument("BuildVersion", "3.22.24.30"); +Settings.Version = Argument("BuildVersion", "3.24.24.1"); Settings.BuildTarget = Argument("BuildTarget", "Default"); Settings.Assembly = Argument("Assembly", ""); var configuration = Argument("Configuration", "Release"); @@ -63,7 +63,10 @@ Task("FullClean") .IsDependentOn("Clean") .Does(() => { - DeleteDirectory("BuildOutput", true); + DeleteDirectory("BuildOutput", new DeleteDirectorySettings { + Recursive = true, + Force = true + }); }); Task("Build") @@ -136,35 +139,6 @@ Task("PackageTemplates") NuGetPack("Source/Templates/GtkSharp.Template.VBNet/GtkSharp.Template.VBNet.nuspec", settings); }); -Task("PackageAddin") - .IsDependentOn("PackageTemplates") - .Does(() => -{ - // Copy the current version nuget templates - CopyFile( - "BuildOutput/NugetPackages/GtkSharp.Template.CSharp." + Settings.Version + ".nupkg", - "Source/Addins/MonoDevelop.GtkSharp.Addin/Templates/GtkSharp.Template.CSharp.nupkg" - ); - CopyFile( - "BuildOutput/NugetPackages/GtkSharp.Template.FSharp." + Settings.Version + ".nupkg", - "Source/Addins/MonoDevelop.GtkSharp.Addin/Templates/GtkSharp.Template.FSharp.nupkg" - ); - - // Generate version code info - var versionline = "[assembly: Mono.Addins.Addin(\"MonoDevelop.GtkSharp.Addin\", Version = \"" + Settings.Version + "\")]"; - FileWriteText("Source/Addins/MonoDevelop.GtkSharp.Addin/Properties/AddinInfo.Version.cs", versionline); - - // Build MonoDevelop addin - var msbuildsettings = new MSBuildSettings - { - Configuration = configuration, - }; - msbuildsettings = msbuildsettings.WithProperty("Version", Settings.Version); - msbuildsettings = msbuildsettings.WithTarget("PackageAddin"); - - MSBuild("Source/Addins/MonoDevelop.GtkSharp.Addin/MonoDevelop.GtkSharp.Addin.sln", msbuildsettings); -}); - // TASK TARGETS Task("Default") @@ -172,8 +146,7 @@ Task("Default") Task("FullBuild") .IsDependentOn("PackageNuGet") - .IsDependentOn("PackageTemplates") - .IsDependentOn("PackageAddin"); + .IsDependentOn("PackageTemplates"); // EXECUTION diff --git a/build.ps1 b/build.ps1 index ad6e59947..2ce2dd795 100644 --- a/build.ps1 +++ b/build.ps1 @@ -5,14 +5,11 @@ ########################################################################## <# - .SYNOPSIS This is a Powershell script to bootstrap a Cake build. - .DESCRIPTION This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) and execute your Cake build script with the parameters you provide. - .PARAMETER Script The build script to execute. .PARAMETER Target @@ -21,40 +18,55 @@ The build script target to run. The build configuration to use. .PARAMETER Verbosity Specifies the amount of information to be displayed. -.PARAMETER Experimental -Tells Cake to use the latest Roslyn release. -.PARAMETER WhatIf -Performs a dry run of the build script. -No tasks will be executed. -.PARAMETER Mono -Tells Cake to use the Mono scripting engine. +.PARAMETER ShowDescription +Shows description about tasks. +.PARAMETER DryRun +Performs a dry run. .PARAMETER SkipToolPackageRestore Skips restoring of packages. .PARAMETER ScriptArgs Remaining arguments are added here. - .LINK https://cakebuild.net - #> [CmdletBinding()] Param( - [string]$Script = "build.cake", - [string]$Target = "Default", - [ValidateSet("Release", "Debug")] - [string]$Configuration = "Release", + [string]$Script, + [string]$Target, + [string]$Configuration, [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity = "Verbose", - [switch]$Experimental, - [Alias("DryRun","Noop")] - [switch]$WhatIf, - [switch]$Mono, + [string]$Verbosity, + [switch]$ShowDescription, + [Alias("WhatIf", "Noop")] + [switch]$DryRun, [switch]$SkipToolPackageRestore, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$ScriptArgs ) +# This is an automatic variable in PowerShell Core, but not in Windows PowerShell 5.x +if (-not (Test-Path variable:global:IsCoreCLR)) { + $IsCoreCLR = $false +} + +# Attempt to set highest encryption available for SecurityProtocol. +# PowerShell will not set this by default (until maybe .NET 4.6.x). This +# will typically produce a message for PowerShell v2 (just an info +# message though) +try { + # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48) + # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't + # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is + # installed (.NET 4.5 is an in-place upgrade). + # PowerShell Core already has support for TLS 1.2 so we can skip this if running in that. + if (-not $IsCoreCLR) { + [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48 + } + } catch { + Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3' + } + [Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null function MD5HashFile([string] $filePath) { @@ -80,49 +92,52 @@ function MD5HashFile([string] $filePath) } } +function GetProxyEnabledWebClient +{ + $wc = New-Object System.Net.WebClient + $proxy = [System.Net.WebRequest]::GetSystemWebProxy() + $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials + $wc.Proxy = $proxy + return $wc +} + Write-Host "Preparing to run build script..." if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } +if(!$Script){ + $Script = Join-Path $PSScriptRoot "build.cake" +} $TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" +$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" $NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" $CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" $NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" $PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" $PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" +$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" +$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" -# Should we use mono? -$UseMono = ""; -if($Mono.IsPresent) { - Write-Verbose -Message "Using the Mono based scripting engine." - $UseMono = "-mono" -} - -# Should we use the new Roslyn? -$UseExperimental = ""; -if($Experimental.IsPresent -and !($Mono.IsPresent)) { - Write-Verbose -Message "Using experimental version of Roslyn." - $UseExperimental = "-experimental" -} - -# Is this a dry run? -$UseDryRun = ""; -if($WhatIf.IsPresent) { - $UseDryRun = "-dryrun" -} +$env:CAKE_PATHS_TOOLS = $TOOLS_DIR +$env:CAKE_PATHS_ADDINS = $ADDINS_DIR +$env:CAKE_PATHS_MODULES = $MODULES_DIR # Make sure tools folder exists if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { Write-Verbose -Message "Creating tools directory..." - New-Item -Path $TOOLS_DIR -Type directory | out-null + New-Item -Path $TOOLS_DIR -Type Directory | Out-Null } # Make sure that packages.config exist. if (!(Test-Path $PACKAGES_CONFIG)) { Write-Verbose -Message "Downloading packages.config..." - try { (New-Object System.Net.WebClient).DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + try { + $wc = GetProxyEnabledWebClient + $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) + } catch { Throw "Could not download packages.config." } } @@ -142,14 +157,26 @@ if (!(Test-Path $NUGET_EXE)) { if (!(Test-Path $NUGET_EXE)) { Write-Verbose -Message "Downloading NuGet.exe..." try { - (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + $wc = GetProxyEnabledWebClient + $wc.DownloadFile($NUGET_URL, $NUGET_EXE) } catch { Throw "Could not download NuGet.exe." } } +# These are automatic variables in PowerShell Core, but not in Windows PowerShell 5.x +if (-not (Test-Path variable:global:ismacos)) { + $IsLinux = $false + $IsMacOS = $false +} + # Save nuget.exe path to environment to be available to child processed -$ENV:NUGET_EXE = $NUGET_EXE +$env:NUGET_EXE = $NUGET_EXE +$env:NUGET_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) { + "mono `"$NUGET_EXE`"" +} else { + "`"$NUGET_EXE`"" +} # Restore tools from NuGet? if(-Not $SkipToolPackageRestore.IsPresent) { @@ -157,24 +184,61 @@ if(-Not $SkipToolPackageRestore.IsPresent) { Set-Location $TOOLS_DIR # Check for changes in packages.config and remove installed tools if true. - [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) + [string] $md5Hash = MD5HashFile $PACKAGES_CONFIG if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or - ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { Write-Verbose -Message "Missing or changed package.config hash..." - Remove-Item * -Recurse -Exclude packages.config,nuget.exe + Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery | + Remove-Item -Recurse -Force } Write-Verbose -Message "Restoring tools from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + + $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" if ($LASTEXITCODE -ne 0) { - Throw "An error occured while restoring NuGet tools." + Throw "An error occurred while restoring NuGet tools." } else { $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" } - Write-Verbose -Message ($NuGetOutput | out-string) + Write-Verbose -Message ($NuGetOutput | Out-String) + + Pop-Location +} + +# Restore addins from NuGet +if (Test-Path $ADDINS_PACKAGES_CONFIG) { + Push-Location + Set-Location $ADDINS_DIR + + Write-Verbose -Message "Restoring addins from NuGet..." + $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occurred while restoring NuGet addins." + } + + Write-Verbose -Message ($NuGetOutput | Out-String) + + Pop-Location +} + +# Restore modules from NuGet +if (Test-Path $MODULES_PACKAGES_CONFIG) { + Push-Location + Set-Location $MODULES_DIR + + Write-Verbose -Message "Restoring modules from NuGet..." + $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occurred while restoring NuGet modules." + } + + Write-Verbose -Message ($NuGetOutput | Out-String) + Pop-Location } @@ -183,7 +247,23 @@ if (!(Test-Path $CAKE_EXE)) { Throw "Could not find Cake.exe at $CAKE_EXE" } +$CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) { + "mono `"$CAKE_EXE`"" +} else { + "`"$CAKE_EXE`"" +} + + # Build an array (not a string) of Cake arguments to be joined later +$cakeArguments = @() +if ($Script) { $cakeArguments += "`"$Script`"" } +if ($Target) { $cakeArguments += "--target=`"$Target`"" } +if ($Configuration) { $cakeArguments += "--configuration=$Configuration" } +if ($Verbosity) { $cakeArguments += "--verbosity=$Verbosity" } +if ($ShowDescription) { $cakeArguments += "--showdescription" } +if ($DryRun) { $cakeArguments += "--dryrun" } +$cakeArguments += $ScriptArgs + # Start Cake Write-Host "Running build script..." -Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" -exit $LASTEXITCODE \ No newline at end of file +Invoke-Expression "& $CAKE_EXE_INVOCATION $($cakeArguments -join " ")" +exit $LASTEXITCODE diff --git a/build.sh b/build.sh index 0e42a0a1e..14392d4ed 100755 --- a/build.sh +++ b/build.sh @@ -56,7 +56,7 @@ if [ ! -f "$TOOLS_DIR/packages.config" ]; then echo "Downloading packages.config..." curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages if [ $? -ne 0 ]; then - echo "An error occured while downloading packages.config." + echo "An error occurred while downloading packages.config." exit 1 fi fi @@ -66,7 +66,7 @@ if [ ! -f "$NUGET_EXE" ]; then echo "Downloading NuGet..." curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe if [ $? -ne 0 ]; then - echo "An error occured while downloading nuget.exe." + echo "An error occurred while downloading nuget.exe." exit 1 fi fi @@ -97,5 +97,5 @@ fi if $SHOW_VERSION; then exec mono "$CAKE_EXE" -version else - exec mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" + exec mono "$CAKE_EXE" $SCRIPT --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" fi \ No newline at end of file diff --git a/tools/packages.config b/tools/packages.config index cedcc6ab5..2a0374690 100644 --- a/tools/packages.config +++ b/tools/packages.config @@ -1,4 +1,4 @@ - +