예제 #1
0
  private Point fixupDisplayBounds(final Point tipSize, final Point location) {

    final Rectangle displayBounds = getDisplayBounds(location);
    final Point rightBottomBounds = new Point(tipSize.x + location.x, tipSize.y + location.y);

    if (!(displayBounds.contains(location) && displayBounds.contains(rightBottomBounds))) {

      if (rightBottomBounds.x > displayBounds.x + displayBounds.width) {
        location.x -= rightBottomBounds.x - (displayBounds.x + displayBounds.width);
      }

      if (rightBottomBounds.y > displayBounds.y + displayBounds.height) {
        // ignore when tt is below the bottom, force the user to resize the tt
        //				location.y -= rightBottomBounds.y - (displayBounds.y + displayBounds.height);
      }

      if (location.x < displayBounds.x) {
        location.x = displayBounds.x;
      }

      if (location.y < displayBounds.y) {
        location.y = displayBounds.y;
      }
    }

    return location;
  }
예제 #2
0
 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);
 }
예제 #3
0
 /**
  * Scrolls the content so that the given revision is visible.
  *
  * @param revision the revision to scroll the client area to.
  */
 private void scrollToRevision(Revision revision) {
   Rectangle revBounds = revision.getBounds();
   Rectangle clientArea = getClientArea();
   clientArea.x = getOrigin().x;
   clientArea.y = getOrigin().y;
   if (!clientArea.contains(revBounds.x, revBounds.y)
       && !clientArea.contains(revBounds.x + revBounds.width, revBounds.y + revBounds.height)) {
     setOrigin(revBounds.x, revBounds.y);
   }
 }
예제 #4
0
 void tableMouseDown(Event event) {
   if (isDisposed() || !isVisible()) return;
   Point pt = new Point(event.x, event.y);
   int lineWidth = table.getLinesVisible() ? table.getGridLineWidth() : 0;
   TableItem item = table.getItem(pt);
   if ((table.getStyle() & SWT.FULL_SELECTION) != 0) {
     if (item == null) return;
   } else {
     int start = item != null ? table.indexOf(item) : table.getTopIndex();
     int end = table.getItemCount();
     Rectangle clientRect = table.getClientArea();
     for (int i = start; i < end; i++) {
       TableItem nextItem = table.getItem(i);
       Rectangle rect = nextItem.getBounds(0);
       if (pt.y >= rect.y && pt.y < rect.y + rect.height + lineWidth) {
         item = nextItem;
         break;
       }
       if (rect.y > clientRect.y + clientRect.height) return;
     }
     if (item == null) return;
   }
   TableColumn newColumn = null;
   int columnCount = table.getColumnCount();
   if (columnCount == 0) {
     if ((table.getStyle() & SWT.FULL_SELECTION) == 0) {
       Rectangle rect = item.getBounds(0);
       rect.width += lineWidth;
       rect.height += lineWidth;
       if (!rect.contains(pt)) return;
     }
   } else {
     for (int i = 0; i < columnCount; i++) {
       Rectangle rect = item.getBounds(i);
       rect.width += lineWidth;
       rect.height += lineWidth;
       if (rect.contains(pt)) {
         newColumn = table.getColumn(i);
         break;
       }
     }
     if (newColumn == null) {
       if ((table.getStyle() & SWT.FULL_SELECTION) == 0) return;
       newColumn = table.getColumn(0);
     }
   }
   setRowColumn(item, newColumn, true);
   setFocus();
   return;
 }
예제 #5
0
 private IHyperlink getHyperlink(MouseEvent e) {
   // bug 257868 support image hyperlinks
   if (annotations.isEmpty()) {
     return null;
   }
   Point point = new Point(e.x, e.y);
   for (ImageAnnotation annotation : annotations) {
     if (annotation.getHyperlnkAnnotation() == null) {
       continue;
     }
     Rectangle region = getRegion(annotation);
     if (region != null) {
       if (region.contains(point)) {
         AnnotationHyperlinkDetector detector =
             (AnnotationHyperlinkDetector)
                 viewer.getTextWidget().getData(AnnotationHyperlinkDetector.class.getName());
         if (detector != null) {
           IHyperlink hyperlink =
               detector.createHyperlink(
                   viewer, viewer.getAnnotationModel(), annotation.getHyperlnkAnnotation());
           return hyperlink;
         }
       }
     }
   }
   return null;
 }
  @Override
  public boolean track(MUIElement dragElement, DnDInfo info) {
    if (!clientBounds.contains(info.cursorPos)) return false;

    boolean wasOnEdge = onEdge;
    int dockLocation = getDockLocation(info);

    if (feedback != null) {
      feedback.setFeedback(getEnclosed(), getModified());
    }

    if (dockLocation == curDockLocation && wasOnEdge == onEdge) return true;

    if (dropStack == dragElement && !onEdge) return false;

    curDockLocation = dockLocation;

    if (curDockLocation != NOWHERE) {
      showFeedback(curDockLocation);
      dndManager.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
    } else {
      unDock(dragElement);
      dndManager.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_NO));
    }

    return true;
  }
예제 #7
0
  private Rectangle getDisplayBounds(final Point location) {

    Rectangle displayBounds;
    final Monitor[] allMonitors = _ownerControl.getDisplay().getMonitors();

    if (allMonitors.length > 1) {
      // By default present in the monitor of the control
      displayBounds = _ownerControl.getMonitor().getBounds();
      final Point p = new Point(location.x, location.y);

      // Search on which monitor the event occurred
      Rectangle tmp;
      for (final Monitor element : allMonitors) {
        tmp = element.getBounds();
        if (tmp.contains(p)) {
          displayBounds = tmp;
          break;
        }
      }

    } else {
      displayBounds = _ownerControl.getDisplay().getBounds();
    }

    return displayBounds;
  }
  /**
   * Handling mouse over event to display hand cursor in case cell contains an URL
   *
   * @param e mouse event
   */
  void handleMouseOver(MouseEvent e) {
    Point pt = new Point(e.x, e.y);
    ViewerCell cell = getViewer().getCell(pt);
    boolean cursorSet = false;

    if (cell != null) {
      int colIndex = cell.getColumnIndex();
      Object element = cell.getElement();
      if (getCellControlType(element, colIndex) == CellControlType.URL) {
        Rectangle cellBounds = cell.getBounds();
        Image img = getImage(element, colIndex);
        if (img != null) {
          cellBounds.x += img.getBounds().width;
        }
        if (cellBounds.contains(pt)) {
          if (getString(element, colIndex) != null) {
            this.control.setCursor(CURSOR_HAND);
            cursorSet = true;
          }
        }
      }
    }

    if (!cursorSet) {
      handleMouseExit(e);
    }
  }
예제 #9
0
 LRESULT WM_MOUSEMOVE(int /*long*/ wParam, int /*long*/ lParam) {
   LRESULT result = super.WM_MOUSEMOVE(wParam, lParam);
   if (OS.COMCTL32_MAJOR < 6) {
     int x = OS.GET_X_LPARAM(lParam);
     int y = OS.GET_Y_LPARAM(lParam);
     if (OS.GetKeyState(OS.VK_LBUTTON) < 0) {
       int oldSelection = selection.y;
       selection.y = layout.getOffset(x, y, null);
       if (selection.y != oldSelection) {
         int newSelection = selection.y;
         if (oldSelection > newSelection) {
           int temp = oldSelection;
           oldSelection = newSelection;
           newSelection = temp;
         }
         Rectangle rect = layout.getBounds(oldSelection, newSelection);
         redraw(rect.x, rect.y, rect.width, rect.height, false);
       }
     } else {
       for (int j = 0; j < offsets.length; j++) {
         Rectangle[] rects = getRectangles(j);
         for (int i = 0; i < rects.length; i++) {
           Rectangle rect = rects[i];
           if (rect.contains(x, y)) {
             setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
             return result;
           }
         }
       }
       setCursor(null);
     }
   }
   return result;
 }
예제 #10
0
  /**
   * Scrolls the containing editor to the given offset of the contained editor
   *
   * @param editor
   * @param scrollTo text offset in the embedded editor that should be revealed
   */
  public void revealSelection(ContainedEditorManager editor, int scrollTo) {
    StyledText containedStyledText = (StyledText) editor.getAdapter(StyledText.class);

    // this progression determines the location of the offset in the coordinate system
    // of the containing styledText
    Point containedLoc = containedStyledText.getLocationAtOffset(scrollTo);
    Point displayLoc = containedStyledText.toDisplay(containedLoc);
    Point containingLoc = styledText.toControl(displayLoc);

    // next, we determine if this location is in the visible area.
    Point containingSize = styledText.getSize();
    Rectangle containingBounds = new Rectangle(0, 0, containingSize.x, containingSize.y);
    if (!containingBounds.contains(containingLoc)) {
      // pad a little to the left and a little bit down
      containingLoc.x -= 50;
      containingLoc.y += 100;

      // if not, then perform a scroll.
      styledText.setTopPixel(styledText.getTopPixel() + containingLoc.y - containingSize.y);

      // do the same for horizontal
      styledText.setHorizontalPixel(styledText.getHorizontalPixel() + containingLoc.x);
    }
    paint(ContainingEditor.EMBEDDED_REPAINT);
  }
예제 #11
0
    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);
            }
          }
        }
      }
    }
예제 #12
0
 /**
  * Is point in event image.
  *
  * @param x
  * @param y
  * @return true if it is, false if its not.
  */
 public boolean isPointInEventImage(int x, int y) {
   if (hasEH) {
     Point p = new Point(x, y);
     getFigure().translateToRelative(p);
     return rectEvent.contains(p.x, p.y);
   }
   return false;
 }
예제 #13
0
  private void drawTile(GC gc, Rectangle bounds, Tile tile, boolean highlight) {
    if (tile == null || tile.equals(Tile.NONE)) return;

    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    int s = Math.min(w, h);
    int n = Math.max(s / 12, 1);
    int x1 = x;
    int x2 = x1 + n;
    int x3 = x + s - n;
    int x4 = x + s;
    int y1 = y;
    int y2 = y1 + n;
    int y3 = y + s - n;
    int y4 = y + s;

    int[] p1 = new int[] {x1, y1, x4, y1, x3, y2, x2, y2, x2, y3, x1, y4};
    int[] p2 = new int[] {x4, y4, x1, y4, x2, y3, x3, y3, x3, y2, x4, y1};

    gc.setBackground(tileFill);
    gc.fillRectangle(x, y, w, h);
    gc.setBackground(highlight ? tileLightHighlight : tileLight);
    gc.fillPolygon(p1);
    gc.setBackground(highlight ? tileDarkHighlight : tileDark);
    gc.fillPolygon(p2);

    if (tile.isWild()) {
      if (!bounds.contains(mousex, mousey)) {
        return;
      }
    }

    Font font = new Font(null, tileFont, s / 2 + 1, SWT.BOLD);
    String string = Character.toString(tile.getLetter()).toUpperCase();
    gc.setFont(font);
    Point extent = gc.stringExtent(string);
    int sx = x + w / 2 - extent.x / 2 - n; // n * 2; //w / 2 - extent.x / 2 - s/8;
    int sy = y + h / 2 - extent.y / 2;
    gc.setForeground(textColor);
    gc.drawString(string, sx, sy, true);
    font.dispose();

    font = new Font(null, tileFont, s / 5, SWT.BOLD);
    string = Integer.toString(game.getTileValues().getValue(tile));
    gc.setFont(font);
    extent = gc.stringExtent(string);
    sx = x + w - n - extent.x - 1;
    sy = y + h - n - extent.y;
    gc.setForeground(textColor);
    gc.drawString(string, sx, sy, true);
    font.dispose();
  }
예제 #14
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
 public static int getColumnAtPos(TreeItem item, int x, int y) {
   int columnCount = item.getParent().getColumnCount();
   for (int i = 0; i < columnCount; i++) {
     Rectangle rect = item.getBounds(i);
     if (rect.contains(x, y)) {
       return i;
     }
   }
   return -1;
 }
 /**
  * Returns the host EditPart when appropriate. Targeting is done by checking if the mouse is
  * clearly over the host's TreeItem.
  *
  * @see org.eclipse.gef.EditPolicy#getTargetEditPart(Request)
  */
 public EditPart getTargetEditPart(Request req) {
   if (req.getType().equals(REQ_ADD)
       || req.getType().equals(REQ_MOVE)
       || req.getType().equals(REQ_CREATE)) {
     DropRequest drop = (DropRequest) req;
     Point where = new Point(drop.getLocation().x, drop.getLocation().y);
     Widget widget = ((TreeEditPart) getHost()).getWidget();
     if (widget instanceof Tree) return getHost();
     TreeItem treeitem = (TreeItem) widget;
     Rectangle bounds = treeitem.getBounds();
     int fudge = bounds.height / 5;
     Rectangle inner =
         new Rectangle(
             bounds.x,
             bounds.y + fudge,
             bounds.width,
             bounds.height - (treeitem.getExpanded() ? 0 : fudge * 2));
     // Point is either outside the Treeitem, or inside the inner Rect.
     if (!bounds.contains(where) || inner.contains(where)) return getHost();
   }
   return null;
 }
예제 #16
0
  /**
   * 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);
  }
예제 #17
0
 /**
  * Returns the tab item at the given point in the receiver or null if no such item exists. The
  * point is in the coordinate system of the receiver.
  *
  * @param point the point used to locate the item
  * @return the tab item at the given point, or null if the point is not in a tab item
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the point is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @since 3.4
  */
 public TabItem getItem(Point point) {
   checkWidget();
   if (point == null) error(SWT.ERROR_NULL_ARGUMENT);
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return null;
   int itemCount = OS.g_list_length(list);
   OS.g_list_free(list);
   for (int i = 0; i < itemCount; i++) {
     TabItem item = items[i];
     Rectangle rect = item.getBounds();
     if (rect.contains(point)) return item;
   }
   return null;
 }
예제 #18
0
 private boolean beginDrag(MouseEvent e) {
   if (drag != null) {
     doDrop(e);
   }
   for (Rectangle rectangle : dragSources.keySet()) {
     if (rectangle.contains(e.x, e.y)) {
       drag = dragSources.get(rectangle);
       if (drag.y == -1) {
         tileRack.remove(drag.x);
       } else {
         placedTiles.remove(new Point(drag.x, drag.y));
       }
       emulateDrop(e);
       return true;
     }
   }
   return false;
 }
예제 #19
0
  private void mouseDown(MouseEvent e) {
    if (game == null) return;
    if (game.getGameState() != GameState.IN_PROGRESS) return;
    if (e.button == 1) {
      // check for drag event
      if (beginDrag(e)) {
        redraw();
        return;
      }

      // update arrow on left mouse click
      int x = e.x;
      int y = e.y;
      boolean del = true;
      for (Iterator i = squareLocations.iterator(); i.hasNext(); ) {
        Square s = (Square) i.next();
        Rectangle r = s.r;
        if (r.contains(x, y)) {
          int n = s.x;
          int m = s.y;
          del = false;
          if (arrow == null || n != arrow.x || m != arrow.y) {
            arrow = new Arrow(n, m, Orientation.HORIZONTAL);
          } else {
            arrow.flip();
          }
          redraw();
        }
      }
      if (del) {
        getLocalTileRack().shuffle();
      }
      resetInput(del);
      redraw();
    } else {
      // stop drag
      doDrop(e);

      // clear typed characters on right mouse click
      resetInput(true);
      redraw();
    }
  }
예제 #20
0
 LRESULT WM_LBUTTONUP(int /*long*/ wParam, int /*long*/ lParam) {
   LRESULT result = super.WM_LBUTTONUP(wParam, lParam);
   if (result == LRESULT.ZERO) return result;
   if (OS.COMCTL32_MAJOR < 6) {
     if (mouseDownIndex == -1) return result;
     int x = OS.GET_X_LPARAM(lParam);
     int y = OS.GET_Y_LPARAM(lParam);
     Rectangle[] rects = getRectangles(mouseDownIndex);
     for (int i = 0; i < rects.length; i++) {
       Rectangle rect = rects[i];
       if (rect.contains(x, y)) {
         Event event = new Event();
         event.text = ids[mouseDownIndex];
         sendSelectionEvent(SWT.Selection, event, true);
         break;
       }
     }
   }
   mouseDownIndex = -1;
   return result;
 }
예제 #21
0
 @Override
 long /*int*/ gtk_button_press_event(long /*int*/ widget, long /*int*/ event) {
   long /*int*/ result = super.gtk_button_press_event(widget, event);
   if (result != 0) return result;
   GdkEventButton gdkEvent = new GdkEventButton();
   OS.memmove(gdkEvent, event, GdkEventButton.sizeof);
   if (gdkEvent.button == 1 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
     if (focusIndex != -1) setFocus();
     int x = (int) gdkEvent.x;
     int y = (int) gdkEvent.y;
     if ((style & SWT.MIRRORED) != 0) x = getClientWidth() - x;
     int offset = layout.getOffset(x, y, null);
     int oldSelectionX = selection.x;
     int oldSelectionY = selection.y;
     selection.x = offset;
     selection.y = -1;
     if (oldSelectionX != -1 && oldSelectionY != -1) {
       if (oldSelectionX > oldSelectionY) {
         int temp = oldSelectionX;
         oldSelectionX = oldSelectionY;
         oldSelectionY = temp;
       }
       Rectangle rect = layout.getBounds(oldSelectionX, oldSelectionY);
       redraw(rect.x, rect.y, rect.width, rect.height, false);
     }
     for (int j = 0; j < offsets.length; j++) {
       Rectangle[] rects = getRectangles(j);
       for (int i = 0; i < rects.length; i++) {
         Rectangle rect = rects[i];
         if (rect.contains(x, y)) {
           focusIndex = j;
           redraw();
           return result;
         }
       }
     }
   }
   return result;
 }
예제 #22
0
 LRESULT WM_LBUTTONDOWN(int /*long*/ wParam, int /*long*/ lParam) {
   LRESULT result = super.WM_LBUTTONDOWN(wParam, lParam);
   if (result == LRESULT.ZERO) return result;
   if (OS.COMCTL32_MAJOR < 6) {
     if (focusIndex != -1) setFocus();
     int x = OS.GET_X_LPARAM(lParam);
     int y = OS.GET_Y_LPARAM(lParam);
     int offset = layout.getOffset(x, y, null);
     int oldSelectionX = selection.x;
     int oldSelectionY = selection.y;
     selection.x = offset;
     selection.y = -1;
     if (oldSelectionX != -1 && oldSelectionY != -1) {
       if (oldSelectionX > oldSelectionY) {
         int temp = oldSelectionX;
         oldSelectionX = oldSelectionY;
         oldSelectionY = temp;
       }
       Rectangle rect = layout.getBounds(oldSelectionX, oldSelectionY);
       redraw(rect.x, rect.y, rect.width, rect.height, false);
     }
     for (int j = 0; j < offsets.length; j++) {
       Rectangle[] rects = getRectangles(j);
       for (int i = 0; i < rects.length; i++) {
         Rectangle rect = rects[i];
         if (rect.contains(x, y)) {
           if (j != focusIndex) {
             redraw();
           }
           focusIndex = mouseDownIndex = j;
           return result;
         }
       }
     }
   }
   return result;
 }
예제 #23
0
 @Override
 long /*int*/ gtk_motion_notify_event(long /*int*/ widget, long /*int*/ event) {
   long /*int*/ result = super.gtk_motion_notify_event(widget, event);
   if (result != 0) return result;
   GdkEventMotion gdkEvent = new GdkEventMotion();
   OS.memmove(gdkEvent, event, GdkEventMotion.sizeof);
   int x = (int) gdkEvent.x;
   int y = (int) gdkEvent.y;
   if ((style & SWT.MIRRORED) != 0) x = getClientWidth() - x;
   if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) {
     int oldSelection = selection.y;
     selection.y = layout.getOffset(x, y, null);
     if (selection.y != oldSelection) {
       int newSelection = selection.y;
       if (oldSelection > newSelection) {
         int temp = oldSelection;
         oldSelection = newSelection;
         newSelection = temp;
       }
       Rectangle rect = layout.getBounds(oldSelection, newSelection);
       redraw(rect.x, rect.y, rect.width, rect.height, false);
     }
   } else {
     for (int j = 0; j < offsets.length; j++) {
       Rectangle[] rects = getRectangles(j);
       for (int i = 0; i < rects.length; i++) {
         Rectangle rect = rects[i];
         if (rect.contains(x, y)) {
           setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
           return result;
         }
       }
     }
     setCursor(null);
   }
   return result;
 }
예제 #24
0
 @Override
 long /*int*/ gtk_button_release_event(long /*int*/ widget, long /*int*/ event) {
   long /*int*/ result = super.gtk_button_release_event(widget, event);
   if (result != 0) return result;
   if (focusIndex == -1) return result;
   GdkEventButton gdkEvent = new GdkEventButton();
   OS.memmove(gdkEvent, event, GdkEventButton.sizeof);
   if (gdkEvent.button == 1) {
     int x = (int) gdkEvent.x;
     int y = (int) gdkEvent.y;
     if ((style & SWT.MIRRORED) != 0) x = getClientWidth() - x;
     Rectangle[] rects = getRectangles(focusIndex);
     for (int i = 0; i < rects.length; i++) {
       Rectangle rect = rects[i];
       if (rect.contains(x, y)) {
         Event ev = new Event();
         ev.text = ids[focusIndex];
         sendSelectionEvent(SWT.Selection, ev, true);
         return result;
       }
     }
   }
   return result;
 }
예제 #25
0
  /** @return Returns <code>true</code> when the tooltip should be kept opened. */
  private boolean onDisplayMouseMove() {

    //		final long start = System.nanoTime();

    if (_shell == null || _shell.isDisposed() || _shell.isVisible() == false) {
      return false;
    }

    if (canCloseToolTip() == false) {

      //			System.out.println(UI.timeStampNano()
      //					+ " ["
      //					+ getClass().getSimpleName()
      //					+ "] onDisplayMouseMove::canCloseToolTip\t");
      //			// TODO remove SYSTEM.OUT.PRINTLN

      return true;
    }

    boolean isHide = false;
    boolean isKeepVisible = false;

    // get control which is hovered with the mouse after the exit, can be null
    final Control hoveredControl = _display.getCursorControl();

    //		System.out.println(UI.timeStampNano() + " onTTDisplayMouseMove - hoveredControl " +
    // hoveredControl);
    //		// TODO remove SYSTEM.OUT.PRINTLN

    if (hoveredControl == null) {

      //			System.out.println(UI.timeStampNano() + " exit 0 hide");
      //			// TODO remove SYSTEM.OUT.PRINTLN

      isHide = true;

    } else {

      /*
       * check if the hovered control is the owner control, if not, hide the tooltip
       */
      Control hoveredParent = hoveredControl;

      // move up child-parent hierarchy until shell is reached
      while (true) {

        if (hoveredParent == _shell) {

          // mouse is hovering in this tooltip

          isKeepVisible = true;

          //					System.out.println(UI.timeStampNano() + " exit 1 no hide");
          //					// TODO remove SYSTEM.OUT.PRINTLN

          break;
        }

        if (hoveredParent == _ownerControl) {

          // mouse is hovering the owner control

          if (_mouseOverBehaviour == MOUSE_OVER_BEHAVIOUR_NO_IGNORE) {

            /*
             * owner is not ignored, which means the when the mouse is hovered the
             * owner, the tooltip keeps opened, this is the default
             */

            isKeepVisible = true;
          }

          //					System.out.println(UI.timeStampNano() + " exit 2 no hide");
          //					// TODO remove SYSTEM.OUT.PRINTLN

          break;
        }

        hoveredParent = hoveredParent.getParent();

        if (hoveredParent == null) {

          // mouse has left the tooltip and the owner control

          //					System.out.println(UI.timeStampNano() + " exit 3 hide");
          //					// TODO remove SYSTEM.OUT.PRINTLN

          isHide = true;

          break;
        }
      }
    }

    /**
     * !!! this adjustment do not work on Linux because the tooltip gets hidden when the mouse tries
     * to mover over the tooltip <br>
     * <br>
     * it seems to work on windows and linux with margin 1, when set to 0 the tooltip do sometime
     * not be poped up again and the i-icons is not deaktivated<br>
     * wolfgang 2010-07-23
     */
    final Rectangle ttShellRect = _shell.getBounds();
    final int margin = 10;

    ttShellRect.x -= margin;
    ttShellRect.y -= margin;
    ttShellRect.width += 2 * margin;
    ttShellRect.height += 2 * margin;

    final Point displayCursorLocation = _display.getCursorLocation();

    final boolean isInTooltip = ttShellRect.contains(displayCursorLocation);

    if (isKeepVisible == false && isHide == false && isInTooltip == false) {
      isHide = true;
    }

    if (isInTooltip && _isShellFadingOut) {

      // don't hide when mouse is hovering hiding tooltip

      ttShow();

    } else if (isHide) {

      final Rectangle noHideArea = noHideOnMouseMove();

      if (noHideArea == null || noHideArea.contains(displayCursorLocation) == false) {

        // hide definitively

        ttHide();
      }
    }

    boolean isKeepOpened = true;

    if (isInTooltip && _isShellFadingOut) {

      // don't hide when mouse is hovering hiding tooltip

      ttShow();

    } else if (isHide) {

      final Rectangle noHideArea = noHideOnMouseMove();

      if (noHideArea == null || noHideArea.contains(displayCursorLocation) == false) {

        // hide definitively

        ttHide();

        isKeepOpened = false;
      }
    }

    //		System.out.println(UI.timeStampNano()
    //				+ " onDisplayMouseMove\t"
    //				+ ((float) (System.nanoTime() - start) / 1000000)
    //				+ " ms");
    //		// TODO remove SYSTEM.OUT.PRINTLN

    return isKeepOpened;
  }
예제 #26
0
 @Override
 int hit(Theme theme, Point position, Rectangle bounds) {
   return bounds.contains(position) ? DrawData.WIDGET_WHOLE : DrawData.WIDGET_NOWHERE;
 }
 private boolean isInUpperHalf(Rectangle rect, org.eclipse.draw2d.geometry.Point pt) {
   Rectangle tempRect = new Rectangle(rect.x, rect.y, rect.width, rect.height / 2);
   return tempRect.contains(new Point(pt.x, pt.y));
 }