Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
68 changes: 35 additions & 33 deletions mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5213,44 +5213,46 @@ private void WmPaint (ref Message m) {
if (paint_event == null)
return;

DoubleBuffer current_buffer = null;
if (UseDoubleBuffering) {
current_buffer = GetBackBuffer ();
// This optimization doesn't work when the area is invalidated
// during a paint operation because finishing the paint operation
// clears the invalidated region and then this thing keeps the new
// invalidate from working. To re-enable this, we would need a
// mechanism to allow for nested invalidates (see bug #328681)
//if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
// // Just blit the previous image
// current_buffer.Blit (paint_event);
// XplatUI.PaintEventEnd (ref m, handle, true);
// return;
//}
current_buffer.Start (paint_event);
}
// If using OptimizedDoubleBuffer, ensure the clip region gets set
if (GetStyle (ControlStyles.OptimizedDoubleBuffer))
paint_event.Graphics.SetClip (Rectangle.Intersect (paint_event.ClipRectangle, this.ClientRectangle));
try {
DoubleBuffer current_buffer = null;
if (UseDoubleBuffering) {
current_buffer = GetBackBuffer ();
// This optimization doesn't work when the area is invalidated
// during a paint operation because finishing the paint operation
// clears the invalidated region and then this thing keeps the new
// invalidate from working. To re-enable this, we would need a
// mechanism to allow for nested invalidates (see bug #328681)
//if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
// // Just blit the previous image
// current_buffer.Blit (paint_event);
// XplatUI.PaintEventEnd (ref m, handle, true);
// return;
//}
current_buffer.Start (paint_event);
}
// If using OptimizedDoubleBuffer, ensure the clip region gets set
if (GetStyle (ControlStyles.OptimizedDoubleBuffer))
paint_event.Graphics.SetClip (Rectangle.Intersect (paint_event.ClipRectangle, this.ClientRectangle));

if (!GetStyle(ControlStyles.Opaque)) {
OnPaintBackground (paint_event);
}
if (!GetStyle(ControlStyles.Opaque)) {
OnPaintBackground (paint_event);
}

// Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
OnPaintBackgroundInternal (paint_event);
// Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
OnPaintBackgroundInternal (paint_event);

OnPaintInternal(paint_event);
if (!paint_event.Handled) {
OnPaint (paint_event);
}
OnPaintInternal(paint_event);
if (!paint_event.Handled) {
OnPaint (paint_event);
}

if (current_buffer != null) {
current_buffer.End (paint_event);
if (current_buffer != null) {
current_buffer.End (paint_event);
}
}
finally {
XplatUI.PaintEventEnd (ref m, handle, true, paint_event);
}


XplatUI.PaintEventEnd (ref m, handle, true, paint_event);
}

private void WmEraseBackground (ref Message m) {
Expand Down
2 changes: 2 additions & 0 deletions mcs/class/System.Windows.Forms/System.Windows.Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,8 @@ protected override void SetVisibleCore(bool value)
if (value && IsMdiChild){
PerformLayout ();
ThemeEngine.Current.ManagedWindowSetButtonLocations (window_manager);
if (ActivateOnShow && MdiParent != null)
MdiParent.ActivateMdiChild (this);
}

// Shown event is only called once, the first time the form is made visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void Dispose() {
}
client_window = IntPtr.Zero;
whole_window = IntPtr.Zero;
zombie = false;
zombie = true;
for (int i = 0; i < marshal_free_list.Count; i++) {
Marshal.FreeHGlobal((IntPtr)marshal_free_list[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,31 +510,6 @@ private void CheckTimers (DateTime now) {
}
}

private void WaitForHwndMessage (Hwnd hwnd, Msg message) {
MSG msg = new MSG ();

bool done = false;
do {
if (GetMessage(null, ref msg, IntPtr.Zero, 0, 0)) {
if ((Msg)msg.message == Msg.WM_QUIT) {
PostQuitMessage (0);
done = true;
}
else {
if (msg.hwnd == hwnd.Handle) {
if ((Msg)msg.message == message)
break;
else if ((Msg)msg.message == Msg.WM_DESTROY)
done = true;
}

TranslateMessage (ref msg);
DispatchMessage (ref msg);
}
}
} while (!done);
}

private void SendParentNotify(IntPtr child, Msg cause, int x, int y) {
Hwnd hwnd;

Expand Down Expand Up @@ -1056,7 +1031,6 @@ internal override IntPtr CreateWindow(CreateParams cp) {
}
}
ShowWindow (WindowHandle);
WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
}
HIViewSetVisible (WholeWindow, true);
HIViewSetVisible (ClientWindow, true);
Expand All @@ -1072,7 +1046,7 @@ internal override IntPtr CreateWindow(CreateParams cp) {
SetWindowState(hwnd.Handle, FormWindowState.Maximized);
}

return hwnd.Handle;
return hwnd.zombie ? IntPtr.Zero : hwnd.Handle;
}

internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
Expand Down Expand Up @@ -1230,7 +1204,7 @@ internal override void DestroyWindow(IntPtr handle) {

hwnd = Hwnd.ObjectFromHandle(handle);

if (hwnd == null) {
if (hwnd == null || hwnd.zombie) {
return;
}

Expand All @@ -1241,11 +1215,13 @@ internal override void DestroyWindow(IntPtr handle) {
ArrayList windows = new ArrayList ();

AccumulateDestroyedHandles (Control.ControlNativeWindow.ControlFromHandle(hwnd.Handle), windows);

windows.Add (hwnd);

foreach (Hwnd h in windows) {
SendMessage (h.Handle, Msg.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
h.zombie = true;
h.expose_pending = h.nc_expose_pending = false;
h.Dispose();
}

// TODO: This is crashing swf-messageboxes
Expand All @@ -1256,9 +1232,11 @@ internal override void DestroyWindow(IntPtr handle) {
CFRelease (hwnd.client_window);
*/

if (WindowMapping [hwnd.Handle] != null) {
DisposeWindow ((IntPtr)(WindowMapping [hwnd.Handle]));
WindowMapping.Remove (hwnd.Handle);
if (WindowMapping [handle] != null) {
IntPtr window_handle = (IntPtr)(WindowMapping [handle]);
DisposeWindow (window_handle);
WindowMapping.Remove (handle);
HandleMapping.Remove (window_handle);
}
}

Expand Down Expand Up @@ -1395,6 +1373,11 @@ internal override bool GetMessage(object queue_id, ref MSG msg, IntPtr hWnd, int
goto loop;
} else {
msg = (MSG)queueobj;
if (msg.hwnd != IntPtr.Zero && msg.hwnd != FosterParent) {
Hwnd hwnd = Hwnd.ObjectFromHandle(msg.hwnd);
if (hwnd == null || hwnd.zombie)
goto loop;
}
}
return GetMessageResult;
}
Expand Down Expand Up @@ -1597,6 +1580,7 @@ internal override bool PeekMessage(Object queue_id, ref MSG msg, IntPtr hWnd, in
ReleaseEvent (evtRef);
}

loop:
lock (queuelock) {
if (MessageQueue.Count <= 0) {
return false;
Expand All @@ -1612,6 +1596,11 @@ internal override bool PeekMessage(Object queue_id, ref MSG msg, IntPtr hWnd, in
return false;
}
msg = (MSG)queueobj;
if (msg.hwnd != IntPtr.Zero && msg.hwnd != FosterParent) {
Hwnd hwnd = Hwnd.ObjectFromHandle(msg.hwnd);
if (hwnd == null || hwnd.zombie)
goto loop;
}
return true;
}
}
Expand Down Expand Up @@ -1736,16 +1725,30 @@ internal override void SetCursorPos(IntPtr handle, int x, int y) {
}

internal override void SetFocus(IntPtr handle) {
if (FocusWindow != IntPtr.Zero) {
PostMessage(FocusWindow, Msg.WM_KILLFOCUS, handle, IntPtr.Zero);
}
PostMessage(handle, Msg.WM_SETFOCUS, FocusWindow, IntPtr.Zero);
if (FocusWindow == handle)
return;

IntPtr previous_focus = FocusWindow;
FocusWindow = handle;

if (previous_focus != IntPtr.Zero) {
SendMessage(previous_focus, Msg.WM_KILLFOCUS, handle, IntPtr.Zero);
// Focus was changed from inside WM_KILLFOCUS
if (FocusWindow != handle)
return;
}

if (handle != IntPtr.Zero) {
SendMessage(handle, Msg.WM_SETFOCUS, FocusWindow, IntPtr.Zero);
}
}

internal override void SetIcon(IntPtr handle, Icon icon) {
Hwnd hwnd = Hwnd.ObjectFromHandle (handle);

if (hwnd == null || hwnd.zombie)
return;

// FIXME: we need to map the icon for active window switches
if (WindowMapping [hwnd.Handle] != null) {
if (icon == null) {
Expand Down Expand Up @@ -1832,6 +1835,10 @@ internal override bool SetOwner(IntPtr hWnd, IntPtr hWndOwner) {

internal override bool SetVisible(IntPtr handle, bool visible, bool activate) {
Hwnd hwnd = Hwnd.ObjectFromHandle (handle);

if (hwnd == null || hwnd.zombie)
return false;

object window = WindowMapping [hwnd.Handle];
if (window != null)
if (visible)
Expand Down Expand Up @@ -1982,6 +1989,10 @@ internal override void SetWindowState(IntPtr handle, FormWindowState state) {

internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
Hwnd hwnd = Hwnd.ObjectFromHandle (handle);

if (hwnd == null || hwnd.zombie)
return;

SetHwndStyles(hwnd, cp);

if (WindowMapping [hwnd.Handle] != null) {
Expand Down Expand Up @@ -2205,7 +2216,12 @@ internal override Size FrameBorderSize {
}
}

internal override Size IconSize { get{ throw new NotImplementedException(); } }
internal override Size IconSize {
get {
return new Size (32, 32);
}
}

internal override Size MaxWindowTrackSize { get{ throw new NotImplementedException(); } }
internal override bool MenuAccessKeysUnderlined {
get {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void Bug694908 ()
}
// with bug 694908 we don't come here. Instead NUnit exits.
Assert.IsTrue (CrashingForm.HasHandledException);

Application.ThreadException -= CrashingForm.HandleThreadException;
}

class CrashingForm: Form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void PubPropTest ()

Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "#30");
Assert.IsFalse (l.Focused, "#31");
Assert.AreEqual (FontFamily.GenericSansSerif, l.Font.FontFamily, "#32");
Assert.AreEqual (SystemFonts.DefaultFont, l.Font, "#32");
Assert.AreEqual (SystemColors.ControlText, l.ForeColor, "#33");

Assert.IsFalse (l.HasChildren, "#35");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected virtual void TearDown () {
if (c > 0) {
Console.WriteLine ("HEY! You created " + c.ToString () + " form(s) and you didn't dispose of them!");
Console.WriteLine ("Please modify your test to shut me up.");
Console.WriteLine ("Test: " + NUnit.Framework.TestContext.CurrentContext.Test.FullName);
}
for (int i = Application.OpenForms.Count - 1; i >= 0; i--) {
Application.OpenForms[i].Dispose ();
Expand Down