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; }
@Override public double distance(Rectangle r) { if (r.contains(x1, y1) || r.contains(x2, y2)) { return 0; } else { double d1 = distance(r.x1(), r.y1(), r.x1(), r.y2()); if (d1 == 0) return 0; double d2 = distance(r.x1(), r.y2(), r.x2(), r.y2()); if (d2 == 0) return 0; double d3 = distance(r.x2(), r.y2(), r.x2(), r.y1()); double d4 = distance(r.x2(), r.y1(), r.x1(), r.y1()); return Math.min(d1, Math.min(d2, Math.min(d3, d4))); } }
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; }
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 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; }
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; }
@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; }
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; }
@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; }
@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; }
@Override int hit(Theme theme, Point position, Rectangle bounds) { return bounds.contains(position) ? DrawData.WIDGET_WHOLE : DrawData.WIDGET_NOWHERE; }
public boolean withinFireButton(float x, float y) { return fireButton.contains(x, y); }
public boolean withinRightButton(float x, float y) { return rightButton.contains(x, y); }
public boolean withinLeftButton(float x, float y) { return leftButton.contains(x, y); }