diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java | 1110 |
1 files changed, 673 insertions, 437 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index 84c4a40b40..d2ef22338b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.swt.widgets; +import java.lang.Runtime.*; import java.util.*; import java.util.function.*; @@ -110,7 +111,9 @@ public class Display extends Device { enum APPEARANCE { Dark, Light, } - APPEARANCE appAppearance = null; + APPEARANCE appAppearance; + /* System property to be set for SWT application to use the system's theme */ + static final String USE_SYSTEM_THEME = "org.eclipse.swt.display.useSystemTheme"; /* Windows and Events */ Event [] eventQueue; @@ -173,7 +176,7 @@ public class Display extends Device { boolean escAsAcceleratorPresent = false; NSApplication application; - long /*int*/ applicationClass; + long applicationClass; NSImage dockImage; boolean isEmbedded; static boolean launched = false; @@ -191,17 +194,15 @@ public class Display extends Device { int[] screenID = new int[32]; NSPoint[] screenCascade = new NSPoint[32]; - long /*int*/ runLoopObserver; + long runLoopObserver; Callback observerCallback; boolean lockCursor = true; static final String LOCK_CURSOR = "org.eclipse.swt.internal.lockCursor"; //$NON-NLS-1$ - long /*int*/ oldCursorSetProc; + long oldCursorSetProc; Callback cursorSetCallback; Combo currentCombo; - boolean mozillaRunning; - static final String MOZILLA_RUNNING = "org.eclipse.swt.internal.mozillaRunning"; //$NON-NLS-1$ // the following Callbacks are never freed static Callback windowCallback2, windowCallback3, windowCallback4, windowCallback5, windowCallback6; @@ -231,9 +232,9 @@ public class Display extends Device { Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1]; /* System Colors */ - double /*float*/ [][] colors; - double /*float*/ [] alternateSelectedControlTextColor, selectedControlTextColor; - double /*float*/ [] alternateSelectedControlColor, secondarySelectedControlColor; + double [][] colors; + double [] alternateSelectedControlTextColor, selectedControlTextColor; + private double [] alternateSelectedControlColor, secondarySelectedControlColor; /* Key Mappings. */ static int [] [] KeyTable = { @@ -376,6 +377,10 @@ public class Display extends Device { }; } + static { + configureSystemOptions (); + } + /* * TEMPORARY CODE. */ @@ -559,7 +564,7 @@ void addPopup (Menu menu) { void addSkinnableWidget (Widget widget) { if (skinCount >= skinList.length) { - Widget[] newSkinWidgets = new Widget [skinList.length + GROW_SIZE]; + Widget[] newSkinWidgets = new Widget [(skinList.length + 1) * 3 / 2]; System.arraycopy (skinList, 0, newSkinWidgets, 0, skinList.length); skinList = newSkinWidgets; } @@ -568,7 +573,7 @@ void addSkinnableWidget (Widget widget) { void addWidget (NSObject view, Widget widget) { if (view == null) return; - long /*int*/ ivar = OS.object_setInstanceVariable (view.id, SWT_OBJECT, widget.jniRef); + long ivar = OS.object_setInstanceVariable (view.id, SWT_OBJECT, widget.jniRef); if (ivar == 0) { if (dynamicObjectMap == null) { @@ -624,18 +629,32 @@ public void beep () { void cascadeWindow (NSWindow window, NSScreen screen) { NSDictionary dictionary = screen.deviceDescription(); - int screenNumber = new NSNumber(dictionary.objectForKey(NSString.stringWith("NSScreenNumber")).id).intValue(); - int index = 0; - while (screenID[index] != 0 && screenID[index] != screenNumber) index++; - screenID[index] = screenNumber; - NSPoint cascade = screenCascade[index]; - if (cascade == null) { - NSRect frame = screen.frame(); - cascade = new NSPoint(); - cascade.x = frame.x; - cascade.y = frame.y + frame.height; + if (dictionary != null) { + id screenNumberObject = dictionary.objectForKey(NSString.stringWith("NSScreenNumber")); + if (screenNumberObject != null) { + int screenNumber = new NSNumber(screenNumberObject.id).intValue(); + int index = 0; + while (screenID[index] != 0 && screenID[index] != screenNumber) index++; + screenID[index] = screenNumber; + NSPoint cascade = screenCascade[index]; + if (cascade == null) { + NSRect frame = screen.frame(); + cascade = new NSPoint(); + cascade.x = frame.x; + cascade.y = frame.y + frame.height; + } + screenCascade[index] = window.cascadeTopLeftFromPoint(cascade); + return; + } } - screenCascade[index] = window.cascadeTopLeftFromPoint(cascade); + /* + * Handle any unexpected cases when dictionary or screenNumberObject may be null. + */ + NSRect frame = screen.frame(); + NSPoint cascade = new NSPoint(); + cascade.x = frame.x; + cascade.y = frame.y + frame.height; + window.cascadeTopLeftFromPoint(cascade); } @Override @@ -761,7 +780,7 @@ static String convertToLf(String text) { /* The string is formatted with CR/LF. * Create a new string with the LF line delimiter. */ i = 0; - StringBuffer result = new StringBuffer (); + StringBuilder result = new StringBuilder (); while (i < length) { int j = text.indexOf (Cr, i); if (j == -1) j = length; @@ -816,6 +835,78 @@ public void close () { if (event.doit) dispose (); } +static private void configureSystemOption (String option, boolean value) { + NSDictionary dictionary = NSDictionary.dictionaryWithObject (NSNumber.numberWithBool (value), NSString.stringWith (option)); + NSUserDefaults.standardUserDefaults ().registerDefaults (dictionary); +} + +static private void configureSystemOptions () { + /* + * Most native applications are layer backed. This means that everything + * painted by the application is cached for performance reasons, such as + * not having to repaint everything when scrolling. + * + * The condition for default layer backing is being compatible with + * responsive scrolling, and SWT is not compatible because it handles + * 'scrollWheel:' and 'drawRect:' in 'NSScrollView'. Making SWT compatible + * is not trivial. + * + * Requesting layer directly is possible, but I decided that it's better to + * just enable system option for older macOS, because it's what happens when + * using newer Java anyway. + * + * The workaround is to enable root layer backing. macOS 10.14 and 10.15 + * already enable this option if app was linked with sdk 10.14+ and + * macOS 11 always enables it regardless of sdk. The option is force + * enabled here in case SWT runs with java/launcher linked with older sdk. + */ + if (!OS.isBigSurOrLater ()) { + configureSystemOption ("NSViewAllowsRootLayerBacking", true); + } + + /* + * Starting with macOS 11, layer backing is always enabled. That's fine. + * What is not fine however is that macOS uses "automatic" image format for + * it. This means that instead of actual rendering, macOS's GC only remembers + * the operations performed. This causes macOS to ignore clip rect and paint + * entire visible rect whenever something changes, and that's a lot of + * painting. Example: Table will now repaint all visible items when a single + * item is selected/deselected. In case of owner drawn Table, this makes + * things a lot slower. The workaround is to disable the "automatic" image + * format. + */ + if (OS.isBigSurOrLater ()) { + configureSystemOption ("NSViewUsesAutomaticLayerBackingStores", false); + } + + /* + * Bug 578171: There is new code in macOS 12 that remembers which + * Shell was active before menu popup was shown and tries to + * re-activate after menu popup is closed. Unfortunately there is a + * bug in this code: if window list changes, it activates a wrong + * Shell. + * + * This is a bug on its own, but worse yet, this causes a JVM crash + * because activating a new Shell causes menu bar to reset its + * internal data, which is unexpected to the macOS's menu tracking + * loop. + * + * Both bugs are bugs of macOS itself. The workaround is to disable + * the new macOS 12 behavior. + * + * The condition should be for (macOS >= 12), but it's not possible + * to reliably distinguish 11 from 12, see comment for OS.VERSION. + * That's fine: older macOS don't know this setting and will not + * check for it anyway. + */ + if (OS.isBigSurOrLater ()) { + // The name of the option is misleading. What it really means + // is whether '-[NSMenuWindowManagerWindow _setVisible:]' shall + // save/restore current key window or not. + configureSystemOption ("NSMenuWindowManagerWindowShouldSetVisible", true); + } +} + /** * Creates the device in the operating system. If the device * does not have a handle, this method may do nothing depending @@ -839,9 +930,8 @@ protected void create (DeviceData data) { } void createDisplay (DeviceData data) { - if (OS.VERSION < 0x1050) { - System.out.println ("***WARNING: SWT requires MacOS X version " + 10 + "." + 5 + " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - System.out.println ("***WARNING: Detected: " + Integer.toHexString((OS.VERSION & 0xFF00) >> 8) + "." + Integer.toHexString((OS.VERSION & 0xF0) >> 4) + "." + Integer.toHexString(OS.VERSION & 0xF)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (OS.VERSION < OS.VERSION (10, 10, 0)) { + System.out.println ("***WARNING: SWT requires MacOS X version 10.10 or greater"); //$NON-NLS-1$ error(SWT.ERROR_NOT_IMPLEMENTED); } @@ -876,14 +966,8 @@ void createDisplay (DeviceData data) { int [] psn = new int [2]; if (OS.GetCurrentProcess (psn) == OS.noErr) { int pid = OS.getpid (); - long /*int*/ ptr = getApplicationName().UTF8String(); + long ptr = getApplicationName().UTF8String(); if (ptr != 0) OS.CPSSetProcessName (psn, ptr); - if (!isBundled ()) { - if (OS.VERSION_MMB >= OS.VERSION_MMB (10, 9, 0)) { - application.setActivationPolicy (OS.NSApplicationActivationPolicyRegular); - NSRunningApplication.currentApplication().activateWithOptions (OS.NSApplicationActivateIgnoringOtherApps); - } - } ptr = C.getenv (ascii ("APP_ICON_" + pid)); if (ptr != 0) { NSString path = NSString.stringWithUTF8String (ptr); @@ -895,21 +979,16 @@ void createDisplay (DeviceData data) { } String className = "SWTApplication"; - long /*int*/ cls; + long cls; if ((cls = OS.objc_lookUpClass (className)) == 0) { Class clazz = getClass(); applicationCallback2 = new Callback(clazz, "applicationProc", 2); - long /*int*/ proc2 = applicationCallback2.getAddress(); - if (proc2 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long proc2 = applicationCallback2.getAddress(); applicationCallback3 = new Callback(clazz, "applicationProc", 3); - long /*int*/ proc3 = applicationCallback3.getAddress(); - if (proc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long proc3 = applicationCallback3.getAddress(); applicationCallback4 = new Callback(clazz, "applicationProc", 4); - long /*int*/ proc4 = applicationCallback4.getAddress(); - if (proc4 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); applicationCallback6 = new Callback(clazz, "applicationProc", 6); - long /*int*/ proc6 = applicationCallback6.getAddress(); - if (proc6 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long proc6 = applicationCallback6.getAddress(); long superClassID = OS.object_getClass(application.id); if (new NSObject(superClassID).className().getString().equals("NSKVONotifying_NSApplication")) { /* @@ -935,10 +1014,8 @@ void createDisplay (DeviceData data) { className = "SWTApplicationDelegate"; if (OS.objc_lookUpClass (className) == 0) { - long /*int*/ appProc3 = applicationCallback3.getAddress(); - if (appProc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - long /*int*/ appProc4 = applicationCallback4.getAddress(); - if (appProc4 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long appProc3 = applicationCallback3.getAddress(); + long appProc4 = applicationCallback4.getAddress(); cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); OS.class_addMethod(cls, OS.sel_applicationWillFinishLaunching_, appProc3, "@:@"); OS.class_addMethod(cls, OS.sel_terminate_, appProc3, "@:@"); @@ -947,6 +1024,7 @@ void createDisplay (DeviceData data) { OS.class_addMethod(cls, OS.sel_hide_, appProc3, "@:@"); OS.class_addMethod(cls, OS.sel_unhideAllApplications_, appProc3, "@:@"); OS.class_addMethod(cls, OS.sel_applicationDidBecomeActive_, appProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_applicationDidFinishLaunching_, appProc3, "@:@"); OS.class_addMethod(cls, OS.sel_applicationDidResignActive_, appProc3, "@:@"); OS.class_addMethod(cls, OS.sel_applicationDockMenu_, appProc3, "@:@"); OS.class_addMethod(cls, OS.sel_application_openFile_, appProc4, "@:@@"); @@ -979,13 +1057,13 @@ void createMainMenu () { appleMenu.initWithTitle(emptyStr); OS.objc_msgSend(application.id, OS.sel_registerName("setAppleMenu:"), appleMenu.id); - title = NSString.stringWith(SWT.getMessage("About") + " " + appName); + title = NSString.stringWith(SWT.getMessage("SWT_About") + " " + appName); menuItem = appleMenu.addItemWithTitle(title, OS.sel_orderFrontStandardAboutPanel_, emptyStr); menuItem.setTarget(applicationDelegate); appleMenu.addItem(NSMenuItem.separatorItem()); - title = NSString.stringWith(SWT.getMessage("Preferences...")); + title = NSString.stringWith(SWT.getMessage("SWT_Preferences")); menuItem = appleMenu.addItemWithTitle(title, 0, NSString.stringWith(",")); /* @@ -996,7 +1074,7 @@ void createMainMenu () { appleMenu.addItem(NSMenuItem.separatorItem()); - title = NSString.stringWith(SWT.getMessage("Services")); + title = NSString.stringWith(SWT.getMessage("SWT_Services")); menuItem = appleMenu.addItemWithTitle(title, 0, emptyStr); NSMenu servicesMenu = (NSMenu)new NSMenu().alloc(); servicesMenu.initWithTitle(emptyStr); @@ -1006,22 +1084,22 @@ void createMainMenu () { appleMenu.addItem(NSMenuItem.separatorItem()); - title = NSString.stringWith(SWT.getMessage("Hide") + " " + appName); + title = NSString.stringWith(SWT.getMessage("SWT_Hide") + " " + appName); menuItem = appleMenu.addItemWithTitle(title, OS.sel_hide_, NSString.stringWith("h")); menuItem.setTarget(applicationDelegate); - title = NSString.stringWith(SWT.getMessage("Hide Others")); + title = NSString.stringWith(SWT.getMessage("SWT_HideOthers")); menuItem = appleMenu.addItemWithTitle(title, OS.sel_hideOtherApplications_, NSString.stringWith("h")); menuItem.setKeyEquivalentModifierMask(OS.NSCommandKeyMask | OS.NSAlternateKeyMask); menuItem.setTarget(applicationDelegate); - title = NSString.stringWith(SWT.getMessage("Show All")); + title = NSString.stringWith(SWT.getMessage("SWT_ShowAll")); menuItem = appleMenu.addItemWithTitle(title, OS.sel_unhideAllApplications_, emptyStr); menuItem.setTarget(applicationDelegate); appleMenu.addItem(NSMenuItem.separatorItem()); - title = NSString.stringWith(SWT.getMessage("Quit") + " " + appName); + title = NSString.stringWith(SWT.getMessage("SWT_Quit") + " " + appName); menuItem = appleMenu.addItemWithTitle(title, OS.sel_applicationShouldTerminate_, NSString.stringWith("q")); menuItem.setTarget(applicationDelegate); @@ -1041,7 +1119,7 @@ NSMutableArray currentTouches() { return currentTouches; } -long /*int*/ cursorSetProc (long /*int*/ id, long /*int*/ sel) { +long cursorSetProc (long id, long sel) { if (lockCursor) { if (currentControl != null) { Cursor cursor = currentControl.findCursor (); @@ -1151,7 +1229,7 @@ boolean filters (int eventType) { * * @noreference This method is not intended to be referenced by clients. */ -public Widget findWidget (long /*int*/ handle) { +public Widget findWidget (long handle) { checkDevice (); return getWidget (handle); } @@ -1180,7 +1258,7 @@ public Widget findWidget (long /*int*/ handle) { * * @since 3.1 */ -public Widget findWidget (long /*int*/ handle, long /*int*/ id) { +public Widget findWidget (long handle, long id) { checkDevice (); return getWidget (handle); } @@ -1204,7 +1282,7 @@ public Widget findWidget (long /*int*/ handle, long /*int*/ id) { * * @since 3.3 */ -public Widget findWidget (Widget widget, long /*int*/ id) { +public Widget findWidget (Widget widget, long id) { checkDevice (); return null; } @@ -1320,14 +1398,14 @@ Rectangle getBounds (NSArray screens) { NSScreen screen = new NSScreen(screens.objectAtIndex(0)); NSRect primaryFrame = screen.frame(); - double /*float*/ minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE; - double /*float*/ minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE; - long /*int*/ count = screens.count(); + double minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE; + double minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE; + long count = screens.count(); for (int i = 0; i < count; i++) { screen = new NSScreen(screens.objectAtIndex(i)); NSRect frame = screen.frame(); - double /*float*/ x1 = frame.x, x2 = frame.x + frame.width; - double /*float*/ y1 = primaryFrame.height - frame.y, y2 = primaryFrame.height - (frame.y + frame.height); + double x1 = frame.x, x2 = frame.x + frame.width; + double y1 = primaryFrame.height - frame.y, y2 = primaryFrame.height - (frame.y + frame.height); if (x1 < minX) minX = x1; if (x2 < minX) minX = x2; if (x1 > maxX) maxX = x1; @@ -1379,7 +1457,7 @@ public Rectangle getClientArea () { NSScreen screen = new NSScreen(screens.objectAtIndex(0)); NSRect frame = screen.frame(); NSRect visibleFrame = screen.visibleFrame(); - double /*float*/ y = frame.height - (visibleFrame.y + visibleFrame.height); + double y = frame.height - (visibleFrame.y + visibleFrame.height); return new Rectangle((int)visibleFrame.x, (int)y, (int)visibleFrame.width, (int)visibleFrame.height); } @@ -1548,7 +1626,7 @@ public int getDismissalAlignment () { */ public int getDoubleClickTime () { checkDevice (); - return OS.GetDblTime () * 1000 / 60; + return (int)(NSEvent.doubleClickInterval() * 1000); } /** @@ -1653,6 +1731,29 @@ public Point [] getIconSizes () { new Point (64, 64), new Point (128, 128)}; } +/** + * Returns <code>true</code> if the current OS theme has a dark appearance, else + * returns <code>false</code>. + * <p> + * Note: This operation is a hint and is not supported on platforms that do not + * have this concept. + * </p> + * <p> + * Note: Windows 10 onwards users can separately configure the theme for OS and + * Application level and this can be read from the Windows registry. Since the + * application needs to honor the application level theme, this API reads the + * Application level theme setting. + * </p> + * + * @return <code>true</code> if the current OS theme has a dark appearance, else + * returns <code>false</code>. + * + * @since 3.112 + */ +public static boolean isSystemDarkTheme () { + return OS.isSystemDarkAppearance(); +} + int getLastEventTime () { NSEvent event = application != null ? application.currentEvent() : null; if (event == null) return 0; @@ -1706,7 +1807,7 @@ public Monitor [] getMonitors () { if (screens == null) return new Monitor[] {}; NSRect primaryFrame = new NSScreen(screens.objectAtIndex(0)).frame(); - int count = (int)/*64*/screens.count(); + int count = (int)screens.count(); Monitor [] monitors = new Monitor [count]; for (int i=0; i<count; i++) { Monitor monitor = new Monitor (); @@ -1777,7 +1878,7 @@ public Shell [] getShells () { checkDevice (); NSArray windows = application.windows(); int index = 0; - Shell [] result = new Shell [(int)/*64*/windows.count()]; + Shell [] result = new Shell [(int)windows.count()]; for (int i = 0; i < result.length; i++) { NSWindow window = new NSWindow(windows.objectAtIndex(i)); Widget widget = getWidget(window.contentView()); @@ -1868,14 +1969,11 @@ Color getWidgetColor (int id) { return null; } -double /*float*/ [] getWidgetColorRGB (int id) { +double [] getWidgetColorRGB (int id) { NSColor color = null; switch (id) { case SWT.COLOR_INFO_FOREGROUND: color = NSColor.blackColor (); break; - case SWT.COLOR_INFO_BACKGROUND: return - OS.VERSION_MMB >= OS.VERSION_MMB (10, 10, 0) - ? new double /*float*/ [] {236/255f, 235/255f, 236/255f, 1} - : new double /*float*/ [] {.984f, .988f, 0.773f, 1}; + case SWT.COLOR_INFO_BACKGROUND: return new double [] {236/255f, 235/255f, 236/255f, 1}; case SWT.COLOR_TITLE_FOREGROUND: color = NSColor.windowFrameTextColor(); break; case SWT.COLOR_TITLE_BACKGROUND: color = NSColor.alternateSelectedControlColor(); break; case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: color = NSColor.selectedControlColor(); break; @@ -1884,26 +1982,29 @@ double /*float*/ [] getWidgetColorRGB (int id) { case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: color = NSColor.secondarySelectedControlColor(); break; case SWT.COLOR_WIDGET_DARK_SHADOW: color = NSColor.controlDarkShadowColor(); break; case SWT.COLOR_WIDGET_NORMAL_SHADOW: - if (OS.VERSION_MMB >= OS.VERSION_MMB (10, 14, 0)) { - return new double /*float*/ [] {159/255f, 159/255f, 159/255f, 1}; + if (OS.VERSION >= OS.VERSION (10, 14, 0)) { + return new double [] {159/255f, 159/255f, 159/255f, 1}; } color = NSColor.controlShadowColor(); break; case SWT.COLOR_WIDGET_LIGHT_SHADOW: - if (OS.VERSION_MMB >= OS.VERSION_MMB (10, 14, 0)) { - return new double /*float*/ [] {232/255f, 232/255f, 232/255f, 1}; + if (OS.VERSION >= OS.VERSION (10, 14, 0)) { + return new double [] {232/255f, 232/255f, 232/255f, 1}; } color = NSColor.controlHighlightColor(); break; case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: color = NSColor.controlLightHighlightColor(); break; case SWT.COLOR_WIDGET_BACKGROUND: - color = OS.VERSION_MMB >= OS.VERSION_MMB (10, 14, 0) ? NSColor.windowBackgroundColor() + color = OS.VERSION >= OS.VERSION (10, 14, 0) ? NSColor.windowBackgroundColor() : NSColor.controlHighlightColor(); break; case SWT.COLOR_WIDGET_FOREGROUND: color = NSColor.controlTextColor(); break; case SWT.COLOR_WIDGET_BORDER: color = NSColor.blackColor (); break; case SWT.COLOR_LIST_FOREGROUND: color = NSColor.textColor(); break; + + case SWT.COLOR_TEXT_DISABLED_BACKGROUND: case SWT.COLOR_LIST_BACKGROUND: color = NSColor.textBackgroundColor(); break; + case SWT.COLOR_LIST_SELECTION_TEXT: color = NSColor.selectedTextColor(); break; case SWT.COLOR_LIST_SELECTION: color = NSColor.selectedTextBackgroundColor(); break; case SWT.COLOR_LINK_FOREGROUND: @@ -1913,21 +2014,27 @@ double /*float*/ [] getWidgetColorRGB (int id) { color = new NSColor(dict.valueForKey(OS.NSForegroundColorAttributeName)); textView.release (); break; - + case SWT.COLOR_WIDGET_DISABLED_FOREGROUND: + if (OS.VERSION >= OS.VERSION (10, 14, 0)) { + color = NSColor.secondarySelectedControlColor(); + } else { + color = NSColor.disabledControlTextColor(); + } + break; } return getNSColorRGB (color); } -double /*float*/ [] getNSColorRGB (NSColor color) { +double [] getNSColorRGB (NSColor color) { if (color == null) return null; NSColorSpace colorSpace = color.colorSpace(); if (colorSpace == null || colorSpace.colorSpaceModel() != OS.NSRGBColorSpaceModel) { color = color.colorUsingColorSpaceName(OS.NSDeviceRGBColorSpace); } if (color == null) return null; - double /*float*/[] components = new double /*float*/[(int)/*64*/color.numberOfComponents()]; + double[] components = new double[(int)color.numberOfComponents()]; color.getComponents(components); - return new double /*float*/ []{components[0], components[1], components[2], components[3]}; + return new double []{components[0], components[1], components[2], components[3]}; } /** @@ -1981,8 +2088,14 @@ public Cursor getSystemCursor (int id) { return cursors [id]; } -NSImage getSystemImageForID(int osType) { - long /*int*/ iconRef[] = new long /*int*/ [1]; +/** + * Gets the system icon using GetIconRefFromTypeInfo() which is deprecated in macOS 10.15. + * For BigSur and later, try to get the system image using NSImage.imageNamed(). + * + * @return NSImage, the returned NSImage instance should be released (for example in Image.destroy()). + */ +static NSImage getSystemImageForID(int osType) { + long iconRef[] = new long [1]; OS.GetIconRefFromTypeInfo(OS.kSystemIconsCreator, osType, 0, 0, 0, iconRef); NSImage nsImage = (NSImage)new NSImage().alloc(); nsImage = nsImage.initWithIconRef(iconRef[0]); @@ -2035,12 +2148,32 @@ public Image getSystemImage (int id) { case SWT.ICON_QUESTION: case SWT.ICON_WORKING: { if (infoImage != null) return infoImage; - NSImage img = getSystemImageForID(OS.kAlertNoteIcon); + NSImage img; + if (OS.isBigSurOrLater()) { + img = NSImage.imageNamed(OS.NSImageNameInfo); + /* + * retain() is required here, as img is used below to create Image object. + * img will be released later in Image.destroy(). + */ + img.retain(); + } else { + img = getSystemImageForID(OS.kAlertNoteIcon); + } return infoImage = Image.cocoa_new (this, SWT.ICON, img); } case SWT.ICON_WARNING: { if (warningImage != null) return warningImage; - NSImage img = getSystemImageForID(OS.kAlertCautionIcon); + NSImage img; + if (OS.isBigSurOrLater()) { + img = NSImage.imageNamed(OS.NSImageNameCaution); + /* + * retain() is required here, as img is used below to create Image object. + * img will be released later in Image.destroy(). + */ + img.retain(); + } else { + img = getSystemImageForID(OS.kAlertCautionIcon); + } return warningImage = Image.cocoa_new (this, SWT.ICON, img); } } @@ -2088,7 +2221,7 @@ public Menu getSystemMenu () { appMenu = new Menu(this, nsAppMenu); // Create menu items that correspond to the NSMenuItems. - long /*int*/ nsCount = nsAppMenu.numberOfItems(); + long nsCount = nsAppMenu.numberOfItems(); for (int j = 0; j < nsCount; j++) { NSMenuItem currMenuItem = nsAppMenu.itemAtIndex(j); new MenuItem(appMenu, currMenuItem); @@ -2135,6 +2268,28 @@ public TaskBar getSystemTaskBar () { } /** + * Used for selection in Table and Tree when in focus. + * @return Returns the system color used for the face of a selected control in a Table or Tree when in focus + */ +double [] getAlternateSelectedControlColor() { + if (alternateSelectedControlColor == null) { + alternateSelectedControlColor = getNSColorRGB(NSColor.alternateSelectedControlColor()); + } + return alternateSelectedControlColor; +} + +/** + * Used for selection in Table and Tree when not in focus. + * @return Returns the system color used for selected controls in non-key views. + */ +double [] getSecondarySelectedControlColor() { + if (secondarySelectedControlColor == null) { + secondarySelectedControlColor = getNSColorRGB(NSColor.secondarySelectedControlColor()); + } + return secondarySelectedControlColor; +} + +/** * Returns the user-interface thread for the receiver. * * @return the receiver's user-interface thread @@ -2165,8 +2320,7 @@ public Thread getThread () { */ public boolean getTouchEnabled() { checkDevice(); - // Gestures are available on OS X 10.5.3 and later. Touch events are only available on 10.6 and later. - return (OS.VERSION > 0x1053); + return true; } int getToolTipTime () { @@ -2175,14 +2329,14 @@ int getToolTipTime () { return 560; } -Widget getWidget (long /*int*/ id) { +Widget getWidget (long id) { return GetWidget (id); } -static Widget GetWidget (long /*int*/ id) { +static Widget GetWidget (long id) { if (id == 0) return null; - long /*int*/ [] jniRef = new long /*int*/ [1]; - long /*int*/ iVar = OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef); + long [] jniRef = new long [1]; + long iVar = OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef); if (iVar == 0) { if (dynamicObjectMap != null) { NSObject key = new NSObject(id); @@ -2202,7 +2356,7 @@ Widget getWidget (NSView view) { boolean hasDefaultButton () { NSArray windows = application.windows(); - long /*int*/ count = windows.count(); + long count = windows.count(); for (int i = 0; i < count; i++) { NSWindow window = new NSWindow(windows.objectAtIndex(i)); if (window.defaultButtonCell() != null) { @@ -2224,6 +2378,13 @@ boolean hasDefaultButton () { @Override protected void init () { super.init (); + + if ("true".equalsIgnoreCase(System.getProperty(USE_SYSTEM_THEME))) { + if (OS.isSystemDarkAppearance()) { + setAppAppearance(APPEARANCE.Dark); + } + } + initClasses (); initColors (); initFonts (); @@ -2238,7 +2399,7 @@ protected void init () { if (currAppDelegate == null) { if (OS.class_JRSAppKitAWT != 0) { - long /*int*/ currDelegatePtr = OS.objc_msgSend(OS.class_JRSAppKitAWT, OS.sel_awtAppDelegate); + long currDelegatePtr = OS.objc_msgSend(OS.class_JRSAppKitAWT, OS.sel_awtAppDelegate); if (currDelegatePtr != 0) { currAppDelegate = new NSObject(currDelegatePtr); currAppDelegate.retain(); @@ -2283,26 +2444,21 @@ protected void init () { if (prefsItem != null) prefsItem.setTag(SWT.ID_PREFERENCES); observerCallback = new Callback (this, "observerProc", 3); //$NON-NLS-1$ - long /*int*/ observerProc = observerCallback.getAddress (); - if (observerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long observerProc = observerCallback.getAddress (); int activities = OS.kCFRunLoopBeforeWaiting; runLoopObserver = OS.CFRunLoopObserverCreate (0, activities, true, 0, observerProc, 0); if (runLoopObserver == 0) error (SWT.ERROR_NO_HANDLES); OS.CFRunLoopAddObserver (OS.CFRunLoopGetCurrent (), runLoopObserver, OS.kCFRunLoopCommonModes ()); // Add AWT Runloop mode for SWT/AWT. - long /*int*/ cls = OS.objc_lookUpClass("JNFRunLoop"); //$NON-NLS-1$ - if (cls != 0) { - long /*int*/ mode = OS.objc_msgSend(cls, OS.sel_javaRunLoopMode); - if (mode != 0) { - OS.CFRunLoopAddObserver (OS.CFRunLoopGetCurrent (), runLoopObserver, mode); - } + NSString javaRunLoopMode = getAwtRunLoopMode(); + if (javaRunLoopMode != null) { + OS.CFRunLoopAddObserver (OS.CFRunLoopGetCurrent (), runLoopObserver, javaRunLoopMode.id); } cursorSetCallback = new Callback(this, "cursorSetProc", 2); - long /*int*/ cursorSetProc = cursorSetCallback.getAddress(); - if (cursorSetProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - long /*int*/ method = OS.class_getInstanceMethod(OS.class_NSCursor, OS.sel_set); + long cursorSetProc = cursorSetCallback.getAddress(); + long method = OS.class_getInstanceMethod(OS.class_NSCursor, OS.sel_set); if (method != 0) oldCursorSetProc = OS.method_setImplementation(method, cursorSetProc); timerDelegate = (SWTWindowDelegate)new SWTWindowDelegate().alloc().init(); @@ -2319,7 +2475,7 @@ protected void init () { textView.release (); NSUserDefaults defaults = NSUserDefaults.standardUserDefaults(); - defaults.setInteger(0, NSString.stringWith(OS.VERSION >= 0x1080 ? "NSScrollAnimationEnabled" : "AppleScrollAnimationEnabled")); + defaults.setInteger(0, NSString.stringWith("NSScrollAnimationEnabled")); id blink = defaults.objectForKey(NSString.stringWith("NSTextInsertionPointBlinkPeriod")); if (blink != null) blinkTime = (int)new NSNumber(blink).integerValue(); if (blinkTime == 0) blinkTime = 560; @@ -2332,7 +2488,53 @@ protected void init () { isPainting = isPainting.initWithCapacity(12); } -void addEventMethods (long /*int*/ cls, long /*int*/ proc2, long /*int*/ proc3, long /*int*/ drawRectProc, long /*int*/ hitTestProc, long /*int*/ needsDisplayInRectProc) { +private static NSString getAwtRunLoopMode() { + // Special run loop mode mode used by AWT enters when it only wants related messages processed. + // The name of this mode is a defacto contract established by the JavaNativeFoundation (JNF) libary. + // It could be accessed via OS.objc_lookUpClass("JNFRunLoop"). + // + // However, in JDK 11.0.12 / 13.0.8 / 15.0.4 / 17 this broke: + // 1) JNF was dropped from JDK: + // https://bugs.openjdk.java.net/browse/JDK-8260616 + // https://bugs.openjdk.java.net/browse/JDK-8261693 + // 2) The contract was broken, since the name was changed from "AWTRunLoopMode" to "jnfRunLoopMode": + // https://www.mail-archive.com/awt-dev@openjdk.java.net/msg17946.html + // + // JNF is also not available in arm64. + // + // In JDK 11.0.14 / 13.0.9 / 15.0.5 / 17.0.0.1 the name was changed back to "AWTRunLoopMode": + // https://bugs.openjdk.java.net/browse/JDK-8270216 + // There is no concept yet to update this: + // https://bugs.openjdk.java.net/browse/JDK-8270211 + // + // Therefore, for now, we follow this approach: + + // 1) If JNFRunLoop is available, we keep using it + long cls = OS.objc_lookUpClass("JNFRunLoop"); + if (cls != 0) { + long mode = OS.objc_msgSend(cls, OS.sel_javaRunLoopMode); + if (mode != 0) { + return new NSString(mode); + } + } + + // 2) If the version is new enough to contain the fix https://bugs.openjdk.java.net/browse/JDK-8270216 + // we are optimistic + Version version = Runtime.version(); + if (version.feature() > 17 // + || version.feature() == 17 && Version.parse("17.0.1").compareToIgnoreOptional(version) <= 0 // + || version.feature() == 11 && Version.parse("11.0.14").compareToIgnoreOptional(version) <= 0 // + || version.feature() == 15 && Version.parse("15.0.5").compareToIgnoreOptional(version) <= 0 // + || version.feature() == 13 && Version.parse("13.0.9").compareToIgnoreOptional(version) <= 0) { + return NSString.stringWith("AWTRunLoopMode"); + } + + // 3) Otherwise, for the few broken Java versions inbetween, we are pessimistic to avoid any immediate + // deadlocks in calling code (although deadlocks will probably still occurr later down the road). + return null; +} + +void addEventMethods (long cls, long proc2, long proc3, long drawRectProc, long hitTestProc, long needsDisplayInRectProc) { if (proc3 != 0) { OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_mouseUp_, proc3, "@:@"); @@ -2361,8 +2563,6 @@ void addEventMethods (long /*int*/ cls, long /*int*/ proc2, long /*int*/ proc3, OS.class_addMethod(cls, OS.sel_touchesMovedWithEvent_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_touchesEndedWithEvent_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_touchesCancelledWithEvent_, proc3, "@:@"); - OS.class_addMethod(cls, OS.sel_beginGestureWithEvent_, proc3, "@:@"); - OS.class_addMethod(cls, OS.sel_endGestureWithEvent_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_swipeWithEvent_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_rotateWithEvent_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_magnifyWithEvent_, proc3, "@:@"); @@ -2387,12 +2587,12 @@ void addEventMethods (long /*int*/ cls, long /*int*/ proc2, long /*int*/ proc3, } } -void addFrameMethods(long /*int*/ cls, long /*int*/ setFrameOriginProc, long /*int*/ setFrameSizeProc) { +void addFrameMethods(long cls, long setFrameOriginProc, long setFrameSizeProc) { OS.class_addMethod(cls, OS.sel_setFrameOrigin_, setFrameOriginProc, "@:{NSPoint}"); OS.class_addMethod(cls, OS.sel_setFrameSize_, setFrameSizeProc, "@:{NSSize}"); } -void addAccessibilityMethods(long /*int*/ cls, long /*int*/ proc2, long /*int*/ proc3, long /*int*/ proc4, long /*int*/ accessibilityHitTestProc) { +void addAccessibilityMethods(long cls, long proc2, long proc3, long proc4, long accessibilityHitTestProc) { OS.class_addMethod(cls, OS.sel_accessibilityActionNames, proc2, "@:"); OS.class_addMethod(cls, OS.sel_accessibilityAttributeNames, proc2, "@:"); OS.class_addMethod(cls, OS.sel_accessibilityParameterizedAttributeNames, proc2, "@:"); @@ -2408,24 +2608,24 @@ void addAccessibilityMethods(long /*int*/ cls, long /*int*/ proc2, long /*int*/ OS.class_addMethod(cls, OS.sel_accessibleHandle, proc2, "@:"); } -long /*int*/ registerCellSubclass(long /*int*/ cellClass, int size, int align, byte[] types) { +long registerCellSubclass(long cellClass, int size, int align, byte[] types) { String cellClassName = OS.class_getName(cellClass); - long /*int*/ cls = OS.objc_allocateClassPair(cellClass, "SWTAccessible" + cellClassName, 0); + long cls = OS.objc_allocateClassPair(cellClass, "SWTAccessible" + cellClassName, 0); OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); OS.objc_registerClassPair(cls); return cls; } -long /*int*/ createWindowSubclass(long /*int*/ baseClass, String newClass, boolean isDynamic) { - long /*int*/ cls = OS.objc_lookUpClass(newClass); +long createWindowSubclass(long baseClass, String newClass, boolean isDynamic) { + long cls = OS.objc_lookUpClass(newClass); if (cls != 0) return cls; cls = OS.objc_allocateClassPair(baseClass, newClass, 0); - long /*int*/ proc3 = windowCallback3.getAddress(); - long /*int*/ proc2 = windowCallback2.getAddress(); - long /*int*/ proc4 = windowCallback4.getAddress(); - long /*int*/ proc6 = windowCallback6.getAddress(); - long /*int*/ view_stringForToolTip_point_userDataProc = OS.CALLBACK_view_stringForToolTip_point_userData_(proc6); - long /*int*/ accessibilityHitTestProc = OS.CALLBACK_accessibilityHitTest_(proc3); + long proc3 = windowCallback3.getAddress(); + long proc2 = windowCallback2.getAddress(); + long proc4 = windowCallback4.getAddress(); + long proc6 = windowCallback6.getAddress(); + long view_stringForToolTip_point_userDataProc = OS.CALLBACK_view_stringForToolTip_point_userData_(proc6); + long accessibilityHitTestProc = OS.CALLBACK_accessibilityHitTest_(proc3); if (!isDynamic) OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); OS.class_addMethod(cls, OS.sel_sendEvent_, proc3, "@:@"); @@ -2440,12 +2640,12 @@ long /*int*/ createWindowSubclass(long /*int*/ baseClass, String newClass, boole return cls; } -long /*int*/ createMenuSubclass(long /*int*/ baseClass, String newClass, boolean isDynamic) { - long /*int*/ cls = OS.objc_lookUpClass(newClass); +long createMenuSubclass(long baseClass, String newClass, boolean isDynamic) { + long cls = OS.objc_lookUpClass(newClass); if (cls != 0) return cls; cls = OS.objc_allocateClassPair(baseClass, newClass, 0); - long /*int*/ proc3 = windowCallback3.getAddress(); - long /*int*/ proc4 = windowCallback4.getAddress(); + long proc3 = windowCallback3.getAddress(); + long proc4 = windowCallback4.getAddress(); OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); OS.class_addMethod(cls, OS.sel_menuWillOpen_, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_menuDidClose_, proc3, "@:@"); @@ -2455,11 +2655,11 @@ long /*int*/ createMenuSubclass(long /*int*/ baseClass, String newClass, boolean return cls; } -long /*int*/ createMenuItemSubclass(long /*int*/ baseClass, String newClass, boolean isDynamic) { - long /*int*/ cls = OS.objc_lookUpClass(newClass); +long createMenuItemSubclass(long baseClass, String newClass, boolean isDynamic) { + long cls = OS.objc_lookUpClass(newClass); if (cls != 0) return cls; cls = OS.objc_allocateClassPair(baseClass, newClass, 0); - long /*int*/ proc2 = windowCallback2.getAddress(); + long proc2 = windowCallback2.getAddress(); if (!isDynamic) OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); OS.objc_registerClassPair(cls); @@ -2471,71 +2671,63 @@ void initClasses () { Class clazz = getClass (); dialogCallback3 = new Callback(clazz, "dialogProc", 3); - long /*int*/ dialogProc3 = dialogCallback3.getAddress(); - if (dialogProc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long dialogProc3 = dialogCallback3.getAddress(); dialogCallback4 = new Callback(clazz, "dialogProc", 4); - long /*int*/ dialogProc4 = dialogCallback4.getAddress(); - if (dialogProc4 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long dialogProc4 = dialogCallback4.getAddress(); dialogCallback5 = new Callback(clazz, "dialogProc", 5); - long /*int*/ dialogProc5 = dialogCallback5.getAddress(); - if (dialogProc5 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long dialogProc5 = dialogCallback5.getAddress(); windowCallback3 = new Callback(clazz, "windowProc", 3); - long /*int*/ proc3 = windowCallback3.getAddress(); - if (proc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long proc3 = windowCallback3.getAddress(); windowCallback2 = new Callback(clazz, "windowProc", 2); - long /*int*/ proc2 = windowCallback2.getAddress(); - if (proc2 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long proc2 = windowCallback2.getAddress(); windowCallback4 = new Callback(clazz, "windowProc", 4); - long /*int*/ proc4 = windowCallback4.getAddress(); - if (proc4 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long proc4 = windowCallback4.getAddress(); windowCallback5 = new Callback(clazz, "windowProc", 5); - long /*int*/ proc5 = windowCallback5.getAddress(); - if (proc5 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + long proc5 = windowCallback5.getAddress(); windowCallback6 = new Callback(clazz, "windowProc", 6); - long /*int*/ proc6 = windowCallback6.getAddress(); - if (proc6 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - long /*int*/ isFlippedProc = OS.isFlipped_CALLBACK(); - long /*int*/ drawRectProc = OS.CALLBACK_drawRect_(proc3); - long /*int*/ drawInteriorWithFrameInViewProc = OS.CALLBACK_drawInteriorWithFrame_inView_ (proc4); - long /*int*/ drawBezelWithFrameInViewProc = OS.CALLBACK_drawBezelWithFrame_inView_ (proc4); - long /*int*/ drawWithExpansionFrameProc = OS.CALLBACK_drawWithExpansionFrame_inView_ (proc4); - long /*int*/ imageRectForBoundsProc = OS.CALLBACK_imageRectForBounds_ (proc3); - long /*int*/ titleRectForBoundsProc = OS.CALLBACK_titleRectForBounds_ (proc3); - long /*int*/ cellSizeForBoundsProc = OS.CALLBACK_cellSizeForBounds_ (proc3); - long /*int*/ hitTestForEvent_inRect_ofViewProc = OS.CALLBACK_hitTestForEvent_inRect_ofView_ (proc5); - long /*int*/ cellSizeProc = OS.CALLBACK_cellSize (proc2); - long /*int*/ drawImageWithFrameInViewProc = OS.CALLBACK_drawImage_withFrame_inView_ (proc5); - long /*int*/ drawTitleWithFrameInViewProc = OS.CALLBACK_drawTitle_withFrame_inView_ (proc5); - long /*int*/ setFrameOriginProc = OS.CALLBACK_setFrameOrigin_(proc3); - long /*int*/ setFrameSizeProc = OS.CALLBACK_setFrameSize_(proc3); - long /*int*/ hitTestProc = OS.CALLBACK_hitTest_(proc3); - long /*int*/ markedRangeProc = OS.CALLBACK_markedRange (proc2); - long /*int*/ selectedRangeProc = OS.CALLBACK_selectedRange (proc2); - long /*int*/ highlightSelectionInClipRectProc = OS.CALLBACK_highlightSelectionInClipRect_ (proc3); - long /*int*/ setMarkedText_selectedRangeProc = OS.CALLBACK_setMarkedText_selectedRange_(proc4); - long /*int*/ attributedSubstringFromRangeProc = OS.CALLBACK_attributedSubstringFromRange_(proc3); - long /*int*/ characterIndexForPointProc = OS.CALLBACK_characterIndexForPoint_(proc3); - long /*int*/ firstRectForCharacterRangeProc = OS.CALLBACK_firstRectForCharacterRange_(proc3); - long /*int*/ textWillChangeSelectionProc = OS.CALLBACK_textView_willChangeSelectionFromCharacterRange_toCharacterRange_(proc5); - long /*int*/ accessibilityHitTestProc = OS.CALLBACK_accessibilityHitTest_(proc3); - long /*int*/ shouldChangeTextInRange_replacementString_Proc = OS.CALLBACK_shouldChangeTextInRange_replacementString_(proc4); - long /*int*/ view_stringForToolTip_point_userDataProc = OS.CALLBACK_view_stringForToolTip_point_userData_(proc6); - long /*int*/ canDragRowsWithIndexes_atPoint_Proc = OS.CALLBACK_canDragRowsWithIndexes_atPoint_(proc4); - long /*int*/ setNeedsDisplayInRectProc = OS.CALLBACK_setNeedsDisplayInRect_(proc3); - long /*int*/ expansionFrameWithFrameProc = OS.CALLBACK_expansionFrameWithFrame_inView_ (proc4); - long /*int*/ focusRingMaskBoundsForFrameProc = OS.CALLBACK_focusRingMaskBoundsForFrame_inView_ (proc4); - long /*int*/ cacheDisplayInRect_toBitmapImageRepProc = OS.CALLBACK_cacheDisplayInRect_toBitmapImageRep_ (proc4); - long /*int*/ sizeOfLabelProc = OS.CALLBACK_sizeOfLabel_ (proc3); - long /*int*/ drawLabelInRectProc = OS.CALLBACK_drawLabel_inRect_ (proc4); - long /*int*/ drawViewBackgroundInRectProc = OS.CALLBACK_drawViewBackgroundInRect_(proc3); - long /*int*/ drawBackgroundInClipRectProc = OS.CALLBACK_drawBackgroundInClipRect_(proc3); - long /*int*/ scrollClipView_ToPointProc = OS.CALLBACK_scrollClipView_toPoint_(proc4); - long /*int*/ headerRectOfColumnProc = OS.CALLBACK_headerRectOfColumn_(proc3); - long /*int*/ columnAtPointProc = OS.CALLBACK_columnAtPoint_(proc3); + long proc6 = windowCallback6.getAddress(); + + long isFlippedProc = OS.isFlipped_CALLBACK(); + long drawRectProc = OS.CALLBACK_drawRect_(proc3); + long drawInteriorWithFrameInViewProc = OS.CALLBACK_drawInteriorWithFrame_inView_ (proc4); + long drawBezelWithFrameInViewProc = OS.CALLBACK_drawBezelWithFrame_inView_ (proc4); + long drawWithExpansionFrameProc = OS.CALLBACK_drawWithExpansionFrame_inView_ (proc4); + long imageRectForBoundsProc = OS.CALLBACK_imageRectForBounds_ (proc3); + long titleRectForBoundsProc = OS.CALLBACK_titleRectForBounds_ (proc3); + long cellSizeForBoundsProc = OS.CALLBACK_cellSizeForBounds_ (proc3); + long hitTestForEvent_inRect_ofViewProc = OS.CALLBACK_hitTestForEvent_inRect_ofView_ (proc5); + long cellSizeProc = OS.CALLBACK_cellSize (proc2); + long drawImageWithFrameInViewProc = OS.CALLBACK_drawImage_withFrame_inView_ (proc5); + long drawTitleWithFrameInViewProc = OS.CALLBACK_drawTitle_withFrame_inView_ (proc5); + long setFrameOriginProc = OS.CALLBACK_setFrameOrigin_(proc3); + long setFrameSizeProc = OS.CALLBACK_setFrameSize_(proc3); + long hitTestProc = OS.CALLBACK_hitTest_(proc3); + long markedRangeProc = OS.CALLBACK_markedRange (proc2); + long selectedRangeProc = OS.CALLBACK_selectedRange (proc2); + long highlightSelectionInClipRectProc = OS.CALLBACK_highlightSelectionInClipRect_ (proc3); + long setMarkedText_selectedRangeProc = OS.CALLBACK_setMarkedText_selectedRange_(proc4); + long attributedSubstringFromRangeProc = OS.CALLBACK_attributedSubstringFromRange_(proc3); + long characterIndexForPointProc = OS.CALLBACK_characterIndexForPoint_(proc3); + long firstRectForCharacterRangeProc = OS.CALLBACK_firstRectForCharacterRange_(proc3); + long textWillChangeSelectionProc = OS.CALLBACK_textView_willChangeSelectionFromCharacterRange_toCharacterRange_(proc5); + long accessibilityHitTestProc = OS.CALLBACK_accessibilityHitTest_(proc3); + long shouldChangeTextInRange_replacementString_Proc = OS.CALLBACK_shouldChangeTextInRange_replacementString_(proc4); + long view_stringForToolTip_point_userDataProc = OS.CALLBACK_view_stringForToolTip_point_userData_(proc6); + long canDragRowsWithIndexes_atPoint_Proc = OS.CALLBACK_canDragRowsWithIndexes_atPoint_(proc4); + long setNeedsDisplayInRectProc = OS.CALLBACK_setNeedsDisplayInRect_(proc3); + long expansionFrameWithFrameProc = OS.CALLBACK_expansionFrameWithFrame_inView_ (proc4); + long focusRingMaskBoundsForFrameProc = OS.CALLBACK_focusRingMaskBoundsForFrame_inView_ (proc4); + long cacheDisplayInRect_toBitmapImageRepProc = OS.CALLBACK_cacheDisplayInRect_toBitmapImageRep_ (proc4); + long sizeOfLabelProc = OS.CALLBACK_sizeOfLabel_ (proc3); + long drawLabelInRectProc = OS.CALLBACK_drawLabel_inRect_ (proc4); + long drawViewBackgroundInRectProc = OS.CALLBACK_drawViewBackgroundInRect_(proc3); + long drawBackgroundInClipRectProc = OS.CALLBACK_drawBackgroundInClipRect_(proc3); + long scrollClipView_ToPointProc = OS.CALLBACK_scrollClipView_toPoint_(proc4); + long headerRectOfColumnProc = OS.CALLBACK_headerRectOfColumn_(proc3); + long columnAtPointProc = OS.CALLBACK_columnAtPoint_(proc3); String className; - long /*int*/ cls; + long cls; className = "SWTBox"; cls = OS.objc_allocateClassPair(OS.class_NSBox, className, 0); @@ -2569,9 +2761,7 @@ void initClasses () { OS.class_addMethod(cls, OS.sel_drawBezelWithFrame_inView_, drawBezelWithFrameInViewProc, "@:{NSRect}@"); OS.class_addMethod(cls, OS.sel_titleRectForBounds_, titleRectForBoundsProc, "@:{NSRect}"); OS.class_addMethod(cls, OS.sel_cellSizeForBounds_, cellSizeForBoundsProc, "@:{NSRect}"); - if (OS.VERSION_MMB >= OS.VERSION_MMB(10, 10, 0)) { - OS.class_addMethod(cls, OS.sel_focusRingMaskBoundsForFrame_inView_, focusRingMaskBoundsForFrameProc, "@:{NSRect}@"); - } + OS.class_addMethod(cls, OS.sel_focusRingMaskBoundsForFrame_inView_, focusRingMaskBoundsForFrameProc, "@:{NSRect}@"); OS.objc_registerClassPair (cls); className = "SWTCanvasView"; @@ -2680,6 +2870,15 @@ void initClasses () { createMenuSubclass(OS.class_NSMenu, "SWTMenu", false); createMenuItemSubclass(OS.class_NSMenuItem, "SWTMenuItem", false); + className = "SWTOpenSavePanelDelegate"; + cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); + OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); + OS.class_addMethod(cls, OS.sel_sendSelection_, dialogProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_panel_shouldEnableURL_, dialogProc4, "@:@@"); + OS.class_addMethod(cls, OS.sel_panel_userEnteredFilename_confirmed_, dialogProc5, "@:@@"); + + OS.objc_registerClassPair(cls); + className = "SWTOutlineView"; cls = OS.objc_allocateClassPair(OS.class_NSOutlineView, className, 0); OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); @@ -2726,7 +2925,6 @@ void initClasses () { OS.class_addMethod(cls, OS.sel_changeFont_, dialogProc3, "@:@"); OS.class_addMethod(cls, OS.sel_validModesForFontPanel_, dialogProc3, "@:@"); OS.class_addMethod(cls, OS.sel_sendSelection_, dialogProc3, "@:@"); - OS.class_addMethod(cls, OS.sel_panel_shouldShowFilename_, dialogProc4, "@:@@"); OS.class_addMethod(cls, OS.sel_panelDidEnd_returnCode_contextInfo_, dialogProc5, "@:@i@"); OS.objc_registerClassPair(cls); @@ -2745,9 +2943,7 @@ void initClasses () { // NSPopUpButtonCell cls = registerCellSubclass(NSPopUpButton.cellClass(), size, align, types); addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); - if (OS.VERSION_MMB >= OS.VERSION_MMB(10, 10, 0)) { - OS.class_addMethod(cls, OS.sel_focusRingMaskBoundsForFrame_inView_, focusRingMaskBoundsForFrameProc, "@:{NSRect}@"); - } + OS.class_addMethod(cls, OS.sel_focusRingMaskBoundsForFrame_inView_, focusRingMaskBoundsForFrameProc, "@:{NSRect}@"); className = "SWTProgressIndicator"; cls = OS.objc_allocateClassPair(OS.class_NSProgressIndicator, className, 0); @@ -2767,11 +2963,9 @@ void initClasses () { addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); OS.objc_registerClassPair(cls); - if (OS.VERSION >= 0x1070) { - /* Note that isFlippedProc is used for performance and convenience */ - long /*int*/ metaClass = OS.objc_getMetaClass(className); - OS.class_addMethod(metaClass, OS.sel_isCompatibleWithOverlayScrollers, isFlippedProc, "@:"); - } + /* Note that isFlippedProc is used for performance and convenience */ + long metaClass = OS.objc_getMetaClass(className); + OS.class_addMethod(metaClass, OS.sel_isCompatibleWithOverlayScrollers, isFlippedProc, "@:"); className = "SWTScrollView"; cls = OS.objc_allocateClassPair(OS.class_NSScrollView, className, 0); @@ -2827,7 +3021,7 @@ void initClasses () { OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}"); OS.objc_registerClassPair(cls); - long /*int*/ nsSecureTextViewClass = OS.objc_lookUpClass("NSSecureTextView"); + long nsSecureTextViewClass = OS.objc_lookUpClass("NSSecureTextView"); if (nsSecureTextViewClass != 0) { className = "SWTSecureEditorView"; cls = OS.objc_allocateClassPair(nsSecureTextViewClass, className, 0); @@ -3036,9 +3230,9 @@ void initClasses () { OS.objc_registerClassPair(cls); } -NSFont getFont (long /*int*/ cls, long /*int*/ sel) { - long /*int*/ widget = OS.objc_msgSend (OS.objc_msgSend (cls, OS.sel_alloc), OS.sel_initWithFrame_, new NSRect()); - long /*int*/ font = 0; +NSFont getFont (long cls, long sel) { + long widget = OS.objc_msgSend (OS.objc_msgSend (cls, OS.sel_alloc), OS.sel_initWithFrame_, new NSRect()); + long font = 0; if (OS.objc_msgSend_bool (widget, OS.sel_respondsToSelector_, sel)) { font = OS.objc_msgSend (widget, sel); } @@ -3058,9 +3252,9 @@ void initColors (boolean ignoreColorChange) { /* * Code to ignore changes to System textColor, textBackgroundColor and controlTextColor */ - double /*float*/ [] color_list_foreground = colors[SWT.COLOR_LIST_FOREGROUND]; - double /*float*/ [] color_list_background = colors[SWT.COLOR_LIST_BACKGROUND]; - double /*float*/ [] color_widget_foreground = colors[SWT.COLOR_WIDGET_FOREGROUND]; + double [] color_list_foreground = colors[SWT.COLOR_LIST_FOREGROUND]; + double [] color_list_background = colors[SWT.COLOR_LIST_BACKGROUND]; + double [] color_widget_foreground = colors[SWT.COLOR_WIDGET_FOREGROUND]; initColors (); colors[SWT.COLOR_LIST_FOREGROUND] = color_list_foreground; colors[SWT.COLOR_LIST_BACKGROUND] = color_list_background; @@ -3071,7 +3265,7 @@ void initColors (boolean ignoreColorChange) { } void initColors () { - colors = new double /*float*/ [SWT.COLOR_LINK_FOREGROUND + 1][]; + colors = new double [SWT.COLOR_WIDGET_DISABLED_FOREGROUND + 1][]; colors[SWT.COLOR_INFO_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_INFO_FOREGROUND); colors[SWT.COLOR_INFO_BACKGROUND] = getWidgetColorRGB(SWT.COLOR_INFO_BACKGROUND); colors[SWT.COLOR_TITLE_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_TITLE_FOREGROUND); @@ -3092,11 +3286,15 @@ void initColors () { colors[SWT.COLOR_LIST_SELECTION_TEXT] = getWidgetColorRGB(SWT.COLOR_LIST_SELECTION_TEXT); colors[SWT.COLOR_LIST_SELECTION] = getWidgetColorRGB(SWT.COLOR_LIST_SELECTION); colors[SWT.COLOR_LINK_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_LINK_FOREGROUND); + colors[SWT.COLOR_TEXT_DISABLED_BACKGROUND] = getWidgetColorRGB(SWT.COLOR_TEXT_DISABLED_BACKGROUND); + colors[SWT.COLOR_WIDGET_DISABLED_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_WIDGET_DISABLED_FOREGROUND); - alternateSelectedControlColor = getNSColorRGB(NSColor.alternateSelectedControlColor()); alternateSelectedControlTextColor = getNSColorRGB(NSColor.alternateSelectedControlTextColor()); - secondarySelectedControlColor = getNSColorRGB(NSColor.secondarySelectedControlColor()); selectedControlTextColor = getNSColorRGB(NSColor.selectedControlTextColor()); + + /* These are set in the getter */ + alternateSelectedControlColor = null; + secondarySelectedControlColor = null; } void initFonts () { @@ -3141,7 +3339,7 @@ void initFonts () { * @noreference This method is not intended to be referenced by clients. */ @Override -public long /*int*/ internal_new_GC (GCData data) { +public long internal_new_GC (GCData data) { if (isDisposed()) error(SWT.ERROR_DEVICE_DISPOSED); if (screenWindow == null) { NSWindow window = (NSWindow) new NSWindow ().alloc (); @@ -3151,6 +3349,18 @@ public long /*int*/ internal_new_GC (GCData data) { screenWindow = window; } NSGraphicsContext context = screenWindow.graphicsContext(); + if (context == null) { + // create a bitmap based context, which will still work e.g. for text size computations + // it is unclear if the bitmap needs to be larger than the text to be measured. + // the following values should be big enough in any case. + int width = 1920; + int height = 256; + NSBitmapImageRep rep = (NSBitmapImageRep) new NSBitmapImageRep().alloc(); + rep = rep.initWithBitmapDataPlanes(0, width, height, 8, 3, false, false, OS.NSDeviceRGBColorSpace, + OS.NSAlphaFirstBitmapFormat, width * 4, 32); + context = NSGraphicsContext.graphicsContextWithBitmapImageRep(rep); + rep.release(); + } // NSAffineTransform transform = NSAffineTransform.transform(); // NSSize size = handle.size(); // transform.translateXBy(0, size.height); @@ -3185,7 +3395,7 @@ public long /*int*/ internal_new_GC (GCData data) { * @noreference This method is not intended to be referenced by clients. */ @Override -public void internal_dispose_GC (long /*int*/ hDC, GCData data) { +public void internal_dispose_GC (long hDC, GCData data) { if (isDisposed()) error(SWT.ERROR_DEVICE_DISPOSED); } @@ -3277,8 +3487,8 @@ public boolean post(Event event) { synchronized (Device.class) { if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); if (event == null) error (SWT.ERROR_NULL_ARGUMENT); - long /*int*/ eventRef = 0; - long /*int*/ eventSource = OS.CGEventSourceCreate(OS.kCGEventSourceStateHIDSystemState); + long eventRef = 0; + long eventSource = OS.CGEventSourceCreate(OS.kCGEventSourceStateHIDSystemState); if (eventSource == 0) return false; boolean returnValue = false; int deadKeyState[] = new int[1]; @@ -3288,9 +3498,9 @@ public boolean post(Event event) { case SWT.KeyUp: { short vKey = (short)Display.untranslateKey (event.keyCode); if (vKey == 0) { - long /*int*/ uchrPtr = 0; - long /*int*/ currentKbd = OS.TISCopyCurrentKeyboardInputSource(); - long /*int*/ uchrCFData = OS.TISGetInputSourceProperty(currentKbd, OS.kTISPropertyUnicodeKeyLayoutData()); + long uchrPtr = 0; + long currentKbd = OS.TISCopyCurrentKeyboardInputSource(); + long uchrCFData = OS.TISGetInputSourceProperty(currentKbd, OS.kTISPropertyUnicodeKeyLayoutData()); if (uchrCFData == 0) return false; uchrPtr = OS.CFDataGetBytePtr(uchrCFData); @@ -3299,7 +3509,7 @@ public boolean post(Event event) { int maxStringLength = 256; vKey = -1; char [] output = new char [maxStringLength]; - int [] actualStringLength = new int [1]; + long [] actualStringLength = new long [1]; for (short i = 0 ; i <= 0x7F ; i++) { deadKeyState[0] = 0; OS.UCKeyTranslate (uchrPtr, i, (short)(type == SWT.KeyDown ? OS.kUCKeyActionDown : OS.kUCKeyActionUp), 0, OS.LMGetKbdType(), 0, deadKeyState, maxStringLength, actualStringLength, output); @@ -3330,11 +3540,7 @@ public boolean post(Event event) { } if (vKey != -1) { - if (OS.VERSION < 0x1060) { - returnValue = OS.CGPostKeyboardEvent((short)0, vKey, type == SWT.KeyDown) == OS.noErr; - } else { - eventRef = OS.CGEventCreateKeyboardEvent(eventSource, vKey, type == SWT.KeyDown); - } + eventRef = OS.CGEventCreateKeyboardEvent(eventSource, vKey, type == SWT.KeyDown); } break; } @@ -3348,35 +3554,35 @@ public boolean post(Event event) { mouseCursorPosition.y = event.y; eventRef = OS.CGEventCreateMouseEvent(eventSource, OS.kCGEventMouseMoved, mouseCursorPosition, 0); } else { - NSPoint nsCursorPosition = NSEvent.mouseLocation(); - NSRect primaryFrame = getPrimaryFrame(); - mouseCursorPosition.x = nsCursorPosition.x; - mouseCursorPosition.y = (int) (primaryFrame.height - nsCursorPosition.y); - int eventType = 0; - // SWT buttons are 1-based: 1,2,3,4,5; CG buttons are 0 based: 0,2,1,3,4 - int cgButton; - switch (event.button) { - case 1: - eventType = (event.type == SWT.MouseDown ? OS.kCGEventLeftMouseDown : OS.kCGEventLeftMouseUp); - cgButton = 0; - break; - case 2: - eventType = (event.type == SWT.MouseDown ? OS.kCGEventOtherMouseDown : OS.kCGEventOtherMouseUp); - cgButton = 2; - break; - case 3: - eventType = (event.type == SWT.MouseDown ? OS.kCGEventRightMouseDown : OS.kCGEventRightMouseUp); - cgButton = 1; - break; - default: - eventType = (event.type == SWT.MouseDown ? OS.kCGEventOtherMouseDown : OS.kCGEventOtherMouseUp); - cgButton = event.button - 1; - break; - } - - if (cgButton >= 0) { - eventRef = OS.CGEventCreateMouseEvent(eventSource, eventType, mouseCursorPosition, cgButton); - } + NSPoint nsCursorPosition = NSEvent.mouseLocation(); + NSRect primaryFrame = getPrimaryFrame(); + mouseCursorPosition.x = nsCursorPosition.x; + mouseCursorPosition.y = (int) (primaryFrame.height - nsCursorPosition.y); + int eventType = 0; + // SWT buttons are 1-based: 1,2,3,4,5; CG buttons are 0 based: 0,2,1,3,4 + int cgButton; + switch (event.button) { + case 1: + eventType = (event.type == SWT.MouseDown ? OS.kCGEventLeftMouseDown : OS.kCGEventLeftMouseUp); + cgButton = 0; + break; + case 2: + eventType = (event.type == SWT.MouseDown ? OS.kCGEventOtherMouseDown : OS.kCGEventOtherMouseUp); + cgButton = 2; + break; + case 3: + eventType = (event.type == SWT.MouseDown ? OS.kCGEventRightMouseDown : OS.kCGEventRightMouseUp); + cgButton = 1; + break; + default: + eventType = (event.type == SWT.MouseDown ? OS.kCGEventOtherMouseDown : OS.kCGEventOtherMouseUp); + cgButton = event.button - 1; + break; + } + + if (cgButton >= 0) { + eventRef = OS.CGEventCreateMouseEvent(eventSource, eventType, mouseCursorPosition, cgButton); + } } break; } @@ -3387,17 +3593,14 @@ public boolean post(Event event) { } } - // returnValue is true if we called CGPostKeyboardEvent (10.5 only). - if (returnValue == false) { - if (eventRef != 0) { - OS.CGEventPost(OS.kCGHIDEventTap, eventRef); - OS.CFRelease(eventRef); - try { - Thread.sleep(1); - } catch (Exception e) { - } - returnValue = true; + if (eventRef != 0) { + OS.CGEventPost(OS.kCGHIDEventTap, eventRef); + OS.CFRelease(eventRef); + try { + Thread.sleep(1); + } catch (Exception e) { } + returnValue = true; } if (eventSource != 0) OS.CFRelease(eventSource); @@ -3675,8 +3878,8 @@ public Rectangle map (Control from, Control to, int x, int y, int width, int hei return rectangle; } -long /*int*/ observerProc (long /*int*/ observer, long /*int*/ activity, long /*int*/ info) { - switch ((int)/*64*/activity) { +long observerProc (long observer, long activity, long info) { + switch ((int)activity) { case OS.kCFRunLoopBeforeWaiting: if (runAsyncMessages) { if (runAsyncMessages (false)) wakeThread (); @@ -3690,8 +3893,8 @@ boolean performKeyEquivalent(NSWindow window, NSEvent nsEvent) { if (modalDialog == null) return false; if (nsEvent.type() != OS.NSKeyDown) return false; int stateMask = 0; - long /*int*/ selector = 0; - long /*int*/ modifierFlags = nsEvent.modifierFlags(); + long selector = 0; + long modifierFlags = nsEvent.modifierFlags(); if ((modifierFlags & OS.NSAlternateKeyMask) != 0) stateMask |= SWT.ALT; if ((modifierFlags & OS.NSShiftKeyMask) != 0) stateMask |= SWT.SHIFT; if ((modifierFlags & OS.NSControlKeyMask) != 0) stateMask |= SWT.CONTROL; @@ -3759,7 +3962,7 @@ public boolean readAndDispatch () { events |= runContexts (); events |= runPopups (); NSEvent event = application.nextEventMatchingMask(OS.NSAnyEventMask, null, OS.NSDefaultRunLoopMode, true); - if (event != null) { + if ((event != null) && (application != null)) { events = true; application.sendEvent(event); } @@ -3817,41 +4020,78 @@ static void register (Display display) { */ @Override protected void release () { - disposing = true; - sendEvent (SWT.Dispose, new Event ()); - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed ()) shell.dispose (); - } - if (tray != null) tray.dispose (); - tray = null; - if (taskBar != null) taskBar.dispose (); - taskBar = null; - while (readAndDispatch ()) {} - if (disposeList != null) { - for (int i=0; i<disposeList.length; i++) { - Runnable next = disposeList [i]; - if (next != null) { + try (ExceptionStash exceptions = new ExceptionStash ()) { + disposing = true; + + try { + sendEvent (SWT.Dispose, new Event ()); + } catch (Error | RuntimeException ex) { + exceptions.stash (ex); + } + + for (Shell shell : getShells ()) { + try { + if (!shell.isDisposed ()) shell.dispose (); + } catch (Error | RuntimeException ex) { + exceptions.stash (ex); + } + } + + try { + if (tray != null) tray.dispose (); + } catch (Error | RuntimeException ex) { + exceptions.stash (ex); + } + tray = null; + + try { + if (taskBar != null) taskBar.dispose (); + } catch (Error | RuntimeException ex) { + exceptions.stash (ex); + } + taskBar = null; + + for (;;) { + try { + if (!readAndDispatch ()) break; + } catch (Error | RuntimeException ex) { + exceptions.stash (ex); + } + } + + if (disposeList != null) { + for (Runnable next : disposeList) { + if (next == null) continue; + try { next.run (); - } catch (RuntimeException exception) { - runtimeExceptionHandler.accept (exception); - } catch (Error error) { - errorHandler.accept (error); + } catch (Error | RuntimeException ex) { + exceptions.stash (ex); } } } + disposeList = null; + + synchronizer.releaseSynchronizer (); + synchronizer = null; + + try { + if (appMenu != null) appMenu.dispose(); + } catch (Error | RuntimeException ex) { + exceptions.stash (ex); + } + appMenu = null; + + try { + if (appMenuBar != null) appMenuBar.dispose(); + } catch (Error | RuntimeException ex) { + exceptions.stash (ex); + } + appMenuBar = null; + + releaseDisplay (); + super.release (); } - disposeList = null; - synchronizer.releaseSynchronizer (); - synchronizer = null; - if (appMenu != null) appMenu.dispose(); - appMenu = null; - if (appMenuBar != null) appMenuBar.dispose(); - appMenuBar = null; - releaseDisplay (); - super.release (); } void releaseDisplay () { @@ -3929,7 +4169,7 @@ void releaseDisplay () { markedAttributes = null; if (oldCursorSetProc != 0) { - long /*int*/ method = OS.class_getInstanceMethod(OS.class_NSCursor, OS.sel_set); + long method = OS.class_getInstanceMethod(OS.class_NSCursor, OS.sel_set); OS.method_setImplementation(method, oldCursorSetProc); } if (cursorSetCallback != null) cursorSetCallback.dispose(); @@ -3945,7 +4185,7 @@ void releaseDisplay () { if (!isEmbedded) { //remove all existing menu items except the application menu NSMenu menubar = application.mainMenu(); - long /*int*/ count = menubar.numberOfItems(); + long count = menubar.numberOfItems(); while (count > 1) { menubar.removeItemAtIndex(count - 1); count--; @@ -4051,8 +4291,8 @@ public void removeListener (int eventType, Listener listener) { Widget removeWidget (NSObject view) { if (view == null) return null; - long /*int*/ [] jniRef = new long /*int*/ [1]; - long /*int*/ iVar = OS.object_getInstanceVariable(view.id, SWT_OBJECT, jniRef); + long [] jniRef = new long [1]; + long iVar = OS.object_getInstanceVariable(view.id, SWT_OBJECT, jniRef); if (iVar == 0) { if (dynamicObjectMap != null) { @@ -4098,16 +4338,20 @@ void removePopup (Menu menu) { } } +/** + * Resets the cached alternateSelectedControlColor and secondarySelectedControlColor. + */ +void resetSelectedControlColors() { + alternateSelectedControlColor = secondarySelectedControlColor = null; +} + boolean runAsyncMessages (boolean all) { return synchronizer.runAsyncMessages (all); } boolean runAWTInvokeLater() { - long /*int*/ cls = OS.objc_lookUpClass("JNFRunLoop"); - if (cls == 0) return false; - long /*int*/ mode = OS.objc_msgSend(cls, OS.sel_javaRunLoopMode); - if (mode == 0) return false; - NSString javaRunLoopMode = new NSString(mode); + NSString javaRunLoopMode = getAwtRunLoopMode(); + if (javaRunLoopMode == null) return false; allowTimers = runAsyncMessages = false; NSRunLoop.currentRunLoop().runMode(javaRunLoopMode, NSDate.distantFuture()); allowTimers = runAsyncMessages = true; @@ -4195,7 +4439,7 @@ NSArray runLoopModes() { boolean runPaint () { if (needsDisplay == null && needsDisplayInRect == null) return false; if (needsDisplay != null) { - long /*int*/ count = needsDisplay.count(); + long count = needsDisplay.count(); for (int i = 0; i < count; i++) { OS.objc_msgSend(needsDisplay.objectAtIndex(i).id, OS.sel_setNeedsDisplay_, true); } @@ -4203,7 +4447,7 @@ boolean runPaint () { needsDisplay = null; } if (needsDisplayInRect != null) { - long /*int*/ count = needsDisplayInRect.count(); + long count = needsDisplayInRect.count(); for (int i = 0; i < count; i+=2) { NSValue value = new NSValue(needsDisplayInRect.objectAtIndex(i+1)); OS.objc_msgSend(needsDisplayInRect.objectAtIndex(i).id, OS.sel_setNeedsDisplayInRect_, value.rectValue()); @@ -4236,13 +4480,13 @@ boolean runSettings () { runSettings = false; boolean ignoreColorChange = false; - /** + /* * Feature in Cocoa: When dark mode is enabled on OSX version >= 10.10 and a SWT TrayItem (NSStatusItem) is present in the menubar, * changing the OSX appearance or changing the configuration of attached displays causes the textColor and textBackground color to change. * This sets the text foreground of several widgets as white and hence text is invisible. The workaround is to detect this case and prevent * the update of LIST_FOREGROUND, LIST_BACKGROUND and COLOR_WIDGET_FOREGROUND colors. */ - if (OS.VERSION_MMB >= OS.VERSION_MMB (10, 10, 0) && tray != null && tray.itemCount > 0) { + if (tray != null && tray.itemCount > 0) { /* * osxMode will be "Dark" when in OSX dark mode. Otherwise, it'll be null. */ @@ -4271,13 +4515,14 @@ NSAppearance getAppearance (APPEARANCE newMode) { } void setAppAppearance (APPEARANCE newMode) { - if (OS.VERSION_MMB < OS.VERSION_MMB (10, 14, 0)) return; + if (OS.VERSION < OS.VERSION (10, 14, 0)) return; NSAppearance appearance = getAppearance(newMode); if (appearance != null && application != null) { OS.objc_msgSend(application.id, OS.sel_setAppearance_, appearance.id); appAppearance = newMode; - } + resetSelectedControlColors(); + } } void setWindowAppearance (NSWindow window, NSAppearance appearance) { @@ -4287,7 +4532,7 @@ void setWindowAppearance (NSWindow window, NSAppearance appearance) { } void setWindowsAppearance (APPEARANCE newMode) { - if (OS.VERSION_MMB < OS.VERSION_MMB (10, 14, 0)) return; + if (OS.VERSION < OS.VERSION (10, 14, 0)) return; NSAppearance appearance = getAppearance(newMode); if (appearance != null) { @@ -4420,7 +4665,7 @@ public void sendPostExternalEventDispatchEvent () { static NSString getApplicationName() { NSString name = null; int pid = OS.getpid (); - long /*int*/ ptr = C.getenv (ascii ("APP_NAME_" + pid)); + long ptr = C.getenv (ascii ("APP_NAME_" + pid)); if (ptr != 0) name = NSString.stringWithUTF8String(ptr); if (name == null && APP_NAME != null) name = NSString.stringWith(APP_NAME); if (name == null) { @@ -4651,10 +4896,6 @@ public void setData (String key, Object value) { setModalDialog (value != null ? (Dialog) value : null); } - if (key.equals (MOZILLA_RUNNING)) { - mozillaRunning = ((Boolean)value).booleanValue (); - } - if (key.equals (LOCK_CURSOR)) { lockCursor = ((Boolean)value).booleanValue (); } @@ -4729,7 +4970,7 @@ void setMenuBar (Menu menu) { */ // menubar.cancelTracking(); OS.CancelMenuTracking (OS.AcquireRootMenu (), true, 0); - long /*int*/ count = menubar.numberOfItems(); + long count = menubar.numberOfItems(); while (count > 1) { menubar.removeItemAtIndex(count - 1); count--; @@ -4746,11 +4987,9 @@ void setMenuBar (Menu menu) { * menu for languages other than english. The fix is to detect * it ourselves. */ - if (OS.VERSION >= 0x1060) { - NSMenu submenu = nsItem.submenu(); - if (submenu != null && submenu.title().getString().equals(SWT.getMessage("SWT_Help"))) { - application.setHelpMenu(submenu); - } + NSMenu submenu = nsItem.submenu(); + if (submenu != null && submenu.title().getString().equals(SWT.getMessage("SWT_Help"))) { + application.setHelpMenu(submenu); } nsItem.setMenu(null); @@ -4977,6 +5216,54 @@ public void syncExec (Runnable runnable) { } /** + * Calls the callable on the user-interface thread at the next reasonable + * opportunity, and returns the its result from this method. The thread which + * calls this method is suspended until the callable completes. + * <p> + * Note that at the time the callable is invoked, widgets that have the receiver + * as their display may have been disposed. Therefore, it is necessary to check + * for this case inside the callable before accessing the widget. + * </p> + * <p> + * Any exception that is thrown from the callable is re-thrown in the calling + * thread. Note: The exception retains its original stack trace from the + * throwing thread. The call to {@code syncCall} will not be present in the + * stack trace. + * </p> + * + * @param callable the code to call on the user-interface thread + * + * @exception SWTException <code>ERROR_DEVICE_DISPOSED</code> - if the receiver + * has been disposed + * @exception E An exception that is thrown by the callable on the + * user-interface thread, and re-thrown on the calling + * thread + * + * @see #syncExec(Runnable) + * @see SwtCallable#call() + * @since 3.118 + */ +public <T, E extends Exception> T syncCall(SwtCallable<T, E> callable) throws E { + Objects.nonNull(callable); + @SuppressWarnings("unchecked") + T[] t = (T[]) new Object[1]; + Object[] ex = new Object[1]; + syncExec(() -> { + try { + t[0] = callable.call(); + } catch (Exception e) { + ex[0] = e; + } + }); + if (ex[0] != null) { + @SuppressWarnings("unchecked") + E e = (E) ex[0]; + throw e; + } + return t[0]; +} + +/** * Causes the <code>run()</code> method of the runnable to * be invoked by the user-interface thread after the specified * number of milliseconds have elapsed. If milliseconds is less @@ -5054,7 +5341,7 @@ public void timerExec (int milliseconds, Runnable runnable) { } } -long /*int*/ timerProc (long /*int*/ id, long /*int*/ sel, long /*int*/ timerID) { +long timerProc (long id, long sel, long timerID) { NSTimer timer = new NSTimer (timerID); try { NSNumber number = new NSNumber(timer.userInfo()); @@ -5130,7 +5417,7 @@ void updateQuitMenu () { NSMenu sm = appitem.submenu(); // Normally this would be sel_terminate_ but we changed it so terminate: doesn't kill the app. - long /*int*/ quitIndex = sm.indexOfItemWithTarget(applicationDelegate, OS.sel_applicationShouldTerminate_); + long quitIndex = sm.indexOfItemWithTarget(applicationDelegate, OS.sel_applicationShouldTerminate_); if (quitIndex != -1) { NSMenuItem quitItem = sm.itemAtIndex(quitIndex); @@ -5172,18 +5459,7 @@ Control findControl (boolean checkTrim) { Control findControl (boolean checkTrim, NSView[] hitView) { NSView view = null; NSPoint screenLocation = NSEvent.mouseLocation(); - long /*int*/ hitWindowNumber = 0; - if (OS.VERSION >= 0x1060) { - hitWindowNumber = NSWindow.windowNumberAtPoint(screenLocation, 0); - } else { - long /*int*/ outWindow[] = new long /*int*/ [1]; - OS.FindWindow ((long /*int*/)screenLocation.x, (long /*int*/)(getPrimaryFrame().height - screenLocation.y), outWindow); - - if (outWindow[0] != 0) { - hitWindowNumber = OS.HIWindowGetCGWindowID(outWindow[0]); - } - } - + long hitWindowNumber = NSWindow.windowNumberAtPoint(screenLocation, 0); NSWindow window = application.windowWithWindowNumber(hitWindowNumber); if (window != null) { NSView contentView = window.contentView(); @@ -5215,7 +5491,7 @@ Control findControl (boolean checkTrim, NSView[] hitView) { return control; } -void finishLaunching (long /*int*/ id, long /*int*/ sel) { +void finishLaunching (long id, long sel) { /* * [NSApplication finishLaunching] cannot run multiple times otherwise * multiple main menus are added. @@ -5228,7 +5504,7 @@ void finishLaunching (long /*int*/ id, long /*int*/ sel) { OS.objc_msgSendSuper(super_struct, sel); } -void applicationDidBecomeActive (long /*int*/ id, long /*int*/ sel, long /*int*/ notification) { +void applicationDidBecomeActive (long id, long sel, long notification) { NSWindow keyWindow = application.keyWindow(); if (keyWindow != null) { keyWindow.orderFrontRegardless(); @@ -5239,37 +5515,22 @@ void applicationDidBecomeActive (long /*int*/ id, long /*int*/ sel, long /*int*/ checkEnterExit(findControl(true), null, false); } -void applicationDidResignActive (long /*int*/ id, long /*int*/ sel, long /*int*/ notification) { +void applicationDidResignActive (long id, long sel, long notification) { checkFocus(); checkEnterExit(null, null, false); } -long /*int*/ applicationNextEventMatchingMask (long /*int*/ id, long /*int*/ sel, long /*int*/ mask, long /*int*/ expiration, long /*int*/ mode, long /*int*/ dequeue) { +long applicationNextEventMatchingMask (long id, long sel, long mask, long expiration, long mode, long dequeue) { if (dequeue != 0 && trackingControl != null && !trackingControl.isDisposed()) runDeferredEvents(); sendPreExternalEventDispatchEvent(); try { objc_super super_struct = new objc_super(); super_struct.receiver = id; super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass); - long /*int*/ result = OS.objc_msgSendSuper(super_struct, sel, mask, expiration, mode, dequeue != 0); + long result = OS.objc_msgSendSuper(super_struct, sel, mask, expiration, mode, dequeue != 0); if (result != 0) { - /* - * Feature of Cocoa. When an NSComboBox's items list is visible it runs an event - * loop that will close the list in response to a processed NSApplicationDefined - * event. - * - * Mozilla-style Browsers are a common source of NSApplicationDefined events that - * will cause this to happen, which is not desirable in the context of SWT. The - * workaround is to detect this case and to not return the event that would trigger - * this to happen. - */ if (dequeue != 0 && currentCombo != null && !currentCombo.isDisposed()) { NSEvent nsEvent = new NSEvent(result); - if (mozillaRunning) { - if (nsEvent.type() == OS.NSApplicationDefined) { - return 0; - } - } if (nsEvent.type() == OS.NSKeyDown) { currentCombo.sendTrackingKeyEvent(nsEvent, SWT.KeyDown); } @@ -5285,7 +5546,7 @@ long /*int*/ applicationNextEventMatchingMask (long /*int*/ id, long /*int*/ sel } void applicationSendTrackingEvent (NSEvent nsEvent, Control trackingControl) { - int type = (int)/*64*/nsEvent.type(); + int type = (int)nsEvent.type(); boolean runEnterExit = false; Control runEnterExitControl = null; switch (type) { @@ -5323,13 +5584,13 @@ void applicationSendTrackingEvent (NSEvent nsEvent, Control trackingControl) { } } -void applicationSendEvent (long /*int*/ id, long /*int*/ sel, long /*int*/ event) { +void applicationSendEvent (long id, long sel, long event) { NSEvent nsEvent = new NSEvent(event); NSWindow window = nsEvent.window (); if (performKeyEquivalent(window, nsEvent)) return; - int type = (int)/*64*/nsEvent.type (); + int type = (int)nsEvent.type (); boolean activate = false, down = false; switch (type) { case OS.NSLeftMouseDown: @@ -5398,32 +5659,15 @@ void applicationSendEvent (long /*int*/ id, long /*int*/ sel, long /*int*/ event if (type != OS.NSAppKitDefined) sendEvent = false; } -void applicationWillFinishLaunching (long /*int*/ id, long /*int*/ sel, long /*int*/ notification) { - boolean loaded = false; - - /* - * Bug in AWT: If the AWT starts up first when the VM was started on the first thread it assumes that - * a Carbon-based SWT will be used, so it calls NSApplicationLoad(). This causes the Carbon menu - * manager to create an application menu that isn't accessible via NSMenu. It is, however, accessible - * via the Carbon menu manager, so find and delete the menu items it added. - * - * Note that this code will continue to work if Apple does change this. GetIndMenuWithCommandID will - * return a non-zero value indicating failure, which we ignore. - */ - if (isEmbedded) { - long /*int*/ outMenu [] = new long /*int*/ [1]; - short outIndex[] = new short[1]; - int status = OS.GetIndMenuItemWithCommandID(0, OS.kHICommandHide, 1, outMenu, outIndex); - if (status == 0) OS.DeleteMenuItem(outMenu[0], outIndex[0]); - status = OS.GetIndMenuItemWithCommandID(0, OS.kHICommandHideOthers, 1, outMenu, outIndex); - if (status == 0) OS.DeleteMenuItem(outMenu[0], outIndex[0]); - status = OS.GetIndMenuItemWithCommandID(0, OS.kHICommandShowAll, 1, outMenu, outIndex); - if (status == 0) OS.DeleteMenuItem(outMenu[0], outIndex[0]); - status = OS.GetIndMenuItemWithCommandID(0, OS.kHICommandQuit, 1, outMenu, outIndex); - if (status == 0) OS.DeleteMenuItem(outMenu[0], outIndex[0]); - status = OS.GetIndMenuItemWithCommandID(0, OS.kHICommandServices, 1, outMenu, outIndex); - if (status == 0) OS.DeleteMenuItem(outMenu[0], outIndex[0]); +void applicationDidFinishLaunching (long id, long sel, long notification) { + if (!isBundled()) { + application.setActivationPolicy (OS.NSApplicationActivationPolicyRegular); + application.activateIgnoringOtherApps (true); } +} + +void applicationWillFinishLaunching (long id, long sel, long notification) { + boolean loaded = false; /* * Get the default locale's language, and then the display name of the language. Some Mac OS X localizations use the @@ -5439,28 +5683,24 @@ void applicationWillFinishLaunching (long /*int*/ id, long /*int*/ sel, long /*i /* To find the nib look for each of these paths, in order, until one is found: * /System/Library/..../Resources/<display name>.lproj/DefaultApp.nib * /System/Library/..../Resources/<language>.lproj/DefaultApp.nib - * /System/Library/..../Resources/<user's default language>.lproj/DefaultApp.nib - * /System/Library/..../Resources/English.lproj/DefaultApp.nib. - * /System/Library/..../Resources/en.lproj/DefaultApp.nib. + * /System/Library/..../Resources/Base.lproj/DefaultApp.nib + * + * If nib file is not found, use the fallback method createMainMenu() to create menu with localized strings. */ NSString path; NSDictionary dict = NSDictionary.dictionaryWithObject(applicationDelegate, NSString.stringWith("NSOwner")); - NSBundle bundle = NSBundle.bundleWithIdentifier(NSString.stringWith("com.apple.JavaVM")); + NSBundle bundle = NSBundle.bundleWithPath(NSString.stringWith("/System/Library/Frameworks/JavaVM.framework/")); if (bundle != null) { path = bundle.pathForResource(NSString.stringWith("DefaultApp"), NSString.stringWith("nib"), null, languageDisplayName); if (path == null) path = bundle.pathForResource(NSString.stringWith("DefaultApp"), NSString.stringWith("nib"), null, NSString.stringWith(languageISOValue)); - if (path == null) path = bundle.pathForResource(NSString.stringWith("DefaultApp"), NSString.stringWith("nib")); - if (!loaded) loaded = path != null && NSBundle.loadNibFile(path, dict, 0); - if (!loaded) { - path = bundle.pathForResource(NSString.stringWith("DefaultApp"), NSString.stringWith("nib"), null, NSString.stringWith("English")); - if (path == null) path = bundle.pathForResource(NSString.stringWith("DefaultApp"), NSString.stringWith("nib"), null, NSString.stringWith("en")); - loaded = path != null && NSBundle.loadNibFile(path, dict, 0); + if (path == null && languageISOValue.equals("en")) { + path = bundle.pathForResource(NSString.stringWith("DefaultApp"), NSString.stringWith("nib")); } + if (!loaded) loaded = path != null && NSBundle.loadNibFile(path, dict, 0); } - if (!loaded) { - path = NSString.stringWith(System.getProperty("java.home") + "/../Resources/English.lproj/DefaultApp.nib"); - loaded = path != null && NSBundle.loadNibFile(path, dict, 0); - } + /* + * Create the main menu ourselves if Default.nib was not loaded or was not found for the specific language + */ if (!loaded) { createMainMenu(); } @@ -5478,7 +5718,7 @@ void applicationWillFinishLaunching (long /*int*/ id, long /*int*/ sel, long /*i NSMenuItem ni = new NSMenuItem(ia.objectAtIndex(i)); NSString title = ni.title().stringByReplacingOccurrencesOfString(match, name); ni.setTitle(title); - long /*int*/ newTag = 0; + long newTag = 0; switch(i) { case 0: newTag = SWT.ID_ABOUT; @@ -5502,7 +5742,7 @@ void applicationWillFinishLaunching (long /*int*/ id, long /*int*/ sel, long /*i if (newTag != 0) ni.setTag(newTag); } - long /*int*/ quitIndex = sm.indexOfItemWithTarget(applicationDelegate, OS.sel_terminate_); + long quitIndex = sm.indexOfItemWithTarget(applicationDelegate, OS.sel_terminate_); if (quitIndex != -1) { NSMenuItem quitItem = sm.itemAtIndex(quitIndex); @@ -5511,7 +5751,7 @@ void applicationWillFinishLaunching (long /*int*/ id, long /*int*/ sel, long /*i } } -static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel) { +static long applicationProc(long id, long sel) { //TODO optimize getting the display Display display = getCurrent (); if (display == null) { @@ -5530,7 +5770,7 @@ static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel) { return 0; } -static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { +static long applicationProc(long id, long sel, long arg0) { //TODO optimize getting the display Display display = getCurrent (); if (display == null && id != applicationDelegate.id) { @@ -5556,6 +5796,10 @@ static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel, long /*in display.applicationSendEvent (id, sel, arg0); return 0; } + case sel_applicationDidFinishLaunching_: { + display.applicationDidFinishLaunching(id, sel, arg0); + return 0; + } case sel_applicationWillFinishLaunching_: { display.applicationWillFinishLaunching(id, sel, arg0); return 0; @@ -5615,7 +5859,7 @@ static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel, long /*in } } -static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1) { +static long applicationProc(long id, long sel, long arg0, long arg1) { Display display = getCurrent(); if (display == null && id != applicationDelegate.id) { @@ -5640,7 +5884,7 @@ static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel, long /*in } case sel_application_openFiles_: { NSArray files = new NSArray(arg1); - long /*int*/ count = files.count(); + long count = files.count(); for (int i=0; i<count; i++) { String file = new NSString(files.objectAtIndex(i)).getString(); Event event = new Event(); @@ -5652,7 +5896,7 @@ static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel, long /*in } case sel_application_openUrls_: { NSArray urls = new NSArray(arg1); - long /*int*/ count = urls.count(); + long count = urls.count(); for (int i=0; i<count; i++) { String url = new NSString(urls.objectAtIndex(i)).getString(); Event event = new Event(); @@ -5673,7 +5917,7 @@ static long /*int*/ applicationProc(long /*int*/ id, long /*int*/ sel, long /*in } } -static long /*int*/ applicationProc(long /*int*/ id, long /*int*/sel, long /*int*/ arg0, long /*int*/ arg1, long /*int*/ arg2, long /*int*/ arg3) { +static long applicationProc(long id, long sel, long arg0, long arg1, long arg2, long arg3) { //TODO optimize getting the display Display display = getCurrent (); if (display == null && id != applicationDelegate.id) { @@ -5688,8 +5932,8 @@ static long /*int*/ applicationProc(long /*int*/ id, long /*int*/sel, long /*int return 0; } -static long /*int*/ dialogProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { - long /*int*/ [] jniRef = new long /*int*/ [1]; +static long dialogProc(long id, long sel, long arg0) { + long [] jniRef = new long [1]; OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef); if (jniRef[0] == 0) return 0; @@ -5732,14 +5976,14 @@ static long /*int*/ dialogProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a } } -static long /*int*/ dialogProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1) { - long /*int*/ [] jniRef = new long /*int*/ [1]; +static long dialogProc(long id, long sel, long arg0, long arg1) { + long [] jniRef = new long [1]; OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef); if (jniRef[0] == 0) return 0; - if (sel == OS.sel_panel_shouldShowFilename_) { + if (sel == OS.sel_panel_shouldEnableURL_) { FileDialog dialog = (FileDialog)OS.JNIGetObject(jniRef[0]); if (dialog == null) return 0; - return dialog.panel_shouldShowFilename(id, sel, arg0, arg1); + return dialog.panel_shouldEnableURL(id, sel, arg0, arg1); } if (sel == OS.sel_setColor_forAttribute_) { FontDialog dialog = (FontDialog)OS.JNIGetObject(jniRef[0]); @@ -5750,19 +5994,19 @@ static long /*int*/ dialogProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a return 0; } -static long /*int*/ dialogProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1, long /*int*/ arg2) { - long /*int*/ [] jniRef = new long /*int*/ [1]; +static long dialogProc(long id, long sel, long arg0, long arg1, long arg2) { + long [] jniRef = new long [1]; OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef); if (jniRef[0] == 0) return 0; - if (sel == OS.sel_panelDidEnd_returnCode_contextInfo_) { - MessageBox dialog = (MessageBox)OS.JNIGetObject(jniRef[0]); + if (sel == OS.sel_panel_userEnteredFilename_confirmed_) { + FileDialog dialog = (FileDialog)OS.JNIGetObject(jniRef[0]); if (dialog == null) return 0; - dialog.panelDidEnd_returnCode_contextInfo(id, sel, arg0, arg1, arg2); + return dialog.panel_userEnteredFilename_confirmed(id, sel, arg0, arg1, arg2); } return 0; } -static Widget LookupWidget (long /*int*/ id, long /*int*/ sel) { +static Widget LookupWidget (long id, long sel) { Widget widget = GetWidget(id); if (widget == null) { NSView view = new NSView (id); @@ -5775,10 +6019,10 @@ static Widget LookupWidget (long /*int*/ id, long /*int*/ sel) { return widget; } -static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel) { +static long windowProc(long id, long sel) { if (sel == OS.sel_cellClass) { - long /*int*/ superCls = OS.objc_msgSend(OS.class_getSuperclass(id), sel); - long /*int*/ cls = OS.objc_lookUpClass("SWTAccessible" + OS.class_getName(superCls)); + long superCls = OS.objc_msgSend(OS.class_getSuperclass(id), sel); + long cls = OS.objc_lookUpClass("SWTAccessible" + OS.class_getName(superCls)); return cls != 0 ? cls : superCls; } /* @@ -5862,21 +6106,21 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel) { case sel_markedRange: { NSRange range = widget.markedRange (id, sel); /* NOTE that this is freed in C */ - long /*int*/ result = C.malloc (NSRange.sizeof); + long result = C.malloc (NSRange.sizeof); OS.memmove (result, range, NSRange.sizeof); return result; } case sel_selectedRange: { NSRange range = widget.selectedRange (id, sel); /* NOTE that this is freed in C */ - long /*int*/ result = C.malloc (NSRange.sizeof); + long result = C.malloc (NSRange.sizeof); OS.memmove (result, range, NSRange.sizeof); return result; } case sel_cellSize: { NSSize size = widget.cellSize (id, sel); /* NOTE that this is freed in C */ - long /*int*/ result = C.malloc (NSSize.sizeof); + long result = C.malloc (NSSize.sizeof); OS.memmove (result, size, NSSize.sizeof); return result; } @@ -5941,7 +6185,7 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel) { } } -static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { +static long windowProc(long id, long sel, long arg0) { /* * Feature in Cocoa. In Cocoa, the default button animation is done * in a separate thread that calls drawRect() and isOpaque() from @@ -6367,14 +6611,6 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a widget.touchesCancelledWithEvent(id, sel, arg0); return 0; } - case sel_beginGestureWithEvent_: { - widget.beginGestureWithEvent(id, sel, arg0); - return 0; - } - case sel_endGestureWithEvent_: { - widget.endGestureWithEvent(id, sel, arg0); - return 0; - } case sel_swipeWithEvent_: { widget.swipeWithEvent(id, sel, arg0); return 0; @@ -6432,7 +6668,7 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a } } -static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1) { +static long windowProc(long id, long sel, long arg0, long arg1) { Widget widget = LookupWidget(id, sel); if (widget == null) return 0; @@ -6515,7 +6751,7 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a OS.memmove(rect, arg0, NSRect.sizeof); rect = widget.expansionFrameWithFrame_inView(id, sel, rect, arg1); /* NOTE that this is freed in C */ - long /*int*/ result = C.malloc (NSRect.sizeof); + long result = C.malloc (NSRect.sizeof); OS.memmove (result, rect, NSRect.sizeof); return result; } @@ -6524,7 +6760,7 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a OS.memmove(rect, arg0, NSRect.sizeof); rect = widget.focusRingMaskBoundsForFrame(id, sel, rect, arg1); /* NOTE that this is freed in C */ - long /*int*/ result = C.malloc (NSRect.sizeof); + long result = C.malloc (NSRect.sizeof); OS.memmove (result, rect, NSRect.sizeof); return result; } @@ -6563,7 +6799,7 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a } } -static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1, long /*int*/ arg2) { +static long windowProc(long id, long sel, long arg0, long arg1, long arg2) { Widget widget = LookupWidget(id, sel); if (widget == null) return 0; @@ -6595,7 +6831,7 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a case sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_: { NSRange range = widget.textView_willChangeSelectionFromCharacterRange_toCharacterRange(id, sel, arg0, arg1, arg2); /* NOTE that this is freed in C */ - long /*int*/ result = C.malloc (NSRange.sizeof); + long result = C.malloc (NSRange.sizeof); OS.memmove (result, range, NSRange.sizeof); return result; } @@ -6615,7 +6851,7 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a OS.memmove (rect, arg1, NSRect.sizeof); rect = widget.drawTitleWithFrameInView (id, sel, arg0, rect, arg2); /* NOTE that this is freed in C */ - long /*int*/ result = C.malloc (NSRect.sizeof); + long result = C.malloc (NSRect.sizeof); OS.memmove (result, rect, NSRect.sizeof); return result; } @@ -6639,7 +6875,7 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a } } -static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1, long /*int*/ arg2, long /*int*/ arg3) { +static long windowProc(long id, long sel, long arg0, long arg1, long arg2, long arg3) { Widget widget = LookupWidget(id, sel); if (widget == null) return 0; |