Пример #1
0
  Rectangle getClientBounds() {
    XToolkit.awtLock();
    try {
      XWindowAttributes wattr = new XWindowAttributes();
      try {
        XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
        int status =
            XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), xembed.handle, wattr.pData);

        XToolkit.RESTORE_XERROR_HANDLER();

        if (status == 0
            || (XToolkit.saved_error != null
                && XToolkit.saved_error.get_error_code() != XConstants.Success)) {
          return null;
        }

        return new Rectangle(wattr.get_x(), wattr.get_y(), wattr.get_width(), wattr.get_height());
      } finally {
        wattr.dispose();
      }
    } finally {
      XToolkit.awtUnlock();
    }
  }
Пример #2
0
  /**
   * Translate coordinates from one window into another. Optimized for XAWT - uses cached data when
   * possible. Preferable over pure XTranslateCoordinates.
   *
   * @return coordinates relative to dst, or null if error happened
   */
  static Point toOtherWindow(long src, long dst, int x, int y) {
    Point rpt = new Point(0, 0);

    // Check if both windows belong to XAWT - then no X calls are necessary

    XBaseWindow srcPeer = XToolkit.windowToXWindow(src);
    XBaseWindow dstPeer = XToolkit.windowToXWindow(dst);

    if (srcPeer != null && dstPeer != null) {
      // (x, y) is relative to src
      rpt.x = x + srcPeer.getAbsoluteX() - dstPeer.getAbsoluteX();
      rpt.y = y + srcPeer.getAbsoluteY() - dstPeer.getAbsoluteY();
    } else if (dstPeer != null && XlibUtil.isRoot(src, dstPeer.getScreenNumber())) {
      // from root into peer
      rpt.x = x - dstPeer.getAbsoluteX();
      rpt.y = y - dstPeer.getAbsoluteY();
    } else if (srcPeer != null && XlibUtil.isRoot(dst, srcPeer.getScreenNumber())) {
      // from peer into root
      rpt.x = x + srcPeer.getAbsoluteX();
      rpt.y = y + srcPeer.getAbsoluteY();
    } else {
      rpt = XlibUtil.translateCoordinates(src, dst, new Point(x, y));
    }
    return rpt;
  }
Пример #3
0
  /** Returns the supported cursor size */
  static Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {

    // Fix for bug 4212593 The Toolkit.createCustomCursor does not
    //                     check absence of the image of cursor
    // We use XQueryBestCursor which accepts unsigned ints to obtain
    // the largest cursor size that could be dislpayed
    // Dimension d = new Dimension(Math.abs(preferredWidth), Math.abs(preferredHeight));
    Dimension d;

    XToolkit.awtLock();
    try {
      long display = XToolkit.getDisplay();
      long root_window = XlibWrapper.RootWindow(display, XlibWrapper.DefaultScreen(display));

      XlibWrapper.XQueryBestCursor(
          display,
          root_window,
          Math.abs(preferredWidth),
          Math.abs(preferredHeight),
          XlibWrapper.larg1,
          XlibWrapper.larg2);
      d =
          new Dimension(
              XlibWrapper.unsafe.getInt(XlibWrapper.larg1),
              XlibWrapper.unsafe.getInt(XlibWrapper.larg2));
    } finally {
      XToolkit.awtUnlock();
    }
    return d;
  }
Пример #4
0
 static long getScreenOfWindow(long window) {
   XToolkit.awtLock();
   try {
     return XlibWrapper.getScreenOfWindow(XToolkit.getDisplay(), window);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #5
0
 long getScreenNumber() {
   XToolkit.awtLock();
   try {
     return XlibWrapper.XScreenNumberOfScreen(getScreen());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #6
0
 public static long xGetInputFocus() {
   XToolkit.awtLock();
   try {
     return XlibWrapper.XGetInputFocus(XToolkit.getDisplay());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #7
0
 public void toFront() {
   XToolkit.awtLock();
   try {
     XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #8
0
 /** Helper function to set W */
 public final void setWMHints(XWMHints hints) {
   XToolkit.awtLock();
   try {
     XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #9
0
 void flush() {
   XToolkit.awtLock();
   try {
     XlibWrapper.XFlush(XToolkit.getDisplay());
   } finally {
     XToolkit.awtUnlock();
   }
 }
 // don't use getLocationOnScreen() inherited from XDecoratedPeer
 public Point getLocationOnScreen() {
   XToolkit.awtLock();
   try {
     return toGlobal(0, 0);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #11
0
  protected void createCursor(
      byte[] xorMask,
      byte[] andMask,
      int width,
      int height,
      int fcolor,
      int bcolor,
      int xHotSpot,
      int yHotSpot) {
    XToolkit.awtLock();
    try {
      long display = XToolkit.getDisplay();
      long root_window = XlibWrapper.RootWindow(display, XlibWrapper.DefaultScreen(display));

      long colormap = XToolkit.getDefaultXColormap();
      XColor fore_color = new XColor();

      fore_color.set_flags((byte) (XlibWrapper.DoRed | XlibWrapper.DoGreen | XlibWrapper.DoBlue));
      fore_color.set_red((short) (((fcolor >> 16) & 0x000000ff) << 8));
      fore_color.set_green((short) (((fcolor >> 8) & 0x000000ff) << 8));
      fore_color.set_blue((short) (((fcolor >> 0) & 0x000000ff) << 8));

      XlibWrapper.XAllocColor(display, colormap, fore_color.pData);

      XColor back_color = new XColor();
      back_color.set_flags((byte) (XlibWrapper.DoRed | XlibWrapper.DoGreen | XlibWrapper.DoBlue));

      back_color.set_red((short) (((bcolor >> 16) & 0x000000ff) << 8));
      back_color.set_green((short) (((bcolor >> 8) & 0x000000ff) << 8));
      back_color.set_blue((short) (((bcolor >> 0) & 0x000000ff) << 8));

      XlibWrapper.XAllocColor(display, colormap, back_color.pData);

      long nativeXorMask = Native.toData(xorMask);
      long source =
          XlibWrapper.XCreateBitmapFromData(display, root_window, nativeXorMask, width, height);

      long nativeAndMask = Native.toData(andMask);
      long mask =
          XlibWrapper.XCreateBitmapFromData(display, root_window, nativeAndMask, width, height);

      long cursor =
          XlibWrapper.XCreatePixmapCursor(
              display, source, mask, fore_color.pData, back_color.pData, xHotSpot, yHotSpot);

      XlibWrapper.unsafe.freeMemory(nativeXorMask);
      XlibWrapper.unsafe.freeMemory(nativeAndMask);
      XlibWrapper.XFreePixmap(display, source);
      XlibWrapper.XFreePixmap(display, mask);
      back_color.dispose();
      fore_color.dispose();

      XGlobalCursorManager.setPData(this, cursor);
    } finally {
      XToolkit.awtUnlock();
    }
  }
Пример #12
0
 public void xRequestFocus() {
   XToolkit.awtLock();
   try {
     if (focusLog.isLoggable(Level.FINER))
       focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
     XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #13
0
 public void setShellSize(Rectangle rec) {
   if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell size on " + this + " to " + rec);
   XToolkit.awtLock();
   try {
     updateSizeHints(rec.x, rec.y, rec.width, rec.height);
     XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #14
0
 protected void initClientLeader() {
   XToolkit.awtLock();
   try {
     if (wm_client_leader == null) {
       wm_client_leader = XAtom.get("WM_CLIENT_LEADER");
     }
     wm_client_leader.setWindowProperty(this, getXAWTRootWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #15
0
 void endDispatching() {
   xembedLog.fine("End dispatching for " + Long.toHexString(xembed.handle));
   XToolkit.awtLock();
   try {
     XDropTargetRegistry.getRegistry().unregisterXEmbedClient(getWindow(), xembed.handle);
     // We can't deselect input since someone else might be interested in it
     XToolkit.removeEventDispatcher(xembed.handle, xembed);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #16
0
 void setWMClass(String[] cl) {
   if (cl.length != 2) {
     throw new IllegalArgumentException("WM_CLASS_NAME consists of exactly two strings");
   }
   XToolkit.awtLock();
   try {
     XAtom xa = XAtom.get(XAtom.XA_WM_CLASS);
     xa.setProperty8(getWindow(), cl[0] + '\0' + cl[1]);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #17
0
  protected void handleCorrectInsets(Insets correctWM) {
    XToolkit.awtLock();
    try {
      /*
       * Ok, now see if we need adjust window size because
       * initial insets were wrong (most likely they were).
       */
      Insets correction = difference(correctWM, currentInsets);
      if (insLog.isLoggable(Level.FINEST)) {
        insLog.log(Level.FINEST, "Corrention {0}", new Object[] {String.valueOf(correction)});
      }
      if (!isNull(correction)) {
        /*
         * Actual insets account for menubar/warning label,
         * so we can't assign directly but must adjust them.
         */
        add(currentInsets, correction);
        applyGuessedInsets();

        // Fix for 6318109: PIT: Min Size is not honored properly when a
        // smaller size is specified in setSize(), XToolkit
        // update minimum size hints
        updateMinSizeHints();

        /*
         * If this window has been sized by a pack() we need
         * to keep the interior geometry intact.  Since pack()
         * computed width and height with wrong insets, we
         * must adjust the target dimensions appropriately.
         */
      }
      if (insLog.isLoggable(Level.FINER)) insLog.finer("Dimensions before reparent: " + dimensions);

      dimensions.setInsets(getRealInsets());
      insets_corrected = true;

      if (isMaximized()) {
        return;
      }

      if ((getHints().get_flags() & (USPosition | PPosition)) != 0) {
        reshape(dimensions, SET_BOUNDS, false);
      } else {
        reshape(dimensions, SET_SIZE, false);
      }
    } finally {
      XToolkit.awtUnlock();
    }
  }
  public void synthesizeFocusInOut(boolean doFocus) {
    XFocusChangeEvent xev = new XFocusChangeEvent();

    XToolkit.awtLock();
    try {
      xev.set_type(doFocus ? FocusIn : FocusOut);
      xev.set_window(getFocusProxy().getWindow());
      xev.set_mode(NotifyNormal);
      XlibWrapper.XSendEvent(
          XToolkit.getDisplay(), getFocusProxy().getWindow(), false, NoEventMask, xev.pData);
    } finally {
      XToolkit.awtUnlock();
      xev.dispose();
    }
  }
Пример #19
0
 void childResized() {
   if (xembedLog.isLoggable(PlatformLogger.FINER)) {
     Rectangle bounds = getClientBounds();
     xembedLog.finer("Child resized: " + bounds);
     // It is not required to update embedder's size when client size changes
     // However, since there is no any means to get client size it seems to be the
     // only way to provide it. However, it contradicts with Java layout concept -
     // so it is disabled for now.
     //             Rectangle my_bounds = getBounds();
     //             setBounds(my_bounds.x, my_bounds.y, bounds.width, bounds.height, SET_BOUNDS);
   }
   XToolkit.postEvent(
       XToolkit.targetToAppContext(target),
       new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED));
 }
Пример #20
0
 Point toLocal(int x, int y) {
   long root;
   XToolkit.awtLock();
   try {
     root = XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber());
   } finally {
     XToolkit.awtUnlock();
   }
   Point p = toOtherWindow(root, getContentWindow(), x, y);
   if (p != null) {
     return p;
   } else {
     return new Point(x, y);
   }
 }
Пример #21
0
 public void xSetVisible(boolean visible) {
   if (log.isLoggable(Level.FINE)) log.fine("Setting visible on " + this + " to " + visible);
   XToolkit.awtLock();
   try {
     this.visible = visible;
     if (visible) {
       XlibWrapper.XMapWindow(XToolkit.getDisplay(), getWindow());
     } else {
       XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
     }
     XlibWrapper.XFlush(XToolkit.getDisplay());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #22
0
 void updateWMName() {
   String name = getWMName();
   XToolkit.awtLock();
   try {
     if (name == null) {
       name = " ";
     }
     XAtom nameAtom = XAtom.get(XAtom.XA_WM_NAME);
     nameAtom.setProperty(getWindow(), name);
     XAtom netNameAtom = XAtom.get("_NET_WM_NAME");
     netNameAtom.setPropertyUTF8(getWindow(), name);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #23
0
 void updateWMName() {
   super.updateWMName();
   String name = getWMName();
   XToolkit.awtLock();
   try {
     if (name == null || name.trim().equals("")) {
       name = "Java";
     }
     XAtom iconNameAtom = XAtom.get(XAtom.XA_WM_ICON_NAME);
     iconNameAtom.setProperty(getWindow(), name);
     XAtom netIconNameAtom = XAtom.get("_NET_WM_ICON_NAME");
     netIconNameAtom.setPropertyUTF8(getWindow(), name);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #24
0
  /**
   * 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;
  }
 void postInit(XCreateWindowParams params) {
   super.postInit(params);
   if (embedder != null) {
     // install X11 event dispatcher
     embedder.setClient(this);
     // reparent to XEmbed server
     embedder.install();
   } else if (getParentWindowHandle() != 0) {
     XToolkit.awtLock();
     try {
       XlibWrapper.XReparentWindow(
           XToolkit.getDisplay(), getWindow(), getParentWindowHandle(), 0, 0);
     } finally {
       XToolkit.awtUnlock();
     }
   }
 }
Пример #26
0
 public Point getLocationOnScreen() {
   XToolkit.awtLock();
   try {
     if (configure_seen) {
       return toGlobal(0, 0);
     } else {
       Point location = target.getLocation();
       if (insLog.isLoggable(Level.FINE))
         insLog.log(
             Level.FINE,
             "getLocationOnScreen {0} not reparented: {1} ",
             new Object[] {String.valueOf(this), String.valueOf(location)});
       return location;
     }
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #27
0
 public Dimension getMinimumSize() {
   if (isXEmbedActive()) {
     XToolkit.awtLock();
     try {
       long p_hints = XlibWrapper.XAllocSizeHints();
       XSizeHints hints = new XSizeHints(p_hints);
       XlibWrapper.XGetWMNormalHints(
           XToolkit.getDisplay(), xembed.handle, p_hints, XlibWrapper.larg1);
       Dimension res = new Dimension(hints.get_min_width(), hints.get_min_height());
       XlibWrapper.XFree(p_hints);
       return res;
     } finally {
       XToolkit.awtUnlock();
     }
   } else {
     return super.getMinimumSize();
   }
 }
Пример #28
0
 /**
  * Dispatches event to the grab Window or event source window depending on whether the grab is
  * active and on the event type
  */
 static void dispatchToWindow(XEvent ev) {
   XBaseWindow target = XAwtState.getGrabWindow();
   if (target == null || !isGrabbedEvent(ev, target)) {
     target = XToolkit.windowToXWindow(ev.get_xany().get_window());
   }
   if (target != null && target.checkInitialised()) {
     target.dispatchEvent(ev);
   }
 }
Пример #29
0
    @Override
    public void installUI(JComponent c) {
      super.installUI(c);

      jtf = (JTextField) c;

      JTextField editor = jtf;

      UIDefaults uidefaults = XToolkit.getUIDefaults();

      String prefix = getPropertyPrefix();
      Font f = editor.getFont();
      if ((f == null) || (f instanceof UIResource)) {
        editor.setFont(uidefaults.getFont(prefix + ".font"));
      }

      Color bg = editor.getBackground();
      if ((bg == null) || (bg instanceof UIResource)) {
        editor.setBackground(uidefaults.getColor(prefix + ".background"));
      }

      Color fg = editor.getForeground();
      if ((fg == null) || (fg instanceof UIResource)) {
        editor.setForeground(uidefaults.getColor(prefix + ".foreground"));
      }

      Color color = editor.getCaretColor();
      if ((color == null) || (color instanceof UIResource)) {
        editor.setCaretColor(uidefaults.getColor(prefix + ".caretForeground"));
      }

      Color s = editor.getSelectionColor();
      if ((s == null) || (s instanceof UIResource)) {
        editor.setSelectionColor(uidefaults.getColor(prefix + ".selectionBackground"));
      }

      Color sfg = editor.getSelectedTextColor();
      if ((sfg == null) || (sfg instanceof UIResource)) {
        editor.setSelectedTextColor(uidefaults.getColor(prefix + ".selectionForeground"));
      }

      Color dfg = editor.getDisabledTextColor();
      if ((dfg == null) || (dfg instanceof UIResource)) {
        editor.setDisabledTextColor(uidefaults.getColor(prefix + ".inactiveForeground"));
      }

      Border b = editor.getBorder();
      if ((b == null) || (b instanceof UIResource)) {
        editor.setBorder(uidefaults.getBorder(prefix + ".border"));
      }

      Insets margin = editor.getMargin();
      if (margin == null || margin instanceof UIResource) {
        editor.setMargin(uidefaults.getInsets(prefix + ".margin"));
      }
    }
Пример #30
0
 public void revalidate() {
   XToolkit.executeOnEventHandlerThread(
       target,
       new Runnable() {
         public void run() {
           target.invalidate();
           target.validate();
         }
       });
 }