Example usage for org.eclipse.swt.ole.win32 OleControlSite OleControlSite

List of usage examples for org.eclipse.swt.ole.win32 OleControlSite OleControlSite

Introduction

In this page you can find the example usage for org.eclipse.swt.ole.win32 OleControlSite OleControlSite.

Prototype

public OleControlSite(Composite parent, int style, String progId) 

Source Link

Document

Create an OleControlSite child widget using style bits to select a particular look or set of properties.

Usage

From source file:MainClass.java

public static void main(String[] args) {

    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(600, 400);/*from ww  w.j ava 2s  .c o  m*/
    shell.setLayout(new FillLayout());

    OleControlSite oleControlSite;

    OleFrame oleFrame = new OleFrame(shell, SWT.NONE);
    oleControlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer");
    oleControlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
    shell.open();

    final OleAutomation browser = new OleAutomation(oleControlSite);

    int[] browserIDs = browser.getIDsOfNames(new String[] { "Navigate", "URL" });
    Variant[] address = new Variant[] { new Variant("http://www.java2s.com") };
    browser.invoke(browserIDs[0], address, new int[] { browserIDs[1] });

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }

    browser.dispose();
    display.dispose();
}

From source file:SWTOleFrame.java

public static void main(String[] args) {

    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(600, 400);//from w w w. j  a v a 2s .c om
    shell.setLayout(new FillLayout());

    OleControlSite oleControlSite;

    OleFrame oleFrame = new OleFrame(shell, SWT.NONE);
    oleControlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer");
    oleControlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
    shell.open();

    final OleAutomation browser = new OleAutomation(oleControlSite);

    int[] browserIDs = browser.getIDsOfNames(new String[] { "Navigate", "URL" });
    Variant[] address = new Variant[] { new Variant("http://www.oreilly.com") };
    browser.invoke(browserIDs[0], address, new int[] { browserIDs[1] });

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }

    browser.dispose();
    display.dispose();
}

From source file:Snippet187.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    OleControlSite controlSite;//from  www  .jav a2s .c o m
    try {
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer");
        controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        return;
    }

    // IWebBrowser
    final OleAutomation webBrowser = new OleAutomation(controlSite);

    // When the document is loaded, access the document object for the new
    // page
    // and evalute expression using Script.
    int DownloadComplete = 104;
    controlSite.addEventListener(DownloadComplete, new OleListener() {
        public void handleEvent(OleEvent event) {
            int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[] { "Document" });
            if (htmlDocumentID == null)
                return;
            Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]);
            if (pVarResult == null || pVarResult.getType() == 0)
                return;
            // IHTMLDocument2
            OleAutomation htmlDocument = null;
            try {
                htmlDocument = pVarResult.getAutomation();
                pVarResult.dispose();

                int[] scriptID = htmlDocument.getIDsOfNames(new String[] { "Script" });
                if (scriptID == null)
                    return;
                pVarResult = htmlDocument.getProperty(scriptID[0]);
                if (pVarResult == null || pVarResult.getType() == 0)
                    return;
                OleAutomation htmlWindow = null;
                try {
                    // IHTMLWindow2
                    htmlWindow = pVarResult.getAutomation();
                    pVarResult.dispose();
                    int[] evaluateID = htmlWindow.getIDsOfNames(new String[] { "evaluate" });
                    if (evaluateID == null)
                        return;
                    String expression = "5+Math.sin(9)";
                    Variant[] rgvarg = new Variant[] { new Variant(expression) };
                    pVarResult = htmlWindow.invoke(evaluateID[0], rgvarg, null);
                    if (pVarResult == null || pVarResult.getType() == 0)
                        return;
                    System.out.println(expression + " =" + pVarResult.getString());
                } finally {
                    htmlWindow.dispose();
                }
            } finally {
                htmlDocument.dispose();
            }
        }
    });

    // Navigate to a web site
    int[] ids = webBrowser.getIDsOfNames(new String[] { "Navigate", "URL" });
    Variant[] rgvarg = new Variant[] { new Variant(
            "http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.html") };
    int[] rgdispidNamedArgs = new int[] { ids[1] };
    webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    // Remember to release OleAutomation Object
    webBrowser.dispose();
    display.dispose();

}

From source file:Snippet81.java

public static void main(String[] args) {

    if (args.length == 0) {
        System.out.println("Usage: java Main <program id>");
        return;//  ww w .ja v a 2  s  .  co  m
    }

    String progID = args[0];

    Shell shell = new Shell();

    OleFrame frame = new OleFrame(shell, SWT.NONE);
    OleControlSite site = null;
    OleAutomation auto = null;
    try {
        site = new OleControlSite(frame, SWT.NONE, progID);
        auto = new OleAutomation(site);
    } catch (SWTException ex) {
        System.out.println("Unable to open type library for " + progID);
        return;
    }

    TYPEATTR typeattr = auto.getTypeInfoAttributes();
    if (typeattr != null) {
        if (typeattr.cFuncs > 0)
            System.out.println("Functions for " + progID + " :\n");
        for (int i = 0; i < typeattr.cFuncs; i++) {
            OleFunctionDescription data = auto.getFunctionDescription(i);
            String argList = "";
            int firstOptionalArgIndex = data.args.length - data.optionalArgCount;
            for (int j = 0; j < data.args.length; j++) {
                argList += "[";
                if (j >= firstOptionalArgIndex)
                    argList += "optional, ";
                argList += getDirection(data.args[j].flags) + "] " + getTypeName(data.args[j].type) + " "
                        + data.args[j].name;
                if (j < data.args.length - 1)
                    argList += ", ";
            }
            System.out.println(getInvokeKind(data.invokeKind) + " (id = " + data.id + ") : "
                    + "\n\tSignature   : " + getTypeName(data.returnType) + " " + data.name + "(" + argList
                    + ")" + "\n\tDescription : " + data.documentation + "\n\tHelp File   : " + data.helpFile
                    + "\n");
        }

        if (typeattr.cVars > 0)
            System.out.println("\n\nVariables for " + progID + " :\n");
        for (int i = 0; i < typeattr.cVars; i++) {
            OlePropertyDescription data = auto.getPropertyDescription(i);
            System.out.println("PROPERTY (id = " + data.id + ") :" + "\n\tName : " + data.name + "\n\tType : "
                    + getTypeName(data.type) + "\n");
        }
    }

    auto.dispose();
    shell.dispose();

}

From source file:org.eclipse.swt.snippets.Snippet187.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 187");
    shell.setLayout(new FillLayout());
    OleControlSite controlSite;//ww w.j av  a 2  s  .  c o  m
    try {
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer");
        controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        display.dispose();
        return;
    }

    // IWebBrowser
    final OleAutomation webBrowser = new OleAutomation(controlSite);

    // When the document is loaded, access the document object for the new page
    // and evalute expression using Script.
    int DownloadComplete = 104;
    controlSite.addEventListener(DownloadComplete, new OleListener() {
        @Override
        public void handleEvent(OleEvent event) {
            int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[] { "Document" });
            if (htmlDocumentID == null)
                return;
            Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]);
            if (pVarResult == null || pVarResult.getType() == 0)
                return;
            //IHTMLDocument2
            OleAutomation htmlDocument = null;
            try {
                htmlDocument = pVarResult.getAutomation();
                pVarResult.dispose();

                int[] scriptID = htmlDocument.getIDsOfNames(new String[] { "Script" });
                if (scriptID == null)
                    return;
                pVarResult = htmlDocument.getProperty(scriptID[0]);
                if (pVarResult == null || pVarResult.getType() == 0)
                    return;
                OleAutomation htmlWindow = null;
                try {
                    //IHTMLWindow2
                    htmlWindow = pVarResult.getAutomation();
                    pVarResult.dispose();
                    int[] evaluateID = htmlWindow.getIDsOfNames(new String[] { "evaluate" });
                    if (evaluateID == null)
                        return;
                    String expression = "5+Math.sin(9)";
                    Variant[] rgvarg = new Variant[] { new Variant(expression) };
                    pVarResult = htmlWindow.invoke(evaluateID[0], rgvarg, null);
                    if (pVarResult == null || pVarResult.getType() == 0)
                        return;
                    System.out.println(expression + " =" + pVarResult.getString());
                } finally {
                    htmlWindow.dispose();
                }
            } finally {
                htmlDocument.dispose();
            }
        }
    });

    // Navigate to a web site
    int[] ids = webBrowser.getIDsOfNames(new String[] { "Navigate", "URL" });
    Variant[] rgvarg = new Variant[] { new Variant(
            "http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.html") };
    int[] rgdispidNamedArgs = new int[] { ids[1] };
    webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    //Remember to release OleAutomation Object
    webBrowser.dispose();
    display.dispose();

}

From source file:org.eclipse.swt.snippets.Snippet305.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Excel Sheet Selection Example");
    shell.setLayout(new FillLayout());
    OleAutomation application;//w  w w  .j  a  v a  2s .  co  m
    try {
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        OleControlSite controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Sheet");
        controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);

        OleAutomation excelSheet = new OleAutomation(controlSite);
        int[] dispIDs = excelSheet.getIDsOfNames(new String[] { "Application" });
        Variant pVarResult = excelSheet.getProperty(dispIDs[0]);
        application = pVarResult.getAutomation();
        pVarResult.dispose();
        excelSheet.dispose();

        OleListener listener = new OleListener() {
            @Override
            public void handleEvent(OleEvent e) {
                // SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
                Variant[] args = e.arguments;
                // OleAutomation sheet = args[1].getAutomation(); // Excel.Sheet
                OleAutomation range = args[0].getAutomation(); // Excel.Range
                int[] dispIDs = range.getIDsOfNames(new String[] { "Row" });
                Variant pVarResult = range.getProperty(dispIDs[0]);
                int row = pVarResult.getInt();
                dispIDs = range.getIDsOfNames(new String[] { "Column" });
                pVarResult = range.getProperty(dispIDs[0]);
                int column = pVarResult.getInt();
                range.dispose();
                System.out.println("row=" + row + " column=" + column);
            }
        };
        controlSite.addEventListener(application, IID_AppEvents, SheetSelectionChange, listener);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        display.dispose();
        return;
    }
    shell.setSize(800, 600);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (application != null)
        application.dispose();
    display.dispose();
}

From source file:Snippet123.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    OleControlSite controlSite;//ww w  .  j a va  2  s.  c o m
    try {
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer");
        controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        return;
    }
    shell.open();

    // IWebBrowser
    final OleAutomation webBrowser = new OleAutomation(controlSite);

    // When a new document is loaded, access the document object for the new
    // page.
    int DownloadComplete = 104;
    controlSite.addEventListener(DownloadComplete, new OleListener() {
        public void handleEvent(OleEvent event) {
            int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[] { "Document" });
            if (htmlDocumentID == null)
                return;
            Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]);
            if (pVarResult == null || pVarResult.getType() == 0)
                return;
            // IHTMLDocument2
            OleAutomation htmlDocument = pVarResult.getAutomation();

            // Request to be notified of click, double click and key down
            // events
            EventDispatch myDispatch = new EventDispatch(EventDispatch.onclick);
            IDispatch idispatch = new IDispatch(myDispatch.getAddress());
            Variant dispatch = new Variant(idispatch);
            htmlDocument.setProperty(EventDispatch.onclick, dispatch);

            myDispatch = new EventDispatch(EventDispatch.ondblclick);
            idispatch = new IDispatch(myDispatch.getAddress());
            dispatch = new Variant(idispatch);
            htmlDocument.setProperty(EventDispatch.ondblclick, dispatch);

            myDispatch = new EventDispatch(EventDispatch.onkeydown);
            idispatch = new IDispatch(myDispatch.getAddress());
            dispatch = new Variant(idispatch);
            htmlDocument.setProperty(EventDispatch.onkeydown, dispatch);

            // Remember to release OleAutomation Object
            htmlDocument.dispose();
        }
    });

    // Navigate to a web site
    int[] ids = webBrowser.getIDsOfNames(new String[] { "Navigate", "URL" });
    Variant[] rgvarg = new Variant[] { new Variant("http://www.google.com") };
    int[] rgdispidNamedArgs = new int[] { ids[1] };
    webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs);

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    // Remember to release OleAutomation Object
    webBrowser.dispose();
    display.dispose();

}

From source file:Main.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.out.println("Usage: java Main <program id>");
        return;/*from w w w . j av a  2  s. c  o m*/
    }

    String progID = args[0];

    Shell shell = new Shell();

    OleFrame frame = new OleFrame(shell, SWT.NONE);
    OleControlSite site = null;
    OleAutomation auto = null;
    try {
        site = new OleControlSite(frame, SWT.NONE, progID);
        auto = new OleAutomation(site);
    } catch (SWTException ex) {
        System.out.println("Unable to open type library for " + progID);
        return;
    }

    TYPEATTR typeattr = auto.getTypeInfoAttributes();
    if (typeattr != null) {
        if (typeattr.cFuncs > 0)
            System.out.println("Functions for " + progID + " :\n");
        for (int i = 0; i < typeattr.cFuncs; i++) {
            OleFunctionDescription data = auto.getFunctionDescription(i);
            String argList = "";
            int firstOptionalArgIndex = data.args.length - data.optionalArgCount;
            for (int j = 0; j < data.args.length; j++) {
                argList += "[";
                if (j >= firstOptionalArgIndex)
                    argList += "optional, ";
                argList += getDirection(data.args[j].flags) + "] " + getTypeName(data.args[j].type) + " "
                        + data.args[j].name;
                if (j < data.args.length - 1)
                    argList += ", ";
            }
            System.out.println(getInvokeKind(data.invokeKind) + " (id = " + data.id + ") : "
                    + "\n\tSignature   : " + getTypeName(data.returnType) + " " + data.name + "(" + argList
                    + ")" + "\n\tDescription : " + data.documentation + "\n\tHelp File   : " + data.helpFile
                    + "\n");
        }

        if (typeattr.cVars > 0)
            System.out.println("\n\nVariables for " + progID + " :\n");
        for (int i = 0; i < typeattr.cVars; i++) {
            OlePropertyDescription data = auto.getPropertyDescription(i);
            System.out.println("PROPERTY (id = " + data.id + ") :" + "\n\tName : " + data.name + "\n\tType : "
                    + getTypeName(data.type) + "\n");
        }
    }

    auto.dispose();
    shell.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet81.java

public static void main(String[] args) {

    if (args.length == 0) {
        System.out.println("Usage: java Main <program id>");
        return;// w  w  w  . j  a va 2s . com
    }

    String progID = args[0];

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 81");

    OleFrame frame = new OleFrame(shell, SWT.NONE);
    OleControlSite site = null;
    OleAutomation auto = null;
    try {
        site = new OleControlSite(frame, SWT.NONE, progID);
        auto = new OleAutomation(site);
    } catch (SWTException ex) {
        System.out.println("Unable to open type library for " + progID);
        display.dispose();
        return;
    }

    printTypeInfo(auto);

    auto.dispose();
    shell.dispose();
    display.dispose();

}

From source file:Snippet186.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(2, false));

    final Text text = new Text(shell, SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Button go = new Button(shell, SWT.PUSH);
    go.setText("Go");
    OleFrame oleFrame = new OleFrame(shell, SWT.NONE);
    oleFrame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    OleControlSite controlSite;//  ww  w .ja  va  2s .  co m
    OleAutomation automation;
    try {
        controlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer");
        automation = new OleAutomation(controlSite);
        controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
    } catch (SWTException ex) {
        return;
    }

    final OleAutomation auto = automation;
    go.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            String url = text.getText();
            int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL" });
            int dispIdMember = rgdispid[0];
            Variant[] rgvarg = new Variant[1];
            rgvarg[0] = new Variant(url);
            int[] rgdispidNamedArgs = new int[1];
            rgdispidNamedArgs[0] = rgdispid[1];
            auto.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);
        }
    });

    // Read PostData whenever we navigate to a site that uses it
    int BeforeNavigate2 = 0xfa;
    controlSite.addEventListener(BeforeNavigate2, new OleListener() {
        public void handleEvent(OleEvent event) {
            Variant url = event.arguments[1];
            Variant postData = event.arguments[4];
            if (postData != null) {
                System.out.println("PostData = " + readSafeArray(postData) + ", URL = " + url.getString());
            }
        }
    });

    // Navigate to this web site which uses post data to fill in the text
    // field
    // and put the string "hello world" into the text box
    text.setText("file://" + Snippet186.class.getResource("Snippet186.html").getFile());
    int[] rgdispid = automation.getIDsOfNames(new String[] { "Navigate", "URL", "PostData" });
    int dispIdMember = rgdispid[0];
    Variant[] rgvarg = new Variant[2];
    rgvarg[0] = new Variant(text.getText());
    rgvarg[1] = writeSafeArray("hello world");
    int[] rgdispidNamedArgs = new int[2];
    rgdispidNamedArgs[0] = rgdispid[1];
    rgdispidNamedArgs[1] = rgdispid[2];
    automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}