Пример #1
0
 // MouseDown in non-client area
 @Override
 public void notifyNCMouseDown() {
   // Ungrab except for a click on a Dialog with the grabbing owner
   if (grabbingWindow != null && !grabbingWindow.isOneOfOwnersOf(this)) {
     grabbingWindow.ungrab();
   }
 }
Пример #2
0
 @Override
 protected void setVisibleImpl(final boolean visible) {
   if (!visible && warningWindow != null) {
     warningWindow.setVisible(false, false);
   }
   updateFocusableWindowState();
   super.setVisibleImpl(visible);
   // TODO: update graphicsConfig, see 4868278
   platformWindow.setVisible(visible);
   if (isSimpleWindow()) {
     KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
     if (visible) {
       if (!getTarget().isAutoRequestFocus()) {
         return;
       } else {
         requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
       }
       // Focus the owner in case this window is focused.
     } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
       // Transfer focus to the owner.
       LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
       if (owner != null) {
         owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
       }
     }
   }
 }
Пример #3
0
  /*
   * Requests platform to set native focus on a frame/dialog.
   * In case of a simple window, triggers appropriate java focus change.
   */
  public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
    if (focusLog.isLoggable(PlatformLogger.FINE)) {
      focusLog.fine("requesting native focus to " + this);
    }

    if (!focusAllowedFor()) {
      focusLog.fine("focus is not allowed");
      return false;
    }

    if (platformWindow.rejectFocusRequest(cause)) {
      return false;
    }

    Window currentActive = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();

    Window opposite = LWKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();

    // Make the owner active window.
    if (isSimpleWindow()) {
      LWWindowPeer owner = getOwnerFrameDialog(this);

      // If owner is not natively active, request native
      // activation on it w/o sending events up to java.
      if (owner != null && !owner.platformWindow.isActive()) {
        if (focusLog.isLoggable(PlatformLogger.FINE)) {
          focusLog.fine("requesting native focus to the owner " + owner);
        }
        LWWindowPeer currentActivePeer =
            (currentActive != null ? (LWWindowPeer) currentActive.getPeer() : null);

        // Ensure the opposite is natively active and suppress sending events.
        if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
          if (focusLog.isLoggable(PlatformLogger.FINE)) {
            focusLog.fine("the opposite is " + currentActivePeer);
          }
          currentActivePeer.skipNextFocusChange = true;
        }
        owner.skipNextFocusChange = true;

        owner.platformWindow.requestWindowFocus();
      }

      // DKFM will synthesize all the focus/activation events correctly.
      changeFocusedWindow(true, opposite);
      return true;

      // In case the toplevel is active but not focused, change focus directly,
      // as requesting native focus on it will not have effect.
    } else if (getTarget() == currentActive && !getTarget().hasFocus()) {

      changeFocusedWindow(true, opposite);
      return true;
    }

    return platformWindow.requestWindowFocus();
  }
Пример #4
0
  public LWWindowPeer(
      Window target,
      PlatformComponent platformComponent,
      PlatformWindow platformWindow,
      PeerType peerType) {
    super(target, platformComponent);
    this.platformWindow = platformWindow;
    this.peerType = peerType;

    Window owner = target.getOwner();
    LWWindowPeer ownerPeer =
        owner == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
    PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;

    // The delegate.initialize() needs a non-null GC on X11.
    GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
    synchronized (getStateLock()) {
      // graphicsConfig should be updated according to the real window
      // bounds when the window is shown, see 4868278
      this.graphicsConfig = gc;
    }

    if (!target.isFontSet()) {
      target.setFont(DEFAULT_FONT);
    }

    if (!target.isBackgroundSet()) {
      target.setBackground(SystemColor.window);
    } else {
      // first we check if user provided alpha for background. This is
      // similar to what Apple's Java do.
      // Since JDK7 we should rely on setOpacity() only.
      // this.opacity = c.getAlpha();
    }

    if (!target.isForegroundSet()) {
      target.setForeground(SystemColor.windowText);
      // we should not call setForeground because it will call a repaint
      // which the peer may not be ready to do yet.
    }

    platformWindow.initialize(target, this, ownerDelegate);

    // Init warning window(for applets)
    SecurityWarningWindow warn = null;
    if (target.getWarningString() != null) {
      // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
      // and TrayIcon balloon windows without a warning window.
      if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) {
        LWToolkit toolkit = (LWToolkit) Toolkit.getDefaultToolkit();
        warn = toolkit.createSecurityWarning(target, this);
      }
    }

    warningWindow = warn;
  }
Пример #5
0
 private boolean isFocusableWindow() {
   boolean focusable = getTarget().isFocusableWindow();
   if (isSimpleWindow()) {
     LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
     if (ownerPeer == null) {
       return false;
     }
     return focusable && ownerPeer.getTarget().isFocusableWindow();
   }
   return focusable;
 }
Пример #6
0
 /*
  * Retrieves the owner of the peer.
  * Note: this method returns the owner which can be activated, (i.e. the instance
  * of Frame or Dialog may be returned).
  */
 static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
   Window owner = (peer != null ? peer.getTarget().getOwner() : null);
   while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
     owner = owner.getOwner();
   }
   return owner == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
 }
Пример #7
0
  /*
   * Our focus model is synthetic and only non-simple window
   * may become natively focusable window.
   */
  private boolean isNativelyFocusableWindow() {
    if (peer == null) {
      return false;
    }

    return !peer.isSimpleWindow() && target.getFocusableWindowState();
  }
Пример #8
0
 // MouseDown in non-client area
 @Override
 public void notifyNCMouseDown() {
   // Ungrab except for a click on a Dialog with the grabbing owner
   if (grabbingWindow != null && grabbingWindow != getOwnerFrameDialog(this)) {
     grabbingWindow.ungrab();
   }
 }
Пример #9
0
 static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
   Window owner = (peer != null ? peer.getTarget().getOwner() : null);
   while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
     owner = owner.getOwner();
   }
   return owner != null ? (LWWindowPeer) owner.getPeer() : null;
 }
Пример #10
0
  @Override
  public void setWindowState(int windowState) {
    if (peer == null || !peer.isVisible()) {
      // setVisible() applies the state
      return;
    }

    int prevWindowState = peer.getState();
    if (prevWindowState == windowState) return;

    final long nsWindowPtr = getNSWindowPtr();
    if ((windowState & Frame.ICONIFIED) != 0) {
      // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
      windowState = Frame.ICONIFIED;
    }
    switch (windowState) {
      case Frame.ICONIFIED:
        if (prevWindowState == Frame.MAXIMIZED_BOTH) {
          // let's return into the normal states first
          // the zoom call toggles between the normal and the max states
          unmaximize();
        }
        CWrapper.NSWindow.miniaturize(nsWindowPtr);
        break;
      case Frame.MAXIMIZED_BOTH:
        if (prevWindowState == Frame.ICONIFIED) {
          // let's return into the normal states first
          CWrapper.NSWindow.deminiaturize(nsWindowPtr);
        }
        maximize();
        break;
      case Frame.NORMAL:
        if (prevWindowState == Frame.ICONIFIED) {
          CWrapper.NSWindow.deminiaturize(nsWindowPtr);
        } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
          // the zoom call toggles between the normal and the max states
          unmaximize();
        }
        break;
      default:
        throw new RuntimeException("Unknown window state: " + windowState);
    }

    // NOTE: the SWP.windowState field gets updated to the newWindowState
    //       value when the native notification comes to us
  }
Пример #11
0
  private void maximize() {
    if (peer == null || isMaximized()) {
      return;
    }
    if (!undecorated) {
      CWrapper.NSWindow.zoom(getNSWindowPtr());
    } else {
      deliverZoom(true);

      // We need an up to date size of the peer, so we flush the native events
      // to be sure that there are no setBounds requests in the queue.
      LWCToolkit.flushNativeSelectors();
      this.normalBounds = peer.getBounds();
      Rectangle maximizedBounds = peer.getMaximizedBounds();
      setBounds(
          maximizedBounds.x, maximizedBounds.y, maximizedBounds.width, maximizedBounds.height);
    }
  }
Пример #12
0
 private boolean isOneOfOwnersOf(LWWindowPeer peer) {
   Window owner = (peer != null ? peer.getTarget().getOwner() : null);
   while (owner != null) {
     if ((LWWindowPeer) owner.getPeer() == this) {
       return true;
     }
     owner = owner.getOwner();
   }
   return false;
 }
Пример #13
0
 private void checkZoom() {
   if (peer != null) {
     int state = peer.getState();
     if (state != Frame.MAXIMIZED_BOTH && isMaximized()) {
       deliverZoom(true);
     } else if (state == Frame.MAXIMIZED_BOTH && !isMaximized()) {
       deliverZoom(false);
     }
   }
 }
Пример #14
0
  @Override
  public void setOpaque(boolean isOpaque) {
    CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
    boolean isTextured = (peer == null) ? false : peer.isTextured();
    if (!isTextured) {
      if (!isOpaque) {
        CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), 0);
      } else if (peer != null) {
        Color color = peer.getBackground();
        if (color != null) {
          int rgb = color.getRGB();
          CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), rgb);
        }
      }
    }

    // This is a temporary workaround. Looks like after 7124236 will be fixed
    // the correct place for invalidateShadow() is CGLayer.drawInCGLContext.
    SwingUtilities.invokeLater(this::invalidateShadow);
  }
Пример #15
0
  private boolean checkBlockingAndOrder() {
    LWWindowPeer blocker = (peer == null) ? null : peer.getBlocker();
    if (blocker == null) {
      return false;
    }

    if (blocker instanceof CPrinterDialogPeer) {
      return true;
    }

    CPlatformWindow pWindow = (CPlatformWindow) blocker.getPlatformWindow();

    pWindow.orderAboveSiblings();

    final long nsWindowPtr = pWindow.getNSWindowPtr();
    CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
    CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr);
    CWrapper.NSWindow.makeMainWindow(nsWindowPtr);

    return true;
  }
Пример #16
0
  protected void deliverMoveResizeEvent(int x, int y, int width, int height, boolean byUser) {
    checkZoom();

    final Rectangle oldB = nativeBounds;
    nativeBounds = new Rectangle(x, y, width, height);
    if (peer != null) {
      peer.notifyReshape(x, y, width, height);
      // System-dependent appearance optimization.
      if ((byUser && !oldB.getSize().equals(nativeBounds.getSize())) || isFullScreenAnimationOn) {
        flushBuffers();
      }
    }
  }
Пример #17
0
  /*
   * Delegate initialization (create native window and all the
   * related resources).
   */
  @Override // PlatformWindow
  public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
    initializeBase(_target, _peer, _owner, new CPlatformView());

    final int styleBits = getInitialStyleBits();

    responder = createPlatformResponder();
    contentView = createContentView();
    contentView.initialize(peer, responder);

    final long ownerPtr = owner != null ? owner.getNSWindowPtr() : 0L;
    Rectangle bounds;
    if (!IS(DECORATED, styleBits)) {
      // For undecorated frames the move/resize event does not come if the frame is centered on the
      // screen
      // so we need to set a stub location to force an initial move/resize. Real bounds would be set
      // later.
      bounds = new Rectangle(0, 0, 1, 1);
    } else {
      bounds = _peer.constrainBounds(_target.getBounds());
    }
    final long nativeWindowPtr =
        nativeCreateNSWindow(
            contentView.getAWTView(),
            ownerPtr,
            styleBits,
            bounds.x,
            bounds.y,
            bounds.width,
            bounds.height);
    setPtr(nativeWindowPtr);

    if (target instanceof javax.swing.RootPaneContainer) {
      final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer) target).getRootPane();
      if (rootpane != null)
        rootpane.addPropertyChangeListener(
            "ancestor",
            new PropertyChangeListener() {
              public void propertyChange(final PropertyChangeEvent evt) {
                CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
                rootpane.removePropertyChangeListener("ancestor", this);
              }
            });
    }

    validateSurface();
  }
Пример #18
0
  /*
   * Changes focused window on java level.
   */
  protected void changeFocusedWindow(boolean becomesFocused, Window opposite) {
    if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
      focusLog.fine((becomesFocused ? "gaining" : "loosing") + " focus window: " + this);
    }
    if (skipNextFocusChange) {
      focusLog.fine("skipping focus change");
      skipNextFocusChange = false;
      return;
    }
    if (!isFocusableWindow() && becomesFocused) {
      focusLog.fine("the window is not focusable");
      return;
    }
    if (becomesFocused) {
      synchronized (getPeerTreeLock()) {
        if (blocker != null) {
          if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
            focusLog.finest("the window is blocked by " + blocker);
          }
          return;
        }
      }
    }

    // Note, the method is not called:
    // - when the opposite (gaining focus) window is an owned/owner window.
    // - for a simple window in any case.
    if (!becomesFocused && (isGrabbing() || this.isOneOfOwnersOf(grabbingWindow))) {
      if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
        focusLog.fine("ungrabbing on " + grabbingWindow);
      }
      // ungrab a simple window if its owner looses activation.
      grabbingWindow.ungrab();
    }

    KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
    kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);

    int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
    WindowEvent windowEvent =
        new TimedWindowEvent(getTarget(), eventID, opposite, System.currentTimeMillis());

    // TODO: wrap in SequencedEvent
    postEvent(windowEvent);
  }
Пример #19
0
  @Override // PlatformWindow
  public void setVisible(boolean visible) {
    final long nsWindowPtr = getNSWindowPtr();

    // Configure stuff
    updateIconImages();
    updateFocusabilityForAutoRequestFocus(false);

    boolean wasMaximized = isMaximized();

    if (visible && target.isLocationByPlatform()) {
      nativeSetNSWindowLocationByPlatform(getNSWindowPtr());
    }

    // Actually show or hide the window
    LWWindowPeer blocker = (peer == null) ? null : peer.getBlocker();
    if (blocker == null || !visible) {
      // If it ain't blocked, or is being hidden, go regular way
      if (visible) {
        CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());

        boolean isPopup = (target.getType() == Window.Type.POPUP);
        if (isPopup) {
          // Popups in applets don't activate applet's process
          CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
        } else {
          CWrapper.NSWindow.orderFront(nsWindowPtr);
        }

        boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
        if (!isKeyWindow) {
          CWrapper.NSWindow.makeKeyWindow(nsWindowPtr);
        }
      } else {
        // immediately hide the window
        CWrapper.NSWindow.orderOut(nsWindowPtr);
        // process the close
        CWrapper.NSWindow.close(nsWindowPtr);
      }
    } else {
      // otherwise, put it in a proper z-order
      CWrapper.NSWindow.orderWindow(
          nsWindowPtr,
          CWrapper.NSWindow.NSWindowBelow,
          ((CPlatformWindow) blocker.getPlatformWindow()).getNSWindowPtr());
    }
    this.visible = visible;

    // Manage the extended state when showing
    if (visible) {
      // Apply the extended state as expected in shared code
      if (target instanceof Frame) {
        if (!wasMaximized && isMaximized()) {
          // setVisible could have changed the native maximized state
          deliverZoom(true);
        } else {
          int frameState = ((Frame) target).getExtendedState();
          if ((frameState & Frame.ICONIFIED) != 0) {
            // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
            frameState = Frame.ICONIFIED;
          }
          switch (frameState) {
            case Frame.ICONIFIED:
              CWrapper.NSWindow.miniaturize(nsWindowPtr);
              break;
            case Frame.MAXIMIZED_BOTH:
              maximize();
              break;
            default: // NORMAL
              unmaximize(); // in case it was maximized, otherwise this is a no-op
              break;
          }
        }
      }
    }

    nativeSynthesizeMouseEnteredExitedEvents();

    // Configure stuff #2
    updateFocusabilityForAutoRequestFocus(true);

    // Manage parent-child relationship when showing
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();

    if (visible) {
      // Order myself above my parent
      if (owner != null && owner.isVisible()) {
        CWrapper.NSWindow.orderWindow(
            nsWindowPtr, CWrapper.NSWindow.NSWindowAbove, owner.getNSWindowPtr());
        applyWindowLevel(target);
      }

      // Order my own children above myself
      for (Window w : target.getOwnedWindows()) {
        final Object p = acc.getPeer(w);
        if (p instanceof LWWindowPeer) {
          CPlatformWindow pw = (CPlatformWindow) ((LWWindowPeer) p).getPlatformWindow();
          if (pw != null && pw.isVisible()) {
            CWrapper.NSWindow.orderWindow(
                pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove, nsWindowPtr);
            pw.applyWindowLevel(w);
          }
        }
      }
    }

    // Deal with the blocker of the window being shown
    if (blocker != null && visible) {
      // Make sure the blocker is above its siblings
      ((CPlatformWindow) blocker.getPlatformWindow()).orderAboveSiblings();
    }
  }
Пример #20
0
  protected int getInitialStyleBits() {
    // defaults style bits
    int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE;

    if (isNativelyFocusableWindow()) {
      styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
      styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
    }

    final boolean isFrame = (target instanceof Frame);
    final boolean isDialog = (target instanceof Dialog);
    final boolean isPopup = (target.getType() == Window.Type.POPUP);
    if (isDialog) {
      styleBits = SET(styleBits, MINIMIZABLE, false);
    }

    // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always
    // is undecorated.
    {
      this.undecorated =
          isFrame
              ? ((Frame) target).isUndecorated()
              : (isDialog ? ((Dialog) target).isUndecorated() : true);
      if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
    }

    // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never
    // resizable
    {
      final boolean resizable =
          isFrame
              ? ((Frame) target).isResizable()
              : (isDialog ? ((Dialog) target).isResizable() : false);
      styleBits = SET(styleBits, RESIZABLE, resizable);
      if (!resizable) {
        styleBits = SET(styleBits, ZOOMABLE, false);
      } else {
        setCanFullscreen(true);
      }
    }

    if (target.isAlwaysOnTop()) {
      styleBits = SET(styleBits, ALWAYS_ON_TOP, true);
    }

    if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
      styleBits = SET(styleBits, MODAL_EXCLUDED, true);
    }

    // If the target is a dialog, popup or tooltip we want it to ignore the brushed metal look.
    if (isPopup) {
      styleBits = SET(styleBits, TEXTURED, false);
      // Popups in applets don't activate applet's process
      styleBits = SET(styleBits, NONACTIVATING, true);
      styleBits = SET(styleBits, IS_POPUP, true);
    }

    if (Window.Type.UTILITY.equals(target.getType())) {
      styleBits = SET(styleBits, UTILITY, true);
    }

    if (target instanceof javax.swing.RootPaneContainer) {
      javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer) target).getRootPane();
      Object prop = null;

      prop = rootpane.getClientProperty(WINDOW_BRUSH_METAL_LOOK);
      if (prop != null) {
        styleBits = SET(styleBits, TEXTURED, Boolean.parseBoolean(prop.toString()));
      }

      if (isDialog && ((Dialog) target).getModalityType() == ModalityType.DOCUMENT_MODAL) {
        prop = rootpane.getClientProperty(WINDOW_DOC_MODAL_SHEET);
        if (prop != null) {
          styleBits = SET(styleBits, SHEET, Boolean.parseBoolean(prop.toString()));
        }
      }

      prop = rootpane.getClientProperty(WINDOW_STYLE);
      if (prop != null) {
        if ("small".equals(prop)) {
          styleBits = SET(styleBits, UTILITY, true);
          if (target.isAlwaysOnTop()
              && rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE) == null) {
            styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, true);
          }
        }
        if ("textured".equals(prop)) styleBits = SET(styleBits, TEXTURED, true);
        if ("unified".equals(prop)) styleBits = SET(styleBits, UNIFIED, true);
        if ("hud".equals(prop)) styleBits = SET(styleBits, HUD, true);
      }

      prop = rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE);
      if (prop != null) {
        styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, Boolean.parseBoolean(prop.toString()));
      }

      prop = rootpane.getClientProperty(WINDOW_CLOSEABLE);
      if (prop != null) {
        styleBits = SET(styleBits, CLOSEABLE, Boolean.parseBoolean(prop.toString()));
      }

      prop = rootpane.getClientProperty(WINDOW_MINIMIZABLE);
      if (prop != null) {
        styleBits = SET(styleBits, MINIMIZABLE, Boolean.parseBoolean(prop.toString()));
      }

      prop = rootpane.getClientProperty(WINDOW_ZOOMABLE);
      if (prop != null) {
        styleBits = SET(styleBits, ZOOMABLE, Boolean.parseBoolean(prop.toString()));
      }

      prop = rootpane.getClientProperty(WINDOW_FULLSCREENABLE);
      if (prop != null) {
        styleBits = SET(styleBits, FULLSCREENABLE, Boolean.parseBoolean(prop.toString()));
      }

      prop = rootpane.getClientProperty(WINDOW_SHADOW);
      if (prop != null) {
        styleBits = SET(styleBits, HAS_SHADOW, Boolean.parseBoolean(prop.toString()));
      }

      prop = rootpane.getClientProperty(WINDOW_DRAGGABLE_BACKGROUND);
      if (prop != null) {
        styleBits = SET(styleBits, DRAGGABLE_BACKGROUND, Boolean.parseBoolean(prop.toString()));
      }
    }

    if (isDialog) {
      styleBits = SET(styleBits, IS_DIALOG, true);
      if (((Dialog) target).isModal()) {
        styleBits = SET(styleBits, IS_MODAL, true);
      }
    }

    peer.setTextured(IS(TEXTURED, styleBits));

    return styleBits;
  }
Пример #21
0
  /*
   * Called by the delegate to dispatch the event to Java. Event
   * coordinates are relative to non-client window are, i.e. the top-left
   * point of the client area is (insets.top, insets.left).
   */
  @Override
  public void notifyMouseEvent(
      int id,
      long when,
      int button,
      int x,
      int y,
      int screenX,
      int screenY,
      int modifiers,
      int clickCount,
      boolean popupTrigger,
      byte[] bdata) {
    // TODO: fill "bdata" member of AWTEvent
    Rectangle r = getBounds();
    // findPeerAt() expects parent coordinates
    LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
    LWWindowPeer lastWindowPeer =
        (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
    LWWindowPeer curWindowPeer = (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null;

    if (id == MouseEvent.MOUSE_EXITED) {
      // Sometimes we may get MOUSE_EXITED after lastMouseEventPeer is switched
      // to a peer from another window. So we must first check if this peer is
      // the same as lastWindowPeer
      if (lastWindowPeer == this) {
        if (isEnabled()) {
          Point lp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
          Component target = lastMouseEventPeer.getTarget();
          postMouseEnteredExitedEvent(
              target,
              MouseEvent.MOUSE_EXITED,
              when,
              modifiers,
              lp,
              screenX,
              screenY,
              clickCount,
              popupTrigger,
              button);
        }
        lastMouseEventPeer = null;
      }
    } else {
      if (targetPeer != lastMouseEventPeer) {
        // lastMouseEventPeer may be null if mouse was out of Java windows
        if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
          // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
          // later), in which case lastWindowPeer is another window
          if (lastWindowPeer != this) {
            Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
            // Additionally translate from this to lastWindowPeer coordinates
            Rectangle lr = lastWindowPeer.getBounds();
            oldp.x += r.x - lr.x;
            oldp.y += r.y - lr.y;
            Component target = lastMouseEventPeer.getTarget();
            postMouseEnteredExitedEvent(
                target,
                MouseEvent.MOUSE_EXITED,
                when,
                modifiers,
                oldp,
                screenX,
                screenY,
                clickCount,
                popupTrigger,
                button);
          } else {
            Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
            Component target = lastMouseEventPeer.getTarget();
            postMouseEnteredExitedEvent(
                target,
                MouseEvent.MOUSE_EXITED,
                when,
                modifiers,
                oldp,
                screenX,
                screenY,
                clickCount,
                popupTrigger,
                button);
          }
        }
        lastMouseEventPeer = targetPeer;
        if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) {
          Point newp = targetPeer.windowToLocal(x, y, curWindowPeer);
          Component target = targetPeer.getTarget();
          postMouseEnteredExitedEvent(
              target,
              MouseEvent.MOUSE_ENTERED,
              when,
              modifiers,
              newp,
              screenX,
              screenY,
              clickCount,
              popupTrigger,
              button);
        }
      }
      // TODO: fill "bdata" member of AWTEvent

      int eventButtonMask = (button > 0) ? MouseEvent.getMaskForButton(button) : 0;
      int otherButtonsPressed = modifiers & ~eventButtonMask;

      // For pressed/dragged/released events OS X treats other
      // mouse buttons as if they were BUTTON2, so we do the same
      int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;

      // MOUSE_ENTERED/EXITED are generated for the components strictly under
      // mouse even when dragging. That's why we first update lastMouseEventPeer
      // based on initial targetPeer value and only then recalculate targetPeer
      // for MOUSE_DRAGGED/RELEASED events
      if (id == MouseEvent.MOUSE_PRESSED) {

        // Ungrab only if this window is not an owned window of the grabbing one.
        if (!isGrabbing()
            && grabbingWindow != null
            && grabbingWindow != getOwnerFrameDialog(this)) {
          grabbingWindow.ungrab();
        }
        if (otherButtonsPressed == 0) {
          mouseClickButtons = eventButtonMask;
        } else {
          mouseClickButtons |= eventButtonMask;
        }

        mouseDownTarget[targetIdx] = targetPeer;
      } else if (id == MouseEvent.MOUSE_DRAGGED) {
        // Cocoa dragged event has the information about which mouse
        // button is being dragged. Use it to determine the peer that
        // should receive the dragged event.
        targetPeer = mouseDownTarget[targetIdx];
        mouseClickButtons &= ~modifiers;
      } else if (id == MouseEvent.MOUSE_RELEASED) {
        // TODO: currently, mouse released event goes to the same component
        // that received corresponding mouse pressed event. For most cases,
        // it's OK, however, we need to make sure that our behavior is consistent
        // with 1.6 for cases where component in question have been
        // hidden/removed in between of mouse pressed/released events.
        targetPeer = mouseDownTarget[targetIdx];

        if ((modifiers & eventButtonMask) == 0) {
          mouseDownTarget[targetIdx] = null;
        }

        // mouseClickButtons is updated below, after MOUSE_CLICK is sent
      }

      // check if we receive mouseEvent from outside the window's bounds
      // it can be either mouseDragged or mouseReleased
      if (curWindowPeer == null) {
        // TODO This can happen if this window is invisible. this is correct behavior in this case?
        curWindowPeer = this;
      }
      if (targetPeer == null) {
        // TODO This can happen if this window is invisible. this is correct behavior in this case?
        targetPeer = this;
      }

      Point lp = targetPeer.windowToLocal(x, y, curWindowPeer);
      if (targetPeer.isEnabled()) {
        if (id == MouseEvent.MOUSE_ENTERED || id == MouseEvent.MOUSE_EXITED) {
          postMouseEnteredExitedEvent(
              targetPeer.getTarget(),
              id,
              when,
              modifiers,
              lp,
              screenX,
              screenY,
              clickCount,
              popupTrigger,
              button);

        } else {
          MouseEvent event =
              new MouseEvent(
                  targetPeer.getTarget(),
                  id,
                  when,
                  modifiers,
                  lp.x,
                  lp.y,
                  screenX,
                  screenY,
                  clickCount,
                  popupTrigger,
                  button);
          postEvent(event);
        }
      }

      if (id == MouseEvent.MOUSE_RELEASED) {
        if ((mouseClickButtons & eventButtonMask) != 0 && targetPeer.isEnabled()) {
          postEvent(
              new MouseEvent(
                  targetPeer.getTarget(),
                  MouseEvent.MOUSE_CLICKED,
                  when,
                  modifiers,
                  lp.x,
                  lp.y,
                  screenX,
                  screenY,
                  clickCount,
                  popupTrigger,
                  button));
        }
        mouseClickButtons &= ~eventButtonMask;
      }
    }
    notifyUpdateCursor();
  }
Пример #22
0
 @Override
 public void notifyActivation(boolean activation, LWWindowPeer opposite) {
   Window oppositeWindow = (opposite == null) ? null : opposite.getTarget();
   changeFocusedWindow(activation, oppositeWindow);
 }
Пример #23
0
 private void deliverZoom(final boolean isZoomed) {
   if (peer != null) {
     peer.notifyZoom(isZoomed);
   }
 }
Пример #24
0
 private void deliverIconify(final boolean iconify) {
   if (peer != null) {
     peer.notifyIconify(iconify);
   }
 }
Пример #25
0
 private void deliverWindowClosingEvent() {
   if (peer != null && peer.getBlocker() == null) {
     peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
   }
 }
Пример #26
0
  /*
   * Called by the delegate to dispatch the event to Java. Event
   * coordinates are relative to non-client window are, i.e. the top-left
   * point of the client area is (insets.top, insets.left).
   */
  @Override
  public void notifyMouseEvent(
      PlatformWindow eventPlatformWindow,
      int id,
      long when,
      int button,
      int x,
      int y,
      int screenX,
      int screenY,
      int modifiers,
      int clickCount,
      boolean popupTrigger,
      byte[] bdata) {
    // TODO: fill "bdata" member of AWTEvent
    Rectangle r = getBounds();
    // findPeerAt() expects parent coordinates
    LWComponentPeer<?, ?> targetPeer = findPeerAt(r.x + x, r.y + y);

    if (id == MouseEvent.MOUSE_EXITED) {
      isMouseOver = false;
      if (lastMouseEventPeer != null) {
        if (lastMouseEventPeer.isEnabled()) {
          Point lp = lastMouseEventPeer.windowToLocal(x, y, this);
          Component target = lastMouseEventPeer.getTarget();
          postMouseExitedEvent(
              target, when, modifiers, lp, screenX, screenY, clickCount, popupTrigger, button);
        }

        // Sometimes we may get MOUSE_EXITED after lastCommonMouseEventPeer is switched
        // to a peer from another window. So we must first check if this peer is
        // the same as lastWindowPeer
        if (lastCommonMouseEventPeer != null
            && lastCommonMouseEventPeer.getWindowPeerOrSelf() == this) {
          lastCommonMouseEventPeer = null;
        }
        lastMouseEventPeer = null;
      }
    } else if (id == MouseEvent.MOUSE_ENTERED) {
      isMouseOver = true;
      if (targetPeer != null) {
        if (targetPeer.isEnabled()) {
          Point lp = targetPeer.windowToLocal(x, y, this);
          Component target = targetPeer.getTarget();
          postMouseEnteredEvent(
              target, when, modifiers, lp, screenX, screenY, clickCount, popupTrigger, button);
        }
        lastCommonMouseEventPeer = targetPeer;
        lastMouseEventPeer = targetPeer;
      }
    } else {

      LWWindowPeer topmostWindowPeer =
          eventPlatformWindow != null ? eventPlatformWindow.getPeer() : null;

      // topmostWindowPeer == null condition is added for the backward
      // compatibility with applets. It can be removed when the
      // getTopmostPlatformWindowUnderMouse() method will be properly
      // implemented in CPlatformEmbeddedFrame class
      if (topmostWindowPeer == this || topmostWindowPeer == null) {
        generateMouseEnterExitEventsForComponents(
            when, button, x, y, screenX, screenY, modifiers, clickCount, popupTrigger, targetPeer);
      } else {
        LWComponentPeer<?, ?> topmostTargetPeer = topmostWindowPeer.findPeerAt(r.x + x, r.y + y);
        topmostWindowPeer.generateMouseEnterExitEventsForComponents(
            when,
            button,
            x,
            y,
            screenX,
            screenY,
            modifiers,
            clickCount,
            popupTrigger,
            topmostTargetPeer);
      }

      // TODO: fill "bdata" member of AWTEvent

      int eventButtonMask = (button > 0) ? MouseEvent.getMaskForButton(button) : 0;
      int otherButtonsPressed = modifiers & ~eventButtonMask;

      // For pressed/dragged/released events OS X treats other
      // mouse buttons as if they were BUTTON2, so we do the same
      int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;

      // MOUSE_ENTERED/EXITED are generated for the components strictly under
      // mouse even when dragging. That's why we first update lastMouseEventPeer
      // based on initial targetPeer value and only then recalculate targetPeer
      // for MOUSE_DRAGGED/RELEASED events
      if (id == MouseEvent.MOUSE_PRESSED) {

        // Ungrab only if this window is not an owned window of the grabbing one.
        if (!isGrabbing() && grabbingWindow != null && !grabbingWindow.isOneOfOwnersOf(this)) {
          grabbingWindow.ungrab();
        }
        if (otherButtonsPressed == 0) {
          mouseClickButtons = eventButtonMask;
        } else {
          mouseClickButtons |= eventButtonMask;
        }

        // The window should be focused on mouse click. If it gets activated by the native platform,
        // this request will be no op. It will take effect when:
        // 1. A simple not focused window is clicked.
        // 2. An active but not focused owner frame/dialog is clicked.
        // The mouse event then will trigger a focus request "in window" to the component, so the
        // window
        // should gain focus before.
        requestWindowFocus(CausedFocusEvent.Cause.MOUSE_EVENT);

        mouseDownTarget[targetIdx] = targetPeer;
      } else if (id == MouseEvent.MOUSE_DRAGGED) {
        // Cocoa dragged event has the information about which mouse
        // button is being dragged. Use it to determine the peer that
        // should receive the dragged event.
        targetPeer = mouseDownTarget[targetIdx];
        mouseClickButtons &= ~modifiers;
      } else if (id == MouseEvent.MOUSE_RELEASED) {
        // TODO: currently, mouse released event goes to the same component
        // that received corresponding mouse pressed event. For most cases,
        // it's OK, however, we need to make sure that our behavior is consistent
        // with 1.6 for cases where component in question have been
        // hidden/removed in between of mouse pressed/released events.
        targetPeer = mouseDownTarget[targetIdx];

        if ((modifiers & eventButtonMask) == 0) {
          mouseDownTarget[targetIdx] = null;
        }

        // mouseClickButtons is updated below, after MOUSE_CLICK is sent
      }

      if (targetPeer == null) {
        // TODO This can happen if this window is invisible. this is correct behavior in this case?
        targetPeer = this;
      }

      Point lp = targetPeer.windowToLocal(x, y, this);
      if (targetPeer.isEnabled()) {
        MouseEvent event =
            new MouseEvent(
                targetPeer.getTarget(),
                id,
                when,
                modifiers,
                lp.x,
                lp.y,
                screenX,
                screenY,
                clickCount,
                popupTrigger,
                button);
        postEvent(event);
      }

      if (id == MouseEvent.MOUSE_RELEASED) {
        if ((mouseClickButtons & eventButtonMask) != 0 && targetPeer.isEnabled()) {
          postEvent(
              new MouseEvent(
                  targetPeer.getTarget(),
                  MouseEvent.MOUSE_CLICKED,
                  when,
                  modifiers,
                  lp.x,
                  lp.y,
                  screenX,
                  screenY,
                  clickCount,
                  popupTrigger,
                  button));
        }
        mouseClickButtons &= ~eventButtonMask;
      }
    }
    notifyUpdateCursor();
  }
Пример #27
0
 private void deliverNCMouseDown() {
   if (peer != null) {
     peer.notifyNCMouseDown();
   }
 }
Пример #28
0
 void grab() {
   if (grabbingWindow != null && !isGrabbing()) {
     grabbingWindow.ungrab();
   }
   grabbingWindow = this;
 }