Apache OpenOffice (AOO) Bugzilla – Issue 49454
OOoBean: No keyboard input possible
Last modified: 2013-02-24 21:08:37 UTC
When Running a test where the bean is repetedly added and removed to a Java frame, sometimes no keyboard input is possible anymore. Maybe one could force the childwindow (the office window) to set the focus, when it is "reparented", that is, it receives the java window as parent. final OOoBean bean = new OOoBean(); java.awt.Frame frame = new java.awt.Frame("OpenOffice.org Demo"); frame.add(bean, BorderLayout.CENTER); frame.pack(); frame.setSize(600,300); frame.show(); bean.loadFromURL("private:factory/swriter", null); for (int i = 0; i < 100; i++) { bean.releaseSystemWindow(); frame.remove(bean); frame.add(bean, BorderLayout.CENTER); bean.aquireSystemWindow(); } frame.addWindowListener( new WindowAdapter() { public void windowClosing( java.awt.event.WindowEvent e) { try { bean.stopOOoConnection(); } catch (Exception exc) { } ((java.awt.Window)e.getSource()).dispose(); } });
set new target
The bug could also be veryfied with a JDK 1.5.0_3. I attach the class file which can be used to reproduce the bug. Start it with: java -classpath d:\m106pro_jl21bean\program\classes\java_uno.jar;d:\m106pro_jl21bean\program\classes\ridl.jar;d:\m106pro_ jl21bean\program\classes\officebean.jar;d:\m106pro_jl21bean\program\classes\unoil.jar;d:\m106pro_jl21bean\program\classes\jurt.jar;d:\m106pro_jl21bean\program\classes\juh.jar;. OTest The paths to the jar files need to be adapted.
The problem seems not to be with the Java frame. If always a new OOoBean is added, everything works fine.
Calling setFocusable(true) in LocalOfficeWindow.aquireSystemWindow does not help. Also tried this without success: -added private native void setFocus(long hwnd) in LocalOfficeWindow which was called in private synchronized void aquireSystemWindow() In the native part a SetFocus on the child window of the LocalOfficeWindow, which is the office window, is called. Maybe the window must be properly removed from the keyboard focus manager, which is done by java.lang.Component.removeNotify. Because we remove the office window before that code is run, this may cause problems. The idea was to call LocalOfficeWindow.releaseSystemWindow, when the parent is destroyed. That is, when in removeNotify ComponentPeer.dispose is called. I thought then the Window is destroyed and we receive a WM_DESTROY message. Then the code that handles the window and focus management in removeNotify would have been run already. However, in our WindowProc for LocalOfficeWindow we do not receive a WM_DESTROY. Although every time we add the LocalOfficeWindow to a JavaFrame a new native peer is created. I also experimented with calling Components.setEnable, setVisible, requestFocus, but without success. Also calling Frame.add(bean), Frame.remove.bean in the AWT thread did not work: EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue(); q.invokeAndWait( new Runnable() { public void run() { try { bean.releaseSystemWindow(); frame.remove(bean); } catch (Exception e) { e.printStackTrace(); } } });
.
This seems to be a timing problem. When inserting some Thread.sleep calls then the code runs without problems: for (int j = 0; j < 10; j++) { final OOoBean bean = new OOoBean(); java.awt.Frame frame = null; bean.setOOoCallTimeOut(10000); try { frame = new java.awt.Frame("OpenOffice.org Demo"); frame.add(bean, BorderLayout.CENTER); frame.pack(); frame.setSize(600,300); frame.show(); bean.loadFromURL("private:factory/swriter", null); // #1 Thread.sleep(1000); StringBuffer buf = new StringBuffer(1000); for (int i = 0; i < 1; i++) { bean.releaseSystemWindow(); frame.remove(bean); frame.add(bean, BorderLayout.CENTER); bean.aquireSystemWindow(); } } finally { bean.stopOOoConnection(); frame.dispose(); } } } or for (int j = 0; j < 50; j++) { final OOoBean bean = new OOoBean(); final java.awt.Frame frame = new Frame("Openoffice.org"); bean.setOOoCallTimeOut(10000); try { frame.add(bean, BorderLayout.CENTER); frame.pack(); frame.setSize(600,400); frame.show(); bean.loadFromURL("private:factory/swriter", null); frame.validate(); // #1 Thread.sleep(1000); for (; i < 1; i++) { EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue(); q.invokeAndWait( new Runnable() { public void run() { try { bean.releaseSystemWindow(); frame.remove(bean); frame.validate(); } catch (Exception e) { e.printStackTrace(); } } }); // #2 Thread.sleep(1000); q.invokeAndWait( new Runnable() { public void run() { try { frame.add(bean, BorderLayout.CENTER); bean.aquireSystemWindow(); frame.validate(); } catch (Exception e) { e.printStackTrace(); } } }); // #3 Thread.sleep(1000); } } finally { bean.stopOOoConnection(); frame.dispose(); } } } These code samples were taken from the bean/qa/complex/OOoBeanTest.java (test6, test6a). Because the bean uses "no official API for displaying the native window" (there is none) we cannot really make a case here with the Java falks. As long as the work around works we should leave it at that.