how to get word DocumentBeforeSaveEvent with ole listener? [message #1488090] |
Wed, 26 November 2014 09:57 |
Flavio Donze Messages: 211 Registered: July 2009 Location: Switzerland |
Senior Member |
|
|
I'm trying to embed word in my eclipse RCP application. Having problems to save an open editor if CTRL+S is pressed inside of the word application.
I tried the following snipped but even in this (from eclipse separated) snipped I do not get the DocumentBeforeSaveEvent event:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleEvent;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.OleListener;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class WordMain {
final static int DocumentBeforeSaveEvent = 0x00000008;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell, SWT.NONE);
shell.setLayout(new GridLayout());
frame.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
OleControlSite site = new OleControlSite(frame, SWT.NONE, "Word.Document");
OleAutomation doc = new OleAutomation(site);
int[] dispInfo = doc.getIDsOfNames(new String[] { "Application" });
Variant variant = doc.getProperty(dispInfo[0]);
OleAutomation app = variant.getAutomation();
variant.dispose();
OleListener listener = new OleListener() {
@Override
public void handleEvent(OleEvent event) {
System.out.println("DocumentBeforeSave Event, no. params:" + event.arguments.length);
}
};
site.addEventListener(app, DocumentBeforeSaveEvent, listener);
site.doVerb(OLE.OLEIVERB_OPEN);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
app.dispose();
}
}
Snippet source: http://www.eclipse.org/forums/index.php/t/139593/
Maybe "DocumentBeforeSaveEvent" is the wrong eventId and I need some kind of key Listener, listening to CTRL+S?
What I noticed, the embeded word has it's own "save" button (top left) which is always deactivated, even if the word is modified and the should be "dirty". So maybe activating the save button (or save functionality) would then also trigger the "DocumentBeforeSaveEvent" event.
Using MS Word 2010, Java 7.
greets
flavio
Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
|
|
|
Powered by
FUDForum. Page generated in 0.03680 seconds