SF 1702604 - alpha prototype for activeXInvocationProxy event callbacks
This commit is contained in:
@@ -74,13 +74,14 @@ public class ExcelEventTest extends InvocationProxy {
|
||||
}
|
||||
|
||||
/**
|
||||
* dummy consturctor to create an InvocationProxy that wraps nothing
|
||||
* Constructor so we can create an instance that implements invoke()
|
||||
*/
|
||||
public ExcelEventTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* override the invoke method to log all the events
|
||||
* Override the invoke method to log all the events so that we don't have to
|
||||
* implement all of the specific events.
|
||||
*/
|
||||
public Variant invoke(String methodName, Variant targetParameter[]) {
|
||||
System.out.println("Received event from Windows program" + methodName);
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.jacob.test.events;
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
/**
|
||||
* This test runs fine against jdk.1.5.0_05 and kills the VM
|
||||
* under any variant of 1.4.
|
||||
* This test runs fine against jdk 1.4 and 1.5
|
||||
*
|
||||
* This demonstrates the new event handling code in jacob 1.7
|
||||
* This example will open up IE and print out some of the events
|
||||
@@ -66,7 +65,7 @@ class IETestThread extends Thread
|
||||
|
||||
System.out.println("IETestThread: About to hookup event listener");
|
||||
IEEvents ieE = new IEEvents();
|
||||
new DispatchEvents((Dispatch) ie, ieE,"InternetExplorer.Application.1");
|
||||
new DispatchEvents(ie, ieE,"InternetExplorer.Application.1");
|
||||
System.out.println("IETestThread: Did hookup event listener");
|
||||
/// why is this here? Was there some other code here in the past?
|
||||
Variant optional = new Variant();
|
||||
@@ -110,7 +109,8 @@ class IETestThread extends Thread
|
||||
}
|
||||
|
||||
/**
|
||||
* the events class must be publicly accessable for reflection to work
|
||||
* The events class must be publicly accessable for reflection to work.
|
||||
* The list of available events is located at http://msdn2.microsoft.com/en-us/library/aa768280.aspx
|
||||
*/
|
||||
public class IEEvents
|
||||
{
|
||||
@@ -134,6 +134,10 @@ public class IEEvents
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): DownloadComplete "+args.length);
|
||||
}
|
||||
|
||||
public void NavigateError(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): NavigateError "+args.length);
|
||||
}
|
||||
|
||||
public void NavigateComplete2(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): NavigateComplete "+args.length);
|
||||
}
|
||||
@@ -179,6 +183,10 @@ public class IEEvents
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): PropertyChange "+args.length);
|
||||
}
|
||||
|
||||
public void SetSecureLockIcon(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): setSecureLockIcon "+args.length);
|
||||
}
|
||||
|
||||
public void StatusTextChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): StatusTextChange "+args.length);
|
||||
}
|
||||
@@ -186,6 +194,10 @@ public class IEEvents
|
||||
public void TitleChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): TitleChange "+args.length);
|
||||
}
|
||||
|
||||
public void WindowClosing(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): WindowClosing "+args.length);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
207
unittest/com/jacob/test/events/IETestActiveXProxy.java
Normal file
207
unittest/com/jacob/test/events/IETestActiveXProxy.java
Normal file
@@ -0,0 +1,207 @@
|
||||
package com.jacob.test.events;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.activeX.ActiveXDispatchEvents;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
/**
|
||||
* This test runs fine against jdk 1.4 and 1.5
|
||||
*
|
||||
* This demonstrates the new event handling code in jacob 1.7
|
||||
* This example will open up IE and print out some of the events
|
||||
* it listens to as it havigates to web sites.
|
||||
* contributed by Niels Olof Bouvin mailto:n.o.bouvin@daimi.au.dk
|
||||
* and Henning Jae jehoej@daimi.au.dk
|
||||
* <p>
|
||||
* May need to run with some command line options (including from inside Eclipse).
|
||||
* Look in the docs area at the Jacob usage document for command line options.
|
||||
*/
|
||||
|
||||
class IETestActiveXProxy
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// this line starts the pump but it runs fine without it
|
||||
ComThread.startMainSTA();
|
||||
// remove this line and it dies
|
||||
///ComThread.InitMTA(true);
|
||||
IETestActiveProxyThread aThread = new IETestActiveProxyThread();
|
||||
aThread.start();
|
||||
while (aThread.isAlive()){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// doen with the sleep
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("Main: Thread quit, about to quit main sta in thread "
|
||||
+Thread.currentThread().getName());
|
||||
// this line only does someting if startMainSTA() was called
|
||||
ComThread.quitMainSTA();
|
||||
System.out.println("Main: did quit main sta in thread "
|
||||
+Thread.currentThread().getName());
|
||||
}
|
||||
}
|
||||
|
||||
class IETestActiveProxyThread extends Thread
|
||||
{
|
||||
public static boolean quitHandled = false;
|
||||
|
||||
public IETestActiveProxyThread(){
|
||||
super();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
// this used to be 5 seconds but sourceforge is slow
|
||||
int delay = 5000; // msec
|
||||
// paired with statement below that blows up
|
||||
ComThread.InitMTA();
|
||||
ActiveXComponent ie = new ActiveXComponent("InternetExplorer.Application");
|
||||
try {
|
||||
Dispatch.put(ie, "Visible", new Variant(true));
|
||||
Dispatch.put(ie, "AddressBar", new Variant(true));
|
||||
System.out.println("IETestActiveProxyThread: " + Dispatch.get(ie, "Path"));
|
||||
Dispatch.put(ie, "StatusText", new Variant("My Status Text"));
|
||||
|
||||
System.out.println("IETestActiveProxyThread: About to hookup event listener");
|
||||
IEEventsActiveProxy ieE = new IEEventsActiveProxy();
|
||||
new ActiveXDispatchEvents(ie, ieE,"InternetExplorer.Application.1");
|
||||
System.out.println("IETestActiveProxyThread: Did hookup event listener");
|
||||
/// why is this here? Was there some other code here in the past?
|
||||
Variant optional = new Variant();
|
||||
optional.putNoParam();
|
||||
|
||||
System.out.println("IETestActiveProxyThread: About to call navigate to sourceforge");
|
||||
Dispatch.call(ie, "Navigate", new Variant("http://sourceforge.net/projects/jacob-project"));
|
||||
System.out.println("IETestActiveProxyThread: Did call navigate to sourceforge");
|
||||
try { Thread.sleep(delay); } catch (Exception e) {}
|
||||
System.out.println("IETestActiveProxyThread: About to call navigate to yahoo");
|
||||
Dispatch.call(ie, "Navigate", new Variant("http://groups.yahoo.com/group/jacob-project"));
|
||||
System.out.println("IETestActiveProxyThread: Did call navigate to yahoo");
|
||||
try { Thread.sleep(delay); } catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Throwable re){
|
||||
re.printStackTrace();
|
||||
} finally {
|
||||
System.out.println("IETestActiveProxyThread: About to send Quit");
|
||||
ie.invoke("Quit", new Variant[] {});
|
||||
System.out.println("IETestActiveProxyThread: Did send Quit");
|
||||
}
|
||||
// this blows up when it tries to release a DispatchEvents object
|
||||
// I think this is because there is still one event we should get back
|
||||
// "OnQuit" that will came after we have released the thread pool
|
||||
// this is probably messed up because DispatchEvent object will have been
|
||||
// freed before the callback
|
||||
// commenting out ie.invoke(quit...) causes this to work without error
|
||||
// this code tries to wait until the quit has been handled but that doesn't work
|
||||
System.out.println("IETestActiveProxyThread: Waiting until we've received the quit callback");
|
||||
while (!quitHandled){
|
||||
try { Thread.sleep(delay/5);} catch (InterruptedException e) {}
|
||||
}
|
||||
System.out.println("IETestActiveProxyThread: Received the quit callback");
|
||||
// wait a little while for it to end
|
||||
//try {Thread.sleep(delay); } catch (InterruptedException e) {}
|
||||
System.out.println("IETestActiveProxyThread: about to call ComThread.Release in thread " +
|
||||
Thread.currentThread().getName());
|
||||
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* The events class must be publicly accessable for reflection to work.
|
||||
* The list of available events is located at http://msdn2.microsoft.com/en-us/library/aa768280.aspx
|
||||
*/
|
||||
public class IEEventsActiveProxy
|
||||
{
|
||||
public void BeforeNavigate2(Dispatch pDisp, String url, Integer flags,
|
||||
String targetFrameName, Variant postData, String headers, Boolean cancel) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): BeforeNavigate2 "+url);
|
||||
}
|
||||
|
||||
public void CommandStateChange(Integer command, Boolean enable) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): CommandStateChange "+command);
|
||||
}
|
||||
|
||||
public void DocumentComplete(Dispatch pDisp, String url) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): DocumentComplete "+url);
|
||||
}
|
||||
|
||||
public void DownloadBegin() {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): DownloadBegin ");
|
||||
}
|
||||
|
||||
public void DownloadComplete() {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): DownloadComplete ");
|
||||
}
|
||||
|
||||
public void NavigateComplete2(Dispatch pDisp, String url) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): NavigateComplete "+url);
|
||||
}
|
||||
|
||||
public void NavigateError(Dispatch pDispatch, String url, String targetFrameName, Integer statusCode, Boolean Cancel) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): NavigateError "+statusCode);
|
||||
}
|
||||
|
||||
public void NewWindow2(Dispatch pDisp, Boolean cancel) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): NewWindow2 "+pDisp);
|
||||
}
|
||||
|
||||
public void OnFullScreen(Boolean fullScreen) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): OnFullScreen "+fullScreen);
|
||||
}
|
||||
|
||||
public void OnMenuBar(Boolean menuBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): OnMenuBar "+menuBar);
|
||||
}
|
||||
|
||||
public void OnQuit() {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): OnQuit ");
|
||||
IETestActiveProxyThread.quitHandled = true;
|
||||
}
|
||||
|
||||
public void OnStatusBar(Boolean statusBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): OnStatusBar "+statusBar);
|
||||
}
|
||||
|
||||
public void OnTheaterMode(Boolean theaterMode) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): OnTheaterMode "+theaterMode);
|
||||
}
|
||||
|
||||
public void OnToolBar(Boolean onToolBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): OnToolBar "+onToolBar);
|
||||
}
|
||||
|
||||
public void OnVisible(Boolean onVisible) {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): onVisible "+ onVisible);
|
||||
}
|
||||
|
||||
public void ProgressChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): ProgressChange ");
|
||||
}
|
||||
|
||||
public void PropertyChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): PropertyChange ");
|
||||
}
|
||||
|
||||
public void SetSecureLockIcon(Integer secureLockIcon) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): setSecureLockIcon "+secureLockIcon);
|
||||
}
|
||||
|
||||
public void StatusTextChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): StatusTextChange ");
|
||||
}
|
||||
|
||||
public void TitleChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("+Thread.currentThread().getName()+"): TitleChange ");
|
||||
}
|
||||
|
||||
public void WindowClosing(Boolean isChildWindow) {
|
||||
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): WindowClosing "+isChildWindow);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,13 +69,13 @@ public class WordEventTest extends InvocationProxy {
|
||||
}
|
||||
|
||||
/**
|
||||
* dummy consturctor to create an InvocationProxy that wraps nothing
|
||||
* Constructor so we can create an instance that implements invoke()
|
||||
*/
|
||||
public WordEventTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* override the invoke method to loga ll the events
|
||||
* override the invoke() method to log all the events without writing a bunch of code
|
||||
*/
|
||||
public Variant invoke(String methodName, Variant targetParameter[]) {
|
||||
System.out.println("Received event from Windows program" + methodName);
|
||||
|
||||
Reference in New Issue
Block a user