Skip to content

Commit 6165c48

Browse files
committed
added IBeam cursor;
cleaned up code a bit;
1 parent 9ea916a commit 6165c48

File tree

14 files changed

+102
-77
lines changed

14 files changed

+102
-77
lines changed

Resources/cursors/ibeam.png

282 Bytes
Loading

System/Windows/Forms/AppGdiImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public struct CursorImages
3434
public Bitmap Hand;
3535
public Bitmap Help;
3636
public Bitmap HSplit;
37+
public Bitmap IBeam;
3738
public Bitmap SizeAll;
3839
public Bitmap SizeNESW;
3940
public Bitmap SizeNS;

System/Windows/Forms/Application.cs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
using System.Globalization;
66
using System.Linq;
77

8-
using UnityEngine;
9-
10-
using Graphics = System.Drawing.Graphics;
11-
128
internal delegate void DragDropRenderHandler(Graphics g);
139

1410
public class Application
@@ -71,17 +67,6 @@ public enum KeyEvents
7167
}
7268

7369
internal static bool IsDraging { get { return dragndrop; } }
74-
internal static bool IsStandalone
75-
{
76-
get
77-
{
78-
#if UNITY_STANDALONE
79-
return true;
80-
#else
81-
return false;
82-
#endif
83-
}
84-
}
8570
internal static float ScaleX
8671
{
8772
get { return scaleX; }
@@ -133,14 +118,14 @@ public void ProccessKeys(KeyEventArgs args, KeyEvents keyEventType)
133118
var keyControl = Control.lastSelected;
134119

135120
// Tab switching through controls.
136-
if (TabSwitching && Event.current.keyCode == KeyCode.Tab && keyEventType == KeyEvents.Down)
121+
if (TabSwitching && args.KeyCode == Keys.Tab && keyEventType == KeyEvents.Down)
137122
{
138123
var containerControl = GetRootControl(keyControl) as ContainerControl;
139124
if (containerControl != null)
140125
{
141-
if (Event.current.modifiers == EventModifiers.None)
126+
if (args.Modifiers == Keys.None)
142127
containerControl.RaiseProcessTabKey(true, keyControl);
143-
else if (Event.current.modifiers == EventModifiers.Shift)
128+
else if (args.Shift)
144129
containerControl.RaiseProcessTabKey(false, keyControl);
145130
}
146131
}
@@ -214,11 +199,6 @@ public void ProccessMouse(MouseEvents mE, float mX, float mY, MouseButtons mButt
214199
MouseHook.RaiseMouseUp(hoveredControl, upArgs);
215200
}
216201
}
217-
public void RaiseMouseEvent(MouseEvents mEv, MouseEventArgs mArgs)
218-
{
219-
if (mArgs != null)
220-
ProccessMouse(mEv, mArgs.X, mArgs.Y, mArgs.Button, mArgs.Clicks, mArgs.Delta);
221-
}
222202
/// <summary>
223203
/// Redrawing the whole screen.
224204
/// </summary>

System/Windows/Forms/ComboBox.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ protected override void OnKeyPress(KeyPressEventArgs args)
190190
char c = KeyHelper.GetLastInputChar();
191191
if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
192192
{
193-
filter += c;
194-
var itemIndex = listBox.FindItemIndex(x => x != null && x.ToString().Contains(filter));
193+
filter += char.ToLower(c);
194+
var itemIndex = listBox.FindItemIndex(x => x != null && x.ToString().ToLower().Contains(filter));
195195
if (itemIndex > -1)
196196
listBox.SelectItem(itemIndex);
197197
}
@@ -213,6 +213,25 @@ protected override void OnMouseDown(MouseEventArgs e)
213213
CreateListBox(String.Empty);
214214
}
215215
}
216+
protected override void OnMouseHover(EventArgs e)
217+
{
218+
base.OnMouseHover(e);
219+
220+
if (Enabled && DropDownStyle == ComboBoxStyle.DropDown)
221+
{
222+
var mclient = PointToClient(MousePosition);
223+
if (mclient.X < Width - 16)
224+
Cursor.Current = Cursors.IBeam;
225+
else
226+
Cursor.Current = Cursors.Default;
227+
}
228+
}
229+
protected override void OnMouseLeave(EventArgs e)
230+
{
231+
base.OnMouseLeave(e);
232+
233+
Cursor.Current = Cursors.Default;
234+
}
216235
protected override void OnMouseWheel(MouseEventArgs e)
217236
{
218237
if (Focused)

System/Windows/Forms/Cursor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ public void SetHotspot(PointPositionTypes x, PointPositionTypes y)
100100
}
101101
public void Draw(Graphics g, Rectangle targetRect)
102102
{
103-
g.DrawImage(image, targetRect.X + HotSpot.X / Application.ScaleX, targetRect.Y + HotSpot.Y / Application.ScaleY, targetRect.Width, targetRect.Height);
103+
g.DrawImage(
104+
image,
105+
targetRect.X + HotSpot.X / Application.ScaleX,
106+
targetRect.Y + HotSpot.Y / Application.ScaleY,
107+
targetRect.Width,
108+
targetRect.Height);
104109
}
105110
}
106111
}

System/Windows/Forms/Cursors.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static class Cursors
1616
private static Cursor hSplit;
1717
private static Cursor vSplit;
1818
private static Cursor hand;
19+
private static Cursor iBeam;
1920

2021
public static Cursor Default
2122
{
@@ -61,6 +62,19 @@ public static Cursor HSplit
6162
return hSplit;
6263
}
6364
}
65+
public static Cursor IBeam
66+
{
67+
get
68+
{
69+
if (iBeam == null)
70+
{
71+
iBeam = new Cursor(images.IBeam);
72+
iBeam.SetHotspot(Cursor.PointPositionTypes.Middle, Cursor.PointPositionTypes.Middle);
73+
}
74+
75+
return iBeam;
76+
}
77+
}
6478
public static Cursor SizeAll
6579
{
6680
get

System/Windows/Forms/FileDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ public pathButton(string path)
809809
arrowButton.Height = Height;
810810
arrowButton.Location = new Point(Width - arrowButton.Width, 0);
811811
arrowButton.Text = "";
812-
arrowButton.Image = Unity.API.UnityWinForms.GdiImages.ArrowRight;
812+
arrowButton.Image = ApplicationResources.Items.ArrowRight;
813813
arrowButton.uwfImageColor = Color.Gray;
814814
arrowButton.uwfImageHoverColor = Color.Gray;
815815

System/Windows/Forms/ListBox.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class ListBox : ListControl
2222
private bool integralHeightAdjust = true;
2323
private int itemHeight = DefaultItemHeight;
2424
private string keyFilter = "";
25-
private Unity.API.UnityWinForms.invokeAction keyFilterIA;
26-
private float keyFilterResetTime = 3;
25+
private Timer keyTimer;
26+
private int keyFilterResetTime = 3; // seconds.
2727
private int visibleItemsCount = 0;
2828
private bool scrollAlwaysVisible;
2929
private int selectedIndex = -1;
@@ -314,9 +314,15 @@ protected override void OnKeyPress(KeyPressEventArgs e)
314314
var itemIndex = FindItemIndex(x => x != null && x.ToString().ToLower().StartsWith(keyFilter));
315315
SelectItem(itemIndex);
316316

317-
if (keyFilterIA == null)
318-
keyFilterIA = Unity.API.UnityWinForms.Invoke(ResetKeyFilter, keyFilterResetTime);
319-
keyFilterIA.Seconds = keyFilterResetTime;
317+
if (keyTimer == null)
318+
{
319+
keyTimer = new Timer();
320+
keyTimer.Interval = keyFilterResetTime * 1000;
321+
keyTimer.Tick += (sender, args) => ResetKeyFilter();
322+
}
323+
324+
keyTimer.Stop();
325+
keyTimer.Start();
320326
}
321327
break;
322328
}
@@ -466,7 +472,8 @@ private void ResetItemHeight()
466472
private void ResetKeyFilter()
467473
{
468474
keyFilter = "";
469-
keyFilterIA = null;
475+
keyTimer.Dispose();
476+
keyTimer = null;
470477
}
471478

472479
public class ObjectCollection : IList

System/Windows/Forms/NumericUpDown.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ protected override void OnKeyDown(KeyEventArgs e)
134134
if (e.KeyCode == Keys.Return)
135135
ConfirmValue();
136136
}
137+
protected override void OnMouseEnter(EventArgs e)
138+
{
139+
base.OnMouseEnter(e);
140+
141+
if (Enabled)
142+
Cursor.Current = Cursors.IBeam;
143+
}
144+
protected override void OnMouseLeave(EventArgs e)
145+
{
146+
base.OnMouseLeave(e);
147+
148+
Cursor.Current = Cursors.Default;
149+
}
137150
protected override void OnMouseWheel(MouseEventArgs e)
138151
{
139152
if (!Focused) return;

System/Windows/Forms/TextBox.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ protected override Size DefaultSize
6262
get { return new Size(100, 24); }
6363
}
6464

65+
protected override void OnMouseEnter(EventArgs e)
66+
{
67+
base.OnMouseEnter(e);
68+
69+
if (Enabled && ReadOnly == false)
70+
Cursor.Current = Cursors.IBeam;
71+
}
72+
protected override void OnMouseLeave(EventArgs e)
73+
{
74+
base.OnMouseLeave(e);
75+
76+
Cursor.Current = Cursors.Default;
77+
}
6578
protected override void OnPaint(PaintEventArgs e)
6679
{
6780
base.OnPaint(e);

0 commit comments

Comments
 (0)