Skip to content

Commit 6bf05bf

Browse files
Thomas Singertmssngr
Thomas Singer
authored andcommitted
ToolItem: for DROP_DOWN item provide correct popup location
1 parent feb87ec commit 6bf05bf

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/ToolItem.java

+15-12
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ default boolean isOnButton(Point location) {
8686
}
8787

8888
/**
89-
* Indicates if the given location is on the arrow area of the {@link ToolItem}.
89+
* Indicates the popup location if the given location is on the arrow area of the {@link ToolItem}.
9090
*
9191
* @param location The location to check.
92-
* @return true if on the arrow are, false otherwise.
92+
* @return the popup location (bottom-left corner of the main button), if the specified location is over the arrow, null otherwise.
9393
*/
94-
default boolean isOnArrow(Point location) {
95-
return false;
94+
default Point getOnArrowLocation(Point location) {
95+
return null;
9696
}
9797
}
9898

@@ -904,15 +904,18 @@ public boolean notifyMouseDown(Point location) {
904904
MouseState newState;
905905
if (renderer.isOnButton(location)) {
906906
newState = MouseState.DOWN;
907-
} else if (renderer.isOnArrow(location)) {
908-
newState = MouseState.IDLE;
909-
Event event = new Event();
910-
event.detail = SWT.ARROW;
911-
event.setLocation(location.x, location.y);
912-
event.stateMask |= SWT.NO_FOCUS;
913-
sendEvent(SWT.Selection, event);
914907
} else {
915-
newState = MouseState.IDLE;
908+
final Point onArrowLocation = renderer.getOnArrowLocation(location);
909+
if (onArrowLocation != null) {
910+
newState = MouseState.IDLE;
911+
Event event = new Event();
912+
event.detail = SWT.ARROW;
913+
event.setLocation(onArrowLocation.x, onArrowLocation.y);
914+
event.stateMask |= SWT.NO_FOCUS;
915+
sendEvent(SWT.Selection, event);
916+
} else {
917+
newState = MouseState.IDLE;
918+
}
916919
}
917920

918921
return updateMouseState(newState);

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/toolbar/ToolItemDropDownRenderer.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ public boolean isOnButton(Point location) {
8484
}
8585

8686
@Override
87-
public boolean isOnArrow(Point location) {
88-
return arrow.contains(location);
87+
public Point getOnArrowLocation(Point location) {
88+
if (!arrow.contains(location)) {
89+
return null;
90+
}
91+
return new Point(button.x, button.y + button.height);
8992
}
9093
}

0 commit comments

Comments
 (0)