Help.
I currently write a java swt(gtk_x86_64) application on OpenSuse.
I need embed the libreoffice(or openoffice) writer window to show some documnets.
I tried many ways that all doe's not working. finally i decided codeing a JNI cpp project set libreoffice writer window's parent to the java swt widget by use the c gtk+-2.0 functions.
Seems it's to be successful, but I get two writer windows, and I only want the embedded one. And they are actually one, if I minimize the outer one, the embedded one will not accept keyboard input, and if I click on the embedded window's menu or toolbar, the minimized outer one will be reactivated.
Below is the code snippet to start libreoffice and set the writer window's parent via JNI:
//omit bootstrap libreoffice and get XComponentLoader object code......
Composite panelParent= new Composite(shell, SWT.EMBEDDED);
XComponent m_xComponent = xCLoader.loadComponentFromURL("private:factory/swriter","_blank" , 0, szEmptyArgs);
XTextDocument xDoc = UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
m_xComponent);
XFrame m_frame= xDoc.getCurrentController().getFrame();
XWindow xWin= m_frame.getContainerWindow();
XSystemDependentWindowPeer xSysDepWinPeer=UnoRuntime.queryInterface(XSystemDependentWindowPeer.class, xWin);
byte[] procID = new byte[0];
Object objLinux=xSysDepWinPeer.getWindowHandle(procID,SystemDependent.SYSTEM_XWINDOW);
SystemDependentXWindow xSysDepWin=(SystemDependentXWindow) objLinux;
// the lparent is swt GtkWidget*
lparent=panelParent.handle;
//the lchild is XLib Window obj
lchild=xSysDepWin.WindowHandle;
long lret= new NativeToolsX11().set_parent_gtk(lparent,lchild);
The following code snippet is the set_parent gtk function in JNI:
JNIEXPORT jlong JNICALL Java_NativeToolsX11_set_1parent_1gtk(JNIEnv *, jobject job, jlong lparent, jlong lchild){
GtkWidget* pParentWidget = (GtkWidget*)((long)lparent);
GdkWindow* pParentWindow = gtk_widget_get_window(pParentWidget);
Window WindowChild=(Window)lchild;
GdkDisplay* gd = gdk_display_get_default();
GdkWindow* pWindowChild= gdk_window_foreign_new_for_display(gd,WindowChild);
gdk_window_reparent(pWindowChild, pParentWindow, 0, 0);}
The following figure is a screenshot:
