Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the default selection to the slider #576

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
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 @@ -51,6 +51,8 @@ public class NebulaSlider extends Canvas {

private IntFunction<String> format;

private int movingValue;

/**
* Constructs a new instance of this class given its parent and a style value
* describing its behavior and appearance.
Expand Down Expand Up @@ -229,12 +231,16 @@ private void addMouseListeners() {
return;
}
moving = true;
movingValue = value;
mouseDeltaX = xPosition - e.x;
});

addListener(SWT.MouseUp, e -> {
moving = false;
mouseDeltaX = 0;
if(movingValue != value) {
SelectionListenerUtil.fireDefaultSelectionListeners(this, e);
}
redraw();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,23 @@ public static void removeSelectionListener(final Control control, final Selectio
* @return true if the selection could be changed, false otherwise
*/
public static boolean fireSelectionListeners(final Control control, final Event sourceEvent) {
for (final Listener listener : control.getListeners(SWT.Selection)) {
return fireSelectionListenersEvent(control, sourceEvent, SWT.Selection);
}

/**
* Fire the default selection listeners of a given control
*
* @param control the control that fires the event
* @param sourceEvent mouse event
* @return true if the selection could be changed, false otherwise
*/
public static boolean fireDefaultSelectionListeners(final Control control, final Event sourceEvent) {
return fireSelectionListenersEvent(control, sourceEvent, SWT.DefaultSelection);
}

private static boolean fireSelectionListenersEvent(final Control control, final Event sourceEvent, int type) {
Listener[] listeners = control.getListeners(SWT.Selection);
for(final Listener listener : listeners) {
final Event event = new Event();

event.button = sourceEvent==null?1:sourceEvent.button;
Expand All @@ -76,7 +92,7 @@ public static boolean fireSelectionListeners(final Control control, final Event
event.time = sourceEvent == null ? 0 : sourceEvent.time;
event.x = sourceEvent == null ? 0 : sourceEvent.x;
event.y = sourceEvent == null ? 0 : sourceEvent.y;
event.type = SWT.Selection;
event.type = type;

listener.handleEvent(event);
if (!event.doit) {
Expand Down
Loading