From: Jean-Philippe Bruyère Date: Tue, 18 Mar 2025 03:48:24 +0000 (+0100) Subject: checkbox focusable handling, png image detection from magic X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=aca564c44af54cd3b7fbfb9552aa1d74fab67df6;p=jp%2Fcrow.git checkbox focusable handling, png image detection from magic --- diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index a10ef1db..0b4491f5 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -531,7 +531,7 @@ namespace Crow windows [window].OnKeyDown (new KeyEventArgs (key, scanCode, modifiers)); }; static CharDelegate HandleCharDelegate = (IntPtr window, CodePoint codepoint) => { - Console.WriteLine ($"Char: cp:{codepoint.Value} -> '{codepoint}'"); + //Console.WriteLine ($"Char: cp:{codepoint.Value} -> '{codepoint}'"); windows [window].OnKeyPress (codepoint.ToChar()); }; static WindowSizeDelegate HandleWindowSizeDelegate = (IntPtr window, int Width, int Height) => { @@ -1112,13 +1112,13 @@ namespace Crow /// public void Update(IContext ctx = null){ - CrowThread[] tmpThreads; + /*CrowThread[] tmpThreads; lock (CrowThreads) { tmpThreads = new CrowThread[CrowThreads.Count]; Array.Copy (CrowThreads.ToArray (), tmpThreads, CrowThreads.Count); } for (int i = 0; i < tmpThreads.Length; i++) - tmpThreads [i].CheckState (); + tmpThreads [i].CheckState ();*/ if (lastMouseDownEvent != null) { if (mouseRepeatTimer.ElapsedMilliseconds > DEVICE_REPEAT_INTERVAL) { @@ -1935,7 +1935,7 @@ namespace Crow } void resetTooltip () { - lock (tooltipMutex) { + lock (tooltipMutex) {//TODO:deadlock if (tooltipVisible) { ToolTipContainer.LayoutChanged -= ToolTipContainer_LayoutChanged; ToolTipContainer.DataSource = null; diff --git a/Crow/src/Widgets/CheckBox.cs b/Crow/src/Widgets/CheckBox.cs index a51ff18c..82db7327 100644 --- a/Crow/src/Widgets/CheckBox.cs +++ b/Crow/src/Widgets/CheckBox.cs @@ -45,8 +45,10 @@ namespace Crow public override void onMouseClick (object sender, MouseButtonEventArgs e) { - IsChecked = !IsChecked; - e.Handled = true; + if (Focusable) { + IsChecked = !IsChecked; + e.Handled = true; + } base.onMouseClick (sender, e); } } diff --git a/Crow/src/Widgets/Image.cs b/Crow/src/Widgets/Image.cs index b1a3a94f..a6f55937 100644 --- a/Crow/src/Widgets/Image.cs +++ b/Crow/src/Widgets/Image.cs @@ -25,6 +25,7 @@ namespace Crow /// public class Image : Scalable { + static readonly byte[] pngMagic = new byte[] {0x89, 0x50 ,0x4e ,0x47 ,0x0d ,0x0a}; Picture _pic; string _svgSub; @@ -139,9 +140,7 @@ namespace Crow /// Initializes a new instance of the class from code /// /// interface to bound to - public Image (Interface iface) : base(iface) - { - } + public Image (Interface iface, string style = null) : base(iface, style) { } #endregion #region Image Loading @@ -154,8 +153,27 @@ namespace Crow if (getcontenttype.Wait(HTTP_DOWNLOAD_TIMEOUT_MS) && getcontenttype.IsCompletedSuccessfully) { if (!getcontenttype.Result.Content.Headers.TryGetValues("content-Type", out IEnumerable contents)) return; - string[] type = contents.FirstOrDefault().Split('/'); - if (!string.Equals(type[0], "image", StringComparison.Ordinal)) + string[] type = contents.FirstOrDefault().Split('/'); + if (string.Equals(contents.FirstOrDefault(), "application/octet-stream")) { + if (task.Wait(HTTP_DOWNLOAD_TIMEOUT_MS) && task.IsCompletedSuccessfully) { + MemoryStream dataCopy = new MemoryStream(); + task.Result.CopyTo(dataCopy); + dataCopy.Position = 0; + Span magic = stackalloc byte[6]; + dataCopy.Read(magic); + if (magic.SequenceEqual(pngMagic)) { + dataCopy.Position = 0; + pic = new BmpPicture(uri.AbsoluteUri); + } else + return; + pic.LoadFromStream(IFace, dataCopy); + pic.Scaled = scaled; + pic.KeepProportions = keepProps; + lock(IFace.UpdateMutex) + Picture = pic; + } + return; + } else if (!string.Equals(type[0], "image", StringComparison.Ordinal)) return; if (string.Equals(type[1], "svg", StringComparison.Ordinal)) pic = new SvgPicture(uri.AbsoluteUri); @@ -176,6 +194,8 @@ namespace Crow lock(IFace.UpdateMutex) Picture = pic; } + } else { + Debug.WriteLine("image downloadThread: get content failed"); } } diff --git a/Crow/src/Widgets/SaturationValueSelector.cs b/Crow/src/Widgets/SaturationValueSelector.cs index 69ff67b9..8cd54d18 100644 --- a/Crow/src/Widgets/SaturationValueSelector.cs +++ b/Crow/src/Widgets/SaturationValueSelector.cs @@ -49,6 +49,8 @@ namespace Crow Rectangle r = ClientRectangle; + gr.Operator = Operator.Over; + if (Foreground != null) {//TODO:test if null should be removed Foreground.SetAsSource (IFace, gr, r); CairoHelpers.CairoRectangle (gr, r, CornerRadius); diff --git a/Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow b/Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow new file mode 100644 index 00000000..24b626cd --- /dev/null +++ b/Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow b/Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow index 6e627506..9582994f 100644 --- a/Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow +++ b/Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow @@ -19,7 +19,7 @@ - - + + +