changeset 6855:03bdbccae5d8

RT-36636: [Accessibility] Finish editable text support - Finished natives in GlassTextRangeProvider.cpp (only VARIANT to jobject is missing, but it harder and only used by FindAttribute()).
author Felipe Heidrich <felipe.heidrich@oracle.com>
date Tue, 22 Apr 2014 12:36:46 -0700
parents cc8a5e12ce20
children 73368266ee9f
files modules/graphics/src/main/native-glass/win/GlassAccessible.cpp modules/graphics/src/main/native-glass/win/GlassTextRangeProvider.cpp
diffstat 2 files changed, 24 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/win/GlassAccessible.cpp	Tue Apr 22 16:24:27 2014 -0600
+++ b/modules/graphics/src/main/native-glass/win/GlassAccessible.cpp	Tue Apr 22 12:36:46 2014 -0700
@@ -607,17 +607,8 @@
     JNIEnv* env = GetEnv();
     jstring str = (jstring)env->CallObjectMethod(m_jAccessible, mid_get_ValueString);
     if (CheckAndClearException(env)) return E_FAIL;
-    if (str) {
-        UINT length = env->GetStringLength(str);
-        const jchar* ptr = env->GetStringCritical(str, NULL);
-        if (ptr != NULL) {
-        	*pRetVal = SysAllocStringLen(reinterpret_cast<const OLECHAR *>(ptr), length);
-        	env->ReleaseStringCritical(str, ptr);
-        }
-    } else {
-        *pRetVal = NULL;
-    }
-    return S_OK;
+
+    return GlassAccessible::copyString(env, str, pRetVal);
 }
 
 /***********************************************/
--- a/modules/graphics/src/main/native-glass/win/GlassTextRangeProvider.cpp	Tue Apr 22 16:24:27 2014 -0600
+++ b/modules/graphics/src/main/native-glass/win/GlassTextRangeProvider.cpp	Tue Apr 22 12:36:46 2014 -0700
@@ -105,9 +105,13 @@
     jlong ptr = env->CallLongMethod(m_jTextRangeProvider, mid_Clone);
     if (CheckAndClearException(env)) return E_FAIL;
 
-    ITextRangeProvider* iUnknown = reinterpret_cast<ITextRangeProvider*>(ptr);
-//    if (iUnknown) iUnknown->AddRef(); /* The refcount of the a new object is one. Do we want to keep a reference to this guy ? */
-    *pRetVal = iUnknown;
+    /* This code is intentionally commented.
+     * The refcount of the a new object is one. Keep it one means JavaFX holds no reference to it.
+     */
+//    ITextRangeProvider* iUnknown = reinterpret_cast<ITextRangeProvider*>(ptr);
+//    if (iUnknown) iUnknown->AddRef();
+
+    *pRetVal = reinterpret_cast<ITextRangeProvider*>(ptr);
     return S_OK;
 }
 
@@ -154,42 +158,45 @@
     jlong ptr = env->CallLongMethod(m_jTextRangeProvider, mid_FindAttribute, attributeId, jVal, backward);
     if (CheckAndClearException(env)) return E_FAIL;
 
-    //TODO AddRef ptr
+    /* AddRef the result */
+    ITextRangeProvider* iUnknown = reinterpret_cast<ITextRangeProvider*>(ptr);
+    if (iUnknown) iUnknown->AddRef();
+
     *pRetVal = reinterpret_cast<ITextRangeProvider*>(ptr);
     return S_OK;
 }
 
 IFACEMETHODIMP GlassTextRangeProvider::FindText(BSTR text, BOOL backward, BOOL ignoreCase, ITextRangeProvider **pRetVal)
 {
-    //TODO TEXT TO JTEXT
-    jstring jText = NULL;
     JNIEnv* env = GetEnv();
+    jsize length = SysStringLen(text);
+    jstring jText = env->NewString((const jchar *)text, length);
     jlong ptr = env->CallLongMethod(m_jTextRangeProvider, mid_FindText, jText, backward, ignoreCase);
     if (CheckAndClearException(env)) return E_FAIL;
 
-    //TODO AddRef ptr
+    /* AddRef the result */
+    ITextRangeProvider* iUnknown = reinterpret_cast<ITextRangeProvider*>(ptr);
+    if (iUnknown) iUnknown->AddRef();
+
     *pRetVal = reinterpret_cast<ITextRangeProvider*>(ptr);
     return S_OK;
 }
 IFACEMETHODIMP GlassTextRangeProvider::GetAttributeValue(TEXTATTRIBUTEID attributeId, VARIANT *pRetVal)
 {
     JNIEnv* env = GetEnv();
-    jobject jval = env->CallObjectMethod(m_jTextRangeProvider, mid_GetAttributeValue, attributeId);
+    jobject jVariant = env->CallObjectMethod(m_jTextRangeProvider, mid_GetAttributeValue, attributeId);
     if (CheckAndClearException(env)) return E_FAIL;
 
-    //TODO jval to val
-//    *pRetVal =
-    return S_OK;
+    return GlassAccessible::copyVariant(env, jVariant, pRetVal);
 }
 
-IFACEMETHODIMP GlassTextRangeProvider::GetBoundingRectangles(SAFEARRAY * *pRetVal)
+IFACEMETHODIMP GlassTextRangeProvider::GetBoundingRectangles(SAFEARRAY **pRetVal)
 {
     JNIEnv* env = GetEnv();
     jarray bounds = (jarray)env->CallObjectMethod(m_jTextRangeProvider, mid_GetBoundingRectangles);
     if (CheckAndClearException(env)) return E_FAIL;
 
-    //TODO bounds to SAFEARRAY
-    return S_OK;
+    return GlassAccessible::copyList(env, bounds, pRetVal, VT_R8);
 }
 
 IFACEMETHODIMP GlassTextRangeProvider::GetEnclosingElement(IRawElementProviderSimple **pRetVal)
@@ -283,8 +290,7 @@
     jarray children = (jarray)env->CallObjectMethod(m_jTextRangeProvider, mid_GetChildren);
     if (CheckAndClearException(env)) return E_FAIL;
 
-    //TODO children to SAFEARRAY
-    return S_OK;
+    return GlassAccessible::copyList(env, children, pRetVal, VT_UNKNOWN);
 }
 
 /***********************************************/