src/macosx/classes/sun/lwawt/LWWindowPeer.java

Print this page




  95 
  96     // Peers where all dragged/released events should come to,
  97     // depending on what mouse button is being dragged according to Cocoa
  98     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  99 
 100     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 101     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 102     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 103     private static int mouseClickButtons = 0;
 104 
 105     private volatile boolean isOpaque = true;
 106 
 107     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 108 
 109     private static LWWindowPeer grabbingWindow;
 110 
 111     private volatile boolean skipNextFocusChange;
 112 
 113     private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
 114 


 115     /**
 116      * Current modal blocker or null.
 117      *
 118      * Synchronization: peerTreeLock.
 119      */
 120     private LWWindowPeer blocker;
 121 
 122     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 123                         PlatformWindow platformWindow)
 124     {
 125         super(target, platformComponent);
 126         this.platformWindow = platformWindow;
 127 
 128         Window owner = target.getOwner();
 129         LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
 130         PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
 131 
 132         // The delegate.initialize() needs a non-null GC on X11.
 133         GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
 134         synchronized (getStateLock()) {


 425     }
 426 
 427     @Override
 428     public final void setOpaque(final boolean isOpaque) {
 429         if (this.isOpaque != isOpaque) {
 430             this.isOpaque = isOpaque;
 431             updateOpaque();
 432         }
 433     }
 434 
 435     private void updateOpaque() {
 436         getPlatformWindow().setOpaque(!isTranslucent());
 437         replaceSurfaceData(false);
 438         repaintPeer();
 439     }
 440 
 441     @Override
 442     public void updateWindow() {
 443     }
 444 








 445     public final boolean isTranslucent() {
 446         synchronized (getStateLock()) {
 447             return !isOpaque || isShaped();






 448         }
 449     }
 450 
 451     @Override
 452     final void applyShapeImpl(final Region shape) {
 453         super.applyShapeImpl(shape);
 454         updateOpaque();
 455     }
 456 
 457     @Override
 458     public void repositionSecurityWarning() {
 459         throw new RuntimeException("not implemented");
 460     }
 461 
 462     // ---- FRAME PEER METHODS ---- //
 463 
 464     @Override // FramePeer and DialogPeer
 465     public void setTitle(String title) {
 466         platformWindow.setTitle(title == null ? "" : title);
 467     }


 596         if (moved) {
 597             handleMove(x, y, true);
 598         }
 599         if (resized) {
 600             handleResize(w, h,true);
 601         }
 602     }
 603 
 604     private void clearBackground(final int w, final int h) {
 605         final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
 606                                                getFont());
 607         if (g != null) {
 608             try {
 609                 if (g instanceof Graphics2D) {
 610                     ((Graphics2D) g).setComposite(AlphaComposite.Src);
 611                 }
 612                 if (isTranslucent()) {
 613                     g.setColor(nonOpaqueBackground);
 614                     g.fillRect(0, 0, w, h);
 615                 }

 616                 if (g instanceof SunGraphics2D) {
 617                     SG2DConstraint((SunGraphics2D) g, getRegion());
 618                 }
 619                 g.setColor(getBackground());
 620                 g.fillRect(0, 0, w, h);

 621             } finally {
 622                 g.dispose();
 623             }
 624         }
 625     }
 626 
 627     public void notifyUpdateCursor() {
 628         getLWToolkit().getCursorManager().updateCursorLater(this);
 629     }
 630 
 631     public void notifyActivation(boolean activation) {
 632         changeFocusedWindow(activation);
 633     }
 634 
 635     // MouseDown in non-client area
 636     public void notifyNCMouseDown() {
 637         // Ungrab except for a click on a Dialog with the grabbing owner
 638         if (grabbingWindow != null &&
 639             grabbingWindow != getOwnerFrameDialog(this))
 640         {


 965                 // TODO: drop oldData for D3D/WGL pipelines
 966                 // This can only happen when this peer is being created
 967                 oldData.flush();
 968             }
 969 
 970             // TODO: volatile image
 971     //        backBuffer = (VolatileImage)delegate.createBackBuffer();
 972             backBuffer = (BufferedImage) platformWindow.createBackBuffer();
 973             if (backBuffer != null) {
 974                 Graphics g = backBuffer.getGraphics();
 975                 try {
 976                     Rectangle r = getBounds();
 977                     if (g instanceof Graphics2D) {
 978                         ((Graphics2D) g).setComposite(AlphaComposite.Src);
 979                     }
 980                     g.setColor(nonOpaqueBackground);
 981                     g.fillRect(0, 0, r.width, r.height);
 982                     if (g instanceof SunGraphics2D) {
 983                         SG2DConstraint((SunGraphics2D) g, getRegion());
 984                     }

 985                     g.setColor(getBackground());
 986                     g.fillRect(0, 0, r.width, r.height);

 987                     if (oldBB != null) {
 988                         // Draw the old back buffer to the new one
 989                         g.drawImage(oldBB, 0, 0, null);
 990                         oldBB.flush();
 991                     }
 992                 } finally {
 993                     g.dispose();
 994                 }
 995             }
 996         }
 997     }
 998 
 999     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
1000         //TODO blit. proof-of-concept
1001         if (src != dst && src != null && dst != null
1002             && !(dst instanceof NullSurfaceData)
1003             && !(src instanceof NullSurfaceData)
1004             && src.getSurfaceType().equals(dst.getSurfaceType())) {
1005             final Rectangle size = getSize();
1006             final Blit blit = Blit.locate(src.getSurfaceType(),




  95 
  96     // Peers where all dragged/released events should come to,
  97     // depending on what mouse button is being dragged according to Cocoa
  98     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  99 
 100     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 101     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 102     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 103     private static int mouseClickButtons = 0;
 104 
 105     private volatile boolean isOpaque = true;
 106 
 107     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 108 
 109     private static LWWindowPeer grabbingWindow;
 110 
 111     private volatile boolean skipNextFocusChange;
 112 
 113     private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
 114 
 115     private volatile boolean textured;
 116 
 117     /**
 118      * Current modal blocker or null.
 119      *
 120      * Synchronization: peerTreeLock.
 121      */
 122     private LWWindowPeer blocker;
 123 
 124     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 125                         PlatformWindow platformWindow)
 126     {
 127         super(target, platformComponent);
 128         this.platformWindow = platformWindow;
 129 
 130         Window owner = target.getOwner();
 131         LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
 132         PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
 133 
 134         // The delegate.initialize() needs a non-null GC on X11.
 135         GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
 136         synchronized (getStateLock()) {


 427     }
 428 
 429     @Override
 430     public final void setOpaque(final boolean isOpaque) {
 431         if (this.isOpaque != isOpaque) {
 432             this.isOpaque = isOpaque;
 433             updateOpaque();
 434         }
 435     }
 436 
 437     private void updateOpaque() {
 438         getPlatformWindow().setOpaque(!isTranslucent());
 439         replaceSurfaceData(false);
 440         repaintPeer();
 441     }
 442 
 443     @Override
 444     public void updateWindow() {
 445     }
 446 
 447     public final boolean isTextured() {
 448         return textured;
 449     }
 450 
 451     public final void setTextured(final boolean isTextured) {
 452         textured = isTextured;
 453     }
 454 
 455     public final boolean isTranslucent() {
 456         synchronized (getStateLock()) {
 457             /*
 458              * Textured window is a special case of translucent window.
 459              * The difference is only in nswindow background. So when we set
 460              * texture property our peer became fully translucent. It doesn't
 461              * fill background, create non opaque backbuffers and layer etc.
 462              */
 463             return !isOpaque || isShaped() || isTextured();
 464         }
 465     }
 466 
 467     @Override
 468     final void applyShapeImpl(final Region shape) {
 469         super.applyShapeImpl(shape);
 470         updateOpaque();
 471     }
 472 
 473     @Override
 474     public void repositionSecurityWarning() {
 475         throw new RuntimeException("not implemented");
 476     }
 477 
 478     // ---- FRAME PEER METHODS ---- //
 479 
 480     @Override // FramePeer and DialogPeer
 481     public void setTitle(String title) {
 482         platformWindow.setTitle(title == null ? "" : title);
 483     }


 612         if (moved) {
 613             handleMove(x, y, true);
 614         }
 615         if (resized) {
 616             handleResize(w, h,true);
 617         }
 618     }
 619 
 620     private void clearBackground(final int w, final int h) {
 621         final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
 622                                                getFont());
 623         if (g != null) {
 624             try {
 625                 if (g instanceof Graphics2D) {
 626                     ((Graphics2D) g).setComposite(AlphaComposite.Src);
 627                 }
 628                 if (isTranslucent()) {
 629                     g.setColor(nonOpaqueBackground);
 630                     g.fillRect(0, 0, w, h);
 631                 }
 632                 if (!isTextured()) {
 633                     if (g instanceof SunGraphics2D) {
 634                         SG2DConstraint((SunGraphics2D) g, getRegion());
 635                     }
 636                     g.setColor(getBackground());
 637                     g.fillRect(0, 0, w, h);
 638                 }
 639             } finally {
 640                 g.dispose();
 641             }
 642         }
 643     }
 644 
 645     public void notifyUpdateCursor() {
 646         getLWToolkit().getCursorManager().updateCursorLater(this);
 647     }
 648 
 649     public void notifyActivation(boolean activation) {
 650         changeFocusedWindow(activation);
 651     }
 652 
 653     // MouseDown in non-client area
 654     public void notifyNCMouseDown() {
 655         // Ungrab except for a click on a Dialog with the grabbing owner
 656         if (grabbingWindow != null &&
 657             grabbingWindow != getOwnerFrameDialog(this))
 658         {


 983                 // TODO: drop oldData for D3D/WGL pipelines
 984                 // This can only happen when this peer is being created
 985                 oldData.flush();
 986             }
 987 
 988             // TODO: volatile image
 989     //        backBuffer = (VolatileImage)delegate.createBackBuffer();
 990             backBuffer = (BufferedImage) platformWindow.createBackBuffer();
 991             if (backBuffer != null) {
 992                 Graphics g = backBuffer.getGraphics();
 993                 try {
 994                     Rectangle r = getBounds();
 995                     if (g instanceof Graphics2D) {
 996                         ((Graphics2D) g).setComposite(AlphaComposite.Src);
 997                     }
 998                     g.setColor(nonOpaqueBackground);
 999                     g.fillRect(0, 0, r.width, r.height);
1000                     if (g instanceof SunGraphics2D) {
1001                         SG2DConstraint((SunGraphics2D) g, getRegion());
1002                     }
1003                     if (!isTextured()) {
1004                         g.setColor(getBackground());
1005                         g.fillRect(0, 0, r.width, r.height);
1006                     }
1007                     if (oldBB != null) {
1008                         // Draw the old back buffer to the new one
1009                         g.drawImage(oldBB, 0, 0, null);
1010                         oldBB.flush();
1011                     }
1012                 } finally {
1013                     g.dispose();
1014                 }
1015             }
1016         }
1017     }
1018 
1019     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
1020         //TODO blit. proof-of-concept
1021         if (src != dst && src != null && dst != null
1022             && !(dst instanceof NullSurfaceData)
1023             && !(src instanceof NullSurfaceData)
1024             && src.getSurfaceType().equals(dst.getSurfaceType())) {
1025             final Rectangle size = getSize();
1026             final Blit blit = Blit.locate(src.getSurfaceType(),