From cad4bd501a14a915b0304d29103d37788f253587 Mon Sep 17 00:00:00 2001 From: Dmytro Ovcharov Date: Thu, 20 Jul 2017 17:20:54 +0300 Subject: Fixes BXC #53775 --- .../MonoDevelop.Components/EventBoxTooltip.cs | 71 ++++++++++++++++++++-- 1 file changed, 65 insertions(+), 6 deletions(-) (limited to 'main/src/core/MonoDevelop.Ide') diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/EventBoxTooltip.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/EventBoxTooltip.cs index ad48d0c426..670fb6d708 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/EventBoxTooltip.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/EventBoxTooltip.cs @@ -29,9 +29,11 @@ using Gtk; using System; using MonoDevelop.Components.AtkCocoaHelper; using MonoDevelop.Ide.Tasks; +using MonoDevelop.Ide; +using Gdk; namespace MonoDevelop.Components -{ +{ public class EventBoxTooltip : IDisposable { EventBox eventBox; @@ -43,24 +45,48 @@ namespace MonoDevelop.Components get { return eventBox.Accessible; } - } - + } + /// /// The EventBox should have Visible set to false otherwise the tooltip pop window /// will have the wrong location. /// + + ImageView image; + Pixbuf normalPixbuf; + Pixbuf activePixbuf; + public EventBoxTooltip (EventBox eventBox) { this.eventBox = eventBox; + eventBox.CanFocus = true; eventBox.EnterNotifyEvent += HandleEnterNotifyEvent; eventBox.LeaveNotifyEvent += HandleLeaveNotifyEvent; eventBox.FocusInEvent += HandleFocusInEvent; eventBox.FocusOutEvent += HandleFocusOutEvent; + image = eventBox.Child as ImageView; + + if (image != null) { + normalPixbuf = image.Image.ToPixbuf (); + } + normalPixbuf = image.Image.ToPixbuf (); + activePixbuf = normalPixbuf.ColorShiftPixbuf (); + + eventBox.FocusGrabbed += (sender, e) => { + if (image != null) + image.Image = activePixbuf.ToXwtImage (); + }; + + eventBox.Focused += (o, args) => { + if (image != null) + image.Image = normalPixbuf.ToXwtImage (); + }; + Position = PopupPosition.TopLeft; - // Accessibility: Disguise this eventbox as a label + // Accessibility: Disguise this eventbox as a label eventBox.Accessible.SetRole (AtkCocoa.Roles.AXStaticText); eventBox.CanFocus = true; } @@ -89,7 +115,7 @@ namespace MonoDevelop.Components [GLib.ConnectBefore] void HandleFocusInEvent (object sender, EventArgs e) { - mouseOver = true; + mouseOver = true; ShowTooltip (); } @@ -146,6 +172,39 @@ namespace MonoDevelop.Components public TaskSeverity? Severity { get; set; } public PopupPosition Position { get; set; } - } + } +#region Extension method for Pixbuf + internal static class PixbufExtension + { + public static unsafe Pixbuf ColorShiftPixbuf (this Pixbuf src, byte shift = 120) + { + var dest = new Gdk.Pixbuf (src.Colorspace, src.HasAlpha, src.BitsPerSample, src.Width, src.Height); + + byte* src_pixels_orig = (byte*)src.Pixels; + byte* dest_pixels_orig = (byte*)dest.Pixels; + + for (int i = 0; i < src.Height; i++) { + byte* src_pixels = src_pixels_orig + i * src.Rowstride; + byte* dest_pixels = dest_pixels_orig + i * dest.Rowstride; + + for (int j = 0; j < src.Width; j++) { + *(dest_pixels++) = PixelClamp (*(src_pixels++) + shift); + *(dest_pixels++) = PixelClamp (*(src_pixels++) + shift); + *(dest_pixels++) = PixelClamp (*(src_pixels++) + shift); + + if (src.HasAlpha) { + *(dest_pixels++) = *(src_pixels++); + } + } + } + return dest; + } + + static byte PixelClamp (int val) + { + return (byte)System.Math.Max (0, System.Math.Min (255, val)); + } + } +#endregion } -- cgit v1.2.3