forked from CopyPlusPlus/CopyPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IconPopup.xaml.cs
125 lines (98 loc) · 3.19 KB
/
IconPopup.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using ControlzEx.Standard;
using Application = System.Windows.Application;
using Clipboard = System.Windows.Clipboard;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using Timer = System.Timers.Timer;
namespace CopyPlusPlus
{
/// <summary>
/// Interaction logic for IconPopup.xaml
/// </summary>
public partial class IconPopup
{
private static Timer _fadeTimer;
private static Timer _stayTimer;
//Get MainWindow
private readonly MainWindow _mainWindow = Application.Current.Windows
.Cast<Window>()
.FirstOrDefault(window => window is MainWindow) as MainWindow;
private double _opacity = 1;
public string CopiedText;
[Obsolete] public POINT MouseLocation;
public IconPopup()
{
InitializeComponent();
// Create a timer
_stayTimer = new Timer(1111);
// Hook up the Elapsed event for the timer.
_stayTimer.Elapsed += OnStayTimedEvent;
// Create a timer
_fadeTimer = new Timer(100);
// Hook up the Elapsed event for the timer.
_fadeTimer.Elapsed += OnFadeTimedEvent;
_fadeTimer.AutoReset = true;
Stay();
}
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
[Obsolete]
private static extern IntPtr WindowFromPoint(POINT point);
[Obsolete]
private async void OnLeftMouseDown(object sender, MouseButtonEventArgs e)
{
Hide();
SetForegroundWindow(WindowFromPoint(MouseLocation));
//await Task.Delay(10);
SendKeys.SendWait("^c");
await Task.Delay(666);
//Thread.Sleep(1111);
_mainWindow.ProcessText(Clipboard.GetText());
}
private static void Stay()
{
_stayTimer.Start();
}
private static void OnStayTimedEvent(object source, ElapsedEventArgs e)
{
Fade();
_stayTimer.Stop();
}
private static void Fade()
{
_fadeTimer.Start();
}
private void OnFadeTimedEvent(object source, ElapsedEventArgs e)
{
_opacity -= 0.04;
if (_opacity == 0) Close();
Icon.Dispatcher.Invoke(delegate { Icon.Opacity = _opacity; });
}
private void Icon_OnMouseEnter(object sender, MouseEventArgs e)
{
Icon.Dispatcher.Invoke(delegate { Icon.Opacity = 1; });
_stayTimer.Stop();
_fadeTimer.Stop();
_opacity = 1;
}
private void Icon_OnMouseLeave(object sender, MouseEventArgs e)
{
Stay();
}
private void OnClosed(object sender, EventArgs e)
{
_fadeTimer.Stop();
_fadeTimer.Dispose();
_stayTimer.Stop();
_stayTimer.Dispose();
}
}
}