void preInit(XCreateWindowParams params) {
   super.preInit(params);
   params.putIfNull(BIT_GRAVITY, Integer.valueOf(XConstants.NorthWestGravity));
   Long eventMask = (Long) params.get(EVENT_MASK);
   if (eventMask != null) {
     eventMask = eventMask & ~(XConstants.StructureNotifyMask);
     params.put(EVENT_MASK, eventMask);
   }
 }
 /**
  * Updates the source action according to the specified state.
  *
  * @returns true if the source
  */
 private boolean updateSourceAction(int state) {
   int action =
       SunDragSourceContextPeer.convertModifiersToDropAction(
           XWindow.getModifiers(state, 0, 0), sourceActions);
   if (sourceAction == action) {
     return false;
   }
   sourceAction = action;
   return true;
 }
  /*
   * DO NOT USE is_hint field of xmotion since it could not be set when we
   * convert XKeyEvent or XButtonRelease to XMotionEvent.
   */
  private void processMouseMove(XMotionEvent xmotion) {
    if (!dragInProgress) {
      return;
    }
    if (xRoot != xmotion.get_x_root() || yRoot != xmotion.get_y_root()) {
      xRoot = xmotion.get_x_root();
      yRoot = xmotion.get_y_root();

      postDragSourceDragEvent(
          targetAction,
          XWindow.getModifiers(xmotion.get_state(), 0, 0),
          xRoot,
          yRoot,
          DISPATCH_MOUSE_MOVED);
    }

    if (eventState != xmotion.get_state()) {
      if (updateSourceAction(xmotion.get_state()) && dragProtocol != null) {
        postDragSourceDragEvent(
            targetAction,
            XWindow.getModifiers(xmotion.get_state(), 0, 0),
            xRoot,
            yRoot,
            DISPATCH_CHANGED);
      }
      eventState = xmotion.get_state();
    }

    updateTargetWindow(xmotion);

    if (dragProtocol != null) {
      dragProtocol.sendMoveMessage(
          xmotion.get_x_root(),
          xmotion.get_y_root(),
          sourceAction,
          sourceActions,
          xmotion.get_time());
    }
  }
Example #4
0
  /**
   * ******************************************************************* create a new frame with a
   * new container window inside, which isn't part of the global frame tree.
   *
   * <p>Attention: a) This frame wont be destroyed by the office. It must be closed by you! Do so -
   * please call XCloseable::close(). b) The container window is part of the frame. Dont hold it
   * alive - nor try to kill it. It will be destroyed inside close().
   */
  public void createPreviewFrame(XMultiServiceFactory xmsf, XControl xControl)
      throws com.sun.star.uno.Exception, com.sun.star.lang.IllegalArgumentException {
    XWindowPeer controlPeer = xControl.getPeer();
    XWindow controlWindow = UnoRuntime.queryInterface(XWindow.class, xControl);
    Rectangle r = controlWindow.getPosSize();

    Object toolkit = xmsf.createInstance("com.sun.star.awt.Toolkit");
    XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, toolkit);

    WindowDescriptor aDescriptor = new WindowDescriptor();
    aDescriptor.Type = WindowClass.SIMPLE;
    aDescriptor.WindowServiceName = "window";
    aDescriptor.ParentIndex = -1;
    aDescriptor.Parent = controlPeer; // xWindowPeer; //argument !
    aDescriptor.Bounds = new Rectangle(0, 0, r.Width, r.Height);
    aDescriptor.WindowAttributes = VclWindowPeerAttribute.CLIPCHILDREN | WindowAttribute.SHOW;

    XWindowPeer xPeer = xToolkit.createWindow(aDescriptor);
    xWindow = UnoRuntime.queryInterface(XWindow.class, xPeer);
    Object frame = xmsf.createInstance("com.sun.star.frame.Frame");
    xFrame = UnoRuntime.queryInterface(XFrame.class, frame);
    xFrame.initialize(xWindow);
    xWindow.setVisible(true);
  }
  @Override
  public void run() {
    // TODO Auto-generated method stub
    XdroidActivity.XWindows[XWindow.SelectedWindow].Maximize(context);
    XWindow.RefreshWindowList(context);

    try {
      Message msg = XdroidActivity.dvHandler.obtainMessage();
      msg.what = Runners.WindowMaximizeWhat;
      XdroidActivity.dvHandler.sendMessage(msg);
    } catch (Exception ex) {
      Log.w("dbg", "Exception during WindowMaximizeRunner");
      Log.w("dbg", ":: " + ex.getMessage());
    }
  }
Example #6
0
  /*
   * Tracks changes of available formats.
   * NOTE: This method may be called by privileged threads.
   *       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
   */
  private void checkChange(XSelectionEvent xse) {
    final long propertyAtom = xse.get_property();
    if (propertyAtom != getTargetsPropertyAtom().getAtom()) {
      // wrong atom
      return;
    }

    final XAtom selectionAtom = XAtom.get(xse.get_selection());
    final XSelection changedSelection = XSelection.getSelection(selectionAtom);

    if (null == changedSelection || changedSelection != selection) {
      // unknown selection - do nothing
      return;
    }

    isSelectionNotifyProcessed = true;

    if (selection.isOwner()) {
      // selection is owner - do not need formats
      return;
    }

    long[] formats = null;

    if (propertyAtom == XConstants.None) {
      // We treat None property atom as "empty selection".
      formats = new long[0];
    } else {
      WindowPropertyGetter targetsGetter =
          new WindowPropertyGetter(
              XWindow.getXAWTRootWindow().getWindow(),
              XAtom.get(propertyAtom),
              0,
              XSelection.MAX_LENGTH,
              true,
              XConstants.AnyPropertyType);
      try {
        targetsGetter.execute();
        formats = XSelection.getFormats(targetsGetter);
      } finally {
        targetsGetter.dispose();
      }
    }

    checkChange(formats);
  }
Example #7
0
 public void dispatchEvent(XEvent ev) {
   if (ev.get_type() == XConstants.SelectionNotify) {
     final XSelectionEvent xse = ev.get_xselection();
     XClipboard clipboard = null;
     synchronized (XClipboard.classLock) {
       if (targetsAtom2Clipboard != null && !targetsAtom2Clipboard.isEmpty()) {
         XToolkit.removeEventDispatcher(XWindow.getXAWTRootWindow().getWindow(), this);
         return;
       }
       final long propertyAtom = xse.get_property();
       clipboard = targetsAtom2Clipboard.get(propertyAtom);
     }
     if (null != clipboard) {
       clipboard.checkChange(xse);
     }
   }
 }
Example #8
0
 // checkChange() will be called on SelectionNotify
 private void getTargetsDelayed() {
   XToolkit.awtLock();
   try {
     long curTime = System.currentTimeMillis();
     if (isSelectionNotifyProcessed
         || curTime >= (convertSelectionTime + UNIXToolkit.getDatatransferTimeout())) {
       convertSelectionTime = curTime;
       XlibWrapper.XConvertSelection(
           XToolkit.getDisplay(),
           selection.getSelectionAtom().getAtom(),
           XDataTransferer.TARGETS_ATOM.getAtom(),
           getTargetsPropertyAtom().getAtom(),
           XWindow.getXAWTRootWindow().getWindow(),
           XConstants.CurrentTime);
       isSelectionNotifyProcessed = false;
     }
   } finally {
     XToolkit.awtUnlock();
   }
 }
Example #9
0
  protected void registerClipboardViewerChecked() {
    // for XConvertSelection() to be called for the first time in getTargetsDelayed()
    isSelectionNotifyProcessed = true;

    boolean mustSchedule = false;
    synchronized (XClipboard.classLock) {
      if (targetsAtom2Clipboard == null) {
        targetsAtom2Clipboard = new HashMap<Long, XClipboard>(2);
      }
      mustSchedule = targetsAtom2Clipboard.isEmpty();
      targetsAtom2Clipboard.put(getTargetsPropertyAtom().getAtom(), this);
      if (mustSchedule) {
        XToolkit.addEventDispatcher(
            XWindow.getXAWTRootWindow().getWindow(), new SelectionNotifyHandler());
      }
    }
    if (mustSchedule) {
      XToolkit.schedule(new CheckChangeTimerTask(), XClipboard.getPollInterval());
    }
  }
  public void handleExposeEvent(Component target, int x, int y, int w, int h) {
    // TODO: ?
    // get rid of 'istanceof' by subclassing:
    // XContentWindow -> XFrameContentWindow

    // Expose event(s) that result from deiconification
    // come before a deicinofication notification.
    // We reorder these events by saving all expose events
    // that come when the frame is iconified. Then we
    // actually handle saved expose events on deiconification.

    if (parentFrame instanceof XFramePeer
        && (((XFramePeer) parentFrame).getState() & java.awt.Frame.ICONIFIED) != 0) {
      // Save expose events if the frame is iconified
      // in order to handle them on deiconification.
      iconifiedExposeEvents.add(new SavedExposeEvent(target, x, y, w, h));
    } else {
      // Normal case: [it is not a frame or] the frame is not iconified.
      super.handleExposeEvent(target, x, y, w, h);
    }
  }
Example #11
0
    private void init(KeyEvent e) {
      byte[] bdata = getBData(e);
      long data = Native.toData(bdata);
      if (data == 0) {
        return;
      }
      try {
        XToolkit.awtLock();
        try {
          keysym = XWindow.getKeySymForAWTKeyCode(e.getKeyCode());
        } finally {
          XToolkit.awtUnlock();
        }
        XKeyEvent ke = new XKeyEvent(data);

        // We recognize only these masks
        modifiers =
            ke.get_state() & (XConstants.ShiftMask | XConstants.ControlMask | XConstants.LockMask);
        if (xembedLog.isLoggable(PlatformLogger.FINEST))
          xembedLog.finest("Mapped " + e + " to " + this);
      } finally {
        XlibWrapper.unsafe.freeMemory(data);
      }
    }
 void purgeIconifiedExposeEvents() {
   for (SavedExposeEvent evt : iconifiedExposeEvents) {
     super.handleExposeEvent(evt.target, evt.x, evt.y, evt.w, evt.h);
   }
   iconifiedExposeEvents.clear();
 }
 public void handleDragReply(int action, int x, int y) {
   // NOTE: we have to use the current modifiers state, since
   // the target didn't specify the modifiers state for the reply.
   handleDragReply(action, xRoot, yRoot, XWindow.getModifiers(eventState, 0, 0));
 }
  protected void startDrag(Transferable transferable, long[] formats, Map formatMap) {
    Component component = getTrigger().getComponent();
    Component c = null;
    XWindowPeer wpeer = null;

    for (c = component;
        c != null && !(c instanceof Window);
        c = AWTAccessor.getComponentAccessor().getParent(c)) ;

    if (c instanceof Window) {
      wpeer = (XWindowPeer) c.getPeer();
    }

    if (wpeer == null) {
      throw new InvalidDnDOperationException("Cannot find top-level for the drag source component");
    }

    long xcursor = 0;
    long rootWindow = 0;
    long dragWindow = 0;
    long timeStamp = 0;

    /* Retrieve the X cursor for the drag operation. */
    {
      Cursor cursor = getCursor();
      if (cursor != null) {
        xcursor = XGlobalCursorManager.getCursor(cursor);
      }
    }

    XToolkit.awtLock();
    try {
      if (proxyModeSourceWindow != 0) {
        throw new InvalidDnDOperationException("Proxy drag in progress");
      }
      if (dndInProgress) {
        throw new InvalidDnDOperationException("Drag in progress");
      }

      /* Determine the root window for the drag operation. */
      {
        long screen = XlibWrapper.XScreenNumberOfScreen(wpeer.getScreen());
        rootWindow = XlibWrapper.RootWindow(XToolkit.getDisplay(), screen);
      }

      dragWindow = XWindow.getXAWTRootWindow().getWindow();

      timeStamp = XToolkit.getCurrentServerTime();

      int dropActions = getDragSourceContext().getSourceActions();

      Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
      while (dragProtocols.hasNext()) {
        XDragSourceProtocol dragProtocol = (XDragSourceProtocol) dragProtocols.next();
        try {
          dragProtocol.initializeDrag(
              dropActions, transferable,
              formatMap, formats);
        } catch (XException xe) {
          throw (InvalidDnDOperationException) new InvalidDnDOperationException().initCause(xe);
        }
      }

      /* Install X grabs. */
      {
        int status;
        XWindowAttributes wattr = new XWindowAttributes();
        try {
          status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), rootWindow, wattr.pData);

          if (status == 0) {
            throw new InvalidDnDOperationException("XGetWindowAttributes failed");
          }

          rootEventMask = wattr.get_your_event_mask();

          XlibWrapper.XSelectInput(
              XToolkit.getDisplay(), rootWindow, rootEventMask | ROOT_EVENT_MASK);
        } finally {
          wattr.dispose();
        }

        XBaseWindow.ungrabInput();

        status =
            XlibWrapper.XGrabPointer(
                XToolkit.getDisplay(),
                rootWindow,
                0,
                GRAB_EVENT_MASK,
                XConstants.GrabModeAsync,
                XConstants.GrabModeAsync,
                XConstants.None,
                xcursor,
                timeStamp);

        if (status != XConstants.GrabSuccess) {
          cleanup(timeStamp);
          throwGrabFailureException("Cannot grab pointer", status);
          return;
        }

        status =
            XlibWrapper.XGrabKeyboard(
                XToolkit.getDisplay(),
                rootWindow,
                0,
                XConstants.GrabModeAsync,
                XConstants.GrabModeAsync,
                timeStamp);

        if (status != XConstants.GrabSuccess) {
          cleanup(timeStamp);
          throwGrabFailureException("Cannot grab keyboard", status);
          return;
        }
      }

      /* Update the global state. */
      dndInProgress = true;
      dragInProgress = true;
      dragRootWindow = rootWindow;
      sourceActions = dropActions;
      sourceFormats = formats;
    } finally {
      XToolkit.awtUnlock();
    }

    /* This implementation doesn't use native context */
    setNativeContext(0);

    SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable);
  }