You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
PopupWindow: implement more stuff, mainly offset
This commit is contained in:
@@ -39,6 +39,22 @@ JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1showAsDropDown
|
||||
JNIEXPORT jboolean JNICALL Java_android_widget_PopupWindow_native_1isShowing
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupWindow
|
||||
* Method: native_setTouchable
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setTouchable
|
||||
(JNIEnv *, jobject, jlong, jboolean);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupWindow
|
||||
* Method: native_setTouchModal
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setTouchModal
|
||||
(JNIEnv *, jobject, jlong, jboolean);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupWindow
|
||||
* Method: native_dismiss
|
||||
@@ -65,19 +81,43 @@ JNIEXPORT void JNICALL Java_android_widget_PopupWindow_setOnDismissListener
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupWindow
|
||||
* Method: setWidth
|
||||
* Signature: (I)V
|
||||
* Method: native_setWidth
|
||||
* Signature: (JI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_setWidth
|
||||
(JNIEnv *, jobject, jint);
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setWidth
|
||||
(JNIEnv *, jobject, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupWindow
|
||||
* Method: setHeight
|
||||
* Signature: (I)V
|
||||
* Method: native_setHeight
|
||||
* Signature: (JI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_setHeight
|
||||
(JNIEnv *, jobject, jint);
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setHeight
|
||||
(JNIEnv *, jobject, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupWindow
|
||||
* Method: native_getWidth
|
||||
* Signature: (J)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_widget_PopupWindow_native_1getWidth
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupWindow
|
||||
* Method: native_getHeight
|
||||
* Signature: (J)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_widget_PopupWindow_native_1getHeight
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupWindow
|
||||
* Method: native_isTouchable
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_android_widget_PopupWindow_native_1isTouchable
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ JNIEXPORT jlong JNICALL Java_android_widget_PopupWindow_native_1constructor(JNIE
|
||||
{
|
||||
GtkWidget *popover = gtk_popover_new();
|
||||
gtk_widget_set_name(popover, "PopupWindow");
|
||||
/* autohiding works by the widget grabbing events, which is not something apps expect */
|
||||
gtk_popover_set_autohide(GTK_POPOVER(popover), false);
|
||||
return _INTPTR(popover);
|
||||
}
|
||||
|
||||
@@ -20,32 +22,76 @@ JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setContentView(JN
|
||||
gtk_popover_set_child(GTK_POPOVER(_PTR(popover_ptr)), GTK_WIDGET(content));
|
||||
}
|
||||
|
||||
static inline void set_offset(GtkPopover *popover, GtkWidget *anchor, int x, int y)
|
||||
{
|
||||
/* FIXME: assumes GTK_POS_BOTTOM */
|
||||
gtk_popover_set_offset(popover, x - gtk_widget_get_width(anchor) / 2, y - gtk_widget_get_height(anchor));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1showAsDropDown(JNIEnv *env, jobject this, jlong popover_ptr, jlong anchor_ptr, jint x, jint y, jint gravity)
|
||||
{
|
||||
GtkPopover *popover = GTK_POPOVER(_PTR(popover_ptr));
|
||||
WrapperWidget *anchor = WRAPPER_WIDGET(gtk_widget_get_parent(GTK_WIDGET(_PTR(anchor_ptr))));
|
||||
|
||||
gtk_widget_insert_before(GTK_WIDGET(popover), GTK_WIDGET(anchor), NULL);
|
||||
set_offset(popover, GTK_WIDGET(anchor), x, y);
|
||||
gtk_popover_present(GTK_POPOVER(popover));
|
||||
gtk_popover_popup(popover);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_setWidth(JNIEnv *env, jobject this, jint width)
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setWidth(JNIEnv *env, jobject this, jlong popover_ptr, jint width)
|
||||
{
|
||||
int height;
|
||||
GtkWidget *popover = GTK_WIDGET(_PTR(_GET_LONG_FIELD(this, "popover")));
|
||||
GtkWidget *popover = GTK_WIDGET(_PTR(popover_ptr));
|
||||
gtk_widget_get_size_request(popover, NULL, &height);
|
||||
gtk_widget_set_size_request(popover, width, height);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_setHeight(JNIEnv *env, jobject this, jint height)
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setHeight(JNIEnv *env, jobject this, jlong popover_ptr, jint height)
|
||||
{
|
||||
int width;
|
||||
GtkWidget *popover = GTK_WIDGET(_PTR(_GET_LONG_FIELD(this, "popover")));
|
||||
GtkWidget *popover = GTK_WIDGET(_PTR(popover_ptr));
|
||||
gtk_widget_get_size_request(popover, &width, NULL);
|
||||
gtk_widget_set_size_request(popover, width, height);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_widget_PopupWindow_native_1getWidth(JNIEnv *env, jobject this, jlong popover_ptr)
|
||||
{
|
||||
GtkWidget *popover = GTK_WIDGET(_PTR(popover_ptr));
|
||||
GtkRequisition natural_size;
|
||||
gtk_widget_get_preferred_size(popover, &natural_size, NULL);
|
||||
return natural_size.width;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_widget_PopupWindow_native_1getHeight(JNIEnv *env, jobject this, jlong popover_ptr)
|
||||
{
|
||||
GtkWidget *popover = GTK_WIDGET(_PTR(popover_ptr));
|
||||
GtkRequisition natural_size;
|
||||
gtk_widget_get_preferred_size(popover, &natural_size, NULL);
|
||||
return natural_size.height;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setTouchable(JNIEnv *env, jobject this, jlong popover_ptr, jboolean touchable)
|
||||
{
|
||||
GtkWidget *popover = GTK_WIDGET(_PTR(popover_ptr));
|
||||
gtk_widget_set_sensitive(popover, touchable);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_android_widget_PopupWindow_native_1isTouchable(JNIEnv *env, jobject this, jlong popover_ptr)
|
||||
{
|
||||
GtkWidget *popover = GTK_WIDGET(_PTR(popover_ptr));
|
||||
return gtk_widget_is_sensitive(popover);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1setTouchModal(JNIEnv *env, jobject this, jlong popover_ptr, jboolean touch_modal)
|
||||
{
|
||||
GtkPopover *popover = GTK_POPOVER(_PTR(popover_ptr));
|
||||
/* FIXME: we should only add grab (not autohide), however we need to remove it again in umap;
|
||||
* GtkPopover is not final, so we should subclass it and check whether it's modal in map/unmap
|
||||
* to add/remove grab, which is the desired part of what GtkPopover does with autohide enabled */
|
||||
gtk_popover_set_autohide(popover, touch_modal);
|
||||
}
|
||||
|
||||
static void on_closed_cb(GtkPopover *popover, jobject listener)
|
||||
{
|
||||
JNIEnv *env = get_jni_env();
|
||||
@@ -74,6 +120,7 @@ JNIEXPORT void JNICALL Java_android_widget_PopupWindow_native_1update(JNIEnv *en
|
||||
GtkPopover *popover = GTK_POPOVER(_PTR(popover_ptr));
|
||||
WrapperWidget *anchor = WRAPPER_WIDGET(gtk_widget_get_parent(GTK_WIDGET(_PTR(anchor_ptr))));
|
||||
gtk_widget_set_size_request(GTK_WIDGET(popover), width, height);
|
||||
set_offset(popover, GTK_WIDGET(anchor), x, y);
|
||||
gtk_widget_insert_before(GTK_WIDGET(popover), GTK_WIDGET(anchor), NULL);
|
||||
gtk_popover_present(GTK_POPOVER(popover));
|
||||
gtk_popover_popup(popover);
|
||||
|
||||
Reference in New Issue
Block a user