Exemplo n.º 1
0
  protected void actionPerformImpl(GComponent gComponent) {

    XAccessible xAccessible = getAccessible(gComponent);

    XAccessibleContext xAccessibleContext = xAccessible.getAccessibleContext();
    if (xAccessibleContext == null) return;

    XAccessibleAction xAction =
        (XAccessibleAction) UnoRuntime.queryInterface(XAccessibleAction.class, xAccessibleContext);

    if (xAction == null) return;
    try {
      int nActions = xAction.getAccessibleActionCount();
      for (int j = 0; j < nActions; j++) {
        xAction.doAccessibleAction(j);
      }
    } catch (IndexOutOfBoundsException e) {
      System.err.println("Cannot click");
      e.printStackTrace();
    }
  }
  /**
   * Get the closer button on the right top of the current window.
   *
   * @return A point representing the closer button.
   */
  private Point getCloser(Point center) {
    XMultiServiceFactory xMSF = tParam.getMSF();
    Object aToolkit = null;
    try {
      aToolkit = xMSF.createInstance("com.sun.star.awt.Toolkit");
    } catch (com.sun.star.uno.Exception e) {
      throw new StatusException("Could not create 'com.sun.star.awt.Toolkit'.", e);
    }
    XExtendedToolkit xExtendedToolkit = UnoRuntime.queryInterface(XExtendedToolkit.class, aToolkit);
    XTopWindow tw = null;

    XAccessibleComponent xAccessibleComponent = null;
    int k = xExtendedToolkit.getTopWindowCount();
    for (int i = 0; i < k; i++) {
      try {
        XTopWindow tw_temp = xExtendedToolkit.getTopWindow(i);
        XAccessible xacc = UnoRuntime.queryInterface(XAccessible.class, tw_temp);
        if (xacc != null) {
          System.out.println("Name: " + xacc.getAccessibleContext().getAccessibleName());
          if (xacc.getAccessibleContext().getAccessibleName().startsWith("the title")) {
            tw = tw_temp;
            XAccessibleContext xContext = xacc.getAccessibleContext();
            xAccessibleComponent = UnoRuntime.queryInterface(XAccessibleComponent.class, xContext);
            if (xAccessibleComponent == null) System.out.println("!!!! MIST !!!!");
            else System.out.println("########## KLAPPT ########## ");
          }
        } else {
          log.println("\t unknown window");
        }

      } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
      }
    }
    if (tw == null) {
      System.out.println("No TopWindow :-(");
      return null;
    }

    XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, tw);
    Rectangle posSize = xWindow.getPosSize();

    // compare the center point with the dimensions of the current top window
    boolean windowOK = false;
    while (!windowOK) {
      if (posSize.X <= center.X && center.X <= posSize.X + posSize.Width) {
        if (posSize.Y <= center.Y && center.Y <= posSize.Y + posSize.Height) {
          // move window out of the way
          posSize.X = posSize.X + 10;
          posSize.Y = posSize.Y + 10;
          xWindow.setPosSize(posSize.X, posSize.Y, posSize.Width, posSize.Height, PosSize.POS);
        } else {
          windowOK = true;
        }
      } else {
        windowOK = true;
      }
    }

    Point p = xAccessibleComponent.getLocationOnScreen();
    Point closer = new Point();
    closer.X = p.X + posSize.Width - 2;
    closer.Y = p.Y + 5;
    System.out.println("Closer: " + closer.X + "   " + closer.Y);
    return closer;
  }
  /**
   * Determine the current top window center and return this as a point.
   *
   * @return a point representing the sheet center.
   */
  protected Point getSheetCenter() {
    log.println("Trying to get AccessibleSpreadsheet");
    new AccessibilityTools();
    XComponent xSheetDoc = (XComponent) tEnv.getObjRelation("DOCUMENT");

    XModel xModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
    System.out.println("Name: " + xModel.getCurrentController().getFrame().getName());

    XWindow xWindow = AccessibilityTools.getCurrentWindow(xModel);
    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    XAccessibleContext ctx =
        AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);

    XAccessibleComponent AccessibleSpreadsheet =
        UnoRuntime.queryInterface(XAccessibleComponent.class, ctx);

    log.println("Got " + util.utils.getImplName(AccessibleSpreadsheet));

    Object toolkit = null;

    try {
      toolkit = tParam.getMSF().createInstance("com.sun.star.awt.Toolkit");
    } catch (com.sun.star.uno.Exception e) {
      log.println("Couldn't get toolkit");
      e.printStackTrace(log);
      throw new StatusException("Couldn't get toolkit", e);
    }

    XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class, toolkit);

    XTopWindow tw = null;

    int k = tk.getTopWindowCount();
    for (int i = 0; i < k; i++) {
      try {
        XTopWindow tw_temp = tk.getTopWindow(i);
        XAccessible xacc = UnoRuntime.queryInterface(XAccessible.class, tw_temp);
        if (xacc != null) {
          if (xacc.getAccessibleContext().getAccessibleName().indexOf("d2") > 0) {
            tw = tw_temp;
          }
        } else {
          log.println("\t unknown window");
        }

      } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
      }
    }
    if (tw == null) {
      System.out.println("No TopWindow :-(");
      return null;
    }

    Point point = AccessibleSpreadsheet.getLocationOnScreen();
    Rectangle rect = AccessibleSpreadsheet.getBounds();
    Point retPoint = new Point();
    retPoint.X = point.X + (rect.Width / 2);
    retPoint.Y = point.Y + (rect.Height / 2);
    return retPoint;
  }