-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminiBrowser.Widget.cs
206 lines (187 loc) · 6.52 KB
/
miniBrowser.Widget.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Timers;
namespace miniExplorer
{
public class PocketForm : Form
{
public bool Foldable = false;
public bool Folded = false;
public Size UnfoldedSize = new Size(300, 300);
public DpiFactor DpiScale
{
get => new DpiFactor(DeviceDpi / 96.0f);
}
public PocketForm()
{
AllowDrop = true;
FormBorderStyle = FormBorderStyle.SizableToolWindow;
StartPosition = FormStartPosition.WindowsDefaultLocation;
TopMost = true;
KeyPreview = true;
AutoScaleMode = AutoScaleMode.Dpi;
Font = SystemFonts.CaptionFont;
DragEnter += new DragEventHandler((object sender, DragEventArgs e) =>
{
if (Foldable)
{
Unfold();
System.Timers.Timer foldTimer = new System.Timers.Timer()
{
Interval = 100
};
foldTimer.Elapsed += new ElapsedEventHandler((object s, ElapsedEventArgs ea) =>
{
if (!this.ClientRectangle.Contains(Cursor.Position))
{
Fold();
foldTimer.Stop();
foldTimer.Dispose();
}
});
}
});
DragLeave += new EventHandler((object sender, EventArgs e) =>
{
if (Foldable & !this.ClientRectangle.Contains(this.PointToClient(Control.MousePosition))) Fold();
});
ResizeEnd += new EventHandler((object sender, EventArgs e) =>
{
Foldable = false;
Folded = false;
UnfoldedSize = new Size(ClientSize.Width, Math.Max(ClientSize.Height, 150 * DpiScale));
});
}
protected override void WndProc(ref Message m)
{
// const int WM_NCLBUTTONDOWN = 0x00A1;
const int WM_NCLBUTTONDBLCLK = 0x00A3;
const int WM_NCRBUTTONDOWN = 0x00A4;
const int WM_CONTEXTMENU = 0x007B;
switch (m.Msg)
{
case WM_CONTEXTMENU:
m.Result = IntPtr.Zero;
break;
case WM_NCLBUTTONDBLCLK:
case WM_NCRBUTTONDOWN:
Foldable = !Foldable;
if (Foldable)
Fold();
else
Unfold();
break;
default:
base.WndProc(ref m);
break;
}
}
protected override void OnDpiChanged(DpiChangedEventArgs e)
{
base.OnDpiChanged(e);
if (!Folded) MinimumSize = new Size(150 * DpiScale, 150 * DpiScale);
}
public void OnMouseEnterWindow()
{
if (Foldable) Unfold();
}
public void OnMouseLeaveWindow()
{
if (Foldable) Fold();
}
public void Fold()
{
Folded = true;
MinimumSize = new Size(150 * DpiScale, 0);
MaximumSize = new Size(int.MaxValue, 0);
ClientSize = new Size(UnfoldedSize.Width, 0);
}
public void Unfold()
{
MaximumSize = new Size(0, 0);
MinimumSize = new Size(150 * DpiScale, 150 * DpiScale);
ClientSize = UnfoldedSize;
Folded = false;
}
}
public class ListViewWithoutHorizontalScrollBar : ListView
{
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)]
public static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, int dwNewLong);
const int GWL_STYLE = -16;
const int WM_NCCALCSIZE = 0x83;
const int WS_VSCROLL = 0x200000;
const int WS_HSCROLL = 0x100000;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCCALCSIZE:
int style = (int)GetWindowLongPtr64(this.Handle, GWL_STYLE);
if ((style & WS_HSCROLL) == WS_HSCROLL)
style &= ~WS_HSCROLL;
SetWindowLongPtr64(this.Handle, GWL_STYLE, style);
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
public bool Updating = false;
new void BeginUpdate()
{
Updating = true;
base.BeginUpdate();
}
new void EndUpdate()
{
base.EndUpdate();
Updating = false;
}
}
public class TabControlW : TabControl
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
// Send TCM_SETMINTABWIDTH
SendMessage(this.Handle, 0x1331, IntPtr.Zero, (IntPtr)10);
}
public TabControlW()
{
}
public TabPage PointedTab
{
get
{
Point pt = PointToClient(Cursor.Position);
for (int i = 0; i < TabPages.Count; i++)
if (GetTabRect(i).Contains(pt))
return TabPages[i];
return null;
}
}
}
public class OneTimeTimer : System.Timers.Timer
{
public Action DisposeAction;
public OneTimeTimer(double interval) : base(interval)
{
AutoReset = false;
Elapsed += new ElapsedEventHandler((object sender, ElapsedEventArgs e) =>
{
if (DisposeAction != null)
DisposeAction();
Stop();
Dispose();
});
}
}
}