Bug 446930: NPE in Control.windowProc (widget disposed in Link MouseUp handler)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
index 11b61a8..2aa73d7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -12,8 +12,8 @@
 
 
 import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
 import org.eclipse.swt.internal.win32.*;
+import org.eclipse.swt.widgets.*;
 
 /**
  * Instances of this class allow the user to select
@@ -349,12 +349,13 @@
 			pd.hDevNames = hMem;
 		}
 	}
+	Display display = parent.getDisplay();
 	if (!success) {
 		/* Initialize PRINTDLG fields, including DEVMODE, for the default printer. */
 		pd.Flags = OS.PD_RETURNDEFAULT;
-		getParent ().getDisplay ().sendPreExternalEventDispatchEvent ();
+		display.sendPreExternalEventDispatchEvent ();
 		success = OS.PrintDlg(pd);
-		getParent ().getDisplay ().sendPostExternalEventDispatchEvent ();
+		display.sendPostExternalEventDispatchEvent ();
 		if (success) {
 			if (pd.hDevNames != 0) {
 				OS.GlobalFree(pd.hDevNames);
@@ -434,7 +435,6 @@
 		pd.nFromPage = (short) Math.min (0xFFFF, Math.max (1, printerData.startPage));
 		pd.nToPage = (short) Math.min (0xFFFF, Math.max (1, printerData.endPage));
 	
-		Display display = parent.getDisplay();
 		Shell [] shells = display.getShells();
 		if ((getStyle() & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
 			for (int i=0; i<shells.length; i++) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT WebKit/win32/org/eclipse/swt/browser/WebUIDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT WebKit/win32/org/eclipse/swt/browser/WebUIDelegate.java
index fc7a99e..f94b096 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT WebKit/win32/org/eclipse/swt/browser/WebUIDelegate.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT WebKit/win32/org/eclipse/swt/browser/WebUIDelegate.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 IBM Corporation and others.
+ * Copyright (c) 2010, 2014 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -240,9 +240,10 @@
 	PRINTDLG pd = new PRINTDLG ();
 	pd.lStructSize = PRINTDLG.sizeof;
 	pd.Flags = OS.PD_RETURNDC;
-	browser.getDisplay ().sendPreExternalEventDispatchEvent ();
+	Display display = browser.getDisplay ();
+	display.sendPreExternalEventDispatchEvent ();
 	boolean success = OS.PrintDlg (pd);
-	browser.getDisplay ().sendPostExternalEventDispatchEvent ();
+	display.sendPostExternalEventDispatchEvent ();
 	if (!success) return COM.S_OK;
 	long /*int*/ printDC = pd.hDC;
 
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
index 74621c6..83b5a23 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
@@ -4618,6 +4618,7 @@
 abstract long /*int*/ windowProc ();
 
 long /*int*/ windowProc (long /*int*/ hwnd, int msg, long /*int*/ wParam, long /*int*/ lParam) {
+	Display display = this.display;
 	LRESULT result = null;
 	switch (msg) {
 		case OS.WM_ACTIVATE:			result = WM_ACTIVATE (wParam, lParam); break;
@@ -4718,7 +4719,7 @@
 		case OS.WM_XBUTTONUP:			result = WM_XBUTTONUP (wParam, lParam); break;
 	}
 	if (result != null) return result.value;
-	Display display = this.display;
+	// widget could be disposed at this point
 	display.sendPreExternalEventDispatchEvent ();
 	try {
 		return callWindowProc (hwnd, msg, wParam, lParam);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java
index 5128255..ba494ba 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -11,9 +11,9 @@
 package org.eclipse.swt.widgets;
 
 
-import org.eclipse.swt.internal.win32.*;
 import org.eclipse.swt.*;
 import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.win32.*;
 
 /**
  * Instances of this class allow the user to select a font
@@ -218,9 +218,8 @@
 	
 	/* Make the parent shell be temporary modal */
 	Dialog oldModal = null;
-	Display display = null;
+	Display display = parent.getDisplay ();
 	if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
-		display = parent.getDisplay ();
 		oldModal = display.getModalDialog ();
 		display.setModalDialog (this);
 	}