55 import java.awt.dnd.DragGestureRecognizer; 56 import java.awt.dnd.MouseDragGestureRecognizer; 57 import java.awt.dnd.InvalidDnDOperationException; 58 import java.awt.dnd.peer.DragSourceContextPeer; 59 60 import java.util.Hashtable; 61 import java.util.Locale; 62 import java.util.Map; 63 import java.util.Properties; 64 65 import sun.font.FontManager; 66 import sun.font.FontManagerFactory; 67 import sun.font.SunFontManager; 68 import sun.misc.PerformanceLogger; 69 import sun.util.logging.PlatformLogger; 70 71 public final class WToolkit extends SunToolkit implements Runnable { 72 73 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit"); 74 75 static GraphicsConfiguration config; 76 77 // System clipboard. 78 WClipboard clipboard; 79 80 // cache of font peers 81 private Hashtable<String,FontPeer> cacheFontPeer; 82 83 // Windows properties 84 private WDesktopProperties wprops; 85 86 // Dynamic Layout Resize client code setting 87 protected boolean dynamicLayoutSetting = false; 88 89 //Is it allowed to generate events assigned to extra mouse buttons. 90 //Set to true by default. 91 private static boolean areExtraMouseButtonsEnabled = true; 92 93 /** 94 * Initialize JNI field and method IDs 877 878 if (name.equals("awt.dynamicLayoutSupported")) { 879 return Boolean.valueOf(isDynamicLayoutSupported()); 880 } 881 882 if (WDesktopProperties.isWindowsProperty(name) || 883 name.startsWith(awtPrefix) || name.startsWith(dndPrefix)) 884 { 885 synchronized(this) { 886 lazilyInitWProps(); 887 return desktopProperties.get(name); 888 } 889 } 890 891 return super.lazilyLoadDesktopProperty(name); 892 } 893 894 private synchronized void lazilyInitWProps() { 895 if (wprops == null) { 896 wprops = new WDesktopProperties(this); 897 updateProperties(); 898 } 899 } 900 901 /* 902 * Called from lazilyLoadDesktopProperty because Windows doesn't 903 * always send WM_SETTINGCHANGE when it should. 904 */ 905 private synchronized boolean isDynamicLayoutSupported() { 906 boolean nativeDynamic = isDynamicLayoutSupportedNative(); 907 lazilyInitWProps(); 908 Boolean prop = (Boolean) desktopProperties.get("awt.dynamicLayoutSupported"); 909 910 if (log.isLoggable(PlatformLogger.Level.FINER)) { 911 log.finer("In WTK.isDynamicLayoutSupported()" + 912 " nativeDynamic == " + nativeDynamic + 913 " wprops.dynamic == " + prop); 914 } 915 916 if ((prop == null) || (nativeDynamic != prop.booleanValue())) { 917 // We missed the WM_SETTINGCHANGE, so we pretend 918 // we just got one - fire the propertyChange, etc. 919 windowsSettingChange(); 920 return nativeDynamic; 921 } 922 923 return prop.booleanValue(); 924 } 925 926 /* 927 * Called from native toolkit code when WM_SETTINGCHANGE message received 928 * Also called from lazilyLoadDynamicLayoutSupportedProperty because 929 * Windows doesn't always send WM_SETTINGCHANGE when it should. 930 */ 931 private void windowsSettingChange() { 932 EventQueue.invokeLater(new Runnable() { 933 @Override 934 public void run() { 935 updateProperties(); 936 } 937 }); 938 } 939 940 private synchronized void updateProperties() { 941 if (null == wprops) { 942 // wprops has not been initialized, so we have nothing to update 943 return; 944 } 945 946 Map<String, Object> props = wprops.getProperties(); 947 for (String propName : props.keySet()) { 948 Object val = props.get(propName); 949 if (log.isLoggable(PlatformLogger.Level.FINER)) { 950 log.finer("changed " + propName + " to " + val); 951 } 952 setDesktopProperty(propName, val); 953 } 954 } 955 956 @Override 957 public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) { 958 if (name == null) { 959 // See JavaDoc for the Toolkit.addPropertyChangeListener() method 960 return; 961 } 962 if ( WDesktopProperties.isWindowsProperty(name) 963 || name.startsWith(awtPrefix) 964 || name.startsWith(dndPrefix)) 965 { 966 // someone is interested in Windows-specific desktop properties 967 // we should initialize wprops 968 lazilyInitWProps(); 969 } 970 super.addPropertyChangeListener(name, pcl); 971 } 972 973 /* | 55 import java.awt.dnd.DragGestureRecognizer; 56 import java.awt.dnd.MouseDragGestureRecognizer; 57 import java.awt.dnd.InvalidDnDOperationException; 58 import java.awt.dnd.peer.DragSourceContextPeer; 59 60 import java.util.Hashtable; 61 import java.util.Locale; 62 import java.util.Map; 63 import java.util.Properties; 64 65 import sun.font.FontManager; 66 import sun.font.FontManagerFactory; 67 import sun.font.SunFontManager; 68 import sun.misc.PerformanceLogger; 69 import sun.util.logging.PlatformLogger; 70 71 public final class WToolkit extends SunToolkit implements Runnable { 72 73 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit"); 74 75 // Desktop property which specifies whether XP visual styles are in effect 76 public static final String XPSTYLE_THEME_ACTIVE = "win.xpstyle.themeActive"; 77 78 static GraphicsConfiguration config; 79 80 // System clipboard. 81 WClipboard clipboard; 82 83 // cache of font peers 84 private Hashtable<String,FontPeer> cacheFontPeer; 85 86 // Windows properties 87 private WDesktopProperties wprops; 88 89 // Dynamic Layout Resize client code setting 90 protected boolean dynamicLayoutSetting = false; 91 92 //Is it allowed to generate events assigned to extra mouse buttons. 93 //Set to true by default. 94 private static boolean areExtraMouseButtonsEnabled = true; 95 96 /** 97 * Initialize JNI field and method IDs 880 881 if (name.equals("awt.dynamicLayoutSupported")) { 882 return Boolean.valueOf(isDynamicLayoutSupported()); 883 } 884 885 if (WDesktopProperties.isWindowsProperty(name) || 886 name.startsWith(awtPrefix) || name.startsWith(dndPrefix)) 887 { 888 synchronized(this) { 889 lazilyInitWProps(); 890 return desktopProperties.get(name); 891 } 892 } 893 894 return super.lazilyLoadDesktopProperty(name); 895 } 896 897 private synchronized void lazilyInitWProps() { 898 if (wprops == null) { 899 wprops = new WDesktopProperties(this); 900 updateProperties(wprops.getProperties()); 901 } 902 } 903 904 /* 905 * Called from lazilyLoadDesktopProperty because Windows doesn't 906 * always send WM_SETTINGCHANGE when it should. 907 */ 908 private synchronized boolean isDynamicLayoutSupported() { 909 boolean nativeDynamic = isDynamicLayoutSupportedNative(); 910 lazilyInitWProps(); 911 Boolean prop = (Boolean) desktopProperties.get("awt.dynamicLayoutSupported"); 912 913 if (log.isLoggable(PlatformLogger.Level.FINER)) { 914 log.finer("In WTK.isDynamicLayoutSupported()" + 915 " nativeDynamic == " + nativeDynamic + 916 " wprops.dynamic == " + prop); 917 } 918 919 if ((prop == null) || (nativeDynamic != prop.booleanValue())) { 920 // We missed the WM_SETTINGCHANGE, so we pretend 921 // we just got one - fire the propertyChange, etc. 922 windowsSettingChange(); 923 return nativeDynamic; 924 } 925 926 return prop.booleanValue(); 927 } 928 929 /* 930 * Called from native toolkit code when WM_SETTINGCHANGE message received 931 * Also called from lazilyLoadDynamicLayoutSupportedProperty because 932 * Windows doesn't always send WM_SETTINGCHANGE when it should. 933 */ 934 private void windowsSettingChange() { 935 // JDK-8039383: Have to update the value of XPSTYLE_THEME_ACTIVE property 936 // as soon as possible to prevent NPE and other errors because theme data 937 // has become unavailable. 938 final Map<String, Object> props = getWProps(); 939 updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE)); 940 941 EventQueue.invokeLater(new Runnable() { 942 @Override 943 public void run() { 944 updateProperties(props); 945 } 946 }); 947 } 948 949 private synchronized void updateProperties(final Map<String, Object> props) { 950 if (null == props) { 951 return; 952 } 953 954 updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE)); 955 956 for (String propName : props.keySet()) { 957 Object val = props.get(propName); 958 if (log.isLoggable(PlatformLogger.Level.FINER)) { 959 log.finer("changed " + propName + " to " + val); 960 } 961 setDesktopProperty(propName, val); 962 } 963 } 964 965 private synchronized Map<String, Object> getWProps() { 966 return (wprops != null) ? wprops.getProperties() : null; 967 } 968 969 private void updateXPStyleEnabled(final Object dskProp) { 970 ThemeReader.xpStyleEnabled = Boolean.TRUE.equals(dskProp); 971 } 972 973 @Override 974 public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) { 975 if (name == null) { 976 // See JavaDoc for the Toolkit.addPropertyChangeListener() method 977 return; 978 } 979 if ( WDesktopProperties.isWindowsProperty(name) 980 || name.startsWith(awtPrefix) 981 || name.startsWith(dndPrefix)) 982 { 983 // someone is interested in Windows-specific desktop properties 984 // we should initialize wprops 985 lazilyInitWProps(); 986 } 987 super.addPropertyChangeListener(name, pcl); 988 } 989 990 /* |