@@ -75,6 +75,16 @@ public override void RecalculateKeyViewLoop()
75
75
NSView last = null ;
76
76
Handler ? . RecalculateKeyViewLoop ( ref last ) ;
77
77
}
78
+
79
+ #if MONOMAC
80
+ protected override void Dispose ( bool disposing )
81
+ {
82
+ // See HandleWillClose for details of this
83
+ // This is needed in addition when a window is created but not ever shown.
84
+ Delegate = null ;
85
+ base . Dispose ( disposing ) ;
86
+ }
87
+ #endif
78
88
}
79
89
80
90
public class EtoPanel : NSPanel , IMacControl
@@ -147,6 +157,16 @@ public override void RecalculateKeyViewLoop()
147
157
NSView last = null ;
148
158
Handler ? . RecalculateKeyViewLoop ( ref last ) ;
149
159
}
160
+
161
+ #if MONOMAC
162
+ protected override void Dispose ( bool disposing )
163
+ {
164
+ // See HandleWillClose for details of this
165
+ // This is needed in addition when a window is created but not ever shown.
166
+ Delegate = null ;
167
+ base . Dispose ( disposing ) ;
168
+ }
169
+ #endif
150
170
}
151
171
152
172
class EtoContentView : MacPanelView
@@ -313,7 +333,17 @@ static void HandleWillClose(object sender, EventArgs e)
313
333
return ;
314
334
handler . IsClosing = true ;
315
335
if ( ApplicationHandler . Instance . ShouldCloseForm ( handler . Widget , true ) )
336
+ {
316
337
handler . Callback . OnClosed ( handler . Widget , EventArgs . Empty ) ;
338
+ #if MONOMAC
339
+ // AppKit still calls some delegate methods on the window after closing a form (e.g. WillReturnFieldEditor),
340
+ // causing exceptions trying to recreate the delegate if it has been garbage collected.
341
+ // This is because MonoMac doesn't use ref counting to determine when objects can be GC'd like MacOS.
342
+ // We avoid this problem by clearing out the delegate after the window is disposed.
343
+ // In Eto, we don't expect any events to be called after that point anyway.
344
+ handler . Control . Delegate = null ;
345
+ #endif
346
+ }
317
347
handler . IsClosing = false ;
318
348
}
319
349
@@ -411,6 +441,7 @@ public override void AttachEvent(string id)
411
441
}
412
442
}
413
443
} ) ;
444
+ HandleEvent ( Window . LocationChangedEvent ) ;
414
445
}
415
446
break ;
416
447
case Window . LocationChangedEvent :
@@ -483,8 +514,8 @@ static void HandleWillMove(object sender, EventArgs e)
483
514
var newLocation = Point . Round ( Mouse . Position - moveOffset ) ;
484
515
if ( handler . oldLocation != newLocation )
485
516
{
486
- handler . Callback . OnLocationChanged ( handler . Widget , EventArgs . Empty ) ;
487
517
handler . oldLocation = newLocation ;
518
+ handler . Callback . OnLocationChanged ( handler . Widget , EventArgs . Empty ) ;
488
519
}
489
520
// check for mouse up event
490
521
@@ -522,13 +553,9 @@ protected virtual void ConfigureWindow()
522
553
Control . ShouldZoom = HandleShouldZoom ;
523
554
Control . WillMiniaturize += HandleWillMiniaturize ;
524
555
Control . WillResize = HandleWillResize ;
556
+
525
557
#if MONOMAC
526
- // AppKit still calls some delegate methods on the window after closing a form (e.g. WillReturnFieldEditor),
527
- // causing exceptions trying to recreate the delegate if it has been garbage collected.
528
- // This is because MonoMac doesn't use ref counting to determine when objects can be GC'd like MacOS.
529
- // We avoid this problem by clearing out the delegate after the window is closed.
530
- // In Eto, we don't expect any events to be called after that point anyway.
531
- Widget . Closed += ( sender , e ) => Application . Instance . AsyncInvoke ( ( ) => Control . Delegate = null ) ;
558
+ HandleEvent ( Window . ClosedEvent ) ;
532
559
#endif
533
560
}
534
561
0 commit comments