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

Print this page




 160             // for a resize; a simple move should not trigger a recreation
 161             try {
 162                 replaceSurfaceData();
 163             } catch (InvalidPipeException e) {
 164                 // REMIND : what do we do if our surface creation failed?
 165             }
 166             oldWidth = width;
 167             oldHeight = height;
 168         }
 169 
 170         serialNum++;
 171     }
 172 
 173     /*
 174      * Called from native code (on Toolkit thread) in order to
 175      * dynamically layout the Container during resizing
 176      */
 177     void dynamicallyLayoutContainer() {
 178         // If we got the WM_SIZING, this must be a Container, right?
 179         // In fact, it must be the top-level Container.
 180         if (log.isLoggable(PlatformLogger.FINE)) {
 181             Container parent = WToolkit.getNativeContainer((Component)target);
 182             if (parent != null) {
 183                 log.fine("Assertion (parent == null) failed");
 184             }
 185         }
 186         final Container cont = (Container)target;
 187 
 188         WToolkit.executeOnEventHandlerThread(cont, new Runnable() {
 189             public void run() {
 190                 // Discarding old paint events doesn't seem to be necessary.
 191                 cont.invalidate();
 192                 cont.validate();
 193 
 194                 if (surfaceData instanceof D3DSurfaceData.D3DWindowSurfaceData ||
 195                     surfaceData instanceof OGLSurfaceData)
 196                 {
 197                     // When OGL or D3D is enabled, it is necessary to
 198                     // replace the SurfaceData for each dynamic layout
 199                     // request so that the viewport stays in sync
 200                     // with the window bounds.


 265             int[] pix = createPrintedPixels(0, startY, totalW, h,
 266                                             bgColor == null ? 255 : bgColor.getAlpha());
 267             if (pix != null) {
 268                 BufferedImage bim = new BufferedImage(totalW, h,
 269                                               BufferedImage.TYPE_INT_ARGB);
 270                 bim.setRGB(0, 0, totalW, h, pix, 0, totalW);
 271                 g.drawImage(bim, 0, startY, null);
 272                 bim.flush();
 273             }
 274         }
 275 
 276         comp.print(g);
 277     }
 278 
 279     public void coalescePaintEvent(PaintEvent e) {
 280         Rectangle r = e.getUpdateRect();
 281         if (!(e instanceof IgnorePaintEvent)) {
 282             paintArea.add(r, e.getID());
 283         }
 284 
 285         if (log.isLoggable(PlatformLogger.FINEST)) {
 286             switch(e.getID()) {
 287             case PaintEvent.UPDATE:
 288                 log.finest("coalescePaintEvent: UPDATE: add: x = " +
 289                     r.x + ", y = " + r.y + ", width = " + r.width + ", height = " + r.height);
 290                 return;
 291             case PaintEvent.PAINT:
 292                 log.finest("coalescePaintEvent: PAINT: add: x = " +
 293                     r.x + ", y = " + r.y + ", width = " + r.width + ", height = " + r.height);
 294                 return;
 295             }
 296         }
 297     }
 298 
 299     public synchronized native void reshape(int x, int y, int width, int height);
 300 
 301     // returns true if the event has been handled and shouldn't be propagated
 302     // though handleEvent method chain - e.g. WTextFieldPeer returns true
 303     // on handling '\n' to prevent it from being passed to native code
 304     public boolean handleJavaKeyEvent(KeyEvent e) { return false; }
 305 


 343                 // Fallthrough to next statement
 344             case PaintEvent.UPDATE:
 345                 // Skip all painting while layouting and all UPDATEs
 346                 // while waiting for native paint
 347                 if (!isLayouting && ! paintPending) {
 348                     paintArea.paint(target,shouldClearRectBeforePaint());
 349                 }
 350                 return;
 351             case FocusEvent.FOCUS_LOST:
 352             case FocusEvent.FOCUS_GAINED:
 353                 handleJavaFocusEvent((FocusEvent)e);
 354             default:
 355             break;
 356         }
 357 
 358         // Call the native code
 359         nativeHandleEvent(e);
 360     }
 361 
 362     void handleJavaFocusEvent(FocusEvent fe) {
 363         if (focusLog.isLoggable(PlatformLogger.FINER)) {
 364             focusLog.finer(fe.toString());
 365         }
 366         setFocus(fe.getID() == FocusEvent.FOCUS_GAINED);
 367     }
 368 
 369     native void setFocus(boolean doSetFocus);
 370 
 371     public Dimension getMinimumSize() {
 372         return ((Component)target).getSize();
 373     }
 374 
 375     public Dimension getPreferredSize() {
 376         return getMinimumSize();
 377     }
 378 
 379     // Do nothing for heavyweight implementation
 380     public void layout() {}
 381 
 382     public Rectangle getBounds() {
 383         return ((Component)target).getBounds();


 665     public boolean requestFocus(Component lightweightChild, boolean temporary,
 666                                 boolean focusedWindowChangeAllowed, long time,
 667                                 CausedFocusEvent.Cause cause)
 668     {
 669         if (WKeyboardFocusManagerPeer.
 670             processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
 671                                                   focusedWindowChangeAllowed, time))
 672         {
 673             return true;
 674         }
 675 
 676         int result = WKeyboardFocusManagerPeer
 677             .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
 678                                             temporary, focusedWindowChangeAllowed,
 679                                             time, cause);
 680 
 681         switch (result) {
 682           case WKeyboardFocusManagerPeer.SNFH_FAILURE:
 683               return false;
 684           case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
 685               if (focusLog.isLoggable(PlatformLogger.FINER)) {
 686                   focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
 687               }
 688               Window parentWindow = SunToolkit.getContainingWindow((Component)target);
 689               if (parentWindow == null) {
 690                   return rejectFocusRequestHelper("WARNING: Parent window is null");
 691               }
 692               WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
 693               if (wpeer == null) {
 694                   return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
 695               }
 696               boolean res = wpeer.requestWindowFocus(cause);
 697 
 698               if (focusLog.isLoggable(PlatformLogger.FINER)) {
 699                   focusLog.finer("Requested window focus: " + res);
 700               }
 701               // If parent window can be made focused and has been made focused(synchronously)
 702               // then we can proceed with children, otherwise we retreat.
 703               if (!(res && parentWindow.isFocused())) {
 704                   return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
 705               }
 706               return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
 707                                                             (Component)target,
 708                                                             temporary,
 709                                                             focusedWindowChangeAllowed,
 710                                                             time, cause);
 711 
 712           case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
 713               // Either lightweight or excessive request - all events are generated.
 714               return true;
 715         }
 716         return false;
 717     }
 718 
 719     private boolean rejectFocusRequestHelper(String logMsg) {
 720         if (focusLog.isLoggable(PlatformLogger.FINER)) {
 721             focusLog.finer(logMsg);
 722         }
 723         WKeyboardFocusManagerPeer.removeLastFocusRequest((Component)target);
 724         return false;
 725     }
 726 
 727     public Image createImage(ImageProducer producer) {
 728         return new ToolkitImage(producer);
 729     }
 730 
 731     public Image createImage(int width, int height) {
 732         Win32GraphicsConfig gc =
 733             (Win32GraphicsConfig)getGraphicsConfiguration();
 734         return gc.createAcceleratedImage((Component)target, width, height);
 735     }
 736 
 737     public VolatileImage createVolatileImage(int width, int height) {
 738         return new SunVolatileImage((Component)target, width, height);
 739     }
 740 


1077     // in the browser on Vista when DWM is enabled.
1078     // @return true if the toplevel container is not an EmbeddedFrame or
1079     // if this EmbeddedFrame is acceleration capable, false otherwise
1080     @SuppressWarnings("deprecation")
1081     private static final boolean isContainingTopLevelAccelCapable(Component c) {
1082         while (c != null && !(c instanceof WEmbeddedFrame)) {
1083             c = c.getParent();
1084         }
1085         if (c == null) {
1086             return true;
1087         }
1088         return ((WEmbeddedFramePeer)c.getPeer()).isAccelCapable();
1089     }
1090 
1091     /**
1092      * Applies the shape to the native component window.
1093      * @since 1.7
1094      */
1095     @SuppressWarnings("deprecation")
1096     public void applyShape(Region shape) {
1097         if (shapeLog.isLoggable(PlatformLogger.FINER)) {
1098             shapeLog.finer("*** INFO: Setting shape: PEER: " + this
1099                             + "; TARGET: " + target
1100                             + "; SHAPE: " + shape);
1101         }
1102 
1103         if (shape != null) {
1104             setRectangularShape(shape.getLoX(), shape.getLoY(), shape.getHiX(), shape.getHiY(),
1105                     (shape.isRectangular() ? null : shape));
1106         } else {
1107             setRectangularShape(0, 0, 0, 0, null);
1108         }
1109     }
1110 
1111     /**
1112      * Lowers this component at the bottom of the above component. If the above parameter
1113      * is null then the method places this component at the top of the Z-order.
1114      */
1115     public void setZOrder(ComponentPeer above) {
1116         long aboveHWND = (above != null) ? ((WComponentPeer)above).getHWnd() : 0;
1117 


 160             // for a resize; a simple move should not trigger a recreation
 161             try {
 162                 replaceSurfaceData();
 163             } catch (InvalidPipeException e) {
 164                 // REMIND : what do we do if our surface creation failed?
 165             }
 166             oldWidth = width;
 167             oldHeight = height;
 168         }
 169 
 170         serialNum++;
 171     }
 172 
 173     /*
 174      * Called from native code (on Toolkit thread) in order to
 175      * dynamically layout the Container during resizing
 176      */
 177     void dynamicallyLayoutContainer() {
 178         // If we got the WM_SIZING, this must be a Container, right?
 179         // In fact, it must be the top-level Container.
 180         if (log.isLoggable(PlatformLogger.Level.FINE)) {
 181             Container parent = WToolkit.getNativeContainer((Component)target);
 182             if (parent != null) {
 183                 log.fine("Assertion (parent == null) failed");
 184             }
 185         }
 186         final Container cont = (Container)target;
 187 
 188         WToolkit.executeOnEventHandlerThread(cont, new Runnable() {
 189             public void run() {
 190                 // Discarding old paint events doesn't seem to be necessary.
 191                 cont.invalidate();
 192                 cont.validate();
 193 
 194                 if (surfaceData instanceof D3DSurfaceData.D3DWindowSurfaceData ||
 195                     surfaceData instanceof OGLSurfaceData)
 196                 {
 197                     // When OGL or D3D is enabled, it is necessary to
 198                     // replace the SurfaceData for each dynamic layout
 199                     // request so that the viewport stays in sync
 200                     // with the window bounds.


 265             int[] pix = createPrintedPixels(0, startY, totalW, h,
 266                                             bgColor == null ? 255 : bgColor.getAlpha());
 267             if (pix != null) {
 268                 BufferedImage bim = new BufferedImage(totalW, h,
 269                                               BufferedImage.TYPE_INT_ARGB);
 270                 bim.setRGB(0, 0, totalW, h, pix, 0, totalW);
 271                 g.drawImage(bim, 0, startY, null);
 272                 bim.flush();
 273             }
 274         }
 275 
 276         comp.print(g);
 277     }
 278 
 279     public void coalescePaintEvent(PaintEvent e) {
 280         Rectangle r = e.getUpdateRect();
 281         if (!(e instanceof IgnorePaintEvent)) {
 282             paintArea.add(r, e.getID());
 283         }
 284 
 285         if (log.isLoggable(PlatformLogger.Level.FINEST)) {
 286             switch(e.getID()) {
 287             case PaintEvent.UPDATE:
 288                 log.finest("coalescePaintEvent: UPDATE: add: x = " +
 289                     r.x + ", y = " + r.y + ", width = " + r.width + ", height = " + r.height);
 290                 return;
 291             case PaintEvent.PAINT:
 292                 log.finest("coalescePaintEvent: PAINT: add: x = " +
 293                     r.x + ", y = " + r.y + ", width = " + r.width + ", height = " + r.height);
 294                 return;
 295             }
 296         }
 297     }
 298 
 299     public synchronized native void reshape(int x, int y, int width, int height);
 300 
 301     // returns true if the event has been handled and shouldn't be propagated
 302     // though handleEvent method chain - e.g. WTextFieldPeer returns true
 303     // on handling '\n' to prevent it from being passed to native code
 304     public boolean handleJavaKeyEvent(KeyEvent e) { return false; }
 305 


 343                 // Fallthrough to next statement
 344             case PaintEvent.UPDATE:
 345                 // Skip all painting while layouting and all UPDATEs
 346                 // while waiting for native paint
 347                 if (!isLayouting && ! paintPending) {
 348                     paintArea.paint(target,shouldClearRectBeforePaint());
 349                 }
 350                 return;
 351             case FocusEvent.FOCUS_LOST:
 352             case FocusEvent.FOCUS_GAINED:
 353                 handleJavaFocusEvent((FocusEvent)e);
 354             default:
 355             break;
 356         }
 357 
 358         // Call the native code
 359         nativeHandleEvent(e);
 360     }
 361 
 362     void handleJavaFocusEvent(FocusEvent fe) {
 363         if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 364             focusLog.finer(fe.toString());
 365         }
 366         setFocus(fe.getID() == FocusEvent.FOCUS_GAINED);
 367     }
 368 
 369     native void setFocus(boolean doSetFocus);
 370 
 371     public Dimension getMinimumSize() {
 372         return ((Component)target).getSize();
 373     }
 374 
 375     public Dimension getPreferredSize() {
 376         return getMinimumSize();
 377     }
 378 
 379     // Do nothing for heavyweight implementation
 380     public void layout() {}
 381 
 382     public Rectangle getBounds() {
 383         return ((Component)target).getBounds();


 665     public boolean requestFocus(Component lightweightChild, boolean temporary,
 666                                 boolean focusedWindowChangeAllowed, long time,
 667                                 CausedFocusEvent.Cause cause)
 668     {
 669         if (WKeyboardFocusManagerPeer.
 670             processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
 671                                                   focusedWindowChangeAllowed, time))
 672         {
 673             return true;
 674         }
 675 
 676         int result = WKeyboardFocusManagerPeer
 677             .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
 678                                             temporary, focusedWindowChangeAllowed,
 679                                             time, cause);
 680 
 681         switch (result) {
 682           case WKeyboardFocusManagerPeer.SNFH_FAILURE:
 683               return false;
 684           case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
 685               if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 686                   focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
 687               }
 688               Window parentWindow = SunToolkit.getContainingWindow((Component)target);
 689               if (parentWindow == null) {
 690                   return rejectFocusRequestHelper("WARNING: Parent window is null");
 691               }
 692               WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
 693               if (wpeer == null) {
 694                   return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
 695               }
 696               boolean res = wpeer.requestWindowFocus(cause);
 697 
 698               if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 699                   focusLog.finer("Requested window focus: " + res);
 700               }
 701               // If parent window can be made focused and has been made focused(synchronously)
 702               // then we can proceed with children, otherwise we retreat.
 703               if (!(res && parentWindow.isFocused())) {
 704                   return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
 705               }
 706               return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
 707                                                             (Component)target,
 708                                                             temporary,
 709                                                             focusedWindowChangeAllowed,
 710                                                             time, cause);
 711 
 712           case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
 713               // Either lightweight or excessive request - all events are generated.
 714               return true;
 715         }
 716         return false;
 717     }
 718 
 719     private boolean rejectFocusRequestHelper(String logMsg) {
 720         if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 721             focusLog.finer(logMsg);
 722         }
 723         WKeyboardFocusManagerPeer.removeLastFocusRequest((Component)target);
 724         return false;
 725     }
 726 
 727     public Image createImage(ImageProducer producer) {
 728         return new ToolkitImage(producer);
 729     }
 730 
 731     public Image createImage(int width, int height) {
 732         Win32GraphicsConfig gc =
 733             (Win32GraphicsConfig)getGraphicsConfiguration();
 734         return gc.createAcceleratedImage((Component)target, width, height);
 735     }
 736 
 737     public VolatileImage createVolatileImage(int width, int height) {
 738         return new SunVolatileImage((Component)target, width, height);
 739     }
 740 


1077     // in the browser on Vista when DWM is enabled.
1078     // @return true if the toplevel container is not an EmbeddedFrame or
1079     // if this EmbeddedFrame is acceleration capable, false otherwise
1080     @SuppressWarnings("deprecation")
1081     private static final boolean isContainingTopLevelAccelCapable(Component c) {
1082         while (c != null && !(c instanceof WEmbeddedFrame)) {
1083             c = c.getParent();
1084         }
1085         if (c == null) {
1086             return true;
1087         }
1088         return ((WEmbeddedFramePeer)c.getPeer()).isAccelCapable();
1089     }
1090 
1091     /**
1092      * Applies the shape to the native component window.
1093      * @since 1.7
1094      */
1095     @SuppressWarnings("deprecation")
1096     public void applyShape(Region shape) {
1097         if (shapeLog.isLoggable(PlatformLogger.Level.FINER)) {
1098             shapeLog.finer("*** INFO: Setting shape: PEER: " + this
1099                             + "; TARGET: " + target
1100                             + "; SHAPE: " + shape);
1101         }
1102 
1103         if (shape != null) {
1104             setRectangularShape(shape.getLoX(), shape.getLoY(), shape.getHiX(), shape.getHiY(),
1105                     (shape.isRectangular() ? null : shape));
1106         } else {
1107             setRectangularShape(0, 0, 0, 0, null);
1108         }
1109     }
1110 
1111     /**
1112      * Lowers this component at the bottom of the above component. If the above parameter
1113      * is null then the method places this component at the top of the Z-order.
1114      */
1115     public void setZOrder(ComponentPeer above) {
1116         long aboveHWND = (above != null) ? ((WComponentPeer)above).getHWnd() : 0;
1117