/** * Returns a rectangle describing the receiver's size and location relative to its parent. * * @return the receiver's bounding rectangle * @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 1.3 */ public Rectangle getBounds() { checkWidget(); Rectangle result = new Rectangle(0, 0, 0, 0); int index = parent.indexOf(this); if (index != -1) { int selectionIndex = parent.getSelectionIndex(); boolean selected = index == selectionIndex; Rectangle padding = parent.getItemPadding(selected); String text = getText(); if (text != null) { Point extent = Graphics.stringExtent(parent.getFont(), text); result.width = extent.x; result.height = extent.y; } Image image = getImage(); if (image != null) { Rectangle imageSize = image.getBounds(); result.width += imageSize.width + IMAGE_TEXT_SPACING; result.height = Math.max(result.height, imageSize.height); } result.width += 2 * ITEM_BORDER + padding.width; result.height += ITEM_BORDER + padding.height; if (selected) { result.height += SELECTED_ITEM_BORDER; } if (selectionIndex != -1) { if (index + 1 == selectionIndex || index - 1 == selectionIndex) { result.width -= ITEM_BORDER; } } if (isBarTop()) { if (index != selectionIndex) { result.y += SELECTED_ITEM_BORDER; } } else { result.y = parent.getBounds().height - 2 * parent.getBorderWidth() - result.height; if (index != selectionIndex) { result.y -= SELECTED_ITEM_BORDER; } } if (index > 0) { TabItem leftItem = parent.getItem(index - 1); Rectangle leftItemBounds = leftItem.getBounds(); result.x = leftItemBounds.x + leftItemBounds.width + TABS_SPACING; if (index == selectionIndex || index - 1 == selectionIndex) { result.x -= TABS_SPACING; } } } return result; }
/** * 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; }