Kaydet (Commit) 41c07e79 authored tarafından Vladimir Glazounov's avatar Vladimir Glazounov

INTEGRATION: CWS uaa03 (1.3.8); FILE MERGED

2003/05/20 08:46:17 obr 1.3.8.1: #i14623# ComboBox.java Tree.java
COLLAPSED state has been removed from UAA

#109167#,#108096# AccessBridge.java WindowsAccessBridgeAdapter.java AccessibleObjectFactory.java
Replaced the XAccessibleTopWindowMap interface with a jni component that registers at VCL on Windows to retrieve the necessary events for registering popup windows and to extract the HWND for every window opened.

The pure java bridge now uses XTopWindowListener and XExtendedToolkit to retrieve WINDOW_OPENED and WINDOW_CLOSED events.
üst 11be3165
...@@ -59,19 +59,28 @@ package org.openoffice.accessibility; ...@@ -59,19 +59,28 @@ package org.openoffice.accessibility;
import org.openoffice.java.accessibility.*; import org.openoffice.java.accessibility.*;
import com.sun.star.accessibility.XAccessible;
import com.sun.star.accessibility.XAccessibleContext;
import com.sun.star.accessibility.AccessibleRole;
import com.sun.star.uno.*;
import com.sun.star.java.XJavaVM;
import javax.accessibility.*; import javax.accessibility.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListener, java.beans.PropertyChangeListener { public class WindowsAccessBridgeAdapter {
Method registerVirtualFrame; private static Method registerVirtualFrame;
Method revokeVirtualFrame; private static Method revokeVirtualFrame;
Method removePropertyChangeListener;
protected class PopupMenuProxy extends AccessibleContext implements Accessible, AccessibleComponent { private static java.util.Hashtable frameMap;
protected static class PopupMenuProxy extends AccessibleContext implements Accessible, AccessibleComponent {
AccessibleContext menu; AccessibleContext menu;
AccessibleComponent menuComponent;
PopupMenuProxy(AccessibleContext ac) { PopupMenuProxy(AccessibleContext ac) {
menu = ac; menu = ac;
...@@ -87,13 +96,19 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -87,13 +96,19 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
return this; return this;
} }
/** Returns the AccessibleText associated with this object */
public javax.accessibility.AccessibleText getAccessibleText() {
return menu.getAccessibleText();
}
/** Returns the AccessibleContext associated with this object */ /** Returns the AccessibleContext associated with this object */
public javax.accessibility.AccessibleStateSet getAccessibleStateSet() { public javax.accessibility.AccessibleStateSet getAccessibleStateSet() {
return null; return menu.getAccessibleStateSet();
} }
public java.util.Locale getLocale() { public java.util.Locale getLocale() {
return java.util.Locale.getDefault(); return menu.getLocale();
} }
public int getAccessibleIndexInParent() { public int getAccessibleIndexInParent() {
...@@ -117,14 +132,16 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -117,14 +132,16 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
*/ */
public void addFocusListener(java.awt.event.FocusListener fl) { public void addFocusListener(java.awt.event.FocusListener fl) {
menuComponent.addFocusListener(fl);
} }
public void removeFocusListener(java.awt.event.FocusListener fl) { public void removeFocusListener(java.awt.event.FocusListener fl) {
menuComponent.removeFocusListener(fl);
} }
/** Returns the background color of the object */ /** Returns the background color of the object */
public java.awt.Color getBackground() { public java.awt.Color getBackground() {
return null; return menuComponent.getBackground();
} }
public void setBackground(java.awt.Color c) { public void setBackground(java.awt.Color c) {
...@@ -133,54 +150,51 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -133,54 +150,51 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
/** Returns the foreground color of the object */ /** Returns the foreground color of the object */
public java.awt.Color getForeground() { public java.awt.Color getForeground() {
return null; return menuComponent.getForeground();
} }
public void setForeground(java.awt.Color c) { public void setForeground(java.awt.Color c) {
// Not supported by UNO accessibility API menuComponent.setForeground(c);
} }
public java.awt.Cursor getCursor() { public java.awt.Cursor getCursor() {
// Not supported by UNO accessibility API return menuComponent.getCursor();
return null;
} }
public void setCursor(java.awt.Cursor cursor) { public void setCursor(java.awt.Cursor cursor) {
// Not supported by UNO accessibility API menuComponent.setCursor(cursor);
} }
public java.awt.Font getFont() { public java.awt.Font getFont() {
// FIXME return menuComponent.getFont();
return null;
} }
public void setFont(java.awt.Font f) { public void setFont(java.awt.Font f) {
// Not supported by UNO accessibility API menuComponent.setFont(f);
} }
public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { public java.awt.FontMetrics getFontMetrics(java.awt.Font f) {
// FIXME return menuComponent.getFontMetrics(f);
return null;
} }
public boolean isEnabled() { public boolean isEnabled() {
return true; return menuComponent.isEnabled();
} }
public void setEnabled(boolean b) { public void setEnabled(boolean b) {
// Not supported by UNO accessibility API menuComponent.setEnabled(b);
} }
public boolean isVisible() { public boolean isVisible() {
return true; return menuComponent.isVisible();
} }
public void setVisible(boolean b) { public void setVisible(boolean b) {
// Not supported by UNO accessibility API menuComponent.setVisible(b);
} }
public boolean isShowing() { public boolean isShowing() {
return true; return menuComponent.isShowing();
} }
public boolean contains(java.awt.Point p) { public boolean contains(java.awt.Point p) {
...@@ -199,7 +213,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -199,7 +213,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
/** Returns the location of the object on the screen. */ /** Returns the location of the object on the screen. */
public java.awt.Point getLocationOnScreen() { public java.awt.Point getLocationOnScreen() {
if (menu != null) {
Accessible a = menu.getAccessibleChild(0); Accessible a = menu.getAccessibleChild(0);
if (a != null) { if (a != null) {
AccessibleContext ac = a.getAccessibleContext(); AccessibleContext ac = a.getAccessibleContext();
...@@ -207,7 +220,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -207,7 +220,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
return ac.getAccessibleComponent().getLocationOnScreen(); return ac.getAccessibleComponent().getLocationOnScreen();
} }
} }
}
return null; return null;
} }
...@@ -236,7 +248,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -236,7 +248,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
/** Returns the size of this component in the form of a Dimension object */ /** Returns the size of this component in the form of a Dimension object */
public java.awt.Dimension getSize() { public java.awt.Dimension getSize() {
if (menu != null) {
int count = menu.getAccessibleChildrenCount(); int count = menu.getAccessibleChildrenCount();
int width = 0; int height = 0; int width = 0; int height = 0;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
...@@ -252,8 +263,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -252,8 +263,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
} }
return new java.awt.Dimension(width, height); return new java.awt.Dimension(width, height);
} }
return null;
}
/** Resizes this component so that it has width d.width and height d.height */ /** Resizes this component so that it has width d.width and height d.height */
public void setSize(java.awt.Dimension d) { public void setSize(java.awt.Dimension d) {
...@@ -262,7 +271,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -262,7 +271,6 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
/** Returns the Accessible child, if one exists, contained at the local coordinate Point */ /** Returns the Accessible child, if one exists, contained at the local coordinate Point */
public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) {
if (menu != null) {
int count = menu.getAccessibleChildrenCount(); int count = menu.getAccessibleChildrenCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Accessible a = menu.getAccessibleChild(i); Accessible a = menu.getAccessibleChild(i);
...@@ -278,21 +286,24 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -278,21 +286,24 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
} }
} }
} }
}
return null; return null;
} }
public boolean isFocusTraversable() { public boolean isFocusTraversable() {
return true; return menuComponent.isFocusTraversable();
} }
public void requestFocus() { public void requestFocus() {
menuComponent.requestFocus();
} }
} }
protected static native byte[] getProcessID();
protected static native boolean createMapping(long jvmaccess);
// On Windows all native frames must be registered to the access bridge. Therefor // On Windows all native frames must be registered to the access bridge. Therefor
// the bridge exports two methods that we try to find here. // the bridge exports two methods that we try to find here.
public WindowsAccessBridgeAdapter() { protected static void attach(XComponentContext xComponentContext) {
try { try {
Class bridge = Class.forName("com.sun.java.accessibility.AccessBridge"); Class bridge = Class.forName("com.sun.java.accessibility.AccessBridge");
Class[] parameterTypes = { javax.accessibility.Accessible.class, Integer.class }; Class[] parameterTypes = { javax.accessibility.Accessible.class, Integer.class };
...@@ -300,20 +311,25 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -300,20 +311,25 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
if (bridge != null) { if (bridge != null) {
registerVirtualFrame = bridge.getMethod("registerVirtualFrame", parameterTypes); registerVirtualFrame = bridge.getMethod("registerVirtualFrame", parameterTypes);
revokeVirtualFrame = bridge.getMethod("revokeVirtualFrame", parameterTypes); revokeVirtualFrame = bridge.getMethod("revokeVirtualFrame", parameterTypes);
}
// Register PropertyChangeListener to track popup windows // load the native dll
Class monitor = Class.forName("com.sun.java.accessibility.util.AccessibilityEventMonitor"); System.loadLibrary("java_uno_accessbridge");
Class[] monitorParams = { java.beans.PropertyChangeListener.class };
Method addPropertyChangeListener = monitor.getMethod("addPropertyChangeListener", monitorParams);
removePropertyChangeListener = monitor.getMethod("removePropertyChangeListener", monitorParams);
Object[] params = { this }; Object any = xComponentContext.getValueByName("/singletons/com.sun.star.java.theJavaVirtualMachine");
addPropertyChangeListener.invoke(null, params); if (AnyConverter.isObject(any)) {
XJavaVM xJavaVM = (XJavaVM) UnoRuntime.queryInterface(XJavaVM.class,
System.loadLibrary("java_uno_accessbridge"); AnyConverter.toObject(new Type(XJavaVM.class), any));
if (xJavaVM != null) {
any = xJavaVM.getJavaVM(getProcessID());
if (AnyConverter.isLong(any)) {
createMapping(AnyConverter.toLong(any));
frameMap = new java.util.Hashtable();
}
}
}
}
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
System.err.println("ERROR: incompatible AccessBridge found: " + e.getMessage()); System.err.println("ERROR: incompatible AccessBridge found: " + e.getMessage());
...@@ -328,49 +344,71 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -328,49 +344,71 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
// Forward this exception to UNO to indicate that the service will not work correctly. // Forward this exception to UNO to indicate that the service will not work correctly.
throw new com.sun.star.uno.RuntimeException("ClassNotFound exception caught: " + e.getMessage()); throw new com.sun.star.uno.RuntimeException("ClassNotFound exception caught: " + e.getMessage());
} catch(IllegalAccessException e) {
System.err.println("IllegalAccessException caught: " + e.getMessage());
// Forward this exception to UNO to indicate that the service will not work correctly.
throw new com.sun.star.uno.RuntimeException("IllegalAccessException caught: " + e.getMessage());
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
System.err.println("IllegalArgumentException caught: " + e.getMessage()); System.err.println("IllegalArgumentException caught: " + e.getMessage());
// Forward this exception to UNO to indicate that the service will not work correctly. // Forward this exception to UNO to indicate that the service will not work correctly.
throw new com.sun.star.uno.RuntimeException("IllegalArgumentException caught: " + e.getMessage()); throw new com.sun.star.uno.RuntimeException("IllegalArgumentException caught: " + e.getMessage());
} catch(InvocationTargetException e) { } catch(com.sun.star.lang.IllegalArgumentException e) {
System.err.println("InvokationTargetException caught: " + e.getMessage()); System.err.println("UNO IllegalArgumentException caught: " + e.getMessage());
// Forward this exception to UNO to indicate that the service will not work correctly. // Forward this exception to UNO to indicate that the service will not work correctly.
throw new com.sun.star.uno.RuntimeException("InvokationTargetException caught: " + e.getMessage()); throw new com.sun.star.uno.RuntimeException("UNO IllegalArgumentException caught: " + e.getMessage());
} }
} }
/** Registers a native frame at the Java AccessBridge for Windows */ protected static boolean isAttached() {
protected void registerFrame(Integer handle, Accessible a) { return frameMap != null;
Object[] args = { a, handle };
if (Build.DEBUG) {
System.err.println("Native frame " + handle + " has been opened");
} }
protected static Accessible getAccessibleWrapper(XAccessible xAccessible) {
Accessible a = null;
try { try {
registerVirtualFrame.invoke(null, args); XAccessibleContext xAccessibleContext = xAccessible.getAccessibleContext();
} catch(IllegalAccessException e) { if (xAccessibleContext != null) {
System.err.println("IllegalAccessException caught: " + e.getMessage()); switch (xAccessibleContext.getAccessibleRole()) {
} catch(IllegalArgumentException e) { case AccessibleRole.POPUP_MENU:
System.err.println("IllegalArgumentException caught: " + e.getMessage()); case AccessibleRole.LIST:
} catch(InvocationTargetException e) { a = (Accessible) AccessibleObjectFactory.getAccessibleComponent(xAccessible);
System.err.println("InvokationTargetException caught: " + e.getMessage()); break;
case AccessibleRole.MENU:
Accessible tmp = (Accessible) AccessibleObjectFactory.getAccessibleComponent(xAccessible);
if (tmp != null) {
AccessibleContext ac = tmp.getAccessibleContext();
if (ac != null) {
a = new PopupMenuProxy(ac);
}
}
break;
default:
a = (Accessible) AccessBridge.getTopWindow(xAccessible);
break;
} }
} }
} catch (com.sun.star.uno.RuntimeException e) {
}
return a;
}
/** Registers a popup window at the Java AccessBridge for Windows */ /** Registers a native frame at the Java AccessBridge for Windows */
protected void registerPopup(Integer handle, Accessible a) { public static void registerTopWindow(int handle, XAccessible xAccessible) {
Object[] args = { a, handle }; Integer hwnd = new Integer(handle);
if (! frameMap.contains(hwnd) ) {
if (Build.DEBUG) { if (Build.DEBUG) {
System.err.println("Popup menu " + handle + " has been opened"); System.err.println("Native frame " + hwnd + " has been opened");
}
Accessible a = getAccessibleWrapper(xAccessible);
if (a != null) {
Object[] args = { a, hwnd };
frameMap.put(hwnd, a);
if (Build.DEBUG) {
System.err.println("registering native frame " + hwnd);
} }
try { try {
...@@ -383,123 +421,30 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen ...@@ -383,123 +421,30 @@ public class WindowsAccessBridgeAdapter implements java.awt.event.AWTEventListen
System.err.println("InvokationTargetException caught: " + e.getMessage()); System.err.println("InvokationTargetException caught: " + e.getMessage());
} }
} }
protected void handleWindowOpened(Accessible a) {
if (a != null) {
AccessibleContext ac = a.getAccessibleContext();
if (ac != null) {
int hwnd = getHWNDFromComponent(ac.getAccessibleComponent());
if (hwnd > 0) {
registerFrame(new Integer(hwnd), a);
}
}
} }
} }
public void eventDispatched(java.awt.AWTEvent evt) { /** Revokes a native frame at the Java AccessBridge for Windows */
switch (evt.getID()) { public static void revokeTopWindow(int handle, XAccessible xAccessible) {
case java.awt.event.WindowEvent.WINDOW_OPENED: Integer hwnd = new Integer(handle);
handleWindowOpened((Accessible) evt.getSource());
break;
case java.awt.event.WindowEvent.WINDOW_CLOSED:
if (Build.DEBUG) {
System.err.println("retrieved WINDOW_CLOSED");
}
break;
default:
break;
}
}
protected void handlePopupMenuOpened(AccessibleContext menu) { Accessible a = (Accessible) frameMap.remove(hwnd);
try { if (a != null) {
PopupMenuProxy pmp = new PopupMenuProxy(menu); Object[] args = { a, hwnd };
int hwnd = getHWNDFromComponent(pmp.getAccessibleComponent());
if (hwnd != 0) {
registerPopup(new Integer(hwnd), pmp);
}
} catch (NullPointerException e) {
} catch (IndexOutOfBoundsException e) {
}
}
/** This method gets called when a bound property is changed. */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(AccessibleContext.ACCESSIBLE_STATE_PROPERTY)) {
AccessibleContext ac = null;
if (evt.getSource() instanceof AccessibleContext) {
ac = (AccessibleContext) evt.getSource();
} else if (evt.getSource() instanceof Accessible) {
ac = ((Accessible) evt.getSource()).getAccessibleContext();
} else {
// This should never happen
return;
}
// Track ComboBox popups by VISIBLE state of their lists ..
if (ac.getAccessibleRole().equals(AccessibleRole.LIST)) {
Accessible pa = ac.getAccessibleParent();
if (pa != null) {
AccessibleContext pac = pa.getAccessibleContext();
if (pac != null && pac.getAccessibleRole().equals(AccessibleRole.COMBO_BOX)) {
if (evt.getOldValue() instanceof AccessibleState) {
AccessibleState as = (AccessibleState) evt.getOldValue();
if (as.equals(AccessibleState.VISIBLE)) {
if (Build.DEBUG) {
System.err.println("ComboBox popup closed");
}
}
}
if (evt.getNewValue() instanceof AccessibleState) {
AccessibleState as = (AccessibleState) evt.getNewValue();
if (as.equals(AccessibleState.VISIBLE)) {
if (Build.DEBUG) {
System.err.println("ComboBox popup opened");
}
}
}
}
}
}
// Track Menu popups by SELECTED state changes ..
if (ac.getAccessibleRole().equals(AccessibleRole.MENU)) {
if (evt.getOldValue() instanceof AccessibleState) {
AccessibleState as = (AccessibleState) evt.getOldValue();
if (as.equals(AccessibleState.SELECTED)) {
if (Build.DEBUG) { if (Build.DEBUG) {
System.err.println("Popup menu closed"); System.err.println("revoking native frame " + hwnd);
}
}
}
if (evt.getNewValue() instanceof AccessibleState) {
AccessibleState as = (AccessibleState) evt.getNewValue();
if (as.equals(AccessibleState.SELECTED)) {
handlePopupMenuOpened(ac);
}
}
}
}
} }
protected static int getHWNDFromComponent(AccessibleComponent ac) { try {
if (ac != null) { revokeVirtualFrame.invoke(null, args);
java.awt.Point p = ac.getLocationOnScreen(); } catch(IllegalAccessException e) {
if (p != null) { System.err.println("IllegalAccessException caught: " + e.getMessage());
java.awt.Dimension d = ac.getSize(); } catch(IllegalArgumentException e) {
if (d != null) { System.err.println("IllegalArgumentException caught: " + e.getMessage());
return getHWNDFromPoint(p.x + (d.width % 2), p.y + (d.height % 2)); } catch(InvocationTargetException e) {
} System.err.println("InvokationTargetException caught: " + e.getMessage());
}
} }
return -1;
} }
protected static native int getHWNDFromPoint(int x, int y);
protected void finalize() throws Throwable {
Object[] params = { this };
removePropertyChangeListener.invoke(null, params);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment