Example #1
0
  void preInit(XCreateWindowParams params) {
    super.preInit(params);
    if (!resize_request.isInterned()) {
      resize_request.intern(false);
    }
    winAttr.initialFocus = true;

    currentInsets = new Insets(0, 0, 0, 0); // replacemenet for wdata->top, left, bottom, right

    applyGuessedInsets();
    Rectangle bounds = (Rectangle) params.get(BOUNDS);
    dimensions = new WindowDimensions(bounds, getRealInsets(), false);
    params.put(BOUNDS, dimensions.getClientRect());

    if (insLog.isLoggable(Level.FINE)) {
      insLog.log(Level.FINE, "Initial dimensions {0}", new Object[] {String.valueOf(dimensions)});
    }

    // Deny default processing of these events on the shell - proxy will take care of
    // them instead
    Long eventMask = (Long) params.get(EVENT_MASK);
    params.add(
        EVENT_MASK,
        Long.valueOf(eventMask.longValue() & ~(FocusChangeMask | KeyPressMask | KeyReleaseMask)));
  }
  /**
   * Creates window using parameters <code>params</code> If params contain flag DELAYED doesn't do
   * anything. Note: Descendants can call this method to create the window at the time different to
   * instance construction.
   */
  protected final void init(XCreateWindowParams params) {
    awtLock();
    initialising = InitialiseState.INITIALISING;
    awtUnlock();

    try {
      if (!Boolean.TRUE.equals(params.get(DELAYED))) {
        preInit(params);
        create(params);
        postInit(params);
      } else {
        instantPreInit(params);
        delayedParams = params;
      }
      awtLock();
      initialising = InitialiseState.INITIALISED;
      awtLockNotifyAll();
      awtUnlock();
    } catch (RuntimeException re) {
      awtLock();
      initialising = InitialiseState.FAILED_INITIALISATION;
      awtLockNotifyAll();
      awtUnlock();
      throw re;
    } catch (Throwable t) {
      log.log(Level.WARNING, "Exception during peer initialization", t);
      awtLock();
      initialising = InitialiseState.FAILED_INITIALISATION;
      awtLockNotifyAll();
      awtUnlock();
    }
  }
  /**
   * Called before window creation, descendants should override to initialize the data, initialize
   * params.
   */
  void preInit(XCreateWindowParams params) {
    state_lock = new StateLock();
    initialising = InitialiseState.NOT_INITIALISED;
    embedded = Boolean.TRUE.equals(params.get(EMBEDDED));
    visible = Boolean.TRUE.equals(params.get(VISIBLE));

    Object parent = params.get(PARENT);
    if (parent instanceof XBaseWindow) {
      parentWindow = (XBaseWindow) parent;
    } else {
      Long parentWindowID = (Long) params.get(PARENT_WINDOW);
      if (parentWindowID != null) {
        parentWindow = XToolkit.windowToXWindow(parentWindowID);
      }
    }

    Long eventMask = (Long) params.get(EVENT_MASK);
    if (eventMask != null) {
      long mask = eventMask.longValue();
      mask |= SubstructureNotifyMask;
      params.put(EVENT_MASK, mask);
    }

    screen = -1;
  }
  /**
   * Verifies that all required parameters are set. If not, sets them to default values. Verifies
   * values of critical parameters, adjust their values when needed.
   *
   * @throws IllegalArgumentException if params is null
   */
  protected void checkParams(XCreateWindowParams params) {
    if (params == null) {
      throw new IllegalArgumentException("Window creation parameters are null");
    }
    params.putIfNull(PARENT_WINDOW, Long.valueOf(XToolkit.getDefaultRootWindow()));
    params.putIfNull(BOUNDS, new Rectangle(DEF_LOCATION, DEF_LOCATION, MIN_SIZE, MIN_SIZE));
    params.putIfNull(DEPTH, Integer.valueOf((int) XlibWrapper.CopyFromParent));
    params.putIfNull(VISUAL, Long.valueOf(XlibWrapper.CopyFromParent));
    params.putIfNull(VISUAL_CLASS, Integer.valueOf((int) XlibWrapper.InputOnly));
    params.putIfNull(VALUE_MASK, Long.valueOf(XlibWrapper.CWEventMask));
    Rectangle bounds = (Rectangle) params.get(BOUNDS);
    bounds.width = Math.max(MIN_SIZE, bounds.width);
    bounds.height = Math.max(MIN_SIZE, bounds.height);

    Long eventMaskObj = (Long) params.get(EVENT_MASK);
    long eventMask = eventMaskObj != null ? eventMaskObj.longValue() : 0;
    // We use our own synthetic grab see XAwtState.getGrabWindow()
    // (see X vol. 1, 8.3.3.2)
    eventMask |= PropertyChangeMask | OwnerGrabButtonMask;
    params.put(EVENT_MASK, Long.valueOf(eventMask));
  }
Example #5
0
  protected void preInit(XCreateWindowParams params) {
    super.preInit(params);

    params.put(
        EVENT_MASK,
        XConstants.KeyPressMask
            | XConstants.KeyReleaseMask
            | XConstants.FocusChangeMask
            | XConstants.ButtonPressMask
            | XConstants.ButtonReleaseMask
            | XConstants.EnterWindowMask
            | XConstants.LeaveWindowMask
            | XConstants.PointerMotionMask
            | XConstants.ButtonMotionMask
            | XConstants.ExposureMask
            | XConstants.StructureNotifyMask
            | XConstants.SubstructureNotifyMask);
  }
  /**
   * Creates window with parameters specified by <code>params</code>
   *
   * @see #init
   */
  private final void create(XCreateWindowParams params) {
    XToolkit.awtLock();
    try {
      XSetWindowAttributes xattr = new XSetWindowAttributes();
      try {
        checkParams(params);

        long value_mask = ((Long) params.get(VALUE_MASK)).longValue();

        Long eventMask = (Long) params.get(EVENT_MASK);
        xattr.set_event_mask(eventMask.longValue());
        value_mask |= XlibWrapper.CWEventMask;

        Long border_pixel = (Long) params.get(BORDER_PIXEL);
        if (border_pixel != null) {
          xattr.set_border_pixel(border_pixel.longValue());
          value_mask |= XlibWrapper.CWBorderPixel;
        }

        Long colormap = (Long) params.get(COLORMAP);
        if (colormap != null) {
          xattr.set_colormap(colormap.longValue());
          value_mask |= XlibWrapper.CWColormap;
        }
        Long background_pixmap = (Long) params.get(BACKGROUND_PIXMAP);
        if (background_pixmap != null) {
          xattr.set_background_pixmap(background_pixmap.longValue());
          value_mask |= XlibWrapper.CWBackPixmap;
        }

        Long parentWindow = (Long) params.get(PARENT_WINDOW);
        Rectangle bounds = (Rectangle) params.get(BOUNDS);
        Integer depth = (Integer) params.get(DEPTH);
        Integer visual_class = (Integer) params.get(VISUAL_CLASS);
        Long visual = (Long) params.get(VISUAL);
        Boolean overrideRedirect = (Boolean) params.get(OVERRIDE_REDIRECT);
        if (overrideRedirect != null) {
          xattr.set_override_redirect(overrideRedirect.booleanValue());
          value_mask |= XlibWrapper.CWOverrideRedirect;
        }

        Boolean saveUnder = (Boolean) params.get(SAVE_UNDER);
        if (saveUnder != null) {
          xattr.set_save_under(saveUnder.booleanValue());
          value_mask |= XlibWrapper.CWSaveUnder;
        }

        Integer backingStore = (Integer) params.get(BACKING_STORE);
        if (backingStore != null) {
          xattr.set_backing_store(backingStore.intValue());
          value_mask |= XlibWrapper.CWBackingStore;
        }

        Integer bitGravity = (Integer) params.get(BIT_GRAVITY);
        if (bitGravity != null) {
          xattr.set_bit_gravity(bitGravity.intValue());
          value_mask |= XlibWrapper.CWBitGravity;
        }

        if (log.isLoggable(Level.FINE)) {
          log.fine("Creating window for " + this + " with the following attributes: \n" + params);
        }
        window =
            XlibWrapper.XCreateWindow(
                XToolkit.getDisplay(),
                parentWindow.longValue(),
                bounds.x,
                bounds.y, // location
                bounds.width,
                bounds.height, // size
                0, // border
                depth.intValue(), // depth
                visual_class.intValue(), // class
                visual.longValue(), // visual
                value_mask, // value mask
                xattr.pData); // attributes

        if (window == 0) {
          throw new IllegalStateException(
              "Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details");
        }
        XToolkit.addToWinMap(window, this);
      } finally {
        xattr.dispose();
      }
    } finally {
      XToolkit.awtUnlock();
    }
  }