GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — STTextBox/ST.Library.UI.STTextBox/STTextBox.MouseEvent.cs at main · DebugST/STTextBox

Expand file tree

/

STTextBox.MouseEvent.cs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
292 lines (278 loc) · 12.1 KB
/

STTextBox.MouseEvent.cs

Copy path

File metadata and controls

292 lines (278 loc) · 12.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace ST.Library.UI.STTextBox
{
partial class STTextBox
{
private struct ScrollIncrement
{
public int Time;
public int Value;
public ScrollIncrement(int nTime, int nValue) {
this.Time = nTime;
this.Value = nValue;
}
}
private DateTime m_dt_last_scroll_h = DateTime.Now;
private DateTime m_dt_last_scroll_v = DateTime.Now;
private ScrollIncrement[] m_arr_si = new ScrollIncrement[]{
new ScrollIncrement(20, 6),
new ScrollIncrement(30, 5),
new ScrollIncrement(40, 4),
new ScrollIncrement(50, 3),
new ScrollIncrement(60, 2),
};
protected override void OnMouseDown(MouseEventArgs e) {
base.OnMouseDown(e);
var c = m_core;
this.Select();
if (c.Scroll.HoverScrollBar != STTextBoxScrollInfo.ScrollBarType.None) {
if (c.Scroll.HBackRect.Contains(e.Location)) {
c.Scroll.DownScrollBar = STTextBoxScrollInfo.ScrollBarType.H;
c.ITextView.ScrollXToMuosePoint(e.X);
this.Invalidate();
} else if (c.Scroll.VBackRect.Contains(e.Location)) {
c.Scroll.DownScrollBar = STTextBoxScrollInfo.ScrollBarType.V;
c.ITextView.ScrollYToMousePoint(e.Y);
this.Invalidate();
}
return;
}
m_last_sel_region = Rectangle.Empty;
var fi = c.ITextView.SetCaretPostion(e.Location);// c.ITextView.FindFromPoint(e.Location);
//c.Caret.CopyFromFindInfo(fi);
if (Control.ModifierKeys != Keys.Shift) {
c.Selection.SetIndex(c.Caret.IndexOfChar);
} else {
c.Selection.SetSelection(c.Selection.AnchorIndex, c.Caret.IndexOfChar);
}
this.Invalidate();
}
private Rectangle m_last_sel_region = Rectangle.Empty;
public void InvalidateSelectionPixelYChange(int oldY, int newY) {
var c = m_core;
int minY = Math.Min(oldY, newY);
int maxY = Math.Max(oldY, newY);
int lineHeight = c.LineHeight;
int spacing = c.TextBox.GetIntYSize(c.TextBox.LineSpacing);
int startY = minY - 2;
int height = (maxY - minY) + lineHeight + spacing + 4;
startY = Math.Max(c.ViewRectangle.Top, startY);
height = Math.Min(height, c.ViewRectangle.Bottom - startY);
if (height <= 0) {
this.Invalidate();
return;
}
Rectangle rect = new Rectangle(c.ViewRectangle.Left, startY, c.ViewRectangle.Width, height);
if (!m_last_sel_region.IsEmpty) {
rect = Rectangle.Union(m_last_sel_region, rect);
}
m_last_sel_region = rect;
this.Invalidate(rect);
}
public void InvalidateSelectionChange(int oldLine, int newLine) {
var c = m_core;
if (c.ITextView is WrapTextView) {
var m = c.TextManager;
int screenStart = c.ViewRectangle.Top;
int screenEnd = c.ViewRectangle.Bottom;
int minLine = Math.Min(oldLine, newLine);
int maxLine = Math.Max(oldLine, newLine);
if (minLine >= 0 && minLine < m.LineCount) {
var fi = c.ITextView.FindFromCharIndex(m[minLine].IndexOfFirstChar);
if (fi.Find) screenStart = fi.Location.Y;
}
if (maxLine >= 0 && maxLine < m.LineCount) {
var fi = c.ITextView.FindFromCharIndex(m[maxLine].IndexOfFirstChar + m[maxLine].RawString.Length);
if (fi.Find) screenEnd = fi.Location.Y + c.LineHeight;
}
InvalidateSelectionPixelYChange(screenStart, screenEnd);
return;
}
int minL = Math.Min(oldLine, newLine);
int maxL = Math.Max(oldLine, newLine);
int lineHeight = c.LineHeight;
Point ptTop = c.ITextView.ViewToControl(new Point(0, minL * lineHeight));
int startY = ptTop.Y - 2;
int spacing = c.TextBox.GetIntYSize(c.TextBox.LineSpacing);
int height = ((maxL - minL + 1) * lineHeight) + spacing + 4;
startY = Math.Max(c.ViewRectangle.Top, startY);
height = Math.Min(height, c.ViewRectangle.Bottom - startY);
if (height <= 0) {
this.Invalidate();
return;
}
Rectangle rect = new Rectangle(c.ViewRectangle.Left, startY, c.ViewRectangle.Width, height);
if (!m_last_sel_region.IsEmpty) {
rect = Rectangle.Union(m_last_sel_region, rect);
}
m_last_sel_region = rect;
this.Invalidate(rect);
}
protected override void OnMouseMove(MouseEventArgs e) {
base.OnMouseMove(e);
var c = m_core;
switch (c.Scroll.DownScrollBar) {
case STTextBoxScrollInfo.ScrollBarType.V:
c.ITextView.ScrollYToMousePoint(e.Y);
this.Invalidate();
return;
case STTextBoxScrollInfo.ScrollBarType.H:
c.ITextView.ScrollXToMuosePoint(e.X);
this.Invalidate();
return;
}
if (e.Button == System.Windows.Forms.MouseButtons.Left) {
int oldCaretY = c.Caret.Y;
var fi = c.ITextView.SetCaretPostion(e.Location);
if (!fi.Find) return;
int nIndex = c.Caret.IndexOfChar;
c.Selection.SetSelection(c.Selection.AnchorIndex, nIndex);
bool scrolled = c.ITextView.ScrollToCaret();
if (scrolled) {
m_last_sel_region = Rectangle.Empty;
this.Invalidate();
} else {
this.InvalidateSelectionPixelYChange(oldCaretY, c.Caret.Y);
}
return;
}
if (e.Button == MouseButtons.None && c.Scroll.CountDown != 0) {
if (c.Scroll.VBackRect.Contains(e.Location)) {
c.Scroll.HoverScrollBar = STTextBoxScrollInfo.ScrollBarType.V;
} else if (c.Scroll.HBackRect.Contains(e.Location)) {
c.Scroll.HoverScrollBar = STTextBoxScrollInfo.ScrollBarType.H;
} else {
c.Scroll.HoverScrollBar = STTextBoxScrollInfo.ScrollBarType.None;
}
if (c.Scroll.HoverScrollBar != STTextBoxScrollInfo.ScrollBarType.None) {
this.ShowScrollBar(c.Scroll.DisplayTime);
if (this.SetCursor(Cursors.Arrow)) {
this.Invalidate();
}
} else {
if (this.SetCursor(Cursors.IBeam)) {
this.Invalidate();
}
}
} else {
c.ITextView.OnSetCursor(e);
}
}
protected override void OnMouseUp(MouseEventArgs e) {
base.OnMouseUp(e);
m_last_sel_region = Rectangle.Empty;
var c = m_core;
c.Scroll.DownScrollBar = STTextBoxScrollInfo.ScrollBarType.None;
this.Invalidate();
}
protected override void OnMouseLeave(EventArgs e) {
base.OnMouseLeave(e);
var c = m_core;
c.Scroll.HoverScrollBar = STTextBoxScrollInfo.ScrollBarType.None;
}
protected override void OnMouseWheel(MouseEventArgs e) {
base.OnMouseWheel(e);
DateTime dt_now = DateTime.Now;
//Console.WriteLine("Scroll: --------------------- " + dt_now.Subtract(m_dt_last_scroll_v).TotalMilliseconds);
int nIncrement = 1;
int nTemp = (int)dt_now.Subtract(m_dt_last_scroll_v).TotalMilliseconds;
foreach (var v in m_arr_si) {
if (nTemp < v.Time) {
nIncrement = v.Value;
break;
}
}
m_dt_last_scroll_v = dt_now;
var c = m_core;
if (e.Delta > 0) {
if (c.Scroll.YValue <= 0) return;
if (c.Scroll.YValue - nIncrement < 0) {
nIncrement = c.Scroll.YValue;
}
c.Scroll.YValue -= nIncrement;
c.Caret.Y += nIncrement * c.LineHeight;// this.Font.Height;
} else {
if (c.Scroll.YValue >= c.Scroll.MaxYValue) {
return;
}
if (c.Scroll.YValue + nIncrement > c.Scroll.MaxYValue) {
nIncrement = c.Scroll.MaxYValue - c.Scroll.YValue;
}
c.Scroll.YValue += nIncrement;
c.Caret.Y -= c.LineHeight * nIncrement;// c.ITextRender.GetFontHeight();
}
c.ITextView.SetCaretPostion(c.Caret.IndexOfChar);
//c.ITextView.SetCaretPostion(c.Caret.X, c.Caret.Y);
this.ShowScrollBar(c.Scroll.DisplayTime);
this.Invalidate();
//c.Scroll.Timer = 5;
}
protected virtual void OnMouseHWheel(MouseEventArgs e) {
DateTime dt_now = DateTime.Now;
//Console.WriteLine("Scroll: --------------------- " + dt_now.Subtract(m_dt_last_scroll_h).TotalMilliseconds);
int nIncrement = 1;
int nTemp = (int)dt_now.Subtract(m_dt_last_scroll_h).TotalMilliseconds;
foreach (var v in m_arr_si) {
if (nTemp < v.Time) {
nIncrement = v.Value;
break;
}
}
m_dt_last_scroll_h = dt_now;
var c = m_core;
if (e.Delta < 0) {
if (c.Scroll.XValue <= 0) return;
if (c.Scroll.XValue - nIncrement < 0) {
nIncrement = c.Scroll.XValue;
}
c.Scroll.XValue -= nIncrement;
c.Caret.X += c.Scroll.XIncrement * nIncrement;
} else {
if (c.Scroll.XValue >= c.Scroll.MaxXValue) {
return;
}
if (c.Scroll.XValue + nIncrement > c.Scroll.MaxXValue) {
nIncrement = c.Scroll.MaxXValue - c.Scroll.XValue;
}
c.Scroll.XValue += nIncrement;
c.Caret.X -= c.Scroll.XIncrement * nIncrement;
}
//c.ITextView.SetCaretPostion(c.Caret.X, c.Caret.Y);
c.ITextView.SetCaretPostion(c.Caret.IndexOfChar);
this.ShowScrollBar(c.Scroll.DisplayTime);
this.Invalidate();
//c.Scroll.Timer = 5;
}
protected override void OnMouseDoubleClick(MouseEventArgs e) {
base.OnMouseDoubleClick(e);
var c = m_core;
var fi = c.ITextView.FindFromPoint(e.Location);
int nIndex = fi.IndexOfChar - fi.Line.IndexOfFirstChar;
int nSelectionStart = fi.IndexOfChar, nSelectionLen = 0;
c.IWordSplitter.Each(fi.Line.RawString, (str, nStart, nLen) => {
if (nIndex >= nStart && nIndex < nStart + nLen) {
switch (str[nStart]) {
case '\r':
case '\n':
return false;
}
nSelectionStart = fi.Line.IndexOfFirstChar + nStart;
nSelectionLen = nLen;
return false;
}
nSelectionStart = fi.Line.IndexOfFirstChar + nStart;
nSelectionLen = nLen;
return true;
});
c.Selection.SetSelection(nSelectionStart, nSelectionStart + nSelectionLen);
c.Caret.IndexOfChar = c.Selection.EndIndex;
c.ITextView.SetCaretPostion(c.Caret.IndexOfChar);
this.Invalidate();
}
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.