Issue 49454 - OOoBean: No keyboard input possible
Summary: OOoBean: No keyboard input possible
Status: CLOSED IRREPRODUCIBLE
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Trivial
Target Milestone: ---
Assignee: joachim.lingner
QA Contact: issues@api
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-18 13:26 UTC by joachim.lingner
Modified: 2013-02-24 21:08 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description joachim.lingner 2005-05-18 13:26:02 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();
   }
               
 });
Comment 1 joachim.lingner 2005-05-20 12:38:31 UTC
set new target
Comment 2 joachim.lingner 2005-07-06 11:11:28 UTC
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.
Comment 3 joachim.lingner 2005-07-15 15:59:36 UTC
The problem seems not to be with the Java frame. If always a new OOoBean is
added, everything works fine.
Comment 4 joachim.lingner 2005-07-18 10:28:25 UTC
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();
                            }
                            
                            }
                        });

Comment 5 joachim.lingner 2005-08-11 13:05:34 UTC
.
Comment 6 joachim.lingner 2005-08-22 14:10:44 UTC
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.
Comment 7 joachim.lingner 2005-08-22 14:11:21 UTC
.