Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,13 @@ void onMouseDoubleClick(Event event) {
notifyListeners(SWT.DefaultSelection, e);
}
}
/**
* Returns whether the given point (px, py) is contained within the bounds
* of the given CTabItem, without allocating a Rectangle object.
*/
static boolean containsPoint(CTabItem item, int px, int py) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used elsewhere that you've made it package private and not private?

return px >= item.x && py >= item.y && px < item.x + item.width && py < item.y + item.height;
}
void onMouse(Event event) {
if( isDisposed() ) {
return;
Expand Down Expand Up @@ -1874,15 +1881,14 @@ public void run() {
CTabItem item = null;
if (single) {
if (selectedIndex != -1) {
Rectangle bounds = items[selectedIndex].getBounds();
if (bounds.contains(x, y)){
item = items[selectedIndex];
CTabItem selectedItem = items[selectedIndex];
if (containsPoint(selectedItem, x, y)){
item = selectedItem;
}
}
} else {
for (CTabItem tabItem : items) {
Rectangle bounds = tabItem.getBounds();
if (bounds.contains(x, y)){
if (containsPoint(tabItem, x, y)){
item = tabItem;
}
}
Expand Down Expand Up @@ -1917,7 +1923,7 @@ public void run() {
for (int i=0; i<items.length; i++) {
CTabItem item = items[i];
close = false;
if (item.getBounds().contains(x, y)) {
if (containsPoint(item, x, y)) {
close = true;
if (item.closeRect.contains(x, y)) {
if (item.closeImageState != SWT.SELECTED && item.closeImageState != SWT.HOT) {
Expand Down Expand Up @@ -1955,15 +1961,14 @@ public void run() {
CTabItem item = null;
if (single) {
if (selectedIndex != -1) {
Rectangle bounds = items[selectedIndex].getBounds();
if (bounds.contains(x, y)){
item = items[selectedIndex];
CTabItem selectedItem = items[selectedIndex];
if (containsPoint(selectedItem, x, y)){
item = selectedItem;
}
}
} else {
for (CTabItem tabItem : items) {
Rectangle bounds = tabItem.getBounds();
if (bounds.contains(x, y)){
if (containsPoint(tabItem, x, y)){
item = tabItem;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, should there maybe be a break after this? I assume only one item can contain the point...

}
}
Expand Down
Loading