src/windows/classes/sun/awt/windows/WToolkit.java

Print this page




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.windows;
  27 
  28 import java.awt.*;
  29 import java.awt.im.InputMethodHighlight;
  30 import java.awt.im.spi.InputMethodDescriptor;
  31 import java.awt.image.*;
  32 import java.awt.peer.*;
  33 import java.awt.event.KeyEvent;
  34 import java.awt.datatransfer.Clipboard;
  35 import java.awt.TrayIcon;
  36 import java.beans.PropertyChangeListener;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedAction;

  39 import sun.awt.AWTAutoShutdown;
  40 import sun.awt.AWTPermissions;
  41 import sun.awt.LightweightFrame;
  42 import sun.awt.SunToolkit;
  43 import sun.awt.util.ThreadGroupUtils;
  44 import sun.awt.Win32GraphicsDevice;
  45 import sun.awt.Win32GraphicsEnvironment;
  46 import sun.awt.datatransfer.DataTransferer;
  47 import sun.java2d.d3d.D3DRenderQueue;
  48 import sun.java2d.opengl.OGLRenderQueue;
  49 
  50 import sun.print.PrintJob2D;
  51 
  52 import java.awt.dnd.DragSource;
  53 import java.awt.dnd.DragGestureListener;
  54 import java.awt.dnd.DragGestureEvent;
  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


 878 
 879         if (name.equals("awt.dynamicLayoutSupported")) {
 880             return  Boolean.valueOf(isDynamicLayoutSupported());
 881         }
 882 
 883         if (WDesktopProperties.isWindowsProperty(name) ||
 884             name.startsWith(awtPrefix) || name.startsWith(dndPrefix))
 885         {
 886             synchronized(this) {
 887                 lazilyInitWProps();
 888                 return desktopProperties.get(name);
 889             }
 890         }
 891 
 892         return super.lazilyLoadDesktopProperty(name);
 893     }
 894 
 895     private synchronized void lazilyInitWProps() {
 896         if (wprops == null) {
 897             wprops = new WDesktopProperties(this);
 898             updateProperties();
 899         }
 900     }
 901 
 902     /*
 903      * Called from lazilyLoadDesktopProperty because Windows doesn't
 904      * always send WM_SETTINGCHANGE when it should.
 905      */
 906     private synchronized boolean isDynamicLayoutSupported() {
 907         boolean nativeDynamic = isDynamicLayoutSupportedNative();
 908         lazilyInitWProps();
 909         Boolean prop = (Boolean) desktopProperties.get("awt.dynamicLayoutSupported");
 910 
 911         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 912             log.finer("In WTK.isDynamicLayoutSupported()" +
 913                       "   nativeDynamic == " + nativeDynamic +
 914                       "   wprops.dynamic == " + prop);
 915         }
 916 
 917         if ((prop == null) || (nativeDynamic != prop.booleanValue())) {
 918             // We missed the WM_SETTINGCHANGE, so we pretend
 919             // we just got one - fire the propertyChange, etc.
 920             windowsSettingChange();
 921             return nativeDynamic;
 922         }
 923 
 924         return prop.booleanValue();
 925     }
 926 
 927     /*
 928      * Called from native toolkit code when WM_SETTINGCHANGE message received
 929      * Also called from lazilyLoadDynamicLayoutSupportedProperty because
 930      * Windows doesn't always send WM_SETTINGCHANGE when it should.
 931      */
 932     private void windowsSettingChange() {
 933         EventQueue.invokeLater(new Runnable() {
 934             @Override
 935             public void run() {
 936                 updateProperties();











 937             }
 938         });
 939     }
 940 
 941     private synchronized void updateProperties() {
 942         if (null == wprops) {
 943             // wprops has not been initialized, so we have nothing to update
 944             return;
 945         }
 946 
 947         Map<String, Object> props = wprops.getProperties();

 948         for (String propName : props.keySet()) {
 949             Object val = props.get(propName);
 950             if (log.isLoggable(PlatformLogger.Level.FINER)) {
 951                 log.finer("changed " + propName + " to " + val);
 952             }
 953             setDesktopProperty(propName, val);
 954         }








 955     }
 956 
 957     @Override
 958     public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
 959         if (name == null) {
 960             // See JavaDoc for the Toolkit.addPropertyChangeListener() method
 961             return;
 962         }
 963         if ( WDesktopProperties.isWindowsProperty(name)
 964              || name.startsWith(awtPrefix)
 965              || name.startsWith(dndPrefix))
 966         {
 967             // someone is interested in Windows-specific desktop properties
 968             // we should initialize wprops
 969             lazilyInitWProps();
 970         }
 971         super.addPropertyChangeListener(name, pcl);
 972     }
 973 
 974     /*




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.windows;
  27 
  28 import java.awt.*;
  29 import java.awt.im.InputMethodHighlight;
  30 import java.awt.im.spi.InputMethodDescriptor;
  31 import java.awt.image.*;
  32 import java.awt.peer.*;
  33 import java.awt.event.KeyEvent;
  34 import java.awt.datatransfer.Clipboard;
  35 import java.awt.TrayIcon;
  36 import java.beans.PropertyChangeListener;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedAction;
  39 import sun.awt.AppContext;
  40 import sun.awt.AWTAutoShutdown;
  41 import sun.awt.AWTPermissions;
  42 import sun.awt.LightweightFrame;
  43 import sun.awt.SunToolkit;
  44 import sun.awt.util.ThreadGroupUtils;
  45 import sun.awt.Win32GraphicsDevice;
  46 import sun.awt.Win32GraphicsEnvironment;
  47 import sun.awt.datatransfer.DataTransferer;
  48 import sun.java2d.d3d.D3DRenderQueue;
  49 import sun.java2d.opengl.OGLRenderQueue;
  50 
  51 import sun.print.PrintJob2D;
  52 
  53 import java.awt.dnd.DragSource;
  54 import java.awt.dnd.DragGestureListener;
  55 import java.awt.dnd.DragGestureEvent;
  56 import java.awt.dnd.DragGestureRecognizer;
  57 import java.awt.dnd.MouseDragGestureRecognizer;
  58 import java.awt.dnd.InvalidDnDOperationException;
  59 import java.awt.dnd.peer.DragSourceContextPeer;
  60 
  61 import java.util.Hashtable;
  62 import java.util.Locale;
  63 import java.util.Map;
  64 import java.util.Properties;
  65 
  66 import sun.font.FontManager;
  67 import sun.font.FontManagerFactory;
  68 import sun.font.SunFontManager;
  69 import sun.misc.PerformanceLogger;
  70 import sun.util.logging.PlatformLogger;
  71 
  72 public final class WToolkit extends SunToolkit implements Runnable {
  73 
  74     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit");
  75 
  76     // Desktop property which specifies whether XP visual styles are in effect
  77     public static final String XPSTYLE_THEME_ACTIVE = "win.xpstyle.themeActive";
  78 
  79     static GraphicsConfiguration config;
  80 
  81     // System clipboard.
  82     WClipboard clipboard;
  83 
  84     // cache of font peers
  85     private Hashtable<String,FontPeer> cacheFontPeer;
  86 
  87     // Windows properties
  88     private WDesktopProperties  wprops;
  89 
  90     // Dynamic Layout Resize client code setting
  91     protected boolean dynamicLayoutSetting = false;
  92 
  93     //Is it allowed to generate events assigned to extra mouse buttons.
  94     //Set to true by default.
  95     private static boolean areExtraMouseButtonsEnabled = true;
  96 
  97     /**
  98      * Initialize JNI field and method IDs


 882 
 883         if (name.equals("awt.dynamicLayoutSupported")) {
 884             return  Boolean.valueOf(isDynamicLayoutSupported());
 885         }
 886 
 887         if (WDesktopProperties.isWindowsProperty(name) ||
 888             name.startsWith(awtPrefix) || name.startsWith(dndPrefix))
 889         {
 890             synchronized(this) {
 891                 lazilyInitWProps();
 892                 return desktopProperties.get(name);
 893             }
 894         }
 895 
 896         return super.lazilyLoadDesktopProperty(name);
 897     }
 898 
 899     private synchronized void lazilyInitWProps() {
 900         if (wprops == null) {
 901             wprops = new WDesktopProperties(this);
 902             updateProperties(wprops.getProperties());
 903         }
 904     }
 905 
 906     /*
 907      * Called from lazilyLoadDesktopProperty because Windows doesn't
 908      * always send WM_SETTINGCHANGE when it should.
 909      */
 910     private synchronized boolean isDynamicLayoutSupported() {
 911         boolean nativeDynamic = isDynamicLayoutSupportedNative();
 912         lazilyInitWProps();
 913         Boolean prop = (Boolean) desktopProperties.get("awt.dynamicLayoutSupported");
 914 
 915         if (log.isLoggable(PlatformLogger.Level.FINER)) {
 916             log.finer("In WTK.isDynamicLayoutSupported()" +
 917                       "   nativeDynamic == " + nativeDynamic +
 918                       "   wprops.dynamic == " + prop);
 919         }
 920 
 921         if ((prop == null) || (nativeDynamic != prop.booleanValue())) {
 922             // We missed the WM_SETTINGCHANGE, so we pretend
 923             // we just got one - fire the propertyChange, etc.
 924             windowsSettingChange();
 925             return nativeDynamic;
 926         }
 927 
 928         return prop.booleanValue();
 929     }
 930 
 931     /*
 932      * Called from native toolkit code when WM_SETTINGCHANGE message received
 933      * Also called from lazilyLoadDynamicLayoutSupportedProperty because
 934      * Windows doesn't always send WM_SETTINGCHANGE when it should.
 935      */
 936     private void windowsSettingChange() {
 937         // JDK-8039383: Have to update the value of XPSTYLE_THEME_ACTIVE property
 938         // as soon as possible to prevent NPE and other errors because theme data
 939         // has become unavailable.
 940         final Map<String, Object> props = getWProps();
 941         updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));
 942 
 943         if (AppContext.getAppContext() == null) {
 944             // We cannot post the update to any EventQueue. Listeners will
 945             // be called on EDTs by DesktopPropertyChangeSupport
 946             updateProperties(props);
 947         } else {
 948             // Cannot update on Toolkit thread.
 949             // DesktopPropertyChangeSupport will call listeners on Toolkit
 950             // thread if it has AppContext (standalone mode)
 951             EventQueue.invokeLater(() -> updateProperties(props));
 952         }

 953     }
 954 
 955     private synchronized void updateProperties(final Map<String, Object> props) {
 956         if (null == props) {

 957             return;
 958         }
 959 
 960         updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));
 961 
 962         for (String propName : props.keySet()) {
 963             Object val = props.get(propName);
 964             if (log.isLoggable(PlatformLogger.Level.FINER)) {
 965                 log.finer("changed " + propName + " to " + val);
 966             }
 967             setDesktopProperty(propName, val);
 968         }
 969     }
 970 
 971     private synchronized Map<String, Object> getWProps() {
 972         return (wprops != null) ? wprops.getProperties() : null;
 973     }
 974 
 975     private void updateXPStyleEnabled(final Object dskProp) {
 976         ThemeReader.xpStyleEnabled = Boolean.TRUE.equals(dskProp);
 977     }
 978 
 979     @Override
 980     public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
 981         if (name == null) {
 982             // See JavaDoc for the Toolkit.addPropertyChangeListener() method
 983             return;
 984         }
 985         if ( WDesktopProperties.isWindowsProperty(name)
 986              || name.startsWith(awtPrefix)
 987              || name.startsWith(dndPrefix))
 988         {
 989             // someone is interested in Windows-specific desktop properties
 990             // we should initialize wprops
 991             lazilyInitWProps();
 992         }
 993         super.addPropertyChangeListener(name, pcl);
 994     }
 995 
 996     /*