diff options
Diffstat (limited to 'accessibility/bridge/org/openoffice/java')
47 files changed, 11669 insertions, 0 deletions
diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AbstractButton.java b/accessibility/bridge/org/openoffice/java/accessibility/AbstractButton.java new file mode 100644 index 000000000000..be7b72df8732 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AbstractButton.java @@ -0,0 +1,176 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleState; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +/** + */ +public abstract class AbstractButton extends Component { + + protected AbstractButton(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + protected abstract class AccessibleAbstractButton extends AccessibleUNOComponent + implements javax.accessibility.AccessibleAction { + + /** + * Though the class is abstract, this should be called by all sub-classes + */ + protected AccessibleAbstractButton() { + super(); + } + + /* + * AccessibleContext + */ + + /** Gets the AccessibleAction associated with this object that supports one or more actions */ + public javax.accessibility.AccessibleAction getAccessibleAction() { + return this; + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleText getAccessibleText() { + + if (disposed) + return null; + + try { + XAccessibleText unoAccessibleText = (XAccessibleText) + UnoRuntime.queryInterface(XAccessibleText.class,unoAccessibleComponent); + if (unoAccessibleText != null) { + return new AccessibleTextImpl(unoAccessibleText); + } else { + return null; + } + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the relation set of this object */ + public javax.accessibility.AccessibleRelationSet getAccessibleRelationSet() { + try { + XAccessibleRelationSet unoAccessibleRelationSet = unoAccessibleContext.getAccessibleRelationSet(); + + if (unoAccessibleRelationSet == null) { + return null; + } + + javax.accessibility.AccessibleRelationSet relationSet = new javax.accessibility.AccessibleRelationSet(); + int count = unoAccessibleRelationSet.getRelationCount(); + + for (int i = 0; i < count; i++) { + AccessibleRelation unoAccessibleRelation = unoAccessibleRelationSet.getRelation(i); + + switch (unoAccessibleRelation.RelationType) { + case AccessibleRelationType.MEMBER_OF: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.MEMBER_OF, + getAccessibleComponents( + unoAccessibleRelation.TargetSet))); + break; + + case AccessibleRelationType.LABELED_BY: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.LABELED_BY, + getAccessibleComponents( + unoAccessibleRelation.TargetSet))); + break; + default: + break; + } + } + + return relationSet; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /* + * AccessibleAction + */ + + /** Performs the specified Action on the object */ + public boolean doAccessibleAction(int param) { + if (param == 0) { + // HACK: this action might open a modal dialog and therefor block + // until the dialog is closed. In case of this thread being the + // AWT EventDispatcherThread this means, the opened dialog will + // not be accessible, so deligate this request to another thread. + if (java.awt.EventQueue.isDispatchThread()) { + Thread t = new Thread () { + public void run() { + AbstractButton.AccessibleAbstractButton.this.doAccessibleAction(0); + } + }; + t.start(); + return true; + } else { + // Actions of MenuItems may also be performed if the item is not + // visible, so just try .. + try { + XAccessibleContext xAccessibleContext = unoAccessibleContext; + if (xAccessibleContext != null) { + // Query for XAccessibleAction interface + XAccessibleAction xAccessibleAction = (XAccessibleAction) + UnoRuntime.queryInterface(XAccessibleAction.class, xAccessibleContext); + + if (xAccessibleAction != null) { + return xAccessibleAction.doAccessibleAction(0); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + } + + return false; + } + + /** Returns a description of the specified action of the object */ + public java.lang.String getAccessibleActionDescription(int param) { + return javax.swing.UIManager.getString("AbstractButton.clickText"); + } + + /** Returns the number of accessible actions available in this object */ + public int getAccessibleActionCount() { + return 1; + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleActionImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleActionImpl.java new file mode 100644 index 000000000000..e4905752d833 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleActionImpl.java @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.XAccessibleAction; + +/** The AccessibleActionWrapper maps the calls to the java AccessibleAction interface + * to the corresponding methods of the UNO XAccessibleAction interface. + */ +public class AccessibleActionImpl implements javax.accessibility.AccessibleAction { + + protected XAccessibleAction unoObject; + + /** Creates new AccessibleActionWrapper */ + public AccessibleActionImpl(XAccessibleAction xAccessibleAction) { + unoObject = xAccessibleAction; + } + + public boolean doAccessibleAction(int param) { + try { + return unoObject.doAccessibleAction(param); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + public java.lang.String getAccessibleActionDescription(int param) { + try { + return unoObject.getAccessibleActionDescription(param); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public int getAccessibleActionCount() { + try { + return unoObject.getAccessibleActionCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleComponentImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleComponentImpl.java new file mode 100644 index 000000000000..5bac982756a2 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleComponentImpl.java @@ -0,0 +1,233 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.AccessibleStateType; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleComponent; +// import com.sun.star.accessibility.XAccessibleExtendedComponent; +import com.sun.star.uno.UnoRuntime; + +public class AccessibleComponentImpl implements javax.accessibility.AccessibleComponent { + + protected XAccessibleComponent unoObject; +// protected XAccessibleExtendedComponent unoAccessibleExtendedComponent = null; + + /** Creates new AccessibleComponentImpl */ + public AccessibleComponentImpl(XAccessibleComponent xAccessibleComponent) { + unoObject = xAccessibleComponent; + } + + protected boolean hasState(short state) { + try { + XAccessibleContext unoAccessibleContext = (XAccessibleContext) + UnoRuntime.queryInterface(XAccessibleContext.class, unoObject); + // All UNO accessibility implementations must support XAccessibleContext + // and return a valid XAccessibleStateSet .. + return unoAccessibleContext.getAccessibleStateSet().contains(state); + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } catch (java.lang.NullPointerException e) { + System.err.println("XAccessibleContext unsupported or no XAccessibleStateSet returned."); + return false; + } + } + + /* + * XAccessibleComponent + */ + + /** Returns the background color of the object */ + public java.awt.Color getBackground() { + try { + return new java.awt.Color(unoObject.getBackground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setBackground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + /** Returns the foreground color of the object */ + public java.awt.Color getForeground() { + try { + return new java.awt.Color(unoObject.getForeground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setForeground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + public java.awt.Cursor getCursor() { + // Not supported by UNO accessibility API + return null; + } + + public void setCursor(java.awt.Cursor cursor) { + // Not supported by UNO accessibility API + } + + public java.awt.Font getFont() { + // FIXME + return null; + } + + public void setFont(java.awt.Font f) { + // Not supported by UNO accessibility API + } + + public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { + // FIXME + return null; + } + + public boolean isEnabled() { + return hasState(AccessibleStateType.ENABLED); + } + + public void setEnabled(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isVisible() { + return hasState(AccessibleStateType.VISIBLE); + } + + public void setVisible(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isShowing() { + return hasState(AccessibleStateType.SHOWING); + } + + public boolean contains(java.awt.Point p) { + try { + return unoObject.containsPoint(new com.sun.star.awt.Point(p.x, p.y)); + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Returns the location of the object on the screen. */ + public java.awt.Point getLocationOnScreen() { + try { + com.sun.star.awt.Point unoPoint = unoObject.getLocationOnScreen(); + return new java.awt.Point(unoPoint.X, unoPoint.Y); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the location of this component in the form of a point specifying the component's top-left corner */ + public java.awt.Point getLocation() { + try { + com.sun.star.awt.Point unoPoint = unoObject.getLocation(); + return new java.awt.Point( unoPoint.X, unoPoint.Y ); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves this component to a new location */ + public void setLocation(java.awt.Point p) { + // Not supported by UNO accessibility API + } + + /** Gets the bounds of this component in the form of a Rectangle object */ + public java.awt.Rectangle getBounds() { + try { + com.sun.star.awt.Rectangle unoRect = unoObject.getBounds(); + return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves and resizes this component to conform to the new bounding rectangle r */ + public void setBounds(java.awt.Rectangle r) { + // Not supported by UNO accessibility API + } + + /** Returns the size of this component in the form of a Dimension object */ + public java.awt.Dimension getSize() { + try { + com.sun.star.awt.Size unoSize = unoObject.getSize(); + return new java.awt.Dimension(unoSize.Width, unoSize.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Resizes this component so that it has width d.width and height d.height */ + public void setSize(java.awt.Dimension d) { + // Not supported by UNO accessibility API + } + + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + // Not supported by this implementation + return null; + } + + public boolean isFocusTraversable() { + return hasState(AccessibleStateType.FOCUSABLE); + } + + public void requestFocus() { + unoObject.grabFocus(); + } + + /** + * Adds the specified focus listener to receive focus events from + * this component when this component gains input focus. + * If listener <code>l</code> is <code>null</code>, + * no exception is thrown and no action is performed. + */ + + public void addFocusListener(java.awt.event.FocusListener l) { + // Not supported by this implementation + } + + /** + * Removes the specified focus listener so that it no longer + * receives focus events from this component. This method performs + * no function, nor does it throw an exception, if the listener + * specified by the argument was not previously added to this component. + * If listener <code>l</code> is <code>null</code>, + * no exception is thrown and no action is performed. + */ + + public void removeFocusListener(java.awt.event.FocusListener l) { + // Not supported by this implementation + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleEditableTextImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleEditableTextImpl.java new file mode 100644 index 000000000000..4863b560ef71 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleEditableTextImpl.java @@ -0,0 +1,367 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.awt.*; +import com.sun.star.style.*; +import com.sun.star.uno.*; +import com.sun.star.accessibility.AccessibleTextType; +import com.sun.star.accessibility.XAccessibleEditableText; + +import javax.accessibility.AccessibleText; +import javax.swing.text.StyleConstants; + +/** The GenericAccessibleEditableText mapps the calls to the java AccessibleEditableText + * interface to the corresponding methods of the UNO XAccessibleEditableText interface. + */ +public class AccessibleEditableTextImpl extends AccessibleTextImpl implements javax.accessibility.AccessibleEditableText { + final static double toPointFactor = 1 / (7/10 + 34.5); + + /** Creates new GenericAccessibleEditableText object */ + public AccessibleEditableTextImpl(XAccessibleEditableText xAccessibleEditableText) { + super(xAccessibleEditableText); + } + + /** Cuts the text between two indices into the system clipboard */ + public void cut(int startIndex, int endIndex) { + try { + ((XAccessibleEditableText) unoObject).cutText(startIndex, endIndex); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Deletes the text between two indices */ + public void delete(int startIndex, int endIndex) { + try { + ((XAccessibleEditableText) unoObject).deleteText(startIndex, endIndex); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Returns the text range between two indices */ + public String getTextRange(int startIndex, int endIndex) { + try { + return unoObject.getTextRange(startIndex, endIndex); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return null; + } + + /** Inserts the specified string at the given index */ + public void insertTextAtIndex(int index, String s){ + try { + ((XAccessibleEditableText) unoObject).insertText(s, index); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Pastes the text form the system clipboard into the text starting at the specified index */ + public void paste(int startIndex) { + try { + ((XAccessibleEditableText) unoObject).pasteText(startIndex); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Replaces the text between two indices with the specified string */ + public void replaceText(int startIndex, int endIndex, String s) { + try { + ((XAccessibleEditableText) unoObject).replaceText(startIndex, endIndex, s); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Selects the text between two indices */ + public void selectText(int startIndex, int endIndex) { + try { + unoObject.setSelection(startIndex, endIndex); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Sets the attributes for the text between two indices */ + public void setAttributes(int startIndex, int endIndex, javax.swing.text.AttributeSet as) { + java.util.Vector propertyValues = new java.util.Vector(); + + // Convert Alignment attribute + Object attribute = as.getAttribute(StyleConstants.Alignment); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "ParaAdjust"; + + switch (StyleConstants.getAlignment(as)) { + case StyleConstants.ALIGN_RIGHT: + propertyValue.Value = ParagraphAdjust.RIGHT; + break; + case StyleConstants.ALIGN_CENTER: + propertyValue.Value = ParagraphAdjust.CENTER; + break; + case StyleConstants.ALIGN_JUSTIFIED: + propertyValue.Value = ParagraphAdjust.BLOCK; + break; + default: + propertyValue.Value = ParagraphAdjust.LEFT; + break; + } + propertyValues.add(propertyValue); + } + + // Convert Background attribute + attribute = as.getAttribute(StyleConstants.Background); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharBackColor"; + propertyValue.Value = new Integer(StyleConstants.getBackground(as).getRGB()); + propertyValues.add(propertyValue); + } + + // FIXME: BidiLevel + + // Set Bold attribute + attribute = as.getAttribute(StyleConstants.Bold); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharWeight"; + if (StyleConstants.isBold(as)) { + propertyValue.Value = new Float(150); + } else { + propertyValue.Value = new Float(100); + } + propertyValues.add(propertyValue); + } + + // FIXME: Java 1.4 ComponentAttribute, ComponentElementName, ComposedTextAttribute + + // Set FirstLineIndent attribute + attribute = as.getAttribute(StyleConstants.FirstLineIndent); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "ParaFirstLineIndent"; + propertyValue.Value = new Double(StyleConstants.getFirstLineIndent(as) / toPointFactor); + propertyValues.add(propertyValue); + } + + // Set font family attribute + attribute = as.getAttribute(StyleConstants.FontFamily); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharFontPitch"; + + if (StyleConstants.getFontFamily(as).equals( "Proportional" )) { + propertyValue.Value = new Short("2"); + } else { + propertyValue.Value = new Short("1"); + } + propertyValues.add(propertyValue); + } + + // Set font size attribute + attribute = as.getAttribute(StyleConstants.FontSize); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharHeight"; + propertyValue.Value = new Integer(StyleConstants.getFontSize(as)); + propertyValues.add(propertyValue); + } + + // Map foreground color + attribute = as.getAttribute(StyleConstants.Foreground); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharColor"; + propertyValue.Value = new Integer (StyleConstants.getForeground(as).getRGB()); + propertyValues.add(propertyValue); + } + + // FIXME: IconAttribute, IconElementName + + // Set italic attribute + attribute = as.getAttribute(StyleConstants.Italic); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharPosture"; + + if (StyleConstants.isItalic(as)) { + propertyValue.Value = FontSlant.ITALIC; + } else { + propertyValue.Value = FontSlant.DONTKNOW; + } + propertyValues.add(propertyValue); + } + + // Set left indent attribute + attribute = as.getAttribute(StyleConstants.LeftIndent); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "ParaFirstLeftMargin"; + propertyValue.Value = new Integer(new Double(StyleConstants.getLeftIndent(as) / toPointFactor).intValue()); + propertyValues.add(propertyValue); + } + + // Set right indent attribute + attribute = as.getAttribute(StyleConstants.RightIndent); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "ParaFirstRightMargin"; + propertyValue.Value = new Integer(new Double(StyleConstants.getRightIndent(as) / toPointFactor).intValue()); + propertyValues.add(propertyValue); + } + + // Set line spacing attribute + attribute = as.getAttribute(StyleConstants.LineSpacing); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "ParaLineSpacing"; + propertyValue.Value = new Integer(new Double(StyleConstants.getLineSpacing(as) / toPointFactor).intValue()); + propertyValues.add(propertyValue); + } + + // FIXME: Java 1.4 NameAttribute, Orientation, ResolveAttribute + + // Set space above attribute + attribute = as.getAttribute(StyleConstants.SpaceAbove); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "ParaTopMargin"; + propertyValue.Value = new Integer(new Double( StyleConstants.getSpaceAbove(as) / toPointFactor).intValue()); + propertyValues.add(propertyValue); + } + + // Set space below attribute + attribute = as.getAttribute(StyleConstants.SpaceBelow); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "ParaBottomMargin"; + propertyValue.Value = new Integer(new Double(StyleConstants.getSpaceBelow(as) / toPointFactor).intValue()); + propertyValues.add(propertyValue); + } + + // Set strike through attribute + attribute = as.getAttribute(StyleConstants.StrikeThrough); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharPosture"; + if (StyleConstants.isStrikeThrough(as)) { + propertyValue.Value = new Short(FontStrikeout.SINGLE); + } else { + propertyValue.Value = new Short(FontStrikeout.NONE); + } + propertyValues.add(propertyValue); + } + + // Set sub-/superscript attribute + attribute = as.getAttribute(StyleConstants.Superscript); + if (null == attribute) { + attribute = as.getAttribute(StyleConstants.Subscript); + } + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharEscapement"; + + if (StyleConstants.isSuperscript(as)) { + propertyValue.Value = new Short( "1" ); + } else if (StyleConstants.isSubscript(as)) { + propertyValue.Value = new Short( "-1" ); + } else { + propertyValue.Value = new Short( "0" ); + } + propertyValues.add(propertyValue); + } + + // Set tabset attribute + attribute = as.getAttribute(StyleConstants.TabSet); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "ParaTabStops"; + + javax.swing.text.TabSet tabSet = StyleConstants.getTabSet(as); + java.util.ArrayList tabStops = new java.util.ArrayList(tabSet.getTabCount()); + + for (int i = 0, max = tabSet.getTabCount(); i < max; i++) { + javax.swing.text.TabStop tab = tabSet.getTab(i); + com.sun.star.style.TabStop unoTab = new com.sun.star.style.TabStop(); + + unoTab.Position = new Double(tab.getPosition() / toPointFactor).intValue(); + + switch (tab.getAlignment()) { + case javax.swing.text.TabStop.ALIGN_CENTER: + unoTab.Alignment = TabAlign.CENTER; + break; + case javax.swing.text.TabStop.ALIGN_RIGHT: + unoTab.Alignment = TabAlign.RIGHT; + break; + case javax.swing.text.TabStop.ALIGN_DECIMAL: + unoTab.Alignment = TabAlign.DECIMAL; + break; + default: + unoTab.Alignment = TabAlign.LEFT; + break; + } + + tabStops.add(unoTab); + } + propertyValue.Value = (com.sun.star.style.TabStop[]) tabStops.toArray(); + propertyValues.add(propertyValue); + } + + // Set underline attribute + attribute = as.getAttribute(StyleConstants.Underline); + if (null != attribute) { + com.sun.star.beans.PropertyValue propertyValue = new com.sun.star.beans.PropertyValue(); + propertyValue.Name = "CharUnderline"; + + if (StyleConstants.isUnderline(as)) { + propertyValue.Value = new Short(FontUnderline.SINGLE); + } else { + propertyValue.Value = new Short(FontUnderline.NONE); + } + propertyValues.add(propertyValue); + } + + try { + ((XAccessibleEditableText) unoObject).setAttributes(startIndex, endIndex, (com.sun.star.beans.PropertyValue[]) propertyValues.toArray()); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Sets the text contents to the specified string */ + public void setTextContents(String s) { + try { + ((XAccessibleEditableText) unoObject).setText(s); + } catch (com.sun.star.uno.RuntimeException e) { + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleExtendedState.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleExtendedState.java new file mode 100644 index 000000000000..3d4500d322df --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleExtendedState.java @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleState; + +public class AccessibleExtendedState extends AccessibleState { + public static final AccessibleState DEFUNCT; + public static final AccessibleState INDETERMINATE; + public static final AccessibleState MANAGES_DESCENDANTS; + public static final AccessibleState SENSITIVE; + public static final AccessibleState STALE; + + static { + DEFUNCT = new AccessibleExtendedState("defunct"); + + // JAVA 1.5: will come with manages_descendants and indeterminate + INDETERMINATE = new AccessibleExtendedState("indeterminate"); + MANAGES_DESCENDANTS = new AccessibleExtendedState("managesDescendants"); + + SENSITIVE = new AccessibleExtendedState("sensitive"); + STALE = new AccessibleExtendedState("stale"); + } + + protected AccessibleExtendedState(String key) { + super(key); + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleHypertextImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleHypertextImpl.java new file mode 100644 index 000000000000..1bb3bc5961ad --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleHypertextImpl.java @@ -0,0 +1,191 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import org.openoffice.java.accessibility.logging.*; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + +/** The AccessibleHypertextImpl mapps all calls to the java AccessibleHypertext + * interface to the corresponding methods of the UNO XAccessibleHypertext + * interface. + */ +public class AccessibleHypertextImpl extends AccessibleTextImpl + implements javax.accessibility.AccessibleHypertext { + + protected class Hyperlink extends javax.accessibility.AccessibleHyperlink { + protected XAccessibleHyperlink unoObject; + + public Hyperlink(XAccessibleHyperlink xHyperlink) { + unoObject = xHyperlink; + } + + public int getStartIndex() { + try { + System.err.println("StartIndex: " + unoObject.getStartIndex()); + return unoObject.getStartIndex(); + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + public Object getAccessibleActionObject(int param) { + System.err.println("getActionObject"); + try { + Object any = unoObject.getAccessibleActionObject(param); + if (AnyConverter.isString(any)) { + String url = AnyConverter.toString(any); + if (null != url) { + return new java.net.URL(url); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.lang.IllegalArgumentException e) { + } catch (java.net.MalformedURLException exception) { + } catch (com.sun.star.uno.RuntimeException e) { + } + + return null; + } + + public int getEndIndex() { + try { + System.err.println("StartIndex: " + unoObject.getEndIndex()); + return unoObject.getEndIndex(); + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + public Object getAccessibleActionAnchor(int param) { + System.err.println("getActionAnchor"); + try { + Object any = unoObject.getAccessibleActionObject(param); + if (AnyConverter.isString(any)) { + System.err.println("Anchor: " + AnyConverter.toString(any)); + return AnyConverter.toString(any); + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.lang.IllegalArgumentException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return null; + } + + public boolean isValid() { + return unoObject.isValid(); + } + + public boolean doAccessibleAction(int param) { + try { + return unoObject.doAccessibleAction(param); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + public String getAccessibleActionDescription(int param) { + try { + return unoObject.getAccessibleActionDescription(param); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } + } + + public int getAccessibleActionCount() { + try { + return unoObject.getAccessibleActionCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + } + + /** Creates new AccessibleHypertextImpl */ + public AccessibleHypertextImpl(XAccessibleHypertext xAccessibleHypertext) { + if (Build.PRODUCT) { + unoObject = xAccessibleHypertext; + } else { + String property = System.getProperty("AccessBridgeLogging"); + if ((property != null) && (property.indexOf("text") != -1)) { + unoObject = new XAccessibleHypertextLog(xAccessibleHypertext); + } else { + unoObject = xAccessibleHypertext; + } + } + } + + public static javax.accessibility.AccessibleText get(com.sun.star.uno.XInterface unoObject) { + try { + XAccessibleHypertext unoAccessibleHypertext = (XAccessibleHypertext) + UnoRuntime.queryInterface(XAccessibleHypertext.class, unoObject); + if (unoAccessibleHypertext != null) { + return new AccessibleHypertextImpl(unoAccessibleHypertext); + } + + XAccessibleText unoAccessibleText = (XAccessibleText) + UnoRuntime.queryInterface(XAccessibleText.class, unoObject); + if (unoAccessibleText != null) { + return new AccessibleTextImpl(unoAccessibleText); + } + } catch (com.sun.star.uno.RuntimeException e) { + } + return null; + } + + public javax.accessibility.AccessibleHyperlink getLink(int param) { + try { + return new Hyperlink(((XAccessibleHypertext) unoObject).getHyperLink(param)); + } + + catch(com.sun.star.lang.IndexOutOfBoundsException exception) { + throw new IndexOutOfBoundsException(exception.getMessage()); + } + } + + public int getLinkCount() { + try { + return ((XAccessibleHypertext) unoObject).getHyperLinkCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + public int getLinkIndex(int param) { + try { + return ((XAccessibleHypertext) unoObject).getHyperLinkIndex(param); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return -1; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleIconImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleIconImpl.java new file mode 100644 index 000000000000..ba41534f245b --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleIconImpl.java @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.XAccessibleImage; + +/** + */ +public class AccessibleIconImpl implements javax.accessibility.AccessibleIcon { + + XAccessibleImage unoAccessibleImage; + + public AccessibleIconImpl(XAccessibleImage xImage) { + unoAccessibleImage = xImage; + } + + /** Gets the description of the icon */ + public String getAccessibleIconDescription() { + try { + return unoAccessibleImage.getAccessibleImageDescription(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the height of the icon */ + public int getAccessibleIconHeight() { + try { + return unoAccessibleImage.getAccessibleImageHeight(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Gets the width of the icon */ + public int getAccessibleIconWidth() { + try { + return unoAccessibleImage.getAccessibleImageWidth(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Sets the description of the icon */ + public void setAccessibleIconDescription(String s) { + // Not supported + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleKeyBinding.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleKeyBinding.java new file mode 100644 index 000000000000..1eb3201c5d68 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleKeyBinding.java @@ -0,0 +1,386 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.awt.KeyStroke; + +/** + * + */ +public class AccessibleKeyBinding extends Object implements javax.accessibility.AccessibleKeyBinding { + + XAccessibleKeyBinding unoAccessibleKeybinding; + + public AccessibleKeyBinding(XAccessibleKeyBinding unoKB) { + unoAccessibleKeybinding = unoKB; + } + + public static int convertModifiers(short s) { + int modifiers = 0; + if ((s & com.sun.star.awt.KeyModifier.SHIFT) != 0) { + modifiers = modifiers | java.awt.event.KeyEvent.SHIFT_DOWN_MASK; + } + + if ((s & com.sun.star.awt.KeyModifier.MOD1) != 0) { + modifiers = modifiers | java.awt.event.KeyEvent.CTRL_DOWN_MASK; + } + + if ((s & com.sun.star.awt.KeyModifier.MOD2) != 0) { + modifiers = modifiers | java.awt.event.KeyEvent.ALT_DOWN_MASK; + } + + if ((s & com.sun.star.awt.KeyModifier.MOD3) != 0) { + modifiers = modifiers | java.awt.event.KeyEvent.META_DOWN_MASK; + } + + return modifiers; + } + + public static int convertKeyCode(short s) { + int keycode = java.awt.event.KeyEvent.VK_UNDEFINED; + + switch(s) { + case com.sun.star.awt.Key.NUM0: + keycode = java.awt.event.KeyEvent.VK_0; + break; + case com.sun.star.awt.Key.NUM1: + keycode = java.awt.event.KeyEvent.VK_1; + break; + case com.sun.star.awt.Key.NUM2: + keycode = java.awt.event.KeyEvent.VK_2; + break; + case com.sun.star.awt.Key.NUM3: + keycode = java.awt.event.KeyEvent.VK_3; + break; + case com.sun.star.awt.Key.NUM4: + keycode = java.awt.event.KeyEvent.VK_4; + break; + case com.sun.star.awt.Key.NUM5: + keycode = java.awt.event.KeyEvent.VK_5; + break; + case com.sun.star.awt.Key.NUM6: + keycode = java.awt.event.KeyEvent.VK_6; + break; + case com.sun.star.awt.Key.NUM7: + keycode = java.awt.event.KeyEvent.VK_7; + break; + case com.sun.star.awt.Key.NUM8: + keycode = java.awt.event.KeyEvent.VK_8; + break; + case com.sun.star.awt.Key.NUM9: + keycode = java.awt.event.KeyEvent.VK_9; + break; + case com.sun.star.awt.Key.A: + keycode = java.awt.event.KeyEvent.VK_A; + break; + case com.sun.star.awt.Key.B: + keycode = java.awt.event.KeyEvent.VK_B; + break; + case com.sun.star.awt.Key.C: + keycode = java.awt.event.KeyEvent.VK_C; + break; + case com.sun.star.awt.Key.D: + keycode = java.awt.event.KeyEvent.VK_D; + break; + case com.sun.star.awt.Key.E: + keycode = java.awt.event.KeyEvent.VK_E; + break; + case com.sun.star.awt.Key.F: + keycode = java.awt.event.KeyEvent.VK_F; + break; + case com.sun.star.awt.Key.G: + keycode = java.awt.event.KeyEvent.VK_G; + break; + case com.sun.star.awt.Key.H: + keycode = java.awt.event.KeyEvent.VK_H; + break; + case com.sun.star.awt.Key.I: + keycode = java.awt.event.KeyEvent.VK_I; + break; + case com.sun.star.awt.Key.J: + keycode = java.awt.event.KeyEvent.VK_J; + break; + case com.sun.star.awt.Key.K: + keycode = java.awt.event.KeyEvent.VK_K; + break; + case com.sun.star.awt.Key.L: + keycode = java.awt.event.KeyEvent.VK_L; + break; + case com.sun.star.awt.Key.M: + keycode = java.awt.event.KeyEvent.VK_M; + break; + case com.sun.star.awt.Key.N: + keycode = java.awt.event.KeyEvent.VK_N; + break; + case com.sun.star.awt.Key.O: + keycode = java.awt.event.KeyEvent.VK_O; + break; + case com.sun.star.awt.Key.P: + keycode = java.awt.event.KeyEvent.VK_P; + break; + case com.sun.star.awt.Key.Q: + keycode = java.awt.event.KeyEvent.VK_Q; + break; + case com.sun.star.awt.Key.R: + keycode = java.awt.event.KeyEvent.VK_R; + break; + case com.sun.star.awt.Key.S: + keycode = java.awt.event.KeyEvent.VK_S; + break; + case com.sun.star.awt.Key.T: + keycode = java.awt.event.KeyEvent.VK_T; + break; + case com.sun.star.awt.Key.U: + keycode = java.awt.event.KeyEvent.VK_U; + break; + case com.sun.star.awt.Key.V: + keycode = java.awt.event.KeyEvent.VK_V; + break; + case com.sun.star.awt.Key.W: + keycode = java.awt.event.KeyEvent.VK_W; + break; + case com.sun.star.awt.Key.X: + keycode = java.awt.event.KeyEvent.VK_X; + break; + case com.sun.star.awt.Key.Y: + keycode = java.awt.event.KeyEvent.VK_Y; + break; + case com.sun.star.awt.Key.Z: + keycode = java.awt.event.KeyEvent.VK_Z; + break; + case com.sun.star.awt.Key.F1: + keycode = java.awt.event.KeyEvent.VK_F1; + break; + case com.sun.star.awt.Key.F2: + keycode = java.awt.event.KeyEvent.VK_F2; + break; + case com.sun.star.awt.Key.F3: + keycode = java.awt.event.KeyEvent.VK_F3; + break; + case com.sun.star.awt.Key.F4: + keycode = java.awt.event.KeyEvent.VK_F4; + break; + case com.sun.star.awt.Key.F5: + keycode = java.awt.event.KeyEvent.VK_F5; + break; + case com.sun.star.awt.Key.F6: + keycode = java.awt.event.KeyEvent.VK_F6; + break; + case com.sun.star.awt.Key.F7: + keycode = java.awt.event.KeyEvent.VK_F7; + break; + case com.sun.star.awt.Key.F8: + keycode = java.awt.event.KeyEvent.VK_F8; + break; + case com.sun.star.awt.Key.F9: + keycode = java.awt.event.KeyEvent.VK_F9; + break; + case com.sun.star.awt.Key.F10: + keycode = java.awt.event.KeyEvent.VK_F10; + break; + case com.sun.star.awt.Key.F11: + keycode = java.awt.event.KeyEvent.VK_F11; + break; + case com.sun.star.awt.Key.F12: + keycode = java.awt.event.KeyEvent.VK_F12; + break; + case com.sun.star.awt.Key.F13: + keycode = java.awt.event.KeyEvent.VK_F13; + break; + case com.sun.star.awt.Key.F14: + keycode = java.awt.event.KeyEvent.VK_F14; + break; + case com.sun.star.awt.Key.F15: + keycode = java.awt.event.KeyEvent.VK_F15; + break; + case com.sun.star.awt.Key.F16: + keycode = java.awt.event.KeyEvent.VK_F16; + break; + case com.sun.star.awt.Key.F17: + keycode = java.awt.event.KeyEvent.VK_F17; + break; + case com.sun.star.awt.Key.F18: + keycode = java.awt.event.KeyEvent.VK_F18; + break; + case com.sun.star.awt.Key.F19: + keycode = java.awt.event.KeyEvent.VK_F19; + break; + case com.sun.star.awt.Key.F20: + keycode = java.awt.event.KeyEvent.VK_F20; + break; + case com.sun.star.awt.Key.F21: + keycode = java.awt.event.KeyEvent.VK_F21; + break; + case com.sun.star.awt.Key.F22: + keycode = java.awt.event.KeyEvent.VK_F22; + break; + case com.sun.star.awt.Key.F23: + keycode = java.awt.event.KeyEvent.VK_F23; + break; + case com.sun.star.awt.Key.F24: + keycode = java.awt.event.KeyEvent.VK_F24; + break; + case com.sun.star.awt.Key.DOWN: + keycode = java.awt.event.KeyEvent.VK_DOWN; + break; + case com.sun.star.awt.Key.UP: + keycode = java.awt.event.KeyEvent.VK_UP; + break; + case com.sun.star.awt.Key.LEFT: + keycode = java.awt.event.KeyEvent.VK_LEFT; + break; + case com.sun.star.awt.Key.RIGHT: + keycode = java.awt.event.KeyEvent.VK_RIGHT; + break; + case com.sun.star.awt.Key.HOME: + keycode = java.awt.event.KeyEvent.VK_HOME; + break; + case com.sun.star.awt.Key.END: + keycode = java.awt.event.KeyEvent.VK_END; + break; + case com.sun.star.awt.Key.PAGEUP: + keycode = java.awt.event.KeyEvent.VK_PAGE_UP; + break; + case com.sun.star.awt.Key.PAGEDOWN: + keycode = java.awt.event.KeyEvent.VK_PAGE_DOWN; + break; + case com.sun.star.awt.Key.RETURN: + keycode = java.awt.event.KeyEvent.VK_ENTER; + break; + case com.sun.star.awt.Key.ESCAPE: + keycode = java.awt.event.KeyEvent.VK_ESCAPE; + break; + case com.sun.star.awt.Key.TAB: + keycode = java.awt.event.KeyEvent.VK_TAB; + break; + case com.sun.star.awt.Key.BACKSPACE: + keycode = java.awt.event.KeyEvent.VK_BACK_SPACE; + break; + case com.sun.star.awt.Key.SPACE: + keycode = java.awt.event.KeyEvent.VK_SPACE; + break; + case com.sun.star.awt.Key.INSERT: + keycode = java.awt.event.KeyEvent.VK_INSERT; + break; + case com.sun.star.awt.Key.DELETE: + keycode = java.awt.event.KeyEvent.VK_DELETE; + break; + case com.sun.star.awt.Key.ADD: + keycode = java.awt.event.KeyEvent.VK_ADD; + break; + case com.sun.star.awt.Key.SUBTRACT: + keycode = java.awt.event.KeyEvent.VK_SUBTRACT; + break; + case com.sun.star.awt.Key.MULTIPLY: + keycode = java.awt.event.KeyEvent.VK_MULTIPLY; + break; + case com.sun.star.awt.Key.DIVIDE: + keycode = java.awt.event.KeyEvent.VK_DIVIDE; + break; + case com.sun.star.awt.Key.POINT: + keycode = java.awt.event.KeyEvent.VK_PERIOD; + break; + case com.sun.star.awt.Key.COMMA: + keycode = java.awt.event.KeyEvent.VK_COMMA; + break; + case com.sun.star.awt.Key.LESS: + keycode = java.awt.event.KeyEvent.VK_LESS; + break; + case com.sun.star.awt.Key.GREATER: + keycode = java.awt.event.KeyEvent.VK_GREATER; + break; + case com.sun.star.awt.Key.EQUAL: + keycode = java.awt.event.KeyEvent.VK_EQUALS; + break; + case com.sun.star.awt.Key.CUT: + keycode = java.awt.event.KeyEvent.VK_CUT; + break; + case com.sun.star.awt.Key.COPY: + keycode = java.awt.event.KeyEvent.VK_COPY; + break; + case com.sun.star.awt.Key.PASTE: + keycode = java.awt.event.KeyEvent.VK_PASTE; + break; + case com.sun.star.awt.Key.UNDO: + keycode = java.awt.event.KeyEvent.VK_UNDO; + break; + case com.sun.star.awt.Key.FIND: + keycode = java.awt.event.KeyEvent.VK_FIND; + break; + case com.sun.star.awt.Key.PROPERTIES: + keycode = java.awt.event.KeyEvent.VK_PROPS; + break; + case com.sun.star.awt.Key.HELP: + keycode = java.awt.event.KeyEvent.VK_HELP; + break; + default: + ; + } + return keycode; + } + + /* + * AccessibleKeyBinding + */ + + /** Returns a key binding for this object */ + public Object getAccessibleKeyBinding(int i) { + try { + KeyStroke[] keys = unoAccessibleKeybinding.getAccessibleKeyBinding(i); + javax.swing.KeyStroke[] data = new javax.swing.KeyStroke[keys.length]; + for (int j=0; j < keys.length; j++) { + int keyCode = convertKeyCode(keys[j].KeyCode); + if (keyCode != java.awt.event.KeyEvent.VK_UNDEFINED) { + data[j] = javax.swing.KeyStroke.getKeyStroke(keyCode, convertModifiers(keys[j].Modifiers)); + } else { + data[j] = null; + } + } + + if (keys.length == 1) { + return data[0]; + } else { + return data; + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the number of key bindings for this object */ + public int getAccessibleKeyBindingCount() { + try { + return unoAccessibleKeybinding.getAccessibleKeyBindingCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleObjectFactory.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleObjectFactory.java new file mode 100644 index 000000000000..129a3b820993 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleObjectFactory.java @@ -0,0 +1,545 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import java.lang.ref.WeakReference; +import javax.accessibility.Accessible; +import javax.accessibility.AccessibleStateSet; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; +import org.openoffice.java.accessibility.logging.XAccessibleEventLog; + +/** +*/ +public class AccessibleObjectFactory { + // This type is needed for conversions from/to uno Any + public static final Type XAccessibleType = new Type(XAccessible.class); + + private static java.util.Hashtable objectList = new java.util.Hashtable(); + private static java.awt.FocusTraversalPolicy focusTraversalPolicy = new FocusTraversalPolicy(); + + private static java.awt.EventQueue theEventQueue = java.awt.Toolkit.getDefaultToolkit(). + getSystemEventQueue(); + + public static java.awt.EventQueue getEventQueue() { + return theEventQueue; + } + + public static void postFocusGained(java.awt.Component c) { + getEventQueue().postEvent(new java.awt.event.FocusEvent(c, java.awt.event.FocusEvent.FOCUS_GAINED)); + } + + public static void postWindowGainedFocus(java.awt.Window w) { + postWindowEvent(w, java.awt.event.WindowEvent.WINDOW_GAINED_FOCUS); + } + + public static void postWindowLostFocus(java.awt.Window w) { + postWindowEvent(w, java.awt.event.WindowEvent.WINDOW_LOST_FOCUS); + } + + public static void postWindowActivated(java.awt.Window w) { + postWindowEvent(w, java.awt.event.WindowEvent.WINDOW_ACTIVATED); + } + + public static void postWindowDeactivated(java.awt.Window w) { + postWindowEvent(w, java.awt.event.WindowEvent.WINDOW_DEACTIVATED); + } + + public static void postWindowOpened(java.awt.Window w) { + postWindowEvent(w, java.awt.event.WindowEvent.WINDOW_OPENED); + } + + public static void postWindowClosed(java.awt.Window w) { + postWindowEvent(w, java.awt.event.WindowEvent.WINDOW_CLOSED); + } + + public static void invokeAndWait() { + try { + theEventQueue.invokeAndWait( new java.lang.Runnable () { + public void run() { + } + }); + } catch (java.lang.reflect.InvocationTargetException e) { + } catch (java.lang.InterruptedException e) { + } + } + + private static void postWindowEvent(java.awt.Window w, int i) { + theEventQueue.postEvent(new java.awt.event.WindowEvent(w, i)); + } + + public static java.awt.Component getAccessibleComponent(XAccessible xAccessible) { + java.awt.Component c = null; + if (xAccessible != null) { + // Retrieve unique id for the original UNO object to be used as a hash key + String oid = UnoRuntime.generateOid(xAccessible); + + // Check if we already have a wrapper object for this context + synchronized (objectList) { + WeakReference r = (WeakReference) objectList.get(oid); + if(r != null) { + c = (java.awt.Component) r.get(); + } + } + } + return c; + } + + public static void addChild(java.awt.Container parent, Object any) { + try { + addChild(parent, (XAccessible) AnyConverter.toObject(XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.err.println(e.getClass().getName() + " caught: " + e.getMessage()); + } + } + + public static void addChild(java.awt.Container parent, XAccessible child) { + try { + if (child != null) { + XAccessibleContext childAC = child.getAccessibleContext(); + if (childAC != null) { + XAccessibleStateSet stateSet = childAC.getAccessibleStateSet(); + if (stateSet != null) { + java.awt.Component c = getAccessibleComponent(child); + + // Re-use existing wrapper if possible, create a new one otherwise + if (c != null) { + // Seems to be already in child list + if (parent.equals(c.getParent())) + return; + // Update general component states + c.setEnabled(stateSet.contains(AccessibleStateType.ENABLED)); + c.setVisible(stateSet.contains(AccessibleStateType.VISIBLE)); + } else { + c = createAccessibleComponentImpl(child, childAC, stateSet); + } + + if (c != null) { + if (c instanceof java.awt.Container) { + populateContainer((java.awt.Container) c, childAC); + } + parent.add(c); + // Simulate focus gained event for new child + if (stateSet.contains(AccessibleStateType.FOCUSED)) { + postFocusGained(c); + } + } + } + } + } + } catch (com.sun.star.uno.RuntimeException e) { + System.err.println(e.getClass().getName() + " caught: " + e.getMessage()); + e.printStackTrace(); + } + } + + protected static void removeChild(java.awt.Container parent, Object any) { + try { + XAccessible xAccessible = (XAccessible) AnyConverter.toObject(XAccessibleType, any); + java.awt.Component c = getAccessibleComponent(xAccessible); + + if (c != null) { + parent.remove(c); + + if (c instanceof java.awt.Container) { + clearContainer((java.awt.Container) c); + } + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.err.println(e.getClass().getName() + " caught: " + e.getMessage()); + } + } + + + /** + * Removes all children from the container parent + */ + + protected static void clearContainer(java.awt.Container parent) { + // Purge all children from this container + int count = parent.getComponentCount(); + for (int i = 0; i < count; i++) { + java.awt.Component c = parent.getComponent(i); + if (c instanceof java.awt.Container) { + clearContainer((java.awt.Container) c); + } + } + parent.removeAll(); + } + + + /** + * Populates the given Container parent with wrapper objects for all children of parentAC. This method is + * intended to be called when a container is added using a CHILDREN_CHANGED event. + */ + + protected static void populateContainer(java.awt.Container parent, XAccessibleContext parentAC) { + if (parentAC != null) { + try { + int childCount = parentAC.getAccessibleChildCount(); + for (int i=0; i<childCount; i++) { + addChild(parent, parentAC.getAccessibleChild(i)); + } + } catch (java.lang.Exception e) { + System.err.println(e.getClass().getName() + " caught: " + e.getMessage()); + e.printStackTrace(); + } + } + } + + /** + * Populates the given Container parent with wrapper objects for all children of parentAC. This method is + * intended to be called when a new window has been opened. + */ + protected static void populateContainer(java.awt.Container parent, XAccessibleContext parentAC, java.awt.Window frame) { + if (parentAC != null) { + try { + int childCount = parentAC.getAccessibleChildCount(); + for (int i=0; i<childCount; i++) { + XAccessible child = parentAC.getAccessibleChild(i); + if (child != null) { + XAccessibleContext childAC = child.getAccessibleContext(); + java.awt.Component c = createAccessibleComponent(child, childAC, frame); + if (c != null) { + if (c instanceof java.awt.Container) { + populateContainer((java.awt.Container) c, childAC, frame); + } + parent.add(c); + } + } else if (Build.DEBUG) { + System.err.println("ignoring not accessible child " + i); + } + } + } + + catch (java.lang.Exception e) { + System.err.println(e.getClass().getName() + " caught: " + e.getMessage()); + e.printStackTrace(); + } + } + } + + protected static java.awt.Component createAccessibleComponent(XAccessible xAccessible) { + try { + XAccessibleContext xAccessibleContext = xAccessible.getAccessibleContext(); + if (xAccessibleContext != null) { + return createAccessibleComponentImpl(xAccessible, xAccessibleContext, xAccessibleContext.getAccessibleStateSet()); + } + } catch (com.sun.star.uno.RuntimeException e) { + System.err.println(e.getClass().getName() + " caught: " + e.getMessage()); + e.printStackTrace(); + } + return null; + } + + protected static java.awt.Component createAccessibleComponent(XAccessible xAccessible, XAccessibleContext xAccessibleContext, + java.awt.Window frame) { + if (xAccessibleContext != null) { + try { + XAccessibleStateSet xAccessibleStateSet = xAccessibleContext.getAccessibleStateSet(); + java.awt.Component c = createAccessibleComponentImpl(xAccessible, xAccessibleContext, xAccessibleStateSet); + if (c != null) { + // Set this component as initial component + if (xAccessibleStateSet.contains(AccessibleStateType.FOCUSED)) { + if (frame instanceof NativeFrame) { + ((NativeFrame) frame).setInitialComponent(c); + } + } + return c; + } + } catch (com.sun.star.uno.RuntimeException e) { + System.err.println(e.getClass().getName() + " caught: " + e.getMessage()); + e.printStackTrace(); + } + } + return null; + } + + protected static java.awt.Component createAccessibleComponentImpl(XAccessible xAccessible, XAccessibleContext xAccessibleContext, + XAccessibleStateSet xAccessibleStateSet) { + java.awt.Component c = null; + short role = xAccessibleContext.getAccessibleRole(); + switch (role) { + case AccessibleRole.CANVAS: + c = new Container(javax.accessibility.AccessibleRole.CANVAS, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.CHECK_BOX: + c = new CheckBox(xAccessible, xAccessibleContext); + break; + case AccessibleRole.COMBO_BOX: + c = new ComboBox(xAccessible, xAccessibleContext); + break; + case AccessibleRole.DOCUMENT: + c = new Container(javax.accessibility.AccessibleRole.CANVAS, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.EMBEDDED_OBJECT: + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.END_NOTE: + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.FILLER: + c = new Container(javax.accessibility.AccessibleRole.FILLER, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.FOOTNOTE: + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.FOOTER: + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.GRAPHIC: + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.HEADER: + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.ICON: + c = new Icon(xAccessible, xAccessibleContext); + break; + case AccessibleRole.LABEL: + c = new Label(xAccessible, xAccessibleContext); + break; + case AccessibleRole.LAYERED_PANE: + c = new Container(javax.accessibility.AccessibleRole.LAYERED_PANE, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.LIST: + if (xAccessibleStateSet.contains(AccessibleStateType.MANAGES_DESCENDANTS)) { + c = new List(xAccessible, xAccessibleContext); + } else { + c = new Container(javax.accessibility.AccessibleRole.LIST, + xAccessible, xAccessibleContext); + } + break; + case AccessibleRole.MENU: + c = new Menu(xAccessible, xAccessibleContext); + break; + case AccessibleRole.MENU_BAR: + c = new MenuContainer(javax.accessibility.AccessibleRole.MENU_BAR, xAccessible, xAccessibleContext); + break; + case AccessibleRole.MENU_ITEM: + c = new MenuItem(xAccessible, xAccessibleContext); + break; + case AccessibleRole.POPUP_MENU: + c = new MenuContainer(javax.accessibility.AccessibleRole.POPUP_MENU, xAccessible, xAccessibleContext); + break; + case AccessibleRole.OPTION_PANE: + c = new Container(javax.accessibility.AccessibleRole.OPTION_PANE, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.PAGE_TAB: + c = new Container(javax.accessibility.AccessibleRole.PAGE_TAB, xAccessible, xAccessibleContext); + break; + case AccessibleRole.PAGE_TAB_LIST: + c = new Container(javax.accessibility.AccessibleRole.PAGE_TAB_LIST, xAccessible, xAccessibleContext); + break; + case AccessibleRole.PARAGRAPH: + case AccessibleRole.HEADING: + c = new Paragraph(xAccessible, xAccessibleContext); + break; + case AccessibleRole.PANEL: + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.PUSH_BUTTON: + c = new Button(xAccessible, xAccessibleContext); + break; + case AccessibleRole.RADIO_BUTTON: + c = new RadioButton(xAccessible, xAccessibleContext); + break; + case AccessibleRole.ROOT_PANE: + c = new Container(javax.accessibility.AccessibleRole.ROOT_PANE, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.SCROLL_BAR: + c = new ScrollBar(xAccessible, xAccessibleContext); + break; + case AccessibleRole.SCROLL_PANE: + c = new Container(javax.accessibility.AccessibleRole.SCROLL_PANE, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.SEPARATOR: + c = new Separator(xAccessible, xAccessibleContext); + break; + case AccessibleRole.SHAPE: + c = new Container(javax.accessibility.AccessibleRole.CANVAS, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.SPLIT_PANE: + c = new Container(javax.accessibility.AccessibleRole.SPLIT_PANE, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.STATUS_BAR: + c = new Container(javax.accessibility.AccessibleRole.STATUS_BAR, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.COLUMN_HEADER: + case AccessibleRole.TABLE: + if (xAccessibleStateSet.contains(AccessibleStateType.MANAGES_DESCENDANTS)) { + c = new Table(xAccessible, xAccessibleContext, + xAccessibleStateSet.contains(AccessibleStateType.MULTI_SELECTABLE)); + } else { + c = new Container(javax.accessibility.AccessibleRole.TABLE, + xAccessible, xAccessibleContext); + } + break; + case AccessibleRole.TABLE_CELL: + if( xAccessibleContext.getAccessibleChildCount() > 0 ) + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + else + c = new Label(xAccessible, xAccessibleContext); + break; + case AccessibleRole.TEXT: + c = new TextComponent(xAccessible, xAccessibleContext); + break; + case AccessibleRole.TEXT_FRAME: + c = new Container(javax.accessibility.AccessibleRole.PANEL, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.TOGGLE_BUTTON: + c = new ToggleButton(xAccessible, xAccessibleContext); + break; + case AccessibleRole.TOOL_BAR: + c = new Container(javax.accessibility.AccessibleRole.TOOL_BAR, + xAccessible, xAccessibleContext); + break; + case AccessibleRole.TOOL_TIP: + c = new ToolTip(xAccessible, xAccessibleContext); + break; + case AccessibleRole.TREE: + c = new Tree(xAccessible, xAccessibleContext); + break; + case AccessibleRole.VIEW_PORT: + c = new Container(javax.accessibility.AccessibleRole.VIEWPORT, + xAccessible, xAccessibleContext); + break; + default: + System.err.println("Unmapped accessible object " + role); + System.err.println("usually mapped to " + AccessibleRoleAdapter.getAccessibleRole(role)); + c = new Container(AccessibleRoleAdapter.getAccessibleRole(role), + xAccessible, xAccessibleContext); + break; + } + if (c != null) { + // Add the newly created object to the cache list + synchronized (objectList) { + objectList.put(c.toString(), new WeakReference(c)); + if (Build.DEBUG) { +// System.out.println("Object cache now contains " + objectList.size() + " objects."); + } + } + + AccessibleStateAdapter.setComponentState(c, xAccessibleStateSet); + + if (! Build.PRODUCT) { + String property = System.getProperty("AccessBridgeLogging"); + if ((property != null) && (property.indexOf("event") != -1)) { + XAccessibleEventLog.addEventListener(xAccessibleContext, c); + } + } + } + + return c; + } + + protected static void disposing(java.awt.Component c) { + if (c != null) { + synchronized (objectList) { + objectList.remove(c.toString()); + } + } + } + + public static java.awt.Window getTopWindow(XAccessible xAccessible) { + XAccessibleContext xAccessibleContext = xAccessible.getAccessibleContext(); + + if (xAccessibleContext != null) { + short role = xAccessibleContext.getAccessibleRole(); + XAccessibleStateSet xAccessibleStateSet = xAccessibleContext.getAccessibleStateSet(); + XAccessibleComponent xAccessibleComponent = (XAccessibleComponent) + UnoRuntime.queryInterface(XAccessibleComponent.class, xAccessibleContext); + + java.awt.Window w; + if (role == AccessibleRole.DIALOG) { + w = new Dialog(new Application(), + xAccessibleContext.getAccessibleName(), + xAccessibleStateSet.contains(AccessibleStateType.MODAL), + xAccessibleComponent); + } else if (role == AccessibleRole.ALERT) { + w = new Alert(new Application(), + xAccessibleContext.getAccessibleName(), + xAccessibleStateSet.contains(AccessibleStateType.MODAL), + xAccessibleComponent); + } else if (role == AccessibleRole.FRAME) { + w = new Frame(xAccessibleContext.getAccessibleName(), + xAccessibleComponent); + } else if (role == AccessibleRole.WINDOW) { + java.awt.Window activeWindow = + java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); + if (activeWindow != null) { + w = new Window(activeWindow, xAccessibleComponent); + } else { + if (Build.DEBUG) { + System.err.println("no active frame found for Window: " + role); + } + return null; + } + } else { + if (Build.DEBUG) { + System.err.println("invalid role for toplevel window: " + role); + } + return null; + } + populateContainer(w, xAccessibleContext, w); + w.setFocusTraversalPolicy(focusTraversalPolicy); + w.setVisible(true); + + // Make the new window the focused one if it has an initialy focused object set. + java.awt.Component c = ((NativeFrame) w).getInitialComponent(); + if (c != null) { + postWindowGainedFocus(w); + } + return w; + } + + return null; + } +} + + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleRelationAdapter.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleRelationAdapter.java new file mode 100644 index 000000000000..2f1709acac45 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleRelationAdapter.java @@ -0,0 +1,64 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.Accessible; +import com.sun.star.accessibility.AccessibleRelation; +import com.sun.star.accessibility.XAccessible; + +/** + */ +public abstract class AccessibleRelationTypeMap { + + final static String[] data = { + null, + javax.accessibility.AccessibleRelation.CONTROLLED_BY, + javax.accessibility.AccessibleRelation.CONTROLLED_BY, + javax.accessibility.AccessibleRelation.CONTROLLER_FOR, + javax.accessibility.AccessibleRelation.CONTROLLER_FOR, + javax.accessibility.AccessibleRelation.LABEL_FOR, + javax.accessibility.AccessibleRelation.LABEL_FOR, + javax.accessibility.AccessibleRelation.LABELED_BY, + javax.accessibility.AccessibleRelation.LABELED_BY, + javax.accessibility.AccessibleRelation.MEMBER_OF, + javax.accessibility.AccessibleRelation.MEMBER_OF + }; + + public static void fillAccessibleRelationSet(javax.accessibility.AccessibleRelationSet s, AccessibleRelation[] relations) { + AccessibleObjectFactory factory = AccessibleObjectFactory.getDefault(); + for(int i=0; i<relations.length; i++) { + if( relations[i].RelationType < data.length && data[relations[i].RelationType] != null ) { + javax.accessibility.AccessibleRelation r = + new javax.accessibility.AccessibleRelation(data[relations[i].RelationType]); + + r.setTarget(factory.getAccessibleObjectSet(relations[i].TargetSet)); + s.add(r); + } + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleRoleAdapter.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleRoleAdapter.java new file mode 100644 index 000000000000..c7f630fdd3ab --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleRoleAdapter.java @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleContext; + +/** This class maps the AccessibleRole(s) of the UNO accessibility API + * to the corresponding javax.accessibility objects. + */ +public abstract class AccessibleRoleAdapter { + + /* This array is used as a mapping between the UNO AccessibleRole + * and the AccessibleRole objects of the Java accessibility API. + */ + public static final javax.accessibility.AccessibleRole[] data = { + javax.accessibility.AccessibleRole.UNKNOWN, + javax.accessibility.AccessibleRole.ALERT, + javax.accessibility.AccessibleRole.COLUMN_HEADER, + javax.accessibility.AccessibleRole.CANVAS, + javax.accessibility.AccessibleRole.CHECK_BOX, + javax.accessibility.AccessibleRole.CHECK_BOX, // CHECK_MENU_ITEM + javax.accessibility.AccessibleRole.COLOR_CHOOSER, + javax.accessibility.AccessibleRole.COMBO_BOX, + javax.accessibility.AccessibleRole.DATE_EDITOR, + javax.accessibility.AccessibleRole.DESKTOP_ICON, + javax.accessibility.AccessibleRole.DESKTOP_PANE, + javax.accessibility.AccessibleRole.DIRECTORY_PANE, + javax.accessibility.AccessibleRole.DIALOG, + javax.accessibility.AccessibleRole.CANVAS, // DOCUMENT + javax.accessibility.AccessibleRole.PANEL, // EMBEDDED_OBJECT + javax.accessibility.AccessibleRole.PANEL, // ENDNOTE + javax.accessibility.AccessibleRole.FILE_CHOOSER, + javax.accessibility.AccessibleRole.FILLER, + javax.accessibility.AccessibleRole.FONT_CHOOSER, + javax.accessibility.AccessibleRole.FOOTER, + javax.accessibility.AccessibleRole.PANEL, // FOOTNOTE + javax.accessibility.AccessibleRole.FRAME, + javax.accessibility.AccessibleRole.GLASS_PANE, + javax.accessibility.AccessibleRole.PANEL, // GRAPHIC + javax.accessibility.AccessibleRole.GROUP_BOX, + javax.accessibility.AccessibleRole.HEADER, + javax.accessibility.AccessibleRole.TEXT, // HEADING + javax.accessibility.AccessibleRole.HYPERLINK, + javax.accessibility.AccessibleRole.ICON, + javax.accessibility.AccessibleRole.INTERNAL_FRAME, + javax.accessibility.AccessibleRole.LABEL, + javax.accessibility.AccessibleRole.LAYERED_PANE, + javax.accessibility.AccessibleRole.LIST, + javax.accessibility.AccessibleRole.LABEL, // LIST_ITEM - required by Zoomtext + javax.accessibility.AccessibleRole.MENU, + javax.accessibility.AccessibleRole.MENU_BAR, + javax.accessibility.AccessibleRole.MENU_ITEM, + javax.accessibility.AccessibleRole.OPTION_PANE, + javax.accessibility.AccessibleRole.PAGE_TAB, + javax.accessibility.AccessibleRole.PAGE_TAB_LIST, + javax.accessibility.AccessibleRole.PANEL, + javax.accessibility.AccessibleRole.PARAGRAPH, + javax.accessibility.AccessibleRole.PASSWORD_TEXT, + javax.accessibility.AccessibleRole.POPUP_MENU, + javax.accessibility.AccessibleRole.PUSH_BUTTON, + javax.accessibility.AccessibleRole.PROGRESS_BAR, + javax.accessibility.AccessibleRole.RADIO_BUTTON, + javax.accessibility.AccessibleRole.RADIO_BUTTON, // RADIO_MENU_ITEM + javax.accessibility.AccessibleRole.ROW_HEADER, + javax.accessibility.AccessibleRole.ROOT_PANE, + javax.accessibility.AccessibleRole.SCROLL_BAR, + javax.accessibility.AccessibleRole.SCROLL_PANE, + javax.accessibility.AccessibleRole.CANVAS, // SHAPE + javax.accessibility.AccessibleRole.SEPARATOR, + javax.accessibility.AccessibleRole.SLIDER, + javax.accessibility.AccessibleRole.SPIN_BOX, + javax.accessibility.AccessibleRole.SPLIT_PANE, + javax.accessibility.AccessibleRole.STATUS_BAR, + javax.accessibility.AccessibleRole.TABLE, + javax.accessibility.AccessibleRole.LABEL, // TABLE_CELL - required by ZoomText + javax.accessibility.AccessibleRole.TEXT, + javax.accessibility.AccessibleRole.PANEL, // TEXT_FRAME + javax.accessibility.AccessibleRole.TOGGLE_BUTTON, + javax.accessibility.AccessibleRole.TOOL_BAR, + javax.accessibility.AccessibleRole.TOOL_TIP, + javax.accessibility.AccessibleRole.TREE, + javax.accessibility.AccessibleRole.VIEWPORT, + javax.accessibility.AccessibleRole.WINDOW, + javax.accessibility.AccessibleRole.RADIO_BUTTON, // BUTTON_DROPDOWN + javax.accessibility.AccessibleRole.RADIO_BUTTON, // BUTTON_MENU + javax.accessibility.AccessibleRole.PANEL, // CAPTION + javax.accessibility.AccessibleRole.PANEL, // CHART + javax.accessibility.AccessibleRole.EDITBAR, + javax.accessibility.AccessibleRole.PANEL, // FORM + javax.accessibility.AccessibleRole.PANEL, // IMAGE_MAP + javax.accessibility.AccessibleRole.PANEL, // NOTE + javax.accessibility.AccessibleRole.PANEL, // PAGE + javax.accessibility.AccessibleRole.RULER, + javax.accessibility.AccessibleRole.PANEL, // SECTION + javax.accessibility.AccessibleRole.LABEL, // TREE_ITEM + javax.accessibility.AccessibleRole.TABLE // TREE_TABLE + }; + + public static javax.accessibility.AccessibleRole getAccessibleRole(short role) { + if(role < data.length) { + if(data[role] == null) { + System.err.println("Unmapped role: " + role); + } + return data[role]; + } + // FIXME: remove debug out + System.err.println("Unmappable role: " + role); + return null; + } + + public static javax.accessibility.AccessibleRole getAccessibleRole(XAccessible unoAccessible) { + try { + XAccessibleContext unoAccessibleContext = unoAccessible.getAccessibleContext(); + if (unoAccessibleContext != null) { + return getAccessibleRole(unoAccessibleContext.getAccessibleRole()); + } + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return javax.accessibility.AccessibleRole.UNKNOWN; + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleSelectionImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleSelectionImpl.java new file mode 100644 index 000000000000..6e40c1e7a78d --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleSelectionImpl.java @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; + +class AccessibleSelectionImpl implements javax.accessibility.AccessibleSelection { + XAccessibleSelection unoAccessibleSelection; + + AccessibleSelectionImpl(XAccessibleSelection xAccessibleSelection) { + unoAccessibleSelection = xAccessibleSelection; + } + + /** Returns an Accessible representing the specified selected child of the object */ + public javax.accessibility.Accessible getAccessibleSelection(int i) { + try { + return (javax.accessibility.Accessible) AccessibleObjectFactory.getAccessibleComponent( + unoAccessibleSelection.getSelectedAccessibleChild(i)); + } catch (com.sun.star.uno.Exception e) { + return null; + } + } + + /** Adds the specified Accessible child of the object to the object's selection */ + public void addAccessibleSelection(int i) { + try { + unoAccessibleSelection.selectAccessibleChild(i); + } catch (com.sun.star.uno.Exception e) { + } + } + + /** Clears the selection in the object, so that no children in the object are selected */ + public void clearAccessibleSelection() { + try { + unoAccessibleSelection.clearAccessibleSelection(); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Returns the number of Accessible children currently selected */ + public int getAccessibleSelectionCount() { + try { + return unoAccessibleSelection.getSelectedAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Determines if the current child of this object is selected */ + public boolean isAccessibleChildSelected(int i) { + try { + return unoAccessibleSelection.isAccessibleChildSelected(i); + } catch (com.sun.star.uno.Exception e) { + return false; + } + } + + /** Removes the specified child of the object from the object's selection */ + public void removeAccessibleSelection(int i) { + try { + unoAccessibleSelection.deselectAccessibleChild(i); + } catch (com.sun.star.uno.Exception e) { + } + } + + /** Causes every child of the object to be selected if the object supports multiple selection */ + public void selectAllAccessibleSelection() { + try { + unoAccessibleSelection.selectAllAccessibleChildren(); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleStateAdapter.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleStateAdapter.java new file mode 100644 index 000000000000..ea1979a545ed --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleStateAdapter.java @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; + +import com.sun.star.uno.AnyConverter; +import com.sun.star.accessibility.AccessibleStateType; +import com.sun.star.accessibility.XAccessibleStateSet; + +public class AccessibleStateAdapter { + + private static final AccessibleState[] stateTypeMap = { + null, + AccessibleState.ACTIVE, + AccessibleState.ARMED, + AccessibleState.BUSY, + AccessibleState.CHECKED, + AccessibleExtendedState.DEFUNCT, + AccessibleState.EDITABLE, + AccessibleState.ENABLED, + AccessibleState.EXPANDABLE, + AccessibleState.EXPANDED, + AccessibleState.FOCUSABLE, + AccessibleState.FOCUSED, + AccessibleState.HORIZONTAL, + AccessibleState.ICONIFIED, + AccessibleExtendedState.INDETERMINATE, + AccessibleExtendedState.MANAGES_DESCENDANTS, + AccessibleState.MODAL, + AccessibleState.MULTI_LINE, + AccessibleState.MULTISELECTABLE, + AccessibleState.OPAQUE, + AccessibleState.PRESSED, + AccessibleState.RESIZABLE, + AccessibleState.SELECTABLE, + AccessibleState.SELECTED, + AccessibleExtendedState.SENSITIVE, + AccessibleState.SHOWING, + AccessibleState.SINGLE_LINE, + AccessibleExtendedState.STALE, + AccessibleState.TRANSIENT, + AccessibleState.VERTICAL, + AccessibleState.VISIBLE + }; + + private static void printToplevelStateMessage(AccessibleState s, java.awt.Component c) { + System.err.println("*** ERROR *** " + s + " state is a toplevel window state " + c); + } + + private static String getDisplayName(java.awt.Component c) { + javax.accessibility.Accessible a = (javax.accessibility.Accessible) c; + if( a != null) { + javax.accessibility.AccessibleContext ac = a.getAccessibleContext(); + return "[" + ac.getAccessibleRole() + "] " + ac.getAccessibleName(); + } else { + return c.toString(); + } + } + + private static void printOutOfSyncMessage(AccessibleState s, java.awt.Component c, boolean enabled) { + System.err.println("*** ERROR *** " + s + " state out of sync (UNO state set: " + !enabled + ", Java component state: " + enabled + ") for " + getDisplayName(c)); + } + + public static AccessibleState getAccessibleState(Object any) { + try { + if (AnyConverter.isShort(any)) { + return getAccessibleState(AnyConverter.toShort(any)); + } + return null; + } catch (com.sun.star.lang.IllegalArgumentException e) { + return null; + } + } + + public static AccessibleState getAccessibleState(short unoStateType) { + if (unoStateType > 0 && unoStateType < stateTypeMap.length) { + return stateTypeMap[unoStateType]; + } + return null; + } + + public static AccessibleStateSet getDefunctStateSet() { + AccessibleStateSet ass = new AccessibleStateSet(); + ass.add(AccessibleExtendedState.DEFUNCT); + return ass; + } + + public static void setComponentState(java.awt.Component c, + XAccessibleStateSet xAccessibleStateSet) { + + try { + if (xAccessibleStateSet != null) { + // Set the boundings of the component if it is visible .. + if (!xAccessibleStateSet.contains(AccessibleStateType.VISIBLE)) { + c.setVisible(false); + } + // Set the components' enabled state .. + if (!xAccessibleStateSet.contains(AccessibleStateType.ENABLED)) { + c.setEnabled(false); + } + // Set the components' focusable state .. + if (!xAccessibleStateSet.contains(AccessibleStateType.FOCUSABLE)) { + c.setFocusable(false); + } + } + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + public static AccessibleStateSet getAccessibleStateSet(java.awt.Component c, + XAccessibleStateSet xAccessibleStateSet) { + + try { + if (xAccessibleStateSet != null) { + AccessibleStateSet as = new AccessibleStateSet(); + short[] unoStateTypes = xAccessibleStateSet.getStates(); + for (int i=0; i<unoStateTypes.length; i++) { + if (unoStateTypes[i] > 0 && + unoStateTypes[i] < stateTypeMap.length) { + as.add(stateTypeMap[unoStateTypes[i]]); + } + } + + // Note: COLLAPSED does not exists in the UAA. + if (as.contains(AccessibleState.EXPANDABLE) && + ! as.contains(AccessibleState.EXPANDED)) { + as.add(AccessibleState.COLLAPSED); + } + + // Sync office and Java FOCUSED state + boolean isFocusInSync; + if (c.isFocusOwner()) { + isFocusInSync = !as.add(AccessibleState.FOCUSED); + } else { + isFocusInSync = !as.remove(AccessibleState.FOCUSED); + } + + // Sync office and Java ACTIVE state + boolean isActiveInSync; + if (c instanceof java.awt.Window && ((java.awt.Window) c).isActive()) { + isActiveInSync = !as.add(AccessibleState.ACTIVE); + } else { + isActiveInSync = !as.remove(AccessibleState.ACTIVE); + } + + // Report out-of-sync messages + if (!Build.PRODUCT) { + if (!isFocusInSync) { + printOutOfSyncMessage(AccessibleState.FOCUSED, c, c.isFocusOwner()); + } + if (!isActiveInSync) { + printOutOfSyncMessage(AccessibleState.ACTIVE, c, ((java.awt.Window) c).isActive()); + } + if (as.contains(AccessibleState.ENABLED) != c.isEnabled()) { + printOutOfSyncMessage(AccessibleState.ENABLED, c, c.isEnabled()); + } + if (as.contains(AccessibleState.FOCUSABLE) != c.isFocusable()) { + printOutOfSyncMessage(AccessibleState.FOCUSABLE, c, c.isFocusable()); + } + if (as.contains(AccessibleState.SHOWING) != c.isShowing()) { + printOutOfSyncMessage(AccessibleState.SHOWING, c, c.isShowing()); + } + if (as.contains(AccessibleState.VISIBLE) != c.isVisible()) { + printOutOfSyncMessage(AccessibleState.VISIBLE, c, c.isVisible()); + } + + // The following states are for toplevel windows only + if (! (c instanceof java.awt.Window)) { + if (as.contains(AccessibleState.ACTIVE)) { + printToplevelStateMessage(AccessibleState.ACTIVE, c); + } + if (as.contains(AccessibleState.ICONIFIED)) { + printToplevelStateMessage(AccessibleState.ICONIFIED, c); + } + if (as.contains(AccessibleState.MODAL)) { + printToplevelStateMessage(AccessibleState.MODAL, c); + } + } + } + return as; + } + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return getDefunctStateSet(); + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java new file mode 100644 index 000000000000..c3bcbde2a71a --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java @@ -0,0 +1,678 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.awt.*; +import com.sun.star.style.*; +import com.sun.star.uno.*; + +import org.openoffice.java.accessibility.logging.*; + +import java.text.BreakIterator; +import java.util.Locale; + +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleText; + +import javax.swing.text.StyleConstants; + +/** The GenericAccessibleEditableText mapps the calls to the java AccessibleEditableText + * interface to the corresponding methods of the UNO XAccessibleEditableText interface. + */ +public class AccessibleTextImpl implements javax.accessibility.AccessibleText { + final static double toPointFactor = 1 / ((7 / 10) + 34.5); + final static String[] attributeList = { + "ParaAdjust", "CharBackColor", "CharWeight", "ParaFirstLineIndent", + "CharFontPitch", "CharHeight", "CharColor", "CharPosture", + "ParaLeftMargin", "ParaLineSpacing", "ParaTopMargin", "ParaBottomMargin", + "CharStrikeout", "CharEscapement", "ParaTabStops", "CharUnderline" + }; + + final static String[] localeAttributeList = { + "CharLocale", "CharLocaleAsian", "CharLocaleComplex" + }; + + XAccessibleText unoObject; + private javax.swing.text.TabSet tabSet = null; + private javax.swing.text.TabStop[] tabStops = null; + private static Type TextSegmentType = new Type(TextSegment.class); + private static Type UnoLocaleType = new Type(com.sun.star.lang.Locale.class); + + /** Creates new GenericAccessibleEditableText object */ + public AccessibleTextImpl(XAccessibleText xAccessibleText) { + + if (Build.PRODUCT) { + unoObject = xAccessibleText; + } else { + String property = System.getProperty("AccessBridgeLogging"); + if ((property != null) && (property.indexOf("text") != -1)) { + unoObject = new XAccessibleTextLog(xAccessibleText); + } else { + unoObject = xAccessibleText; + } + } + } + + public AccessibleTextImpl() { + } + + public static javax.accessibility.AccessibleText get(com.sun.star.uno.XInterface unoObject) { + try { + XAccessibleText unoAccessibleText = (XAccessibleText) + UnoRuntime.queryInterface(XAccessibleText.class, unoObject); + if (unoAccessibleText != null) { + return new AccessibleTextImpl(unoAccessibleText); + } + } catch (com.sun.star.uno.RuntimeException e) { + } + return null; + } + + protected static Object convertTextSegment(Object any) { + try { + if (AnyConverter.isObject(any)) { + TextSegment ts = (TextSegment) + AnyConverter.toObject(TextSegmentType, any); + if (ts != null) { + // Since there is nothing like a "range" object in the JAA yet, + // the Object[3] is a private negotiation with the JABG + Object[] array = { new Integer(ts.SegmentStart), + new Integer(ts.SegmentEnd), ts.SegmentText }; + return array; + } + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + + return null; + } + + /** Returns the locale object. + * + * Since switching the UI language only takes effect on the next + * office start, UI elements can return a cached value here - given + * that Java UNO initializes the default locale correctly, this is + * the perfect place to grab this cached values. + * + * However, since there are more sophisticated components with + * potentially more than one locale, we first check for the + * CharLocale[Asian|Complex] property. + */ + + protected java.util.Locale getLocale(int index) { + try { + com.sun.star.beans.PropertyValue[] propertyValues = + unoObject.getCharacterAttributes(index, localeAttributeList); + + if (null != propertyValues) { + for (int i = 0; i < propertyValues.length; i++) { + com.sun.star.lang.Locale unoLocale = (com.sun.star.lang.Locale) + AnyConverter.toObject(UnoLocaleType, propertyValues[i]); + if (unoLocale != null) { + return new java.util.Locale(unoLocale.Language, unoLocale.Country); + } + } + } + + return java.util.Locale.getDefault(); + } catch (com.sun.star.lang.IllegalArgumentException e) { + return java.util.Locale.getDefault(); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return java.util.Locale.getDefault(); + } + } + + + /** Returns the string after a given index + * + * The Java word iterator has a different understanding of what + * a word is than the word iterator used by OOo, so we use the + * Java iterators to ensure maximal compatibility with Java. + */ + public String getAfterIndex(int part, int index) { + switch (part) { + case AccessibleText.CHARACTER: + try { + String s = unoObject.getText(); + return s.substring(index+1, index+2); + } catch (IndexOutOfBoundsException e) { + return null; + } + case AccessibleText.WORD: + try { + String s = unoObject.getText(); + BreakIterator words = BreakIterator.getWordInstance(getLocale(index)); + words.setText(s); + int start = words.following(index); + if (start == BreakIterator.DONE || start >= s.length()) { + return null; + } + int end = words.following(start); + if (end == BreakIterator.DONE || end >= s.length()) { + return null; + } + return s.substring(start, end); + } catch (IllegalArgumentException e) { + return null; + } catch (IndexOutOfBoundsException e) { + return null; + } + case AccessibleText.SENTENCE: + try { + String s = unoObject.getText(); + BreakIterator sentence = + BreakIterator.getSentenceInstance(getLocale(index)); + sentence.setText(s); + int start = sentence.following(index); + if (start == BreakIterator.DONE || start >= s.length()) { + return null; + } + int end = sentence.following(start); + if (end == BreakIterator.DONE || end >= s.length()) { + return null; + } + return s.substring(start, end); + } catch (IllegalArgumentException e) { + return null; + } catch (IndexOutOfBoundsException e) { + return null; + } + case 4: + try { + TextSegment ts = unoObject.getTextBehindIndex(index, AccessibleTextType.LINE); + return ts.SegmentText; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + // Workaround for #104847# + if (index > 0 && getCharCount() == index) { + return getAfterIndex(part, index - 1); + } + return null; + } catch (com.sun.star.lang.IllegalArgumentException e) { + return null; + } + case 5: + try { + TextSegment ts = unoObject.getTextBehindIndex(index, AccessibleTextType.ATTRIBUTE_RUN); + return ts.SegmentText; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.lang.IllegalArgumentException e) { + return null; + } + default: + return null; + } + } + + /** Returns the zero-based offset of the caret */ + public int getCaretPosition() { + try { + return unoObject.getCaretPosition(); + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the start offset within the selected text */ + public int getSelectionStart() { + try { + int index = unoObject.getSelectionStart(); + + if (index == -1) { + index = getCaretPosition(); + } + + return index; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + protected void setAttribute(javax.swing.text.MutableAttributeSet as, + com.sun.star.beans.PropertyValue property) { + try { + // Map alignment attribute + if (property.Name.equals("ParaAdjust")) { + ParagraphAdjust adjust = null; + + if (property.Value instanceof ParagraphAdjust) { + adjust = (ParagraphAdjust) property.Value; + } else if (property.Value instanceof Any) { + adjust = (ParagraphAdjust) AnyConverter.toObject(new Type( + ParagraphAdjust.class), property.Value); + } else { + adjust = ParagraphAdjust.fromInt(AnyConverter.toInt( + property.Value)); + } + + if (adjust != null) { + if (adjust.equals(ParagraphAdjust.LEFT)) { + StyleConstants.setAlignment(as, + StyleConstants.ALIGN_LEFT); + } else if (adjust.equals(ParagraphAdjust.RIGHT)) { + StyleConstants.setAlignment(as, + StyleConstants.ALIGN_RIGHT); + } else if (adjust.equals(ParagraphAdjust.CENTER)) { + StyleConstants.setAlignment(as, + StyleConstants.ALIGN_CENTER); + } else if (adjust.equals(ParagraphAdjust.BLOCK) || + adjust.equals(ParagraphAdjust.STRETCH)) { + StyleConstants.setAlignment(as, + StyleConstants.ALIGN_JUSTIFIED); + } + } else if (Build.DEBUG) { + System.err.println( + "Invalid property value for key ParaAdjust: " + + property.Value.getClass().getName()); + } + + // Map background color + } else if (property.Name.equals("CharBackColor")) { + StyleConstants.setBackground(as, + new java.awt.Color(AnyConverter.toInt(property.Value))); + + // FIXME: BidiLevel + // Set bold attribute + } else if (property.Name.equals("CharWeight")) { + boolean isBold = AnyConverter.toFloat(property.Value) > 125; + StyleConstants.setBold(as, isBold); + + // FIXME: Java 1.4 ComponentAttribute, ComponentElementName, ComposedTextAttribute + // Set FirstLineIndent attribute + } else if (property.Name.equals("ParaFirstLineIndent")) { + StyleConstants.setFirstLineIndent(as, + (float) (toPointFactor * AnyConverter.toInt(property.Value))); + + // Set font family attribute + } else if (property.Name.equals("CharFontPitch")) { + if (AnyConverter.toShort(property.Value) == 2) { + StyleConstants.setFontFamily(as, "Proportional"); + } + + // Set font size attribute + } else if (property.Name.equals("CharHeight")) { + StyleConstants.setFontSize(as, + (int) AnyConverter.toFloat(property.Value)); + + // Map foreground color + } else if (property.Name.equals("CharColor")) { + StyleConstants.setForeground(as, + new java.awt.Color(AnyConverter.toInt(property.Value))); + + // FIXME: IconAttribute, IconElementName + // Set italic attribute + } else if (property.Name.equals("CharPosture")) { + FontSlant fs = null; + + if (property.Value instanceof FontSlant) { + fs = (FontSlant) property.Value; + } else if (property.Value instanceof Any) { + fs = (FontSlant) AnyConverter.toObject(new Type( + FontSlant.class), property.Value); + } + + if (fs != null) { + StyleConstants.setItalic(as, FontSlant.ITALIC.equals(fs)); + } + + // Set left indent attribute + } else if (property.Name.equals("ParaLeftMargin")) { + StyleConstants.setLeftIndent(as, + (float) (toPointFactor * AnyConverter.toInt(property.Value))); + + // Set right indent attribute + } else if (property.Name.equals("ParaRightMargin")) { + StyleConstants.setRightIndent(as, + (float) (toPointFactor * AnyConverter.toInt(property.Value))); + } + // Set line spacing attribute + else if (property.Name.equals("ParaLineSpacing")) { + LineSpacing ls = null; + + if (property.Value instanceof LineSpacing) { + ls = (LineSpacing) property.Value; + } else if (property.Value instanceof Any) { + ls = (LineSpacing) AnyConverter.toObject(new Type( + LineSpacing.class), property.Value); + } + + if (ls != null) { + StyleConstants.setLineSpacing(as, + (float) (toPointFactor * ls.Height)); + } + } + // FIXME: Java 1.4 NameAttribute, Orientation, ResolveAttribute + // Set space above attribute + else if (property.Name.equals("ParaTopMargin")) { + StyleConstants.setSpaceAbove(as, + (float) (toPointFactor * AnyConverter.toInt(property.Value))); + } + // Set space below attribute + else if (property.Name.equals("ParaBottomMargin")) { + StyleConstants.setSpaceBelow(as, + (float) (toPointFactor * AnyConverter.toInt(property.Value))); + + // Set strike through attribute + } else if (property.Name.equals("CharStrikeout")) { + boolean isStrikeThrough = (FontStrikeout.NONE != AnyConverter.toShort(property.Value)); + StyleConstants.setStrikeThrough(as, isStrikeThrough); + + // Set sub-/superscript attribute + } else if (property.Name.equals("CharEscapement")) { + short value = AnyConverter.toShort(property.Value); + + if (value > 0) { + StyleConstants.setSuperscript(as, true); + } else if (value < 0) { + StyleConstants.setSubscript(as, true); + } + + // Set tabset attribute + } else if (property.Name.equals("ParaTabStops")) { + TabStop[] unoTabStops = (TabStop[]) AnyConverter.toArray(property.Value); + javax.swing.text.TabStop[] tabStops = new javax.swing.text.TabStop[unoTabStops.length]; + + for (int index2 = 0; index2 < unoTabStops.length; index2++) { + float pos = (float) (toPointFactor * unoTabStops[index2].Position); + + if (unoTabStops[index2].Alignment.equals(TabAlign.LEFT)) { + tabStops[index2] = new javax.swing.text.TabStop(pos, + javax.swing.text.TabStop.ALIGN_LEFT, + javax.swing.text.TabStop.LEAD_NONE); + } else if (unoTabStops[index2].Alignment.equals( + TabAlign.CENTER)) { + tabStops[index2] = new javax.swing.text.TabStop(pos, + javax.swing.text.TabStop.ALIGN_CENTER, + javax.swing.text.TabStop.LEAD_NONE); + } else if (unoTabStops[index2].Alignment.equals( + TabAlign.RIGHT)) { + tabStops[index2] = new javax.swing.text.TabStop(pos, + javax.swing.text.TabStop.ALIGN_RIGHT, + javax.swing.text.TabStop.LEAD_NONE); + } else if (unoTabStops[index2].Alignment.equals( + TabAlign.DECIMAL)) { + tabStops[index2] = new javax.swing.text.TabStop(pos, + javax.swing.text.TabStop.ALIGN_DECIMAL, + javax.swing.text.TabStop.LEAD_NONE); + } else { + tabStops[index2] = new javax.swing.text.TabStop(pos); + } + } + + // Re-use tabSet object if possible to make AttributeSet.equals work + if ((this.tabSet == null) || + !java.util.Arrays.equals(tabStops, this.tabStops)) { + this.tabStops = tabStops; + this.tabSet = new javax.swing.text.TabSet(tabStops); + } + + StyleConstants.setTabSet(as, this.tabSet); + + // Set underline attribute + } else if (property.Name.equals("CharUnderline")) { + boolean isUnderline = (FontUnderline.NONE != AnyConverter.toShort(property.Value)); + StyleConstants.setUnderline(as, isUnderline); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + if (Build.DEBUG) { + System.err.println("*** ERROR *** " + e.getClass().getName() + + " caught for property " + property.Name + ": " + + e.getMessage()); + System.err.println(" value is of type " + + property.Value.getClass().getName()); + } + } + } + + /** Returns the AttributSet for a given character at a given index */ + public javax.swing.text.AttributeSet getCharacterAttribute(int index) { + try { + com.sun.star.beans.PropertyValue[] propertyValues = unoObject.getCharacterAttributes(index, + attributeList); + javax.swing.text.SimpleAttributeSet attributeSet = new javax.swing.text.SimpleAttributeSet(); + + if (null != propertyValues) { + for (int i = 0; i < propertyValues.length; i++) { + setAttribute(attributeSet, propertyValues[i]); + } + } + + return attributeSet; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + if ((index > 0) && (getCharCount() == index)) { + return getCharacterAttribute(index - 1); + } + return null; + } + } + + /** Given a point in local coordinates, return the zero-based index of the character under that point */ + public int getIndexAtPoint(java.awt.Point point) { + try { + return unoObject.getIndexAtPoint(new Point(point.x, point.y)); + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the end offset within the selected text */ + public int getSelectionEnd() { + try { + int index = unoObject.getSelectionEnd(); + + if (index == -1) { + index = getCaretPosition(); + } + + return index; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the string before a given index + * + * The Java word iterator has a different understanding of what + * a word is than the word iterator used by OOo, so we use the + * Java iterators to ensure maximal compatibility with Java. + */ + public java.lang.String getBeforeIndex(int part, int index) { + switch (part) { + case AccessibleText.CHARACTER: + try { + String s = unoObject.getText(); + return s.substring(index-1, index); + } catch (IndexOutOfBoundsException e) { + return null; + } + case AccessibleText.WORD: + try { + String s = unoObject.getText(); + BreakIterator words = BreakIterator.getWordInstance(getLocale(index)); + words.setText(s); + int end = words.following(index); + end = words.previous(); + int start = words.previous(); + if (start == BreakIterator.DONE) { + return null; + } + return s.substring(start, end); + } catch (IllegalArgumentException e) { + return null; + } catch (IndexOutOfBoundsException e) { + return null; + } + case AccessibleText.SENTENCE: + try { + String s = unoObject.getText(); + BreakIterator sentence = + BreakIterator.getSentenceInstance(getLocale(index)); + sentence.setText(s); + int end = sentence.following(index); + end = sentence.previous(); + int start = sentence.previous(); + if (start == BreakIterator.DONE) { + return null; + } + return s.substring(start, end); + } catch (IllegalArgumentException e) { + return null; + } catch (IndexOutOfBoundsException e) { + return null; + } + case 4: + try { + TextSegment ts = unoObject.getTextBeforeIndex(index, AccessibleTextType.LINE); + return ts.SegmentText; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + // Workaround for #104847# + if (index > 0 && getCharCount() == index) { + return getBeforeIndex(part, index - 1); + } + return null; + } catch (com.sun.star.lang.IllegalArgumentException e) { + return null; + } + case 5: + try { + TextSegment ts = unoObject.getTextBeforeIndex(index, AccessibleTextType.ATTRIBUTE_RUN); + return ts.SegmentText; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.lang.IllegalArgumentException e) { + return null; + } + default: + return null; + } + } + + + /** Returns the string at a given index + * + * The Java word iterator has a different understanding of what + * a word is than the word iterator used by OOo, so we use the + * Java iterators to ensure maximal compatibility with Java. + */ + public java.lang.String getAtIndex(int part, int index) { + switch (part) { + case AccessibleText.CHARACTER: + try { + String s = unoObject.getText(); + return s.substring(index, index + 1); + } catch (IndexOutOfBoundsException e) { + return null; + } + case AccessibleText.WORD: + try { + String s = unoObject.getText(); + BreakIterator words = BreakIterator.getWordInstance(getLocale(index)); + words.setText(s); + int end = words.following(index); + return s.substring(words.previous(), end); + } catch (IllegalArgumentException e) { + return null; + } catch (IndexOutOfBoundsException e) { + return null; + } + case AccessibleText.SENTENCE: + try { + String s = unoObject.getText(); + BreakIterator sentence = + BreakIterator.getSentenceInstance(getLocale(index)); + sentence.setText(s); + int end = sentence.following(index); + return s.substring(sentence.previous(), end); + } catch (IllegalArgumentException e) { + return null; + } catch (IndexOutOfBoundsException e) { + return null; + } + case 4: + try { + TextSegment ts = unoObject.getTextAtIndex(index, AccessibleTextType.LINE); + return ts.SegmentText; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + // Workaround for #104847# + if (index > 0 && getCharCount() == index) { + return getAtIndex(part, index - 1); + } + return null; + } catch (com.sun.star.lang.IllegalArgumentException e) { + return null; + } + case 5: + try { + TextSegment ts = unoObject.getTextAtIndex(index, AccessibleTextType.ATTRIBUTE_RUN); + return ts.SegmentText; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.lang.IllegalArgumentException e) { + return null; + } + + default: + return null; + } + } + + /** Returns the number of characters (valid indicies) */ + public int getCharCount() { + try { + return unoObject.getCharacterCount(); + } catch (com.sun.star.uno.RuntimeException e) { + } + + return 0; + } + + /** Returns the portion of the text that is selected */ + public java.lang.String getSelectedText() { + try { + return unoObject.getSelectedText(); + } catch (com.sun.star.uno.RuntimeException e) { + } + + return null; + } + + /** Determines the bounding box of the character at the given index into the string */ + public java.awt.Rectangle getCharacterBounds(int index) { + try { + Rectangle unoRect = unoObject.getCharacterBounds(index); + return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + if ((index > 0) && (getCharCount() == index)) { + return getCharacterBounds(index - 1); + } + } catch (com.sun.star.uno.RuntimeException e) { + } + + return new java.awt.Rectangle(); + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleValueImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleValueImpl.java new file mode 100644 index 000000000000..cabbf3f5d323 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleValueImpl.java @@ -0,0 +1,96 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.XAccessibleValue; +import com.sun.star.uno.AnyConverter; + +/** The AccessibleValueImpl mappes the calls to the java AccessibleValue + * interface to the corresponding methods of the UNO XAccessibleValue interface + */ +public class AccessibleValueImpl implements javax.accessibility.AccessibleValue { + protected XAccessibleValue unoObject; + + /** Creates new AccessibleValueImpl */ + public AccessibleValueImpl(XAccessibleValue xAccessibleValue) { + unoObject = xAccessibleValue; + } + + public static java.lang.Number toNumber(java.lang.Object any) { + try { + if(AnyConverter.isByte(any)) { + return new Byte(AnyConverter.toByte(any)); + } else if (AnyConverter.isShort(any)) { + return new Short(AnyConverter.toShort(any)); + } else if (AnyConverter.isInt(any)) { + return new Integer(AnyConverter.toInt(any)); + } else if (AnyConverter.isLong(any)) { + return new Long(AnyConverter.toLong(any)); + } else if (AnyConverter.isFloat(any)) { + return new Float(AnyConverter.toFloat(any)); + } else if (AnyConverter.isDouble(any)) { + return new Double(AnyConverter.toDouble(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + + return null; + } + + public java.lang.Number getMinimumAccessibleValue() { + try { + return toNumber(unoObject.getMinimumValue()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public java.lang.Number getCurrentAccessibleValue() { + try { + return toNumber(unoObject.getCurrentValue()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public java.lang.Number getMaximumAccessibleValue() { + try { + return toNumber(unoObject.getMaximumValue()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public boolean setCurrentAccessibleValue(java.lang.Number number) { + try { + return unoObject.setCurrentValue(number); + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Alert.java b/accessibility/bridge/org/openoffice/java/accessibility/Alert.java new file mode 100644 index 000000000000..e853fabecba0 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Alert.java @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleRole; +import com.sun.star.accessibility.*; + +public class Alert extends Dialog { + + protected Alert(java.awt.Frame owner, XAccessibleComponent xAccessibleComponent) { + super(owner, xAccessibleComponent); + } + + protected Alert(java.awt.Frame owner, String name, XAccessibleComponent xAccessibleComponent) { + super(owner, name, xAccessibleComponent); + } + + protected Alert(java.awt.Frame owner, String name, boolean modal, XAccessibleComponent xAccessibleComponent) { + super(owner, name, modal, xAccessibleComponent); + } + + /** Returns the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + accessibleContext = new AccessibleAlert(); + accessibleContext.setAccessibleName(getTitle()); + } + return accessibleContext; + } + + protected class AccessibleAlert extends AccessibleDialog { + + protected AccessibleAlert() { + super(); + } + + public AccessibleRole getAccessibleRole() { + return AccessibleRole.ALERT; + } + }; +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Application.java b/accessibility/bridge/org/openoffice/java/accessibility/Application.java new file mode 100644 index 000000000000..c67da714f4df --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Application.java @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.Accessible; +import javax.accessibility.AccessibleContext; + +public class Application extends java.awt.Frame implements Accessible { + + protected AccessibleContext accessibleContext = null; + + protected Application() { + super(); + } + + public boolean isShowing() { + return true; + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Button.java b/accessibility/bridge/org/openoffice/java/accessibility/Button.java new file mode 100644 index 000000000000..44bccc30ffc1 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Button.java @@ -0,0 +1,157 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +class Button extends AbstractButton implements javax.accessibility.Accessible { + + public Button(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleButtonListener(); + } + + protected class AccessibleButtonListener + extends AccessibleUNOComponentListener { + protected AccessibleButtonListener() { + super(); + } + + protected javax.accessibility.AccessibleContext getContext( Object any ) { + try { + XAccessible xAccessible = (XAccessible) + AnyConverter.toObject( AccessibleObjectFactory.XAccessibleType, any ); + + javax.accessibility.Accessible accessible = + (javax.accessibility.Accessible) Button.this.getComponent( xAccessible ); + + return accessible.getAccessibleContext(); + } catch( com.sun.star.uno.Exception e ) { + return null; + } + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.CHILD: + java.awt.Component c = getComponent(unoAccessible); + + Object values[] = { null, null }; + + if (AnyConverter.isObject(event.OldValue)) { + values[0] = getContext( event.OldValue ); + } + + if (AnyConverter.isObject(event.NewValue)) { + values[1] = getContext( event.NewValue); + } + + firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + values[0], values[1]); + break; + + default: + super.notifyEvent(event); + } + } + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleButton(); + } + + protected java.awt.Component getComponent(XAccessible unoAccessible) { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent(unoAccessible); + + if (c == null) { + c = AccessibleObjectFactory.createAccessibleComponent(unoAccessible); + + if (c instanceof javax.accessibility.Accessible) { + ((javax.accessibility.Accessible) c).getAccessibleContext() + .setAccessibleParent(this); + } + + if( c instanceof java.awt.Container ) { + AccessibleObjectFactory.populateContainer((java.awt.Container) c, unoAccessible.getAccessibleContext() ); + } + } + + return c; + } + + protected class AccessibleButton extends AccessibleAbstractButton { + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.PUSH_BUTTON; + } + + /** Returns the number of accessible children of the object */ + public int getAccessibleChildrenCount() { + try { + return unoAccessibleContext.getAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the specified Accessible child of the object */ + public synchronized javax.accessibility.Accessible getAccessibleChild( int i) { + try { + return (javax.accessibility.Accessible) getComponent( unoAccessibleContext.getAccessibleChild(i) ); + } catch (com.sun.star.uno.RuntimeException e) { + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } + return null; + } + + /* + * AccessibleComponent + */ + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + try { + java.awt.Component c = getComponent(unoAccessibleComponent.getAccessibleAtPoint( + new com.sun.star.awt.Point(p.x, p.y))); + + return (javax.accessibility.Accessible) c; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/CheckBox.java b/accessibility/bridge/org/openoffice/java/accessibility/CheckBox.java new file mode 100644 index 000000000000..624dfd048c89 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/CheckBox.java @@ -0,0 +1,51 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +class CheckBox extends ToggleButton { + + public CheckBox(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleCheckBox(); + } + + protected class AccessibleCheckBox extends AccessibleToggleButton { + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.CHECK_BOX; + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/ComboBox.java b/accessibility/bridge/org/openoffice/java/accessibility/ComboBox.java new file mode 100644 index 000000000000..5f5cf4a34374 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/ComboBox.java @@ -0,0 +1,117 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; + +import javax.swing.SwingConstants; + + +/** + */ +public class ComboBox extends Container { + private XAccessibleAction unoAccessibleAction = null; + + public ComboBox(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(javax.accessibility.AccessibleRole.COMBO_BOX, xAccessible, + xAccessibleContext); + } + + /** Appends the specified component to the end of this container */ + public java.awt.Component add(java.awt.Component c) { + // List should be always the first child + if (c instanceof List) { + return super.add(c, 0); + } else { + return super.add(c); + } + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleComboBox(); + } + + protected class AccessibleComboBox extends AccessibleContainer + implements javax.accessibility.AccessibleAction { + /** + * Though the class is abstract, this should be called by all sub-classes + */ + protected AccessibleComboBox() { + super(); + } + + /* + * AccessibleContext + */ + + /** Gets the AccessibleAction associated with this object that supports one or more actions */ + public javax.accessibility.AccessibleAction getAccessibleAction() { + if (unoAccessibleAction == null) { + unoAccessibleAction = (XAccessibleAction) UnoRuntime.queryInterface(XAccessibleAction.class, + unoAccessibleContext); + + if (unoAccessibleAction == null) { + return null; + } + } + + return this; + } + + /* + * AccessibleAction + */ + + /** Performs the specified Action on the object */ + public boolean doAccessibleAction(int param) { + if (param == 0) { + try { + return unoAccessibleAction.doAccessibleAction(0); + } catch (com.sun.star.uno.Exception e) { + } + } + + return false; + } + + /** Returns a description of the specified action of the object */ + public java.lang.String getAccessibleActionDescription(int param) { + return javax.swing.UIManager.getString("ComboBox.togglePopupText"); + } + + /** Returns the number of accessible actions available in this object */ + public int getAccessibleActionCount() { + return 1; + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Component.java b/accessibility/bridge/org/openoffice/java/accessibility/Component.java new file mode 100644 index 000000000000..21043e1f5098 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Component.java @@ -0,0 +1,740 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleState; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +public abstract class Component extends java.awt.Component { + public static final Type RectangleType = new Type(com.sun.star.awt.Rectangle.class); + public static final Type SelectionType = new Type(com.sun.star.awt.Selection.class); + + protected XAccessible unoAccessible; + protected XAccessibleContext unoAccessibleContext; + protected XAccessibleComponent unoAccessibleComponent; + + protected boolean disposed = false; + + protected Component(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(); + unoAccessible = xAccessible; + unoAccessibleContext = xAccessibleContext; + unoAccessibleComponent = (XAccessibleComponent) + UnoRuntime.queryInterface(XAccessibleComponent.class, xAccessibleContext); + // Add the event listener right away, because the global focus notification doesn't + // work yet .. + XAccessibleEventBroadcaster broadcaster = (XAccessibleEventBroadcaster) + UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, + unoAccessibleComponent); + if (broadcaster != null) { + broadcaster.addEventListener(createEventListener()); + } + } + + /** + * Determines whether this <code>Component</code> is showing on screen. + * This means that the component must be visible, and it must be in a + * <code>container</code> that is visible and showing. + * @see #addNotify + * @see #removeNotify + * @since JDK1.0 + */ + public boolean isShowing() { + if (isVisible()) { + java.awt.Container parent = getParent(); + return (parent == null) || parent.isShowing(); + } + return false; + } + + /** + * Makes this <code>Component</code> displayable by connecting it to a + * native screen resource. + * This method is called internally by the toolkit and should + * not be called directly by programs. + * @see #isDisplayable + * @see #removeNotify + * @since JDK1.0 + */ + public void addNotify() { + } + + /** + * Makes this <code>Component</code> undisplayable by destroying it native + * screen resource. + * This method is called by the toolkit internally and should + * not be called directly by programs. + * @see #isDisplayable + * @see #addNotify + * @since JDK1.0 + */ + public void removeNotify() { + } + + /* + * Fake the java focus handling. This is necessary to keep OOo focus + * in sync with the java focus. See java.awt.DefaultKeyboardFocusManager + * for implementation details. + **/ + + /** Requests focus for this object */ + public void requestFocus() { + } + + /** Requests focus for this object */ + public boolean requestFocus(boolean temporary) { + // Must be a no-op to make focus handling work + return true; + } + + /** Requests the focus for this object in the containing window */ + public boolean requestFocusInWindow() { + return requestFocusInWindow(false); + } + + /** Requests the focus for this object in the containing window */ + protected boolean requestFocusInWindow(boolean temporary) { + if (isFocusable() && isVisible()) { + getEventQueue().postEvent(new java.awt.event.FocusEvent(this, java.awt.event.FocusEvent.FOCUS_GAINED, temporary)); + return true; + } + return false; + } + + public Object[] getAccessibleComponents(Object[] targetSet) { + try { + java.util.ArrayList list = new java.util.ArrayList(targetSet.length); + for (int i=0; i < targetSet.length; i++) { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent( + (XAccessible) UnoRuntime.queryInterface(XAccessible.class, targetSet[i])); + if (c != null) { + list.add(c); + } + } + list.trimToSize(); + return list.toArray(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + protected java.awt.EventQueue getEventQueue() { + return java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue(); + } + + protected class PropertyChangeBroadcaster implements Runnable { + String propertyName; + Object oldValue; + Object newValue; + + public PropertyChangeBroadcaster(String name, Object param1, Object param2) { + propertyName = name; + oldValue = param1; + newValue = param2; + } + + public void run() { + // Because this code is executed in the DispatchThread, it is better to catch every + // exception that might occur + try { + AccessibleContext ac = accessibleContext; + if (ac != null) { + ac.firePropertyChange(propertyName, oldValue, newValue); + } + } catch (java.lang.Exception e) { + if (Build.DEBUG) { + System.err.println(e.getClass().getName() + " caught propagating " + propertyName + " event: " + e.getMessage()); + e.printStackTrace(); + } + } + } + } + + protected void firePropertyChange(String property, Object oldValue, Object newValue) { + getEventQueue().invokeLater(new PropertyChangeBroadcaster(property, oldValue, newValue)); + } + + protected void fireStatePropertyChange(AccessibleState state, boolean set) { + PropertyChangeBroadcaster broadcaster; + +// if (Build.DEBUG) { +// System.err.println("[" + AccessibleRoleAdapter.getAccessibleRole(unoAccessibleContext.getAccessibleRole()) + "] " + +// unoAccessibleContext.getAccessibleName() + " is " + (set ? "now " : "no longer ") + state); +// } + + if (set) { + broadcaster = new PropertyChangeBroadcaster( + accessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, state); + } else { + broadcaster = new PropertyChangeBroadcaster( + accessibleContext.ACCESSIBLE_STATE_PROPERTY, + state, null); + } + getEventQueue().invokeLater(broadcaster); + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleUNOComponentListener implements XAccessibleEventListener { + + protected AccessibleUNOComponentListener() { + } + + protected void setComponentState(short state, boolean enable) { + switch (state) { + case AccessibleStateType.ACTIVE: + // Only frames should be active + break; + case AccessibleStateType.ARMED: + fireStatePropertyChange(AccessibleState.ARMED, enable); + break; + case AccessibleStateType.CHECKED: + fireStatePropertyChange(AccessibleState.CHECKED, enable); + break; + case AccessibleStateType.ENABLED: + setEnabled(enable); + // Since we can't access awt.Componet.accessibleContext, we need to fire + // this event manually .. + fireStatePropertyChange(AccessibleState.ENABLED, enable); + break; + case AccessibleStateType.FOCUSED: + getEventQueue().postEvent(new java.awt.event.FocusEvent( + Component.this, enable ? + java.awt.event.FocusEvent.FOCUS_GAINED : + java.awt.event.FocusEvent.FOCUS_LOST)); + break; + case AccessibleStateType.PRESSED: + fireStatePropertyChange(AccessibleState.PRESSED, enable); + break; + case AccessibleStateType.SELECTED: + fireStatePropertyChange(AccessibleState.SELECTED, enable); + break; + case AccessibleStateType.SENSITIVE: + // This state equals ENABLED in OOo (but not in Gtk+) and does not exist in Java 1.5 + break; + case AccessibleStateType.SHOWING: +// fireStatePropertyChange(AccessibleState.SHOWING, enable); + break; + case AccessibleStateType.VISIBLE: + Component.this.setVisible(enable); + break; + default: + if (Build.DEBUG) { + System.err.println("[component]: " + getName() + "unexpected state change " + state); + } + break; + } + } + + /** Updates the accessible name and fires the appropriate PropertyChangedEvent */ + protected void handleNameChangedEvent(Object any) { + try { + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + if (accessibleContext != null) { + accessibleContext.setAccessibleName(AnyConverter.toString(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the accessible description and fires the appropriate PropertyChangedEvent */ + protected void handleDescriptionChangedEvent(Object any) { + try { + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + if (accessibleContext != null) { + accessibleContext.setAccessibleDescription(AnyConverter.toString(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the internal states and fires the appropriate PropertyChangedEvent */ + protected void handleStateChangedEvent(Object any1, Object any2) { + try { + if (AnyConverter.isShort(any1)) { + setComponentState(AnyConverter.toShort(any1), false); + } + + if (AnyConverter.isShort(any2)) { + setComponentState(AnyConverter.toShort(any2), true); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + + if ( !disposed ) { + + switch (event.EventId) { + case AccessibleEventId.ACTION_CHANGED: + firePropertyChange(accessibleContext.ACCESSIBLE_ACTION_PROPERTY, + toNumber(event.OldValue), toNumber(event.NewValue)); + break; + case AccessibleEventId.NAME_CHANGED: + // Set the accessible name for the corresponding context, which will fire a property + // change event itself + handleNameChangedEvent(event.NewValue); + break; + case AccessibleEventId.DESCRIPTION_CHANGED: + // Set the accessible description for the corresponding context, which will fire a property + // change event itself - so do not set propertyName ! + handleDescriptionChangedEvent(event.NewValue); + break; + case AccessibleEventId.CHILD: + if (Build.DEBUG) { + System.out.println("Unexpected child event for object of role " + getAccessibleContext().getAccessibleRole()); + } + break; + case AccessibleEventId.STATE_CHANGED: + // Update the internal state set and fire the appropriate PropertyChangedEvent + handleStateChangedEvent(event.OldValue, event.NewValue); + break; + case AccessibleEventId.VISIBLE_DATA_CHANGED: + case AccessibleEventId.BOUNDRECT_CHANGED: + firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, null, null); + break; + case AccessibleEventId.TEXT_CHANGED: + firePropertyChange(AccessibleContext.ACCESSIBLE_TEXT_PROPERTY, + AccessibleTextImpl.convertTextSegment(event.OldValue), + AccessibleTextImpl.convertTextSegment(event.NewValue)); + break; + /* + * the Java AccessBridge for GNOME maps SELECTION_PROPERTY change events + * for objects of role TEXT to object:text-selection-changed + */ + case AccessibleEventId.TEXT_SELECTION_CHANGED: + firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, null, null); + break; + case AccessibleEventId.CARET_CHANGED: + firePropertyChange(accessibleContext.ACCESSIBLE_CARET_PROPERTY, toNumber(event.OldValue), toNumber(event.NewValue)); + break; + case AccessibleEventId.VALUE_CHANGED: + firePropertyChange(accessibleContext.ACCESSIBLE_VALUE_PROPERTY, toNumber(event.OldValue), toNumber(event.NewValue)); + default: + // Warn about unhandled events + if(Build.DEBUG) { + System.out.println(this + ": unhandled accessibility event id=" + event.EventId); + } + } + } + } + + /** Called by OpenOffice process to notify that the UNO component is disposing */ + public void disposing(com.sun.star.lang.EventObject eventObject) { + disposed = true; + AccessibleObjectFactory.disposing(Component.this); + } + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleUNOComponentListener(); + } + + protected javax.accessibility.AccessibleContext accessibleContext = null; + + /** This method actually creates the AccessibleContext object returned by + * getAccessibleContext(). + */ + protected javax.accessibility.AccessibleContext createAccessibleContext() { + return null; + } + + /** Returns the AccessibleContext associated with this object */ + public final javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + try { + AccessibleContext ac = createAccessibleContext(); + if (ac != null) { + // Set accessible name and description here to avoid + // unnecessary property change events later .. + ac.setAccessibleName(unoAccessibleContext.getAccessibleName()); + ac.setAccessibleDescription(unoAccessibleContext.getAccessibleDescription()); + accessibleContext = ac; + } + } catch (com.sun.star.uno.RuntimeException e) { + } + } + return accessibleContext; + } + + protected abstract class AccessibleUNOComponent extends java.awt.Component.AccessibleAWTComponent + implements javax.accessibility.AccessibleExtendedComponent { + + protected java.awt.event.ComponentListener accessibleComponentHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when shown/hidden.. + */ + protected class AccessibleComponentHandler implements java.awt.event.ComponentListener { + public void componentHidden(java.awt.event.ComponentEvent e) { + AccessibleUNOComponent.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + AccessibleState.VISIBLE, null); + } + + public void componentShown(java.awt.event.ComponentEvent e) { + AccessibleUNOComponent.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, AccessibleState.VISIBLE); + } + + public void componentMoved(java.awt.event.ComponentEvent e) { + } + + public void componentResized(java.awt.event.ComponentEvent e) { + } + } // inner class AccessibleComponentHandler + + protected java.awt.event.FocusListener accessibleFocusHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when focus events happen + */ + protected class AccessibleFocusHandler implements java.awt.event.FocusListener { + public void focusGained(java.awt.event.FocusEvent event) { + AccessibleUNOComponent.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, AccessibleState.FOCUSED); + if (Build.DEBUG) { + System.err.println("[" + getAccessibleRole() + "] " + getAccessibleName() + " is now focused"); + } + } + public void focusLost(java.awt.event.FocusEvent event) { + AccessibleUNOComponent.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + AccessibleState.FOCUSED, null); + if (Build.DEBUG) { + System.err.println("[" + getAccessibleRole() + "] " + getAccessibleName() + " is no longer focused"); + } + } + } // inner class AccessibleFocusHandler + + protected int propertyChangeListenerCount = 0; + + /** + * Add a PropertyChangeListener to the listener list. + * + * @param listener The PropertyChangeListener to be added + */ + public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (propertyChangeListenerCount++ == 0) { + accessibleComponentHandler = new AccessibleComponentHandler(); + Component.this.addComponentListener(accessibleComponentHandler); + + accessibleFocusHandler = new AccessibleFocusHandler(); + Component.this.addFocusListener(accessibleFocusHandler); + } + super.addPropertyChangeListener(listener); + } + + /** + * Remove a PropertyChangeListener from the listener list. + * This removes a PropertyChangeListener that was registered + * for all properties. + * + * @param listener The PropertyChangeListener to be removed + */ + public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (--propertyChangeListenerCount == 0) { + Component.this.removeComponentListener(accessibleComponentHandler); + accessibleComponentHandler = null; + + Component.this.removeFocusListener(accessibleFocusHandler); + accessibleFocusHandler = null; + } + super.removePropertyChangeListener(listener); + } + + /** + * Gets the current state set of this object. + * + * @return an instance of <code>AccessibleStateSet</code> + * containing the current state set of the object + * @see AccessibleState + */ + public javax.accessibility.AccessibleStateSet getAccessibleStateSet() { + if (disposed) + return AccessibleStateAdapter.getDefunctStateSet(); + + try { + return AccessibleStateAdapter.getAccessibleStateSet(Component.this, + unoAccessibleContext.getAccessibleStateSet()); + } catch (com.sun.star.uno.RuntimeException e) { + return AccessibleStateAdapter.getDefunctStateSet(); + } + } + + /** Gets the locale of the component */ + public java.util.Locale getLocale() throws java.awt.IllegalComponentStateException { + try { + com.sun.star.lang.Locale unoLocale = unoAccessible.getAccessibleContext().getLocale(); + return new java.util.Locale(unoLocale.Language, unoLocale.Country); + } catch (IllegalAccessibleComponentStateException e) { + throw new java.awt.IllegalComponentStateException(e.getMessage()); + } catch (com.sun.star.uno.RuntimeException e) { + return java.util.Locale.getDefault(); + } + } + + /* + * AccessibleExtendedComponent + */ + + /** Returns the background color of the object */ + public java.awt.Color getBackground() { + try { + return new java.awt.Color(unoAccessibleComponent.getBackground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setBackground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + /** Returns the foreground color of the object */ + public java.awt.Color getForeground() { + try { + return new java.awt.Color(unoAccessibleComponent.getForeground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setForeground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + public java.awt.Cursor getCursor() { + // Not supported by UNO accessibility API + return null; + } + + public void setCursor(java.awt.Cursor cursor) { + // Not supported by UNO accessibility API + } + + public java.awt.Font getFont() { + // FIXME + return null; + } + + public void setFont(java.awt.Font f) { + // Not supported by UNO accessibility API + } + + public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { + // FIXME + return null; + } + + public boolean isEnabled() { + return Component.this.isEnabled(); + } + + public void setEnabled(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isVisible() { + return Component.this.isVisible(); + } + + public void setVisible(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isShowing() { + return Component.this.isShowing(); + } + + public boolean contains(java.awt.Point p) { + try { + return unoAccessibleComponent.containsPoint(new com.sun.star.awt.Point(p.x, p.y)); + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Returns the location of the object on the screen. */ + public java.awt.Point getLocationOnScreen() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocationOnScreen(); +// if (Build.DEBUG) { +// System.err.println("Returning location on screen( " + unoPoint.X + ", " + unoPoint.Y + " )" ); +// } + return new java.awt.Point(unoPoint.X, unoPoint.Y); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the location of this component in the form of a point specifying the component's top-left corner */ + public java.awt.Point getLocation() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocation(); + return new java.awt.Point( unoPoint.X, unoPoint.Y ); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves this component to a new location */ + public void setLocation(java.awt.Point p) { + // Not supported by UNO accessibility API + } + + /** Gets the bounds of this component in the form of a Rectangle object */ + public java.awt.Rectangle getBounds() { + try { + com.sun.star.awt.Rectangle unoRect = unoAccessibleComponent.getBounds(); + return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves and resizes this component to conform to the new bounding rectangle r */ + public void setBounds(java.awt.Rectangle r) { + // Not supported by UNO accessibility API + } + + /** Returns the size of this component in the form of a Dimension object */ + public java.awt.Dimension getSize() { + try { + com.sun.star.awt.Size unoSize = unoAccessibleComponent.getSize(); + return new java.awt.Dimension(unoSize.Width, unoSize.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Resizes this component so that it has width d.width and height d.height */ + public void setSize(java.awt.Dimension d) { + // Not supported by UNO accessibility API + } + + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + // Not supported by this implementation + return null; + } + + public boolean isFocusTraversable() { + return Component.this.isFocusable(); + } + + public void requestFocus() { + unoAccessibleComponent.grabFocus(); + } + + public String getToolTipText() { + try { + XAccessibleExtendedComponent unoAccessibleExtendedComponent = (XAccessibleExtendedComponent) + UnoRuntime.queryInterface(XAccessibleExtendedComponent.class, unoAccessibleComponent); + if (unoAccessibleExtendedComponent != null) { + return unoAccessibleExtendedComponent.getToolTipText(); + } + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + return null; + } + + public String getTitledBorderText() { + try { + XAccessibleExtendedComponent unoAccessibleExtendedComponent = (XAccessibleExtendedComponent) + UnoRuntime.queryInterface(XAccessibleExtendedComponent.class, unoAccessibleComponent); + if (unoAccessibleExtendedComponent != null) { + return unoAccessibleExtendedComponent.getTitledBorderText(); + } + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + return null; + } + + public javax.accessibility.AccessibleKeyBinding getAccessibleKeyBinding() { + try { + XAccessibleAction unoAccessibleAction = (XAccessibleAction) + UnoRuntime.queryInterface(XAccessibleAction.class, unoAccessibleComponent); + if (unoAccessibleAction != null) { + XAccessibleKeyBinding unoAccessibleKeyBinding = unoAccessibleAction.getAccessibleActionKeyBinding(0); + if (unoAccessibleKeyBinding != null) { + return new AccessibleKeyBinding(unoAccessibleKeyBinding); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + return null; + } + } + + // Extract a number from a UNO any + public static java.lang.Number toNumber(java.lang.Object any) { + try { + if (AnyConverter.isByte(any)) { + return new Byte(AnyConverter.toByte(any)); + } else if (AnyConverter.isShort(any)) { + return new Short(AnyConverter.toShort(any)); + } else if (AnyConverter.isInt(any)) { + return new Integer(AnyConverter.toInt(any)); + } else if (AnyConverter.isLong(any)) { + return new Long(AnyConverter.toLong(any)); + } else if (AnyConverter.isFloat(any)) { + return new Float(AnyConverter.toFloat(any)); + } else if (AnyConverter.isDouble(any)) { + return new Double(AnyConverter.toDouble(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new IllegalArgumentException(e.getMessage()); + } + return null; + } + + public String toString() { + return UnoRuntime.generateOid(unoAccessible); + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Container.java b/accessibility/bridge/org/openoffice/java/accessibility/Container.java new file mode 100644 index 000000000000..257cdab8b757 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Container.java @@ -0,0 +1,763 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleState; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +public class Container extends java.awt.Container implements javax.accessibility.Accessible { + + protected XAccessible unoAccessible; + protected XAccessibleContext unoAccessibleContext; + protected XAccessibleComponent unoAccessibleComponent = null; + + protected javax.accessibility.AccessibleRole accessibleRole; + protected javax.accessibility.AccessibleText accessibleText; + protected boolean disposed = false; + + protected Container(javax.accessibility.AccessibleRole role, + XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + accessibleRole = role; + unoAccessible = xAccessible; + unoAccessibleContext = xAccessibleContext; + unoAccessibleComponent = (XAccessibleComponent) + UnoRuntime.queryInterface(XAccessibleComponent.class, + xAccessibleContext); + + // Add the event listener right away, because the global focus notification doesn't + // work yet .. + XAccessibleEventBroadcaster broadcaster = (XAccessibleEventBroadcaster) + UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, + unoAccessibleContext); + if (broadcaster != null) { + broadcaster.addEventListener(createEventListener()); + } + } + + /** + * Determines whether this <code>Container</code> is showing on screen. + * This means that the component must be visible, and it must be in a + * <code>container</code> that is visible and showing. + * @see #addNotify + * @see #removeNotify + * @since JDK1.0 + */ + public boolean isShowing() { + if (isVisible()) { + java.awt.Container parent = getParent(); + return (parent == null) || parent.isShowing(); + } + return false; + } + + /** + * Makes this <code>Container</code> displayable by connecting it to a + * native screen resource. + * This method is called internally by the toolkit and should + * not be called directly by programs. + * @see #isDisplayable + * @see #removeNotify + * @since JDK1.0 + */ + public void addNotify() { + } + + /** + * Makes this <code>Container</code> undisplayable by destroying it native + * screen resource. + * This method is called by the toolkit internally and should + * not be called directly by programs. + * @see #isDisplayable + * @see #addNotify + * @since JDK1.0 + */ + public void removeNotify() { + } + + /* + * Fake the java focus handling. This is necessary to keep OOo focus + * in sync with the java focus. See java.awt.DefaultKeyboardFocusManager + * for implementation details. + **/ + + /** Requests focus for this object */ + public void requestFocus() { + } + + /** Requests focus for this object */ + public boolean requestFocus(boolean temporary) { + // Must be a no-op to make focus handling work + return true; + } + + /** Requests the focus for this object in the containing window */ + public boolean requestFocusInWindow() { + return requestFocusInWindow(false); + } + + /** Requests the focus for this object in the containing window */ + protected boolean requestFocusInWindow(boolean temporary) { + if (isFocusable() && isVisible()) { + getEventQueue().postEvent(new java.awt.event.FocusEvent(this, java.awt.event.FocusEvent.FOCUS_GAINED, temporary)); + return true; + } + return false; + } + + public Object[] getAccessibleComponents(Object[] targetSet) { + try { + java.util.ArrayList list = new java.util.ArrayList(targetSet.length); + for (int i=0; i < targetSet.length; i++) { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent( + (XAccessible) UnoRuntime.queryInterface(XAccessible.class, targetSet[i])); + if (c != null) { + list.add(c); + } + } + list.trimToSize(); + return list.toArray(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + protected java.awt.EventQueue getEventQueue() { + return java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue(); + } + + protected class PropertyChangeBroadcaster implements Runnable { + String propertyName; + Object oldValue; + Object newValue; + + public PropertyChangeBroadcaster(String name, Object param1, Object param2) { + propertyName = name; + oldValue = param1; + newValue = param2; + } + + public void run() { + // Because this code is executed in the DispatchThread, it is better tocatch every + // exception that might occur + try { + AccessibleContext ac = Container.this.accessibleContext; + if (ac != null) { + ac.firePropertyChange(propertyName, oldValue, newValue); + } + } catch (java.lang.Exception e) { + if (Build.DEBUG) { + System.err.println(e.getClass().getName() + " caught propagating " + propertyName + " event: " + e.getMessage()); + e.printStackTrace(); + } + } + } + } + + protected void firePropertyChange(String property, Object oldValue, Object newValue) { + getEventQueue().invokeLater(new PropertyChangeBroadcaster(property, oldValue, newValue)); + } + + protected void fireStatePropertyChange(AccessibleState state, boolean set) { + PropertyChangeBroadcaster broadcaster; + if (set) { + broadcaster = new PropertyChangeBroadcaster( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, state); + } else { + broadcaster = new PropertyChangeBroadcaster( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + state, null); + } + getEventQueue().invokeLater(broadcaster); + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleContainerListener implements XAccessibleEventListener { + + protected AccessibleContainerListener() { + } + + protected java.awt.EventQueue getEventQueue() { + return java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue(); + } + + protected void setComponentState(short state, boolean enable) { + switch (state) { + case AccessibleStateType.ACTIVE: + // Only frames should be active + break; + case AccessibleStateType.ENABLED: + setEnabled(enable); + // Since we can't access awt.Componet.accessibleContext, we need to fire + // this event manually .. + fireStatePropertyChange(AccessibleState.ENABLED, enable); + break; + case AccessibleStateType.FOCUSED: + getEventQueue().postEvent(new java.awt.event.FocusEvent( + Container.this, enable ? + java.awt.event.FocusEvent.FOCUS_GAINED : + java.awt.event.FocusEvent.FOCUS_LOST)); + break; + case AccessibleStateType.SELECTED: + fireStatePropertyChange(AccessibleState.SELECTED, enable); + break; + case AccessibleStateType.SENSITIVE: + // This state equals ENABLED in OOo (but not in Gtk+) and does not exist in Java 1.5 + break; + case AccessibleStateType.SHOWING: + case AccessibleStateType.VISIBLE: + setVisible(enable); + break; + default: + if (Build.DEBUG) { + System.err.println(Container.this + "unexpected state change " + state); + } + break; + } + } + /** Updates the accessible name and fires the appropriate PropertyChangedEvent */ + protected void handleNameChangedEvent(Object any) { + try { + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + if (accessibleContext != null) { + accessibleContext.setAccessibleName(AnyConverter.toString(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the accessible description and fires the appropriate PropertyChangedEvent */ + protected void handleDescriptionChangedEvent(Object any) { + try { + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + if (accessibleContext != null) { + accessibleContext.setAccessibleDescription(AnyConverter.toString(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the internal states and fires the appropriate PropertyChangedEvent */ + protected void handleStateChangedEvent(Object any1, Object any2) { + try { + if (AnyConverter.isShort(any1)) { + setComponentState(AnyConverter.toShort(any1), false); + } + + if (AnyConverter.isShort(any2)) { + setComponentState(AnyConverter.toShort(any2), true); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /* This event is only necessary because some objects in the office don't know their parent + * and are therefor unable to revoke and re-insert themselves. + */ + protected void handleAllChildrenChangedEvent() { + javax.accessibility.Accessible parent = (javax.accessibility.Accessible) getParent(); + if (parent != null) { + javax.accessibility.AccessibleContext parentAC = parent.getAccessibleContext(); + if (parentAC != null) { + + parentAC.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + Container.this, + null); + + AccessibleObjectFactory.clearContainer(Container.this); + AccessibleObjectFactory.populateContainer(Container.this, unoAccessibleContext); + + parentAC.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, + Container.this); + } + } + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + + if ( !disposed ) { + + switch (event.EventId) { + case AccessibleEventId.NAME_CHANGED: + // Set the accessible name for the corresponding context, which will fire a property + // change event itself + handleNameChangedEvent(event.NewValue); + break; + case AccessibleEventId.DESCRIPTION_CHANGED: + // Set the accessible description for the corresponding context, which will fire a property + // change event itself - so do not set propertyName ! + handleDescriptionChangedEvent(event.NewValue); + break; + case AccessibleEventId.STATE_CHANGED: + // Update the internal state set and fire the appropriate PropertyChangedEvent + handleStateChangedEvent(event.OldValue, event.NewValue); + break; + case AccessibleEventId.TEXT_CHANGED: + firePropertyChange(AccessibleContext.ACCESSIBLE_TEXT_PROPERTY, + AccessibleTextImpl.convertTextSegment(event.OldValue), + AccessibleTextImpl.convertTextSegment(event.NewValue)); + break; + case AccessibleEventId.CHILD: + if (AnyConverter.isObject(event.OldValue)) { + AccessibleObjectFactory.removeChild(Container.this, event.OldValue); + } else if (AnyConverter.isObject(event.NewValue)) { + AccessibleObjectFactory.addChild(Container.this, event.NewValue); + } + break; + case AccessibleEventId.VISIBLE_DATA_CHANGED: + case AccessibleEventId.BOUNDRECT_CHANGED: + firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, null, null); + break; + /* + * the Java AccessBridge for GNOME maps SELECTION_PROPERTY change events + * for objects of role TEXT to object:text-selection-changed + */ + case AccessibleEventId.TEXT_SELECTION_CHANGED: + case AccessibleEventId.SELECTION_CHANGED: + firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, null, null); + break; + case AccessibleEventId.INVALIDATE_ALL_CHILDREN: + handleAllChildrenChangedEvent(); + break; + default: + // Warn about unhandled events + if(Build.DEBUG) { + System.out.println(this + ": unhandled accessibility event id=" + event.EventId); + } + } + } + } + + /** Called by OpenOffice process to notify that the UNO component is disposing */ + public void disposing(com.sun.star.lang.EventObject eventObject) { + disposed = true; + AccessibleObjectFactory.disposing(Container.this); + } + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleContainerListener(); + } + + protected javax.accessibility.AccessibleContext accessibleContext = null; + + /** This method actually creates the AccessibleContext object returned by + * getAccessibleContext(). + */ + protected javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleContainer(); + } + + /** Returns the AccessibleContext associated with this object */ + public final javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + try { + AccessibleContext ac = createAccessibleContext(); + if (ac != null) { + // Set accessible name and description here to avoid + // unnecessary property change events later .. + ac.setAccessibleName(unoAccessibleContext.getAccessibleName()); + ac.setAccessibleDescription(unoAccessibleContext.getAccessibleDescription()); + accessibleContext = ac; + } + } catch (com.sun.star.uno.RuntimeException e) { + } + } + return accessibleContext; + } + + protected class AccessibleContainer extends java.awt.Container.AccessibleAWTContainer { + + protected AccessibleContainer() { + /* Since getAccessibleText() is heavily used by the java access + * bridge for gnome and the gnome at-tools, we do a query interface + * here and remember the result. + */ + accessibleText = AccessibleTextImpl.get(unoAccessibleContext); + } + + protected AccessibleContainer(boolean query) { + /* This constructor is explicitly for subclasses that implement + * AccessibleHypertext and therefor the default constructor would + * bring unnecessary overhead. + */ + } + + protected java.awt.event.ComponentListener accessibleComponentHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when shown/hidden.. + */ + protected class AccessibleComponentHandler implements java.awt.event.ComponentListener { + public void componentHidden(java.awt.event.ComponentEvent e) { + AccessibleContainer.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + AccessibleState.VISIBLE, null); + } + + public void componentShown(java.awt.event.ComponentEvent e) { + AccessibleContainer.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, AccessibleState.VISIBLE); + } + + public void componentMoved(java.awt.event.ComponentEvent e) { + } + + public void componentResized(java.awt.event.ComponentEvent e) { + } + } // inner class AccessibleContainerHandler + + protected java.awt.event.FocusListener accessibleFocusHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when focus events happen + */ + protected class AccessibleFocusHandler implements java.awt.event.FocusListener { + public void focusGained(java.awt.event.FocusEvent event) { + AccessibleContainer.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, AccessibleState.FOCUSED); + if (Build.DEBUG) { + System.err.println("[" + getAccessibleRole() + "] " + getAccessibleName() + " is now focused"); + } + } + public void focusLost(java.awt.event.FocusEvent event) { + AccessibleContainer.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + AccessibleState.FOCUSED, null); + if (Build.DEBUG) { + System.err.println("[" + getAccessibleRole() + "] " + getAccessibleName() + " is no longer focused"); + } + } + } // inner class AccessibleFocusHandler + + protected java.awt.event.ContainerListener accessibleContainerHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when children added/removed. + */ + + protected class AccessibleContainerHandler implements java.awt.event.ContainerListener { + public void componentAdded(java.awt.event.ContainerEvent e) { + java.awt.Component c = e.getChild(); + if (c != null && c instanceof javax.accessibility.Accessible) { + AccessibleContainer.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, ((javax.accessibility.Accessible) c).getAccessibleContext()); + } + } + public void componentRemoved(java.awt.event.ContainerEvent e) { + java.awt.Component c = e.getChild(); + if (c != null && c instanceof javax.accessibility.Accessible) { + AccessibleContainer.this.firePropertyChange( + AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + ((javax.accessibility.Accessible) c).getAccessibleContext(), null); + } + } + } + + protected int propertyChangeListenerCount = 0; + + /** + * Add a PropertyChangeListener to the listener list. + * + * @param listener The PropertyChangeListener to be added + */ + public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (propertyChangeListenerCount++ == 0) { + accessibleFocusHandler = new AccessibleFocusHandler(); + Container.this.addFocusListener(accessibleFocusHandler); + + accessibleContainerHandler = new AccessibleContainerHandler(); + Container.this.addContainerListener(accessibleContainerHandler); + + accessibleComponentHandler = new AccessibleComponentHandler(); + Container.this.addComponentListener(accessibleComponentHandler); + } + super.addPropertyChangeListener(listener); + } + + /** + * Remove a PropertyChangeListener from the listener list. + * This removes a PropertyChangeListener that was registered + * for all properties. + * + * @param listener The PropertyChangeListener to be removed + */ + public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (--propertyChangeListenerCount == 0) { + Container.this.removeComponentListener(accessibleComponentHandler); + accessibleComponentHandler = null; + + Container.this.removeContainerListener(accessibleContainerHandler); + accessibleContainerHandler = null; + + Container.this.removeFocusListener(accessibleFocusHandler); + accessibleFocusHandler = null; + } + super.removePropertyChangeListener(listener); + } + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return accessibleRole; + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleText getAccessibleText() { + + if (disposed) + return null; + + return accessibleText; + } + + /** + * Gets the current state set of this object. + * + * @return an instance of <code>AccessibleStateSet</code> + * containing the current state set of the object + * @see AccessibleState + */ + public javax.accessibility.AccessibleStateSet getAccessibleStateSet() { + if (disposed) + return AccessibleStateAdapter.getDefunctStateSet(); + + try { + return AccessibleStateAdapter.getAccessibleStateSet(Container.this, + unoAccessibleContext.getAccessibleStateSet()); + } catch (com.sun.star.uno.RuntimeException e) { + return AccessibleStateAdapter.getDefunctStateSet(); + } + } + + /** Returns the AccessibleSelection interface for this object */ + public javax.accessibility.AccessibleSelection getAccessibleSelection() { + try { + XAccessibleSelection unoAccessibleSelection = (XAccessibleSelection) + UnoRuntime.queryInterface(XAccessibleSelection.class, unoAccessibleContext); + if (unoAccessibleSelection != null) { + return new AccessibleSelectionImpl(unoAccessibleSelection); + } + } catch (com.sun.star.uno.RuntimeException e) { + } + + return null; + } + + /** Gets the locale of the component */ + public java.util.Locale getLocale() throws java.awt.IllegalComponentStateException { + try { + com.sun.star.lang.Locale unoLocale = unoAccessible.getAccessibleContext().getLocale(); + return new java.util.Locale(unoLocale.Language, unoLocale.Country); + } catch (IllegalAccessibleComponentStateException e) { + throw new java.awt.IllegalComponentStateException(e.getMessage()); + } catch (com.sun.star.uno.RuntimeException e) { + return super.getLocale(); + } + } + + /* + * AccessibleComponent + */ + + /** Returns the background color of the object */ + public java.awt.Color getBackground() { + try { + return new java.awt.Color(unoAccessibleComponent.getBackground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setBackground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + /** Returns the foreground color of the object */ + public java.awt.Color getForeground() { + try { + return new java.awt.Color(unoAccessibleComponent.getForeground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setForeground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + public java.awt.Cursor getCursor() { + // Not supported by UNO accessibility API + return null; + } + + public void setCursor(java.awt.Cursor cursor) { + // Not supported by UNO accessibility API + } + + public java.awt.Font getFont() { + // FIXME + return null; + } + + public void setFont(java.awt.Font f) { + // Not supported by UNO accessibility API + } + + public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { + // FIXME + return null; + } + + public boolean isEnabled() { + return Container.this.isEnabled(); + } + + public void setEnabled(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isVisible() { + return Container.this.isVisible(); + } + + public void setVisible(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isShowing() { + return Container.this.isShowing(); + } + + public boolean contains(java.awt.Point p) { + try { + return unoAccessibleComponent.containsPoint(new com.sun.star.awt.Point(p.x, p.y)); + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Returns the location of the object on the screen. */ + public java.awt.Point getLocationOnScreen() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocationOnScreen(); + return new java.awt.Point(unoPoint.X, unoPoint.Y); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the location of this component in the form of a point specifying the component's top-left corner */ + public java.awt.Point getLocation() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocation(); + return new java.awt.Point( unoPoint.X, unoPoint.Y ); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves this component to a new location */ + public void setLocation(java.awt.Point p) { + // Not supported by UNO accessibility API + } + + /** Gets the bounds of this component in the form of a Rectangle object */ + public java.awt.Rectangle getBounds() { + try { + com.sun.star.awt.Rectangle unoRect = unoAccessibleComponent.getBounds(); + return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves and resizes this component to conform to the new bounding rectangle r */ + public void setBounds(java.awt.Rectangle r) { + // Not supported by UNO accessibility API + } + + /** Returns the size of this component in the form of a Dimension object */ + public java.awt.Dimension getSize() { + try { + com.sun.star.awt.Size unoSize = unoAccessibleComponent.getSize(); + return new java.awt.Dimension(unoSize.Width, unoSize.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Resizes this component so that it has width d.width and height d.height */ + public void setSize(java.awt.Dimension d) { + // Not supported by UNO accessibility API + } + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + try { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent( + unoAccessibleComponent.getAccessibleAtPoint(new com.sun.star.awt.Point(p.x, p.y))); + + return (javax.accessibility.Accessible) c; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public boolean isFocusTraversable() { + return Container.this.isFocusable(); + } + + public void requestFocus() { + unoAccessibleComponent.grabFocus(); + } + } + + public String toString() { + return UnoRuntime.generateOid(unoAccessible); + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/DescendantManager.java b/accessibility/bridge/org/openoffice/java/accessibility/DescendantManager.java new file mode 100644 index 000000000000..5b8c45b716b4 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/DescendantManager.java @@ -0,0 +1,161 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; + +import javax.accessibility.AccessibleState; + + +public abstract class DescendantManager extends Component { + protected XAccessibleSelection unoAccessibleSelection = null; + protected javax.accessibility.Accessible activeDescendant = null; + protected boolean multiselectable = false; + + protected DescendantManager(XAccessible xAccessible, + XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + protected DescendantManager(XAccessible xAccessible, + XAccessibleContext xAccessibleContext, boolean multiselectable) { + super(xAccessible, xAccessibleContext); + this.multiselectable = multiselectable; + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleDescendantManagerListener + extends AccessibleUNOComponentListener { + protected AccessibleDescendantManagerListener() { + unoAccessibleSelection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, + unoAccessibleContext); + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.SELECTION_CHANGED: + firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, + null, null); + + break; + + default: + super.notifyEvent(event); + } + } + } + + protected abstract class AccessibleDescendantManager + extends AccessibleUNOComponent + implements javax.accessibility.AccessibleSelection { + protected AccessibleDescendantManager() { + unoAccessibleSelection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, + unoAccessibleContext); + } + + /* + * AccessibleContext + */ + + /** Returns the number of accessible children of the object */ + public int getAccessibleChildrenCount() { + try { + return unoAccessibleContext.getAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the AccessibleSelection interface for this object */ + public javax.accessibility.AccessibleSelection getAccessibleSelection() { + return (unoAccessibleSelection != null) ? this : null; + } + + /* + * AccessibleSelection + */ + + /** Adds the specified Accessible child of the object to the object's selection */ + public void addAccessibleSelection(int i) { + try { + unoAccessibleSelection.selectAccessibleChild(i); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Clears the selection in the object, so that no children in the object are selected */ + public void clearAccessibleSelection() { + try { + unoAccessibleSelection.clearAccessibleSelection(); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Returns the number of Accessible children currently selected */ + public int getAccessibleSelectionCount() { + try { + return unoAccessibleSelection.getSelectedAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Determines if the current child of this object is selected */ + public boolean isAccessibleChildSelected(int i) { + try { + return unoAccessibleSelection.isAccessibleChildSelected(i); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Removes the specified child of the object from the object's selection */ + public void removeAccessibleSelection(int i) { + try { + unoAccessibleSelection.deselectAccessibleChild(i); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Causes every child of the object to be selected if the object supports multiple selection */ + public void selectAllAccessibleSelection() { + try { + unoAccessibleSelection.selectAllAccessibleChildren(); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Dialog.java b/accessibility/bridge/org/openoffice/java/accessibility/Dialog.java new file mode 100644 index 000000000000..dcb067368996 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Dialog.java @@ -0,0 +1,633 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleState; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +public class Dialog extends java.awt.Dialog implements javax.accessibility.Accessible, NativeFrame { + protected XAccessibleComponent unoAccessibleComponent; + + boolean opened = false; + boolean visible = false; + boolean active = false; + + java.awt.EventQueue eventQueue = null; + + protected Dialog(java.awt.Frame owner, XAccessibleComponent xAccessibleComponent) { + super(owner); + initialize(xAccessibleComponent); + } + + protected Dialog(java.awt.Frame owner, String name, XAccessibleComponent xAccessibleComponent) { + super(owner, name); + initialize(xAccessibleComponent); + } + + protected Dialog(java.awt.Frame owner, String name, boolean modal, XAccessibleComponent xAccessibleComponent) { + super(owner, name, modal); + initialize(xAccessibleComponent); + } + + private void initialize(XAccessibleComponent xAccessibleComponent) { + unoAccessibleComponent = xAccessibleComponent; + eventQueue = java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue(); + XAccessibleEventBroadcaster broadcaster = (XAccessibleEventBroadcaster) + UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, + xAccessibleComponent); + if (broadcaster != null) { + broadcaster.addEventListener(new AccessibleDialogListener()); + } + } + + java.awt.Component initialComponent = null; + + public java.awt.Component getInitialComponent() { + return initialComponent; + } + + public void setInitialComponent(java.awt.Component c) { + initialComponent = c; + } + + public Integer getHWND() { + return null; + } + + /** + * Determines whether this <code>Component</code> is showing on screen. + * This means that the component must be visible, and it must be in a + * <code>container</code> that is visible and showing. + * @see #addNotify + * @see #removeNotify + * @since JDK1.0 + */ + public boolean isShowing() { + if (isVisible()) { + java.awt.Container parent = getParent(); + return (parent == null) || parent.isShowing(); + } + return false; + } + + /** + * Makes this <code>Component</code> displayable by connecting it to a + * native screen resource. + * This method is called internally by the toolkit and should + * not be called directly by programs. + * @see #isDisplayable + * @see #removeNotify + * @since JDK1.0 + */ + public void addNotify() { +// createHierarchyEvents(0, null, null, 0, false); + } + + /** + * Makes this <code>Component</code> undisplayable by destroying it native + * screen resource. + * This method is called by the toolkit internally and should + * not be called directly by programs. + * @see #isDisplayable + * @see #addNotify + * @since JDK1.0 + */ + public void removeNotify() { + } + + /** + * Determines if the object is visible. Note: this means that the + * object intends to be visible; however, it may not in fact be + * showing on the screen because one of the objects that this object + * is contained by is not visible. To determine if an object is + * showing on the screen, use <code>isShowing</code>. + * + * @return true if object is visible; otherwise, false + */ + public boolean isVisible(){ + return visible; + } + + /** + * Shows or hides this component depending on the value of parameter + * <code>b</code>. + * @param b if <code>true</code>, shows this component; + * otherwise, hides this component + * @see #isVisible + * @since JDK1.1 + */ + public void setVisible(boolean b) { + if (visible != b){ + visible = b; + if (b) { + // If it is the first show, fire WINDOW_OPENED event + if (!opened) { + postWindowEvent(java.awt.event.WindowEvent.WINDOW_OPENED); + opened = true; + } + postComponentEvent(java.awt.event.ComponentEvent.COMPONENT_SHOWN); + } else { + postComponentEvent(java.awt.event.ComponentEvent.COMPONENT_HIDDEN); + } + } + } + + public void dispose() { + setVisible(false); + postWindowEvent(java.awt.event.WindowEvent.WINDOW_CLOSED); + } + + protected void postWindowEvent(int i) { + eventQueue.postEvent(new java.awt.event.WindowEvent(this, i)); + } + + protected void postComponentEvent(int i) { + eventQueue.postEvent(new java.awt.event.ComponentEvent(this, i)); + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleDialogListener implements XAccessibleEventListener { + + protected AccessibleDialogListener() { + } + + protected void setComponentState(short state, boolean enable) { + switch (state) { + case AccessibleStateType.ACTIVE: + active = enable; + if (enable) { + AccessibleObjectFactory.postWindowActivated(Dialog.this); + } else { + AccessibleObjectFactory.postWindowLostFocus(Dialog.this); + } + break; + case AccessibleStateType.ICONIFIED: + postWindowEvent(enable ? + java.awt.event.WindowEvent.WINDOW_ICONIFIED : + java.awt.event.WindowEvent.WINDOW_DEICONIFIED); + break; + case AccessibleStateType.VISIBLE: + Dialog.this.setVisible(enable); + break; + default: + if (Build.DEBUG) { + System.err.println("[dialog]: " + getTitle() + "unexpected state change " + state); + } + break; + } + } + + /** Updates the accessible name and fires the appropriate PropertyChangedEvent */ + protected void handleNameChangedEvent(Object any) { + try { + String title = AnyConverter.toString(any); + setTitle(title); + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + javax.accessibility.AccessibleContext ac = accessibleContext; + if (ac!= null) { + ac.setAccessibleName(title); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the accessible description and fires the appropriate PropertyChangedEvent */ + protected void handleDescriptionChangedEvent(Object any) { + try { + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + javax.accessibility.AccessibleContext ac = accessibleContext; + if (ac!= null) { + ac.setAccessibleDescription(AnyConverter.toString(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the internal states and fires the appropriate PropertyChangedEvent */ + protected void handleStateChangedEvent(Object any1, Object any2) { + try { + if (AnyConverter.isShort(any1)) { + setComponentState(AnyConverter.toShort(any1), false); + } + + if (AnyConverter.isShort(any2)) { + setComponentState(AnyConverter.toShort(any2), true); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Fires a visible data property change event */ + protected void handleVisibleDataEvent() { + javax.accessibility.AccessibleContext ac = accessibleContext; + if (ac != null) { + ac.firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, null, null); + } + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.NAME_CHANGED: + // Set the accessible name for the corresponding context, which will fire a property + // change event itself + handleNameChangedEvent(event.NewValue); + break; + case AccessibleEventId.DESCRIPTION_CHANGED: + // Set the accessible description for the corresponding context, which will fire a property + // change event itself - so do not set propertyName ! + handleDescriptionChangedEvent(event.NewValue); + break; + case AccessibleEventId.STATE_CHANGED: + // Update the internal state set and fire the appropriate PropertyChangedEvent + handleStateChangedEvent(event.OldValue, event.NewValue); + break; + case AccessibleEventId.CHILD: + if (AnyConverter.isObject(event.OldValue)) { + AccessibleObjectFactory.removeChild(Dialog.this, event.OldValue); + } else if (AnyConverter.isObject(event.NewValue)) { + AccessibleObjectFactory.addChild(Dialog.this, event.NewValue); + } + break; + case AccessibleEventId.VISIBLE_DATA_CHANGED: + case AccessibleEventId.BOUNDRECT_CHANGED: + handleVisibleDataEvent(); + break; + default: + // Warn about unhandled events + if(Build.DEBUG) { + System.out.println(this + ": unhandled accessibility event id=" + event.EventId); + } + } + } + + /** Called by OpenOffice process to notify that the UNO component is disposing */ + public void disposing(com.sun.star.lang.EventObject eventObject) { + } + } + + javax.accessibility.AccessibleContext accessibleContext = null; + + /** Returns the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + accessibleContext = new AccessibleDialog(); + accessibleContext.setAccessibleName(getTitle()); + } + return accessibleContext; + } + + protected class AccessibleDialog extends java.awt.Dialog.AccessibleAWTDialog { + protected AccessibleDialog() { + super(); + } + + protected java.awt.event.ComponentListener accessibleComponentHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when shown/hidden.. + */ + protected class AccessibleComponentHandler implements java.awt.event.ComponentListener { + public void componentHidden(java.awt.event.ComponentEvent e) { + AccessibleDialog.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + javax.accessibility.AccessibleState.VISIBLE, null); + } + + public void componentShown(java.awt.event.ComponentEvent e) { + AccessibleDialog.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, javax.accessibility.AccessibleState.VISIBLE); + } + + public void componentMoved(java.awt.event.ComponentEvent e) { + } + + public void componentResized(java.awt.event.ComponentEvent e) { + } + } // inner class AccessibleComponentHandler + + protected java.awt.event.WindowListener accessibleWindowHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when window events happen + */ + protected class AccessibleWindowHandler implements java.awt.event.WindowListener { + /** Invoked when the Window is set to be the active Window. */ + public void windowActivated(java.awt.event.WindowEvent e) { + AccessibleDialog.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, javax.accessibility.AccessibleState.ACTIVE); + if (Build.DEBUG) { + System.err.println("[Dialog] " + getTitle() + " is now active"); + } + } + + /** Invoked when a window has been closed as the result of calling dispose on the window. */ + public void windowClosed(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[Dialog] " + getTitle() + " has been closed"); + } + } + + /** Invoked when the user attempts to close the window from the window's system menu. */ + public void windowClosing(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[Dialog] " + getTitle() + " is closing"); + } + } + + /** Invoked when a Window is no longer the active Window. */ + public void windowDeactivated(java.awt.event.WindowEvent e) { + AccessibleDialog.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + javax.accessibility.AccessibleState.ACTIVE, null); + if (Build.DEBUG) { + System.err.println("[Dialog] " + getTitle() + " is no longer active"); + } + } + + /** Invoked when a window is changed from a minimized to a normal state. */ + public void windowDeiconified(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[Dialog] " + getTitle() + " has been deiconified"); + } + } + + /** Invoked when a window is changed from a normal to a minimized state. */ + public void windowIconified(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[Dialog] " + getTitle() + " has been iconified"); + } + } + + /** Invoked the first time a window is made visible. */ + public void windowOpened(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[Dialog] " + getTitle() + " has been opened"); + } + } + + } // inner class AccessibleWindowHandler + + protected java.awt.event.ContainerListener accessibleContainerHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when children added/removed. + */ + + protected class AccessibleContainerHandler implements java.awt.event.ContainerListener { + public void componentAdded(java.awt.event.ContainerEvent e) { + java.awt.Component c = e.getChild(); + if (c != null && c instanceof javax.accessibility.Accessible) { + AccessibleDialog.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, ((javax.accessibility.Accessible) c).getAccessibleContext()); + } + } + public void componentRemoved(java.awt.event.ContainerEvent e) { + java.awt.Component c = e.getChild(); + if (c != null && c instanceof javax.accessibility.Accessible) { + AccessibleDialog.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + ((javax.accessibility.Accessible) c).getAccessibleContext(), null); + } + } + } + + protected int propertyChangeListenerCount = 0; + + /** + * Add a PropertyChangeListener to the listener list. + * + * @param listener The PropertyChangeListener to be added + */ + public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (propertyChangeListenerCount++ == 0) { + accessibleWindowHandler = new AccessibleWindowHandler(); + Dialog.this.addWindowListener(accessibleWindowHandler); + + accessibleContainerHandler = new AccessibleContainerHandler(); + Dialog.this.addContainerListener(accessibleContainerHandler); + + accessibleComponentHandler = new AccessibleComponentHandler(); + Dialog.this.addComponentListener(accessibleComponentHandler); + } + super.addPropertyChangeListener(listener); + } + + /** + * Remove a PropertyChangeListener from the listener list. + * This removes a PropertyChangeListener that was registered + * for all properties. + * + * @param listener The PropertyChangeListener to be removed + */ + public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (--propertyChangeListenerCount == 0) { + Dialog.this.removeComponentListener(accessibleComponentHandler); + accessibleComponentHandler = null; + + Dialog.this.removeContainerListener(accessibleContainerHandler); + accessibleContainerHandler = null; + + Dialog.this.removeWindowListener(accessibleWindowHandler); + accessibleWindowHandler = null; + } + super.removePropertyChangeListener(listener); + } + + /* + * AccessibleComponent + */ + + /** Returns the background color of the object */ + public java.awt.Color getBackground() { + try { + return new java.awt.Color(unoAccessibleComponent.getBackground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setBackground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + /** Returns the foreground color of the object */ + public java.awt.Color getForeground() { + try { + return new java.awt.Color(unoAccessibleComponent.getForeground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setForeground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + public java.awt.Cursor getCursor() { + // Not supported by UNO accessibility API + return null; + } + + public void setCursor(java.awt.Cursor cursor) { + // Not supported by UNO accessibility API + } + + public java.awt.Font getFont() { + // FIXME + return null; + } + + public void setFont(java.awt.Font f) { + // Not supported by UNO accessibility API + } + + public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { + // FIXME + return null; + } + + public boolean isEnabled() { + return Dialog.this.isEnabled(); + } + + public void setEnabled(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isVisible() { + return Dialog.this.isVisible(); + } + + public void setVisible(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isShowing() { + return Dialog.this.isShowing(); + } + + public boolean contains(java.awt.Point p) { + try { + return unoAccessibleComponent.containsPoint(new com.sun.star.awt.Point(p.x, p.y)); + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Returns the location of the object on the screen. */ + public java.awt.Point getLocationOnScreen() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocationOnScreen(); + return new java.awt.Point(unoPoint.X, unoPoint.Y); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the location of this component in the form of a point specifying the component's top-left corner */ + public java.awt.Point getLocation() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocation(); + return new java.awt.Point( unoPoint.X, unoPoint.Y ); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves this component to a new location */ + public void setLocation(java.awt.Point p) { + // Not supported by UNO accessibility API + } + + /** Gets the bounds of this component in the form of a Rectangle object */ + public java.awt.Rectangle getBounds() { + try { + com.sun.star.awt.Rectangle unoRect = unoAccessibleComponent.getBounds(); + return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves and resizes this component to conform to the new bounding rectangle r */ + public void setBounds(java.awt.Rectangle r) { + // Not supported by UNO accessibility API + } + + /** Returns the size of this component in the form of a Dimension object */ + public java.awt.Dimension getSize() { + try { + com.sun.star.awt.Size unoSize = unoAccessibleComponent.getSize(); + return new java.awt.Dimension(unoSize.Width, unoSize.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Resizes this component so that it has width d.width and height d.height */ + public void setSize(java.awt.Dimension d) { + // Not supported by UNO accessibility API + } + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + try { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent( + unoAccessibleComponent.getAccessibleAtPoint(new com.sun.star.awt.Point(p.x, p.y))); + + return (javax.accessibility.Accessible) c; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public boolean isFocusTraversable() { + return Dialog.this.isFocusable(); + } + + public void requestFocus() { + unoAccessibleComponent.grabFocus(); + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/FocusTraversalPolicy.java b/accessibility/bridge/org/openoffice/java/accessibility/FocusTraversalPolicy.java new file mode 100644 index 000000000000..75f6c91354f4 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/FocusTraversalPolicy.java @@ -0,0 +1,89 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + + +public class FocusTraversalPolicy extends java.awt.FocusTraversalPolicy { + + protected javax.accessibility.Accessible getSelectedAccessibleChild(javax.accessibility.Accessible a) { + javax.accessibility.AccessibleContext ac = a.getAccessibleContext(); + if (ac != null) { + javax.accessibility.AccessibleSelection as = ac.getAccessibleSelection(); + if (as != null) { + return as.getAccessibleSelection(0); + } + } + return null; + } + + /** Returns the Component that should receive the focus after aComponent */ + public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, + java.awt.Component aComponent) { + return null; + } + + /** Returns the Component that should receive the focus before aComponent */ + public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, + java.awt.Component aComponent) { + return null; + } + + /** Returns the default Component to focus */ + public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot) { + // getDefaultComponent must not return null for Windows to make them focusable. + if (focusCycleRoot instanceof NativeFrame) { + java.awt.Component c = ((NativeFrame) focusCycleRoot).getInitialComponent(); + if (c != null) { + return c; + } + } + + if (focusCycleRoot instanceof javax.accessibility.Accessible) { + return (java.awt.Component) getSelectedAccessibleChild((javax.accessibility.Accessible) focusCycleRoot); + } + return null; + } + + /** Returns the first Component in the traversal cycle */ + public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot) { + return null; + } + + /** Returns the Component that should receive the focus when a Window is made visible for the first time */ + public java.awt.Component getInitialComponent(java.awt.Window window) { + if (window instanceof NativeFrame) { + return ((NativeFrame) window).getInitialComponent(); + } + return null; + } + + /** Returns the last Component in the traversal cycle */ + public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot) { + return null; + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Frame.java b/accessibility/bridge/org/openoffice/java/accessibility/Frame.java new file mode 100644 index 000000000000..b7f37b2d6b18 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Frame.java @@ -0,0 +1,646 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +public class Frame extends java.awt.Frame implements javax.accessibility.Accessible, NativeFrame { + protected XAccessibleComponent unoAccessibleComponent; + + boolean opened = false; + boolean visible = false; + boolean active = false; + + java.awt.EventQueue eventQueue = null; + + protected Frame(XAccessibleComponent xAccessibleComponent) { + initialize(xAccessibleComponent); + } + + protected Frame(String name, XAccessibleComponent xAccessibleComponent) { + super(name); + initialize(xAccessibleComponent); + } + + private void initialize(XAccessibleComponent xAccessibleComponent) { + unoAccessibleComponent = xAccessibleComponent; + eventQueue = java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue(); + XAccessibleEventBroadcaster broadcaster = (XAccessibleEventBroadcaster) + UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, + unoAccessibleComponent); + if (broadcaster != null) { + broadcaster.addEventListener(new AccessibleFrameListener()); + } + } + + java.awt.Component initialComponent = null; + + public java.awt.Component getInitialComponent() { + return initialComponent; + } + + public void setInitialComponent(java.awt.Component c) { + initialComponent = c; + } + + public Integer getHWND() { + return null; + } + + /** + * Determines whether this <code>Component</code> is showing on screen. + * This means that the component must be visible, and it must be in a + * <code>container</code> that is visible and showing. + * @see #addNotify + * @see #removeNotify + * @since JDK1.0 + */ + public boolean isShowing() { + if (isVisible()) { + java.awt.Container parent = getParent(); + return (parent == null) || parent.isShowing(); + } + return false; + } + + /** + * Makes this <code>Component</code> displayable by connecting it to a + * native screen resource. + * This method is called internally by the toolkit and should + * not be called directly by programs. + * @see #isDisplayable + * @see #removeNotify + * @since JDK1.0 + */ + public void addNotify() { +// createHierarchyEvents(0, null, null, 0, false); + } + + /** + * Makes this <code>Component</code> undisplayable by destroying it native + * screen resource. + * This method is called by the toolkit internally and should + * not be called directly by programs. + * @see #isDisplayable + * @see #addNotify + * @since JDK1.0 + */ + public void removeNotify() { + } + + /** + * Determines if the object is visible. Note: this means that the + * object intends to be visible; however, it may not in fact be + * showing on the screen because one of the objects that this object + * is contained by is not visible. To determine if an object is + * showing on the screen, use <code>isShowing</code>. + * + * @return true if object is visible; otherwise, false + */ + public boolean isVisible(){ + return visible; + } + + /** + * Shows or hides this component depending on the value of parameter + * <code>b</code>. + * @param b if <code>true</code>, shows this component; + * otherwise, hides this component + * @see #isVisible + * @since JDK1.1 + */ + public void setVisible(boolean b) { + if (visible != b){ + visible = b; + if (b) { + // If it is the first show, fire WINDOW_OPENED event + if (!opened) { + postWindowEvent(java.awt.event.WindowEvent.WINDOW_OPENED); + opened = true; + } + postComponentEvent(java.awt.event.ComponentEvent.COMPONENT_SHOWN); + } else { + postComponentEvent(java.awt.event.ComponentEvent.COMPONENT_HIDDEN); + } + } + } + + public void dispose() { + setVisible(false); + postWindowEvent(java.awt.event.WindowEvent.WINDOW_CLOSED); + } + + protected void postWindowEvent(int i) { + eventQueue.postEvent(new java.awt.event.WindowEvent(this, i)); + } + + protected void postComponentEvent(int i) { + eventQueue.postEvent(new java.awt.event.ComponentEvent(this, i)); + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleFrameListener implements XAccessibleEventListener { + + protected AccessibleFrameListener() { + } + + // The only expected state changes are ACTIVE and VISIBLE + protected void setComponentState(short state, boolean enable) { + switch (state) { + case AccessibleStateType.ACTIVE: + active = enable; + if (enable) { + AccessibleObjectFactory.postWindowActivated(Frame.this); + } else { + AccessibleObjectFactory.postWindowLostFocus(Frame.this); + } + break; + case AccessibleStateType.ICONIFIED: + if (Build.DEBUG) { + System.err.println("[frame]" + getTitle() + (enable ? " is now " : " is no longer ") + "iconified"); + } + postWindowEvent(enable ? + java.awt.event.WindowEvent.WINDOW_ICONIFIED : + java.awt.event.WindowEvent.WINDOW_DEICONIFIED); + break; + case AccessibleStateType.VISIBLE: + Frame.this.setVisible(enable); + break; + default: + if (Build.DEBUG) { + System.err.println("[frame]: " + getTitle() + "unexpected state change " + state); + } + break; + } + } + + /** Updates the accessible name and fires the appropriate PropertyChangedEvent */ + protected void handleNameChangedEvent(Object any) { + try { + String title = AnyConverter.toString(any); + setTitle(title); + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + javax.accessibility.AccessibleContext ac = accessibleContext; + if (ac!= null) { + ac.setAccessibleName(title); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the accessible description and fires the appropriate PropertyChangedEvent */ + protected void handleDescriptionChangedEvent(Object any) { + try { + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + javax.accessibility.AccessibleContext ac = accessibleContext; + if (ac!= null) { + ac.setAccessibleDescription(AnyConverter.toString(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the internal states and fires the appropriate PropertyChangedEvent */ + protected void handleStateChangedEvent(Object any1, Object any2) { + try { + if (AnyConverter.isShort(any1)) { + setComponentState(AnyConverter.toShort(any1), false); + } + + if (AnyConverter.isShort(any2)) { + setComponentState(AnyConverter.toShort(any2), true); + } + } + + catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Fires a visible data property change event */ + protected void handleVisibleDataEvent() { + javax.accessibility.AccessibleContext ac = accessibleContext; + if (ac != null) { + ac.firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, null, null); + } + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.NAME_CHANGED: + // Set the accessible name for the corresponding context, which will fire a property + // change event itself + handleNameChangedEvent(event.NewValue); + break; + case AccessibleEventId.DESCRIPTION_CHANGED: + // Set the accessible description for the corresponding context, which will fire a property + // change event itself - so do not set propertyName ! + handleDescriptionChangedEvent(event.NewValue); + break; + case AccessibleEventId.STATE_CHANGED: + // Update the internal state set and fire the appropriate PropertyChangedEvent + handleStateChangedEvent(event.OldValue, event.NewValue); + break; + case AccessibleEventId.CHILD: + if (AnyConverter.isObject(event.OldValue)) { + AccessibleObjectFactory.removeChild(Frame.this, event.OldValue); + } else if (AnyConverter.isObject(event.NewValue)) { + AccessibleObjectFactory.addChild(Frame.this, event.NewValue); + } + break; + case AccessibleEventId.VISIBLE_DATA_CHANGED: + case AccessibleEventId.BOUNDRECT_CHANGED: + handleVisibleDataEvent(); + break; + default: + // Warn about unhandled events + if(Build.DEBUG) { + System.out.println(this + ": unhandled accessibility event id=" + event.EventId); + } + } + } + + /** Called by OpenOffice process to notify that the UNO component is disposing */ + public void disposing(com.sun.star.lang.EventObject eventObject) { + } + } + + protected javax.accessibility.AccessibleContext accessibleContext = null; + + /** Returns the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + accessibleContext = new AccessibleFrame(); + accessibleContext.setAccessibleName(getTitle()); + } + return accessibleContext; + } + + protected class AccessibleFrame extends java.awt.Frame.AccessibleAWTFrame { + protected AccessibleFrame() { + super(); + } + + protected java.awt.event.ComponentListener accessibleComponentHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when shown/hidden.. + */ + protected class AccessibleComponentHandler implements java.awt.event.ComponentListener { + public void componentHidden(java.awt.event.ComponentEvent e) { + AccessibleFrame.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + javax.accessibility.AccessibleState.VISIBLE, null); + } + + public void componentShown(java.awt.event.ComponentEvent e) { + AccessibleFrame.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, javax.accessibility.AccessibleState.VISIBLE); + } + + public void componentMoved(java.awt.event.ComponentEvent e) { + } + + public void componentResized(java.awt.event.ComponentEvent e) { + } + } // inner class AccessibleComponentHandler + + protected java.awt.event.WindowListener accessibleWindowHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when window events happen + */ + protected class AccessibleWindowHandler implements java.awt.event.WindowListener { + /** Invoked when the Window is set to be the active Window. */ + public void windowActivated(java.awt.event.WindowEvent e) { + AccessibleFrame.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, javax.accessibility.AccessibleState.ACTIVE); + if (Build.DEBUG) { + System.err.println("[frame] " + getTitle() + " is now active"); + } + } + + /** Invoked when a window has been closed as the result of calling dispose on the window. */ + public void windowClosed(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[frame] " + getTitle() + " has been closed"); + } + } + + /** Invoked when the user attempts to close the window from the window's system menu. */ + public void windowClosing(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[frame] " + getTitle() + " is closing"); + } + } + + /** Invoked when a Window is no longer the active Window. */ + public void windowDeactivated(java.awt.event.WindowEvent e) { + AccessibleFrame.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + javax.accessibility.AccessibleState.ACTIVE, null); + if (Build.DEBUG) { + System.err.println("[frame] " + getTitle() + " is no longer active"); + } + } + + /** Invoked when a window is changed from a minimized to a normal state. */ + public void windowDeiconified(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[frame] " + getTitle() + " is no longer iconified"); + } + } + + /** Invoked when a window is changed from a normal to a minimized state. */ + public void windowIconified(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[frame] " + getTitle() + " has been iconified"); + } + } + + /** Invoked the first time a window is made visible. */ + public void windowOpened(java.awt.event.WindowEvent e) { + if (Build.DEBUG) { + System.err.println("[frame] " + getTitle() + " has been opened"); + } + } + + } // inner class AccessibleWindowHandler + + protected java.awt.event.ContainerListener accessibleContainerHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when children added/removed. + */ + + protected class AccessibleContainerHandler implements java.awt.event.ContainerListener { + public void componentAdded(java.awt.event.ContainerEvent e) { + java.awt.Component c = e.getChild(); + if (c != null && c instanceof javax.accessibility.Accessible) { + AccessibleFrame.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, ((javax.accessibility.Accessible) c).getAccessibleContext()); + } + } + public void componentRemoved(java.awt.event.ContainerEvent e) { + java.awt.Component c = e.getChild(); + if (c != null && c instanceof javax.accessibility.Accessible) { + AccessibleFrame.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + ((javax.accessibility.Accessible) c).getAccessibleContext(), null); + } + } + } + + protected int propertyChangeListenerCount = 0; + + /** + * Add a PropertyChangeListener to the listener list. + * + * @param listener The PropertyChangeListener to be added + */ + public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (propertyChangeListenerCount++ == 0) { + accessibleWindowHandler = new AccessibleWindowHandler(); + Frame.this.addWindowListener(accessibleWindowHandler); + + accessibleContainerHandler = new AccessibleContainerHandler(); + Frame.this.addContainerListener(accessibleContainerHandler); + + accessibleComponentHandler = new AccessibleComponentHandler(); + Frame.this.addComponentListener(accessibleComponentHandler); + } + super.addPropertyChangeListener(listener); + } + + /** + * Remove a PropertyChangeListener from the listener list. + * This removes a PropertyChangeListener that was registered + * for all properties. + * + * @param listener The PropertyChangeListener to be removed + */ + public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (--propertyChangeListenerCount == 0) { + Frame.this.removeComponentListener(accessibleComponentHandler); + accessibleComponentHandler = null; + + Frame.this.removeContainerListener(accessibleContainerHandler); + accessibleContainerHandler = null; + + Frame.this.removeWindowListener(accessibleWindowHandler); + accessibleWindowHandler = null; + } + super.removePropertyChangeListener(listener); + } + + /** + * Get the state set of this object. + * + * @return an instance of AccessibleState containing the current state + * of the object + * @see AccessibleState + */ + public javax.accessibility.AccessibleStateSet getAccessibleStateSet() { + javax.accessibility.AccessibleStateSet states = super.getAccessibleStateSet(); + if ((getExtendedState() & java.awt.Frame.ICONIFIED) > 0) { + states.add(javax.accessibility.AccessibleState.ICONIFIED); + } + return states; + } + + /* + * AccessibleComponent + */ + + /** Returns the background color of the object */ + public java.awt.Color getBackground() { + try { + return new java.awt.Color(unoAccessibleComponent.getBackground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setBackground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + /** Returns the foreground color of the object */ + public java.awt.Color getForeground() { + try { + return new java.awt.Color(unoAccessibleComponent.getForeground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setForeground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + public java.awt.Cursor getCursor() { + // Not supported by UNO accessibility API + return null; + } + + public void setCursor(java.awt.Cursor cursor) { + // Not supported by UNO accessibility API + } + + public java.awt.Font getFont() { + // FIXME + return null; + } + + public void setFont(java.awt.Font f) { + // Not supported by UNO accessibility API + } + + public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { + // FIXME + return null; + } + + public boolean isEnabled() { + return Frame.this.isEnabled(); + } + + public void setEnabled(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isVisible() { + return Frame.this.isVisible(); + } + + public void setVisible(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isShowing() { + return Frame.this.isShowing(); + } + + public boolean contains(java.awt.Point p) { + try { + return unoAccessibleComponent.containsPoint(new com.sun.star.awt.Point(p.x, p.y)); + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Returns the location of the object on the screen. */ + public java.awt.Point getLocationOnScreen() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocationOnScreen(); + return new java.awt.Point(unoPoint.X, unoPoint.Y); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the location of this component in the form of a point specifying the component's top-left corner */ + public java.awt.Point getLocation() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocation(); + return new java.awt.Point( unoPoint.X, unoPoint.Y ); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves this component to a new location */ + public void setLocation(java.awt.Point p) { + // Not supported by UNO accessibility API + } + + /** Gets the bounds of this component in the form of a Rectangle object */ + public java.awt.Rectangle getBounds() { + try { + com.sun.star.awt.Rectangle unoRect = unoAccessibleComponent.getBounds(); + return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves and resizes this component to conform to the new bounding rectangle r */ + public void setBounds(java.awt.Rectangle r) { + // Not supported by UNO accessibility API + } + + /** Returns the size of this component in the form of a Dimension object */ + public java.awt.Dimension getSize() { + try { + com.sun.star.awt.Size unoSize = unoAccessibleComponent.getSize(); + return new java.awt.Dimension(unoSize.Width, unoSize.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Resizes this component so that it has width d.width and height d.height */ + public void setSize(java.awt.Dimension d) { + // Not supported by UNO accessibility API + } + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + try { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent( + unoAccessibleComponent.getAccessibleAtPoint(new com.sun.star.awt.Point(p.x, p.y))); + + return (javax.accessibility.Accessible) c; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public boolean isFocusTraversable() { + return Frame.this.isFocusable(); + } + + public void requestFocus() { + unoAccessibleComponent.grabFocus(); + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Icon.java b/accessibility/bridge/org/openoffice/java/accessibility/Icon.java new file mode 100644 index 000000000000..8ccc97def4d8 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Icon.java @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; + + +/** + */ +public class Icon extends Component implements javax.accessibility.Accessible { + protected Icon(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleIcon(); + } + + protected class AccessibleIcon extends AccessibleUNOComponent { + /** + * Though the class is abstract, this should be called by all sub-classes + */ + protected AccessibleIcon() { + super(); + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleIcon[] getAccessibleIcon() { + try { + XAccessibleImage unoAccessibleImage = (XAccessibleImage) UnoRuntime.queryInterface(XAccessibleImage.class, + unoAccessibleComponent); + + if (unoAccessibleImage != null) { + javax.accessibility.AccessibleIcon[] icons = { + new AccessibleIconImpl(unoAccessibleImage) + }; + + return icons; + } + } catch (com.sun.star.uno.RuntimeException e) { + } + + return null; + } + + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Label.java b/accessibility/bridge/org/openoffice/java/accessibility/Label.java new file mode 100644 index 000000000000..9afaa0a1ae37 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Label.java @@ -0,0 +1,130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; + + +/** + */ +public class Label extends Component implements javax.accessibility.Accessible { + protected Label(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleLabel(); + } + + protected class AccessibleLabel extends AccessibleUNOComponent { + /** + * Though the class is abstract, this should be called by all sub-classes + */ + protected AccessibleLabel() { + super(); + } + + /* + * AccessibleContext + */ + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.LABEL; + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleText getAccessibleText() { + + if (disposed) + return null; + + try { + XAccessibleText unoAccessibleText = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, + unoAccessibleContext); + + if (unoAccessibleText != null) { + return new AccessibleTextImpl(unoAccessibleText); + } else { + return null; + } + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the relation set of this object */ + public javax.accessibility.AccessibleRelationSet getAccessibleRelationSet() { + try { + XAccessibleRelationSet unoAccessibleRelationSet = unoAccessibleContext.getAccessibleRelationSet(); + + if (unoAccessibleRelationSet == null) { + return null; + } + + javax.accessibility.AccessibleRelationSet relationSet = new javax.accessibility.AccessibleRelationSet(); + int count = unoAccessibleRelationSet.getRelationCount(); + + for (int i = 0; i < count; i++) { + AccessibleRelation unoAccessibleRelation = unoAccessibleRelationSet.getRelation(i); + + switch (unoAccessibleRelation.RelationType) { + case AccessibleRelationType.LABEL_FOR: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.LABEL_FOR, + getAccessibleComponents( + unoAccessibleRelation.TargetSet))); + + break; + + case AccessibleRelationType.MEMBER_OF: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.MEMBER_OF, + getAccessibleComponents( + unoAccessibleRelation.TargetSet))); + + break; + + default: + break; + } + } + + return relationSet; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/List.java b/accessibility/bridge/org/openoffice/java/accessibility/List.java new file mode 100644 index 000000000000..c0583bf9b692 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/List.java @@ -0,0 +1,452 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleState; + +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.accessibility.*; + +public class List extends DescendantManager implements javax.accessibility.Accessible { + + protected List(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + protected void setActiveDescendant(javax.accessibility.Accessible descendant) { + javax.accessibility.Accessible oldAD = activeDescendant; + activeDescendant = descendant; + firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, + oldAD, descendant); + } + + protected void setActiveDescendant(Object any) { + javax.accessibility.Accessible descendant = null; + try { + if (AnyConverter.isObject(any)) { + XAccessible unoAccessible = (XAccessible) AnyConverter.toObject( + AccessibleObjectFactory.XAccessibleType, any); + if (unoAccessible != null) { + // FIXME: have to handle non transient objects here .. + descendant = new ListItem(unoAccessible); + if (Build.DEBUG) { + try { + if (Build.DEBUG) { + System.err.println("[List] retrieved active descendant event: new descendant is " + + unoAccessible.getAccessibleContext().getAccessibleName()); + } + } catch (java.lang.NullPointerException e) { + System.err.println("*** ERROR *** new active descendant not accessible"); + } + } + } + } + setActiveDescendant(descendant); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + protected void add(XAccessible unoAccessible) { + if (unoAccessible != null) { + ListItem item = new ListItem(unoAccessible); + // The AccessBridge for Windows expects an instance of AccessibleContext + // as parameters + firePropertyChange(AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, item.getAccessibleContext()); + } + } + + protected void remove(XAccessible unoAccessible) { + if (unoAccessible != null) { + ListItem item = new ListItem(unoAccessible); + // The AccessBridge for Windows expects an instance of AccessibleContext + // as parameters + firePropertyChange(AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + item.getAccessibleContext(), null); + } + } + + protected void add(Object any) { + try { + add((XAccessible) AnyConverter.toObject(AccessibleObjectFactory.XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + protected void remove(Object any) { + try { + remove((XAccessible) AnyConverter.toObject(AccessibleObjectFactory.XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleListListener extends AccessibleDescendantManagerListener { + + protected AccessibleListListener() { + super(); + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.ACTIVE_DESCENDANT_CHANGED: + setActiveDescendant(event.NewValue); + break; + case AccessibleEventId.CHILD: + if (AnyConverter.isObject(event.OldValue)) { + remove(event.OldValue); + } + if (AnyConverter.isObject(event.NewValue)) { + add(event.NewValue); + } + break; + case AccessibleEventId.INVALIDATE_ALL_CHILDREN: + // Since List items a transient a child events are mostly used + // to attach/detach listeners, it is save to ignore it here + break; + default: + super.notifyEvent(event); + } + } + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleListListener(); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleList(); + } + + protected class AccessibleList extends AccessibleDescendantManager { + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.LIST; + } + + /** Returns the specified Accessible child of the object */ + public javax.accessibility.Accessible getAccessibleChild(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = List.this.activeDescendant; + if ((activeDescendant instanceof ListItem) && xAccessible.equals(((ListItem) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new ListItem(xAccessible); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /* + * AccessibleComponent + */ + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleComponent.getAccessibleAtPoint(new com.sun.star.awt.Point(p.x, p.y)); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = List.this.activeDescendant; + if ((activeDescendant instanceof ListItem) && xAccessible.equals(((ListItem) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new ListItem(xAccessible); + } + } + return child; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /* + * AccessibleSelection + */ + + /** Returns an Accessible representing the specified selected child of the object */ + public javax.accessibility.Accessible getAccessibleSelection(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleSelection.getSelectedAccessibleChild(i); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = List.this.activeDescendant; + if ((activeDescendant instanceof ListItem) && xAccessible.equals(((ListItem) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new ListItem(xAccessible); + } + } else if (Build.DEBUG) { + System.out.println(i + "th selected child is not accessible"); + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + if (Build.DEBUG) { + System.err.println("IndexOutOfBoundsException caught for AccessibleList.getAccessibleSelection(" + i + ")"); + } + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + } + + class ListItem extends java.awt.Component implements javax.accessibility.Accessible { + + protected XAccessible unoAccessible; + + public ListItem(XAccessible xAccessible) { + unoAccessible = xAccessible; + } + + public Object[] create(Object[] targetSet) { + try { + java.util.ArrayList list = new java.util.ArrayList(targetSet.length); + for (int i=0; i < targetSet.length; i++) { + XAccessible xAccessible = (XAccessible) UnoRuntime.queryInterface( + XAccessible.class, targetSet[i]); + if (xAccessible != null) { + list.add(new ListItem(xAccessible)); + } + } + list.trimToSize(); + return list.toArray(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + javax.accessibility.AccessibleContext accessibleContext = null; + + /** Returns the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + try { + XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext(); + if (xAccessibleContext != null) { + javax.accessibility.AccessibleContext ac = new AccessibleListItem(xAccessibleContext); + if (ac != null) { + ac.setAccessibleParent(List.this); + accessibleContext = ac; + } + AccessibleStateAdapter.setComponentState(this, xAccessibleContext.getAccessibleStateSet()); + } + } catch (com.sun.star.uno.RuntimeException e) { + } + } + return accessibleContext; + } + + protected class AccessibleListItem extends javax.accessibility.AccessibleContext { + + XAccessibleContext unoAccessibleContext; + + public AccessibleListItem(XAccessibleContext xAccessibleContext) { + unoAccessibleContext = xAccessibleContext; + } + + /** Returns the accessible name of this object */ + public String getAccessibleName() { + try { + return unoAccessibleContext.getAccessibleName(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Sets the accessible name of this object */ + public void setAccessibleName(String name) { + // Not supported + } + + /** Returns the accessible name of this object */ + public String getAccessibleDescription() { + try { + return unoAccessibleContext.getAccessibleDescription(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Sets the accessible name of this object */ + public void setAccessibleDescription(String name) { + // Not supported + } + + /** Returns the accessible role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + try { + javax.accessibility.AccessibleRole role = AccessibleRoleAdapter.getAccessibleRole( + unoAccessibleContext.getAccessibleRole()); + return (role != null) ? role : javax.accessibility.AccessibleRole.LABEL; + } catch(com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the locale of the component */ + public java.util.Locale getLocale() throws java.awt.IllegalComponentStateException { + try { + com.sun.star.lang.Locale unoLocale = unoAccessibleContext.getLocale(); + return new java.util.Locale(unoLocale.Language, unoLocale.Country); + } catch (IllegalAccessibleComponentStateException e) { + throw new java.awt.IllegalComponentStateException(e.getMessage()); + } catch (com.sun.star.uno.RuntimeException e) { + return List.this.getLocale(); + } + } + + /** Gets the 0-based index of this object in its accessible parent */ + public int getAccessibleIndexInParent() { + try { + return unoAccessibleContext.getAccessibleIndexInParent(); + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the number of accessible children of the object. */ + public int getAccessibleChildrenCount() { + try { + return unoAccessibleContext.getAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the specified Accessible child of the object. */ + public javax.accessibility.Accessible getAccessibleChild(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i); + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = List.this.activeDescendant; + if ((activeDescendant instanceof ListItem) && ((ListItem) activeDescendant).unoAccessible.equals(xAccessible)) { + child = activeDescendant; + } else if (xAccessible != null) { + child = new ListItem(xAccessible); + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /** Returns the state set of this object */ + public javax.accessibility.AccessibleStateSet getAccessibleStateSet() { + try { + return AccessibleStateAdapter.getAccessibleStateSet(ListItem.this, + unoAccessibleContext.getAccessibleStateSet()); + } catch (com.sun.star.uno.RuntimeException e) { + return AccessibleStateAdapter.getDefunctStateSet(); + } + } + + /** Gets the AccessibleComponent associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleComponent getAccessibleComponent() { + try { + XAccessibleComponent unoAccessibleComponent = (XAccessibleComponent) + UnoRuntime.queryInterface(XAccessibleComponent.class, unoAccessibleContext); + return (unoAccessibleComponent != null) ? + new AccessibleComponentImpl(unoAccessibleComponent) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleAction associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleAction getAccessibleAction() { + try { + XAccessibleAction unoAccessibleAction = (XAccessibleAction) + UnoRuntime.queryInterface(XAccessibleAction.class, unoAccessibleContext); + return (unoAccessibleAction != null) ? + new AccessibleActionImpl(unoAccessibleAction) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleText associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleText getAccessibleText() { + + if (disposed) + return null; + + try { + XAccessibleText unoAccessibleText = (XAccessibleText) + UnoRuntime.queryInterface(XAccessibleText.class, unoAccessibleContext); + return (unoAccessibleText != null) ? + new AccessibleTextImpl(unoAccessibleText) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleValue associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleValue getAccessibleValue() { + try { + XAccessibleValue unoAccessibleValue = (XAccessibleValue) + UnoRuntime.queryInterface(XAccessibleValue.class, unoAccessibleContext); + return (unoAccessibleValue != null) ? + new AccessibleValueImpl(unoAccessibleValue) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleIcon[] getAccessibleIcon() { + try { + XAccessibleImage unoAccessibleImage = (XAccessibleImage) + UnoRuntime.queryInterface(XAccessibleImage.class, unoAccessibleContext); + if (unoAccessibleImage != null) { + javax.accessibility.AccessibleIcon[] icons = { new AccessibleIconImpl(unoAccessibleImage) }; + return icons; + } + } catch (com.sun.star.uno.RuntimeException e) { + } + return null; + } + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Menu.java b/accessibility/bridge/org/openoffice/java/accessibility/Menu.java new file mode 100644 index 000000000000..346baca749b3 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Menu.java @@ -0,0 +1,328 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; + + +public class Menu extends AbstractButton + implements javax.accessibility.Accessible { + private java.util.Vector children; + protected XAccessibleSelection unoAccessibleSelection = null; + + protected Menu(XAccessible xAccessible, + XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + + try { + // Create a vector with the correct initial capacity + int count = unoAccessibleContext.getAccessibleChildCount(); + children = new java.util.Vector(count); + + // Fill the vector with objects + for (int i = 0; i < count; i++) { + java.awt.Component c = getComponent(unoAccessibleContext.getAccessibleChild(i)); + + if (c != null) { + children.add(c); + } + } + } catch (com.sun.star.uno.RuntimeException e) { + if (Build.DEBUG) { + System.err.println( + "RuntimeException caught during menu initialization: " + + e.getMessage()); + } + + if (children == null) { + children = new java.util.Vector(0); + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } + } + + protected synchronized void add(XAccessible unoAccessible) { + // The AccessBridge for Windows expects an instance of AccessibleContext + // as parameters + java.awt.Component c = getComponent(unoAccessible); + + if (c != null) { + try { + children.add(unoAccessible.getAccessibleContext() + .getAccessibleIndexInParent(), c); + firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, + ((javax.accessibility.Accessible) c).getAccessibleContext()); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + } + + protected synchronized void remove(XAccessible unoAccessible) { + // The AccessBridge for Windows expects an instance of AccessibleContext + // as parameters + java.awt.Component c = getComponent(unoAccessible); + + if (c != null) { + try { + children.remove(c); + firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + ((javax.accessibility.Accessible) c).getAccessibleContext(), + null); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + } + + protected void add(Object any) { + try { + add((XAccessible) AnyConverter.toObject( + AccessibleObjectFactory.XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + protected void remove(Object any) { + try { + remove((XAccessible) AnyConverter.toObject( + AccessibleObjectFactory.XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + protected synchronized int indexOf(Object child) { + return children.indexOf(child); + } + + protected java.awt.Component getComponent(XAccessible unoAccessible) { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent(unoAccessible); + + if (c == null) { + c = AccessibleObjectFactory.createAccessibleComponent(unoAccessible); + + if (c instanceof javax.accessibility.Accessible) { + ((javax.accessibility.Accessible) c).getAccessibleContext() + .setAccessibleParent(this); + } + } + + return c; + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleMenuListener(); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleMenu(); + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleMenuListener + extends AccessibleUNOComponentListener { + protected AccessibleMenuListener() { + super(); + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.CHILD: + + if (AnyConverter.isObject(event.OldValue)) { + remove(event.OldValue); + } + + if (AnyConverter.isObject(event.NewValue)) { + add(event.NewValue); + } + + break; + + // #i56539# Java 1.5 does not fire ACCESSIBLE_SELECTION_PROPERTY for menus + case AccessibleEventId.SELECTION_CHANGED: + break; + + default: + super.notifyEvent(event); + } + } + } + + protected class AccessibleMenu extends AccessibleAbstractButton + implements javax.accessibility.AccessibleSelection { + protected AccessibleMenu() { + unoAccessibleSelection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, + unoAccessibleContext); + } + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.MENU; + } + + /** Gets the 0-based index of this object in its accessible parent */ + public int getAccessibleIndexInParent() { + if (getAccessibleParent() instanceof Menu) { + return ((Menu) getAccessibleParent()).indexOf(Menu.this); + } else { + return super.getAccessibleIndexInParent(); + } + } + + /** Returns the number of accessible children of the object */ + public synchronized int getAccessibleChildrenCount() { + return children.size(); + } + + /** Returns the specified Accessible child of the object */ + public synchronized javax.accessibility.Accessible getAccessibleChild( + int i) { + try { + if (i < children.size()) { + return (javax.accessibility.Accessible) children.get(i); + } else { + return null; + } + } catch (ArrayIndexOutOfBoundsException e) { + return null; + } + } + + /** Returns the AccessibleSelection interface for this object */ + public javax.accessibility.AccessibleSelection getAccessibleSelection() { + // This method is called to determine the SELECTABLE state of every + // child, so don't do the query interface here. + return this; + } + + /* + * AccessibleComponent + */ + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + try { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent(unoAccessibleComponent.getAccessibleAtPoint( + new com.sun.star.awt.Point(p.x, p.y))); + + return (javax.accessibility.Accessible) c; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /* + * AccessibleSelection + */ + + /** Returns an Accessible representing the specified selected child of the object */ + public javax.accessibility.Accessible getAccessibleSelection(int i) { + try { + return (javax.accessibility.Accessible) getComponent(unoAccessibleSelection.getSelectedAccessibleChild( + i)); + } catch (java.lang.Exception e) { + /* + * Possible exceptions are: + * java.lang.NullPointerException + * com.sun.star.uno.RuntimeException + * com.sun.star.lang.IndexOutOfBoundsException + */ + return null; + } + } + + /** Adds the specified Accessible child of the object to the object's selection */ + public void addAccessibleSelection(int i) { + try { + javax.accessibility.Accessible a = getAccessibleChild(i); + + // selecting menu items invokes the click action in Java 1.5 + if( a instanceof MenuItem ) + a.getAccessibleContext().getAccessibleAction().doAccessibleAction(0); + else + unoAccessibleSelection.selectAccessibleChild(i); + } catch (java.lang.Exception e) { + /* + * Possible exceptions are: + * java.lang.NullPointerException + * com.sun.star.uno.RuntimeException + * com.sun.star.lang.IndexOutOfBoundsException + */ + } + } + + /** Clears the selection in the object, so that no children in the object are selected */ + public void clearAccessibleSelection() { + try { + unoAccessibleSelection.clearAccessibleSelection(); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Returns the number of Accessible children currently selected */ + public int getAccessibleSelectionCount() { + try { + return unoAccessibleSelection.getSelectedAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Determines if the current child of this object is selected */ + public boolean isAccessibleChildSelected(int i) { + try { + return unoAccessibleSelection.isAccessibleChildSelected(i); + } catch (java.lang.Exception e) { + /* + * Possible exceptions are: + * java.lang.NullPointerException + * com.sun.star.uno.RuntimeException + * com.sun.star.lang.IndexOutOfBoundsException + */ + return false; + } + } + + /** Removes the specified child of the object from the object's selection */ + public void removeAccessibleSelection(int i) { + if (isAccessibleChildSelected(i)) { + clearAccessibleSelection(); + } + } + + /** Causes every child of the object to be selected if the object supports multiple selection */ + public void selectAllAccessibleSelection() { + // not supported + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/MenuContainer.java b/accessibility/bridge/org/openoffice/java/accessibility/MenuContainer.java new file mode 100644 index 000000000000..ccae0ccadd04 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/MenuContainer.java @@ -0,0 +1,167 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleContext; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +/** + * Specialized container for MenuBar and Popup-Menu(s) + * FIXME: join with Menu ? + */ +public class MenuContainer extends Container implements javax.accessibility.Accessible { + + protected XAccessibleSelection unoAccessibleSelection = null; + + protected MenuContainer(javax.accessibility.AccessibleRole role, XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(role, xAccessible, xAccessibleContext); + } + + protected class AccessibleMenuContainerListener extends AccessibleContainerListener { + + protected AccessibleMenuContainerListener() { + super(); + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + + // #i56539# Java 1.5 does not fire ACCESSIBLE_SELECTION_PROPERTY for menus + case AccessibleEventId.SELECTION_CHANGED: + break; + + default: + super.notifyEvent(event); + } + } + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleMenuContainerListener(); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleMenuContainer(); + } + + protected class AccessibleMenuContainer extends AccessibleContainer implements javax.accessibility.AccessibleSelection { + + protected AccessibleMenuContainer() { + unoAccessibleSelection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, + unoAccessibleContext); + } + + /** Returns the AccessibleSelection interface for this object */ + public javax.accessibility.AccessibleSelection getAccessibleSelection() { + return this; + } + + /* + * AccessibleSelection + */ + + /** Returns an Accessible representing the specified selected child of the object */ + public javax.accessibility.Accessible getAccessibleSelection(int i) { + try { + return (javax.accessibility.Accessible) AccessibleObjectFactory.getAccessibleComponent( + unoAccessibleSelection.getSelectedAccessibleChild(i)); + } catch (com.sun.star.uno.Exception e) { + return null; + } + } + + /** Adds the specified Accessible child of the object to the object's selection */ + public void addAccessibleSelection(int i) { + try { + javax.accessibility.Accessible a = getAccessibleChild(i); + + // selecting menu items invokes the click action in Java 1.5 + if( a instanceof MenuItem ) + a.getAccessibleContext().getAccessibleAction().doAccessibleAction(0); + else + unoAccessibleSelection.selectAccessibleChild(i); + } catch (java.lang.Exception e) { + /* + * Possible exceptions are: + * java.lang.NullPointerException + * com.sun.star.uno.RuntimeException + * com.sun.star.lang.IndexOutOfBoundsException + */ + } + } + + /** Clears the selection in the object, so that no children in the object are selected */ + public void clearAccessibleSelection() { + try { + unoAccessibleSelection.clearAccessibleSelection(); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Returns the number of Accessible children currently selected */ + public int getAccessibleSelectionCount() { + try { + return unoAccessibleSelection.getSelectedAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Determines if the current child of this object is selected */ + public boolean isAccessibleChildSelected(int i) { + try { + return unoAccessibleSelection.isAccessibleChildSelected(i); + } catch (java.lang.Exception e) { + /* + * Possible exceptions are: + * java.lang.NullPointerException + * com.sun.star.uno.RuntimeException + * com.sun.star.lang.IndexOutOfBoundsException + */ + return false; + } + } + + /** Removes the specified child of the object from the object's selection */ + public void removeAccessibleSelection(int i) { + if (isAccessibleChildSelected(i)) { + clearAccessibleSelection(); + } + } + + /** Causes every child of the object to be selected if the object supports multiple selection */ + public void selectAllAccessibleSelection() { + // not supported + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/MenuItem.java b/accessibility/bridge/org/openoffice/java/accessibility/MenuItem.java new file mode 100644 index 000000000000..39aa1b73ce30 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/MenuItem.java @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleEventListener; + + +class MenuItem extends ToggleButton { + public MenuItem(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + protected class AccessibleMenuItemListener extends AccessibleUNOComponentListener { + + protected AccessibleMenuItemListener() { + } + + protected void setComponentState(short state, boolean enable) { + + // #i56538# menu items in Java 1.5 are ARMED, not SELECTED + if( state == com.sun.star.accessibility.AccessibleStateType.SELECTED ) + fireStatePropertyChange(javax.accessibility.AccessibleState.ARMED, enable); + else + super.setComponentState(state, enable); + } + }; + + protected XAccessibleEventListener createEventListener() { + return new AccessibleMenuItemListener(); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleMenuItem(); + } + + protected class AccessibleMenuItem extends AccessibleToggleButton { + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.MENU_ITEM; + } + + /** Gets the 0-based index of this object in its accessible parent */ + public int getAccessibleIndexInParent() { + if (getAccessibleParent() instanceof Menu) { + return ((Menu) getAccessibleParent()).indexOf(MenuItem.this); + } else { + return super.getAccessibleIndexInParent(); + } + } + + /** + * Gets the current state set of this object. + * + * @return an instance of <code>AccessibleStateSet</code> + * containing the current state set of the object + * @see AccessibleState + */ + public javax.accessibility.AccessibleStateSet getAccessibleStateSet() { + javax.accessibility.AccessibleStateSet stateSet = super.getAccessibleStateSet(); + + // #i56538# menu items in Java do not have SELECTABLE .. + stateSet.remove(javax.accessibility.AccessibleState.SELECTABLE); + + // .. and also ARMED insted of SELECTED + if( stateSet.remove(javax.accessibility.AccessibleState.SELECTED) ) + stateSet.add(javax.accessibility.AccessibleState.ARMED); + + return stateSet; + } + + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/NativeFrame.java b/accessibility/bridge/org/openoffice/java/accessibility/NativeFrame.java new file mode 100644 index 000000000000..bcc4c0dddebc --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/NativeFrame.java @@ -0,0 +1,35 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +public interface NativeFrame { + public java.awt.Component getInitialComponent(); + public void setInitialComponent(java.awt.Component c); +// public Integer getHWND(); +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Paragraph.java b/accessibility/bridge/org/openoffice/java/accessibility/Paragraph.java new file mode 100644 index 000000000000..6088bf48eabe --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Paragraph.java @@ -0,0 +1,222 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleText; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +/** + */ +public class Paragraph extends Container implements javax.accessibility.Accessible { + + protected Paragraph(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(javax.accessibility.AccessibleRole.TEXT, xAccessible, xAccessibleContext); + } + + protected class AccessibleParagraphListener extends AccessibleContainerListener { + + protected AccessibleParagraphListener() { + super(); + } + + protected void setComponentState(short state, boolean enable) { + switch (state) { + case AccessibleStateType.EDITABLE: + fireStatePropertyChange(javax.accessibility.AccessibleState.EDITABLE, enable); + break; + case AccessibleStateType.MULTI_LINE: + fireStatePropertyChange(javax.accessibility.AccessibleState.MULTI_LINE, enable); + break; + case AccessibleStateType.SINGLE_LINE: + break; + default: + super.setComponentState(state, enable); + break; + } + } + + + protected void handleVisibleDataChanged() { + if (Paragraph.this.isFocusOwner()) { + AccessibleContext ac = accessibleContext; + if (ac != null) { + AccessibleText at = ac.getAccessibleText(); + if (at != null) { + int pos = at.getCaretPosition(); + // Simulating a caret event here should help at tools + // that re not aware of the paragraph approach of OOo. + firePropertyChange(ac.ACCESSIBLE_CARET_PROPERTY, + new Integer(-1), new Integer(pos)); + } + } + } + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.CARET_CHANGED: + firePropertyChange(accessibleContext.ACCESSIBLE_CARET_PROPERTY, + Component.toNumber(event.OldValue), + Component.toNumber(event.NewValue)); + break; + case AccessibleEventId.VISIBLE_DATA_CHANGED: + case AccessibleEventId.BOUNDRECT_CHANGED: + // Whenever a paragraph gets inserted above the currently + // focused one, this is the only event that will occur for. + handleVisibleDataChanged(); + default: + super.notifyEvent(event); + break; + } + } + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleParagraphListener(); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleParagraph(); + } + + protected class AccessibleParagraph extends AccessibleContainer { + + protected AccessibleParagraph() { + // Don't do the queryInterface on XAccessibleText already .. + super(false); + /* Since getAccessibleText() is heavily used by the java access + * bridge for gnome and the gnome at-tools, we do a query interface + * here and remember the result. + */ + accessibleText = AccessibleHypertextImpl.get(unoAccessibleContext); + } + + /* + * AccessibleContext + */ + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.TEXT; + } + + /** Gets the AccessibleEditableText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleEditableText getAccessibleEditableText() { + + if (disposed) + return null; + + try { + XAccessibleEditableText unoAccessibleText = (XAccessibleEditableText) + UnoRuntime.queryInterface(XAccessibleEditableText.class, + unoAccessibleComponent); + if (unoAccessibleText != null) { + return new AccessibleEditableTextImpl(unoAccessibleText); + } else { + return null; + } + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleAction associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleAction getAccessibleAction() { + try { + XAccessibleAction unoAccessibleAction = (XAccessibleAction) + UnoRuntime.queryInterface(XAccessibleAction.class, unoAccessibleComponent); + return (unoAccessibleAction != null) ? + new AccessibleActionImpl(unoAccessibleAction) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the relation set of this object */ + public javax.accessibility.AccessibleRelationSet getAccessibleRelationSet() { + try { + XAccessibleRelationSet unoAccessibleRelationSet = + unoAccessible.getAccessibleContext().getAccessibleRelationSet(); + if (unoAccessibleRelationSet == null) { + return super.getAccessibleRelationSet(); + } + + javax.accessibility.AccessibleRelationSet relationSet = new javax.accessibility.AccessibleRelationSet(); + int count = unoAccessibleRelationSet.getRelationCount(); + for (int i = 0; i < count; i++) { + AccessibleRelation unoAccessibleRelation = unoAccessibleRelationSet.getRelation(i); + switch (unoAccessibleRelation.RelationType) { + case AccessibleRelationType.CONTROLLED_BY: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.CONTROLLED_BY, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.CONTROLLER_FOR: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.CONTROLLER_FOR, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.LABELED_BY: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.LABELED_BY, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.MEMBER_OF: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.MEMBER_OF, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.CONTENT_FLOWS_TO: + relationSet.add(new javax.accessibility.AccessibleRelation( + "flowsTo", + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.CONTENT_FLOWS_FROM: + relationSet.add(new javax.accessibility.AccessibleRelation( + "flowsFrom", + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + default: + break; + } + } + return relationSet; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return super.getAccessibleRelationSet(); + } catch (com.sun.star.uno.RuntimeException e) { + return super.getAccessibleRelationSet(); + } + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/RadioButton.java b/accessibility/bridge/org/openoffice/java/accessibility/RadioButton.java new file mode 100644 index 000000000000..3daeee6cd8de --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/RadioButton.java @@ -0,0 +1,50 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + + +class RadioButton extends ToggleButton { + public RadioButton(XAccessible xAccessible, + XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleRadioButton(); + } + + protected class AccessibleRadioButton extends AccessibleToggleButton { + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.RADIO_BUTTON; + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/ScrollBar.java b/accessibility/bridge/org/openoffice/java/accessibility/ScrollBar.java new file mode 100644 index 000000000000..83b17d698201 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/ScrollBar.java @@ -0,0 +1,126 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; +import javax.swing.SwingConstants; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +/** + */ +public class ScrollBar extends Component implements SwingConstants, javax.accessibility.Accessible { + + public ScrollBar(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleScrollBar(); + } + + protected class AccessibleScrollBar extends AccessibleUNOComponent implements + javax.accessibility.AccessibleAction { + + protected XAccessibleAction unoAccessibleAction; + protected int actionCount = 0; + + /** + * Though the class is abstract, this should be called by all sub-classes + */ + protected AccessibleScrollBar() { + super(); + unoAccessibleAction = (XAccessibleAction) UnoRuntime.queryInterface( + XAccessibleAction.class, unoAccessibleContext); + if (unoAccessibleAction != null) { + actionCount = unoAccessibleAction.getAccessibleActionCount(); + } + } + + /* + * AccessibleContext + */ + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.SCROLL_BAR; + } + + /** Gets the AccessibleValue associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleValue getAccessibleValue() { + try { + XAccessibleValue unoAccessibleValue = (XAccessibleValue) + UnoRuntime.queryInterface(XAccessibleValue.class, unoAccessibleContext); + return (unoAccessibleValue != null) ? + new AccessibleValueImpl(unoAccessibleValue) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleAction associated with this object that supports one or more actions */ + public javax.accessibility.AccessibleAction getAccessibleAction() { + return this; + } + + /* + * AccessibleAction + */ + + /** Performs the specified Action on the object */ + public boolean doAccessibleAction(int param) { + if (param < actionCount) { + try { + return unoAccessibleAction.doAccessibleAction(param); + } catch(com.sun.star.lang.IndexOutOfBoundsException e) { + } + } + return false; + } + + /** Returns a description of the specified action of the object */ + public java.lang.String getAccessibleActionDescription(int param) { + if(param < actionCount) { + try { + return unoAccessibleAction.getAccessibleActionDescription(param); + } catch(com.sun.star.lang.IndexOutOfBoundsException e) { + } + } + return null; + } + + /** Returns the number of accessible actions available in this object */ + public int getAccessibleActionCount() { + return actionCount; + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Separator.java b/accessibility/bridge/org/openoffice/java/accessibility/Separator.java new file mode 100644 index 000000000000..892768e07cbb --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Separator.java @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; + +import javax.swing.SwingConstants; + + +/** + */ +public class Separator extends Component implements SwingConstants, + javax.accessibility.Accessible { + + public Separator(XAccessible xAccessible, + XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + setFocusable(false); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleSeparator(); + } + + protected class AccessibleSeparator extends AccessibleUNOComponent { + /** + * Though the class is abstract, this should be called by all sub-classes + */ + protected AccessibleSeparator() { + super(); + } + + /* + * AccessibleContext + */ + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.SEPARATOR; + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Table.java b/accessibility/bridge/org/openoffice/java/accessibility/Table.java new file mode 100644 index 000000000000..24ea912d4217 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Table.java @@ -0,0 +1,727 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleState; + +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.accessibility.*; + +public class Table extends DescendantManager implements javax.accessibility.Accessible { + + protected Table(XAccessible xAccessible, XAccessibleContext xAccessibleContext, boolean multiselectable) { + super(xAccessible, xAccessibleContext, multiselectable); + } + + protected void setActiveDescendant(javax.accessibility.Accessible descendant) { + javax.accessibility.Accessible oldAD = activeDescendant; + activeDescendant = descendant; + firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, + oldAD, descendant); + } + + protected void setActiveDescendant(Object any) { + javax.accessibility.Accessible descendant = null; + try { + if (AnyConverter.isObject(any)) { + XAccessible unoAccessible = (XAccessible) AnyConverter.toObject( + AccessibleObjectFactory.XAccessibleType, any); + if (unoAccessible != null) { + // FIXME: have to handle non transient objects here .. + descendant = new TableCell(unoAccessible); + } + } + setActiveDescendant(descendant); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + protected void add(XAccessible unoAccessible) { + if (unoAccessible != null) { + TableCell cell = new TableCell(unoAccessible); + // The AccessBridge for Windows expects an instance of AccessibleContext + // as parameters + firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, cell.getAccessibleContext()); + } + } + + protected void remove(XAccessible unoAccessible) { + if (unoAccessible != null) { + TableCell cell = new TableCell(unoAccessible); + // The AccessBridge for Windows expects an instance of AccessibleContext + // as parameters + firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + cell.getAccessibleContext(), null); + } + } + + protected void add(Object any) { + try { + add((XAccessible) AnyConverter.toObject(AccessibleObjectFactory.XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + protected void remove(Object any) { + try { + remove((XAccessible) AnyConverter.toObject(AccessibleObjectFactory.XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleTableListener extends AccessibleDescendantManagerListener { + + protected AccessibleTableListener() { + super(); + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.ACTIVE_DESCENDANT_CHANGED: + setActiveDescendant(event.NewValue); + break; + case AccessibleEventId.CHILD: + if (AnyConverter.isObject(event.OldValue)) { + remove(event.OldValue); + } + if (AnyConverter.isObject(event.NewValue)) { + add(event.NewValue); + } + break; + default: + super.notifyEvent(event); + } + } + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleTableListener(); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleTable(); + } + + protected class AccessibleTable extends AccessibleDescendantManager implements javax.accessibility.AccessibleExtendedTable { + + protected XAccessibleTable unoAccessibleTable; + + public AccessibleTable() { + unoAccessibleTable = (XAccessibleTable) UnoRuntime.queryInterface(XAccessibleTable.class, unoAccessibleContext); + } + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.TABLE; + } + + /** Returns the AccessibleTable interface of this object */ + public javax.accessibility.AccessibleTable getAccessibleTable() { + return this; + } + + /** Returns the specified Accessible child of the object */ + public javax.accessibility.Accessible getAccessibleChild(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant; + if ((activeDescendant instanceof TableCell) && xAccessible.equals(((TableCell) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new TableCell(xAccessible); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /* + * AccessibleComponent + */ + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleComponent.getAccessibleAtPoint( + new com.sun.star.awt.Point(p.x, p.y)); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant; + if ((activeDescendant instanceof TableCell) && xAccessible.equals(((TableCell) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new TableCell(xAccessible); + } + } + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /* + * AccessibleSelection + */ + + /** Returns an Accessible representing the specified selected child of the object */ + public javax.accessibility.Accessible getAccessibleSelection(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleSelection.getSelectedAccessibleChild(i); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant; + if ((activeDescendant instanceof TableCell) && xAccessible.equals(((TableCell) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new TableCell(xAccessible); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /* + * AccessibleTable + */ + + /** Returns the Accessible at a specified row and column in the table. */ + public javax.accessibility.Accessible getAccessibleAt(int r, int c) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleTable.getAccessibleCellAt(r,c); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant; + if ((activeDescendant instanceof TableCell) && xAccessible.equals(((TableCell) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new TableCell(xAccessible); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /** Returns the caption for the table. */ + public javax.accessibility.Accessible getAccessibleCaption() { + // Not yet supported. + return null; + } + + /** Returns the number of columns in the table. */ + public int getAccessibleColumnCount() { + try { + return unoAccessibleTable.getAccessibleColumnCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the description text of the specified column in the table. */ + public javax.accessibility.Accessible getAccessibleColumnDescription(int c) { + try { + return new javax.swing.JLabel( + unoAccessibleTable.getAccessibleColumnDescription(c)); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** + * Returns the number of columns occupied by the Accessible + * at a specified row and column in the table. + */ + public int getAccessibleColumnExtentAt(int r, int c) { + try { + return unoAccessibleTable.getAccessibleColumnExtentAt(r,c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return 0; + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the column headers as an AccessibleTable. */ + public javax.accessibility.AccessibleTable getAccessibleColumnHeader() { + // Not yet supported + return null; + } + + /** Returns the number of rows in the table. */ + public int getAccessibleRowCount() { + try { + return unoAccessibleTable.getAccessibleRowCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the description of the specified row in the table. */ + public javax.accessibility.Accessible getAccessibleRowDescription(int r) { + try { + return new javax.swing.JLabel( + unoAccessibleTable.getAccessibleRowDescription(r)); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** + * Returns the number of rows occupied by the Accessible + * at a specified row and column in the table. + */ + public int getAccessibleRowExtentAt(int r, int c) { + try { + return unoAccessibleTable.getAccessibleRowExtentAt(r,c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return 0; + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the row headers as an AccessibleTable. */ + public javax.accessibility.AccessibleTable getAccessibleRowHeader() { + // Not yet supported + return null; + } + + /** Returns the summary description of the table. */ + public javax.accessibility.Accessible getAccessibleSummary() { + // Not yet supported. + return null; + } + + /** Returns the selected columns in a table. */ + public int[] getSelectedAccessibleColumns() { + try { + return unoAccessibleTable.getSelectedAccessibleColumns(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the selected rows in a table. */ + public int[] getSelectedAccessibleRows() { + try { + return unoAccessibleTable.getSelectedAccessibleRows(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns a boolean value indicating whether the specified column is selected. */ + public boolean isAccessibleColumnSelected(int c) { + try { + return unoAccessibleTable.isAccessibleColumnSelected(c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Returns a boolean value indicating whether the specified row is selected. */ + public boolean isAccessibleRowSelected(int r) { + try { + return unoAccessibleTable.isAccessibleRowSelected(r); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** + * Returns a boolean value indicating whether the accessible + * at a specified row and column is selected. + */ + public boolean isAccessibleSelected(int r, int c) { + try { + return unoAccessibleTable.isAccessibleSelected(r,c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Sets the caption for the table. */ + public void setAccessibleCaption(javax.accessibility.Accessible accessible) { + // Not supported by the UNO Accessibility API + } + + /** Sets the description text of the specified column in the table. */ + public void setAccessibleColumnDescription(int param, javax.accessibility.Accessible accessible) { + // Not supported by the UNO Accessibility API + } + + /** Sets the column headers. */ + public void setAccessibleColumnHeader(javax.accessibility.AccessibleTable accessibleTable) { + // Not supported by the UNO Accessibility API + } + + /** Sets the description text of the specified row of the table. */ + public void setAccessibleRowDescription(int param, javax.accessibility.Accessible accessible) { + // Not supported by the UNO Accessibility API + } + + /** Sets the row headers. */ + public void setAccessibleRowHeader(javax.accessibility.AccessibleTable accessibleTable) { + // Not supported by the UNO Accessibility API + } + + /** Sets the summary description of the table */ + public void setAccessibleSummary(javax.accessibility.Accessible accessible) { + // Not supported by the UNO Accessibility API + } + + /** Returns the column number of an index in the table */ + public int getAccessibleColumn(int index) { + try { + return unoAccessibleTable.getAccessibleColumn(index); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return -1; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the index of a specified row and column in the table. */ + public int getAccessibleIndex(int r, int c) { + try { + return unoAccessibleTable.getAccessibleIndex(r,c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return -1; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the row number of an index in the table */ + public int getAccessibleRow(int index) { + try { + return unoAccessibleTable.getAccessibleRow(index); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return -1; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + } + + class TableCell extends java.awt.Component implements javax.accessibility.Accessible { + + protected XAccessible unoAccessible; + + public TableCell(XAccessible xAccessible) { + unoAccessible = xAccessible; + } + + public Object[] create(Object[] targetSet) { + try { + java.util.ArrayList list = new java.util.ArrayList(targetSet.length); + for (int i=0; i < targetSet.length; i++) { + XAccessible xAccessible = (XAccessible) UnoRuntime.queryInterface( + XAccessible.class, targetSet[i]); + if (xAccessible != null) { + list.add(new TableCell(xAccessible)); + } + } + list.trimToSize(); + return list.toArray(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + javax.accessibility.AccessibleContext accessibleContext = null; + + /** Returns the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + try { + XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext(); + if (xAccessibleContext != null) { + javax.accessibility.AccessibleContext ac = new AccessibleTableCell(xAccessibleContext); + if (ac != null) { + ac.setAccessibleParent(Table.this); + accessibleContext = ac; + } + } + } catch (com.sun.star.uno.RuntimeException e) { + } + } + return accessibleContext; + } + + protected class AccessibleTableCell extends javax.accessibility.AccessibleContext { + + XAccessibleContext unoAccessibleContext; + + public AccessibleTableCell(XAccessibleContext xAccessibleContext) { + unoAccessibleContext = xAccessibleContext; + } + + /** Returns the accessible name of this object */ + public String getAccessibleName() { + try { + return unoAccessibleContext.getAccessibleName(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Sets the accessible name of this object */ + public void setAccessibleName(String name) { + // Not supported + } + + /** Returns the accessible name of this object */ + public String getAccessibleDescription() { + try { + return unoAccessibleContext.getAccessibleDescription(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Sets the accessible name of this object */ + public void setAccessibleDescription(String name) { + // Not supported + } + + /** Returns the accessible role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + try { + javax.accessibility.AccessibleRole role = AccessibleRoleAdapter.getAccessibleRole( + unoAccessibleContext.getAccessibleRole()); + return (role != null) ? role : javax.accessibility.AccessibleRole.LABEL; + } catch(com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the locale of the component */ + public java.util.Locale getLocale() throws java.awt.IllegalComponentStateException { + try { + com.sun.star.lang.Locale unoLocale = unoAccessibleContext.getLocale(); + return new java.util.Locale(unoLocale.Language, unoLocale.Country); + } catch (IllegalAccessibleComponentStateException e) { + throw new java.awt.IllegalComponentStateException(e.getMessage()); + } catch (com.sun.star.uno.RuntimeException e) { + return Table.this.getLocale(); + } + } + + /** Gets the 0-based index of this object in its accessible parent */ + public int getAccessibleIndexInParent() { + try { + return unoAccessibleContext.getAccessibleIndexInParent(); + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the number of accessible children of the object. */ + public int getAccessibleChildrenCount() { + try { + return unoAccessibleContext.getAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the specified Accessible child of the object. */ + public javax.accessibility.Accessible getAccessibleChild(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i); + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Table.this.activeDescendant; + if ((activeDescendant instanceof TableCell) && ((TableCell) activeDescendant).unoAccessible.equals(xAccessible)) { + child = activeDescendant; + } else if (xAccessible != null) { + child = new TableCell(xAccessible); + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /** Returns the state set of this object */ + public javax.accessibility.AccessibleStateSet getAccessibleStateSet() { + try { + return AccessibleStateAdapter.getAccessibleStateSet(TableCell.this, + unoAccessibleContext.getAccessibleStateSet()); + } catch (com.sun.star.uno.RuntimeException e) { + return AccessibleStateAdapter.getDefunctStateSet(); + } + } + + /** Returns the relation set of this object */ + public javax.accessibility.AccessibleRelationSet getAccessibleRelationSet() { + try { + XAccessibleRelationSet unoAccessibleRelationSet = unoAccessibleContext.getAccessibleRelationSet(); + if (unoAccessibleRelationSet == null) { + return null; + } + + javax.accessibility.AccessibleRelationSet relationSet = new javax.accessibility.AccessibleRelationSet(); + int count = unoAccessibleRelationSet.getRelationCount(); + for (int i = 0; i < count; i++) { + AccessibleRelation unoAccessibleRelation = unoAccessibleRelationSet.getRelation(i); + switch (unoAccessibleRelation.RelationType) { + case AccessibleRelationType.CONTROLLED_BY: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.CONTROLLED_BY, + create(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.CONTROLLER_FOR: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.CONTROLLER_FOR, + create(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.LABELED_BY: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.LABELED_BY, + create(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.LABEL_FOR: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.LABEL_FOR, + create(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.MEMBER_OF: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.MEMBER_OF, + create(unoAccessibleRelation.TargetSet))); + break; + default: + break; + } + } + return relationSet; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleComponent associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleComponent getAccessibleComponent() { + try { + XAccessibleComponent unoAccessibleComponent = (XAccessibleComponent) + UnoRuntime.queryInterface(XAccessibleComponent.class, unoAccessibleContext); + return (unoAccessibleComponent != null) ? + new AccessibleComponentImpl(unoAccessibleComponent) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleAction associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleAction getAccessibleAction() { + try { + XAccessibleAction unoAccessibleAction = (XAccessibleAction) + UnoRuntime.queryInterface(XAccessibleAction.class, unoAccessibleContext); + return (unoAccessibleAction != null) ? + new AccessibleActionImpl(unoAccessibleAction) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleText associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleText getAccessibleText() { + + if (disposed) + return null; + + try { + XAccessibleText unoAccessibleText = (XAccessibleText) + UnoRuntime.queryInterface(XAccessibleText.class, unoAccessibleContext); + return (unoAccessibleText != null) ? + new AccessibleTextImpl(unoAccessibleText) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleValue associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleValue getAccessibleValue() { + try { + XAccessibleValue unoAccessibleValue = (XAccessibleValue) + UnoRuntime.queryInterface(XAccessibleValue.class, unoAccessibleContext); + return (unoAccessibleValue != null) ? + new AccessibleValueImpl(unoAccessibleValue) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleIcon[] getAccessibleIcon() { + try { + XAccessibleImage unoAccessibleImage = (XAccessibleImage) + UnoRuntime.queryInterface(XAccessibleImage.class, unoAccessibleContext); + if (unoAccessibleImage != null) { + javax.accessibility.AccessibleIcon[] icons = { new AccessibleIconImpl(unoAccessibleImage) }; + return icons; + } + } catch (com.sun.star.uno.RuntimeException e) { + } + return null; + } + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/TextComponent.java b/accessibility/bridge/org/openoffice/java/accessibility/TextComponent.java new file mode 100644 index 000000000000..a142297c4c12 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/TextComponent.java @@ -0,0 +1,194 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.accessibility.*; + +/** + */ +public class TextComponent extends Component implements javax.accessibility.Accessible { + + protected TextComponent(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + protected class AccessibleTextComponentListener extends AccessibleUNOComponentListener { + + protected AccessibleTextComponentListener() { + super(); + } + + protected void setComponentState(short state, boolean enable) { + switch (state) { + case AccessibleStateType.EDITABLE: + fireStatePropertyChange(javax.accessibility.AccessibleState.EDITABLE, enable); + break; + case AccessibleStateType.MULTI_LINE: + fireStatePropertyChange(javax.accessibility.AccessibleState.MULTI_LINE, enable); + break; + case AccessibleStateType.SINGLE_LINE: + break; + default: + super.setComponentState(state, enable); + break; + } + } + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleTextComponentListener(); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleTextComponent(); + } + + protected class AccessibleTextComponent extends AccessibleUNOComponent { + + /** + * Though the class is abstract, this should be called by all sub-classes + */ + protected AccessibleTextComponent() { + super(); + } + + /* + * AccessibleContext + */ + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.TEXT; + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleText getAccessibleText() { + + if (disposed) + return null; + + try { + XAccessibleText unoAccessibleText = (XAccessibleText) + UnoRuntime.queryInterface(XAccessibleText.class,unoAccessibleComponent); + if (unoAccessibleText != null) { + return new AccessibleTextImpl(unoAccessibleText); + } else { + return null; + } + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleEditableText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleEditableText getAccessibleEditableText() { + try { + XAccessibleEditableText unoAccessibleText = (XAccessibleEditableText) + UnoRuntime.queryInterface(XAccessibleEditableText.class,unoAccessibleComponent); + if (unoAccessibleText != null) { + return new AccessibleEditableTextImpl(unoAccessibleText); + } else { + return null; + } + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleAction associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleAction getAccessibleAction() { + try { + XAccessibleAction unoAccessibleAction = (XAccessibleAction) + UnoRuntime.queryInterface(XAccessibleAction.class, unoAccessibleComponent); + return (unoAccessibleAction != null) ? + new AccessibleActionImpl(unoAccessibleAction) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the relation set of this object */ + public javax.accessibility.AccessibleRelationSet getAccessibleRelationSet() { + try { + XAccessibleRelationSet unoAccessibleRelationSet = + unoAccessible.getAccessibleContext().getAccessibleRelationSet(); + if (unoAccessibleRelationSet == null) { + return super.getAccessibleRelationSet(); + } + + javax.accessibility.AccessibleRelationSet relationSet = new javax.accessibility.AccessibleRelationSet(); + int count = unoAccessibleRelationSet.getRelationCount(); + for (int i = 0; i < count; i++) { + AccessibleRelation unoAccessibleRelation = unoAccessibleRelationSet.getRelation(i); + switch (unoAccessibleRelation.RelationType) { + case AccessibleRelationType.CONTROLLED_BY: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.CONTROLLED_BY, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.CONTROLLER_FOR: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.CONTROLLER_FOR, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.LABELED_BY: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.LABELED_BY, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.MEMBER_OF: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.MEMBER_OF, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.CONTENT_FLOWS_TO: + relationSet.add(new javax.accessibility.AccessibleRelation( + "flowsTo", + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.CONTENT_FLOWS_FROM: + relationSet.add(new javax.accessibility.AccessibleRelation( + "flowsFrom", + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + default: + break; + } + } + return relationSet; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return super.getAccessibleRelationSet(); + } catch (com.sun.star.uno.RuntimeException e) { + return super.getAccessibleRelationSet(); + } + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/ToggleButton.java b/accessibility/bridge/org/openoffice/java/accessibility/ToggleButton.java new file mode 100644 index 000000000000..bac8035a2ece --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/ToggleButton.java @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + + +class ToggleButton extends AbstractButton implements javax.accessibility.Accessible { + public ToggleButton(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleToggleButton(); + } + + protected class AccessibleToggleButton extends AccessibleAbstractButton { + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.TOGGLE_BUTTON; + } + + /** Gets the AccessibleValue associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleValue getAccessibleValue() { + try { + XAccessibleValue unoAccessibleValue = (XAccessibleValue) UnoRuntime.queryInterface(XAccessibleValue.class, + unoAccessibleContext); + + return (unoAccessibleValue != null) + ? new AccessibleValueImpl(unoAccessibleValue) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/ToolTip.java b/accessibility/bridge/org/openoffice/java/accessibility/ToolTip.java new file mode 100644 index 000000000000..071a6a37fd98 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/ToolTip.java @@ -0,0 +1,117 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; + + +/** + */ +public class ToolTip extends Component implements javax.accessibility.Accessible { + protected ToolTip(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleToolTip(); + } + + protected class AccessibleToolTip extends AccessibleUNOComponent { + + /* + * AccessibleContext + */ + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.TOOL_TIP; + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleText getAccessibleText() { + + if (disposed) + return null; + + try { + XAccessibleText unoAccessibleText = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, + unoAccessibleComponent); + + if (unoAccessibleText != null) { + return new AccessibleTextImpl(unoAccessibleText); + } else { + return null; + } + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the relation set of this object */ + + /* + public javax.accessibility.AccessibleRelationSet getAccessibleRelationSet() { + try { + XAccessibleRelationSet unoAccessibleRelationSet = unoAccessibleContext.getAccessibleRelationSet(); + if (unoAccessibleRelationSet == null) { + return null; + } + + javax.accessibility.AccessibleRelationSet relationSet = new javax.accessibility.AccessibleRelationSet(); + int count = unoAccessibleRelationSet.getRelationCount(); + for (int i = 0; i < count; i++) { + AccessibleRelation unoAccessibleRelation = unoAccessibleRelationSet.getRelation(i); + switch (unoAccessibleRelation.RelationType) { + case AccessibleRelationType.LABEL_FOR: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.LABEL_FOR, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + case AccessibleRelationType.MEMBER_OF: + relationSet.add(new javax.accessibility.AccessibleRelation( + javax.accessibility.AccessibleRelation.MEMBER_OF, + getAccessibleComponents(unoAccessibleRelation.TargetSet))); + break; + default: + break; + } + } + return relationSet; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + */ + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Tree.java b/accessibility/bridge/org/openoffice/java/accessibility/Tree.java new file mode 100644 index 000000000000..5fdd5a196397 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Tree.java @@ -0,0 +1,768 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleState; + +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.accessibility.*; + +public class Tree extends DescendantManager implements javax.accessibility.Accessible { + + protected Tree(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { + super(xAccessible, xAccessibleContext); + } + + protected void setActiveDescendant(javax.accessibility.Accessible descendant) { + javax.accessibility.Accessible oldAD = activeDescendant; + activeDescendant = descendant; + firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, + oldAD, descendant); + } + + protected void setActiveDescendant(Object any) { + javax.accessibility.Accessible descendant = null; + try { + if (AnyConverter.isObject(any)) { + XAccessible unoAccessible = (XAccessible) AnyConverter.toObject( + AccessibleObjectFactory.XAccessibleType, any); + if (unoAccessible != null) { + // FIXME: have to handle non transient objects here .. + descendant = new TreeItem(unoAccessible); + } + } + setActiveDescendant(descendant); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + protected void add(XAccessible unoAccessible) { + if (unoAccessible != null) { + firePropertyChange(AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, new TreeItem(unoAccessible)); + } + } + + protected void remove(XAccessible unoAccessible) { + if (unoAccessible != null) { + firePropertyChange(AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + new TreeItem(unoAccessible), null); + } + } + + protected void add(Object any) { + try { + add((XAccessible) AnyConverter.toObject(AccessibleObjectFactory.XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + protected void remove(Object any) { + try { + remove((XAccessible) AnyConverter.toObject(AccessibleObjectFactory.XAccessibleType, any)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleTreeListener extends AccessibleDescendantManagerListener { + + protected AccessibleTreeListener() { + super(); + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.ACTIVE_DESCENDANT_CHANGED: + setActiveDescendant(event.NewValue); + break; + case AccessibleEventId.CHILD: + if (AnyConverter.isObject(event.OldValue)) { + remove(event.OldValue); + } + if (AnyConverter.isObject(event.NewValue)) { + add(event.NewValue); + } + break; + + case AccessibleEventId.LISTBOX_ENTRY_EXPANDED: + firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + AccessibleState.COLLAPSED, AccessibleState.EXPANDED); + break; + + case AccessibleEventId.LISTBOX_ENTRY_COLLAPSED: + firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + AccessibleState.EXPANDED, AccessibleState.COLLAPSED); + break; + + default: + super.notifyEvent(event); + } + } + } + + protected XAccessibleEventListener createEventListener() { + return new AccessibleTreeListener(); + } + + /** Creates the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext createAccessibleContext() { + return new AccessibleTree(); + } + + protected class AccessibleTree extends AccessibleDescendantManager implements javax.accessibility.AccessibleExtendedTable { + + protected XAccessibleTable unoAccessibleTable; + + public AccessibleTree() { + unoAccessibleTable = (XAccessibleTable) UnoRuntime.queryInterface(XAccessibleTable.class, unoAccessibleContext); + } + + /* + * AccessibleContext + */ + + /** Gets the role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + return javax.accessibility.AccessibleRole.TREE; + } + + /** Returns the AccessibleTable interface of this object */ + public javax.accessibility.AccessibleTable getAccessibleTable() { + return ( unoAccessibleTable != null ) ? this : null; + } + + /** Returns the specified Accessible child of the object */ + public javax.accessibility.Accessible getAccessibleChild(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Tree.this.activeDescendant; + if ((activeDescendant instanceof TreeItem) && xAccessible.equals(((TreeItem) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new TreeItem(xAccessible); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /* + * AccessibleComponent + */ + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleComponent.getAccessibleAtPoint( + new com.sun.star.awt.Point(p.x, p.y)); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Tree.this.activeDescendant; + if ((activeDescendant instanceof TreeItem) && xAccessible.equals(((TreeItem) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new TreeItem(xAccessible); + } + } + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /* + * AccessibleSelection + */ + + /** Returns an Accessible representing the specified selected child of the object */ + public javax.accessibility.Accessible getAccessibleSelection(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Tree.this.activeDescendant; + if ((activeDescendant instanceof TreeItem) && xAccessible.equals(((TreeItem) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new TreeItem(xAccessible); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /* + * AccessibleTable + */ + + /** Returns the Accessible at a specified row and column in the table. */ + public javax.accessibility.Accessible getAccessibleAt(int r, int c) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleTable.getAccessibleCellAt(r,c); + if (xAccessible != null) { + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Tree.this.activeDescendant; + if ((activeDescendant instanceof TreeItem) && xAccessible.equals(((TreeItem) activeDescendant).unoAccessible)) { + child = activeDescendant; + } else { + child = new TreeItem(xAccessible); + } + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /** Returns the caption for the table. */ + public javax.accessibility.Accessible getAccessibleCaption() { + // Not yet supported. + return null; + } + + /** Returns the number of columns in the table. */ + public int getAccessibleColumnCount() { + try { + return unoAccessibleTable.getAccessibleColumnCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the description text of the specified column in the table. */ + public javax.accessibility.Accessible getAccessibleColumnDescription(int c) { + try { + return new javax.swing.JLabel( + unoAccessibleTable.getAccessibleColumnDescription(c)); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** + * Returns the number of columns occupied by the Accessible + * at a specified row and column in the table. + */ + public int getAccessibleColumnExtentAt(int r, int c) { + try { + return unoAccessibleTable.getAccessibleColumnExtentAt(r,c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return 0; + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the column headers as an AccessibleTable. */ + public javax.accessibility.AccessibleTable getAccessibleColumnHeader() { + // Not yet supported + return null; + } + + /** Returns the number of rows in the table. */ + public int getAccessibleRowCount() { + try { + return unoAccessibleTable.getAccessibleRowCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the description of the specified row in the table. */ + public javax.accessibility.Accessible getAccessibleRowDescription(int r) { + try { + return new javax.swing.JLabel( + unoAccessibleTable.getAccessibleRowDescription(r)); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** + * Returns the number of rows occupied by the Accessible + * at a specified row and column in the table. + */ + public int getAccessibleRowExtentAt(int r, int c) { + try { + return unoAccessibleTable.getAccessibleRowExtentAt(r,c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return 0; + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the row headers as an AccessibleTable. */ + public javax.accessibility.AccessibleTable getAccessibleRowHeader() { + // Not yet supported + return null; + } + + /** Returns the summary description of the table. */ + public javax.accessibility.Accessible getAccessibleSummary() { + // Not yet supported. + return null; + } + + /** Returns the selected columns in a table. */ + public int[] getSelectedAccessibleColumns() { + try { + return unoAccessibleTable.getSelectedAccessibleColumns(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the selected rows in a table. */ + public int[] getSelectedAccessibleRows() { + try { + return unoAccessibleTable.getSelectedAccessibleRows(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns a boolean value indicating whether the specified column is selected. */ + public boolean isAccessibleColumnSelected(int c) { + try { + return unoAccessibleTable.isAccessibleColumnSelected(c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Returns a boolean value indicating whether the specified row is selected. */ + public boolean isAccessibleRowSelected(int r) { + try { + return unoAccessibleTable.isAccessibleRowSelected(r); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** + * Returns a boolean value indicating whether the accessible + * at a specified row and column is selected. + */ + public boolean isAccessibleSelected(int r, int c) { + try { + return unoAccessibleTable.isAccessibleSelected(r,c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Sets the caption for the table. */ + public void setAccessibleCaption(javax.accessibility.Accessible accessible) { + // Not supported by the UNO Accessibility API + } + + /** Sets the description text of the specified column in the table. */ + public void setAccessibleColumnDescription(int param, javax.accessibility.Accessible accessible) { + // Not supported by the UNO Accessibility API + } + + /** Sets the column headers. */ + public void setAccessibleColumnHeader(javax.accessibility.AccessibleTable accessibleTable) { + // Not supported by the UNO Accessibility API + } + + /** Sets the description text of the specified row of the table. */ + public void setAccessibleRowDescription(int param, javax.accessibility.Accessible accessible) { + // Not supported by the UNO Accessibility API + } + + /** Sets the row headers. */ + public void setAccessibleRowHeader(javax.accessibility.AccessibleTable accessibleTable) { + // Not supported by the UNO Accessibility API + } + + /** Sets the summary description of the table */ + public void setAccessibleSummary(javax.accessibility.Accessible accessible) { + // Not supported by the UNO Accessibility API + } + + /** Returns the column number of an index in the table */ + public int getAccessibleColumn(int index) { + try { + return unoAccessibleTable.getAccessibleColumn(index); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return -1; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the index of a specified row and column in the table. */ + public int getAccessibleIndex(int r, int c) { + try { + return unoAccessibleTable.getAccessibleIndex(r,c); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return -1; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the row number of an index in the table */ + public int getAccessibleRow(int index) { + try { + return unoAccessibleTable.getAccessibleRow(index); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return -1; + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + } + + class TreeItem extends java.awt.Component implements javax.accessibility.Accessible { + + protected XAccessible unoAccessible; + + public TreeItem(XAccessible xAccessible) { + unoAccessible = xAccessible; + } + + public Object[] create(Object[] targetSet) { + try { + java.util.ArrayList list = new java.util.ArrayList(targetSet.length); + for (int i=0; i < targetSet.length; i++) { + XAccessible xAccessible = (XAccessible) UnoRuntime.queryInterface( + XAccessible.class, targetSet[i]); + if (xAccessible != null) { + list.add(new TreeItem(xAccessible)); + } + } + list.trimToSize(); + return list.toArray(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + javax.accessibility.AccessibleContext accessibleContext = null; + + /** Returns the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + try { + XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext(); + if (xAccessibleContext != null) { + javax.accessibility.AccessibleContext ac = new AccessibleTreeItem(xAccessibleContext); + if (ac != null) { + ac.setAccessibleParent(Tree.this); + accessibleContext = ac; + } + } + } catch (com.sun.star.uno.RuntimeException e) { + } + } + return accessibleContext; + } + + protected class AccessibleTreeItem extends javax.accessibility.AccessibleContext + implements javax.accessibility.AccessibleSelection { + + XAccessibleContext unoAccessibleContext; + XAccessibleSelection unoAccessibleSelection; + + public AccessibleTreeItem(XAccessibleContext xAccessibleContext) { + unoAccessibleContext = xAccessibleContext; + unoAccessibleSelection = (XAccessibleSelection) + UnoRuntime.queryInterface(XAccessibleSelection.class, xAccessibleContext); + } + + /** Returns the accessible name of this object */ + public String getAccessibleName() { + try { + return unoAccessibleContext.getAccessibleName(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Sets the accessible name of this object */ + public void setAccessibleName(String name) { + // Not supported + } + + /** Returns the accessible name of this object */ + public String getAccessibleDescription() { + try { + return unoAccessibleContext.getAccessibleDescription(); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Sets the accessible name of this object */ + public void setAccessibleDescription(String name) { + // Not supported + } + + /** Returns the accessible role of this object */ + public javax.accessibility.AccessibleRole getAccessibleRole() { + try { + javax.accessibility.AccessibleRole role = AccessibleRoleAdapter.getAccessibleRole( + unoAccessibleContext.getAccessibleRole()); + return (role != null) ? role : javax.accessibility.AccessibleRole.LABEL; + } catch(com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the locale of the component */ + public java.util.Locale getLocale() throws java.awt.IllegalComponentStateException { + try { + com.sun.star.lang.Locale unoLocale = unoAccessibleContext.getLocale(); + return new java.util.Locale(unoLocale.Language, unoLocale.Country); + } catch (IllegalAccessibleComponentStateException e) { + throw new java.awt.IllegalComponentStateException(e.getMessage()); + } catch (com.sun.star.uno.RuntimeException e) { + return Tree.this.getLocale(); + } + } + + /** Gets the 0-based index of this object in its accessible parent */ + public int getAccessibleIndexInParent() { + try { + return unoAccessibleContext.getAccessibleIndexInParent(); + } catch (com.sun.star.uno.RuntimeException e) { + return -1; + } + } + + /** Returns the number of accessible children of the object. */ + public int getAccessibleChildrenCount() { + try { + return unoAccessibleContext.getAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Returns the specified Accessible child of the object. */ + public javax.accessibility.Accessible getAccessibleChild(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i); + // Re-use the active descandant wrapper if possible + javax.accessibility.Accessible activeDescendant = Tree.this.activeDescendant; + if ((activeDescendant instanceof TreeItem) && ((TreeItem) activeDescendant).unoAccessible.equals(xAccessible)) { + child = activeDescendant; + } else if (xAccessible != null) { + child = new TreeItem(xAccessible); + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /** Returns the state set of this object */ + public javax.accessibility.AccessibleStateSet getAccessibleStateSet() { + try { + return AccessibleStateAdapter.getAccessibleStateSet(TreeItem.this, + unoAccessibleContext.getAccessibleStateSet()); + } catch (com.sun.star.uno.RuntimeException e) { + return AccessibleStateAdapter.getDefunctStateSet(); + } + } + + /** Gets the AccessibleComponent associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleComponent getAccessibleComponent() { + try { + XAccessibleComponent unoAccessibleComponent = (XAccessibleComponent) + UnoRuntime.queryInterface(XAccessibleComponent.class, unoAccessibleContext); + return (unoAccessibleComponent != null) ? + new AccessibleComponentImpl(unoAccessibleComponent) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Returns the AccessibleSelection interface for this object */ + public javax.accessibility.AccessibleSelection getAccessibleSelection() { + return (unoAccessibleSelection != null) ? this : null; + } + + /** Gets the AccessibleAction associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleAction getAccessibleAction() { + try { + XAccessibleAction unoAccessibleAction = (XAccessibleAction) + UnoRuntime.queryInterface(XAccessibleAction.class, unoAccessibleContext); + return (unoAccessibleAction != null) ? + new AccessibleActionImpl(unoAccessibleAction) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleText associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleText getAccessibleText() { + + if (disposed) + return null; + + try { + XAccessibleText unoAccessibleText = (XAccessibleText) + UnoRuntime.queryInterface(XAccessibleText.class, unoAccessibleContext); + return (unoAccessibleText != null) ? + new AccessibleTextImpl(unoAccessibleText) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleValue associated with this object that has a graphical representation */ + public javax.accessibility.AccessibleValue getAccessibleValue() { + try { + XAccessibleValue unoAccessibleValue = (XAccessibleValue) + UnoRuntime.queryInterface(XAccessibleValue.class, unoAccessibleContext); + return (unoAccessibleValue != null) ? + new AccessibleValueImpl(unoAccessibleValue) : null; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the AccessibleText associated with this object presenting text on the display */ + public javax.accessibility.AccessibleIcon[] getAccessibleIcon() { + try { + XAccessibleImage unoAccessibleImage = (XAccessibleImage) + UnoRuntime.queryInterface(XAccessibleImage.class, unoAccessibleContext); + if (unoAccessibleImage != null) { + javax.accessibility.AccessibleIcon[] icons = { new AccessibleIconImpl(unoAccessibleImage) }; + return icons; + } + } catch (com.sun.star.uno.RuntimeException e) { + } + return null; + } + + /* + * AccessibleSelection + */ + + /** Returns an Accessible representing the specified selected child of the object */ + public javax.accessibility.Accessible getAccessibleSelection(int i) { + javax.accessibility.Accessible child = null; + try { + XAccessible xAccessible = unoAccessibleContext.getAccessibleChild(i); + if (xAccessible != null) { + child = new TreeItem(xAccessible); + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + return child; + } + + /** Adds the specified Accessible child of the object to the object's selection */ + public void addAccessibleSelection(int i) { + try { + unoAccessibleSelection.selectAccessibleChild(i); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Clears the selection in the object, so that no children in the object are selected */ + public void clearAccessibleSelection() { + try { + unoAccessibleSelection.clearAccessibleSelection(); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Returns the number of Accessible children currently selected */ + public int getAccessibleSelectionCount() { + try { + return unoAccessibleSelection.getSelectedAccessibleChildCount(); + } catch (com.sun.star.uno.RuntimeException e) { + return 0; + } + } + + /** Determines if the current child of this object is selected */ + public boolean isAccessibleChildSelected(int i) { + try { + return unoAccessibleSelection.isAccessibleChildSelected(i); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + return false; + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Removes the specified child of the object from the object's selection */ + public void removeAccessibleSelection(int i) { + try { + unoAccessibleSelection.deselectAccessibleChild(i); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + /** Causes every child of the object to be selected if the object supports multiple selection */ + public void selectAllAccessibleSelection() { + try { + unoAccessibleSelection.selectAllAccessibleChildren(); + } catch (com.sun.star.uno.RuntimeException e) { + } + } + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/Window.java b/accessibility/bridge/org/openoffice/java/accessibility/Window.java new file mode 100644 index 000000000000..ef44c3380a48 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/Window.java @@ -0,0 +1,551 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility; + +import com.sun.star.uno.*; +import com.sun.star.accessibility.*; + +public class Window extends java.awt.Window implements javax.accessibility.Accessible, NativeFrame { + protected XAccessibleComponent unoAccessibleComponent; + + boolean opened = false; + boolean visible = false; + + java.awt.EventQueue eventQueue = null; + + public Window(java.awt.Window owner, XAccessibleComponent xAccessibleComponent) { + super(owner); + initialize(xAccessibleComponent); + } + + private void initialize(XAccessibleComponent xAccessibleComponent) { + unoAccessibleComponent = xAccessibleComponent; + eventQueue = java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue(); + XAccessibleEventBroadcaster broadcaster = (XAccessibleEventBroadcaster) + UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, + unoAccessibleComponent); + if (broadcaster != null) { + broadcaster.addEventListener(new AccessibleWindowListener()); + } + } + + java.awt.Component initialComponent = null; + + public java.awt.Component getInitialComponent() { + if (Build.DEBUG) { + System.err.println("returning initial component object of class: " + initialComponent.getClass().getName()); + } + return initialComponent; + } + + public void setInitialComponent(java.awt.Component c) { + initialComponent = c; + } + + public Integer getHWND() { + return null; + } + + /** + * Determines whether this <code>Component</code> is showing on screen. + * This means that the component must be visible, and it must be in a + * <code>container</code> that is visible and showing. + * @see #addNotify + * @see #removeNotify + * @since JDK1.0 + */ + public boolean isShowing() { + if (isVisible()) { + java.awt.Container parent = getParent(); + return (parent == null) || parent.isShowing(); + } + return false; + } + + /** + * Makes this <code>Component</code> displayable by connecting it to a + * native screen resource. + * This method is called internally by the toolkit and should + * not be called directly by programs. + * @see #isDisplayable + * @see #removeNotify + * @since JDK1.0 + */ + public void addNotify() { +// createHierarchyEvents(0, null, null, 0, false); + } + + /** + * Makes this <code>Component</code> undisplayable by destroying it native + * screen resource. + * This method is called by the toolkit internally and should + * not be called directly by programs. + * @see #isDisplayable + * @see #addNotify + * @since JDK1.0 + */ + public void removeNotify() { + } + + /** + * Determines if the object is visible. Note: this means that the + * object intends to be visible; however, it may not in fact be + * showing on the screen because one of the objects that this object + * is contained by is not visible. To determine if an object is + * showing on the screen, use <code>isShowing</code>. + * + * @return true if object is visible; otherwise, false + */ + public boolean isVisible(){ + return visible; + } + + /** + * Shows or hides this component depending on the value of parameter + * <code>b</code>. + * @param b if <code>true</code>, shows this component; + * otherwise, hides this component + * @see #isVisible + * @since JDK1.1 + */ + public void setVisible(boolean b) { + if (visible != b){ + visible = b; + if (b) { + // If it is the first show, fire WINDOW_OPENED event + if (!opened) { + postWindowEvent(java.awt.event.WindowEvent.WINDOW_OPENED); + opened = true; + } + postComponentEvent(java.awt.event.ComponentEvent.COMPONENT_SHOWN); + } else { + postComponentEvent(java.awt.event.ComponentEvent.COMPONENT_HIDDEN); + } + } + } + + public void dispose() { + setVisible(false); + postWindowEvent(java.awt.event.WindowEvent.WINDOW_CLOSED); + + // Transfer window focus back to the owner window if it is still the active frame + if ((getOwner() instanceof Frame && ((Frame) getOwner()).active) || + (getOwner() instanceof Dialog && ((Dialog) getOwner()).active)) { + eventQueue.postEvent(new java.awt.event.WindowEvent(getOwner(), + java.awt.event.WindowEvent.WINDOW_GAINED_FOCUS)); + } + } + + protected void postWindowEvent(int i) { + eventQueue.postEvent(new java.awt.event.WindowEvent(this, i)); + } + + protected void postComponentEvent(int i) { + eventQueue.postEvent(new java.awt.event.ComponentEvent(this, i)); + } + + /** + * Update the proxy objects appropriatly on property change events + */ + protected class AccessibleWindowListener implements XAccessibleEventListener { + + protected AccessibleWindowListener() { + } + + // The only expected state changes are ACTIVE and VISIBLE + protected void setComponentState(short state, boolean enable) { + switch (state) { + case AccessibleStateType.ICONIFIED: + postWindowEvent(enable ? + java.awt.event.WindowEvent.WINDOW_ICONIFIED : + java.awt.event.WindowEvent.WINDOW_DEICONIFIED); + break; + case AccessibleStateType.SHOWING: + case AccessibleStateType.VISIBLE: + setVisible(enable); + break; + default: + if (Build.DEBUG) { +// System.err.println("[frame]: " + getTitle() + "unexpected state change " + state); + } + break; + } + } + + /** Updates the accessible name and fires the appropriate PropertyChangedEvent */ + protected void handleNameChangedEvent(Object any) { + try { + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + javax.accessibility.AccessibleContext ac = accessibleContext; + if (ac!= null) { + ac.setAccessibleName(AnyConverter.toString(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the accessible description and fires the appropriate PropertyChangedEvent */ + protected void handleDescriptionChangedEvent(Object any) { + try { + // This causes the property change event to be fired in the VCL thread + // context. If this causes problems, it has to be deligated to the java + // dispatch thread .. + if (accessibleContext != null) { + accessibleContext.setAccessibleDescription(AnyConverter.toString(any)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Updates the internal states and fires the appropriate PropertyChangedEvent */ + protected void handleStateChangedEvent(Object any1, Object any2) { + try { + if (AnyConverter.isShort(any1)) { + setComponentState(AnyConverter.toShort(any1), false); + } + + if (AnyConverter.isShort(any2)) { + setComponentState(AnyConverter.toShort(any2), true); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + /** Fires a visible data property change event */ + protected void handleVisibleDataEvent() { + javax.accessibility.AccessibleContext ac = accessibleContext; + if (ac != null) { + ac.firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, null, null); + } + } + + /** Called by OpenOffice process to notify property changes */ + public void notifyEvent(AccessibleEventObject event) { + switch (event.EventId) { + case AccessibleEventId.NAME_CHANGED: + // Set the accessible name for the corresponding context, which will fire a property + // change event itself + handleNameChangedEvent(event.NewValue); + break; + case AccessibleEventId.DESCRIPTION_CHANGED: + // Set the accessible description for the corresponding context, which will fire a property + // change event itself - so do not set propertyName ! + handleDescriptionChangedEvent(event.NewValue); + break; + case AccessibleEventId.STATE_CHANGED: + // Update the internal state set and fire the appropriate PropertyChangedEvent + handleStateChangedEvent(event.OldValue, event.NewValue); + break; + case AccessibleEventId.CHILD: + if (AnyConverter.isObject(event.OldValue)) { + AccessibleObjectFactory.removeChild(Window.this, event.OldValue); + } else if (AnyConverter.isObject(event.NewValue)) { + AccessibleObjectFactory.addChild(Window.this, event.NewValue); + } + break; + case AccessibleEventId.VISIBLE_DATA_CHANGED: + case AccessibleEventId.BOUNDRECT_CHANGED: + handleVisibleDataEvent(); + break; + default: + // Warn about unhandled events + if(Build.DEBUG) { + System.out.println(this + ": unhandled accessibility event id=" + event.EventId); + } + } + } + + /** Called by OpenOffice process to notify that the UNO component is disposing */ + public void disposing(com.sun.star.lang.EventObject eventObject) { + } + } + + protected javax.accessibility.AccessibleContext accessibleContext = null; + + /** Returns the AccessibleContext associated with this object */ + public javax.accessibility.AccessibleContext getAccessibleContext() { + if (accessibleContext == null) { + accessibleContext = new AccessibleWindow(); +// accessibleContext.setAccessibleName(getTitle()); + } + return accessibleContext; + } + + protected class AccessibleWindow extends java.awt.Window.AccessibleAWTWindow { + protected AccessibleWindow() { + super(); + } + + protected java.awt.event.ComponentListener accessibleComponentHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when shown/hidden.. + */ + protected class AccessibleComponentHandler implements java.awt.event.ComponentListener { + public void componentHidden(java.awt.event.ComponentEvent e) { + AccessibleWindow.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + javax.accessibility.AccessibleState.VISIBLE, null); + } + + public void componentShown(java.awt.event.ComponentEvent e) { + AccessibleWindow.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_STATE_PROPERTY, + null, javax.accessibility.AccessibleState.VISIBLE); + } + + public void componentMoved(java.awt.event.ComponentEvent e) { + } + + public void componentResized(java.awt.event.ComponentEvent e) { + } + } // inner class AccessibleComponentHandler + + protected java.awt.event.ContainerListener accessibleContainerHandler = null; + + /** + * Fire PropertyChange listener, if one is registered, + * when children added/removed. + */ + + protected class AccessibleContainerHandler implements java.awt.event.ContainerListener { + public void componentAdded(java.awt.event.ContainerEvent e) { + java.awt.Component c = e.getChild(); + if (c != null && c instanceof javax.accessibility.Accessible) { + AccessibleWindow.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + null, ((javax.accessibility.Accessible) c).getAccessibleContext()); + } + } + public void componentRemoved(java.awt.event.ContainerEvent e) { + java.awt.Component c = e.getChild(); + if (c != null && c instanceof javax.accessibility.Accessible) { + AccessibleWindow.this.firePropertyChange( + javax.accessibility.AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, + ((javax.accessibility.Accessible) c).getAccessibleContext(), null); + } + } + } + + protected int propertyChangeListenerCount = 0; + + /** + * Add a PropertyChangeListener to the listener list. + * + * @param listener The PropertyChangeListener to be added + */ + public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (propertyChangeListenerCount++ == 0) { + accessibleContainerHandler = new AccessibleContainerHandler(); + Window.this.addContainerListener(accessibleContainerHandler); + + accessibleComponentHandler = new AccessibleComponentHandler(); + Window.this.addComponentListener(accessibleComponentHandler); + } + super.addPropertyChangeListener(listener); + } + + /** + * Remove a PropertyChangeListener from the listener list. + * This removes a PropertyChangeListener that was registered + * for all properties. + * + * @param listener The PropertyChangeListener to be removed + */ + public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) { + if (--propertyChangeListenerCount == 0) { + Window.this.removeComponentListener(accessibleComponentHandler); + accessibleComponentHandler = null; + + Window.this.removeContainerListener(accessibleContainerHandler); + accessibleContainerHandler = null; + } + super.removePropertyChangeListener(listener); + } + + /* + * AccessibleComponent + */ + + /** Returns the background color of the object */ + public java.awt.Color getBackground() { + try { + return new java.awt.Color(unoAccessibleComponent.getBackground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setBackground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + /** Returns the foreground color of the object */ + public java.awt.Color getForeground() { + try { + return new java.awt.Color(unoAccessibleComponent.getForeground()); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public void setForeground(java.awt.Color c) { + // Not supported by UNO accessibility API + } + + public java.awt.Cursor getCursor() { + // Not supported by UNO accessibility API + return null; + } + + public void setCursor(java.awt.Cursor cursor) { + // Not supported by UNO accessibility API + } + + public java.awt.Font getFont() { + // FIXME + return null; + } + + public void setFont(java.awt.Font f) { + // Not supported by UNO accessibility API + } + + public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { + // FIXME + return null; + } + + public boolean isEnabled() { + return Window.this.isEnabled(); + } + + public void setEnabled(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isVisible() { + return Window.this.isVisible(); + } + + public void setVisible(boolean b) { + // Not supported by UNO accessibility API + } + + public boolean isShowing() { + return Window.this.isShowing(); + } + + public boolean contains(java.awt.Point p) { + try { + return unoAccessibleComponent.containsPoint(new com.sun.star.awt.Point(p.x, p.y)); + } catch (com.sun.star.uno.RuntimeException e) { + return false; + } + } + + /** Returns the location of the object on the screen. */ + public java.awt.Point getLocationOnScreen() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocationOnScreen(); + return new java.awt.Point(unoPoint.X, unoPoint.Y); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Gets the location of this component in the form of a point specifying the component's top-left corner */ + public java.awt.Point getLocation() { + try { + com.sun.star.awt.Point unoPoint = unoAccessibleComponent.getLocationOnScreen(); + return new java.awt.Point( unoPoint.X, unoPoint.Y ); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves this component to a new location */ + public void setLocation(java.awt.Point p) { + // Not supported by UNO accessibility API + } + + /** Gets the bounds of this component in the form of a Rectangle object */ + public java.awt.Rectangle getBounds() { + try { + com.sun.star.awt.Rectangle unoRect = unoAccessibleComponent.getBounds(); + return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Moves and resizes this component to conform to the new bounding rectangle r */ + public void setBounds(java.awt.Rectangle r) { + // Not supported by UNO accessibility API + } + + /** Returns the size of this component in the form of a Dimension object */ + public java.awt.Dimension getSize() { + try { + com.sun.star.awt.Size unoSize = unoAccessibleComponent.getSize(); + return new java.awt.Dimension(unoSize.Width, unoSize.Height); + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + /** Resizes this component so that it has width d.width and height d.height */ + public void setSize(java.awt.Dimension d) { + // Not supported by UNO accessibility API + } + + /** Returns the Accessible child, if one exists, contained at the local coordinate Point */ + public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) { + try { + java.awt.Component c = AccessibleObjectFactory.getAccessibleComponent( + unoAccessibleComponent.getAccessibleAtPoint(new com.sun.star.awt.Point(p.x, p.y))); + + return (javax.accessibility.Accessible) c; + } catch (com.sun.star.uno.RuntimeException e) { + return null; + } + } + + public boolean isFocusTraversable() { + return Window.this.isFocusable(); + } + + public void requestFocus() { + unoAccessibleComponent.grabFocus(); + } + } +} + diff --git a/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleEventLog.java b/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleEventLog.java new file mode 100644 index 000000000000..36bec1cab8fb --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleEventLog.java @@ -0,0 +1,186 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility.logging; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + +/** + * + */ +public class XAccessibleEventLog implements XAccessibleEventListener { + + private static XAccessibleEventLog theEventListener = null; + + private static java.util.Hashtable proxyList = new java.util.Hashtable(); + + /** Creates a new instance of UNOAccessibleEventListener */ + public XAccessibleEventLog() { + } + + private static XAccessibleEventListener get() { + if (theEventListener == null) { + theEventListener = new XAccessibleEventLog(); + } + return theEventListener; + } + + public static void addEventListener(XAccessibleContext xac, java.awt.Component c) { + XAccessibleEventBroadcaster broadcaster = (XAccessibleEventBroadcaster) + UnoRuntime.queryInterface(XAccessibleEventBroadcaster.class, xac); + if (broadcaster != null) { + broadcaster.addEventListener(XAccessibleEventLog.get()); + + // remember the proxy objects + synchronized (proxyList) { +// proxyList.put(UnoRuntime.generateOid(xac), new WeakReference(c)); + proxyList.put(UnoRuntime.generateOid(xac), c); + } + } + } + + public void disposing(com.sun.star.lang.EventObject eventObject) { + } + + public void notifyEvent(com.sun.star.accessibility.AccessibleEventObject accessibleEventObject) { + switch (accessibleEventObject.EventId) { + case AccessibleEventId.ACTIVE_DESCENDANT_CHANGED: + logMessage(accessibleEventObject.Source, "Retrieved active descendant event."); + break; + case AccessibleEventId.STATE_CHANGED: + logStateChange(accessibleEventObject.Source, + accessibleEventObject.OldValue, + accessibleEventObject.NewValue); + break; + case AccessibleEventId.CHILD: + logMessage(accessibleEventObject.Source, "Retrieved children event."); + break; + case AccessibleEventId.BOUNDRECT_CHANGED: + logMessage(accessibleEventObject.Source, "Retrieved boundrect changed event."); + break; + case AccessibleEventId.VISIBLE_DATA_CHANGED: + logMessage(accessibleEventObject.Source, "Retrieved visible data changed event."); + break; + case AccessibleEventId.INVALIDATE_ALL_CHILDREN: + logMessage(accessibleEventObject.Source, "Retrieved invalidate children event."); + break; + default: + break; + } + } + + public void logStateChange(Object o, Object any1, Object any2) { + try { + if (AnyConverter.isShort(any1)) { + logStateChange(o, AnyConverter.toShort(any1), " is no longer "); + } + + if (AnyConverter.isShort(any2)) { + logStateChange(o, AnyConverter.toShort(any2), " is now "); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + } + } + + public void logStateChange(Object o, short n, String s) { + switch(n) { + case AccessibleStateType.ACTIVE: + logMessage(o, s + javax.accessibility.AccessibleState.ACTIVE); + break; + case AccessibleStateType.ARMED: + logMessage(o, s + javax.accessibility.AccessibleState.ARMED); + break; + case AccessibleStateType.CHECKED: + logMessage(o, s + javax.accessibility.AccessibleState.CHECKED); + break; + case AccessibleStateType.ENABLED: + logMessage(o, s + javax.accessibility.AccessibleState.ENABLED); + break; + case AccessibleStateType.FOCUSED: + logMessage(o, s + javax.accessibility.AccessibleState.FOCUSED); + break; + case AccessibleStateType.PRESSED: + logMessage(o, s + javax.accessibility.AccessibleState.PRESSED); + break; + case AccessibleStateType.SELECTED: + logMessage(o, s + javax.accessibility.AccessibleState.SELECTED); + break; + case AccessibleStateType.SENSITIVE: + logMessage(o, s + "sensitive"); + break; + case AccessibleStateType.SHOWING: + logMessage(o, s + javax.accessibility.AccessibleState.SHOWING); + break; + case AccessibleStateType.VISIBLE: + logMessage(o, s + javax.accessibility.AccessibleState.VISIBLE); + break; + default: + logMessage(o, s + "??? (FIXME)"); + break; + } + } + + protected static void logMessage(Object o, String s) { + XAccessibleContext xac = (XAccessibleContext) UnoRuntime.queryInterface(XAccessibleContext.class, o); + if( xac != null ) { + String oid = UnoRuntime.generateOid(xac); + synchronized (proxyList) { + logMessage( (javax.accessibility.Accessible) proxyList.get( oid ), s ); +// WeakReference r = (WeakReference) proxyList.get( oid ); +// if(r != null) { +// System.err.println( "*** Warning *** event is " + r.get() ); +// logMessage( (javax.accessibility.Accessible) r.get(), s ); +// } else { +// System.err.println( "*** Warning *** event source not found in broadcaster list" ); +// } + } + } else + System.err.println( "*** Warning *** event source does not implement XAccessibleContext" ); + } + + protected static void logMessage(javax.accessibility.Accessible a, String s) { + if (a != null) { + logMessage(a.getAccessibleContext(), s); + } else { + logMessage(s); + } + } + + protected static void logMessage(javax.accessibility.AccessibleContext ac, String s) { + if (ac != null) { + logMessage("[" + ac.getAccessibleRole() + "] " + + ac.getAccessibleName() + ": " + s); + } else { + logMessage(s); + } + } + + protected static void logMessage(String s) { + System.err.println(s); + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleHypertextLog.java b/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleHypertextLog.java new file mode 100644 index 000000000000..f14da6d8280b --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleHypertextLog.java @@ -0,0 +1,61 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.java.accessibility.logging; + +import com.sun.star.accessibility.*; +import com.sun.star.uno.*; + +/** The AccessibleHypertextImpl mapps all calls to the java AccessibleHypertext + * interface to the corresponding methods of the UNO XAccessibleHypertext + * interface. + */ +public class XAccessibleHypertextLog extends XAccessibleTextLog + implements com.sun.star.accessibility.XAccessibleHypertext { + + private com.sun.star.accessibility.XAccessibleHypertext unoObject; + + /** Creates a new instance of XAccessibleTextLog */ + public XAccessibleHypertextLog(XAccessibleHypertext xAccessibleHypertext) { + super(xAccessibleHypertext); + unoObject = xAccessibleHypertext; + } + + public XAccessibleHyperlink getHyperLink(int param) + throws com.sun.star.lang.IndexOutOfBoundsException { + return unoObject.getHyperLink(param); + } + + public int getHyperLinkCount() { + return unoObject.getHyperLinkCount(); + } + + public int getHyperLinkIndex(int param) + throws com.sun.star.lang.IndexOutOfBoundsException { + return unoObject.getHyperLinkIndex(param); + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleTextLog.java b/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleTextLog.java new file mode 100644 index 000000000000..4b415ee60c74 --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/logging/XAccessibleTextLog.java @@ -0,0 +1,270 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package org.openoffice.java.accessibility.logging; + +import org.openoffice.java.accessibility.*; + + +/** + * + */ +public class XAccessibleTextLog + implements com.sun.star.accessibility.XAccessibleText { + private com.sun.star.accessibility.XAccessibleText unoObject; + private String name = "[Unknown] NoName"; + + /** Creates a new instance of XAccessibleTextLog */ + public XAccessibleTextLog( + com.sun.star.accessibility.XAccessibleText xAccessibleText) { + unoObject = xAccessibleText; + setName(xAccessibleText); + } + + private void setName( + com.sun.star.accessibility.XAccessibleText xAccessibleText) { + try { + com.sun.star.accessibility.XAccessibleContext unoAccessibleContext = (com.sun.star.accessibility.XAccessibleContext) com.sun.star.uno.UnoRuntime.queryInterface(com.sun.star.accessibility.XAccessibleContext.class, + xAccessibleText); + + if (unoAccessibleContext != null) { + name = "[" + + AccessibleRoleAdapter.getAccessibleRole(unoAccessibleContext.getAccessibleRole()) + + "] " + unoAccessibleContext.getAccessibleName() + ": "; + } + } catch (com.sun.star.uno.RuntimeException e) { + } + } + + private String getPartString(short s) { + String part = "INVALID"; + + switch (s) { + case com.sun.star.accessibility.AccessibleTextType.CHARACTER: + part = "CHARACTER"; + + break; + + case com.sun.star.accessibility.AccessibleTextType.WORD: + part = "WORD"; + + break; + + case com.sun.star.accessibility.AccessibleTextType.SENTENCE: + part = "SENTENCE"; + + break; + + case com.sun.star.accessibility.AccessibleTextType.LINE: + part = "LINE"; + + break; + + case com.sun.star.accessibility.AccessibleTextType.ATTRIBUTE_RUN: + part = "ATTRIBUTE_RUN"; + + break; + + default: + break; + } + + return part; + } + + private String dumpTextSegment(com.sun.star.accessibility.TextSegment ts) { + if (ts != null) { + return "(" + ts.SegmentStart + "," + ts.SegmentEnd + "," + + ts.SegmentText + ")"; + } + + return "NULL"; + } + + public boolean copyText(int param, int param1) + throws com.sun.star.lang.IndexOutOfBoundsException { + return unoObject.copyText(param, param1); + } + + public int getCaretPosition() { + int pos = unoObject.getCaretPosition(); + System.err.println(name + "getCaretPosition() returns " + pos); + + return pos; + } + + public char getCharacter(int param) + throws com.sun.star.lang.IndexOutOfBoundsException { + return unoObject.getCharacter(param); + } + + public com.sun.star.beans.PropertyValue[] getCharacterAttributes( + int param, String[] str) + throws com.sun.star.lang.IndexOutOfBoundsException { + return unoObject.getCharacterAttributes(param, str); + } + + public com.sun.star.awt.Rectangle getCharacterBounds(int param) + throws com.sun.star.lang.IndexOutOfBoundsException { + try { + com.sun.star.awt.Rectangle r = unoObject.getCharacterBounds(param); + System.err.println(name + "getCharacterBounds(" + param + + ") returns (" + r.X + "," + r.Y + "," + r.Width + "," + + r.Height + ")"); + + return r; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + System.err.println("IndexOutOufBoundsException caught for " + name + + "getCharacterBounds(" + param + ")"); + throw e; + } + } + + public int getCharacterCount() { + return unoObject.getCharacterCount(); + } + + public int getIndexAtPoint(com.sun.star.awt.Point point) { + try { + int index = unoObject.getIndexAtPoint(point); + System.err.println(name + "getIndexAtPoint(" + point.X + ", " + + point.Y + ") returns " + index); + + return index; + } catch (com.sun.star.uno.RuntimeException e) { + System.err.println(name + + "RuntimeException caught for getIndexAtPoint(" + point.X + + ", " + point.Y + ")"); + System.err.println(e.getMessage()); + throw e; + } + } + + public String getSelectedText() { + return unoObject.getSelectedText(); + } + + public int getSelectionEnd() { + return unoObject.getSelectionEnd(); + } + + public int getSelectionStart() { + return unoObject.getSelectionStart(); + } + + public String getText() { + return unoObject.getText(); + } + + public com.sun.star.accessibility.TextSegment getTextAtIndex(int param, + short param1) + throws com.sun.star.lang.IndexOutOfBoundsException, + com.sun.star.lang.IllegalArgumentException { + try { + com.sun.star.accessibility.TextSegment ts = unoObject.getTextAtIndex(param, + param1); + System.err.println(name + "getTextAtIndex(" + + getPartString(param1) + "," + param + ") returns " + + dumpTextSegment(ts)); + + return ts; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + System.err.println("IndexOutOufBoundsException caught for " + name + + " getTextAtIndex(" + getPartString(param1) + "," + param1 + + ")"); + throw e; + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.err.println("IllegalArgumentException caught for " + name + + " getTextAtIndex(" + getPartString(param1) + "," + param + ")"); + throw e; + } + } + + public com.sun.star.accessibility.TextSegment getTextBeforeIndex( + int param, short param1) + throws com.sun.star.lang.IndexOutOfBoundsException, + com.sun.star.lang.IllegalArgumentException { + try { + com.sun.star.accessibility.TextSegment ts = unoObject.getTextBeforeIndex(param, + param1); + System.err.println(name + " getTextBeforeIndex(" + + getPartString(param1) + "," + param + ") returns " + + dumpTextSegment(ts)); + + return ts; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + System.err.println("IndexOutOufBoundsException caught for " + name + + " getTextBeforeIndex(" + getPartString(param1) + "," + param1 + + ")"); + throw e; + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.err.println("IllegalArgumentException caught for " + name + + " getTextBeforeIndex(" + getPartString(param1) + "," + param + + ")"); + throw e; + } + } + + public com.sun.star.accessibility.TextSegment getTextBehindIndex( + int param, short param1) + throws com.sun.star.lang.IndexOutOfBoundsException, + com.sun.star.lang.IllegalArgumentException { + try { + com.sun.star.accessibility.TextSegment ts = unoObject.getTextBehindIndex(param, + param1); + System.err.println(name + " getTextBehindIndex(" + + getPartString(param1) + "," + param + ") returns " + + dumpTextSegment(ts)); + + return ts; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + System.err.println("IndexOutOufBoundsException caught for " + name + + " getTextBehindIndex(" + getPartString(param1) + "," + param1 + + ")"); + throw e; + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.err.println("IllegalArgumentException caught for " + name + + " getTextBehindIndex(" + getPartString(param1) + "," + param + + ")"); + throw e; + } + } + + public String getTextRange(int param, int param1) + throws com.sun.star.lang.IndexOutOfBoundsException { + return unoObject.getTextRange(param, param1); + } + + public boolean setCaretPosition(int param) + throws com.sun.star.lang.IndexOutOfBoundsException { + return unoObject.setCaretPosition(param); + } + + public boolean setSelection(int param, int param1) + throws com.sun.star.lang.IndexOutOfBoundsException { + return unoObject.setSelection(param, param1); + } +} diff --git a/accessibility/bridge/org/openoffice/java/accessibility/makefile.mk b/accessibility/bridge/org/openoffice/java/accessibility/makefile.mk new file mode 100755 index 000000000000..0d98760a31df --- /dev/null +++ b/accessibility/bridge/org/openoffice/java/accessibility/makefile.mk @@ -0,0 +1,115 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJNAME = accessibility +PRJ = ..$/..$/..$/..$/.. +TARGET = java_accessibility +PACKAGE = org$/openoffice$/java$/accessibility + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +JAVADIR = $(OUT)$/misc$/java +JARFILES = jurt.jar unoil.jar ridl.jar +JAVAFILES = \ + logging$/XAccessibleEventLog.java \ + logging$/XAccessibleHypertextLog.java \ + logging$/XAccessibleTextLog.java \ + AbstractButton.java \ + AccessibleActionImpl.java \ + AccessibleComponentImpl.java \ + AccessibleEditableTextImpl.java \ + AccessibleExtendedState.java \ + AccessibleHypertextImpl.java \ + AccessibleIconImpl.java \ + AccessibleKeyBinding.java \ + AccessibleObjectFactory.java \ + AccessibleRoleAdapter.java \ + AccessibleSelectionImpl.java \ + AccessibleStateAdapter.java \ + AccessibleTextImpl.java \ + AccessibleValueImpl.java \ + Alert.java \ + Application.java \ + Button.java \ + CheckBox.java \ + ComboBox.java \ + Component.java \ + Container.java \ + DescendantManager.java \ + Dialog.java \ + FocusTraversalPolicy.java \ + Frame.java \ + Icon.java \ + Label.java \ + List.java \ + Menu.java \ + MenuItem.java \ + MenuContainer.java \ + NativeFrame.java \ + Paragraph.java \ + RadioButton.java \ + ScrollBar.java \ + Separator.java \ + Table.java \ + TextComponent.java \ + ToggleButton.java \ + ToolTip.java \ + Tree.java \ + Window.java + +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:s/.java//).class) $(CLASSDIR)$/$(PACKAGE)$/Build.class + +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE +JARCLASSDIRS = $(PACKAGE) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +# Enable logging in non-product only +.IF "$(PRODUCT)"!="" +DEBUGSWITCH = false +PRODUCTSWITCH = true +.ELSE +PRODUCTSWITCH = false +DEBUGSWITCH = true +.ENDIF + +$(JAVADIR)$/$(PACKAGE)$/%.java: makefile.mk + @@-$(MKDIRHIER) $(JAVADIR)$/$(PACKAGE) + @-echo package org.openoffice.java.accessibility\; > $@ + @-echo public class Build { >> $@ + @-echo public static final boolean DEBUG = $(DEBUGSWITCH)\; >> $@ + @-echo public static final boolean PRODUCT = $(PRODUCTSWITCH)\; >> $@ + @-echo } >> $@ + +$(CLASSDIR)$/$(PACKAGE)$/Build.class : $(JAVADIR)$/$(PACKAGE)$/Build.java + -$(JAVAC) -d $(CLASSDIR) $(JAVADIR)$/$(PACKAGE)$/Build.java + |