OS.InstallEventHandler (appTarget, fontPanelCallback.getAddress(), mask.length / 2, mask, 0, outRef);
OS.InstallEventHandler (appTarget, fontPanelCallbackAddress, mask.length / 2, mask, 0, outRef);
public FontData open () {	FontSelectionQDStyle qdStyle = new FontSelectionQDStyle();	qdStyle.version = OS.kFontSelectionQDStyleVersionZero;	// NEEDS WORK - color not supported in native dialog for Carbon	if (rgb != null) {		qdStyle.hasColor = true;		qdStyle.color_red = (short)(rgb.red * 257);		qdStyle.color_green = (short)(rgb.green * 257);		qdStyle.color_blue = (short)(rgb.blue * 257);	}	if (fontData != null) {		String familyName = fontData.name;		int[] font = new int[1];		byte[] buffer = familyName.getBytes();		if (OS.ATSUFindFontFromName(buffer, buffer.length, OS.kFontFamilyName, OS.kFontNoPlatformCode, OS.kFontNoScriptCode, OS.kFontNoLanguageCode, font) == OS.noErr) {			short[] family = new short[1];			OS.FMGetFontFamilyInstanceFromFont(font[0], family, new short[1]);					qdStyle.instance_fontFamily = family[0];		}		int style = fontData.style;		int fontStyle = OS.normal;		if ((style & SWT.BOLD) != 0) fontStyle |= OS.bold;		if ((style & SWT.ITALIC) != 0) fontStyle |= OS.italic;		qdStyle.instance_fontStyle = (short)fontStyle;		qdStyle.size = (short)fontData.height;	}	int ptr = OS.NewPtr(FontSelectionQDStyle.sizeof);	OS.memcpy (ptr, qdStyle, FontSelectionQDStyle.sizeof);	OS.SetFontInfoForSelection(OS.kFontSelectionQDType, 1, ptr, 0);	OS.DisposePtr (ptr);	int[] mask = new int[] {		OS.kEventClassFont, OS.kEventFontSelection,		OS.kEventClassFont, OS.kEventFontPanelClosed,	};	Callback fontPanelCallback = new Callback (this, "fontProc", 3);	int appTarget = OS.GetApplicationEventTarget ();	int [] outRef = new int [1];	OS.InstallEventHandler (appTarget, fontPanelCallback.getAddress(), mask.length / 2, mask, 0, outRef);	fontData = null;	rgb = null;	open = true;	/*	* Feature in the Macintosh.  The Fonts window is not modal and it cannot	* be accessed through direct API.  The fix is to figure out the Fonts	* window by checking all available windows and set its modality	* explicitily.	*/	int count = 0;	int window = OS.GetPreviousWindow (0);	while (window != 0) {		count++;		window = OS.GetPreviousWindow (window);	}	int [] windows = new int [count];	boolean[] visible = new boolean [count];	count = 0;	window = OS.GetPreviousWindow (0);	while (window != 0) {		windows [count] = window;		visible [count] = OS.IsWindowVisible (window);		count++;		window = OS.GetPreviousWindow (window);	}	OS.FPShowHideFontPanel ();	int fontsWindow = 0;	window = OS.GetPreviousWindow (0);	while (window != 0 && fontsWindow == 0) {		if (OS.IsWindowVisible (window)) {			boolean found = false;			for (int i = 0; i < windows.length; i++) {				if (windows [i] == window) {					found = true;					if (!visible [i]) {						fontsWindow = window;						break;											}				}			}			if (!found) {				fontsWindow = window;				break;			}		}		window = OS.GetPreviousWindow (window);	}	if (fontsWindow != 0) {		int inModalKind = OS.kWindowModalityNone;		if ((style & SWT.PRIMARY_MODAL) != 0) inModalKind = OS.kWindowModalityWindowModal;		if ((style & SWT.APPLICATION_MODAL) != 0) inModalKind = OS.kWindowModalityAppModal;		if ((style & SWT.SYSTEM_MODAL) != 0) inModalKind = OS.kWindowModalitySystemModal;		if (inModalKind != OS.kWindowModalityNone) {			int inUnavailableWindow = 0;			if (parent != null) inUnavailableWindow = OS.GetControlOwner (parent.handle);			OS.SetWindowModality (fontsWindow, inModalKind, inUnavailableWindow);			OS.SelectWindow (fontsWindow);		}	}	Display display = parent.display;	while (!parent.isDisposed() && open) {		if (!display.readAndDispatch ()) display.sleep ();	}	OS.RemoveEventHandler (outRef [0]);	fontPanelCallback.dispose ();	return fontData;}