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

Print this page




  57 import java.util.Locale;
  58 import java.util.Map;
  59 import java.util.Properties;
  60 
  61 import sun.font.FontManager;
  62 import sun.font.FontManagerFactory;
  63 import sun.font.SunFontManager;
  64 import sun.misc.PerformanceLogger;
  65 import sun.util.logging.PlatformLogger;
  66 
  67 public class WToolkit extends SunToolkit implements Runnable {
  68 
  69     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit");
  70 
  71     static GraphicsConfiguration config;
  72 
  73     // System clipboard.
  74     WClipboard clipboard;
  75 
  76     // cache of font peers
  77     private Hashtable cacheFontPeer;
  78 
  79     // Windows properties
  80     private WDesktopProperties  wprops;
  81 
  82     // Dynamic Layout Resize client code setting
  83     protected boolean dynamicLayoutSetting = false;
  84 
  85     //Is it allowed to generate events assigned to extra mouse buttons.
  86     //Set to true by default.
  87     private static boolean areExtraMouseButtonsEnabled = true;
  88 
  89     /**
  90      * Initialize JNI field and method IDs
  91      */
  92     private static native void initIDs();
  93     private static boolean loaded = false;
  94     public static void loadLibraries() {
  95         if (!loaded) {
  96             java.security.AccessController.doPrivileged(
  97                           new sun.security.action.LoadLibraryAction("awt"));
  98             loaded = true;
  99         }
 100     }
 101 
 102     private static native String getWindowsVersion();
 103 
 104     static {
 105         loadLibraries();
 106         initIDs();
 107 
 108         // Print out which version of Windows is running
 109         if (log.isLoggable(PlatformLogger.FINE)) {
 110             log.fine("Win version: " + getWindowsVersion());
 111         }
 112 
 113         java.security.AccessController.doPrivileged(
 114             new java.security.PrivilegedAction()
 115         {
 116             public Object run() {
 117                 String browserProp = System.getProperty("browser");
 118                 if (browserProp != null && browserProp.equals("sun.plugin")) {
 119                     disableCustomPalette();
 120                 }
 121                 return null;
 122             }
 123         });
 124     }
 125 
 126     private static native void disableCustomPalette();
 127 
 128     /*
 129      * Reset the static GraphicsConfiguration to the default.  Called on
 130      * startup and when display settings have changed.
 131      */
 132     public static void resetGC() {
 133         if (GraphicsEnvironment.isHeadless()) {
 134             config = null;
 135         } else {
 136           config = (GraphicsEnvironment


 244                     wait();
 245                 }
 246             }
 247         } catch (InterruptedException x) {
 248             // swallow the exception
 249         }
 250 
 251         SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);
 252 
 253         // Enabled "live resizing" by default.  It remains controlled
 254         // by the native system though.
 255         setDynamicLayout(true);
 256 
 257         areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
 258         //set system property if not yet assigned
 259         System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
 260         setExtraMouseButtonsEnabledNative(areExtraMouseButtonsEnabled);
 261     }
 262 
 263     private final void registerShutdownHook() {
 264         AccessController.doPrivileged(new PrivilegedAction() {
 265             public Object run() {
 266                 ThreadGroup currentTG =
 267                     Thread.currentThread().getThreadGroup();
 268                 ThreadGroup parentTG = currentTG.getParent();
 269                 while (parentTG != null) {
 270                     currentTG = parentTG;
 271                     parentTG = currentTG.getParent();
 272                 }
 273                 Thread shutdown = new Thread(currentTG, new Runnable() {
 274                     public void run() {
 275                         shutdown();
 276                     }
 277                 });
 278                 shutdown.setContextClassLoader(null);
 279                 Runtime.getRuntime().addShutdownHook(shutdown);
 280                 return null;
 281             }
 282         });
 283      }
 284 
 285     public void run() {


 382     }
 383 
 384     public ChoicePeer createChoice(Choice target) {
 385         ChoicePeer peer = new WChoicePeer(target);
 386         targetCreatedPeer(target, peer);
 387         return peer;
 388     }
 389 
 390     public FramePeer  createFrame(Frame target) {
 391         FramePeer peer = new WFramePeer(target);
 392         targetCreatedPeer(target, peer);
 393         return peer;
 394     }
 395 
 396     public CanvasPeer createCanvas(Canvas target) {
 397         CanvasPeer peer = new WCanvasPeer(target);
 398         targetCreatedPeer(target, peer);
 399         return peer;
 400     }
 401 

 402     public void disableBackgroundErase(Canvas canvas) {
 403         WCanvasPeer peer = (WCanvasPeer)canvas.getPeer();
 404         if (peer == null) {
 405             throw new IllegalStateException("Canvas must have a valid peer");
 406         }
 407         peer.disableBackgroundErase();
 408     }
 409 
 410     public PanelPeer createPanel(Panel target) {
 411         PanelPeer peer = new WPanelPeer(target);
 412         targetCreatedPeer(target, peer);
 413         return peer;
 414     }
 415 
 416     public WindowPeer createWindow(Window target) {
 417         WindowPeer peer = new WWindowPeer(target);
 418         targetCreatedPeer(target, peer);
 419         return peer;
 420     }
 421 


 575     protected native int getScreenWidth();
 576     protected native int getScreenHeight();
 577     protected native Insets getScreenInsets(int screen);
 578 
 579 
 580     public FontMetrics getFontMetrics(Font font) {
 581         // This is an unsupported hack, but left in for a customer.
 582         // Do not remove.
 583         FontManager fm = FontManagerFactory.getInstance();
 584         if (fm instanceof SunFontManager
 585             && ((SunFontManager) fm).usePlatformFontMetrics()) {
 586             return WFontMetrics.getFontMetrics(font);
 587         }
 588         return super.getFontMetrics(font);
 589     }
 590 
 591     public FontPeer getFontPeer(String name, int style) {
 592         FontPeer retval = null;
 593         String lcName = name.toLowerCase();
 594         if (null != cacheFontPeer) {
 595             retval = (FontPeer)cacheFontPeer.get(lcName + style);
 596             if (null != retval) {
 597                 return retval;
 598             }
 599         }
 600         retval = new WFontPeer(name, style);
 601         if (retval != null) {
 602             if (null == cacheFontPeer) {
 603                 cacheFontPeer = new Hashtable(5, (float)0.9);
 604             }
 605             if (null != cacheFontPeer) {
 606                 cacheFontPeer.put(lcName + style, retval);
 607             }
 608         }
 609         return retval;
 610     }
 611 
 612     private native void nativeSync();
 613 
 614     public void sync() {
 615         // flush the GDI/DD buffers
 616         nativeSync();
 617         // now flush the OGL pipeline (this is a no-op if OGL is not enabled)
 618         OGLRenderQueue.sync();
 619         // now flush the D3D pipeline (this is a no-op if D3D is not enabled)
 620         D3DRenderQueue.sync();
 621     }
 622 
 623     public PrintJob getPrintJob(Frame frame, String doctitle,


 681     protected native void loadSystemColors(int[] systemColors);
 682 
 683     public static final Object targetToPeer(Object target) {
 684         return SunToolkit.targetToPeer(target);
 685     }
 686 
 687     public static final void targetDisposedPeer(Object target, Object peer) {
 688         SunToolkit.targetDisposedPeer(target, peer);
 689     }
 690 
 691     /**
 692      * Returns a new input method adapter descriptor for native input methods.
 693      */
 694     public InputMethodDescriptor getInputMethodAdapterDescriptor() {
 695         return new WInputMethodDescriptor();
 696     }
 697 
 698     /**
 699      * Returns a style map for the input method highlight.
 700      */
 701     public Map mapInputMethodHighlight(InputMethodHighlight highlight) {


 702         return WInputMethod.mapInputMethodHighlight(highlight);
 703     }
 704 
 705     /**
 706      * Returns whether enableInputMethods should be set to true for peered
 707      * TextComponent instances on this platform.
 708      */
 709     public boolean enableInputMethodsForTextComponent() {
 710         return true;
 711     }
 712 
 713     /**
 714      * Returns the default keyboard locale of the underlying operating system
 715      */
 716     public Locale getDefaultKeyboardLocale() {
 717         Locale locale = WInputMethod.getNativeLocale();
 718 
 719         if (locale == null) {
 720             return super.getDefaultKeyboardLocale();
 721         } else {


 951      * - in some cases with buffer per window enabled it is possible for the
 952      *   paint manager to redirect rendering to the screen for some operations
 953      *   (like copyArea), and since bpw uses its own BufferStrategy the
 954      *   d3d onscreen rendering support is disabled and rendering goes through
 955      *   GDI. This doesn't work well with Vista's DWM since one
 956      *   can not perform GDI and D3D operations on the same surface
 957      *   (see 6630702 for more info)
 958      *
 959      * Note: even though DWM composition state can change during the lifetime
 960      * of the application it is a rare event, and it is more often that it
 961      * is temporarily disabled (because of some app) than it is getting
 962      * permanently enabled so we can live with this approach without the
 963      * complexity of dwm state listeners and such. This can be revisited if
 964      * proved otherwise.
 965      */
 966     @Override
 967     public boolean useBufferPerWindow() {
 968         return !Win32GraphicsEnvironment.isDWMCompositionEnabled();
 969     }
 970 

 971     public void grab(Window w) {
 972         if (w.getPeer() != null) {
 973             ((WWindowPeer)w.getPeer()).grab();
 974         }
 975     }
 976 

 977     public void ungrab(Window w) {
 978         if (w.getPeer() != null) {
 979            ((WWindowPeer)w.getPeer()).ungrab();
 980         }
 981     }
 982 
 983     public native boolean syncNativeQueue(final long timeout);
 984     public boolean isDesktopSupported() {
 985         return true;
 986     }
 987 
 988     public DesktopPeer createDesktopPeer(Desktop target) {
 989         return new WDesktopPeer();
 990     }
 991 
 992     public static native void setExtraMouseButtonsEnabledNative(boolean enable);
 993 
 994     public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
 995         return areExtraMouseButtonsEnabled;
 996     }




  57 import java.util.Locale;
  58 import java.util.Map;
  59 import java.util.Properties;
  60 
  61 import sun.font.FontManager;
  62 import sun.font.FontManagerFactory;
  63 import sun.font.SunFontManager;
  64 import sun.misc.PerformanceLogger;
  65 import sun.util.logging.PlatformLogger;
  66 
  67 public class WToolkit extends SunToolkit implements Runnable {
  68 
  69     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit");
  70 
  71     static GraphicsConfiguration config;
  72 
  73     // System clipboard.
  74     WClipboard clipboard;
  75 
  76     // cache of font peers
  77     private Hashtable<String,FontPeer> cacheFontPeer;
  78 
  79     // Windows properties
  80     private WDesktopProperties  wprops;
  81 
  82     // Dynamic Layout Resize client code setting
  83     protected boolean dynamicLayoutSetting = false;
  84 
  85     //Is it allowed to generate events assigned to extra mouse buttons.
  86     //Set to true by default.
  87     private static boolean areExtraMouseButtonsEnabled = true;
  88 
  89     /**
  90      * Initialize JNI field and method IDs
  91      */
  92     private static native void initIDs();
  93     private static boolean loaded = false;
  94     public static void loadLibraries() {
  95         if (!loaded) {
  96             java.security.AccessController.doPrivileged(
  97                           new sun.security.action.LoadLibraryAction("awt"));
  98             loaded = true;
  99         }
 100     }
 101 
 102     private static native String getWindowsVersion();
 103 
 104     static {
 105         loadLibraries();
 106         initIDs();
 107 
 108         // Print out which version of Windows is running
 109         if (log.isLoggable(PlatformLogger.FINE)) {
 110             log.fine("Win version: " + getWindowsVersion());
 111         }
 112 
 113         AccessController.doPrivileged(
 114             new PrivilegedAction <Void> ()
 115         {
 116             public Void run() {
 117                 String browserProp = System.getProperty("browser");
 118                 if (browserProp != null && browserProp.equals("sun.plugin")) {
 119                     disableCustomPalette();
 120                 }
 121                 return null;
 122             }
 123         });
 124     }
 125 
 126     private static native void disableCustomPalette();
 127 
 128     /*
 129      * Reset the static GraphicsConfiguration to the default.  Called on
 130      * startup and when display settings have changed.
 131      */
 132     public static void resetGC() {
 133         if (GraphicsEnvironment.isHeadless()) {
 134             config = null;
 135         } else {
 136           config = (GraphicsEnvironment


 244                     wait();
 245                 }
 246             }
 247         } catch (InterruptedException x) {
 248             // swallow the exception
 249         }
 250 
 251         SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);
 252 
 253         // Enabled "live resizing" by default.  It remains controlled
 254         // by the native system though.
 255         setDynamicLayout(true);
 256 
 257         areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
 258         //set system property if not yet assigned
 259         System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
 260         setExtraMouseButtonsEnabledNative(areExtraMouseButtonsEnabled);
 261     }
 262 
 263     private final void registerShutdownHook() {
 264         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 265             public Void run() {
 266                 ThreadGroup currentTG =
 267                     Thread.currentThread().getThreadGroup();
 268                 ThreadGroup parentTG = currentTG.getParent();
 269                 while (parentTG != null) {
 270                     currentTG = parentTG;
 271                     parentTG = currentTG.getParent();
 272                 }
 273                 Thread shutdown = new Thread(currentTG, new Runnable() {
 274                     public void run() {
 275                         shutdown();
 276                     }
 277                 });
 278                 shutdown.setContextClassLoader(null);
 279                 Runtime.getRuntime().addShutdownHook(shutdown);
 280                 return null;
 281             }
 282         });
 283      }
 284 
 285     public void run() {


 382     }
 383 
 384     public ChoicePeer createChoice(Choice target) {
 385         ChoicePeer peer = new WChoicePeer(target);
 386         targetCreatedPeer(target, peer);
 387         return peer;
 388     }
 389 
 390     public FramePeer  createFrame(Frame target) {
 391         FramePeer peer = new WFramePeer(target);
 392         targetCreatedPeer(target, peer);
 393         return peer;
 394     }
 395 
 396     public CanvasPeer createCanvas(Canvas target) {
 397         CanvasPeer peer = new WCanvasPeer(target);
 398         targetCreatedPeer(target, peer);
 399         return peer;
 400     }
 401 
 402     @SuppressWarnings("deprecation")
 403     public void disableBackgroundErase(Canvas canvas) {
 404         WCanvasPeer peer = (WCanvasPeer)canvas.getPeer();
 405         if (peer == null) {
 406             throw new IllegalStateException("Canvas must have a valid peer");
 407         }
 408         peer.disableBackgroundErase();
 409     }
 410 
 411     public PanelPeer createPanel(Panel target) {
 412         PanelPeer peer = new WPanelPeer(target);
 413         targetCreatedPeer(target, peer);
 414         return peer;
 415     }
 416 
 417     public WindowPeer createWindow(Window target) {
 418         WindowPeer peer = new WWindowPeer(target);
 419         targetCreatedPeer(target, peer);
 420         return peer;
 421     }
 422 


 576     protected native int getScreenWidth();
 577     protected native int getScreenHeight();
 578     protected native Insets getScreenInsets(int screen);
 579 
 580 
 581     public FontMetrics getFontMetrics(Font font) {
 582         // This is an unsupported hack, but left in for a customer.
 583         // Do not remove.
 584         FontManager fm = FontManagerFactory.getInstance();
 585         if (fm instanceof SunFontManager
 586             && ((SunFontManager) fm).usePlatformFontMetrics()) {
 587             return WFontMetrics.getFontMetrics(font);
 588         }
 589         return super.getFontMetrics(font);
 590     }
 591 
 592     public FontPeer getFontPeer(String name, int style) {
 593         FontPeer retval = null;
 594         String lcName = name.toLowerCase();
 595         if (null != cacheFontPeer) {
 596             retval = cacheFontPeer.get(lcName + style);
 597             if (null != retval) {
 598                 return retval;
 599             }
 600         }
 601         retval = new WFontPeer(name, style);
 602         if (retval != null) {
 603             if (null == cacheFontPeer) {
 604                 cacheFontPeer = new Hashtable<>(5, 0.9f);
 605             }
 606             if (null != cacheFontPeer) {
 607                 cacheFontPeer.put(lcName + style, retval);
 608             }
 609         }
 610         return retval;
 611     }
 612 
 613     private native void nativeSync();
 614 
 615     public void sync() {
 616         // flush the GDI/DD buffers
 617         nativeSync();
 618         // now flush the OGL pipeline (this is a no-op if OGL is not enabled)
 619         OGLRenderQueue.sync();
 620         // now flush the D3D pipeline (this is a no-op if D3D is not enabled)
 621         D3DRenderQueue.sync();
 622     }
 623 
 624     public PrintJob getPrintJob(Frame frame, String doctitle,


 682     protected native void loadSystemColors(int[] systemColors);
 683 
 684     public static final Object targetToPeer(Object target) {
 685         return SunToolkit.targetToPeer(target);
 686     }
 687 
 688     public static final void targetDisposedPeer(Object target, Object peer) {
 689         SunToolkit.targetDisposedPeer(target, peer);
 690     }
 691 
 692     /**
 693      * Returns a new input method adapter descriptor for native input methods.
 694      */
 695     public InputMethodDescriptor getInputMethodAdapterDescriptor() {
 696         return new WInputMethodDescriptor();
 697     }
 698 
 699     /**
 700      * Returns a style map for the input method highlight.
 701      */
 702     public Map<java.awt.font.TextAttribute,?> mapInputMethodHighlight(
 703         InputMethodHighlight highlight)
 704     {
 705         return WInputMethod.mapInputMethodHighlight(highlight);
 706     }
 707 
 708     /**
 709      * Returns whether enableInputMethods should be set to true for peered
 710      * TextComponent instances on this platform.
 711      */
 712     public boolean enableInputMethodsForTextComponent() {
 713         return true;
 714     }
 715 
 716     /**
 717      * Returns the default keyboard locale of the underlying operating system
 718      */
 719     public Locale getDefaultKeyboardLocale() {
 720         Locale locale = WInputMethod.getNativeLocale();
 721 
 722         if (locale == null) {
 723             return super.getDefaultKeyboardLocale();
 724         } else {


 954      * - in some cases with buffer per window enabled it is possible for the
 955      *   paint manager to redirect rendering to the screen for some operations
 956      *   (like copyArea), and since bpw uses its own BufferStrategy the
 957      *   d3d onscreen rendering support is disabled and rendering goes through
 958      *   GDI. This doesn't work well with Vista's DWM since one
 959      *   can not perform GDI and D3D operations on the same surface
 960      *   (see 6630702 for more info)
 961      *
 962      * Note: even though DWM composition state can change during the lifetime
 963      * of the application it is a rare event, and it is more often that it
 964      * is temporarily disabled (because of some app) than it is getting
 965      * permanently enabled so we can live with this approach without the
 966      * complexity of dwm state listeners and such. This can be revisited if
 967      * proved otherwise.
 968      */
 969     @Override
 970     public boolean useBufferPerWindow() {
 971         return !Win32GraphicsEnvironment.isDWMCompositionEnabled();
 972     }
 973 
 974     @SuppressWarnings("deprecation")
 975     public void grab(Window w) {
 976         if (w.getPeer() != null) {
 977             ((WWindowPeer)w.getPeer()).grab();
 978         }
 979     }
 980 
 981     @SuppressWarnings("deprecation")
 982     public void ungrab(Window w) {
 983         if (w.getPeer() != null) {
 984            ((WWindowPeer)w.getPeer()).ungrab();
 985         }
 986     }
 987 
 988     public native boolean syncNativeQueue(final long timeout);
 989     public boolean isDesktopSupported() {
 990         return true;
 991     }
 992 
 993     public DesktopPeer createDesktopPeer(Desktop target) {
 994         return new WDesktopPeer();
 995     }
 996 
 997     public static native void setExtraMouseButtonsEnabledNative(boolean enable);
 998 
 999     public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
1000         return areExtraMouseButtonsEnabled;
1001     }