comparison android/dw.cpp @ 2543:f9367eb9a6e7

Android: Initial menu support, incomplete but basics functional.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 13 May 2021 19:54:15 +0000
parents bb75e64e6138
children dbfcc0e357d6
comparison
equal deleted inserted replaced
2542:bb75e64e6138 2543:f9367eb9a6e7
583 /* 583 /*
584 * Runs a message loop for Dynamic Windows. 584 * Runs a message loop for Dynamic Windows.
585 */ 585 */
586 void API dw_main(void) 586 void API dw_main(void)
587 { 587 {
588 JNIEnv *env;
589
590 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
591 {
592 // First get the class that contains the method you need to call
593 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
594 // Get the method that you want to call
595 jmethodID dwMain = env->GetMethodID(clazz, "dwMain",
596 "()V");
597 // Call the method on the object
598 env->CallVoidMethod(_dw_obj, dwMain);
599 }
600
588 /* We don't actually run a loop here, 601 /* We don't actually run a loop here,
589 * we launched a new thread to run the loop there. 602 * we launched a new thread to run the loop there.
590 * Just wait for dw_main_quit() on the DWMainEvent. 603 * Just wait for dw_main_quit() on the DWMainEvent.
591 */ 604 */
592 dw_event_wait(_dw_main_event, DW_TIMEOUT_INFINITE); 605 dw_event_wait(_dw_main_event, DW_TIMEOUT_INFINITE);
3894 * Returns: 3907 * Returns:
3895 * Handle to the created menu or nullptr on error. 3908 * Handle to the created menu or nullptr on error.
3896 */ 3909 */
3897 HMENUI API dw_menu_new(ULONG cid) 3910 HMENUI API dw_menu_new(ULONG cid)
3898 { 3911 {
3912 JNIEnv *env;
3913
3914 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3915 {
3916 // First get the class that contains the method you need to call
3917 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3918 // Get the method that you want to call
3919 jmethodID menuNew = env->GetMethodID(clazz, "menuNew",
3920 "(I)Lorg/dbsoft/dwindows/DWMenu;");
3921 // Call the method on the object
3922 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, menuNew, (int)cid));
3923 return result;
3924 }
3899 return nullptr; 3925 return nullptr;
3900 } 3926 }
3901 3927
3902 /* 3928 /*
3903 * Create a menubar on a window. 3929 * Create a menubar on a window.
3906 * Returns: 3932 * Returns:
3907 * Handle to the created menu bar or nullptr on error. 3933 * Handle to the created menu bar or nullptr on error.
3908 */ 3934 */
3909 HMENUI API dw_menubar_new(HWND location) 3935 HMENUI API dw_menubar_new(HWND location)
3910 { 3936 {
3937 JNIEnv *env;
3938
3939 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3940 {
3941 // First get the class that contains the method you need to call
3942 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3943 // Get the method that you want to call
3944 jmethodID menuBarNew = env->GetMethodID(clazz, "menuBarNew",
3945 "(Landroid/view/View;)Lorg/dbsoft/dwindows/DWMenu;");
3946 // Call the method on the object
3947 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, menuBarNew, location));
3948 return result;
3949 }
3911 return nullptr; 3950 return nullptr;
3912 } 3951 }
3913 3952
3914 /* 3953 /*
3915 * Destroys a menu created with dw_menubar_new or dw_menu_new. 3954 * Destroys a menu created with dw_menubar_new or dw_menu_new.
3958 * Returns: 3997 * Returns:
3959 * Handle to the created menu item or nullptr on error. 3998 * Handle to the created menu item or nullptr on error.
3960 */ 3999 */
3961 HWND API dw_menu_append_item(HMENUI menux, const char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux) 4000 HWND API dw_menu_append_item(HMENUI menux, const char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux)
3962 { 4001 {
4002 JNIEnv *env;
4003
4004 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
4005 {
4006 // Create a string
4007 jstring jstr = env->NewStringUTF(title);
4008 // First get the class that contains the method you need to call
4009 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4010 // Get the method that you want to call
4011 jmethodID menuAppendItem = env->GetMethodID(clazz, "menuAppendItem",
4012 "(Lorg/dbsoft/dwindows/DWMenu;Ljava/lang/String;IIIILorg/dbsoft/dwindows/DWMenu;)Lorg/dbsoft/dwindows/DWMenuItem;");
4013 // Call the method on the object
4014 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, menuAppendItem, menux, jstr, (int)itemid, (int)flags, end, check, submenux));
4015 return result;
4016 }
3963 return nullptr; 4017 return nullptr;
3964 } 4018 }
3965 4019
3966 /* 4020 /*
3967 * Sets the state of a menu item check. 4021 * Sets the state of a menu item check.
4801 const char *release = nullptr; 4855 const char *release = nullptr;
4802 4856
4803 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 4857 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
4804 { 4858 {
4805 // First get the class that contains the method you need to call 4859 // First get the class that contains the method you need to call
4806 //jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 4860 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4807 jclass clazz = env->FindClass(DW_CLASS_NAME);
4808 // Get the method that you want to call 4861 // Get the method that you want to call
4809 jmethodID androidGetRelease = env->GetMethodID(clazz, "androidGetRelease", 4862 jmethodID androidGetRelease = env->GetMethodID(clazz, "androidGetRelease",
4810 "()Ljava/lang/String;"); 4863 "()Ljava/lang/String;");
4811 // Call the method on the object 4864 // Call the method on the object
4812 jstring jstr = (jstring)env->CallObjectMethod(_dw_obj, androidGetRelease); 4865 jstring jstr = (jstring)env->CallObjectMethod(_dw_obj, androidGetRelease);