diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e011b8e91..d1b569c08 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,6 +5,8 @@ on: [push, pull_request] jobs: build: runs-on: ${{ matrix.os }} + permissions: + packages: write strategy: matrix: os: [ubuntu-20.04] @@ -24,7 +26,11 @@ jobs: GITHUB_ACTIONS: true - uses: actions/upload-artifact@main with: - name: Nuget Packages + name: NuGet Packages path: | BuildOutput/NugetPackages/**/*.nupkg if-no-files-found: error + - name: Push NuGet to GitHub packages + run: dotnet nuget push BuildOutput/NugetPackages/**/*.nupkg --source https://nuget.pkg.github.com/$GITHUB_REPOSITORY_OWNER/index.json --api-key ${GITHUB_TOKEN} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CakeScripts/TargetEnvironment.cake b/CakeScripts/TargetEnvironment.cake new file mode 100644 index 000000000..811351fae --- /dev/null +++ b/CakeScripts/TargetEnvironment.cake @@ -0,0 +1,211 @@ +#addin "nuget:?package=Microsoft.Win32.Registry&version=5.0.0" +using System; +using D = System.IO.Directory; +using F = System.IO.File; +using P = System.IO.Path; +using Pr = System.Diagnostics.Process; +using PSI = System.Diagnostics.ProcessStartInfo; +using R = Microsoft.Win32.Registry; +using RI = System.Runtime.InteropServices.RuntimeInformation; +using Z = System.IO.Compression.ZipFile; + +class TargetEnvironment +{ + public static string DotNetInstallPath { get; private set; } + public static string DotNetInstalledWorkloadsMetadataPath { get; private set; } + public static string DotNetInstallerTypeMetadataPath { get; private set; } + public static string DotNetManifestPath { get; private set; } + public static string DotNetPacksPath { get; private set; } + public static string DotNetTemplatePacksPath { get; private set; } + + public static string DotNetCliPath { get; private set; } + public static string DotNetCliFeatureBand { get; private set; } + + static TargetEnvironment() + { + DotNetInstallPath = Environment.GetEnvironmentVariable("DOTNET_ROOT"); + if (DotNetInstallPath == null) + { + if (OperatingSystem.IsWindows()) + { + DotNetInstallPath = P.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "dotnet"); + } + else if (OperatingSystem.IsLinux()) + { + DotNetInstallPath = "/usr/share/dotnet"; + } + else if (OperatingSystem.IsMacOS()) + { + DotNetInstallPath = "/usr/local/share/dotnet"; + } + } + + DotNetCliPath = P.Combine(DotNetInstallPath, "dotnet"); + + var proc = Pr.Start(new PSI() + { + FileName = DotNetCliPath, + Arguments = "--version", + RedirectStandardOutput = true, + }); + + proc.WaitForExit(); + + DotNetCliFeatureBand = proc.StandardOutput.ReadToEnd().Trim(); + DotNetCliFeatureBand = DotNetCliFeatureBand.Substring(0, DotNetCliFeatureBand.Length - 2) + "00"; + + DotNetInstalledWorkloadsMetadataPath = P.Combine(DotNetInstallPath, "metadata", "workloads", DotNetCliFeatureBand, "InstalledWorkloads"); + DotNetInstallerTypeMetadataPath = P.Combine(DotNetInstallPath, "metadata", "workloads", DotNetCliFeatureBand, "InstallerType"); + DotNetManifestPath = P.Combine(DotNetInstallPath, "sdk-manifests", DotNetCliFeatureBand); + DotNetPacksPath = P.Combine(DotNetInstallPath, "packs"); + DotNetTemplatePacksPath = P.Combine(DotNetInstallPath, "template-packs"); + } + + public static void RegisterInstalledWorkload(string workloadName) + { + D.CreateDirectory(DotNetInstalledWorkloadsMetadataPath); + F.WriteAllText(P.Combine(DotNetInstalledWorkloadsMetadataPath, workloadName), string.Empty); + if (F.Exists(P.Combine(DotNetInstallerTypeMetadataPath, "msi"))) + { + //HKLM:\SOFTWARE\Microsoft\dotnet\InstalledWorkloads\Standalone\x64\6.0.300\gtk + + // TODO: Check for other Windows architectures (x86 and arm64) + var archString = RI.OSArchitecture.ToString().ToLower(); + + var hklm = R.LocalMachine; + var software = hklm.CreateSubKey("SOFTWARE"); + var microsoft = software.CreateSubKey("Microsoft"); + var dotnet = microsoft.CreateSubKey("dotnet"); + var installedWorkloads = dotnet.CreateSubKey("InstalledWorkloads"); + var standalone = installedWorkloads.CreateSubKey("Standalone"); + var arch = standalone.CreateSubKey(archString); + var version = arch.CreateSubKey(DotNetCliFeatureBand); + var workload = version.CreateSubKey(workloadName); + + workload.Close(); + version.Close(); + arch.Close(); + standalone.Close(); + installedWorkloads.Close(); + dotnet.Close(); + microsoft.Close(); + software.Close(); + hklm.Close(); + } + } + + public static void UnregisterInstalledWorkload(string workloadName) + { + F.Delete(P.Combine(DotNetInstalledWorkloadsMetadataPath, workloadName)); + if (F.Exists(P.Combine(DotNetInstallerTypeMetadataPath, "msi"))) + { + var archString = RI.OSArchitecture.ToString().ToLower(); + + var hklm = R.LocalMachine; + var software = hklm.CreateSubKey("SOFTWARE"); + var microsoft = software.CreateSubKey("Microsoft"); + var dotnet = microsoft.CreateSubKey("dotnet"); + var installedWorkloads = dotnet.CreateSubKey("InstalledWorkloads"); + var standalone = installedWorkloads.CreateSubKey("Standalone"); + var arch = standalone.CreateSubKey(archString); + var version = arch.CreateSubKey(DotNetCliFeatureBand); + + version.DeleteSubKey(workloadName, false); + + version.Close(); + arch.Close(); + standalone.Close(); + installedWorkloads.Close(); + dotnet.Close(); + microsoft.Close(); + software.Close(); + hklm.Close(); + } + } + + public static void InstallManifests(string manifestName, string manifestPackPath) + { + var targetDirectory = P.Combine(DotNetManifestPath, manifestName); + var tempDirectory = P.Combine(targetDirectory, "temp"); + + // Delete existing installations to avoid conflict. + if (D.Exists(targetDirectory)) + { + D.Delete(targetDirectory, true); + } + + // Also creates the target + D.CreateDirectory(tempDirectory); + + Z.ExtractToDirectory(manifestPackPath, tempDirectory); + var tempDataDirectory = P.Combine(tempDirectory, "data"); + + foreach (var filePath in D.GetFiles(tempDataDirectory)) + { + var targetFilePath = P.Combine(targetDirectory, P.GetFileName(filePath)); + F.Copy(filePath, targetFilePath, true); + } + + D.Delete(tempDirectory, true); + } + + public static void UninstallManifests(string manifestName) + { + var targetDirectory = P.Combine(DotNetManifestPath, manifestName); + if (D.Exists(targetDirectory)) + { + D.Delete(targetDirectory, true); + } + } + + public static void InstallPack(string name, string version, string packPath) + { + var targetDirectory = P.Combine(DotNetPacksPath, name, version); + + if (D.Exists(targetDirectory)) + { + D.Delete(targetDirectory, true); + } + + D.CreateDirectory(targetDirectory); + + Z.ExtractToDirectory(packPath, targetDirectory); + } + + public static void UninstallPack(string name, string version) + { + var packInstallDirectory = P.Combine(DotNetPacksPath, name); + + var targetDirectory = P.Combine(packInstallDirectory, version); + if (D.Exists(targetDirectory)) + { + D.Delete(targetDirectory, true); + } + + // Clean up the template if no other verions exist. + try + { + D.Delete(packInstallDirectory, false); + } + catch (System.IO.IOException) + { + // Silently fail. Mostly because the directory is not empty (there are other verions installed). + } + } + + public static void InstallTemplatePack(string packName, string packPath) + { + D.CreateDirectory(DotNetTemplatePacksPath); + var targetPath = P.Combine(DotNetTemplatePacksPath, packName); + F.Copy(packPath, targetPath, true); + } + + public static void UninstallTemplatePack(string packName) + { + var targetPath = P.Combine(DotNetTemplatePacksPath, packName); + if (F.Exists(targetPath)) + { + F.Delete(targetPath); + } + } +} \ No newline at end of file diff --git a/Source/Directory.Build.props b/Source/Directory.Build.props new file mode 100644 index 000000000..fa2214edd --- /dev/null +++ b/Source/Directory.Build.props @@ -0,0 +1,12 @@ + + + <_GtkSharpNetVersion>6.0 + <_GtkSharpSourceDirectory>$(MSBuildThisFileDirectory) + <_GtkSharpBuildOutputDirectory>$(MSBuildThisFileDirectory)..\BuildOutput\ + + + + https://github.com/GtkSharp/GtkSharp + https://github.com/GtkSharp/GtkSharp + + \ No newline at end of file diff --git a/Source/Libs/CairoSharp/Context.cs b/Source/Libs/CairoSharp/Context.cs index a30c67c3a..cded41d1a 100644 --- a/Source/Libs/CairoSharp/Context.cs +++ b/Source/Libs/CairoSharp/Context.cs @@ -737,13 +737,13 @@ public void TransformPoint (ref double x, ref double y) [Obsolete("Use UserToDeviceDistance instead")] public void TransformDistance (ref double dx, ref double dy) { - UserToDevice (ref dx, ref dy); + UserToDeviceDistance (ref dx, ref dy); } [Obsolete("Use DeviceToUser instead")] public void InverseTransformPoint (ref double x, ref double y) { - UserToDevice (ref x, ref y); + DeviceToUser (ref x, ref y); } [Obsolete("Use DeviceToUserDistance instead")] diff --git a/Source/Libs/Directory.Build.props b/Source/Libs/Directory.Build.props index 4a9335642..c3762d1ca 100644 --- a/Source/Libs/Directory.Build.props +++ b/Source/Libs/Directory.Build.props @@ -1,9 +1,15 @@ + + - net6.0;netstandard2.0 + net$(_GtkSharpNetVersion);netstandard2.0 true - https://github.com/GtkSharp/GtkSharp - https://github.com/GtkSharp/GtkSharp - ..\..\..\BuildOutput\$(Configuration) + $(_GtkSharpBuildOutputDirectory)\$(Configuration) + + True + $(MSBuildThisFileDirectory)\GtkSharp.snk \ No newline at end of file diff --git a/Source/Libs/GLibSharp/GType.cs b/Source/Libs/GLibSharp/GType.cs index 8fceea7c7..67107f424 100644 --- a/Source/Libs/GLibSharp/GType.cs +++ b/Source/Libs/GLibSharp/GType.cs @@ -251,15 +251,15 @@ public static Type LookupType (IntPtr typeid) // in a patch from bug #400595, and a desire to keep memory usage low // by avoiding a complete loading of all dependent assemblies. string ns = type_name.Substring (0, type_name.LastIndexOf ('.')); - string asm_name = ns.ToLower ().Replace ('.', '-') + "-sharp"; + string asm_name = ns.Replace (".", "") + "Sharp"; foreach (Assembly asm in assemblies) { foreach (AssemblyName ref_name in asm.GetReferencedAssemblies ()) { if (ref_name.Name != asm_name) continue; try { - string asm_dir = Path.GetDirectoryName (asm.Location); + string asm_dir = Path.GetDirectoryName (asm.Location); // will be null or empty for single file publish Assembly ref_asm; - if (File.Exists (Path.Combine (asm_dir, ref_name.Name + ".dll"))) + if (!string.IsNullOrEmpty (asm_dir) && File.Exists (Path.Combine (asm_dir, ref_name.Name + ".dll"))) ref_asm = Assembly.LoadFrom (Path.Combine (asm_dir, ref_name.Name + ".dll")); else ref_asm = Assembly.Load (ref_name); diff --git a/Source/Libs/GLibSharp/IOChannel.cs b/Source/Libs/GLibSharp/IOChannel.cs index b6e7b949f..554a1c244 100644 --- a/Source/Libs/GLibSharp/IOChannel.cs +++ b/Source/Libs/GLibSharp/IOChannel.cs @@ -185,14 +185,12 @@ public void Dispose () public uint AddWatch (int priority, IOCondition condition, IOFunc func) { - IOFuncWrapper func_wrapper = null; - IntPtr user_data = IntPtr.Zero; - DestroyNotify notify = null; - if (func != null) { - func_wrapper = new IOFuncWrapper (func); - user_data = (IntPtr) GCHandle.Alloc (func_wrapper); - notify = DestroyHelper.NotifyHandler; - } + if (func == null) + return 0; + + IOFuncWrapper func_wrapper = new IOFuncWrapper (func); + IntPtr user_data = (IntPtr) GCHandle.Alloc (func_wrapper); + DestroyNotify notify = DestroyHelper.NotifyHandler; return g_io_add_watch_full (Handle, priority, (int) condition, func_wrapper.NativeDelegate, user_data, notify); } diff --git a/Source/Libs/GLibSharp/KeyFile.cs b/Source/Libs/GLibSharp/KeyFile.cs index ea8f3dda0..515991b34 100644 --- a/Source/Libs/GLibSharp/KeyFile.cs +++ b/Source/Libs/GLibSharp/KeyFile.cs @@ -41,7 +41,7 @@ public enum KeyFileFlags { KeepTranslations = 1 << 1, } - public class KeyFile { + public class KeyFile : IDisposable { IntPtr handle; bool owned; @@ -65,10 +65,23 @@ public bool Handler () { if (!owned) return; + + if (handle == IntPtr.Zero) + return; + FinalizerInfo info = new FinalizerInfo (Handle); Timeout.Add (50, new TimeoutHandler (info.Handler)); } + public void Dispose () + { + if (owned && handle != IntPtr.Zero) + g_key_file_free (handle); + + handle = IntPtr.Zero; + GC.SuppressFinalize (this); + } + public KeyFile (IntPtr handle) : this (handle, false) {} public KeyFile (IntPtr handle, bool owned) @@ -183,6 +196,30 @@ public int GetInteger (string group_name, string key) return ret; } + public long GetInt64 (string group_name, string key) + { + IntPtr error; + IntPtr native_group_name = Marshaller.StringToPtrGStrdup (group_name); + IntPtr native_key = Marshaller.StringToPtrGStrdup (key); + long ret = g_key_file_get_int64 (Handle, native_group_name, native_key, out error); + Marshaller.Free (native_group_name); + Marshaller.Free (native_key); + if (error != IntPtr.Zero) throw new GException (error); + return ret; + } + + public ulong GetUInt64 (string group_name, string key) + { + IntPtr error; + IntPtr native_group_name = Marshaller.StringToPtrGStrdup (group_name); + IntPtr native_key = Marshaller.StringToPtrGStrdup (key); + ulong ret = g_key_file_get_uint64 (Handle, native_group_name, native_key, out error); + Marshaller.Free (native_group_name); + Marshaller.Free (native_key); + if (error != IntPtr.Zero) throw new GException (error); + return ret; + } + public int[] GetIntegerList (string group_name, string key) { IntPtr native_group_name = Marshaller.StringToPtrGStrdup (group_name); @@ -445,6 +482,24 @@ public void SetInteger (string group_name, string key, int value) Marshaller.Free (native_key); } + public void SetInt64 (string group_name, string key, long value) + { + IntPtr native_group_name = Marshaller.StringToPtrGStrdup (group_name); + IntPtr native_key = Marshaller.StringToPtrGStrdup (key); + g_key_file_set_int64 (Handle, native_group_name, native_key, value); + Marshaller.Free (native_group_name); + Marshaller.Free (native_key); + } + + public void SetUInt64 (string group_name, string key, ulong value) + { + IntPtr native_group_name = Marshaller.StringToPtrGStrdup (group_name); + IntPtr native_key = Marshaller.StringToPtrGStrdup (key); + g_key_file_set_uint64 (Handle, native_group_name, native_key, value); + Marshaller.Free (native_group_name); + Marshaller.Free (native_key); + } + public void SetIntegerList (string group_name, string key, int[] list) { if (list == null) @@ -540,125 +595,135 @@ public byte[] ToData () } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_free(IntPtr raw); - static d_g_key_file_free g_key_file_free = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_free")); + static d_g_key_file_free g_key_file_free = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_free")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_get_boolean(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_get_boolean g_key_file_get_boolean = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_boolean")); + static d_g_key_file_get_boolean g_key_file_get_boolean = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_boolean")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_boolean_list(IntPtr raw, IntPtr group_name, IntPtr key, out UIntPtr length, out IntPtr error); - static d_g_key_file_get_boolean_list g_key_file_get_boolean_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_boolean_list")); + static d_g_key_file_get_boolean_list g_key_file_get_boolean_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_boolean_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_comment(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_get_comment g_key_file_get_comment = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_comment")); + static d_g_key_file_get_comment g_key_file_get_comment = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_comment")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate double d_g_key_file_get_double(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_get_double g_key_file_get_double = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_double")); + static d_g_key_file_get_double g_key_file_get_double = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_double")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_double_list(IntPtr raw, IntPtr group_name, IntPtr key, out UIntPtr length, out IntPtr error); - static d_g_key_file_get_double_list g_key_file_get_double_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_double_list")); + static d_g_key_file_get_double_list g_key_file_get_double_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_double_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_groups(IntPtr raw, IntPtr dummy); - static d_g_key_file_get_groups g_key_file_get_groups = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_groups")); + static d_g_key_file_get_groups g_key_file_get_groups = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_groups")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int d_g_key_file_get_integer(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_get_integer g_key_file_get_integer = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_integer")); + static d_g_key_file_get_integer g_key_file_get_integer = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_integer")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_integer_list(IntPtr raw, IntPtr group_name, IntPtr key, out UIntPtr length, out IntPtr error); - static d_g_key_file_get_integer_list g_key_file_get_integer_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_integer_list")); + static d_g_key_file_get_integer_list g_key_file_get_integer_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_integer_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_keys(IntPtr raw, IntPtr group_name, IntPtr dummy, out IntPtr error); - static d_g_key_file_get_keys g_key_file_get_keys = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_keys")); + static d_g_key_file_get_keys g_key_file_get_keys = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_keys")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_locale_string(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr locale, out IntPtr error); - static d_g_key_file_get_locale_string g_key_file_get_locale_string = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_locale_string")); + static d_g_key_file_get_locale_string g_key_file_get_locale_string = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_locale_string")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_locale_string_list(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr locale, IntPtr dummy, out IntPtr error); - static d_g_key_file_get_locale_string_list g_key_file_get_locale_string_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_locale_string_list")); + static d_g_key_file_get_locale_string_list g_key_file_get_locale_string_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_locale_string_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_start_group(IntPtr raw); - static d_g_key_file_get_start_group g_key_file_get_start_group = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_start_group")); + static d_g_key_file_get_start_group g_key_file_get_start_group = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_start_group")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_string(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_get_string g_key_file_get_string = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_string")); + static d_g_key_file_get_string g_key_file_get_string = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_string")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_string_list(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr dummy, out IntPtr error); - static d_g_key_file_get_string_list g_key_file_get_string_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_string_list")); + static d_g_key_file_get_string_list g_key_file_get_string_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_string_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_get_value(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_get_value g_key_file_get_value = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_get_value")); + static d_g_key_file_get_value g_key_file_get_value = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_value")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_has_group(IntPtr raw, IntPtr group_name); - static d_g_key_file_has_group g_key_file_has_group = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_has_group")); + static d_g_key_file_has_group g_key_file_has_group = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_has_group")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_has_key(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_has_key g_key_file_has_key = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_has_key")); + static d_g_key_file_has_key g_key_file_has_key = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_has_key")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_load_from_data(IntPtr raw, byte[] data, UIntPtr length, int flags, out IntPtr error); - static d_g_key_file_load_from_data g_key_file_load_from_data = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_load_from_data")); + static d_g_key_file_load_from_data g_key_file_load_from_data = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_load_from_data")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_load_from_data_dirs(IntPtr raw, IntPtr file, out IntPtr full_path, int flags, out IntPtr error); - static d_g_key_file_load_from_data_dirs g_key_file_load_from_data_dirs = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_load_from_data_dirs")); + static d_g_key_file_load_from_data_dirs g_key_file_load_from_data_dirs = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_load_from_data_dirs")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_load_from_dirs(IntPtr raw, IntPtr file, IntPtr search_dirs, out IntPtr full_path, int flags, out IntPtr error); - static d_g_key_file_load_from_dirs g_key_file_load_from_dirs = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_load_from_dirs")); + static d_g_key_file_load_from_dirs g_key_file_load_from_dirs = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_load_from_dirs")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_load_from_file(IntPtr raw, IntPtr file, int flags, out IntPtr error); - static d_g_key_file_load_from_file g_key_file_load_from_file = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_load_from_file")); + static d_g_key_file_load_from_file g_key_file_load_from_file = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_load_from_file")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_new(); - static d_g_key_file_new g_key_file_new = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_new")); + static d_g_key_file_new g_key_file_new = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_new")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_remove_comment(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_remove_comment g_key_file_remove_comment = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_remove_comment")); + static d_g_key_file_remove_comment g_key_file_remove_comment = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_remove_comment")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_remove_group(IntPtr raw, IntPtr group_name, out IntPtr error); - static d_g_key_file_remove_group g_key_file_remove_group = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_remove_group")); + static d_g_key_file_remove_group g_key_file_remove_group = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_remove_group")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_remove_key(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); - static d_g_key_file_remove_key g_key_file_remove_key = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_remove_key")); + static d_g_key_file_remove_key g_key_file_remove_key = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_remove_key")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_boolean(IntPtr raw, IntPtr group_name, IntPtr key, bool value); - static d_g_key_file_set_boolean g_key_file_set_boolean = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_boolean")); + static d_g_key_file_set_boolean g_key_file_set_boolean = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_boolean")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_boolean_list(IntPtr raw, IntPtr group_name, IntPtr key, bool[] list, UIntPtr n_list); - static d_g_key_file_set_boolean_list g_key_file_set_boolean_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_boolean_list")); + static d_g_key_file_set_boolean_list g_key_file_set_boolean_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_boolean_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool d_g_key_file_set_comment(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr comment, out IntPtr error); - static d_g_key_file_set_comment g_key_file_set_comment = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_comment")); + static d_g_key_file_set_comment g_key_file_set_comment = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_comment")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_double(IntPtr raw, IntPtr group_name, IntPtr key, double value); - static d_g_key_file_set_double g_key_file_set_double = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_double")); + static d_g_key_file_set_double g_key_file_set_double = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_double")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_double_list(IntPtr raw, IntPtr group_name, IntPtr key, double[] list, UIntPtr n_list); - static d_g_key_file_set_double_list g_key_file_set_double_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_double_list")); + static d_g_key_file_set_double_list g_key_file_set_double_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_double_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_integer(IntPtr raw, IntPtr group_name, IntPtr key, int value); - static d_g_key_file_set_integer g_key_file_set_integer = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_integer")); + static d_g_key_file_set_integer g_key_file_set_integer = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_integer")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_integer_list(IntPtr raw, IntPtr group_name, IntPtr key, int[] list, UIntPtr n_list); - static d_g_key_file_set_integer_list g_key_file_set_integer_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_integer_list")); + static d_g_key_file_set_integer_list g_key_file_set_integer_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_integer_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_list_separator(IntPtr raw, byte separator); - static d_g_key_file_set_list_separator g_key_file_set_list_separator = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_list_separator")); + static d_g_key_file_set_list_separator g_key_file_set_list_separator = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_list_separator")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_locale_string(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr locale, IntPtr value); - static d_g_key_file_set_locale_string g_key_file_set_locale_string = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_locale_string")); + static d_g_key_file_set_locale_string g_key_file_set_locale_string = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_locale_string")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_locale_string_list(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr locale, IntPtr list, UIntPtr length); - static d_g_key_file_set_locale_string_list g_key_file_set_locale_string_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_locale_string_list")); + static d_g_key_file_set_locale_string_list g_key_file_set_locale_string_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_locale_string_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_string(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr value); - static d_g_key_file_set_string g_key_file_set_string = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_string")); + static d_g_key_file_set_string g_key_file_set_string = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_string")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_string_list(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr list, UIntPtr n_list); - static d_g_key_file_set_string_list g_key_file_set_string_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_string_list")); + static d_g_key_file_set_string_list g_key_file_set_string_list = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_string_list")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void d_g_key_file_set_value(IntPtr raw, IntPtr group_name, IntPtr key, IntPtr value); - static d_g_key_file_set_value g_key_file_set_value = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_set_value")); + static d_g_key_file_set_value g_key_file_set_value = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_value")); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr d_g_key_file_to_data(IntPtr raw, out UIntPtr length, IntPtr dummy); - static d_g_key_file_to_data g_key_file_to_data = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_key_file_to_data")); - + static d_g_key_file_to_data g_key_file_to_data = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_to_data")); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate long d_g_key_file_get_int64(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); + static d_g_key_file_get_int64 g_key_file_get_int64 = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_int64")); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate ulong d_g_key_file_get_uint64(IntPtr raw, IntPtr group_name, IntPtr key, out IntPtr error); + static d_g_key_file_get_uint64 g_key_file_get_uint64 = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_get_uint64")); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void d_g_key_file_set_int64(IntPtr raw, IntPtr group_name, IntPtr key, long value); + static d_g_key_file_set_int64 g_key_file_set_int64 = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_int64")); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void d_g_key_file_set_uint64(IntPtr raw, IntPtr group_name, IntPtr key, ulong value); + static d_g_key_file_set_uint64 g_key_file_set_uint64 = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_key_file_set_uint64")); } } - diff --git a/Source/Libs/GLibSharp/Marshaller.cs b/Source/Libs/GLibSharp/Marshaller.cs index 449e5b7f3..bb70434da 100644 --- a/Source/Libs/GLibSharp/Marshaller.cs +++ b/Source/Libs/GLibSharp/Marshaller.cs @@ -48,15 +48,14 @@ public static void Free (IntPtr[] ptrs) g_free (ptrs [i]); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate IntPtr d_g_filename_to_utf8(IntPtr mem, int len, IntPtr read, out IntPtr written, out IntPtr error); + delegate IntPtr d_g_filename_to_utf8(IntPtr mem, IntPtr len, IntPtr read, out IntPtr written, out IntPtr error); static d_g_filename_to_utf8 g_filename_to_utf8 = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_filename_to_utf8")); public static string FilenamePtrToString (IntPtr ptr) { if (ptr == IntPtr.Zero) return null; - IntPtr dummy, error; - IntPtr utf8 = g_filename_to_utf8 (ptr, -1, IntPtr.Zero, out dummy, out error); + IntPtr utf8 = g_filename_to_utf8 (ptr, (IntPtr)(-1), IntPtr.Zero, out _, out var error); if (error != IntPtr.Zero) throw new GLib.GException (error); @@ -117,7 +116,7 @@ public static string PtrToStringGFree (IntPtr ptr) return ret; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate IntPtr d_g_filename_from_utf8(IntPtr mem, int len, IntPtr read, out IntPtr written, out IntPtr error); + delegate IntPtr d_g_filename_from_utf8(IntPtr mem, IntPtr len, IntPtr read, out IntPtr written, out IntPtr error); static d_g_filename_from_utf8 g_filename_from_utf8 = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_filename_from_utf8")); public static IntPtr StringToFilenamePtr (string str) @@ -125,9 +124,8 @@ public static IntPtr StringToFilenamePtr (string str) if (str == null) return IntPtr.Zero; - IntPtr dummy, error; IntPtr utf8 = StringToPtrGStrdup (str); - IntPtr result = g_filename_from_utf8 (utf8, -1, IntPtr.Zero, out dummy, out error); + IntPtr result = g_filename_from_utf8 (utf8, (IntPtr)(-1), IntPtr.Zero, out _, out var error); g_free (utf8); if (error != IntPtr.Zero) diff --git a/Source/Libs/GdkSharp/EventSelection.cs b/Source/Libs/GdkSharp/EventSelection.cs index 7be982522..97cd0d30e 100644 --- a/Source/Libs/GdkSharp/EventSelection.cs +++ b/Source/Libs/GdkSharp/EventSelection.cs @@ -75,7 +75,6 @@ struct NativeStruct { get { return GLib.Opaque.GetOpaque (Native.target, typeof (Atom), false) as Atom; } set { NativeStruct native = Native; - native.target = value.Handle; native.target = value == null ? IntPtr.Zero : value.Handle; Marshal.StructureToPtr (native, Handle, false); } diff --git a/Source/Libs/GdkSharp/GdkSharp.metadata b/Source/Libs/GdkSharp/GdkSharp.metadata index cf9a428eb..97ce0e6d1 100644 --- a/Source/Libs/GdkSharp/GdkSharp.metadata +++ b/Source/Libs/GdkSharp/GdkSharp.metadata @@ -16,7 +16,6 @@ out 1 out - 1 EventHelper const-gchar* 1 @@ -100,6 +99,7 @@ 1 true 1 + true 1 1 1 diff --git a/Source/Libs/GioSharp/GioSharp.metadata b/Source/Libs/GioSharp/GioSharp.metadata index a7d1b8cbc..65fe8b1ea 100644 --- a/Source/Libs/GioSharp/GioSharp.metadata +++ b/Source/Libs/GioSharp/GioSharp.metadata @@ -14,6 +14,8 @@ GetDescription GetIcon GetMimeType + 1 + n_data Guess GuessForTree IsA diff --git a/Source/Libs/GtkSharp.snk b/Source/Libs/GtkSharp.snk new file mode 100644 index 000000000..54d626f05 Binary files /dev/null and b/Source/Libs/GtkSharp.snk differ diff --git a/Source/Libs/GtkSharp/Box.cs b/Source/Libs/GtkSharp/Box.cs new file mode 100644 index 000000000..da8891b44 --- /dev/null +++ b/Source/Libs/GtkSharp/Box.cs @@ -0,0 +1,30 @@ +// Gtk.Box.cs - Gtk Box class customizations +// +// Author: Marcel Tiede +// +// Copyright (C) 2019 Marcel Tiede +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +namespace Gtk { + + using System; + using System.Runtime.InteropServices; + + public partial class Box { + + protected Box() : base() { } + } +} diff --git a/Source/Libs/GtkSharp/Builder.cs b/Source/Libs/GtkSharp/Builder.cs index 75ff7279f..2d6c6daf8 100644 --- a/Source/Libs/GtkSharp/Builder.cs +++ b/Source/Libs/GtkSharp/Builder.cs @@ -33,90 +33,6 @@ namespace Gtk { using System.Text; public partial class Builder { - - [System.Serializable] - public class HandlerNotFoundException : SystemException - { - string handler_name; - string signal_name; - System.Reflection.EventInfo evnt; - Type delegate_type; - - public HandlerNotFoundException (string handler_name, string signal_name, - System.Reflection.EventInfo evnt, Type delegate_type) - : this (handler_name, signal_name, evnt, delegate_type, null) - { - } - - public HandlerNotFoundException (string handler_name, string signal_name, - System.Reflection.EventInfo evnt, Type delegate_type, Exception inner) - : base ("No handler " + handler_name + " found for signal " + signal_name, - inner) - { - this.handler_name = handler_name; - this.signal_name = signal_name; - this.evnt = evnt; - this.delegate_type = delegate_type; - } - - public HandlerNotFoundException (string message, string handler_name, string signal_name, - System.Reflection.EventInfo evnt, Type delegate_type) - : base ((message != null) ? message : "No handler " + handler_name + " found for signal " + signal_name, - null) - { - this.handler_name = handler_name; - this.signal_name = signal_name; - this.evnt = evnt; - this.delegate_type = delegate_type; - } - - protected HandlerNotFoundException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base (info, context) - { - handler_name = info.GetString ("HandlerName"); - signal_name = info.GetString ("SignalName"); - evnt = info.GetValue ("Event", typeof (System.Reflection.EventInfo)) as System.Reflection.EventInfo; - delegate_type = info.GetValue ("DelegateType", typeof (Type)) as Type; - } - - public string HandlerName - { - get { - return handler_name; - } - } - - public string SignalName - { - get { - return signal_name; - } - } - - public System.Reflection.EventInfo Event - { - get { - return evnt; - } - } - - public Type DelegateType - { - get { - return delegate_type; - } - } - - public override void GetObjectData (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - { - base.GetObjectData (info, context); - info.AddValue ("HandlerName", handler_name); - info.AddValue ("SignalName", signal_name); - info.AddValue ("Event", evnt); - info.AddValue ("DelegateType", delegate_type); - } - } - [AttributeUsage (AttributeTargets.Field)] public class ObjectAttribute : Attribute @@ -207,170 +123,24 @@ public Builder (Assembly assembly, string resource_name, string translation_doma public void Autoconnect (object handler) { - BindFields (handler); - (new SignalConnector (this, handler)).ConnectSignals (); + Autoconnect (handler, false); } - + + public void Autoconnect (object handler, bool throwOnUnknownObject) + { + BindFields (handler, handler.GetType (), throwOnUnknownObject); + new SignalConnector (handler).ConnectSignals (this); + } + public void Autoconnect (Type handler_class) { - BindFields (handler_class); - (new SignalConnector (this, handler_class)).ConnectSignals (); + Autoconnect (handler_class, false); } - class SignalConnector + public void Autoconnect (Type handler_class, bool throwOnUnknownObject) { - Builder builder; - Type handler_type; - object handler; - - public SignalConnector (Builder builder, object handler) - { - this.builder = builder; - this.handler = handler; - handler_type = handler.GetType (); - } - - public SignalConnector (Builder builder, Type handler_type) - { - this.builder = builder; - this.handler = null; - this.handler_type = handler_type; - } - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate void d_gtk_builder_connect_signals_full(IntPtr raw, GtkSharp.BuilderConnectFuncNative func, IntPtr user_data); - static d_gtk_builder_connect_signals_full gtk_builder_connect_signals_full = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_builder_connect_signals_full")); - - public void ConnectSignals() { - GtkSharp.BuilderConnectFuncWrapper func_wrapper = new GtkSharp.BuilderConnectFuncWrapper (new BuilderConnectFunc (ConnectFunc)); - gtk_builder_connect_signals_full(builder.Handle, func_wrapper.NativeDelegate, IntPtr.Zero); - } - - public void ConnectFunc (Builder builder, GLib.Object objekt, string signal_name, string handler_name, GLib.Object connect_object, GLib.ConnectFlags flags) - { - /* search for the event to connect */ - System.Reflection.MemberInfo[] evnts = objekt.GetType (). - FindMembers (System.Reflection.MemberTypes.Event, - System.Reflection.BindingFlags.Instance - | System.Reflection.BindingFlags.Static - | System.Reflection.BindingFlags.Public - | System.Reflection.BindingFlags.NonPublic, - new System.Reflection.MemberFilter (SignalFilter), signal_name); - foreach (System.Reflection.EventInfo ei in evnts) { - bool connected = false; - System.Reflection.MethodInfo add = ei.GetAddMethod (); - System.Reflection.ParameterInfo[] addpi = add.GetParameters (); - if (addpi.Length == 1) { /* this should be always true, unless there's something broken */ - Type delegate_type = addpi[0].ParameterType; - - /* look for an instance method */ - if (connect_object != null || handler != null) - try { - Delegate d = Delegate.CreateDelegate (delegate_type, connect_object != null ? connect_object : handler, handler_name); - add.Invoke (objekt, new object[] { d } ); - connected = true; - } catch (ArgumentException) { /* ignore if there is not such instance method */ - } - - /* look for a static method if no instance method has been found */ - if (!connected && handler_type != null) - try { - Delegate d = Delegate.CreateDelegate (delegate_type, handler_type, handler_name); - add.Invoke (objekt, new object[] { d } ); - connected = true; - } catch (ArgumentException) { /* ignore if there is not such static method */ - } - - if (!connected) { - string msg = ExplainError (ei.Name, delegate_type, handler_type, handler_name); - throw new HandlerNotFoundException (msg, handler_name, signal_name, ei, delegate_type); - } - } - } - } - - static bool SignalFilter (System.Reflection.MemberInfo m, object filterCriteria) - { - string signame = (filterCriteria as string); - object[] attrs = m.GetCustomAttributes (typeof (GLib.SignalAttribute), false); - if (attrs.Length > 0) - { - foreach (GLib.SignalAttribute a in attrs) - { - if (signame == a.CName) - { - return true; - } - } - return false; - } - else - { - /* this tries to match the names when no attibutes are present. - It is only a fallback. */ - signame = signame.ToLower ().Replace ("_", ""); - string evname = m.Name.ToLower (); - return signame == evname; - } - } - - static string GetSignature (System.Reflection.MethodInfo method) - { - if (method == null) - return null; - - System.Reflection.ParameterInfo [] parameters = method.GetParameters (); - System.Text.StringBuilder sb = new System.Text.StringBuilder (); - sb.Append ('('); - foreach (System.Reflection.ParameterInfo info in parameters) { - sb.Append (info.ParameterType.ToString ()); - sb.Append (','); - } - if (sb.Length != 0) - sb.Length--; - - sb.Append (')'); - return sb.ToString (); - } - - static string GetSignature (Type delegate_type) - { - System.Reflection.MethodInfo method = delegate_type.GetMethod ("Invoke"); - return GetSignature (method); - } - - const System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.NonPublic | - System.Reflection.BindingFlags.Public | - System.Reflection.BindingFlags.Static | - System.Reflection.BindingFlags.Instance; - static string GetSignature (Type klass, string method_name) - { - try { - System.Reflection.MethodInfo method = klass.GetMethod (method_name, flags); - return GetSignature (method); - } catch { - // May be more than one method with that name and none matches - return null; - } - } - - - static string ExplainError (string event_name, Type deleg, Type klass, string method) - { - if (deleg == null || klass == null || method == null) - return null; - - System.Text.StringBuilder sb = new System.Text.StringBuilder (); - string expected = GetSignature (deleg); - string actual = GetSignature (klass, method); - if (actual == null) - return null; - sb.AppendFormat ("The handler for the event {0} should take '{1}', " + - "but the signature of the provided handler ('{2}') is '{3}'\n", - event_name, expected, method, actual); - return sb.ToString (); - } - + BindFields (null, handler_class, throwOnUnknownObject); + new SignalConnector (handler_class).ConnectSignals (this); } void AddFromStream (Stream stream) @@ -390,17 +160,7 @@ void AddFromStream (Stream stream) AddFromString (text); } - void BindFields (object target) - { - BindFields (target, target.GetType ()); - } - - void BindFields (Type type) - { - BindFields (null, type); - } - - void BindFields (object target, Type type) + void BindFields (object target, Type type, bool throwOnUnknownObject) { System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.DeclaredOnly; if (target != null) @@ -421,11 +181,8 @@ void BindFields (object target, Type type) // The widget to field binding must be 1:1, so only check // the first attribute. ObjectAttribute attr = (ObjectAttribute) attrs[0]; - GLib.Object gobject; - if (attr.Specified) - gobject = GetObject (attr.Name); - else - gobject = GetObject (field.Name); + string name = attr.Specified ? attr.Name : field.Name; + GLib.Object gobject = GetObject (name); if (gobject != null) try { @@ -434,6 +191,8 @@ void BindFields (object target, Type type) Console.WriteLine ("Unable to set value for field " + field.Name); throw e; } + else if (throwOnUnknownObject) + throw new Exception ("Unknown object '" + name + "' to connect in type '" + type + "'"); } type = type.BaseType; } @@ -441,4 +200,3 @@ void BindFields (object target, Type type) } } } - diff --git a/Source/Libs/GtkSharp/ChildAttribute.cs b/Source/Libs/GtkSharp/ChildAttribute.cs new file mode 100644 index 000000000..ec46deaa5 --- /dev/null +++ b/Source/Libs/GtkSharp/ChildAttribute.cs @@ -0,0 +1,38 @@ +// ChildAttribute.cs - Child attribute +// +// Author: +// Marcel Tiede +// +// Copyright (c) 2019 Marcel Tiede +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +namespace Gtk +{ + using System; + + [AttributeUsage(AttributeTargets.Field)] + public class ChildAttribute : Attribute + { + public string Name { get; } + public bool Internal { get; } + + public ChildAttribute(string name = null, bool @internal = false) + { + this.Name = name; + this.Internal = @internal; + } + } +} diff --git a/Source/Libs/GtkSharp/Container.cs b/Source/Libs/GtkSharp/Container.cs index c812abe8f..c4c632f39 100644 --- a/Source/Libs/GtkSharp/Container.cs +++ b/Source/Libs/GtkSharp/Container.cs @@ -80,7 +80,7 @@ public IEnumerator GetEnumerator() class ChildAccumulator { - public ArrayList Children = new ArrayList(); + public System.Collections.Generic.List Children = new System.Collections.Generic.List(); public void Add(Gtk.Widget widget) { @@ -97,12 +97,12 @@ public IEnumerable AllChildren return acc.Children; } } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate bool d_gtk_container_get_focus_chain(IntPtr raw, out IntPtr list_ptr); - static d_gtk_container_get_focus_chain gtk_container_get_focus_chain = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_container_get_focus_chain")); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate void d_gtk_container_set_focus_chain(IntPtr raw, IntPtr list_ptr); - static d_gtk_container_set_focus_chain gtk_container_set_focus_chain = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_container_set_focus_chain")); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate bool d_gtk_container_get_focus_chain(IntPtr raw, out IntPtr list_ptr); + static d_gtk_container_get_focus_chain gtk_container_get_focus_chain = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_container_get_focus_chain")); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void d_gtk_container_set_focus_chain(IntPtr raw, IntPtr list_ptr); + static d_gtk_container_set_focus_chain gtk_container_set_focus_chain = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_container_set_focus_chain")); public Widget[] FocusChain { diff --git a/Source/Libs/GtkSharp/CssNameAttribute.cs b/Source/Libs/GtkSharp/CssNameAttribute.cs new file mode 100644 index 000000000..6fd8b57ee --- /dev/null +++ b/Source/Libs/GtkSharp/CssNameAttribute.cs @@ -0,0 +1,15 @@ +namespace Gtk { + + using System; + + [AttributeUsage(AttributeTargets.Class)] + public sealed class CssNameAttribute : Attribute { + + public CssNameAttribute (string name) + { + Name = name; + } + + public string Name { get; private set; } + } +} diff --git a/Source/Libs/GtkSharp/GtkSharp-api.xml b/Source/Libs/GtkSharp/GtkSharp-api.xml index 6e44325e5..c8cbd04a3 100644 --- a/Source/Libs/GtkSharp/GtkSharp-api.xml +++ b/Source/Libs/GtkSharp/GtkSharp-api.xml @@ -13638,7 +13638,7 @@ - + @@ -19833,8 +19833,8 @@ - - + + @@ -21211,7 +21211,7 @@ - + @@ -28475,7 +28475,7 @@ - + diff --git a/Source/Libs/GtkSharp/GtkSharp.metadata b/Source/Libs/GtkSharp/GtkSharp.metadata index 051f4d24e..01078c5b4 100644 --- a/Source/Libs/GtkSharp/GtkSharp.metadata +++ b/Source/Libs/GtkSharp/GtkSharp.metadata @@ -664,7 +664,7 @@ out out out - out + 1 1 out 1 @@ -858,8 +858,11 @@ 1 [GLib.TypeInitializer (typeof (Gtk.Widget), "ClassInit")] 1 + 1 1 1 + 1 + 1 out true 1 @@ -951,12 +954,6 @@ true true - SliderDetail - gchar* - slider_detail - - StepperDetail - 1 1 1 diff --git a/Source/Libs/GtkSharp/HBox.cs b/Source/Libs/GtkSharp/HBox.cs index 83fd52508..e9b75ea8a 100644 --- a/Source/Libs/GtkSharp/HBox.cs +++ b/Source/Libs/GtkSharp/HBox.cs @@ -19,6 +19,7 @@ namespace Gtk { public partial class HBox { + [Obsolete] public HBox () : this (false, 0) {} } diff --git a/Source/Libs/GtkSharp/HScale.cs b/Source/Libs/GtkSharp/HScale.cs index 5ae67c3f2..6eef0be32 100644 --- a/Source/Libs/GtkSharp/HScale.cs +++ b/Source/Libs/GtkSharp/HScale.cs @@ -28,6 +28,7 @@ public partial class HScale { delegate IntPtr d_gtk_hscale_new_with_range(double min, double max, double step); static d_gtk_hscale_new_with_range gtk_hscale_new_with_range = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_hscale_new_with_range")); + [Obsolete] public HScale (double min, double max, double step) : base (IntPtr.Zero) { if (GetType() != typeof (HScale)) { diff --git a/Source/Libs/GtkSharp/HandlerNotFoundException.cs b/Source/Libs/GtkSharp/HandlerNotFoundException.cs new file mode 100644 index 000000000..db98a6108 --- /dev/null +++ b/Source/Libs/GtkSharp/HandlerNotFoundException.cs @@ -0,0 +1,112 @@ +// HandlerNotFoundException.cs - exception for Gtk.Builder +// +// Authors: Stephane Delcroix +// The biggest part of this code is adapted from glade#, by +// Ricardo Fernández Pascual +// Rachel Hestilow +// +// Copyright (c) 2002 Ricardo Fernández Pascual +// Copyright (c) 2003 Rachel Hestilow +// Copyright (c) 2008 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +using System; + +namespace Gtk +{ + [System.Serializable] + public class HandlerNotFoundException : SystemException + { + string handler_name; + string signal_name; + System.Reflection.EventInfo evnt; + Type delegate_type; + + public HandlerNotFoundException (string handler_name, string signal_name, + System.Reflection.EventInfo evnt, Type delegate_type) + : this (handler_name, signal_name, evnt, delegate_type, null) + { + } + + public HandlerNotFoundException (string handler_name, string signal_name, + System.Reflection.EventInfo evnt, Type delegate_type, Exception inner) + : base ("No handler " + handler_name + " found for signal " + signal_name, + inner) + { + this.handler_name = handler_name; + this.signal_name = signal_name; + this.evnt = evnt; + this.delegate_type = delegate_type; + } + + public HandlerNotFoundException (string message, string handler_name, string signal_name, + System.Reflection.EventInfo evnt, Type delegate_type) + : base ((message != null) ? message : "No handler " + handler_name + " found for signal " + signal_name, + null) + { + this.handler_name = handler_name; + this.signal_name = signal_name; + this.evnt = evnt; + this.delegate_type = delegate_type; + } + + protected HandlerNotFoundException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) + : base (info, context) + { + handler_name = info.GetString ("HandlerName"); + signal_name = info.GetString ("SignalName"); + evnt = info.GetValue ("Event", typeof (System.Reflection.EventInfo)) as System.Reflection.EventInfo; + delegate_type = info.GetValue ("DelegateType", typeof (Type)) as Type; + } + + public string HandlerName + { + get { + return handler_name; + } + } + + public string SignalName + { + get { + return signal_name; + } + } + + public System.Reflection.EventInfo Event + { + get { + return evnt; + } + } + + public Type DelegateType + { + get { + return delegate_type; + } + } + + public override void GetObjectData (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) + { + base.GetObjectData (info, context); + info.AddValue ("HandlerName", handler_name); + info.AddValue ("SignalName", signal_name); + info.AddValue ("Event", evnt); + info.AddValue ("DelegateType", delegate_type); + } + } +} diff --git a/Source/Libs/GtkSharp/IconFactory.cs b/Source/Libs/GtkSharp/IconFactory.cs index 04b1b4195..8ec8e9a4e 100644 --- a/Source/Libs/GtkSharp/IconFactory.cs +++ b/Source/Libs/GtkSharp/IconFactory.cs @@ -24,7 +24,7 @@ public partial class IconFactory { static d_gtk_icon_size_lookup gtk_icon_size_lookup = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_icon_size_lookup")); /// Query icon dimensions - /// Queries dimensions for icons of the specified size. + /// Queries dimensions for icons of the specified size. public void LookupIconSize (IconSize size, out int width, out int height) { gtk_icon_size_lookup (size, out width, out height); diff --git a/Source/Libs/GtkSharp/IconSet.cs b/Source/Libs/GtkSharp/IconSet.cs index 91b5fd454..71dc2fd5b 100644 --- a/Source/Libs/GtkSharp/IconSet.cs +++ b/Source/Libs/GtkSharp/IconSet.cs @@ -25,6 +25,7 @@ public partial class IconSet { /// Sizes Property /// To be completed + [Obsolete] public Gtk.IconSize [] Sizes { get { diff --git a/Source/Libs/GtkSharp/IconTheme.cs b/Source/Libs/GtkSharp/IconTheme.cs index 9ecfe829f..a99c4c8f8 100644 --- a/Source/Libs/GtkSharp/IconTheme.cs +++ b/Source/Libs/GtkSharp/IconTheme.cs @@ -93,9 +93,9 @@ public string[] ListIcons (string context) native_path = GLib.Marshaller.StringArrayToNullTermPointer (value); if (IsWindowsPlatform) - gtk_icon_theme_set_search_path_utf8 (Handle, native_path, value.Length); + gtk_icon_theme_set_search_path_utf8 (Handle, native_path, value != null ? value.Length : 0); else - gtk_icon_theme_set_search_path (Handle, native_path, value.Length); + gtk_icon_theme_set_search_path (Handle, native_path, value != null ? value.Length : 0); GLib.Marshaller.Free (native_path); } diff --git a/Source/Libs/GtkSharp/ImageMenuItem.cs b/Source/Libs/GtkSharp/ImageMenuItem.cs index c2644d93a..afbad46f6 100644 --- a/Source/Libs/GtkSharp/ImageMenuItem.cs +++ b/Source/Libs/GtkSharp/ImageMenuItem.cs @@ -28,6 +28,7 @@ public partial class ImageMenuItem { delegate IntPtr d_gtk_image_menu_item_new_with_mnemonic(IntPtr label); static d_gtk_image_menu_item_new_with_mnemonic gtk_image_menu_item_new_with_mnemonic = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_image_menu_item_new_with_mnemonic")); + [Obsolete] public ImageMenuItem (string label) : base (IntPtr.Zero) { if (GetType() != typeof (ImageMenuItem)) { diff --git a/Source/Libs/GtkSharp/NodeView.cs b/Source/Libs/GtkSharp/NodeView.cs index 1127a890b..ded012a2e 100644 --- a/Source/Libs/GtkSharp/NodeView.cs +++ b/Source/Libs/GtkSharp/NodeView.cs @@ -83,7 +83,7 @@ public Gtk.TreeViewColumn AppendColumn (string title, Gtk.CellRenderer cell, Gtk } public Gdk.Rectangle GetCellArea (ITreeNode node, Gtk.TreeViewColumn column) { - return GetBackgroundArea (store.GetPath (node), column); + return GetCellArea (store.GetPath (node), column); } public ITreeNode GetNodeAtPos (int x, int y) { diff --git a/Source/Libs/GtkSharp/Printer.cs b/Source/Libs/GtkSharp/Printer.cs index 9f2277032..ad4d4f308 100644 --- a/Source/Libs/GtkSharp/Printer.cs +++ b/Source/Libs/GtkSharp/Printer.cs @@ -30,20 +30,13 @@ public partial class Printer { public static void EnumeratePrinters (Gtk.PrinterFunc func, bool wait) { - GtkSharp.PrinterFuncWrapper func_wrapper; - IntPtr func_data; - GLib.DestroyNotify destroy; - if (func == null) { - func_wrapper = null; - func_data = IntPtr.Zero; - destroy = null; - } else { - func_wrapper = new GtkSharp.PrinterFuncWrapper (func); - func_data = (IntPtr) GCHandle.Alloc (func_wrapper); - destroy = GLib.DestroyHelper.NotifyHandler; - } + if (func == null) + return; + + GtkSharp.PrinterFuncWrapper func_wrapper = new GtkSharp.PrinterFuncWrapper (func); + IntPtr func_data = (IntPtr) GCHandle.Alloc (func_wrapper); + GLib.DestroyNotify destroy = GLib.DestroyHelper.NotifyHandler; gtk_enumerate_printers (func_wrapper.NativeDelegate, func_data, destroy, wait); } } } - diff --git a/Source/Libs/GtkSharp/RadioAction.cs b/Source/Libs/GtkSharp/RadioAction.cs index 5f3bc3482..3f7b319e4 100644 --- a/Source/Libs/GtkSharp/RadioAction.cs +++ b/Source/Libs/GtkSharp/RadioAction.cs @@ -32,6 +32,7 @@ public partial class RadioAction delegate void d_gtk_radio_action_set_group(IntPtr raw, IntPtr list); static d_gtk_radio_action_set_group gtk_radio_action_set_group = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_radio_action_set_group")); + [Obsolete] [GLib.Property ("group")] public RadioAction[] Group { get { diff --git a/Source/Libs/GtkSharp/RadioToolButton.cs b/Source/Libs/GtkSharp/RadioToolButton.cs index 066143b78..439743815 100644 --- a/Source/Libs/GtkSharp/RadioToolButton.cs +++ b/Source/Libs/GtkSharp/RadioToolButton.cs @@ -49,6 +49,7 @@ public RadioToolButton (RadioToolButton[] group) : base (IntPtr.Zero) delegate IntPtr d_gtk_radio_tool_button_new_from_stock(IntPtr group, IntPtr stock_id); static d_gtk_radio_tool_button_new_from_stock gtk_radio_tool_button_new_from_stock = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_radio_tool_button_new_from_stock")); + [Obsolete] public RadioToolButton (RadioToolButton[] group, string stock_id) : base (IntPtr.Zero) { if (GetType () != typeof (RadioToolButton)) { diff --git a/Source/Libs/GtkSharp/SignalConnector.cs b/Source/Libs/GtkSharp/SignalConnector.cs new file mode 100644 index 000000000..397b642fd --- /dev/null +++ b/Source/Libs/GtkSharp/SignalConnector.cs @@ -0,0 +1,204 @@ +// SignalConnector.cs - helper for Gtk.Builder +// +// Authors: Stephane Delcroix +// The biggest part of this code is adapted from glade#, by +// Ricardo Fernández Pascual +// Rachel Hestilow +// +// Copyright (c) 2002 Ricardo Fernández Pascual +// Copyright (c) 2003 Rachel Hestilow +// Copyright (c) 2008 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +using System; +using System.Runtime.InteropServices; + +namespace Gtk +{ + internal class SignalConnector + { + Type handler_type; + object handler; + internal object template_object_instance; + + public SignalConnector (object handler) + { + this.handler = handler; + handler_type = handler.GetType (); + } + + public SignalConnector (Type handler_type) + { + this.handler = null; + this.handler_type = handler_type; + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void d_gtk_builder_connect_signals_full(IntPtr raw, GtkSharp.BuilderConnectFuncNative func, IntPtr user_data); + static d_gtk_builder_connect_signals_full gtk_builder_connect_signals_full = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_builder_connect_signals_full")); + + public void ConnectSignals(Builder builder) { + GtkSharp.BuilderConnectFuncWrapper func_wrapper = new GtkSharp.BuilderConnectFuncWrapper (new BuilderConnectFunc (ConnectFunc)); + gtk_builder_connect_signals_full(builder.Handle, func_wrapper.NativeDelegate, IntPtr.Zero); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_gtk_widget_class_set_connect_func(IntPtr class_ptr, GtkSharp.BuilderConnectFuncNative connect_func, IntPtr data); + static d_gtk_widget_class_set_connect_func gtk_widget_class_set_connect_func = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), nameof(gtk_widget_class_set_connect_func))); + + public void ConnectSignals(GLib.GType gtype) + { + var func_wrapper = new GtkSharp.BuilderConnectFuncWrapper (new BuilderConnectFunc (ConnectFunc)); + gtk_widget_class_set_connect_func(gtype.GetClassPtr (), func_wrapper.NativeDelegate, IntPtr.Zero); + } + + public void ConnectFunc (Builder builder, GLib.Object objekt, string signal_name, string handler_name, GLib.Object connect_object, GLib.ConnectFlags flags) + { + /* search for the event to connect */ + System.Reflection.MemberInfo[] evnts = objekt.GetType (). + FindMembers (System.Reflection.MemberTypes.Event, + System.Reflection.BindingFlags.Instance + | System.Reflection.BindingFlags.Static + | System.Reflection.BindingFlags.Public + | System.Reflection.BindingFlags.NonPublic, + new System.Reflection.MemberFilter (SignalFilter), signal_name); + foreach (System.Reflection.EventInfo ei in evnts) { + bool connected = false; + System.Reflection.MethodInfo add = ei.GetAddMethod (); + System.Reflection.ParameterInfo[] addpi = add.GetParameters (); + if (addpi.Length == 1) { /* this should be always true, unless there's something broken */ + Type delegate_type = addpi[0].ParameterType; + + /* look for an instance method */ + if (connect_object != null || handler != null) + try { + Delegate d = Delegate.CreateDelegate (delegate_type, connect_object != null ? connect_object : handler, handler_name); + add.Invoke (objekt, new object[] { d } ); + connected = true; + } catch (ArgumentException) { /* ignore if there is not such instance method */ + } + + /* look for an instance method for template */ + if (!connected && template_object_instance != null) + try { + Delegate d = Delegate.CreateDelegate (delegate_type, template_object_instance, handler_name); + add.Invoke (objekt, new object[] { d }); + connected = true; + } catch (ArgumentException) { /* ignore if there is not such instance method */ + } + + /* look for a static method if no instance method has been found */ + if (!connected && handler_type != null) + try { + Delegate d = Delegate.CreateDelegate (delegate_type, handler_type, handler_name); + add.Invoke (objekt, new object[] { d } ); + connected = true; + } catch (ArgumentException) { /* ignore if there is not such static method */ + } + + if (!connected) { + string msg = ExplainError (ei.Name, delegate_type, handler_type, handler_name); + throw new HandlerNotFoundException (msg, handler_name, signal_name, ei, delegate_type); + } + } + } + } + + static bool SignalFilter (System.Reflection.MemberInfo m, object filterCriteria) + { + string signame = (filterCriteria as string); + object[] attrs = m.GetCustomAttributes (typeof (GLib.SignalAttribute), false); + if (attrs.Length > 0) + { + foreach (GLib.SignalAttribute a in attrs) + { + if (signame == a.CName) + { + return true; + } + } + return false; + } + else + { + /* this tries to match the names when no attributes are present. + It is only a fallback. */ + signame = signame.ToLower ().Replace ("_", ""); + string evname = m.Name.ToLower (); + return signame == evname; + } + } + + static string GetSignature (System.Reflection.MethodInfo method) + { + if (method == null) + return null; + + System.Reflection.ParameterInfo [] parameters = method.GetParameters (); + System.Text.StringBuilder sb = new System.Text.StringBuilder (); + sb.Append ('('); + foreach (System.Reflection.ParameterInfo info in parameters) { + sb.Append (info.ParameterType.ToString ()); + sb.Append (','); + } + if (sb.Length != 0) + sb.Length--; + + sb.Append (')'); + return sb.ToString (); + } + + static string GetSignature (Type delegate_type) + { + System.Reflection.MethodInfo method = delegate_type.GetMethod ("Invoke"); + return GetSignature (method); + } + + static string GetSignature (Type klass, string method_name) + { + const System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.NonPublic | + System.Reflection.BindingFlags.Public | + System.Reflection.BindingFlags.Static | + System.Reflection.BindingFlags.Instance; + + try { + System.Reflection.MethodInfo method = klass.GetMethod (method_name, flags); + return GetSignature (method); + } catch { + // May be more than one method with that name and none matches + return null; + } + } + + static string ExplainError (string event_name, Type deleg, Type klass, string method) + { + if (deleg == null || klass == null || method == null) + return null; + + System.Text.StringBuilder sb = new System.Text.StringBuilder (); + string expected = GetSignature (deleg); + string actual = GetSignature (klass, method); + if (actual == null) + return null; + + sb.AppendFormat ("The handler for the event {0} should take '{1}', " + + "but the signature of the provided handler ('{2}') is '{3}'\n", + event_name, expected, method, actual); + + return sb.ToString (); + } + } +} diff --git a/Source/Libs/GtkSharp/StatusIcon.cs b/Source/Libs/GtkSharp/StatusIcon.cs index 116a9d467..6b476a043 100644 --- a/Source/Libs/GtkSharp/StatusIcon.cs +++ b/Source/Libs/GtkSharp/StatusIcon.cs @@ -87,6 +87,7 @@ public void PresentMenu (Menu menu, uint button, uint activate_time) delegate bool d_gtk_status_icon_get_geometry(IntPtr raw, out IntPtr screen, IntPtr area, out int orientation); static d_gtk_status_icon_get_geometry gtk_status_icon_get_geometry = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_status_icon_get_geometry")); + [Obsolete] public bool GetGeometry(out Gdk.Screen screen, out Gdk.Rectangle area, out Gtk.Orientation orientation) { IntPtr native_screen; diff --git a/Source/Libs/GtkSharp/StyleContext.cs b/Source/Libs/GtkSharp/StyleContext.cs index 189ef2772..afebd3bea 100644 --- a/Source/Libs/GtkSharp/StyleContext.cs +++ b/Source/Libs/GtkSharp/StyleContext.cs @@ -16,6 +16,7 @@ using System; +using System.Runtime.InteropServices; namespace Gtk { @@ -95,5 +96,21 @@ public void RenderSlider (Cairo.Context cr, double x, double y, double width, do { Render.Slider (this, cr, x, y, width, height, orientation); } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + unsafe delegate void d_gtk_style_context_get_property(IntPtr raw, IntPtr property, int state, GLib.Value* value); + static d_gtk_style_context_get_property gtk_style_context_get_property = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_style_context_get_property")); + + public GLib.Value GetProperty(string property, Gtk.StateFlags state) + { + var value = new GLib.Value(); + IntPtr native_property = GLib.Marshaller.StringToPtrGStrdup(property); + unsafe + { + gtk_style_context_get_property(Handle, native_property, (int)state, &value); + } + GLib.Marshaller.Free(native_property); + return value; + } } } diff --git a/Source/Libs/GtkSharp/TemplateAttribute.cs b/Source/Libs/GtkSharp/TemplateAttribute.cs new file mode 100644 index 000000000..4204dcc0d --- /dev/null +++ b/Source/Libs/GtkSharp/TemplateAttribute.cs @@ -0,0 +1,44 @@ +// TemplateAttribute.cs - Template attribute +// +// Author: +// Marcel Tiede +// +// Copyright (c) 2019 Marcel Tiede +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +namespace Gtk +{ + using System; + + [AttributeUsage(AttributeTargets.Class)] + public class TemplateAttribute : Attribute + { + public string Ui { get; } + + public bool ThrowOnUnknownChild { get; } + + public TemplateAttribute(string ui) + { + Ui = ui; + } + + public TemplateAttribute(string ui, bool throwOnUnknownChild) + { + Ui = ui; + ThrowOnUnknownChild = throwOnUnknownChild; + } + } +} diff --git a/Source/Libs/GtkSharp/UIManager.cs b/Source/Libs/GtkSharp/UIManager.cs index 02fa9cb7e..56f1400a1 100644 --- a/Source/Libs/GtkSharp/UIManager.cs +++ b/Source/Libs/GtkSharp/UIManager.cs @@ -26,6 +26,7 @@ namespace Gtk { public partial class UIManager { + [Obsolete] [MethodImpl(MethodImplOptions.NoInlining)] public uint AddUiFromResource (string resource) { @@ -42,6 +43,7 @@ public uint AddUiFromResource (string resource) delegate uint d_gtk_ui_manager_new_merge_id(IntPtr raw); static d_gtk_ui_manager_new_merge_id gtk_ui_manager_new_merge_id = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_ui_manager_new_merge_id")); + [Obsolete] public uint NewMergeId () { return gtk_ui_manager_new_merge_id (Handle); @@ -50,10 +52,11 @@ public uint NewMergeId () delegate IntPtr d_gtk_ui_manager_get_toplevels(IntPtr raw, int types); static d_gtk_ui_manager_get_toplevels gtk_ui_manager_get_toplevels = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_ui_manager_get_toplevels")); + [Obsolete] public Widget[] GetToplevels (Gtk.UIManagerItemType types) { IntPtr raw_ret = gtk_ui_manager_get_toplevels (Handle, (int) types); GLib.SList list = new GLib.SList (raw_ret); - Widget[] result = new Widget [list.Count]; + Widget[] result = new Widget [list.Count]; for (int i = 0; i < list.Count; i++) result [i] = list [i] as Widget; @@ -63,11 +66,12 @@ public uint NewMergeId () delegate IntPtr d_gtk_ui_manager_get_action_groups(IntPtr raw); static d_gtk_ui_manager_get_action_groups gtk_ui_manager_get_action_groups = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_ui_manager_get_action_groups")); + [Obsolete] public ActionGroup[] ActionGroups { get { IntPtr raw_ret = gtk_ui_manager_get_action_groups (Handle); GLib.List list = new GLib.List(raw_ret); - ActionGroup[] result = new ActionGroup [list.Count]; + ActionGroup[] result = new ActionGroup [list.Count]; for (int i = 0; i < list.Count; i++) result [i] = list [i] as ActionGroup; diff --git a/Source/Libs/GtkSharp/VBox.cs b/Source/Libs/GtkSharp/VBox.cs index d2fe292b6..48268859c 100644 --- a/Source/Libs/GtkSharp/VBox.cs +++ b/Source/Libs/GtkSharp/VBox.cs @@ -19,6 +19,7 @@ namespace Gtk { public partial class VBox { + [Obsolete] public VBox () : this (false, 0) {} } diff --git a/Source/Libs/GtkSharp/VScale.cs b/Source/Libs/GtkSharp/VScale.cs index cad220ce2..a320cf9cd 100644 --- a/Source/Libs/GtkSharp/VScale.cs +++ b/Source/Libs/GtkSharp/VScale.cs @@ -28,6 +28,7 @@ public partial class VScale { delegate IntPtr d_gtk_vscale_new_with_range(double min, double max, double step); static d_gtk_vscale_new_with_range gtk_vscale_new_with_range = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_vscale_new_with_range")); + [Obsolete] public VScale (double min, double max, double step) : base (IntPtr.Zero) { if (GetType() != typeof (VScale)) { diff --git a/Source/Libs/GtkSharp/Widget.cs b/Source/Libs/GtkSharp/Widget.cs index 370f3ac18..c92cad14d 100644 --- a/Source/Libs/GtkSharp/Widget.cs +++ b/Source/Libs/GtkSharp/Widget.cs @@ -3,7 +3,9 @@ // // Authors: Rachel Hestilow , // Brad Taylor +// Marcel Tiede // +// Copyright (C) 2019 Marcel Tiede // Copyright (C) 2007 Brad Taylor // Copyright (C) 2002 Rachel Hestilow // @@ -25,6 +27,7 @@ namespace Gtk { using System; using System.Collections.Generic; + using System.Reflection; using System.Runtime.InteropServices; public partial class Widget { @@ -35,6 +38,22 @@ public partial class Widget { set { Window = value; } } + struct TemplateData + { + public Dictionary FieldBindings; + public SignalConnector SignalConnector; + public bool ThrowOnUnknownChild; + + public static TemplateData Create() + { + var res = new TemplateData(); + res.FieldBindings = new Dictionary(); + return res; + } + } + + private static Dictionary Templates = new Dictionary(); + public void AddAccelerator (string accel_signal, AccelGroup accel_group, AccelKey accel_key) { this.AddAccelerator (accel_signal, accel_group, (uint) accel_key.Key, accel_key.AccelMods, (Gtk.AccelFlags) accel_key.AccelFlags); @@ -194,6 +213,13 @@ struct GtkBindingArgData { } static void ClassInit (GLib.GType gtype, Type t) + { + InitBindings (gtype, t); + InitTemplateForType (gtype, t); + InitCssName (gtype, t); + } + + static void InitBindings (GLib.GType gtype, Type t) { object[] attrs = t.GetCustomAttributes (typeof (BindingAttribute), true); if (attrs.Length == 0) return; @@ -229,6 +255,104 @@ static void ClassInit (GLib.GType gtype, Type t) GLib.Marshaller.Free (native_signame); } + static void InitTemplateForType (GLib.GType gtype, Type type) + { + var attr = type.GetCustomAttribute (true); + if (attr == null) return; + + var data = TemplateData.Create (); + data.ThrowOnUnknownChild = attr.ThrowOnUnknownChild; + var resource_name = attr.Ui; + var resource_stream = type.Assembly.GetManifestResourceStream (resource_name); + + if (resource_stream == null) + throw new Exception ("Template resource '" + resource_name + "' not found"); + + SetTemplateFromStream (gtype, resource_stream); + BindTemplateChildren (gtype, type, data.FieldBindings); + + data.SignalConnector = new SignalConnector (type); + data.SignalConnector.ConnectSignals (gtype); + Templates[type] = data; + } + + delegate IntPtr d_gtk_widget_class_set_template(IntPtr class_ptr, IntPtr template_bytes); + static d_gtk_widget_class_set_template gtk_widget_class_set_template = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_widget_class_set_template")); + + static void SetTemplateFromStream (GLib.GType gtype, System.IO.Stream resource) + { + var buffer = new byte[(int)resource.Length]; + resource.Read (buffer, 0, buffer.Length); + resource.Dispose (); + + var bytes = new GLib.Bytes (buffer); + gtk_widget_class_set_template (gtype.GetClassPtr (), bytes.Handle); + bytes.Dispose (); + } + + delegate IntPtr d_gtk_widget_class_bind_template_child_full(IntPtr class_ptr, IntPtr name, bool internal_child, IntPtr struct_offset); + static d_gtk_widget_class_bind_template_child_full gtk_widget_class_bind_template_child_full = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_widget_class_bind_template_child_full")); + + static void BindTemplateChildren (GLib.GType gtype, Type type, Dictionary fields) + { + const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance; + + foreach (var field in type.GetFields (flags)) + { + var attr = field.GetCustomAttribute (true); + + if (attr == null) + continue; + + var name = attr.Name ?? field.Name; + + var native_name = GLib.Marshaller.StringToPtrGStrdup (name); + gtk_widget_class_bind_template_child_full (gtype.GetClassPtr (), native_name, attr.Internal, new IntPtr ((long)0)); + GLib.Marshaller.Free (native_name); + + fields[field] = name; + } + } + + static void InitCssName (GLib.GType gtype, Type t) + { + CssNameAttribute attr = t.GetCustomAttribute(true); + if (attr != null) + SetCssName (gtype, attr.Name); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void d_gtk_widget_init_template(IntPtr raw); + static d_gtk_widget_init_template gtk_widget_init_template = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_widget_init_template")); + + void InitTemplateForInstance () + { + var type = GetType (); + if (Templates.TryGetValue(type, out TemplateData data)) + { + GLib.GType gtype = LookupGType (type); + data.SignalConnector.template_object_instance = this; + gtk_widget_init_template (Handle); + data.SignalConnector.template_object_instance = null; + foreach (KeyValuePair pair in data.FieldBindings) + { + FieldInfo field = pair.Key; + string name = pair.Value; + GLib.Object child = GetTemplateChild (gtype, name); + + if (child != null) + { + const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance; + field.SetValue (this, child, flags, null, null); + } + else if (data.ThrowOnUnknownChild) + { + throw new Exception ("Unknown child in template for type '" + type + "'"); + } + } + } + } + public object StyleGetProperty (string property_name) { GLib.Value value; @@ -386,6 +510,7 @@ static void NativeDestroy (object o, EventArgs args) protected override void CreateNativeObject (string[] names, GLib.Value[] vals) { base.CreateNativeObject (names, vals); + InitTemplateForInstance (); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -445,6 +570,30 @@ public virtual void Destroy () InternalDestroyed -= NativeDestroyHandler; } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_gtk_widget_class_get_css_name(IntPtr widget_class); + static d_gtk_widget_class_get_css_name gtk_widget_class_get_css_name = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_widget_class_get_css_name")); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void d_gtk_widget_class_set_css_name(IntPtr widget_class, IntPtr name); + static d_gtk_widget_class_set_css_name gtk_widget_class_set_css_name = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_widget_class_set_css_name")); + + public static string GetCssName (GLib.GType widget_type) + { + IntPtr class_ptr = widget_type.GetClassPtr (); + IntPtr native_name = gtk_widget_class_get_css_name (class_ptr); + string name = GLib.Marshaller.Utf8PtrToString (native_name); + return name; + } + + protected static void SetCssName (GLib.GType widget_type, string name) + { + IntPtr class_ptr = widget_type.GetClassPtr (); + IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name); + gtk_widget_class_set_css_name (class_ptr, native_name); + GLib.Marshaller.Free (native_name); + } } } diff --git a/Source/Libs/PangoSharp/PangoSharp.metadata b/Source/Libs/PangoSharp/PangoSharp.metadata index fcb2b4a83..da202ca39 100644 --- a/Source/Libs/PangoSharp/PangoSharp.metadata +++ b/Source/Libs/PangoSharp/PangoSharp.metadata @@ -40,6 +40,8 @@ Library.PangoCairo 1 1 + true + true ref PangoItem* true diff --git a/Source/Samples/Sections/Dialogs/FileChooserDialogSection.cs b/Source/Samples/Sections/Dialogs/FileChooserDialogSection.cs new file mode 100644 index 000000000..6c75a366a --- /dev/null +++ b/Source/Samples/Sections/Dialogs/FileChooserDialogSection.cs @@ -0,0 +1,32 @@ +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(FileChooserDialog), Category = Category.Dialogs)] + class FileChooserDialogSection : ListSection + { + public FileChooserDialogSection () + { + AddItem ($"Press button to open {nameof(FileChooserDialog)} :", new FileChooserDialogDemo ("Press me")); + } + } + + class FileChooserDialogDemo : Button + { + public FileChooserDialogDemo (string text) : base (text) { } + + protected override void OnPressed () + { + var fcd = new FileChooserDialog ("Open File", null, FileChooserAction.Open); + fcd.AddButton (Stock.Cancel, ResponseType.Cancel); + fcd.AddButton (Stock.Open, ResponseType.Ok); + fcd.DefaultResponse = ResponseType.Ok; + fcd.SelectMultiple = false; + + ResponseType response = (ResponseType) fcd.Run (); + if (response == ResponseType.Ok) + ApplicationOutput.WriteLine (fcd.Filename); + fcd.Destroy (); + } + } +} \ No newline at end of file diff --git a/Source/Samples/Sections/Miscellaneous/CssNameSection.cs b/Source/Samples/Sections/Miscellaneous/CssNameSection.cs new file mode 100644 index 000000000..c4f162876 --- /dev/null +++ b/Source/Samples/Sections/Miscellaneous/CssNameSection.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(CssNameDemo), Category = Category.Miscellaneous)] + class CssNameSection : Box + { + public CssNameSection() : base(Orientation.Vertical, 3) + { + CssNameDemo.Create(this); + } + } + + class CssNameDemo + { + // inherited label has same css name as parent + internal class MyLabel : Label + { + } + + // css name can be set by [CssName] + [CssName("my-label-attrib")] + internal class MyLabelWithAttrib : Label + { + } + + // css name can be set in class initializer method + [GLib.TypeInitializer(typeof(MyLabelWithInit), nameof(MyLabelWithInit.ClassInit))] + internal class MyLabelWithInit : Label + { + static void ClassInit(GLib.GType gtype, Type type) + { + SetCssName(gtype, "my-label-init"); + } + } + + public static void Create(Box box) + { + var css = new CssProvider(); + css.LoadFromData(@" +label.x { + background: LightCoral; +} +my-label-attrib { + background: LightGreen; +} +my-label-init { + background: LightSkyBlue; +} +my-label-init.x { + background: LightBlue; +} +"); + StyleContext.AddProviderForScreen(Gdk.Screen.Default, css, StyleProviderPriority.Application); + + string name; + + name = Widget.GetCssName(Label.GType); + var label1 = new Label { Text = "Label, css name: " + name }; + label1.StyleContext.AddClass("x"); + + name = Widget.GetCssName((GLib.GType)typeof(MyLabel)); + var label2 = new MyLabel { Text = "Inherited Label, css name: " + name }; + label2.StyleContext.AddClass("x"); + + name = Widget.GetCssName((GLib.GType)typeof(MyLabelWithAttrib)); + var label3 = new MyLabelWithAttrib { Text = "Inherited Label with [CssName], css name: " + name }; + + name = Widget.GetCssName((GLib.GType)typeof(MyLabelWithInit)); + var label4 = new MyLabelWithInit { Text = "Inherited Label with class initializer, css name: " + name }; + + name = Widget.GetCssName((GLib.GType)typeof(MyLabelWithInit)); + var label5 = new MyLabelWithInit { Text = "Inherited Label with class initializer and css class, css name: " + name }; + label5.StyleContext.AddClass("x"); + + box.PackStart(label1, false, false, 0); + box.PackStart(label2, false, false, 0); + box.PackStart(label3, false, false, 0); + box.PackStart(label4, false, false, 0); + box.PackStart(label5, false, false, 0); + } + } +} diff --git a/Source/Samples/Sections/Miscellaneous/StyleContextSection.cs b/Source/Samples/Sections/Miscellaneous/StyleContextSection.cs new file mode 100644 index 000000000..829c382c6 --- /dev/null +++ b/Source/Samples/Sections/Miscellaneous/StyleContextSection.cs @@ -0,0 +1,30 @@ +using System; +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(StyleContext), Category = Category.Miscellaneous)] + class StyleContextSection : ListSection + { + public StyleContextSection() + { + var btn = new Button() { Label = "Press me" }; + btn.Clicked += OnBtnClicked; + AddItem("Press button to output style context properties:", btn); + } + + private void OnBtnClicked(object sender, EventArgs e) + { + var styleCtx = ((Button)sender).StyleContext; + + var props = new[] { "padding-left", "padding-right", "padding-top", "padding-bottom", "min-width", "min-height", "color", "background-color", "font-size", "font-style" }; + + foreach (var prop in props) + { + GLib.Value val = styleCtx.GetProperty(prop, styleCtx.State); + string msg = string.Format("Property {0}, type {1}, value {2}", prop, val.Val.GetType().Name, val.Val.ToString()); + ApplicationOutput.WriteLine(msg); + } + } + } +} diff --git a/Source/Samples/Sections/Widgets/CompositeWidgetSection.cs b/Source/Samples/Sections/Widgets/CompositeWidgetSection.cs new file mode 100644 index 000000000..590292d71 --- /dev/null +++ b/Source/Samples/Sections/Widgets/CompositeWidgetSection.cs @@ -0,0 +1,47 @@ +using System; +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(CompositeWidget), Category = Category.Widgets)] + class CompositeWidgetSection : ListSection + { + public CompositeWidgetSection() + { + AddItem("CompositeWidget:", new CompositeWidget()); + AddItem("Other instance:", new CompositeWidget()); + } + } + + [Template("CompositeWidget.glade", true)] + [GLib.TypeName(nameof(CompositeWidget))] + class CompositeWidget : Bin + { +#pragma warning disable CS0649, CS0169 + [Child] Button btn1; + [Child] Button btn2; + [Child("label")] Entry entry; +#pragma warning restore CS0649, CS0169 + + public CompositeWidget() + { + // Base constructor sets [Child] fields + // if [Template(throwOnUnknownChild = true) and GTK can't bind any [Child] field then base constructor throws + // GTK writes invalid field/widget name in console (project must be Exe to see console on Windows OS) + System.Diagnostics.Debug.Assert(btn1 != null); + System.Diagnostics.Debug.Assert(btn2 != null); + System.Diagnostics.Debug.Assert(entry != null); + } + + private void on_btn1_clicked(object sender, EventArgs e) + { + entry.Text = DateTime.Now.ToString(); + ApplicationOutput.WriteLine(this, "Instance handler clicked"); + } + + private static void on_btn2_clicked(object sender, EventArgs e) + { + ApplicationOutput.WriteLine("Static handler clicked"); + } + } +} diff --git a/Source/Samples/Sections/Widgets/CustomWidgets/CompositeWidget.glade b/Source/Samples/Sections/Widgets/CustomWidgets/CompositeWidget.glade new file mode 100644 index 000000000..dd7ce77f4 --- /dev/null +++ b/Source/Samples/Sections/Widgets/CustomWidgets/CompositeWidget.glade @@ -0,0 +1,78 @@ + + + + + + diff --git a/Source/Tools/GapiCodegen/Ctor.cs b/Source/Tools/GapiCodegen/Ctor.cs index 4c2fa1f0a..1502dbd2a 100644 --- a/Source/Tools/GapiCodegen/Ctor.cs +++ b/Source/Tools/GapiCodegen/Ctor.cs @@ -30,12 +30,15 @@ namespace GtkSharp.Generation { public class Ctor : MethodBase { private bool preferred; + private bool deprecated; private string name; - private bool needs_chaining = false; + private bool needs_chaining; public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor) { preferred = elem.GetAttributeAsBoolean ("preferred"); + deprecated = elem.GetAttributeAsBoolean("deprecated"); + if (implementor is ObjectGen) needs_chaining = true; @@ -47,6 +50,12 @@ public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor) set { preferred = value; } } + public bool IsDeprecated { + get { + return deprecated; + } + } + public string StaticName { get { if (!IsStatic) @@ -101,6 +110,10 @@ public void Generate (GenerationInfo gen_info) if (IsStatic) GenerateStatic (gen_info); else { + + if (IsDeprecated) + sw.WriteLine("\t\t[Obsolete]"); + sw.WriteLine("\t\t{0} {1}{2} ({3}) {4}", Protection, Safety, name, Signature.ToString(), needs_chaining ? ": base (IntPtr.Zero)" : ""); sw.WriteLine("\t\t{"); @@ -108,7 +121,7 @@ public void Generate (GenerationInfo gen_info) sw.WriteLine ("\t\t\tif (GetType () != typeof (" + name + ")) {"); if (Parameters.Count == 0) { - sw.WriteLine ("\t\t\t\tCreateNativeObject (new string [0], new GLib.Value[0]);"); + sw.WriteLine ("\t\t\t\tCreateNativeObject (Array.Empty (), Array.Empty ());"); sw.WriteLine ("\t\t\t\treturn;"); } else { var names = new List (); diff --git a/Source/Tools/GapiCodegen/FieldBase.cs b/Source/Tools/GapiCodegen/FieldBase.cs index f7f7fa5b7..8bd383973 100644 --- a/Source/Tools/GapiCodegen/FieldBase.cs +++ b/Source/Tools/GapiCodegen/FieldBase.cs @@ -32,7 +32,7 @@ public abstract class FieldBase : PropertyBase { public FieldBase (XmlElement elem, ClassBase container_type) : base (elem, container_type) {} public FieldBase (XmlElement elem, ClassBase container_type, FieldBase abi_field) : base (elem, container_type) { - abi_field = abi_field; + this.abi_field = abi_field; } diff --git a/Source/Tools/GapiCodegen/ObjectGen.cs b/Source/Tools/GapiCodegen/ObjectGen.cs index 8b78a61f3..453484ba1 100644 --- a/Source/Tools/GapiCodegen/ObjectGen.cs +++ b/Source/Tools/GapiCodegen/ObjectGen.cs @@ -270,7 +270,7 @@ protected override void GenCtors (GenerationInfo gen_info) gen_info.Writer.WriteLine(); gen_info.Writer.WriteLine("\t\tprotected " + Name + "() : base(IntPtr.Zero)"); gen_info.Writer.WriteLine("\t\t{"); - gen_info.Writer.WriteLine("\t\t\tCreateNativeObject (new string [0], new GLib.Value [0]);"); + gen_info.Writer.WriteLine("\t\t\tCreateNativeObject (Array.Empty (), Array.Empty ());"); gen_info.Writer.WriteLine("\t\t}"); } gen_info.Writer.WriteLine(); diff --git a/Source/Tools/GapiCodegen/Parameters.cs b/Source/Tools/GapiCodegen/Parameters.cs index 1b0544d5f..660025795 100644 --- a/Source/Tools/GapiCodegen/Parameters.cs +++ b/Source/Tools/GapiCodegen/Parameters.cs @@ -227,7 +227,7 @@ public bool Validate (LogWriter log) p.IsCount = false; if (i < elem.ChildNodes.Count - 1) { XmlElement next = elem.ChildNodes [i + 1] as XmlElement; - if (next != null || next.Name == "parameter") { + if (next != null && next.Name == "parameter") { Parameter a = new Parameter (next); if (a.IsArray) { p = new ArrayCountPair (next, parm, true); diff --git a/Source/Workload/Directory.Build.props b/Source/Workload/Directory.Build.props new file mode 100644 index 000000000..6a174a965 --- /dev/null +++ b/Source/Workload/Directory.Build.props @@ -0,0 +1,22 @@ + + + + + <_GtkSharpVersion>$([System.Text.RegularExpressions.Regex]::Match($(Version), '(\d+)\.(\d+)')) + <_GtkSharpTfm>net$(_GtkSharpNetVersion)-gtk + <_GtkSharpFullTfm>net$(_GtkSharpNetVersion)-gtk$(_GtkSharpVersion) + <_GtkSharpManifestVersionBand Condition=" '$(_GtkSharpManifestVersionBand)' == '' ">6.0.400 + + $(_GtkSharpBuildOutputDirectory)WorkloadPacks\$(Configuration)\$(MSBuildProjectName)\$(Version) + + + + + + + + Icon.png + GtkSharp Contributors + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.NET.Sdk.Gtk/GtkSharp.NET.Sdk.Gtk.csproj b/Source/Workload/GtkSharp.NET.Sdk.Gtk/GtkSharp.NET.Sdk.Gtk.csproj new file mode 100644 index 000000000..ed37fbe7e --- /dev/null +++ b/Source/Workload/GtkSharp.NET.Sdk.Gtk/GtkSharp.NET.Sdk.Gtk.csproj @@ -0,0 +1,60 @@ + + + + + + $(PackageId).Manifest-$(_GtkSharpManifestVersionBand) + GtkSharp workload manifest + + + + + <_GtkSharpVersionMajorMinorPatch>$([System.Text.RegularExpressions.Regex]::Match($(Version), '(\d+)\.(\d+).(\d+)')) + <_GtkSharpManifestVersion>$(Version.Replace('$(_GtkSharpVersionMajorMinorPatch).', '$(_GtkSharpVersionMajorMinorPatch)-rev.')) + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.NET.Sdk.Gtk/WorkloadManifest.in.json b/Source/Workload/GtkSharp.NET.Sdk.Gtk/WorkloadManifest.in.json new file mode 100644 index 000000000..ec7760f0b --- /dev/null +++ b/Source/Workload/GtkSharp.NET.Sdk.Gtk/WorkloadManifest.in.json @@ -0,0 +1,39 @@ +{ + "version": "@GTKSHARPMANIFESTVERSION@", + "workloads": { + "gtk": { + "description": ".NET SDK workload for building GtkSharp applications.", + "packs": [ + "GtkSharp.Sdk", + "GtkSharp.Ref", + "GtkSharp.Runtime" + ] + } + }, + "packs": { + "GtkSharp.Sdk": { + "kind": "sdk", + "version": "@VERSION@" + }, + "GtkSharp.Ref": { + "kind": "framework", + "version": "@VERSION@" + }, + "GtkSharp.Runtime": { + "kind": "framework", + "version": "@VERSION@" + }, + "GtkSharp.Workload.Template.CSharp": { + "kind": "template", + "version": "@VERSION@" + }, + "GtkSharp.Workload.Template.FSharp": { + "kind": "template", + "version": "@VERSION@" + }, + "GtkSharp.Workload.Template.VBNet": { + "kind": "template", + "version": "@VERSION@" + } + } + } \ No newline at end of file diff --git a/Source/Workload/GtkSharp.NET.Sdk.Gtk/WorkloadManifest.targets b/Source/Workload/GtkSharp.NET.Sdk.Gtk/WorkloadManifest.targets new file mode 100644 index 000000000..451e6089d --- /dev/null +++ b/Source/Workload/GtkSharp.NET.Sdk.Gtk/WorkloadManifest.targets @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Ref/GtkSharp.Ref.csproj b/Source/Workload/GtkSharp.Ref/GtkSharp.Ref.csproj new file mode 100644 index 000000000..f6c5f8f0e --- /dev/null +++ b/Source/Workload/GtkSharp.Ref/GtkSharp.Ref.csproj @@ -0,0 +1,20 @@ + + + + + + + GtkSharp targeting pack + + + + + + <_PackageFiles Include="@(None)" PackagePath="ref\$(_GtkSharpFullTfm)" TargetPath="ref\$(_GtkSharpFullTfm)" /> + + + + + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Runtime/GtkSharp.Runtime.csproj b/Source/Workload/GtkSharp.Runtime/GtkSharp.Runtime.csproj new file mode 100644 index 000000000..fd8d3e4fd --- /dev/null +++ b/Source/Workload/GtkSharp.Runtime/GtkSharp.Runtime.csproj @@ -0,0 +1,20 @@ + + + + + + + GtkSharp runtime pack + + + + + + <_PackageFiles Include="@(None)" PackagePath="lib\$(_GtkSharpFullTfm)" TargetPath="lib\$(_GtkSharpFullTfm)" /> + + + + + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Sdk/GtkSharp.Sdk.csproj b/Source/Workload/GtkSharp.Sdk/GtkSharp.Sdk.csproj new file mode 100644 index 000000000..39aeb9465 --- /dev/null +++ b/Source/Workload/GtkSharp.Sdk/GtkSharp.Sdk.csproj @@ -0,0 +1,58 @@ + + + + + + GtkSharp SDK. Enabled via the net6.0-gtk TFM. + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Sdk/Sdk/Sdk.in.targets b/Source/Workload/GtkSharp.Sdk/Sdk/Sdk.in.targets new file mode 100644 index 000000000..482221298 --- /dev/null +++ b/Source/Workload/GtkSharp.Sdk/Sdk/Sdk.in.targets @@ -0,0 +1,66 @@ + + + + + + + + + + + + <_DefaultTargetPlatformVersion>@GTKSHARPVERSION@ + + + + true + $(_DefaultTargetPlatformVersion) + + + + + + + + + + + + + + + + + + + <_IsGtkDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)GTK($|;)')) + GTK;$(DefineConstants) + + + + + true + win-x64 + win-x86 + linux-x64 + linux-x86 + osx-x64 + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/GtkSharp.Workload.Template.CSharp.csproj b/Source/Workload/GtkSharp.Workload.Template.CSharp/GtkSharp.Workload.Template.CSharp.csproj new file mode 100644 index 000000000..56a58047d --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/GtkSharp.Workload.Template.CSharp.csproj @@ -0,0 +1,47 @@ + + + + + + GTK templates for CSharp + A set of C# templates for your .NET GTK Application. Installed with the GtkSharp .NET workload. + + + + <_GtkSharpTemplateContent Include="content\**" /> + <_GtkSharpTemplateContent Remove="**\*.in.*" /> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/.template.config/template.in.json b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/.template.config/template.in.json new file mode 100644 index 000000000..e79099cb4 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/.template.config/template.in.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "GUI App" + ], + "name": "Gtk Application", + "identity": "GtkSharp.Application.CSharp", + "groupIdentity": "GtkSharp.Application", + "shortName": "gtk", + "tags": { + "language": "C#", + "type": "project" + }, + "sourceName": "GtkNamespace", + "preferNameDirectory": true, + "symbols": { + "targetframework": { + "type": "parameter", + "description": "The target framework for the project.", + "defaultValue": "net@GTKSHARPNETVERSION@-gtk", + "replaces": "$(FrameworkParameter)" + } + }, + "primaryOutputs": [ + { "path": "GtkNamespace.csproj" } + ] +} diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/GtkNamespace.csproj b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/GtkNamespace.csproj new file mode 100644 index 000000000..25cdc1cb3 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/GtkNamespace.csproj @@ -0,0 +1,15 @@ + + + + WinExe + $(FrameworkParameter) + + + + + + %(Filename)%(Extension) + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.cs b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.cs new file mode 100644 index 000000000..a6fc08a26 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.cs @@ -0,0 +1,35 @@ +using System; +using Gtk; +using UI = Gtk.Builder.ObjectAttribute; + +namespace GtkNamespace +{ + class MainWindow : Window + { + [UI] private Label _label1 = null; + [UI] private Button _button1 = null; + + private int _counter; + + public MainWindow() : this(new Builder("MainWindow.glade")) { } + + private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow")) + { + builder.Autoconnect(this); + + DeleteEvent += Window_DeleteEvent; + _button1.Clicked += Button1_Clicked; + } + + private void Window_DeleteEvent(object sender, DeleteEventArgs a) + { + Application.Quit(); + } + + private void Button1_Clicked(object sender, EventArgs a) + { + _counter++; + _label1.Text = "Hello World! This button has been clicked " + _counter + " time(s)."; + } + } +} diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.glade b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.glade new file mode 100644 index 000000000..a13c41b20 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/MainWindow.glade @@ -0,0 +1,46 @@ + + + + + False + Example Window + 480 + 240 + + + True + False + 4 + 4 + 4 + 4 + vertical + + + True + False + Hello World! + + + True + True + 0 + + + + + Click me! + True + False + True + + + False + True + 1 + + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/Program.cs b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/Program.cs new file mode 100644 index 000000000..56195ab62 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Application.CSharp/Program.cs @@ -0,0 +1,23 @@ +using System; +using Gtk; + +namespace GtkNamespace +{ + class Program + { + [STAThread] + public static void Main(string[] args) + { + Application.Init(); + + var app = new Application("org.GtkNamespace.GtkNamespace", GLib.ApplicationFlags.None); + app.Register(GLib.Cancellable.Current); + + var win = new MainWindow(); + app.AddWindow(win); + + win.Show(); + Application.Run(); + } + } +} diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/.template.config/template.json new file mode 100644 index 000000000..1c053e4fa --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Dialog", + "identity": "GtkSharp.Dialog.CSharp", + "groupIdentity": "GtkSharp.Dialog", + "shortName": "gtkdialog", + "tags": { + "language": "C#", + "type": "item" + }, + "sourceName": "Gtk_Dialog", + "primaryOutputs": [ + { + "path": "Gtk_Dialog.cs" + }, + { + "path": "Gtk_Dialog.glade" + } + ], + "defaultName": "Gtk_Dialog", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.cs b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.cs new file mode 100644 index 000000000..5f7d60f10 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.cs @@ -0,0 +1,24 @@ +using System; +using Gtk; +using UI = Gtk.Builder.ObjectAttribute; + +namespace GtkNamespace +{ + class Gtk_Dialog : Dialog + { + public Gtk_Dialog() : this(new Builder("Gtk_Dialog.glade")) { } + + private Gtk_Dialog(Builder builder) : base(builder.GetRawOwnedObject("Gtk_Dialog")) + { + builder.Autoconnect(this); + DefaultResponse = ResponseType.Cancel; + + Response += Dialog_Response; + } + + private void Dialog_Response(object o, ResponseArgs args) + { + Hide(); + } + } +} diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.glade b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.glade new file mode 100644 index 000000000..8cc7c549a --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Dialog.CSharp/Gtk_Dialog.glade @@ -0,0 +1,51 @@ + + + + + False + 320 + 260 + dialog + + + False + vertical + 2 + + + False + end + + + + + + gtk-close + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + button1 + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/.template.config/template.json new file mode 100644 index 000000000..8d903c00c --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Widget", + "identity": "GtkSharp.Widget.CSharp", + "groupIdentity": "GtkSharp.Widget", + "shortName": "gtkwidget", + "tags": { + "language": "C#", + "type": "item" + }, + "sourceName": "Gtk_Widget", + "primaryOutputs": [ + { + "path": "Gtk_Widget.cs" + }, + { + "path": "Gtk_Widget.glade" + } + ], + "defaultName": "Gtk_Widget", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.cs b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.cs new file mode 100644 index 000000000..88c911502 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.cs @@ -0,0 +1,16 @@ +using System; +using Gtk; +using UI = Gtk.Builder.ObjectAttribute; + +namespace GtkNamespace +{ + public class Gtk_Widget : Box + { + public Gtk_Widget() : this(new Builder("Gtk_Widget.glade")) { } + + private Gtk_Widget(Builder builder) : base(builder.GetRawOwnedObject("Gtk_Widget")) + { + builder.Autoconnect(this); + } + } +} diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.glade b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.glade new file mode 100644 index 000000000..7a1be14d1 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Widget.CSharp/Gtk_Widget.glade @@ -0,0 +1,11 @@ + + + + + True + False + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/.template.config/template.json new file mode 100644 index 000000000..56f3766b1 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Window", + "identity": "GtkSharp.Window.CSharp", + "groupIdentity": "GtkSharp.Window", + "shortName": "gtkwindow", + "tags": { + "language": "C#", + "type": "item" + }, + "sourceName": "Gtk_Window", + "primaryOutputs": [ + { + "path": "Gtk_Window.cs" + }, + { + "path": "Gtk_Window.glade" + } + ], + "defaultName": "Gtk_Window", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.cs b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.cs new file mode 100644 index 000000000..2b863d03c --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.cs @@ -0,0 +1,16 @@ +using System; +using Gtk; +using UI = Gtk.Builder.ObjectAttribute; + +namespace GtkNamespace +{ + class Gtk_Window : Window + { + public Gtk_Window() : this(new Builder("Gtk_Window.glade")) { } + + private Gtk_Window(Builder builder) : base(builder.GetRawOwnedObject("Gtk_Window")) + { + builder.Autoconnect(this); + } + } +} diff --git a/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.glade b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.glade new file mode 100644 index 000000000..44e554e80 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.CSharp/content/GtkSharp.Window.CSharp/Gtk_Window.glade @@ -0,0 +1,11 @@ + + + + + False + Gtk_Window + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/GtkSharp.Workload.Template.FSharp.csproj b/Source/Workload/GtkSharp.Workload.Template.FSharp/GtkSharp.Workload.Template.FSharp.csproj new file mode 100644 index 000000000..464850538 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/GtkSharp.Workload.Template.FSharp.csproj @@ -0,0 +1,47 @@ + + + + + + GTK templates for FSharp + A set of F# templates for your .NET GTK Application. Installed with the GtkSharp .NET workload. + + + + <_GtkSharpTemplateContent Include="content\**" /> + <_GtkSharpTemplateContent Remove="**\*.in.*" /> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/.template.config/template.in.json b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/.template.config/template.in.json new file mode 100644 index 000000000..66ff5781f --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/.template.config/template.in.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "GUI App" + ], + "name": "Gtk Application", + "identity": "GtkSharp.Application.FSharp", + "groupIdentity": "GtkSharp.Application", + "shortName": "gtk", + "tags": { + "language": "F#", + "type": "project" + }, + "sourceName": "GtkNamespace", + "preferNameDirectory": true, + "symbols": { + "targetframework": { + "type": "parameter", + "description": "The target framework for the project.", + "defaultValue": "net@GTKSHARPNETVERSION@-gtk", + "replaces": "$(FrameworkParameter)" + } + }, + "primaryOutputs": [ + { "path": "GtkNamespace.fsproj" } + ] +} diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/GtkNamespace.fsproj b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/GtkNamespace.fsproj new file mode 100644 index 000000000..e24d76353 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/GtkNamespace.fsproj @@ -0,0 +1,24 @@ + + + + Exe + $(FrameworkParameter) + + + + + + + + + + + %(Filename)%(Extension) + + + + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.fs b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.fs new file mode 100644 index 000000000..03ffbc5d7 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.fs @@ -0,0 +1,24 @@ +namespace GtkNamespace + +open Gtk + +type MainWindow (builder : Builder) as this = + inherit Window(builder.GetRawOwnedObject("MainWindow")) + + let mutable _label1 : Label = null + let mutable _button1 : Button = null + let mutable _counter = 0; + + do + _label1 <- builder.GetObject("_label1") :?> Label + _button1 <- builder.GetObject("_button1") :?> Button + + this.DeleteEvent.Add(fun _ -> + Application.Quit() + ) + _button1.Clicked.Add(fun _ -> + _counter <- _counter + 1 + _label1.Text <- "Hello World! This button has been clicked " + _counter.ToString() + " time(s)." + ) + + new() = new MainWindow(new Builder("MainWindow.glade")) diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.glade b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.glade new file mode 100644 index 000000000..a13c41b20 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/MainWindow.glade @@ -0,0 +1,46 @@ + + + + + False + Example Window + 480 + 240 + + + True + False + 4 + 4 + 4 + 4 + vertical + + + True + False + Hello World! + + + True + True + 0 + + + + + Click me! + True + False + True + + + False + True + 1 + + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/Program.fs b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/Program.fs new file mode 100644 index 000000000..037050ae1 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Application.FSharp/Program.fs @@ -0,0 +1,18 @@ +namespace GtkNamespace +module Program = + + open Gtk + + [] + let main argv = + Application.Init() + + let app = new Application("org.GtkNamespace.GtkNamespace", GLib.ApplicationFlags.None) + app.Register(GLib.Cancellable.Current) |> ignore; + + let win = new MainWindow() + app.AddWindow(win) + + win.Show() + Application.Run() + 0 diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/.template.config/template.json new file mode 100644 index 000000000..82d90535a --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Dialog", + "identity": "GtkSharp.Dialog.FSharp", + "groupIdentity": "GtkSharp.Dialog", + "shortName": "gtkdialog", + "tags": { + "language": "F#", + "type": "item" + }, + "sourceName": "Gtk_Dialog", + "primaryOutputs": [ + { + "path": "Gtk_Dialog.fs" + }, + { + "path": "Gtk_Dialog.glade" + } + ], + "defaultName": "Gtk_Dialog", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.fs b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.fs new file mode 100644 index 000000000..7e52fb76e --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.fs @@ -0,0 +1,13 @@ +namespace GtkNamespace + +open Gtk + +type Gtk_Dialog (builder : Builder) as this = + inherit Dialog(builder.GetRawOwnedObject("Gtk_Dialog")) + do + this.DefaultResponse <- ResponseType.Cancel; + this.Response.Add(fun _ -> + this.Hide(); + ) + + new() = new Gtk_Dialog(new Builder("Gtk_Dialog.glade")) diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.glade b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.glade new file mode 100644 index 000000000..8cc7c549a --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Dialog.FSharp/Gtk_Dialog.glade @@ -0,0 +1,51 @@ + + + + + False + 320 + 260 + dialog + + + False + vertical + 2 + + + False + end + + + + + + gtk-close + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + button1 + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/.template.config/template.json new file mode 100644 index 000000000..53dd6eb65 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Widget", + "identity": "GtkSharp.Widget.FSharp", + "groupIdentity": "GtkSharp.Widget", + "shortName": "gtkwidget", + "tags": { + "language": "F#", + "type": "item" + }, + "sourceName": "Gtk_Widget", + "primaryOutputs": [ + { + "path": "Gtk_Widget.fs" + }, + { + "path": "Gtk_Widget.glade" + } + ], + "defaultName": "Gtk_Widget", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.fs b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.fs new file mode 100644 index 000000000..2812ea947 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.fs @@ -0,0 +1,8 @@ +namespace GtkNamespace + +open Gtk + +type Gtk_Widget (builder : Builder) = + inherit Box(builder.GetRawOwnedObject("Gtk_Widget")) + + new() = new Gtk_Widget(new Builder("Gtk_Widget.glade")) diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.glade b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.glade new file mode 100644 index 000000000..7a1be14d1 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Widget.FSharp/Gtk_Widget.glade @@ -0,0 +1,11 @@ + + + + + True + False + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/.template.config/template.json new file mode 100644 index 000000000..0d43a621d --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Window", + "identity": "GtkSharp.Window.FSharp", + "groupIdentity": "GtkSharp.Window", + "shortName": "gtkwindow", + "tags": { + "language": "F#", + "type": "item" + }, + "sourceName": "Gtk_Window", + "primaryOutputs": [ + { + "path": "Gtk_Window.fs" + }, + { + "path": "Gtk_Window.glade" + } + ], + "defaultName": "Gtk_Window", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.fs b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.fs new file mode 100644 index 000000000..a4f3fc885 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.fs @@ -0,0 +1,8 @@ +namespace GtkNamespace + +open Gtk + +type Gtk_Window (builder : Builder) = + inherit Window(builder.GetRawOwnedObject("Gtk_Window")) + + new() = new Gtk_Window(new Builder("Gtk_Window.glade")) diff --git a/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.glade b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.glade new file mode 100644 index 000000000..44e554e80 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.FSharp/content/GtkSharp.Window.FSharp/Gtk_Window.glade @@ -0,0 +1,11 @@ + + + + + False + Gtk_Window + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/GtkSharp.Workload.Template.VBNet.csproj b/Source/Workload/GtkSharp.Workload.Template.VBNet/GtkSharp.Workload.Template.VBNet.csproj new file mode 100644 index 000000000..ba4b8e680 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/GtkSharp.Workload.Template.VBNet.csproj @@ -0,0 +1,47 @@ + + + + + + GTK templates for Visual Basic + A set of Visual Basic templates for your .NET GTK Application. Installed with the GtkSharp .NET workload. + + + + <_GtkSharpTemplateContent Include="content\**" /> + <_GtkSharpTemplateContent Remove="**\*.in.*" /> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/.template.config/template.in.json b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/.template.config/template.in.json new file mode 100644 index 000000000..dc48e9a2e --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/.template.config/template.in.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "GUI App" + ], + "name": "Gtk Application", + "identity": "GtkSharp.Application.VBNet", + "groupIdentity": "GtkSharp.Application", + "shortName": "gtk", + "tags": { + "language": "VB", + "type": "project" + }, + "sourceName": "GtkNamespace", + "preferNameDirectory": true, + "symbols": { + "targetframework": { + "type": "parameter", + "description": "The target framework for the project.", + "defaultValue": "net@GTKSHARPNETVERSION@-gtk", + "replaces": "$(FrameworkParameter)" + } + }, + "primaryOutputs": [ + { "path": "GtkNamespace.vbproj" } + ] +} diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/GtkNamespace.vbproj b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/GtkNamespace.vbproj new file mode 100644 index 000000000..491e8f7af --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/GtkNamespace.vbproj @@ -0,0 +1,19 @@ + + + + WinExe + $(FrameworkParameter) + + + + + + %(Filename)%(Extension) + + + + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.glade b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.glade new file mode 100644 index 000000000..a13c41b20 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.glade @@ -0,0 +1,46 @@ + + + + + False + Example Window + 480 + 240 + + + True + False + 4 + 4 + 4 + 4 + vertical + + + True + False + Hello World! + + + True + True + 0 + + + + + Click me! + True + False + True + + + False + True + 1 + + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.vb b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.vb new file mode 100644 index 000000000..5a1f6fa05 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/MainWindow.vb @@ -0,0 +1,37 @@ +Imports System +Imports Gtk +Imports UI = Gtk.Builder.ObjectAttribute + +Namespace GtkNamespace + Public Class MainWindow + Inherits Window + + Private _counter = 0 + Private _label1 As Label + Private _button1 As Button + + Public Sub New (builder as Builder) + MyBase.New(builder.GetRawOwnedObject("MainWindow")) + + builder.Autoconnect (Me) + + AddHandler MyBase.DeleteEvent, AddressOf Window_Delete + AddHandler _button1.Clicked, AddressOf Button1_Clicked + End Sub + + Public Sub New () + Me.New(new Builder("MainWindow.glade")) + End Sub + + Private Sub Window_Delete (ByVal sender As Object, ByVal a As DeleteEventArgs) + Application.Quit () + a.RetVal = true + End Sub + + Private Sub Button1_Clicked (ByVal sender As Object, ByVal a As EventArgs) + _counter += 1 + _label1.Text = "Hello World! This button has been clicked " + _counter.ToString() + " time(s)." + End Sub + + End Class +End Namespace diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/Program.vb b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/Program.vb new file mode 100644 index 000000000..627f2b08a --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Application.VBNet/Program.vb @@ -0,0 +1,21 @@ +Imports System +Imports Gtk + +Namespace GtkNamespace + Public Class MainClass + + Public Shared Sub Main () + Application.Init () + + Dim app as new Application ("org.GtkNamespace.GtkNamespace", GLib.ApplicationFlags.None) + app.Register (GLib.Cancellable.Current) + + Dim win as new MainWindow () + app.AddWindow (win) + + win.Show () + Application.Run () + End Sub + + End Class +End Namespace diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/.template.config/template.json new file mode 100644 index 000000000..701219110 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Dialog", + "identity": "GtkSharp.Dialog.VBNet", + "groupIdentity": "GtkSharp.Dialog", + "shortName": "gtkdialog", + "tags": { + "language": "VB", + "type": "item" + }, + "sourceName": "Gtk_Dialog", + "primaryOutputs": [ + { + "path": "Gtk_Dialog.vb" + }, + { + "path": "Gtk_Dialog.glade" + } + ], + "defaultName": "Gtk_Dialog", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.glade b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.glade new file mode 100644 index 000000000..8cc7c549a --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.glade @@ -0,0 +1,51 @@ + + + + + False + 320 + 260 + dialog + + + False + vertical + 2 + + + False + end + + + + + + gtk-close + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + button1 + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.vb b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.vb new file mode 100644 index 000000000..e4b15f60b --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Dialog.VBNet/Gtk_Dialog.vb @@ -0,0 +1,27 @@ +Imports System +Imports Gtk +Imports UI = Gtk.Builder.ObjectAttribute + +Namespace GtkNamespace + Public Class Gtk_Dialog + Inherits Dialog + + Public Sub New (builder as Builder) + MyBase.New (builder.GetRawOwnedObject("Gtk_Dialog")) + + builder.Autoconnect (Me) + DefaultResponse = ResponseType.Cancel + + AddHandler MyBase.Response, AddressOf Dialog_OnResponse + End Sub + + Public Sub New () + Me.New (new Builder ("Gtk_Dialog.glade")) + End Sub + + Private Sub Dialog_OnResponse (ByVal sender As Object, ByVal args As ResponseArgs) + Hide () + End Sub + + End Class +End Namespace diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/.template.config/template.json new file mode 100644 index 000000000..f80ede244 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Widget", + "identity": "GtkSharp.Widget.VBNet", + "groupIdentity": "GtkSharp.Widget", + "shortName": "gtkwidget", + "tags": { + "language": "VB", + "type": "item" + }, + "sourceName": "Gtk_Widget", + "primaryOutputs": [ + { + "path": "Gtk_Widget.vb" + }, + { + "path": "Gtk_Widget.glade" + } + ], + "defaultName": "Gtk_Widget", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.glade b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.glade new file mode 100644 index 000000000..7a1be14d1 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.glade @@ -0,0 +1,11 @@ + + + + + True + False + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.vb b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.vb new file mode 100644 index 000000000..359a413e7 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Widget.VBNet/Gtk_Widget.vb @@ -0,0 +1,20 @@ +Imports System +Imports Gtk +Imports UI = Gtk.Builder.ObjectAttribute + +Namespace GtkNamespace + Public Class Gtk_Widget + Inherits Box + + Public Sub New (builder as Builder) + MyBase.New (builder.GetRawOwnedObject("Gtk_Widget")) + + builder.Autoconnect (Me) + End Sub + + Public Sub New () + Me.New (new Builder("Gtk_Widget.glade")) + End Sub + + End Class +End Namespace diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/.template.config/template.json b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/.template.config/template.json new file mode 100644 index 000000000..74ff39a48 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/.template.config/template.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "GtkSharp Contributors", + "classifications": [ + "Gtk", + "UI" + ], + "name": "Gtk Window", + "identity": "GtkSharp.Window.VBNet", + "groupIdentity": "GtkSharp.Window", + "shortName": "gtkwindow", + "tags": { + "language": "VB", + "type": "item" + }, + "sourceName": "Gtk_Window", + "primaryOutputs": [ + { + "path": "Gtk_Window.vb" + }, + { + "path": "Gtk_Window.glade" + } + ], + "defaultName": "Gtk_Window", + "symbols": { + "namespace": { + "description": "Namespace for the generated files", + "replaces": "GtkNamespace", + "type": "parameter" + } + } +} \ No newline at end of file diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.glade b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.glade new file mode 100644 index 000000000..44e554e80 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.glade @@ -0,0 +1,11 @@ + + + + + False + Gtk_Window + + + + + diff --git a/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.vb b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.vb new file mode 100644 index 000000000..2e0b365f4 --- /dev/null +++ b/Source/Workload/GtkSharp.Workload.Template.VBNet/content/GtkSharp.Window.VBNet/Gtk_Window.vb @@ -0,0 +1,20 @@ +Imports System +Imports Gtk +Imports UI = Gtk.Builder.ObjectAttribute + +Namespace GtkNamespace + Public Class Gtk_Window + Inherits Window + + Public Sub New (builder as Builder) + MyBase.New (builder.GetRawOwnedObject("Gtk_Window")) + + builder.Autoconnect (Me) + End Sub + + Public Sub New () + Me.New (new Builder ("Gtk_Window.glade")) + End Sub + + End Class +End Namespace diff --git a/Source/Workload/Shared/Common.targets b/Source/Workload/Shared/Common.targets new file mode 100644 index 000000000..6cf9bab29 --- /dev/null +++ b/Source/Workload/Shared/Common.targets @@ -0,0 +1,12 @@ + + + netstandard2.0 + DotnetPlatform + $(MSBuildProjectName) + true + false + false + false + $(NoWarn);NU5100;NU5128;NU5130;NU5131 + + \ No newline at end of file diff --git a/Source/Workload/Shared/Frameworks.targets b/Source/Workload/Shared/Frameworks.targets new file mode 100644 index 000000000..d4d824cdb --- /dev/null +++ b/Source/Workload/Shared/Frameworks.targets @@ -0,0 +1,42 @@ + + + + <_FrameworkListFile Condition=" !$(MSBuildProjectName.Contains('.Runtime')) " Include="$(IntermediateOutputPath)FrameworkList.xml" /> + <_FrameworkListFile Condition=" !$(MSBuildProjectName.Contains('.Ref')) " Include="$(IntermediateOutputPath)RuntimeList.xml" /> + + + + + + + + false + + + + + + <_RootAttribute Include="Name" Value="GtkSharp" /> + <_RootAttribute Include="TargetFrameworkIdentifier" Value=".NETCoreApp" /> + <_RootAttribute Include="TargetFrameworkVersion" Value="6.0" /> + <_RootAttribute Include="FrameworkName" Value="$(MSBuildProjectName.Replace('.Ref','').Replace('.Runtime',''))" /> + <_AssemblyFiles Include="@(_PackageFiles)" Condition=" '%(_PackageFiles.Extension)' == '.dll' and '%(_PackageFiles.SubFolder)' == '' " /> + <_Classifications Include="@(_AssemblyFiles->'%(FileName)%(Extension)'->Distinct())" Profile="GTK" /> + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Workload/Shared/ReplaceText.targets b/Source/Workload/Shared/ReplaceText.targets new file mode 100644 index 000000000..d1c0ab978 --- /dev/null +++ b/Source/Workload/Shared/ReplaceText.targets @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Workload/Shared/Templates.targets b/Source/Workload/Shared/Templates.targets new file mode 100644 index 000000000..a09ce8cd0 --- /dev/null +++ b/Source/Workload/Shared/Templates.targets @@ -0,0 +1,14 @@ + + + + Template + $(MSBuildProjectName) + netstandard2.0 + true + false + false + false + NU5128 + + + \ No newline at end of file diff --git a/Source/Workload/global.json b/Source/Workload/global.json new file mode 100644 index 000000000..0beb2f501 --- /dev/null +++ b/Source/Workload/global.json @@ -0,0 +1,5 @@ +{ + "msbuild-sdks": { + "Microsoft.Build.NoTargets": "3.3.0" + } +} \ No newline at end of file diff --git a/Source/Workload/nuget.config b/Source/Workload/nuget.config new file mode 100644 index 000000000..42c64aefb --- /dev/null +++ b/Source/Workload/nuget.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/build.cake b/build.cake index 0b9c6d7c9..4699712bb 100644 --- a/build.cake +++ b/build.cake @@ -1,5 +1,6 @@ #load CakeScripts\GAssembly.cake #load CakeScripts\Settings.cake +#load CakeScripts\TargetEnvironment.cake #addin "Cake.FileHelpers&version=5.0.0" #addin "Cake.Incubator&version=7.0.0" @@ -13,6 +14,7 @@ var configuration = Argument("Configuration", "Release"); var msbuildsettings = new DotNetMSBuildSettings(); var list = new List(); +var supportedVersionBands = new List() {"6.0.100", "6.0.200", "6.0.300", "6.0.400"}; // TASKS @@ -128,6 +130,33 @@ Task("PackageNuGet") DotNetPack(gassembly.Csproj, settings); }); +Task("PackageWorkload") + .IsDependentOn("Build") + .Does(() => +{ + var packSettings = new DotNetPackSettings + { + MSBuildSettings = msbuildsettings, + Configuration = configuration, + OutputDirectory = "BuildOutput/NugetPackages", + // Some of the nugets here depend on output generated during build. + NoBuild = false + }; + + DotNetPack("Source/Workload/GtkSharp.Workload.Template.CSharp/GtkSharp.Workload.Template.CSharp.csproj", packSettings); + DotNetPack("Source/Workload/GtkSharp.Workload.Template.FSharp/GtkSharp.Workload.Template.FSharp.csproj", packSettings); + DotNetPack("Source/Workload/GtkSharp.Workload.Template.VBNet/GtkSharp.Workload.Template.VBNet.csproj", packSettings); + DotNetPack("Source/Workload/GtkSharp.Ref/GtkSharp.Ref.csproj", packSettings); + DotNetPack("Source/Workload/GtkSharp.Runtime/GtkSharp.Runtime.csproj", packSettings); + DotNetPack("Source/Workload/GtkSharp.Sdk/GtkSharp.Sdk.csproj", packSettings); + + foreach (var band in supportedVersionBands) + { + packSettings.MSBuildSettings = packSettings.MSBuildSettings.WithProperty("_GtkSharpManifestVersionBand", band); + DotNetPack("Source/Workload/GtkSharp.NET.Sdk.Gtk/GtkSharp.NET.Sdk.Gtk.csproj", packSettings); + } +}); + Task("PackageTemplates") .IsDependentOn("Init") .Does(() => @@ -144,11 +173,81 @@ Task("PackageTemplates") DotNetPack("Source/Templates/GtkSharp.Template.VBNet/GtkSharp.Template.VBNet.csproj", settings); }); +const string manifestName = "GtkSharp.NET.Sdk.Gtk"; +var manifestPack = $"{manifestName}.Manifest-{TargetEnvironment.DotNetCliFeatureBand}.{Settings.Version}.nupkg"; +var manifestPackPath = $"BuildOutput/NugetPackages/{manifestPack}"; + +var packNames = new List() +{ + "GtkSharp.Ref", + "GtkSharp.Runtime", + "GtkSharp.Sdk" +}; + +var templateLanguages = new List() +{ + "CSharp", + "FSharp", + "VBNet" +}; + +Task("InstallWorkload") + .IsDependentOn("PackageWorkload") + .IsDependentOn("PackageTemplates") + .Does(() => +{ + Console.WriteLine($"Installing workload for SDK version {TargetEnvironment.DotNetCliFeatureBand}, at {TargetEnvironment.DotNetInstallPath}"); + Console.WriteLine($"Installing manifests to {TargetEnvironment.DotNetManifestPath}"); + TargetEnvironment.InstallManifests(manifestName, manifestPackPath); + Console.WriteLine($"Installing packs to {TargetEnvironment.DotNetPacksPath}"); + foreach (var name in packNames) + { + Console.WriteLine($"Installing {name}"); + var pack = $"{name}.{Settings.Version}.nupkg"; + var packPath = $"BuildOutput/NugetPackages/{pack}"; + TargetEnvironment.InstallPack(name, Settings.Version, packPath); + } + Console.WriteLine($"Installing templates to {TargetEnvironment.DotNetTemplatePacksPath}"); + foreach (var language in templateLanguages) + { + Console.WriteLine($"Installing {language} templates"); + var pack = $"GtkSharp.Workload.Template.{language}.{Settings.Version}.nupkg"; + var packPath = $"BuildOutput/NugetPackages/{pack}"; + TargetEnvironment.InstallTemplatePack(pack, packPath); + } + Console.WriteLine($"Registering \"gtk\" installed workload..."); + TargetEnvironment.RegisterInstalledWorkload("gtk"); +}); + +Task("UninstallWorkload") + .Does(() => +{ + Console.WriteLine($"Uninstalling workload for SDK version {TargetEnvironment.DotNetCliFeatureBand}, at {TargetEnvironment.DotNetInstallPath}"); + Console.WriteLine($"Removing manifests from {TargetEnvironment.DotNetManifestPath}"); + TargetEnvironment.UninstallManifests(manifestName); + Console.WriteLine($"Removing packs from {TargetEnvironment.DotNetPacksPath}"); + foreach (var name in packNames) + { + Console.WriteLine($"Removing {name}"); + TargetEnvironment.UninstallPack(name, Settings.Version); + } + Console.WriteLine($"Removing templates from {TargetEnvironment.DotNetTemplatePacksPath}"); + foreach (var language in templateLanguages) + { + Console.WriteLine($"Removing {language} templates"); + var pack = $"GtkSharp.Workload.Template.{language}.{Settings.Version}.nupkg"; + TargetEnvironment.UninstallTemplatePack(pack); + } + Console.WriteLine($"Unregistering \"gtk\" installed workload..."); + TargetEnvironment.UnregisterInstalledWorkload("gtk"); +}); + // TASK TARGETS Task("Default") .IsDependentOn("Build") .IsDependentOn("PackageNuGet") + .IsDependentOn("PackageWorkload") .IsDependentOn("PackageTemplates"); // EXECUTION