Skip to content

Commit 9723997

Browse files
committed
added CreateParams, not really working, but you can add WS_DISABLED to form.CreateParams.ExStyle from NativeMethods to disable it from focusing on 'Show' method;
added control.Owner; added form.Show(Form owner) and form.ShowDialog(Form owner); added tabControl events: Selected, Selecting, Deselected, Deselecting;
1 parent 4f2bde3 commit 9723997

File tree

9 files changed

+374
-32
lines changed

9 files changed

+374
-32
lines changed

System/Windows/Forms/Application.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class Application
1515
{
1616
internal static Control activeResizeControl;
17-
internal static CultureInfo currentCulture;
17+
internal static CultureInfo currentCulture = ApiHolder.System.CurrentCulture;
1818
internal static bool dragndrop;
1919
internal static object dragData;
2020
internal readonly List<Control> Contexts = new List<Control>();
@@ -44,8 +44,7 @@ public class Application
4444
public Application()
4545
{
4646
TabSwitching = true;
47-
48-
currentCulture = ApiHolder.System.CurrentCulture;
47+
4948
paintEventArgs = new PaintEventArgs();
5049
paintEventArgs.Graphics = new Graphics();
5150

System/Windows/Forms/Control.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Control : Component, IDropTarget
2929
private int clientWidth;
3030
private ControlCollection controls;
3131
private ControlStyles controlStyle;
32+
private CreateParams createParams;
3233
private bool enabled;
3334
private Font font = SystemFonts.uwfArial_12;
3435
private Color foreColor = defaultForeColor;
@@ -277,6 +278,22 @@ internal virtual bool uwfContext // Close on click control.
277278
}
278279
internal bool uwfHovered { get { return hovered; } }
279280

281+
protected virtual CreateParams CreateParams
282+
{
283+
get
284+
{
285+
if (createParams == null)
286+
createParams = new CreateParams();
287+
288+
createParams.Caption = text;
289+
createParams.X = x;
290+
createParams.Y = y;
291+
createParams.Width = width;
292+
createParams.Height = height;
293+
294+
return createParams;
295+
}
296+
}
280297
protected virtual Size DefaultSize
281298
{
282299
get { return Size.Empty; }

System/Windows/Forms/CreateParams.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
namespace System.Windows.Forms
2+
{
3+
using System.Text;
4+
5+
public class CreateParams
6+
{
7+
private string caption;
8+
private string className;
9+
private int classStyle;
10+
private int exStyle;
11+
private int height;
12+
private object param;
13+
private IntPtr parent;
14+
private int style;
15+
private int width;
16+
private int x;
17+
private int y;
18+
19+
public string Caption
20+
{
21+
get { return caption; }
22+
set { caption = value; }
23+
}
24+
public string ClassName
25+
{
26+
get { return className; }
27+
set { className = value; }
28+
}
29+
public int ClassStyle
30+
{
31+
get { return classStyle; }
32+
set { classStyle = value; }
33+
}
34+
public int ExStyle
35+
{
36+
get { return exStyle; }
37+
set { exStyle = value; }
38+
}
39+
public int Height
40+
{
41+
get { return height; }
42+
set { height = value; }
43+
}
44+
public object Param
45+
{
46+
get { return param; }
47+
set { param = value; }
48+
}
49+
public IntPtr Parent
50+
{
51+
get { return parent; }
52+
set { parent = value; }
53+
}
54+
/// <summary>
55+
/// TODO: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
56+
/// </summary>
57+
public int Style
58+
{
59+
get { return style; }
60+
set { style = value; }
61+
}
62+
public int Width
63+
{
64+
get { return width; }
65+
set { width = value; }
66+
}
67+
public int X
68+
{
69+
get { return x; }
70+
set { x = value; }
71+
}
72+
public int Y
73+
{
74+
get { return y; }
75+
set { y = value; }
76+
}
77+
78+
public override string ToString()
79+
{
80+
StringBuilder sb = new StringBuilder(64);
81+
sb.Append("CreateParams {'");
82+
sb.Append(className);
83+
sb.Append("', '");
84+
sb.Append(caption);
85+
sb.Append("', 0x");
86+
sb.Append(Convert.ToString(style, 16));
87+
sb.Append(", 0x");
88+
sb.Append(Convert.ToString(exStyle, 16));
89+
sb.Append(", {");
90+
sb.Append(x);
91+
sb.Append(", ");
92+
sb.Append(y);
93+
sb.Append(", ");
94+
sb.Append(width);
95+
sb.Append(", ");
96+
sb.Append(height);
97+
sb.Append("}");
98+
sb.Append("}");
99+
return sb.ToString();
100+
}
101+
}
102+
}

System/Windows/Forms/Form.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void SetResize(ControlResizeTypes resize)
217217
break;
218218
}
219219
}
220-
public void Show(bool fShouldFocus = true)
220+
public void Show()
221221
{
222222
if (Visible)
223223
return;
@@ -229,11 +229,7 @@ public void Show(bool fShouldFocus = true)
229229
if (uwfAppOwner.Forms.Contains(this) == false)
230230
uwfAppOwner.Forms.Add(this);
231231

232-
if (fShouldFocus)
233-
{
234-
Focus();
235-
_SelectFirstControl();
236-
}
232+
TryFocus();
237233

238234
OnShown(EventArgs.Empty);
239235
}
@@ -245,6 +241,12 @@ public void Show(Form owner) // original: public void Show(IWin32Window owner)
245241
}
246242
public DialogResult ShowDialog(Action<Form, DialogResult> onClosed = null)
247243
{
244+
return ShowDialog(null, onClosed);
245+
}
246+
public DialogResult ShowDialog(Form owner, Action<Form, DialogResult> onClosed = null)
247+
{
248+
this.owner = owner;
249+
248250
PlaceAtStartPosition(startPosition);
249251

250252
dialog = true;
@@ -256,8 +258,7 @@ public DialogResult ShowDialog(Action<Form, DialogResult> onClosed = null)
256258
if (self == -1)
257259
uwfAppOwner.ModalForms.Add(this);
258260

259-
Focus();
260-
_SelectFirstControl();
261+
TryFocus();
261262

262263
OnShown(EventArgs.Empty);
263264

@@ -571,6 +572,19 @@ private void _SelectFirstControl()
571572
return;
572573
}
573574
}
575+
private bool TryFocus()
576+
{
577+
// Check if we should focus form.
578+
if ((CreateParams.ExStyle & (NativeMethods.WS_DISABLED | NativeMethods.WS_EX_TOOLWINDOW)) == 0)
579+
{
580+
Focus();
581+
_SelectFirstControl();
582+
583+
return true;
584+
}
585+
586+
return false;
587+
}
574588

575589
private class formSystemButton : Button
576590
{
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Drawing;
6-
7-
namespace System.Windows.Forms
1+
namespace System.Windows.Forms
82
{
9-
public interface IResizableControl
10-
{
11-
ControlResizeTypes GetResizeAt(Point mclient);
12-
}
3+
using System.Drawing;
134

145
public enum ControlResizeTypes
156
{
@@ -25,4 +16,9 @@ public enum ControlResizeTypes
2516
LeftUp,
2617
RightUp
2718
}
19+
20+
public interface IResizableControl
21+
{
22+
ControlResizeTypes GetResizeAt(Point mclient);
23+
}
2824
}

System/Windows/Forms/NativeMethods.cs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,109 @@ internal static class NativeMethods
1717
EDGE_ETCHED = 0x0002 | 0x0004,
1818
EDGE_RAISED = 0x0001 | 0x0004,
1919
EDGE_SUNKEN = 0x0002 | 0x0008;
20+
21+
public const int WHEEL_DELTA = 120,
22+
WM_PARENTNOTIFY = 0x0210,
23+
WM_ENTERMENULOOP = 0x0211,
24+
WM_EXITMENULOOP = 0x0212,
25+
WM_NEXTMENU = 0x0213,
26+
WM_SIZING = 0x0214,
27+
WM_CAPTURECHANGED = 0x0215,
28+
WM_MOVING = 0x0216,
29+
WM_POWERBROADCAST = 0x0218,
30+
WM_DEVICECHANGE = 0x0219,
31+
WM_IME_SETCONTEXT = 0x0281,
32+
WM_IME_NOTIFY = 0x0282,
33+
WM_IME_CONTROL = 0x0283,
34+
WM_IME_COMPOSITIONFULL = 0x0284,
35+
WM_IME_SELECT = 0x0285,
36+
WM_IME_CHAR = 0x0286,
37+
WM_IME_KEYDOWN = 0x0290,
38+
WM_IME_KEYUP = 0x0291,
39+
WM_MDICREATE = 0x0220,
40+
WM_MDIDESTROY = 0x0221,
41+
WM_MDIACTIVATE = 0x0222,
42+
WM_MDIRESTORE = 0x0223,
43+
WM_MDINEXT = 0x0224,
44+
WM_MDIMAXIMIZE = 0x0225,
45+
WM_MDITILE = 0x0226,
46+
WM_MDICASCADE = 0x0227,
47+
WM_MDIICONARRANGE = 0x0228,
48+
WM_MDIGETACTIVE = 0x0229,
49+
WM_MDISETMENU = 0x0230,
50+
WM_ENTERSIZEMOVE = 0x0231,
51+
WM_EXITSIZEMOVE = 0x0232,
52+
WM_DROPFILES = 0x0233,
53+
WM_MDIREFRESHMENU = 0x0234,
54+
WM_MOUSEHOVER = 0x02A1,
55+
WM_MOUSELEAVE = 0x02A3,
56+
WM_CUT = 0x0300,
57+
WM_COPY = 0x0301,
58+
WM_PASTE = 0x0302,
59+
WM_CLEAR = 0x0303,
60+
WM_UNDO = 0x0304,
61+
WM_RENDERFORMAT = 0x0305,
62+
WM_RENDERALLFORMATS = 0x0306,
63+
WM_DESTROYCLIPBOARD = 0x0307,
64+
WM_DRAWCLIPBOARD = 0x0308,
65+
WM_PAINTCLIPBOARD = 0x0309,
66+
WM_VSCROLLCLIPBOARD = 0x030A,
67+
WM_SIZECLIPBOARD = 0x030B,
68+
WM_ASKCBFORMATNAME = 0x030C,
69+
WM_CHANGECBCHAIN = 0x030D,
70+
WM_HSCROLLCLIPBOARD = 0x030E,
71+
WM_QUERYNEWPALETTE = 0x030F,
72+
WM_PALETTEISCHANGING = 0x0310,
73+
WM_PALETTECHANGED = 0x0311,
74+
WM_HOTKEY = 0x0312,
75+
WM_PRINT = 0x0317,
76+
WM_PRINTCLIENT = 0x0318,
77+
WM_THEMECHANGED = 0x031A,
78+
WM_HANDHELDFIRST = 0x0358,
79+
WM_HANDHELDLAST = 0x035F,
80+
WM_AFXFIRST = 0x0360,
81+
WM_AFXLAST = 0x037F,
82+
WM_PENWINFIRST = 0x0380,
83+
WM_PENWINLAST = 0x038F,
84+
WM_APP = 0x8000,
85+
WM_USER = 0x0400,
86+
WM_REFLECT = WM_USER + 0x1C00,
87+
WS_OVERLAPPED = 0x00000000,
88+
WS_POPUP = unchecked((int)0x80000000),
89+
WS_CHILD = 0x40000000,
90+
WS_MINIMIZE = 0x20000000,
91+
WS_VISIBLE = 0x10000000,
92+
WS_DISABLED = 0x08000000, // preventing auto-focus atm.
93+
WS_CLIPSIBLINGS = 0x04000000,
94+
WS_CLIPCHILDREN = 0x02000000,
95+
WS_MAXIMIZE = 0x01000000,
96+
WS_CAPTION = 0x00C00000,
97+
WS_BORDER = 0x00800000,
98+
WS_DLGFRAME = 0x00400000,
99+
WS_VSCROLL = 0x00200000,
100+
WS_HSCROLL = 0x00100000,
101+
WS_SYSMENU = 0x00080000,
102+
WS_THICKFRAME = 0x00040000,
103+
WS_TABSTOP = 0x00010000,
104+
WS_MINIMIZEBOX = 0x00020000,
105+
WS_MAXIMIZEBOX = 0x00010000,
106+
WS_EX_DLGMODALFRAME = 0x00000001,
107+
WS_EX_MDICHILD = 0x00000040,
108+
WS_EX_TOOLWINDOW = 0x00000080,
109+
WS_EX_CLIENTEDGE = 0x00000200,
110+
WS_EX_CONTEXTHELP = 0x00000400,
111+
WS_EX_RIGHT = 0x00001000,
112+
WS_EX_LEFT = 0x00000000,
113+
WS_EX_RTLREADING = 0x00002000,
114+
WS_EX_LEFTSCROLLBAR = 0x00004000,
115+
WS_EX_CONTROLPARENT = 0x00010000,
116+
WS_EX_STATICEDGE = 0x00020000,
117+
WS_EX_APPWINDOW = 0x00040000,
118+
WS_EX_LAYERED = 0x00080000,
119+
WS_EX_TOPMOST = 0x00000008,
120+
WS_EX_LAYOUTRTL = 0x00400000,
121+
WS_EX_NOINHERITLAYOUT = 0x00100000,
122+
WPF_SETMINPOSITION = 0x0001,
123+
WM_CHOOSEFONT_GETLOGFONT = 0x0400 + 1;
20124
}
21125
}

0 commit comments

Comments
 (0)