using OnTopReplica.Native; using OnTopReplica.Properties; using System; using System.Drawing; using System.Windows.Forms; using WindowsFormsAero.TaskDialog; namespace OnTopReplica { //Contains some feature implementations of MainForm partial class MainForm { #region Click forwarding public bool ClickForwardingEnabled { get { return _thumbnailPanel.ReportThumbnailClicks; } set { if (value && Settings.Default.FirstTimeClickForwarding) { TaskDialog dlg = new TaskDialog(Strings.InfoClickForwarding, Strings.InfoClickForwardingTitle, Strings.InfoClickForwardingContent) { CommonButtons = CommonButton.Yes | CommonButton.No }; if (dlg.Show(this).CommonButton == CommonButtonResult.No) return; Settings.Default.FirstTimeClickForwarding = false; } _thumbnailPanel.ReportThumbnailClicks = value; } } #endregion #region Click-through bool _clickThrough = false; readonly Color DefaultNonClickTransparencyKey; public bool ClickThroughEnabled { get { return _clickThrough; } set { TransparencyKey = (value) ? Color.Black : DefaultNonClickTransparencyKey; if (value) { //Re-force as top most (always helps in some cases) TopMost = false; this.Activate(); TopMost = true; } _clickThrough = value; } } //Must NOT be equal to any other valid opacity value const double ClickThroughHoverOpacity = 0.6; Timer _clickThroughComeBackTimer = null; long _clickThroughComeBackTicks; const int ClickThroughComeBackTimerInterval = 1000; /// /// When the mouse hovers over a fully opaque click-through form, /// this fades the form to semi-transparency /// and starts a timeout to get back to full opacity. /// private void RefreshClickThroughComeBack() { if (this.Opacity == 1.0) { this.Opacity = ClickThroughHoverOpacity; } if (_clickThroughComeBackTimer == null) { _clickThroughComeBackTimer = new Timer(); _clickThroughComeBackTimer.Tick += _clickThroughComeBackTimer_Tick; _clickThroughComeBackTimer.Interval = ClickThroughComeBackTimerInterval; } _clickThroughComeBackTicks = DateTime.UtcNow.Ticks; _clickThroughComeBackTimer.Start(); } void _clickThroughComeBackTimer_Tick(object sender, EventArgs e) { var diff = DateTime.UtcNow.Subtract(new DateTime(_clickThroughComeBackTicks)); if (diff.TotalSeconds > 2) { var mousePointer = WindowMethods.GetCursorPos(); if (!this.ContainsMousePointer(mousePointer)) { if (this.Opacity == ClickThroughHoverOpacity) { this.Opacity = 1.0; } _clickThroughComeBackTimer.Stop(); } } } #endregion #region Chrome readonly FormBorderStyle DefaultBorderStyle; // = FormBorderStyle.Sizable; // FormBorderStyle.SizableToolWindow; public bool IsChromeVisible { get { return (FormBorderStyle == DefaultBorderStyle); } set { //Cancel hiding chrome if no thumbnail is shown if (!value && !_thumbnailPanel.IsShowingThumbnail) return; if (!value) { Location = new Point { X = Location.X + SystemInformation.FrameBorderSize.Width, Y = Location.Y + SystemInformation.FrameBorderSize.Height }; FormBorderStyle = FormBorderStyle.None; } else if(value) { Location = new Point { X = Location.X - SystemInformation.FrameBorderSize.Width, Y = Location.Y - SystemInformation.FrameBorderSize.Height }; FormBorderStyle = DefaultBorderStyle; } Program.Platform.OnFormStateChange(this); Invalidate(); } } #endregion #region Position lock ScreenPosition? _positionLock = null; /// /// Gets or sets the screen position where the window is currently locked in. /// public ScreenPosition? PositionLock { get { return _positionLock; } set { if (value != null) this.SetScreenPosition(value.Value); _positionLock = value; } } /// /// Refreshes window position if in lock mode. /// private void RefreshScreenLock() { //If locked in position, move accordingly if (PositionLock.HasValue) { this.SetScreenPosition(PositionLock.Value); } } #endregion } }