All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mmarquee.automation.uiautomation.IUIAutomationElementConverter Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
/*
 * Copyright 2016-17 [email protected]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package mmarquee.automation.uiautomation;

import com.sun.jna.Function;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Guid;
import com.sun.jna.platform.win32.Variant;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;

/**
 * Convert class for the IUIAutomationElement.
 *
 * Pulled out to allow better isolation and testing
 */
class IUIAutomationElementConverter {
    private static int UIAutomationElement_Methods  = 85; // 0-2 IUnknown, 3-84 IUIAutomationElement3

    public static IUIAutomationElement PointerToInterface(final PointerByReference ptr) {
        final Pointer interfacePointer = ptr.getValue();
        final Pointer vTablePointer = interfacePointer.getPointer(0);
        final Pointer[] vTable = new Pointer[UIAutomationElement_Methods];
        vTablePointer.read(0, vTable, 0, vTable.length);
        return new IUIAutomationElement() {

            private Function getFunction(int offset) {
                return Function.getFunction(vTable[offset], Function.ALT_CONVENTION);
            }

            // IUnknown
            @Override
            public WinNT.HRESULT QueryInterface(Guid.REFIID byValue, PointerByReference pointerByReference) {
                Function f = getFunction(0);
                return new WinNT.HRESULT(f.invokeInt(new Object[]{interfacePointer, byValue, pointerByReference}));
            }

            @Override
            public int AddRef() {
                Function f = this.getFunction(1);
                return f.invokeInt(new Object[]{interfacePointer});
            }

            public int Release() {
                Function f = this.getFunction(2);
                return f.invokeInt(new Object[]{interfacePointer});
            }

            public int setFocus() {
                Function f = this.getFunction(3);
                return f.invokeInt(new Object[]{interfacePointer});
            }

            public int getRuntimeId (/* SAFEARRAY */ PointerByReference runtimeId) {
                Function f = this.getFunction(4);
                return f.invokeInt(new Object[]{interfacePointer, runtimeId});
            }

            public int findFirst(TreeScope scope, Pointer condition, PointerByReference sr) {
                Function f = this.getFunction(5);
                return f.invokeInt(new Object[]{interfacePointer, scope.value, condition, sr});
            }

            public int findAll(TreeScope scope, Pointer condition, PointerByReference sr) {
                Function f = this.getFunction(6);
                return f.invokeInt(new Object[]{interfacePointer, scope.value, condition, sr});
            }

//                public int FindFirstBuildCache (/* [in] */ int scope, /* [in] */ /* IUIAutomationCondition */ Pointer condition, /* [in] */ /* IUIAutomationCacheRequest */ Pointer cacheRequest, /* IUIAutomationElement3 */ PointerByReference found) {
//                    Function f = Function.getFunction(vTable[7], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, scope, condition, cacheRequest, found});
//                }

//                public int FindAllBuildCache (/* [in] */ int scope, /* [in] */ /* IUIAutomationCondition */ Pointer condition, /* [in] */ /* IUIAutomationCacheRequest */ Pointer cacheRequest, /* IUIAutomationElementArray */ PointerByReference found) {
//                    Function f = Function.getFunction(vTable[8], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, scope, condition, cacheRequest, found});
//                }

//                public int BuildUpdatedCache (/* [in] */ /* IUIAutomationCacheRequest */ Pointer cacheRequest, /* IUIAutomationElement3 */ PointerByReference updatedElement) {
//                    Function f = Function.getFunction(vTable[9], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, cacheRequest, updatedElement});
//                }

            public int getCurrentPropertyValue(int propertyId, Variant.VARIANT.ByReference value) {
                Function f = this.getFunction(10);
                return f.invokeInt(new Object[]{interfacePointer, propertyId, value});
            }

            public int getCurrentPropertyValueEx (/* [in] */ int propertyId, /* [in] */ WinDef.BOOL ignoreDefaultValue, Variant.VARIANT retVal) {
                Function f = this.getFunction(11);
                return f.invokeInt(new Object[]{interfacePointer, propertyId, ignoreDefaultValue, retVal});
            }

//                public int GetCachedPropertyValue (/* [in] */ int propertyId, Variant.VARIANT retVal) {
//                    Function f = Function.getFunction(vTable[12], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, propertyId, retVal});
//                }

//                public int GetCachedPropertyValueEx (/* [in] */ int propertyId, /* [in] */ WinDef.BOOL ignoreDefaultValue, Variant.VARIANT retVal) {
//                    Function f = Function.getFunction(vTable[13], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, propertyId, ignoreDefaultValue, retVal});
//                }

            public int getCurrentPatternAs (/* [in] */ int patternId, /* [in] */ Guid.REFIID riid, /* [retval][iid_is][out] */ PointerByReference patternObject) {
                Function f = this.getFunction(14);
                return f.invokeInt(new Object[]{interfacePointer, patternId, riid, patternObject});
            }

//                public int GetCachedPatternAs (/* [in] */ int patternId, /* [in] */ Guid.REFIID riid, /* [retval][iid_is][out] */ PointerByReference patternObject) {
//                    Function f = Function.getFunction(vTable[15], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, patternId, riid, patternObject});
//                }

            public int getCurrentPattern(Integer patternId, PointerByReference pbr) {
                Function f = this.getFunction(16);
                return f.invokeInt(new Object[]{interfacePointer, patternId, pbr});
            }

//                public int GetCachedPattern (/* [in] */ int patternId, PointerByReference patternObject) {
//                    Function f = Function.getFunction(vTable[17], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, patternId, patternObject});
//                }

//                public int GetCachedParent (/* IUIAutomationElement3 */ PointerByReference parent) {
//                    Function f = Function.getFunction(vTable[18], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, parent});
//                }

//                public int GetCachedChildren (/* IUIAutomationElementArray */ PointerByReference children) {
//                    Function f = Function.getFunction(vTable[19], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, children});
//                }

            public int getCurrentProcessId (IntByReference retVal) {
                Function f = this.getFunction(20);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentControlType(IntByReference ipr) {
                Function f = this.getFunction(21);
                return f.invokeInt(new Object[]{interfacePointer, ipr});
            }

            public int getCurrentLocalizedControlType (PointerByReference retVal) {
                Function f = this.getFunction(22);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentName(PointerByReference sr) {
                Function f = this.getFunction(23);
                return f.invokeInt(new Object[]{interfacePointer, sr});
            }

            public int getCurrentAcceleratorKey (PointerByReference retVal) {
                Function f = this.getFunction(24);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentAccessKey (PointerByReference retVal) {
                Function f = this.getFunction(25);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentHasKeyboardFocus (WinDef.BOOLByReference retVal) {
                Function f = this.getFunction(26);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentIsKeyboardFocusable (WinDef.BOOLByReference retVal) {
                Function f = this.getFunction(27);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentIsEnabled (WinDef.BOOLByReference retVal) {
                Function f = this.getFunction(28);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentAutomationId (PointerByReference retVal) {
                Function f = this.getFunction(29);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentClassName(PointerByReference sr) {
                Function f = this.getFunction(30);
                return f.invokeInt(new Object[]{interfacePointer, sr});
            }

            public int getCurrentHelpText (PointerByReference retVal) {
                Function f = this.getFunction(31);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentCulture (IntByReference retVal) {
                Function f = this.getFunction(32);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentIsControlElement (WinDef.BOOLByReference retVal) {
                Function f = this.getFunction(33);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentIsContentElement (WinDef.BOOLByReference retVal) {
                Function f = this.getFunction(34);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentIsPassword(IntByReference value) {
                Function f = this.getFunction(35);
                return f.invokeInt(new Object[]{interfacePointer, value});
            }

            public int getCurrentNativeWindowHandle (PointerByReference retVal) {
                Function f = this.getFunction(36);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentItemType (PointerByReference retVal) {
                Function f = this.getFunction(37);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentIsOffscreen (WinDef.BOOLByReference retVal) {
                Function f = this.getFunction(38);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentOrientation (IntByReference retVal) {
                Function f = this.getFunction(39);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentFrameworkId (PointerByReference retVal) {
                Function f = this.getFunction(40);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentIsRequiredForForm (WinDef.BOOLByReference retVal) {
                Function f = this.getFunction(41);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentItemStatus (PointerByReference retVal) {
                Function f = this.getFunction(42);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentBoundingRectangle (WinDef.RECT retVal) {
                Function f = this.getFunction(43);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentLabeledBy (PointerByReference retVal) {
                Function f = this.getFunction(44);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentAriaRole(PointerByReference sr) {
                Function f = this.getFunction(45);
                return f.invokeInt(new Object[]{interfacePointer, sr});
            }

            public int getCurrentAriaProperties (PointerByReference retVal) {
                Function f = this.getFunction(46);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentIsDataValidForForm (WinDef.BOOLByReference retVal) {
                Function f = this.getFunction(47);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentControllerFor (/* IUIAutomationElementArray */ PointerByReference retVal) {
                Function f = this.getFunction(48);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentDescribedBy (/* IUIAutomationElementArray */ PointerByReference retVal) {
                Function f = this.getFunction(49);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentFlowsTo (/* IUIAutomationElementArray */ PointerByReference retVal) {
                Function f = this.getFunction(50);
                return f.invokeInt(new Object[]{interfacePointer, retVal});
            }

            public int getCurrentProviderDescription(PointerByReference sr) {
                Function f = this.getFunction(51);
                return f.invokeInt(new Object[]{interfacePointer, sr});
            }

//                public int get_CachedControlType (IntByReference retVal) {
//                    Function f = Function.getFunction(vTable[53], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedLocalizedControlType (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[54], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedName (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[55], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedAcceleratorKey (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[56], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedAccessKey (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[57], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedHasKeyboardFocus (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[58], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedIsKeyboardFocusable (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[59], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
            //               }

//                public int get_CachedIsEnabled (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[60], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedAutomationId (PointerByReference retVal) {
            //                   Function f = Function.getFunction(vTable[61], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedClassName (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[62], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedHelpText (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[63], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedCulture (IntByReference retVal) {
//                    Function f = Function.getFunction(vTable[64], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedIsControlElement (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[65], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedIsContentElement (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[66], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedIsPassword (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[67], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedNativeWindowHandle (WinDef.HWND retVal) {
//                    Function f = Function.getFunction(vTable[68], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedItemType (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[69], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedIsOffscreen (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[70], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedOrientation (IntByReference retVal) {
//                    Function f = Function.getFunction(vTable[71], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedFrameworkId (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[72], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedIsRequiredForForm (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[73], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedItemStatus (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[74], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedBoundingRectangle (WinDef.RECT retVal) {
//                    Function f = Function.getFunction(vTable[75], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedLabeledBy (/* IUIAutomationElement3 */ PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[76], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedAriaRole (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[77], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedAriaProperties (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[78], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedIsDataValidForForm (WinDef.BOOLByReference retVal) {
//                    Function f = Function.getFunction(vTable[79], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedControllerFor (/* IUIAutomationElementArray */ PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[80], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedDescribedBy (/* IUIAutomationElementArray */ PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[81], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedFlowsTo (/* IUIAutomationElementArray */ PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[82], Function.ALT_CONVENTION);
//                    return f.invokeInt(new Object[]{interfacePointer, retVal});
//                }

//                public int get_CachedProviderDescription (PointerByReference retVal) {
//                    Function f = Function.getFunction(vTable[83], Function.ALT_CONVENTION);
            //                   return f.invokeInt(new Object[]{interfacePointer, retVal});
///                }

            public int getClickablePoint (WinDef.POINT.ByReference clickable, WinDef.BOOLByReference gotClickable) {
                Function f = this.getFunction(84);
                return f.invokeInt(new Object[]{interfacePointer, clickable, gotClickable});
            }

        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy