private Point computeMenuLocation(Control focus, Menu menu) {
   Point cursorLocation = focus.getDisplay().getCursorLocation();
   Rectangle clientArea = null;
   Point result = null;
   if (focus instanceof StyledText) {
     StyledText styledText = (StyledText) focus;
     clientArea = styledText.getClientArea();
     result = computeMenuLocation(styledText);
   } else if (focus instanceof Tree) {
     Tree tree = (Tree) focus;
     clientArea = tree.getClientArea();
     result = computeMenuLocation(tree);
   } else if (focus instanceof Table) {
     Table table = (Table) focus;
     clientArea = table.getClientArea();
     result = computeMenuLocation(table);
   }
   if (result == null) {
     result = focus.toControl(cursorLocation);
   }
   if (clientArea != null && !clientArea.contains(result)) {
     result = new Point(clientArea.x + clientArea.width / 2, clientArea.y + clientArea.height / 2);
   }
   Rectangle shellArea = focus.getShell().getClientArea();
   if (!shellArea.contains(focus.getShell().toControl(focus.toDisplay(result)))) {
     result = new Point(shellArea.x + shellArea.width / 2, shellArea.y + shellArea.height / 2);
   }
   return focus.toDisplay(result);
 }
 protected Point[] determineLocations(int paramA, int paramB, int paramC, int paramD, int method) {
   Point[] array = new Point[2];
   if (method >= ConsistencyUtility.MOUSE_CLICK) array[0] = control.toDisplay(paramA, paramB);
   if (method >= ConsistencyUtility.MOUSE_DRAG) array[1] = control.toDisplay(paramC, paramD);
   if (method == ConsistencyUtility.MOUSE_CLICK && paramD == ConsistencyUtility.ESCAPE_MENU)
     array[1] = shell.toDisplay(25, -10);
   else if (method == ConsistencyUtility.SHELL_ICONIFY) {
     array[0] = control.toDisplay(0, 0);
     array[1] = control.toDisplay(control.getSize().x - 20, 0);
   }
   return array;
 }
 /**
  * @see ch.post.pf.gui.ocp.wt.ext.dialogs.OcpDialog#showDialogFor(org.eclipse.swt.widgets.Control)
  */
 public int showDialogFor(Control field) {
   create();
   getShell()
       .addShellListener(
           new ShellAdapter() {
             @Override
             public void shellDeactivated(ShellEvent e) {
               close();
             }
           });
   // make sure that the popup fit into the application window.
   Rectangle appBounds = getEnvironment().getDisplay().getBounds();
   Point absPrefPos =
       field.toDisplay(field.getSize().x - getShell().getSize().x, field.getSize().y);
   Rectangle prefBounds =
       new Rectangle(absPrefPos.x, absPrefPos.y, getShell().getSize().x, getShell().getSize().y);
   // horizontal correction
   if (prefBounds.x + prefBounds.width > appBounds.width) {
     prefBounds.x = appBounds.width - prefBounds.width;
   }
   // vertical correciton
   if (prefBounds.y + prefBounds.height > appBounds.height) {
     prefBounds.y = appBounds.height - prefBounds.height;
   }
   getShell().setLocation(prefBounds.x, prefBounds.y);
   int ret = this.open();
   return ret;
 }
    public void handleEvent(final Event event) {
      // only go further if the event has a new time stamp
      if (mayScroll() && acceptEvent(event)) {
        lastEventTime = event.time;
        final Rectangle navigationComponentBounds = getNavigationComponent().getBounds();

        // convert navigation bounds relative to display
        final Point navigationPtAtDisplay = getNavigationComponent().toDisplay(0, 0);
        navigationComponentBounds.x = navigationPtAtDisplay.x;
        navigationComponentBounds.y = navigationPtAtDisplay.y;

        if (event.widget instanceof Control) {
          final Control widget = (Control) event.widget;
          // convert widget event point relative to display
          final Point evtPt = widget.toDisplay(event.getBounds().x, event.getBounds().y);
          // now check if inside navigation
          if (navigationComponentBounds.contains(evtPt.x, evtPt.y)) {
            if (event.count > 0) {
              scrollUp(SCROLLING_STEP);
            } else {
              scrollDown(SCROLLING_STEP);
            }
          }
        }
      }
    }
  /**
   * Get an area from the segment display position which can be hovered and the tooltip do not get
   * hidden.
   *
   * @param control
   * @param displayCursorLocation
   * @return
   */
  public boolean isInNoHideArea(final Control control, final Point displayCursorLocation) {

    final Point segmentDisplayPosition = control.toDisplay(devXSegment, 0);

    final Rectangle segmentArea =
        new Rectangle(
            segmentDisplayPosition.x,
            segmentDisplayPosition.y,
            devSegmentWidth,
            devYTitle + titleHeight);

    return segmentArea.contains(displayCursorLocation);
  }
 void ourPlaceMouseInViewer(Point p) {
   if (getCurrentViewer() == null) return;
   Control c = getCurrentViewer().getControl();
   Rectangle rect;
   if (c instanceof Scrollable) rect = ((Scrollable) c).getClientArea();
   else rect = c.getBounds();
   if (p.x > rect.x + rect.width - 1) p.x = rect.x + rect.width - 1;
   else if (p.x < rect.x) p.x = rect.x;
   if (p.y > rect.y + rect.height - 1) p.y = rect.y + rect.height - 1;
   else if (p.y < rect.y) p.y = rect.y;
   org.eclipse.swt.graphics.Point swt = new org.eclipse.swt.graphics.Point(p.x, p.y);
   swt = c.toDisplay(swt);
   c.getDisplay().setCursorLocation(swt);
 }
Exemple #7
0
  public Image captureImage(Control control) {
    Rectangle rectangle = control.getBounds();
    Display display = control.getDisplay();
    Image image = null;
    if (control instanceof Shell) {
      Shell shell = (Shell) control;
      shell.layout();
      Point parentLocation = control.toDisplay(0, 0);
      image = getImage(control, rectangle.width, rectangle.height, false);

      rectangle.x = parentLocation.x;
      rectangle.y = parentLocation.y;

      GC myImageGC = new GC(image);
      try {
        for (Control child : shell.getChildren()) {
          Rectangle childBounds = child.getBounds();
          // bug of SWT on Win32, child bounds is not correct in the Window is not in the ToolBar
          int x = (rectangle.width - childBounds.width) / 2;
          int y = (rectangle.height - childBounds.height) - x;
          childBounds.x = rectangle.x + x;
          childBounds.y = rectangle.y + y;
          if (!rectangle.intersects(childBounds)) continue; // Child is completely outside parent.

          Image childImage = new Image(display, child.getBounds());
          GC gc = new GC(childImage);
          child.print(gc);
          DisposeUtil.dispose(gc);
          try {
            myImageGC.drawImage(childImage, x, y);
          } finally {
            childImage.dispose();
          }
        }
      } finally {
        myImageGC.dispose();
      }
    } else {
      image = defaultCapture(control);
    }
    return image;
  }
Exemple #8
0
  public void runWithEvent(Event e) {
    if (selectedAction == null) {

      final Control parent =
          e.widget != null && e.widget instanceof ToolItem
              ? ((ToolItem) e.widget).getParent()
              : null;
      Menu m = getMenu(parent);
      if (m != null) {
        // position the menu below the drop down item
        Point point = parent.toDisplay(new Point(e.x, e.y));
        m.setLocation(point.x, point.y); // waiting
        // for SWT
        // 0.42
        m.setVisible(true); // for SWT
      }

    } else {
      run();
    }
  }
Exemple #9
0
 private Point getMessageLocation(Control control) {
   Point point = control.toDisplay(0, 0);
   point.y += control.getBounds().height + 2;
   return point;
 }