org.gnome.gtk.GestureClick Maven / Gradle / Ivy
// This file was automatically generated by Java-GI. Do not edit this file
// directly! Visit for more information.
//
// The API documentation in this file was derived from GObject-Introspection
// metadata and may include text or comments from the original C sources.
//
// Copyright (c), upstream authors as identified in the GObject-Introspection
// metadata.
//
// This generated file is distributed under the same license as the original
// GObject-Introspection data, unless otherwise specified. Users of this file
// are responsible for complying with any licenses or terms required by the
// original authors.
//
// THIS FILE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
//
package org.gnome.gtk;
import io.github.jwharm.javagi.base.FunctionPointer;
import io.github.jwharm.javagi.gobject.InstanceCache;
import io.github.jwharm.javagi.gobject.SignalConnection;
import io.github.jwharm.javagi.gobject.types.Signals;
import io.github.jwharm.javagi.interop.Arenas;
import io.github.jwharm.javagi.interop.Interop;
import java.lang.FunctionalInterface;
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import javax.annotation.processing.Generated;
import org.gnome.gdk.EventSequence;
import org.gnome.glib.Type;
import org.gnome.gobject.GObject;
import org.gnome.gobject.TypeClass;
import org.gnome.gobject.Value;
import org.jetbrains.annotations.Nullable;
/**
* {@code GtkGestureClick} is a {@code GtkGesture} implementation for clicks.
*
* It is able to recognize multiple clicks on a nearby zone, which
* can be listened for through the {@code Gtk.GestureClick::pressed}
* signal. Whenever time or distance between clicks exceed the GTK
* defaults, {@code Gtk.GestureClick::stopped} is emitted, and the
* click counter is reset.
*/
@Generated("io.github.jwharm.JavaGI")
public class GestureClick extends GestureSingle {
static {
Gtk.javagi$ensureInitialized();
}
/**
* Create a GestureClick proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public GestureClick(MemorySegment address) {
super(Interop.reinterpret(address, getMemoryLayout().byteSize()));
}
/**
* Returns a newly created {@code GtkGesture} that recognizes
* single and multiple presses.
*/
public GestureClick() {
this(constructNew());
InstanceCache.put(handle(), this);
}
/**
* Get the GType of the GestureClick class
*
* @return the GType
*/
public static Type getType() {
return Interop.getType("gtk_gesture_click_get_type");
}
/**
* Returns this instance as if it were its parent type. This is mostly
* synonymous to the Java {@code super} keyword, but will set the native
* typeclass function pointers to the parent type. When overriding a native
* virtual method in Java, "chaining up" with {@code super.methodName()}
* doesn't work, because it invokes the overridden function pointer again.
* To chain up, call {@code asParent().methodName()}. This will call the
* native function pointer of this virtual method in the typeclass of the
* parent type.
*/
protected GestureClick asParent() {
GestureClick _parent = new GestureClick(handle());
_parent.callParent(true);
return _parent;
}
private static MemorySegment constructNew() {
MemorySegment _result;
try {
_result = (MemorySegment) MethodHandles.gtk_gesture_click_new.invokeExact();
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
/**
* Emitted whenever a button or touch press happens.
*
* @param handler the signal handler
* @return a signal handler ID to keep track of the signal connection
* @see PressedCallback#run
*/
public SignalConnection onPressed(PressedCallback handler) {
try (Arena _arena = Arena.ofConfined()) {
try {
var _name = Interop.allocateNativeString("pressed", _arena);
var _callbackArena = Arena.ofShared();
var _result = (int) (long) Signals.g_signal_connect_data.invokeExact(handle(),
_name, handler.toCallback(_callbackArena),
Arenas.cacheArena(_callbackArena), Arenas.CLOSE_CB_SYM, 0);
return new SignalConnection<>(handle(), _result);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
}
/**
* Emits the "pressed" signal. See {@link #onPressed}.
*/
public void emitPressed(int nPress, double x, double y) {
try (Arena _arena = Arena.ofConfined()) {
MemorySegment _name = Interop.allocateNativeString("pressed", _arena);
Object[] _args = new Object[] {nPress, x, y};
Signals.g_signal_emit_by_name.invokeExact(handle(), _name, _args);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Emitted when a button or touch is released.
*
* {@code nPress} will report the number of press that is paired to
* this event, note that {@code Gtk.GestureClick::stopped} may
* have been emitted between the press and its release, {@code nPress}
* will only start over at the next press.
*
* @param handler the signal handler
* @return a signal handler ID to keep track of the signal connection
* @see ReleasedCallback#run
*/
public SignalConnection onReleased(ReleasedCallback handler) {
try (Arena _arena = Arena.ofConfined()) {
try {
var _name = Interop.allocateNativeString("released", _arena);
var _callbackArena = Arena.ofShared();
var _result = (int) (long) Signals.g_signal_connect_data.invokeExact(handle(),
_name, handler.toCallback(_callbackArena),
Arenas.cacheArena(_callbackArena), Arenas.CLOSE_CB_SYM, 0);
return new SignalConnection<>(handle(), _result);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
}
/**
* Emits the "released" signal. See {@link #onReleased}.
*/
public void emitReleased(int nPress, double x, double y) {
try (Arena _arena = Arena.ofConfined()) {
MemorySegment _name = Interop.allocateNativeString("released", _arena);
Object[] _args = new Object[] {nPress, x, y};
Signals.g_signal_emit_by_name.invokeExact(handle(), _name, _args);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Emitted whenever any time/distance threshold has been exceeded.
*
* @param handler the signal handler
* @return a signal handler ID to keep track of the signal connection
* @see StoppedCallback#run
*/
public SignalConnection onStopped(StoppedCallback handler) {
try (Arena _arena = Arena.ofConfined()) {
try {
var _name = Interop.allocateNativeString("stopped", _arena);
var _callbackArena = Arena.ofShared();
var _result = (int) (long) Signals.g_signal_connect_data.invokeExact(handle(),
_name, handler.toCallback(_callbackArena),
Arenas.cacheArena(_callbackArena), Arenas.CLOSE_CB_SYM, 0);
return new SignalConnection<>(handle(), _result);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
}
/**
* Emits the "stopped" signal. See {@link #onStopped}.
*/
public void emitStopped() {
try (Arena _arena = Arena.ofConfined()) {
MemorySegment _name = Interop.allocateNativeString("stopped", _arena);
Object[] _args = new Object[0];
Signals.g_signal_emit_by_name.invokeExact(handle(), _name, _args);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Emitted whenever the gesture receives a release
* event that had no previous corresponding press.
*
* Due to implicit grabs, this can only happen on situations
* where input is grabbed elsewhere mid-press or the pressed
* widget voluntarily relinquishes its implicit grab.
*
* @param handler the signal handler
* @return a signal handler ID to keep track of the signal connection
* @see UnpairedReleaseCallback#run
*/
public SignalConnection onUnpairedRelease(
UnpairedReleaseCallback handler) {
try (Arena _arena = Arena.ofConfined()) {
try {
var _name = Interop.allocateNativeString("unpaired-release", _arena);
var _callbackArena = Arena.ofShared();
var _result = (int) (long) Signals.g_signal_connect_data.invokeExact(handle(),
_name, handler.toCallback(_callbackArena),
Arenas.cacheArena(_callbackArena), Arenas.CLOSE_CB_SYM, 0);
return new SignalConnection<>(handle(), _result);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
}
/**
* Emits the "unpaired-release" signal. See {@link #onUnpairedRelease}.
*/
public void emitUnpairedRelease(double x, double y, int button,
@Nullable EventSequence sequence) {
try (Arena _arena = Arena.ofConfined()) {
MemorySegment _name = Interop.allocateNativeString("unpaired-release", _arena);
Object[] _args = new Object[] {x, y, button,
(MemorySegment) (sequence == null ? MemorySegment.NULL : sequence.handle())};
Signals.g_signal_emit_by_name.invokeExact(handle(), _name, _args);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* A {@link Builder} object constructs a {@code GestureClick}
* with the specified properties.
* Use the various {@code set...()} methods to set properties,
* and finish construction with {@link Builder#build()}.
*/
public static Builder extends Builder> builder() {
return new Builder<>();
}
/**
* Functional interface declaration of the {@code PressedCallback} callback.
*
* @see PressedCallback#run
*/
@FunctionalInterface
public interface PressedCallback extends FunctionPointer {
/**
* Emitted whenever a button or touch press happens.
*/
void run(int nPress, double x, double y);
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default void upcall(MemorySegment sourceGestureClick, int nPress, double x, double y) {
run(nPress, x, y);
}
/**
* Creates a native function pointer to the {@link #upcall} method.
*
* @return the native function pointer
*/
default MemorySegment toCallback(Arena arena) {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), PressedCallback.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}
/**
* Functional interface declaration of the {@code ReleasedCallback} callback.
*
* @see ReleasedCallback#run
*/
@FunctionalInterface
public interface ReleasedCallback extends FunctionPointer {
/**
* Emitted when a button or touch is released.
*
* {@code nPress} will report the number of press that is paired to
* this event, note that {@code Gtk.GestureClick::stopped} may
* have been emitted between the press and its release, {@code nPress}
* will only start over at the next press.
*/
void run(int nPress, double x, double y);
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default void upcall(MemorySegment sourceGestureClick, int nPress, double x, double y) {
run(nPress, x, y);
}
/**
* Creates a native function pointer to the {@link #upcall} method.
*
* @return the native function pointer
*/
default MemorySegment toCallback(Arena arena) {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), ReleasedCallback.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}
/**
* Functional interface declaration of the {@code StoppedCallback} callback.
*
* @see StoppedCallback#run
*/
@FunctionalInterface
public interface StoppedCallback extends FunctionPointer {
/**
* Emitted whenever any time/distance threshold has been exceeded.
*/
void run();
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default void upcall(MemorySegment sourceGestureClick) {
run();
}
/**
* Creates a native function pointer to the {@link #upcall} method.
*
* @return the native function pointer
*/
default MemorySegment toCallback(Arena arena) {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), StoppedCallback.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}
/**
* Functional interface declaration of the {@code UnpairedReleaseCallback} callback.
*
* @see UnpairedReleaseCallback#run
*/
@FunctionalInterface
public interface UnpairedReleaseCallback extends FunctionPointer {
/**
* Emitted whenever the gesture receives a release
* event that had no previous corresponding press.
*
* Due to implicit grabs, this can only happen on situations
* where input is grabbed elsewhere mid-press or the pressed
* widget voluntarily relinquishes its implicit grab.
*/
void run(double x, double y, int button, @Nullable EventSequence sequence);
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default void upcall(MemorySegment sourceGestureClick, double x, double y, int button,
MemorySegment sequence) {
run(x, y, button, MemorySegment.NULL.equals(sequence) ? null : new EventSequence(sequence));
}
/**
* Creates a native function pointer to the {@link #upcall} method.
*
* @return the native function pointer
*/
default MemorySegment toCallback(Arena arena) {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_INT,
ValueLayout.ADDRESS);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), UnpairedReleaseCallback.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}
public static class GestureClickClass extends TypeClass {
/**
* Create a GestureClickClass proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public GestureClickClass(MemorySegment address) {
super(address);
}
}
/**
* Inner class implementing a builder pattern to construct a GObject with
* properties.
*
* @param the type of the Builder that is returned
*/
public static class Builder> extends GestureSingle.Builder {
/**
* Default constructor for a {@code Builder} object.
*/
protected Builder() {
}
/**
* Finish building the {@code GestureClick} object. This will call
* {@link GObject#withProperties} to create a new GObject instance,
* which is then cast to {@code GestureClick}.
*
* @return a new instance of {@code GestureClick} with the properties
* that were set in the Builder object.
*/
public GestureClick build() {
try {
var _instance = (GestureClick) GObject.withProperties(GestureClick.getType(), getNames(), getValues());
connectSignals(_instance.handle());
return _instance;
} finally {
for (Value _value : getValues()) _value.unset();
getArena().close();
}
}
/**
* Emitted whenever a button or touch press happens.
*
* @param handler the signal handler
* @return the {@code Builder} instance is returned, to allow method chaining
* @see PressedCallback#run
*/
public B onPressed(PressedCallback handler) {
connect("pressed", handler);
return (B) this;
}
/**
* Emitted when a button or touch is released.
*
* {@code nPress} will report the number of press that is paired to
* this event, note that {@code Gtk.GestureClick::stopped} may
* have been emitted between the press and its release, {@code nPress}
* will only start over at the next press.
*
* @param handler the signal handler
* @return the {@code Builder} instance is returned, to allow method chaining
* @see ReleasedCallback#run
*/
public B onReleased(ReleasedCallback handler) {
connect("released", handler);
return (B) this;
}
/**
* Emitted whenever any time/distance threshold has been exceeded.
*
* @param handler the signal handler
* @return the {@code Builder} instance is returned, to allow method chaining
* @see StoppedCallback#run
*/
public B onStopped(StoppedCallback handler) {
connect("stopped", handler);
return (B) this;
}
/**
* Emitted whenever the gesture receives a release
* event that had no previous corresponding press.
*
* Due to implicit grabs, this can only happen on situations
* where input is grabbed elsewhere mid-press or the pressed
* widget voluntarily relinquishes its implicit grab.
*
* @param handler the signal handler
* @return the {@code Builder} instance is returned, to allow method chaining
* @see UnpairedReleaseCallback#run
*/
public B onUnpairedRelease(UnpairedReleaseCallback handler) {
connect("unpaired-release", handler);
return (B) this;
}
}
private static final class MethodHandles {
static final MethodHandle gtk_gesture_click_new = Interop.downcallHandle(
"gtk_gesture_click_new", FunctionDescriptor.of(ValueLayout.ADDRESS), false);
}
}