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

Print this page




 205                         // what do we do if surface creation fails?
 206                     }
 207                 }
 208 
 209                 // Forcing a paint here doesn't seem to be necessary.
 210                 // paintDamagedAreaImmediately();
 211             }
 212         });
 213     }
 214 
 215     /*
 216      * Paints any portion of the component that needs updating
 217      * before the call returns (similar to the Win32 API UpdateWindow)
 218      */
 219     void paintDamagedAreaImmediately() {
 220         // force Windows to send any pending WM_PAINT events so
 221         // the damage area is updated on the Java side
 222         updateWindow();
 223         // make sure paint events are transferred to main event queue
 224         // for coalescing
 225         WToolkit.getWToolkit().flushPendingEvents();
 226         // paint the damaged area
 227         paintArea.paint(target, shouldClearRectBeforePaint());
 228     }
 229 
 230     native synchronized void updateWindow();
 231 
 232     public void paint(Graphics g) {
 233         ((Component)target).paint(g);
 234     }
 235 
 236     public void repaint(long tm, int x, int y, int width, int height) {
 237     }
 238 
 239     private static final double BANDING_DIVISOR = 4.0;
 240     private native int[] createPrintedPixels(int srcX, int srcY,
 241                                              int srcW, int srcH,
 242                                              int alpha);
 243     public void print(Graphics g) {
 244 
 245         Component comp = (Component)target;


 303     // on handling '\n' to prevent it from being passed to native code
 304     public boolean handleJavaKeyEvent(KeyEvent e) { return false; }
 305 
 306     public void handleJavaMouseEvent(MouseEvent e) {
 307         switch (e.getID()) {
 308           case MouseEvent.MOUSE_PRESSED:
 309               // Note that Swing requests focus in its own mouse event handler.
 310               if (target == e.getSource() &&
 311                   !((Component)target).isFocusOwner() &&
 312                   WKeyboardFocusManagerPeer.shouldFocusOnClick((Component)target))
 313               {
 314                   WKeyboardFocusManagerPeer.requestFocusFor((Component)target,
 315                                                             CausedFocusEvent.Cause.MOUSE_EVENT);
 316               }
 317               break;
 318         }
 319     }
 320 
 321     native void nativeHandleEvent(AWTEvent e);
 322 

 323     public void handleEvent(AWTEvent e) {
 324         int id = e.getID();
 325 
 326         if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() &&
 327             ((Component)target).isEnabled())
 328         {
 329             if (e instanceof MouseEvent && !(e instanceof MouseWheelEvent)) {
 330                 handleJavaMouseEvent((MouseEvent) e);
 331             } else if (e instanceof KeyEvent) {
 332                 if (handleJavaKeyEvent((KeyEvent)e)) {
 333                     return;
 334                 }
 335             }
 336         }
 337 
 338         switch(id) {
 339             case PaintEvent.PAINT:
 340                 // Got native painting
 341                 paintPending = false;
 342                 // Fallthrough to next statement


 532     }
 533 
 534     //Returns null for Components not yet added to a Container
 535     public ColorModel getColorModel(int transparency) {
 536 //      return WToolkit.config.getColorModel(transparency);
 537         GraphicsConfiguration gc = getGraphicsConfiguration();
 538         if (gc != null) {
 539             return gc.getColorModel(transparency);
 540         }
 541         else {
 542             return null;
 543         }
 544     }
 545     public java.awt.Toolkit getToolkit() {
 546         return Toolkit.getDefaultToolkit();
 547     }
 548 
 549     // fallback default font object
 550     final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
 551 

 552     public Graphics getGraphics() {
 553         if (isDisposed()) {
 554             return null;
 555         }
 556 
 557         Component target = (Component)getTarget();
 558         Window window = SunToolkit.getContainingWindow(target);
 559         if (window != null) {
 560             Graphics g =
 561                 ((WWindowPeer)window.getPeer()).getTranslucentGraphics();
 562             // getTranslucentGraphics() returns non-null value for non-opaque windows only
 563             if (g != null) {
 564                 // Non-opaque windows do not support heavyweight children.
 565                 // Redirect all painting to the Window's Graphics instead.
 566                 // The caller is responsible for calling the
 567                 // WindowPeer.updateWindow() after painting has finished.
 568                 int x = 0, y = 0;
 569                 for (Component c = target; c != window; c = c.getParent()) {
 570                     x += c.getX();
 571                     y += c.getY();


 639      *
 640      * @see sun.java2d.d3d.D3DScreenUpdateManager#validate(D3DWindowSurfaceData)
 641      */
 642     public Color getBackgroundNoSync() {
 643         return background;
 644     }
 645 
 646     public native void _setForeground(int rgb);
 647     public native void _setBackground(int rgb);
 648 
 649     public synchronized void setFont(Font f) {
 650         font = f;
 651         _setFont(f);
 652     }
 653     public synchronized native void _setFont(Font f);
 654     public final void updateCursorImmediately() {
 655         WGlobalCursorManager.getCursorManager().updateCursorImmediately();
 656     }
 657 
 658     // TODO: consider moving it to KeyboardFocusManagerPeerImpl

 659     public boolean requestFocus(Component lightweightChild, boolean temporary,
 660                                 boolean focusedWindowChangeAllowed, long time,
 661                                 CausedFocusEvent.Cause cause)
 662     {
 663         if (WKeyboardFocusManagerPeer.
 664             processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
 665                                                   focusedWindowChangeAllowed, time))
 666         {
 667             return true;
 668         }
 669 
 670         int result = WKeyboardFocusManagerPeer
 671             .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
 672                                             temporary, focusedWindowChangeAllowed,
 673                                             time, cause);
 674 
 675         switch (result) {
 676           case WKeyboardFocusManagerPeer.SNFH_FAILURE:
 677               return false;
 678           case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:


1041         // these problems are no longer present in Vista
1042         return !isTranslucent || Win32GraphicsEnvironment.isVistaOS();
1043     }
1044 
1045     /**
1046      * Disables acceleration for this peer.
1047      */
1048     public void disableAcceleration() {
1049         isAccelCapable = false;
1050     }
1051 
1052 
1053     native void setRectangularShape(int lox, int loy, int hix, int hiy,
1054                      Region region);
1055 
1056 
1057     // REMIND: Temp workaround for issues with using HW acceleration
1058     // in the browser on Vista when DWM is enabled.
1059     // @return true if the toplevel container is not an EmbeddedFrame or
1060     // if this EmbeddedFrame is acceleration capable, false otherwise

1061     private static final boolean isContainingTopLevelAccelCapable(Component c) {
1062         while (c != null && !(c instanceof WEmbeddedFrame)) {
1063             c = c.getParent();
1064         }
1065         if (c == null) {
1066             return true;
1067         }
1068         return ((WEmbeddedFramePeer)c.getPeer()).isAccelCapable();
1069     }
1070 
1071     /**
1072      * Applies the shape to the native component window.
1073      * @since 1.7
1074      */

1075     public void applyShape(Region shape) {
1076         if (shapeLog.isLoggable(PlatformLogger.FINER)) {
1077             shapeLog.finer(
1078                     "*** INFO: Setting shape: PEER: " + this
1079                     + "; TARGET: " + target
1080                     + "; SHAPE: " + shape);
1081         }
1082 
1083         if (shape != null) {
1084             setRectangularShape(shape.getLoX(), shape.getLoY(), shape.getHiX(), shape.getHiY(),
1085                     (shape.isRectangular() ? null : shape));
1086         } else {
1087             setRectangularShape(0, 0, 0, 0, null);
1088         }
1089     }
1090 
1091     /**
1092      * Lowers this component at the bottom of the above component. If the above parameter
1093      * is null then the method places this component at the top of the Z-order.
1094      */


 205                         // what do we do if surface creation fails?
 206                     }
 207                 }
 208 
 209                 // Forcing a paint here doesn't seem to be necessary.
 210                 // paintDamagedAreaImmediately();
 211             }
 212         });
 213     }
 214 
 215     /*
 216      * Paints any portion of the component that needs updating
 217      * before the call returns (similar to the Win32 API UpdateWindow)
 218      */
 219     void paintDamagedAreaImmediately() {
 220         // force Windows to send any pending WM_PAINT events so
 221         // the damage area is updated on the Java side
 222         updateWindow();
 223         // make sure paint events are transferred to main event queue
 224         // for coalescing
 225         SunToolkit.flushPendingEvents();
 226         // paint the damaged area
 227         paintArea.paint(target, shouldClearRectBeforePaint());
 228     }
 229 
 230     native synchronized void updateWindow();
 231 
 232     public void paint(Graphics g) {
 233         ((Component)target).paint(g);
 234     }
 235 
 236     public void repaint(long tm, int x, int y, int width, int height) {
 237     }
 238 
 239     private static final double BANDING_DIVISOR = 4.0;
 240     private native int[] createPrintedPixels(int srcX, int srcY,
 241                                              int srcW, int srcH,
 242                                              int alpha);
 243     public void print(Graphics g) {
 244 
 245         Component comp = (Component)target;


 303     // on handling '\n' to prevent it from being passed to native code
 304     public boolean handleJavaKeyEvent(KeyEvent e) { return false; }
 305 
 306     public void handleJavaMouseEvent(MouseEvent e) {
 307         switch (e.getID()) {
 308           case MouseEvent.MOUSE_PRESSED:
 309               // Note that Swing requests focus in its own mouse event handler.
 310               if (target == e.getSource() &&
 311                   !((Component)target).isFocusOwner() &&
 312                   WKeyboardFocusManagerPeer.shouldFocusOnClick((Component)target))
 313               {
 314                   WKeyboardFocusManagerPeer.requestFocusFor((Component)target,
 315                                                             CausedFocusEvent.Cause.MOUSE_EVENT);
 316               }
 317               break;
 318         }
 319     }
 320 
 321     native void nativeHandleEvent(AWTEvent e);
 322 
 323     @SuppressWarnings("fallthrough")
 324     public void handleEvent(AWTEvent e) {
 325         int id = e.getID();
 326 
 327         if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() &&
 328             ((Component)target).isEnabled())
 329         {
 330             if (e instanceof MouseEvent && !(e instanceof MouseWheelEvent)) {
 331                 handleJavaMouseEvent((MouseEvent) e);
 332             } else if (e instanceof KeyEvent) {
 333                 if (handleJavaKeyEvent((KeyEvent)e)) {
 334                     return;
 335                 }
 336             }
 337         }
 338 
 339         switch(id) {
 340             case PaintEvent.PAINT:
 341                 // Got native painting
 342                 paintPending = false;
 343                 // Fallthrough to next statement


 533     }
 534 
 535     //Returns null for Components not yet added to a Container
 536     public ColorModel getColorModel(int transparency) {
 537 //      return WToolkit.config.getColorModel(transparency);
 538         GraphicsConfiguration gc = getGraphicsConfiguration();
 539         if (gc != null) {
 540             return gc.getColorModel(transparency);
 541         }
 542         else {
 543             return null;
 544         }
 545     }
 546     public java.awt.Toolkit getToolkit() {
 547         return Toolkit.getDefaultToolkit();
 548     }
 549 
 550     // fallback default font object
 551     final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
 552 
 553     @SuppressWarnings("deprecation")
 554     public Graphics getGraphics() {
 555         if (isDisposed()) {
 556             return null;
 557         }
 558 
 559         Component target = (Component)getTarget();
 560         Window window = SunToolkit.getContainingWindow(target);
 561         if (window != null) {
 562             Graphics g =
 563                 ((WWindowPeer)window.getPeer()).getTranslucentGraphics();
 564             // getTranslucentGraphics() returns non-null value for non-opaque windows only
 565             if (g != null) {
 566                 // Non-opaque windows do not support heavyweight children.
 567                 // Redirect all painting to the Window's Graphics instead.
 568                 // The caller is responsible for calling the
 569                 // WindowPeer.updateWindow() after painting has finished.
 570                 int x = 0, y = 0;
 571                 for (Component c = target; c != window; c = c.getParent()) {
 572                     x += c.getX();
 573                     y += c.getY();


 641      *
 642      * @see sun.java2d.d3d.D3DScreenUpdateManager#validate(D3DWindowSurfaceData)
 643      */
 644     public Color getBackgroundNoSync() {
 645         return background;
 646     }
 647 
 648     public native void _setForeground(int rgb);
 649     public native void _setBackground(int rgb);
 650 
 651     public synchronized void setFont(Font f) {
 652         font = f;
 653         _setFont(f);
 654     }
 655     public synchronized native void _setFont(Font f);
 656     public final void updateCursorImmediately() {
 657         WGlobalCursorManager.getCursorManager().updateCursorImmediately();
 658     }
 659 
 660     // TODO: consider moving it to KeyboardFocusManagerPeerImpl
 661     @SuppressWarnings("deprecation")
 662     public boolean requestFocus(Component lightweightChild, boolean temporary,
 663                                 boolean focusedWindowChangeAllowed, long time,
 664                                 CausedFocusEvent.Cause cause)
 665     {
 666         if (WKeyboardFocusManagerPeer.
 667             processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
 668                                                   focusedWindowChangeAllowed, time))
 669         {
 670             return true;
 671         }
 672 
 673         int result = WKeyboardFocusManagerPeer
 674             .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
 675                                             temporary, focusedWindowChangeAllowed,
 676                                             time, cause);
 677 
 678         switch (result) {
 679           case WKeyboardFocusManagerPeer.SNFH_FAILURE:
 680               return false;
 681           case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:


1044         // these problems are no longer present in Vista
1045         return !isTranslucent || Win32GraphicsEnvironment.isVistaOS();
1046     }
1047 
1048     /**
1049      * Disables acceleration for this peer.
1050      */
1051     public void disableAcceleration() {
1052         isAccelCapable = false;
1053     }
1054 
1055 
1056     native void setRectangularShape(int lox, int loy, int hix, int hiy,
1057                      Region region);
1058 
1059 
1060     // REMIND: Temp workaround for issues with using HW acceleration
1061     // in the browser on Vista when DWM is enabled.
1062     // @return true if the toplevel container is not an EmbeddedFrame or
1063     // if this EmbeddedFrame is acceleration capable, false otherwise
1064     @SuppressWarnings("deprecation")
1065     private static final boolean isContainingTopLevelAccelCapable(Component c) {
1066         while (c != null && !(c instanceof WEmbeddedFrame)) {
1067             c = c.getParent();
1068         }
1069         if (c == null) {
1070             return true;
1071         }
1072         return ((WEmbeddedFramePeer)c.getPeer()).isAccelCapable();
1073     }
1074 
1075     /**
1076      * Applies the shape to the native component window.
1077      * @since 1.7
1078      */
1079     @SuppressWarnings("deprecation")
1080     public void applyShape(Region shape) {
1081         if (shapeLog.isLoggable(PlatformLogger.FINER)) {
1082             shapeLog.finer(
1083                     "*** INFO: Setting shape: PEER: " + this
1084                     + "; TARGET: " + target
1085                     + "; SHAPE: " + shape);
1086         }
1087 
1088         if (shape != null) {
1089             setRectangularShape(shape.getLoX(), shape.getLoY(), shape.getHiX(), shape.getHiY(),
1090                     (shape.isRectangular() ? null : shape));
1091         } else {
1092             setRectangularShape(0, 0, 0, 0, null);
1093         }
1094     }
1095 
1096     /**
1097      * Lowers this component at the bottom of the above component. If the above parameter
1098      * is null then the method places this component at the top of the Z-order.
1099      */