void LoadData()
        {
            accContextInfo = new AccessibleContextInfo();
            System.Windows.Forms.Application.DoEvents();
            bool result = JavaAccNativeMethods.getAccessibleContextInfo(_vmId, _javaWin, out accContextInfo);

            if (result == false)
            {
                System.Diagnostics.Debug.WriteLine("No info");
                return;
            }
            int count = JavaAccNativeMethods.getAccessibleActions(_vmId, _javaWin);

            for (int i = 0; i < count; i++)
            {
                IntPtr actionname = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(JavaAccNativeMethods.ACTIONNAMESIZE);
                if (!actionname.Equals((System.IntPtr)System.IntPtr.Zero) && JavaAccNativeMethods.getAccessibleActionItem(i, actionname, JavaAccNativeMethods.ACTIONNAMESIZE))
                {
                    javaactions.Add(System.Runtime.InteropServices.Marshal.PtrToStringUni(actionname));
                }
            }
            System.Windows.Forms.Application.DoEvents();
            if (accContextInfo.childrenCount == 0)
            {
                return; // we are done!
            }
            // get children
            System.Windows.Forms.Application.DoEvents();
            for (int i = 0; i < accContextInfo.childrenCount; i++)
            {
                IntPtr childPtr = JavaAccNativeMethods.getAccessibleChildFromContext(_vmId, _javaWin, i);
                _children.Add(new JavaWindow(this, childPtr, _vmId));
            }
        }
        internal static string GetName(System.IntPtr accObj, int vmId)
        {
            string str = string.Empty;

            if (!accObj.Equals((System.IntPtr)System.IntPtr.Zero))
            {
                AccessibleContextInfo accContextInfo = new AccessibleContextInfo();
                try
                {
                    if (JavaAccNativeMethods.getAccessibleContextInfo(vmId, accObj, out accContextInfo) && !string.IsNullOrEmpty(accContextInfo.name))
                    {
                        return(accContextInfo.name);
                    }
                }
                catch (System.Exception exception)
                {
                    if (!IsJavaAccException(exception) || !IsJavaAccExceptionMaskable(exception))
                    {
                        throw;
                    }
                    return(str);
                }
            }
            return(str);
        }
 internal static string BuildAccKey(System.IntPtr accObj, int vmId)
 {
     System.Text.StringBuilder builder = new System.Text.StringBuilder();
     if (!accObj.Equals((System.IntPtr)System.IntPtr.Zero))
     {
         try
         {
             System.IntPtr ptr  = JavaAccNativeMethods.getTopLevelObject(vmId, accObj);
             System.IntPtr hWnd = JavaAccNativeMethods.getHWNDFromAccessibleContext(vmId, ptr);
             builder.AppendFormat("{0}.{1}.{2:X8}", (int)GetRoleID(accObj, vmId), (int)vmId, (int)hWnd.ToInt32());
             LPRECT lpRect = new LPRECT();
             Win32NativeMethods.GetWindowRect(hWnd, ref lpRect);
             AccessibleContextInfo accContextInfo = new AccessibleContextInfo();
             JavaAccNativeMethods.getAccessibleContextInfo(vmId, accObj, out accContextInfo);
             int num    = (int)(accContextInfo.x - lpRect.Left);
             int num2   = (int)(accContextInfo.y - lpRect.Top);
             int width  = accContextInfo.width;
             int height = accContextInfo.height;
             builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, ".{0},{1},{2},{3}", new object[] { (int)num, (int)num2, (int)width, (int)height });
         }
         catch (System.Exception exception)
         {
             if (!IsJavaAccException(exception) || !IsJavaAccExceptionMaskable(exception))
             {
                 throw;
             }
         }
     }
     return(builder.ToString());
 }
        private static string GetAccessibleText(System.IntPtr accObj, int vmId)
        {
            string sentence = string.Empty;

            if (!accObj.Equals((System.IntPtr)System.IntPtr.Zero))
            {
                try
                {
                    AccessibleContextInfo accContextInfo = new AccessibleContextInfo();
                    JavaAccNativeMethods.getAccessibleContextInfo(vmId, accObj, out accContextInfo);
                    if (accContextInfo.accessibleText)
                    {
                        AccessibleTextInfo accTextInfo = new AccessibleTextInfo();
                        if (JavaAccNativeMethods.getAccessibleTextInfo(vmId, accObj, out accTextInfo, 0, 0))
                        {
                            AccessibleTextItemsInfo accTextItems = new AccessibleTextItemsInfo();
                            if (JavaAccNativeMethods.getAccessibleTextItems(vmId, accObj, out accTextItems, accTextInfo.indexAtPoint))
                            {
                                sentence = accTextItems.sentence;
                            }
                        }
                    }
                }
                catch (System.Exception exception)
                {
                    if (!IsJavaAccException(exception) || !IsJavaAccExceptionMaskable(exception))
                    {
                        throw;
                    }
                    return(sentence);
                }
            }
            return(sentence);
        }
 internal static int GetRoleID(System.IntPtr accObj, int vmId)
 {
     if (!accObj.Equals((System.IntPtr)System.IntPtr.Zero))
     {
         bool flag = false;
         AccessibleContextInfo accContextInfo = new AccessibleContextInfo();
         try
         {
             flag = JavaAccNativeMethods.getAccessibleContextInfo(vmId, accObj, out accContextInfo);
         }
         catch (System.Exception exception)
         {
             if (!IsJavaAccException(exception) || !IsJavaAccExceptionMaskable(exception))
             {
                 throw;
             }
         }
         if (flag && !string.IsNullOrEmpty(accContextInfo.role))
         {
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.PUSH_BUTTON, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(0);
             }
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.TOGGLE_BUTTON, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(6);
             }
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.CHECK_BOX, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(1);
             }
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.RADIO_BUTTON, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(2);
             }
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.COMBO_BOX, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(3);
             }
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.TEXT, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(4);
             }
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.LABEL, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(5);
             }
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.MENU, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(7);
             }
             if (accContextInfo.role.Equals(JavaDataDrivenAdapterConstants.MENU_ITEM, System.StringComparison.OrdinalIgnoreCase))
             {
                 return(8);
             }
         }
     }
     return(-1);
 }
        internal static int GetChildrenCount(System.IntPtr accObj, int vmId)
        {
            int childrenCount = 0;

            try
            {
                AccessibleContextInfo accContextInfo = new AccessibleContextInfo();
                if (JavaAccNativeMethods.getAccessibleContextInfo(vmId, accObj, out accContextInfo))
                {
                    childrenCount = accContextInfo.childrenCount;
                }
            }
            catch (System.Exception exception)
            {
                if (!IsJavaAccException(exception) || !IsJavaAccExceptionMaskable(exception))
                {
                    throw;
                }
                return(childrenCount);
            }
            return(childrenCount);
        }
        private static string GetAccessibleValueInt(System.IntPtr accObj, int vmId)
        {
            string str = string.Empty;

            if (!accObj.Equals((System.IntPtr)System.IntPtr.Zero))
            {
                System.IntPtr zero = System.IntPtr.Zero;
                try
                {
                    zero = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(4);
                    if (!zero.Equals((System.IntPtr)System.IntPtr.Zero))
                    {
                        AccessibleContextInfo accContextInfo = new AccessibleContextInfo();
                        JavaAccNativeMethods.getAccessibleContextInfo(vmId, accObj, out accContextInfo);
                        if (accContextInfo.accessibleInterfaces && JavaAccNativeMethods.getCurrentAccessibleValueFromContext(vmId, accObj, zero, 4))
                        {
                            str = System.Runtime.InteropServices.Marshal.PtrToStringUni(zero);
                        }
                    }
                }
                catch (System.Exception exception)
                {
                    if (!IsJavaAccException(exception) || !IsJavaAccExceptionMaskable(exception))
                    {
                        throw;
                    }
                    return(str);
                }
                finally
                {
                    if (!zero.Equals((System.IntPtr)System.IntPtr.Zero))
                    {
                        System.Runtime.InteropServices.Marshal.FreeCoTaskMem(zero);
                    }
                }
            }
            return(str);
        }
 internal static string GetRole(System.IntPtr accObj, int vmId)
 {
     if (!accObj.Equals((System.IntPtr)System.IntPtr.Zero))
     {
         bool flag = false;
         AccessibleContextInfo accContextInfo = new AccessibleContextInfo();
         try
         {
             flag = JavaAccNativeMethods.getAccessibleContextInfo(vmId, accObj, out accContextInfo);
         }
         catch (System.Exception exception)
         {
             if (!IsJavaAccException(exception) || !IsJavaAccExceptionMaskable(exception))
             {
                 throw;
             }
         }
         if (flag && !string.IsNullOrEmpty(accContextInfo.role))
         {
             return(accContextInfo.role_en_US);
         }
     }
     return(string.Empty);
 }
        public override IUSDAutomationObject GetAutomationObject(XmlNode control)
        {
            /*
             * <Controls>
             *  <JAccControl name="clickme"> // this is the control
             *      <Path>
             *      <NextName offset = "1">Click Me</NextName>
             *      </Path>
             *  </JAccControl>
             *  <JAccControl name="textbox">
             *      <Path>
             *      <NextRole offset = "0">text</NextRole>
             *      </Path>
             *  </JAccControl>
             * </Controls>
             */

            if (!JavaAccNativeMethods._IsWindowsAccessBridgeAvailable)
            {
                throw new Exception("Java Bridge not available");
            }
            if (control.Name != "JAccControl")
            {
                throw new Exception("Invalid node type included: " + control.Name + ". Only JAccControl is valid.");
            }

            string  name = GetAttributeValue(control, "name", "");
            XmlNode path = control.SelectSingleNode("Path");
            int     vmId = 0;

            System.IntPtr zero = System.IntPtr.Zero;
            zero = this.JavaFindAccObj(name, out vmId, path.OuterXml);
            AccessibleContextInfo accContextInfo = new AccessibleContextInfo();

            if (Tracing)
            {
                StringBuilder sb = new StringBuilder();
                if (JavaAccNativeMethods.getAccessibleContextInfo(vmId, zero, out accContextInfo))
                {
                    sb.AppendLine("Java Control Found: " + name);
                    sb.AppendLine("\taccessibleText: " + accContextInfo.accessibleText.ToString());
                    sb.AppendLine("\taccessibleAction: " + accContextInfo.accessibleAction.ToString());
                    sb.AppendLine("\taccessibleComponent: " + accContextInfo.accessibleComponent.ToString());
                    sb.AppendLine("\taccessibleInterfaces: " + accContextInfo.accessibleInterfaces.ToString());
                    sb.AppendLine("\taccessibleSelection: " + accContextInfo.accessibleSelection.ToString());
                    sb.AppendLine("\tchildrenCount: " + accContextInfo.childrenCount.ToString());
                    sb.AppendLine("\tdescription: " + accContextInfo.description.ToString());
                    sb.AppendLine("\theight: " + accContextInfo.height.ToString());
                    sb.AppendLine("\tindexInParent: " + accContextInfo.indexInParent.ToString());
                    sb.AppendLine("\tname: " + accContextInfo.name);
                    sb.AppendLine("\trole: " + accContextInfo.role);
                    sb.AppendLine("\trole_en_US: " + accContextInfo.role_en_US);
                    sb.AppendLine("\tstates: " + accContextInfo.states);
                    sb.AppendLine("\tstates_en_US: " + accContextInfo.states_en_US);
                    sb.AppendLine("\twidth: " + accContextInfo.width.ToString());
                    sb.AppendLine("\tx: " + accContextInfo.x.ToString());
                    sb.AppendLine("\ty: " + accContextInfo.y.ToString());
                    string[] stateList = accContextInfo.states.Split(',');
                }

                int count = JavaAccNativeMethods.getAccessibleActions(vmId, zero);
                sb.AppendLine("\tActions: " + count.ToString());
                for (int i = 0; i < count; i++)
                {
                    IntPtr actionname = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(JavaAccNativeMethods.ACTIONNAMESIZE);
                    if (!actionname.Equals((System.IntPtr)System.IntPtr.Zero) && JavaAccNativeMethods.getAccessibleActionItem(i, actionname, JavaAccNativeMethods.ACTIONNAMESIZE))
                    {
                        string action = System.Runtime.InteropServices.Marshal.PtrToStringUni(actionname);
                        sb.AppendLine("\t\t: " + action);
                    }
                }

                LogWriter.Log(sb.ToString(), TraceEventType.Verbose);
                Trace.WriteLine(sb.ToString());
            }
            return(new JavaAutomationObject(name, vmId, zero));
        }
        internal static System.IntPtr GetNextChildByRole(string role, ref int count, int offset, ref bool nodeFound, System.IntPtr accObj, int vmId)
        {
            System.IntPtr zero = System.IntPtr.Zero;
            bool          flag = false;

            try
            {
                if (!accObj.Equals((System.IntPtr)System.IntPtr.Zero))
                {
                    if (GetRole(accObj, vmId).Equals(role.Trim(), System.StringComparison.OrdinalIgnoreCase) && (--count <= 0))
                    {
                        flag = true;
                        return(accObj);
                    }
                    AccessibleContextInfo accContextInfo = new AccessibleContextInfo();
                    if (!JavaAccNativeMethods.getAccessibleContextInfo(vmId, accObj, out accContextInfo))
                    {
                        return(zero);
                    }
                    for (int i = 0; i < accContextInfo.childrenCount; i = (int)(i + 1))
                    {
                        System.IntPtr ptr2 = JavaAccNativeMethods.getAccessibleChildFromContext(vmId, accObj, i);
                        zero = GetNextChildByRole(role, ref count, offset, ref nodeFound, ptr2, vmId);
                        if (!nodeFound && !zero.Equals((System.IntPtr)System.IntPtr.Zero))
                        {
                            nodeFound = true;
                            if (offset != 0)
                            {
                                if (((i + offset) >= 0) && ((i + offset) < accContextInfo.childrenCount))
                                {
                                    zero = JavaAccNativeMethods.getAccessibleChildFromContext(vmId, accObj, (int)(i + offset));
                                }
                                else
                                {
                                    zero = System.IntPtr.Zero;
                                }
                            }
                        }
                        if (nodeFound)
                        {
                            return(zero);
                        }
                    }
                }
                return(zero);
            }
            catch (System.Exception exception)
            {
                if (!IsJavaAccException(exception) || !IsJavaAccExceptionMaskable(exception))
                {
                    throw;
                }
                return(zero);
            }
            finally
            {
                if (!flag || (offset != 0))
                {
                    ReleaseObject(accObj, vmId);
                }
            }
            return(zero);
        }