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
move AndroidLayout class to own file
This commit is contained in:
@@ -94,6 +94,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
|
|||||||
'src/api-impl-jni/widgets/android_widget_TextView.c',
|
'src/api-impl-jni/widgets/android_widget_TextView.c',
|
||||||
'src/api-impl-jni/widgets/android_widget_LinearLayout.c',
|
'src/api-impl-jni/widgets/android_widget_LinearLayout.c',
|
||||||
'src/api-impl-jni/widgets/android_view_SurfaceView.c',
|
'src/api-impl-jni/widgets/android_view_SurfaceView.c',
|
||||||
|
'src/api-impl-jni/views/AndroidLayout.c',
|
||||||
'src/api-impl-jni/views/android_view_View.c',
|
'src/api-impl-jni/views/android_view_View.c',
|
||||||
'src/api-impl-jni/views/android_view_ViewGroup.c',
|
'src/api-impl-jni/views/android_view_ViewGroup.c',
|
||||||
'src/api-impl-jni/android_graphics_Bitmap.c',
|
'src/api-impl-jni/android_graphics_Bitmap.c',
|
||||||
|
|||||||
51
src/api-impl-jni/views/AndroidLayout.c
Normal file
51
src/api-impl-jni/views/AndroidLayout.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#include "../util.h"
|
||||||
|
#include "AndroidLayout.h"
|
||||||
|
|
||||||
|
static void android_layout_measure(GtkLayoutManager *layout_manager, GtkWidget *widget, GtkOrientation orientation, int for_size, int *minimum, int *natural, int *minimum_baseline, int *natural_baseline)
|
||||||
|
{
|
||||||
|
AndroidLayout *layout = ATL_ANDROID_LAYOUT(layout_manager);
|
||||||
|
JNIEnv *env = get_jni_env();
|
||||||
|
|
||||||
|
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
|
||||||
|
*minimum = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getSuggestedMinimumWidth);
|
||||||
|
*natural = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getMeasuredWidth);
|
||||||
|
}
|
||||||
|
if (orientation == GTK_ORIENTATION_VERTICAL) {
|
||||||
|
*minimum = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getSuggestedMinimumHeight);
|
||||||
|
*natural = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getMeasuredHeight);
|
||||||
|
}
|
||||||
|
if (*natural < *minimum)
|
||||||
|
*natural = *minimum;
|
||||||
|
|
||||||
|
*minimum_baseline = -1;
|
||||||
|
*natural_baseline = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void android_layout_allocate(GtkLayoutManager *layout_manager, GtkWidget *widget, int width, int height, int baseline)
|
||||||
|
{
|
||||||
|
AndroidLayout *layout = ATL_ANDROID_LAYOUT(layout_manager);
|
||||||
|
JNIEnv *env = get_jni_env();
|
||||||
|
|
||||||
|
(*env)->CallVoidMethod(env, layout->view, handle_cache.view.layoutInternal, width, height);
|
||||||
|
if((*env)->ExceptionCheck(env))
|
||||||
|
(*env)->ExceptionDescribe(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void android_layout_class_init(AndroidLayoutClass *klass)
|
||||||
|
{
|
||||||
|
klass->parent_class.measure = android_layout_measure;
|
||||||
|
klass->parent_class.allocate = android_layout_allocate;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void android_layout_init(AndroidLayout *self) {}
|
||||||
|
|
||||||
|
G_DEFINE_TYPE(AndroidLayout, android_layout, GTK_TYPE_LAYOUT_MANAGER)
|
||||||
|
|
||||||
|
GtkLayoutManager *android_layout_new(jobject view)
|
||||||
|
{
|
||||||
|
AndroidLayout *layout = g_object_new(android_layout_get_type(), NULL);
|
||||||
|
layout->view = view;
|
||||||
|
return &layout->parent_instance;
|
||||||
|
}
|
||||||
16
src/api-impl-jni/views/AndroidLayout.h
Normal file
16
src/api-impl-jni/views/AndroidLayout.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef ANDROID_LAYOUT_H
|
||||||
|
#define ANDROID_LAYOUT_H
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE(AndroidLayout, android_layout, ATL, ANDROID_LAYOUT, GtkLayoutManager);
|
||||||
|
|
||||||
|
struct _AndroidLayout {
|
||||||
|
GtkLayoutManager parent_instance;
|
||||||
|
jobject view;
|
||||||
|
};
|
||||||
|
|
||||||
|
GtkLayoutManager *android_layout_new(jobject view);
|
||||||
|
|
||||||
|
#endif // ANDROID_LAYOUT_H
|
||||||
@@ -4,62 +4,13 @@
|
|||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
|
|
||||||
#include "../widgets/WrapperWidget.h"
|
#include "../widgets/WrapperWidget.h"
|
||||||
|
#include "../views/AndroidLayout.h"
|
||||||
|
|
||||||
#include "../generated_headers/android_view_ViewGroup.h"
|
#include "../generated_headers/android_view_ViewGroup.h"
|
||||||
#include "../generated_headers/android_view_View.h"
|
#include "../generated_headers/android_view_View.h"
|
||||||
|
|
||||||
#define SOURCE_CLASS_POINTER 0x2
|
#define SOURCE_CLASS_POINTER 0x2
|
||||||
|
|
||||||
struct _AndroidLayout {
|
|
||||||
GtkLayoutManager parent_instance;
|
|
||||||
jobject view;
|
|
||||||
};
|
|
||||||
G_DECLARE_FINAL_TYPE(AndroidLayout, android_layout, ATL, ANDROID_LAYOUT, GtkLayoutManager);
|
|
||||||
|
|
||||||
static void android_layout_measure(GtkLayoutManager *layout_manager, GtkWidget *widget, GtkOrientation orientation, int for_size, int *minimum, int *natural, int *minimum_baseline, int *natural_baseline) {
|
|
||||||
AndroidLayout *layout = ATL_ANDROID_LAYOUT(layout_manager);
|
|
||||||
JNIEnv *env = get_jni_env();
|
|
||||||
|
|
||||||
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
|
|
||||||
*minimum = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getSuggestedMinimumWidth);
|
|
||||||
*natural = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getMeasuredWidth);
|
|
||||||
}
|
|
||||||
if (orientation == GTK_ORIENTATION_VERTICAL) {
|
|
||||||
*minimum = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getSuggestedMinimumHeight);
|
|
||||||
*natural = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getMeasuredHeight);
|
|
||||||
}
|
|
||||||
if (*natural < *minimum)
|
|
||||||
*natural = *minimum;
|
|
||||||
|
|
||||||
*minimum_baseline = -1;
|
|
||||||
*natural_baseline = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void android_layout_allocate(GtkLayoutManager *layout_manager, GtkWidget *widget, int width, int height, int baseline) {
|
|
||||||
AndroidLayout *layout = ATL_ANDROID_LAYOUT(layout_manager);
|
|
||||||
JNIEnv *env = get_jni_env();
|
|
||||||
|
|
||||||
(*env)->CallVoidMethod(env, layout->view, handle_cache.view.layoutInternal, width, height);
|
|
||||||
if((*env)->ExceptionCheck(env))
|
|
||||||
(*env)->ExceptionDescribe(env);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void android_layout_class_init(AndroidLayoutClass *klass) {
|
|
||||||
klass->parent_class.measure = android_layout_measure;
|
|
||||||
klass->parent_class.allocate = android_layout_allocate;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void android_layout_init(AndroidLayout *self) {
|
|
||||||
}
|
|
||||||
|
|
||||||
G_DEFINE_TYPE(AndroidLayout, android_layout, GTK_TYPE_LAYOUT_MANAGER)
|
|
||||||
|
|
||||||
static GtkLayoutManager *android_layout_new(jobject view) {
|
|
||||||
AndroidLayout *layout = g_object_new(android_layout_get_type(), NULL);
|
|
||||||
layout->view = view;
|
|
||||||
return &layout->parent_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MAGIC_SCROLL_FACTOR 32
|
#define MAGIC_SCROLL_FACTOR 32
|
||||||
|
|
||||||
static gboolean scroll_cb(GtkEventControllerScroll* self, gdouble dx, gdouble dy, jobject this)
|
static gboolean scroll_cb(GtkEventControllerScroll* self, gdouble dx, gdouble dy, jobject this)
|
||||||
|
|||||||
Reference in New Issue
Block a user