org.gnome.gtk.EntryBuffer Maven / Gradle / Ivy
Show all versions of gtk Show documentation
// 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.Constants;
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.Overrides;
import io.github.jwharm.javagi.gobject.types.Signals;
import io.github.jwharm.javagi.gobject.types.Types;
import io.github.jwharm.javagi.interop.Arenas;
import io.github.jwharm.javagi.interop.Interop;
import java.lang.FunctionalInterface;
import java.lang.NullPointerException;
import java.lang.String;
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.annotation.processing.Generated;
import org.gnome.glib.GLib;
import org.gnome.glib.LogLevelFlags;
import org.gnome.glib.Type;
import org.gnome.gobject.GObject;
import org.gnome.gobject.Value;
import org.jetbrains.annotations.Nullable;
/**
* A {@code GtkEntryBuffer} hold the text displayed in a {@code GtkText} widget.
*
* A single {@code GtkEntryBuffer} object can be shared by multiple widgets
* which will then share the same text content, but not the cursor
* position, visibility attributes, icon etc.
*
* {@code GtkEntryBuffer} may be derived from. Such a derived class might allow
* text to be stored in an alternate location, such as non-pageable memory,
* useful in the case of important passwords. Or a derived class could
* integrate with an application’s concept of undo/redo.
*/
@Generated("io.github.jwharm.JavaGI")
public class EntryBuffer extends GObject {
static {
Gtk.javagi$ensureInitialized();
}
/**
* Create a EntryBuffer proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public EntryBuffer(MemorySegment address) {
super(Interop.reinterpret(address, getMemoryLayout().byteSize()));
}
/**
* Create a new {@code GtkEntryBuffer} object.
*
* Optionally, specify initial text to set in the buffer.
*
* @param initialChars initial buffer text
* @param nInitialChars number of characters in {@code initialChars}, or -1
*/
public EntryBuffer(@Nullable String initialChars, int nInitialChars) {
this(constructNew(initialChars, nInitialChars));
InstanceCache.put(handle(), this);
}
/**
* Get the GType of the EntryBuffer class
*
* @return the GType
*/
public static Type getType() {
return Interop.getType("gtk_entry_buffer_get_type");
}
/**
* The memory layout of the native struct.
* @return the memory layout
*/
public static MemoryLayout getMemoryLayout() {
return MemoryLayout.structLayout(
GObject.getMemoryLayout().withName("parent_instance")
).withName("GtkEntryBuffer");
}
/**
* 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 EntryBuffer asParent() {
EntryBuffer _parent = new EntryBuffer(handle());
_parent.callParent(true);
return _parent;
}
private static MemorySegment constructNew(@Nullable String initialChars, int nInitialChars) {
try (var _arena = Arena.ofConfined()) {
MemorySegment _result;
try {
_result = (MemorySegment) MethodHandles.gtk_entry_buffer_new.invokeExact(
(MemorySegment) (initialChars == null ? MemorySegment.NULL : Interop.allocateNativeString(initialChars, _arena)),
nInitialChars);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
}
/**
* Deletes a sequence of characters from the buffer.
*
* {@code nChars} characters are deleted starting at {@code position}.
* If {@code nChars} is negative, then all characters until the
* end of the text are deleted.
*
* If {@code position} or {@code nChars} are out of bounds, then they
* are coerced to sane values.
*
* Note that the positions are specified in characters,
* not bytes.
*
* @param position position at which to delete text
* @param nChars number of characters to delete
* @return The number of characters deleted.
*/
public int deleteText(int position, int nChars) {
int _result;
try {
if (callParent()) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
MemorySegment _func = Overrides.lookupVirtualMethodParent(handle(),
EntryBufferClass.getMemoryLayout(), "delete_text");
if (_func.equals(MemorySegment.NULL)) throw new NullPointerException();
_result = (int) Interop.downcallHandle(_func, _fdesc).invokeExact(handle(),
position, nChars);
} else {
_result = (int) MethodHandles.gtk_entry_buffer_delete_text.invokeExact(handle(),
position, nChars);
}
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
/**
* Used when subclassing {@code GtkEntryBuffer}.
*
* @param position position at which text was deleted
* @param nChars number of characters deleted
*/
public void emitDeletedText(int position, int nChars) {
try {
MethodHandles.gtk_entry_buffer_emit_deleted_text.invokeExact(handle(), position,
nChars);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Used when subclassing {@code GtkEntryBuffer}.
*
* @param position position at which text was inserted
* @param chars text that was inserted
* @param nChars number of characters inserted
*/
public void emitInsertedText(int position, String chars, int nChars) {
try (var _arena = Arena.ofConfined()) {
try {
MethodHandles.gtk_entry_buffer_emit_inserted_text.invokeExact(handle(), position,
(MemorySegment) (chars == null ? MemorySegment.NULL : Interop.allocateNativeString(chars, _arena)),
nChars);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
}
/**
* Retrieves the length in bytes of the buffer.
*
* See {@link EntryBuffer#getLength}.
*
* @return The byte length of the buffer.
*/
public long getBytes() {
long _result;
try {
_result = (long) MethodHandles.gtk_entry_buffer_get_bytes.invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
/**
* Retrieves the length in characters of the buffer.
*
* @return The number of characters in the buffer.
*/
public int getLength() {
int _result;
try {
if (callParent()) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS);
MemorySegment _func = Overrides.lookupVirtualMethodParent(handle(),
EntryBufferClass.getMemoryLayout(), "get_length");
if (_func.equals(MemorySegment.NULL)) throw new NullPointerException();
_result = (int) Interop.downcallHandle(_func, _fdesc).invokeExact(handle());
} else {
_result = (int) MethodHandles.gtk_entry_buffer_get_length.invokeExact(handle());
}
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
/**
* Retrieves the maximum allowed length of the text in this EntryBuffer.
*
* @return the maximum allowed number of characters
* in {@code GtkEntryBuffer}, or 0 if there is no maximum.
*/
public int getMaxLength() {
int _result;
try {
_result = (int) MethodHandles.gtk_entry_buffer_get_max_length.invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
/**
* Retrieves the contents of the buffer.
*
* The memory pointer returned by this call will not change
* unless this object emits a signal, or is finalized.
*
* @return a pointer to the contents of the widget as a
* string. This string points to internally allocated storage
* in the buffer and must not be freed, modified or stored.
*/
public String getText() {
MemorySegment _result;
try {
_result = (MemorySegment) MethodHandles.gtk_entry_buffer_get_text.invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return Interop.getStringFrom(_result, false);
}
/**
* Inserts {@code nChars} characters of {@code chars} into the contents of the
* buffer, at position {@code position}.
*
* If {@code nChars} is negative, then characters from chars will be inserted
* until a null-terminator is found. If {@code position} or {@code nChars} are out of
* bounds, or the maximum buffer text length is exceeded, then they are
* coerced to sane values.
*
* Note that the position and length are in characters, not in bytes.
*
* @param position the position at which to insert text.
* @param chars the text to insert into the buffer.
* @param nChars the length of the text in characters, or -1
* @return The number of characters actually inserted.
*/
public int insertText(int position, String chars, int nChars) {
try (var _arena = Arena.ofConfined()) {
int _result;
try {
if (callParent()) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS,
ValueLayout.JAVA_INT);
MemorySegment _func = Overrides.lookupVirtualMethodParent(handle(),
EntryBufferClass.getMemoryLayout(), "insert_text");
if (_func.equals(MemorySegment.NULL)) throw new NullPointerException();
_result = (int) Interop.downcallHandle(_func, _fdesc).invokeExact(handle(),
position,
(MemorySegment) (chars == null ? MemorySegment.NULL : Interop.allocateNativeString(chars, _arena)),
nChars);
} else {
_result = (int) MethodHandles.gtk_entry_buffer_insert_text.invokeExact(
handle(), position,
(MemorySegment) (chars == null ? MemorySegment.NULL : Interop.allocateNativeString(chars, _arena)),
nChars);
}
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
}
/**
* Sets the maximum allowed length of the contents of the buffer.
*
* If the current contents are longer than the given length, then
* they will be truncated to fit.
*
* @param maxLength the maximum length of the entry buffer, or 0 for no maximum.
* (other than the maximum length of entries.) The value passed in will
* be clamped to the range 0-65536.
*/
public void setMaxLength(int maxLength) {
try {
MethodHandles.gtk_entry_buffer_set_max_length.invokeExact(handle(), maxLength);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Sets the text in the buffer.
*
* This is roughly equivalent to calling
* {@link EntryBuffer#deleteText} and
* {@link EntryBuffer#insertText}.
*
* Note that {@code nChars} is in characters, not in bytes.
*
* @param chars the new text
* @param nChars the number of characters in {@code text}, or -1
*/
public void setText(String chars, int nChars) {
try (var _arena = Arena.ofConfined()) {
try {
MethodHandles.gtk_entry_buffer_set_text.invokeExact(handle(),
(MemorySegment) (chars == null ? MemorySegment.NULL : Interop.allocateNativeString(chars, _arena)),
nChars);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
}
protected void deletedText(int position, int nChars) {
try {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
MemorySegment _func = Overrides.lookupVirtualMethodParent(handle(),
EntryBufferClass.getMemoryLayout(), "deleted_text");
if (_func.equals(MemorySegment.NULL)) throw new NullPointerException();
Interop.downcallHandle(_func, _fdesc).invokeExact(handle(), position, nChars);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
protected String getText(MemorySegment nBytes) {
MemorySegment _result;
try {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS,
ValueLayout.ADDRESS, ValueLayout.ADDRESS);
MemorySegment _func = Overrides.lookupVirtualMethodParent(handle(),
EntryBufferClass.getMemoryLayout(), "get_text");
if (_func.equals(MemorySegment.NULL)) throw new NullPointerException();
_result = (MemorySegment) Interop.downcallHandle(_func, _fdesc).invokeExact(handle(),
(MemorySegment) (nBytes == null ? MemorySegment.NULL : nBytes));
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return Interop.getStringFrom(_result, false);
}
protected void insertedText(int position, String chars, int nChars) {
try (var _arena = Arena.ofConfined()) {
try {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
MemorySegment _func = Overrides.lookupVirtualMethodParent(handle(),
EntryBufferClass.getMemoryLayout(), "inserted_text");
if (_func.equals(MemorySegment.NULL)) throw new NullPointerException();
Interop.downcallHandle(_func, _fdesc).invokeExact(handle(), position,
(MemorySegment) (chars == null ? MemorySegment.NULL : Interop.allocateNativeString(chars, _arena)),
nChars);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
}
/**
* The text is altered in the default handler for this signal.
*
* If you want access to the text after the text has been modified,
* use {@link org.gnome.gobject.ConnectFlags#AFTER}.
*
* @param handler the signal handler
* @return a signal handler ID to keep track of the signal connection
* @see DeletedTextCallback#run
*/
public SignalConnection onDeletedText(DeletedTextCallback handler) {
try (Arena _arena = Arena.ofConfined()) {
try {
var _name = Interop.allocateNativeString("deleted-text", _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);
}
}
}
/**
* This signal is emitted after text is inserted into the buffer.
*
* @param handler the signal handler
* @return a signal handler ID to keep track of the signal connection
* @see InsertedTextCallback#run
*/
public SignalConnection onInsertedText(InsertedTextCallback handler) {
try (Arena _arena = Arena.ofConfined()) {
try {
var _name = Interop.allocateNativeString("inserted-text", _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);
}
}
}
/**
* A {@link Builder} object constructs a {@code EntryBuffer}
* 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 DeletedTextCallback} callback.
*
* @see DeletedTextCallback#run
*/
@FunctionalInterface
public interface DeletedTextCallback extends FunctionPointer {
/**
* The text is altered in the default handler for this signal.
*
* If you want access to the text after the text has been modified,
* use {@link org.gnome.gobject.ConnectFlags#AFTER}.
*/
void run(int position, int nChars);
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default void upcall(MemorySegment sourceEntryBuffer, int position, int nChars) {
run(position, nChars);
}
/**
* 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_INT);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), DeletedTextCallback.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}
/**
* Functional interface declaration of the {@code InsertedTextCallback} callback.
*
* @see InsertedTextCallback#run
*/
@FunctionalInterface
public interface InsertedTextCallback extends FunctionPointer {
/**
* This signal is emitted after text is inserted into the buffer.
*/
void run(int position, String chars, int nChars);
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default void upcall(MemorySegment sourceEntryBuffer, int position, MemorySegment chars,
int nChars) {
Arena _arena = Arena.ofAuto();
run(position, Interop.getStringFrom(chars, false), nChars);
}
/**
* 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.ADDRESS, ValueLayout.JAVA_INT);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), InsertedTextCallback.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}
public static class EntryBufferClass extends GObject.ObjectClass {
private Method _insertedTextMethod;
private Method _deletedTextMethod;
private Method _getTextMethod;
private Method _getLengthMethod;
private Method _insertTextMethod;
private Method _deleteTextMethod;
/**
* Create a EntryBufferClass proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public EntryBufferClass(MemorySegment address) {
super(Interop.reinterpret(address, getMemoryLayout().byteSize()));
}
/**
* Allocate a new EntryBufferClass.
*
* @param arena to control the memory allocation scope
*/
public EntryBufferClass(Arena arena) {
super(arena.allocate(getMemoryLayout()));
}
/**
* Allocate a new EntryBufferClass.
* The memory is allocated with {@link Arena#ofAuto}.
*/
public EntryBufferClass() {
super(Arena.ofAuto().allocate(getMemoryLayout()));
}
/**
* The memory layout of the native struct.
* @return the memory layout
*/
public static MemoryLayout getMemoryLayout() {
return MemoryLayout.structLayout(
GObject.ObjectClass.getMemoryLayout().withName("parent_class"),
ValueLayout.ADDRESS.withName("inserted_text"),
ValueLayout.ADDRESS.withName("deleted_text"),
ValueLayout.ADDRESS.withName("get_text"),
ValueLayout.ADDRESS.withName("get_length"),
ValueLayout.ADDRESS.withName("insert_text"),
ValueLayout.ADDRESS.withName("delete_text"),
ValueLayout.ADDRESS.withName("_gtk_reserved1"),
ValueLayout.ADDRESS.withName("_gtk_reserved2"),
ValueLayout.ADDRESS.withName("_gtk_reserved3"),
ValueLayout.ADDRESS.withName("_gtk_reserved4"),
ValueLayout.ADDRESS.withName("_gtk_reserved5"),
ValueLayout.ADDRESS.withName("_gtk_reserved6"),
ValueLayout.ADDRESS.withName("_gtk_reserved7"),
ValueLayout.ADDRESS.withName("_gtk_reserved8")
).withName("GtkEntryBufferClass");
}
/**
* Override virtual method {@code inserted_text}.
*
* @param method the method to invoke
*/
public void overrideInsertedText(Arena arena, Method method) {
this._insertedTextMethod = method;
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), EntryBufferClass.class, "insertedTextUpcall", _fdesc);
MemorySegment _address = Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("inserted_text"))
.set(handle(), 0, (method == null ? MemorySegment.NULL : _address));
}
private void insertedTextUpcall(MemorySegment buffer, int position, MemorySegment chars,
int nChars) {
try {
Arena _arena = Arena.ofAuto();
this._insertedTextMethod.invoke((EntryBuffer) InstanceCache.getForType(buffer, EntryBuffer::new, false), position, Interop.getStringFrom(chars, false), nChars);
} catch (InvocationTargetException ite) {
GLib.log(Constants.LOG_DOMAIN, LogLevelFlags.LEVEL_WARNING, ite.getCause().toString() + " in " + _insertedTextMethod);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Override virtual method {@code deleted_text}.
*
* @param method the method to invoke
*/
public void overrideDeletedText(Arena arena, Method method) {
this._deletedTextMethod = method;
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), EntryBufferClass.class, "deletedTextUpcall", _fdesc);
MemorySegment _address = Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("deleted_text"))
.set(handle(), 0, (method == null ? MemorySegment.NULL : _address));
}
private void deletedTextUpcall(MemorySegment buffer, int position, int nChars) {
try {
Arena _arena = Arena.ofAuto();
this._deletedTextMethod.invoke((EntryBuffer) InstanceCache.getForType(buffer, EntryBuffer::new, false), position, nChars);
} catch (InvocationTargetException ite) {
GLib.log(Constants.LOG_DOMAIN, LogLevelFlags.LEVEL_WARNING, ite.getCause().toString() + " in " + _deletedTextMethod);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Override virtual method {@code get_text}.
*
* @param method the method to invoke
*/
public void overrideGetText(Arena arena, Method method) {
this._getTextMethod = method;
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS,
ValueLayout.ADDRESS, ValueLayout.ADDRESS);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), EntryBufferClass.class, "getTextUpcall", _fdesc);
MemorySegment _address = Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("get_text"))
.set(handle(), 0, (method == null ? MemorySegment.NULL : _address));
}
private MemorySegment getTextUpcall(MemorySegment buffer, MemorySegment nBytes) {
try {
Arena _arena = Arena.ofAuto();
var _result = (String) this._getTextMethod.invoke((EntryBuffer) InstanceCache.getForType(buffer, EntryBuffer::new, false), nBytes);
if (_result == null) return MemorySegment.NULL;
return Interop.allocateNativeString(_result, _arena);
} catch (InvocationTargetException ite) {
GLib.log(Constants.LOG_DOMAIN, LogLevelFlags.LEVEL_WARNING, ite.getCause().toString() + " in " + _getTextMethod);
return MemorySegment.NULL;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Override virtual method {@code get_length}.
*
* @param method the method to invoke
*/
public void overrideGetLength(Arena arena, Method method) {
this._getLengthMethod = method;
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), EntryBufferClass.class, "getLengthUpcall", _fdesc);
MemorySegment _address = Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("get_length"))
.set(handle(), 0, (method == null ? MemorySegment.NULL : _address));
}
private int getLengthUpcall(MemorySegment buffer) {
try {
Arena _arena = Arena.ofAuto();
var _result = (int) this._getLengthMethod.invoke((EntryBuffer) InstanceCache.getForType(buffer, EntryBuffer::new, false));
return _result;
} catch (InvocationTargetException ite) {
GLib.log(Constants.LOG_DOMAIN, LogLevelFlags.LEVEL_WARNING, ite.getCause().toString() + " in " + _getLengthMethod);
return 0;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Override virtual method {@code insert_text}.
*
* @param method the method to invoke
*/
public void overrideInsertText(Arena arena, Method method) {
this._insertTextMethod = method;
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS,
ValueLayout.JAVA_INT);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), EntryBufferClass.class, "insertTextUpcall", _fdesc);
MemorySegment _address = Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("insert_text"))
.set(handle(), 0, (method == null ? MemorySegment.NULL : _address));
}
private int insertTextUpcall(MemorySegment buffer, int position, MemorySegment chars,
int nChars) {
try {
Arena _arena = Arena.ofAuto();
var _result = (int) this._insertTextMethod.invoke((EntryBuffer) InstanceCache.getForType(buffer, EntryBuffer::new, false), position, Interop.getStringFrom(chars, false), nChars);
return _result;
} catch (InvocationTargetException ite) {
GLib.log(Constants.LOG_DOMAIN, LogLevelFlags.LEVEL_WARNING, ite.getCause().toString() + " in " + _insertTextMethod);
return 0;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Override virtual method {@code delete_text}.
*
* @param method the method to invoke
*/
public void overrideDeleteText(Arena arena, Method method) {
this._deleteTextMethod = method;
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), EntryBufferClass.class, "deleteTextUpcall", _fdesc);
MemorySegment _address = Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("delete_text"))
.set(handle(), 0, (method == null ? MemorySegment.NULL : _address));
}
private int deleteTextUpcall(MemorySegment buffer, int position, int nChars) {
try {
Arena _arena = Arena.ofAuto();
var _result = (int) this._deleteTextMethod.invoke((EntryBuffer) InstanceCache.getForType(buffer, EntryBuffer::new, false), position, nChars);
return _result;
} catch (InvocationTargetException ite) {
GLib.log(Constants.LOG_DOMAIN, LogLevelFlags.LEVEL_WARNING, ite.getCause().toString() + " in " + _deleteTextMethod);
return 0;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
/**
* 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 GObject.Builder {
/**
* Default constructor for a {@code Builder} object.
*/
protected Builder() {
}
/**
* Finish building the {@code EntryBuffer} object. This will call
* {@link GObject#withProperties} to create a new GObject instance,
* which is then cast to {@code EntryBuffer}.
*
* @return a new instance of {@code EntryBuffer} with the properties
* that were set in the Builder object.
*/
public EntryBuffer build() {
try {
var _instance = (EntryBuffer) GObject.withProperties(EntryBuffer.getType(), getNames(), getValues());
connectSignals(_instance.handle());
return _instance;
} finally {
for (Value _value : getValues()) _value.unset();
getArena().close();
}
}
/**
* The maximum length (in characters) of the text in the buffer.
*
* @param maxLength the value for the {@code max-length} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setMaxLength(int maxLength) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(Types.INT);
_value.setInt(maxLength);
addBuilderProperty("max-length", _value);
return (B) this;
}
/**
* The contents of the buffer.
*
* @param text the value for the {@code text} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setText(String text) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(Types.STRING);
_value.setString(text);
addBuilderProperty("text", _value);
return (B) this;
}
/**
* The text is altered in the default handler for this signal.
*
* If you want access to the text after the text has been modified,
* use {@link org.gnome.gobject.ConnectFlags#AFTER}.
*
* @param handler the signal handler
* @return the {@code Builder} instance is returned, to allow method chaining
* @see DeletedTextCallback#run
*/
public B onDeletedText(DeletedTextCallback handler) {
connect("deleted-text", handler);
return (B) this;
}
/**
* This signal is emitted after text is inserted into the buffer.
*
* @param handler the signal handler
* @return the {@code Builder} instance is returned, to allow method chaining
* @see InsertedTextCallback#run
*/
public B onInsertedText(InsertedTextCallback handler) {
connect("inserted-text", handler);
return (B) this;
}
}
private static final class MethodHandles {
static final MethodHandle gtk_entry_buffer_new = Interop.downcallHandle(
"gtk_entry_buffer_new", FunctionDescriptor.of(ValueLayout.ADDRESS,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT), false);
static final MethodHandle gtk_entry_buffer_delete_text = Interop.downcallHandle(
"gtk_entry_buffer_delete_text", FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT), false);
static final MethodHandle gtk_entry_buffer_emit_deleted_text = Interop.downcallHandle(
"gtk_entry_buffer_emit_deleted_text", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT, ValueLayout.JAVA_INT), false);
static final MethodHandle gtk_entry_buffer_emit_inserted_text = Interop.downcallHandle(
"gtk_entry_buffer_emit_inserted_text",
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT), false);
static final MethodHandle gtk_entry_buffer_get_bytes = Interop.downcallHandle(
"gtk_entry_buffer_get_bytes", FunctionDescriptor.of(ValueLayout.JAVA_LONG,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_entry_buffer_get_length = Interop.downcallHandle(
"gtk_entry_buffer_get_length", FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_entry_buffer_get_max_length = Interop.downcallHandle(
"gtk_entry_buffer_get_max_length", FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_entry_buffer_get_text = Interop.downcallHandle(
"gtk_entry_buffer_get_text", FunctionDescriptor.of(ValueLayout.ADDRESS,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_entry_buffer_insert_text = Interop.downcallHandle(
"gtk_entry_buffer_insert_text", FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS,
ValueLayout.JAVA_INT), false);
static final MethodHandle gtk_entry_buffer_set_max_length = Interop.downcallHandle(
"gtk_entry_buffer_set_max_length", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT), false);
static final MethodHandle gtk_entry_buffer_set_text = Interop.downcallHandle(
"gtk_entry_buffer_set_text", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.ADDRESS, ValueLayout.JAVA_INT), false);
}
}