comparison android/dw.cpp @ 2582:01fca1937806

Android: Implement dw_window_set_focus(), dw_window_default() and dw_window_get_font(). dw_window_get_font() is untested... will test it shortly in another app.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 23 May 2021 07:30:52 +0000
parents 473eb9ff3f04
children 2acc7ba5dea0
comparison
equal deleted inserted replaced
2581:9dea42f27b0a 2582:01fca1937806
5091 * Remarks: 5091 * Remarks:
5092 * This is for use after showing the window/dialog. 5092 * This is for use after showing the window/dialog.
5093 */ 5093 */
5094 void API dw_window_set_focus(HWND handle) 5094 void API dw_window_set_focus(HWND handle)
5095 { 5095 {
5096 JNIEnv *env;
5097
5098 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
5099 {
5100 // First get the class that contains the method you need to call
5101 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
5102 // Get the method that you want to call
5103 jmethodID windowSetFocus = env->GetMethodID(clazz, "windowSetFocus",
5104 "(Landroid/view/View;)V");
5105 // Call the method on the object
5106 env->CallVoidMethod(_dw_obj, windowSetFocus, handle);
5107 _dw_jni_check_exception(env);
5108 }
5096 } 5109 }
5097 5110
5098 /* 5111 /*
5099 * Sets the default focus item for a window/dialog. 5112 * Sets the default focus item for a window/dialog.
5100 * Parameters: 5113 * Parameters:
5103 * Remarks: 5116 * Remarks:
5104 * This is for use before showing the window/dialog. 5117 * This is for use before showing the window/dialog.
5105 */ 5118 */
5106 void API dw_window_default(HWND handle, HWND defaultitem) 5119 void API dw_window_default(HWND handle, HWND defaultitem)
5107 { 5120 {
5121 JNIEnv *env;
5122
5123 if(handle && defaultitem && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
5124 {
5125 // First get the class that contains the method you need to call
5126 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
5127 // Get the method that you want to call
5128 jmethodID windowDefault = env->GetMethodID(clazz, "windowDefault",
5129 "(Landroid/view/View;Landroid/view/View;)V");
5130 // Call the method on the object
5131 env->CallVoidMethod(_dw_obj, windowDefault, handle, defaultitem);
5132 _dw_jni_check_exception(env);
5133 }
5108 } 5134 }
5109 5135
5110 /* 5136 /*
5111 * Sets window to click the default dialog item when an ENTER is pressed. 5137 * Sets window to click the default dialog item when an ENTER is pressed.
5112 * Parameters: 5138 * Parameters:
5160 // Construct a string 5186 // Construct a string
5161 jstring jstr = env->NewStringUTF(fontname); 5187 jstring jstr = env->NewStringUTF(fontname);
5162 // First get the class that contains the method you need to call 5188 // First get the class that contains the method you need to call
5163 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 5189 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
5164 // Get the method that you want to call 5190 // Get the method that you want to call
5165 jmethodID windowHideShow = env->GetMethodID(clazz, "windowSetFont", 5191 jmethodID windowSetFont = env->GetMethodID(clazz, "windowSetFont",
5166 "(Landroid/view/View;Ljava/lang/String;)V"); 5192 "(Landroid/view/View;Ljava/lang/String;)V");
5167 // Call the method on the object 5193 // Call the method on the object
5168 env->CallVoidMethod(_dw_obj, windowHideShow, handle, jstr); 5194 env->CallVoidMethod(_dw_obj, windowSetFont, handle, jstr);
5169 if(!_dw_jni_check_exception(env)) 5195 if(!_dw_jni_check_exception(env))
5170 return DW_ERROR_NONE; 5196 return DW_ERROR_NONE;
5171 } 5197 }
5172 return DW_ERROR_GENERAL; 5198 return DW_ERROR_GENERAL;
5173 } 5199 }
5179 * Returns: 5205 * Returns:
5180 * A malloc()ed font name string to be dw_free()ed or nullptr on error. 5206 * A malloc()ed font name string to be dw_free()ed or nullptr on error.
5181 */ 5207 */
5182 char * API dw_window_get_font(HWND handle) 5208 char * API dw_window_get_font(HWND handle)
5183 { 5209 {
5184 return nullptr; 5210 JNIEnv *env;
5211 char *fontname = nullptr;
5212
5213 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
5214 {
5215 // First get the class that contains the method you need to call
5216 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
5217 // Get the method that you want to call
5218 jmethodID windowGetFont = env->GetMethodID(clazz, "windowGetFont",
5219 "(Landroid/view/View;)Ljava/lang/String;");
5220 // Call the method on the object
5221 jstring jstr = (jstring)_dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, windowGetFont, handle), _DW_REFERENCE_NONE);
5222
5223 if(jstr)
5224 fontname = strdup(env->GetStringUTFChars(jstr, nullptr));
5225 }
5226 return fontname;
5185 } 5227 }
5186 5228
5187 /* Allows the user to choose a font using the system's font chooser dialog. 5229 /* Allows the user to choose a font using the system's font chooser dialog.
5188 * Parameters: 5230 * Parameters:
5189 * currfont: current font 5231 * currfont: current font