comparison dwt/accessibility/Accessible.d @ 60:62202ce0039f

Updated and fixed many modules to 3.514
author Jacob Carlborg <doob@me.com>
date Mon, 22 Dec 2008 15:10:19 +0100
parents 83b0ad9d9238
children c74ba20de292
comparison
equal deleted inserted replaced
59:83b0ad9d9238 60:62202ce0039f
34 import dwt.widgets.Control; 34 import dwt.widgets.Control;
35 import dwt.widgets.Display; 35 import dwt.widgets.Display;
36 import dwt.widgets.Monitor; 36 import dwt.widgets.Monitor;
37 import dwt.widgets.Shell; 37 import dwt.widgets.Shell;
38 38
39 import tango.core.Thread;
39 import tango.util.container.HashMap; 40 import tango.util.container.HashMap;
40 41
42 import dwt.accessibility.ACC;
43 import dwt.accessibility.AccessibleControlEvent;
44 import dwt.accessibility.AccessibleEvent;
41 import dwt.accessibility.AccessibleListener; 45 import dwt.accessibility.AccessibleListener;
42 import dwt.accessibility.AccessibleControlListener; 46 import dwt.accessibility.AccessibleControlListener;
47 import dwt.accessibility.AccessibleTextEvent;
43 import dwt.accessibility.AccessibleTextListener; 48 import dwt.accessibility.AccessibleTextListener;
44 import dwt.accessibility.SWTAccessibleDelegate; 49 import dwt.accessibility.SWTAccessibleDelegate;
45 import dwt.dwthelper.array; 50 import dwt.dwthelper.array;
46 51
47 /** 52 /**
229 // The supported action list depends on the role played by the control. 234 // The supported action list depends on the role played by the control.
230 AccessibleControlEvent event = new AccessibleControlEvent(this); 235 AccessibleControlEvent event = new AccessibleControlEvent(this);
231 event.childID = childID; 236 event.childID = childID;
232 event.detail = -1; 237 event.detail = -1;
233 for (int i = 0; i < accessibleControlListeners.size(); i++) { 238 for (int i = 0; i < accessibleControlListeners.size(); i++) {
234 AccessibleControlListener listener = accessibleControlListeners.elementAt(i); 239 AccessibleControlListener listener = elementAt(accessibleControlListeners, i);
235 listener.getRole(event); 240 listener.getRole(event);
236 } 241 }
237 242
238 // No accessible listener is overriding the role of the control, so let Cocoa return the default set for the control. 243 // No accessible listener is overriding the role of the control, so let Cocoa return the default set for the control.
239 if (event.detail is -1) { 244 if (event.detail is -1) {
359 * Only report back sub-roles when the DWT role maps to a sub-role. 364 * Only report back sub-roles when the DWT role maps to a sub-role.
360 */ 365 */
361 if (event.detail !is -1) { 366 if (event.detail !is -1) {
362 String osRole = roleToOs(event.detail); 367 String osRole = roleToOs(event.detail);
363 368
364 if (osRole.indexOf(':') is -1) 369 if (dwt.dwthelper.utils.indexOf(osRole, ':') is -1)
365 returnValue.removeObject(OS.NSAccessibilitySubroleAttribute); 370 returnValue.removeObject(OS.NSAccessibilitySubroleAttribute);
366 } 371 }
367 372
368 /* 373 /*
369 * Children never return their own children, so remove that attribute. 374 * Children never return their own children, so remove that attribute.
451 // You can assume the point has already been determined to lie within the receiver. 456 // You can assume the point has already been determined to lie within the receiver.
452 // Override this method to do deeper hit testing within a UIElement - e.g. a NSMatrix would test its cells. The point is bottom-left relative screen coordinates. 457 // Override this method to do deeper hit testing within a UIElement - e.g. a NSMatrix would test its cells. The point is bottom-left relative screen coordinates.
453 public cocoa.id internal_accessibilityHitTest(NSPoint point, int childID) { 458 public cocoa.id internal_accessibilityHitTest(NSPoint point, int childID) {
454 AccessibleControlEvent event = new AccessibleControlEvent(this); 459 AccessibleControlEvent event = new AccessibleControlEvent(this);
455 event.x = cast(int) point.x; 460 event.x = cast(int) point.x;
456 Monitor primaryMonitor = Display.getCurrent().getPrimaryMonitor(); 461 dwt.widgets.Monitor.Monitor primaryMonitor = Display.getCurrent().getPrimaryMonitor();
457 event.y = cast(int) (primaryMonitor.getBounds().height - point.y); 462 event.y = cast(int) (primaryMonitor.getBounds().height - point.y);
458 463
459 // Set an impossible value to determine if anything responded to the event. 464 // Set an impossible value to determine if anything responded to the event.
460 event.childID = ACC.CHILDID_MULTIPLE; 465 event.childID = ACC.CHILDID_MULTIPLE;
461 for (int i = 0; i < accessibleControlListeners.size(); i++) { 466 for (int i = 0; i < accessibleControlListeners.size(); i++) {
584 AccessibleControlListener listener = accessibleControlListeners.elementAt(i); 589 AccessibleControlListener listener = accessibleControlListeners.elementAt(i);
585 listener.getRole(event); 590 listener.getRole(event);
586 } 591 }
587 if (event.detail !is -1) { 592 if (event.detail !is -1) {
588 String appRole = roleToOs (event.detail); 593 String appRole = roleToOs (event.detail);
589 int index = appRole.indexOf(':'); 594 int index = dwt.dwthelper.utils.indexOf(appRole, ':');
590 if (index !is -1) appRole = appRole.substring(0, index); 595 if (index !is -1) appRole = appRole.substring(0, index);
591 returnValue = NSString.stringWith(appRole); 596 returnValue = NSString.stringWith(appRole);
592 } 597 }
593 598
594 return returnValue; 599 return returnValue;
603 AccessibleControlListener listener = accessibleControlListeners.elementAt(i); 608 AccessibleControlListener listener = accessibleControlListeners.elementAt(i);
604 listener.getRole(event); 609 listener.getRole(event);
605 } 610 }
606 if (event.detail !is -1) { 611 if (event.detail !is -1) {
607 String appRole = roleToOs (event.detail); 612 String appRole = roleToOs (event.detail);
608 int index = appRole.indexOf(':'); 613 int index = dwt.dwthelper.utils.indexOf(appRole, ':');
609 if (index !is -1) { 614 if (index !is -1) {
610 appRole = appRole.substring(index + 1); 615 appRole = appRole.substring(index + 1);
611 returnValue = NSString.stringWith(appRole); 616 returnValue = NSString.stringWith(appRole);
612 } 617 }
613 } 618 }
624 listener.getRole(event); 629 listener.getRole(event);
625 } 630 }
626 if (event.detail !is -1) { 631 if (event.detail !is -1) {
627 String appRole = roleToOs (event.detail); 632 String appRole = roleToOs (event.detail);
628 String appSubrole = null; 633 String appSubrole = null;
629 int index = appRole.indexOf(':'); 634 int index = dwt.dwthelper.utils.indexOf(appRole, ':');
630 if (index !is -1) { 635 if (index !is -1) {
631 appSubrole = appRole.substring(index + 1); 636 appSubrole = appRole.substring(index + 1);
632 appRole = appRole.substring(0, index); 637 appRole = appRole.substring(0, index);
633 } 638 }
634 NSString nsAppRole = NSString.stringWith(appRole); 639 NSString nsAppRole = NSString.stringWith(appRole);
669 } 674 }
670 return returnValue; 675 return returnValue;
671 } 676 }
672 677
673 cocoa.id getValueAttribute (int childID) { 678 cocoa.id getValueAttribute (int childID) {
674 id returnValue = null; 679 cocoa.id returnValue = null;
675 AccessibleControlEvent event = new AccessibleControlEvent(this); 680 AccessibleControlEvent event = new AccessibleControlEvent(this);
676 event.childID = childID; 681 event.childID = childID;
677 event.detail = -1; 682 event.detail = -1;
678 event.result = null; //TODO: could pass the OS value to the app 683 event.result = null; //TODO: could pass the OS value to the app
679 for (int i = 0; i < accessibleControlListeners.size(); i++) { 684 for (int i = 0; i < accessibleControlListeners.size(); i++) {
715 } 720 }
716 if (ace.childID >= ACC.CHILDID_SELF) { 721 if (ace.childID >= ACC.CHILDID_SELF) {
717 if (role is ACC.ROLE_TABITEM) { 722 if (role is ACC.ROLE_TABITEM) {
718 returnValue = NSNumber.numberWithBool(ace.childID is childID); 723 returnValue = NSNumber.numberWithBool(ace.childID is childID);
719 } else { 724 } else {
720 returnValue = new id(OS.NSAccessibilityUnignoredAncestor(childIDToOs(ace.childID).id)); 725 returnValue = new cocoa.id(OS.NSAccessibilityUnignoredAncestor(childIDToOs(ace.childID).id));
721 } 726 }
722 } else { 727 } else {
723 returnValue = NSNumber.numberWithBool(false); 728 returnValue = NSNumber.numberWithBool(false);
724 } 729 }
725 break; 730 break;
796 cocoa.id getParentAttribute (int childID) { 801 cocoa.id getParentAttribute (int childID) {
797 // Returning null here means 'let Cocoa figure it out.' 802 // Returning null here means 'let Cocoa figure it out.'
798 if (childID is ACC.CHILDID_SELF) 803 if (childID is ACC.CHILDID_SELF)
799 return null; 804 return null;
800 else 805 else
801 return new id(OS.NSAccessibilityUnignoredAncestor(control.view.id)); 806 return new cocoa.id(OS.NSAccessibilityUnignoredAncestor(control.view.id));
802 } 807 }
803 808
804 cocoa.id getChildrenAttribute (int childID) { 809 cocoa.id getChildrenAttribute (int childID) {
805 cocoa.id returnValue = null; 810 cocoa.id returnValue = null;
806 if (childID is ACC.CHILDID_SELF) { 811 if (childID is ACC.CHILDID_SELF) {
822 NSMutableArray childArray = NSMutableArray.arrayWithCapacity(appChildren.length); 827 NSMutableArray childArray = NSMutableArray.arrayWithCapacity(appChildren.length);
823 828
824 for (int i = 0; i < appChildren.length; i++) { 829 for (int i = 0; i < appChildren.length; i++) {
825 Object child = appChildren[i]; 830 Object child = appChildren[i];
826 if (cast(Integer) child) { 831 if (cast(Integer) child) {
827 id accChild = childIDToOs((cast(Integer)child).intValue()); 832 cocoa.id accChild = childIDToOs((cast(Integer)child).intValue());
828 childArray.addObject(accChild); 833 childArray.addObject(accChild);
829 } else { 834 } else {
830 childArray.addObject((cast(Accessible)child).control.view); 835 childArray.addObject((cast(Accessible)child).control.view);
831 } 836 }
832 } 837 }
916 for (int i = 0; i < accessibleControlListeners.size(); i++) { 921 for (int i = 0; i < accessibleControlListeners.size(); i++) {
917 AccessibleControlListener listener = accessibleControlListeners.elementAt(i); 922 AccessibleControlListener listener = accessibleControlListeners.elementAt(i);
918 listener.getLocation(event); 923 listener.getLocation(event);
919 } 924 }
920 925
921 Monitor primaryMonitor = Display.getCurrent().getPrimaryMonitor(); 926 dwt.widgets.Monitor.Monitor primaryMonitor = Display.getCurrent().getPrimaryMonitor();
922 927
923 NSPoint osPositionAttribute = NSPoint (); 928 NSPoint osPositionAttribute = NSPoint ();
924 if (event.width !is -1) { 929 if (event.width !is -1) {
925 // The point returned is the lower-left coordinate of the widget in lower-left relative screen coordinates. 930 // The point returned is the lower-left coordinate of the widget in lower-left relative screen coordinates.
926 osPositionAttribute.x = event.x; 931 osPositionAttribute.x = event.x;
1034 cocoa.id returnValue = null; 1039 cocoa.id returnValue = null;
1035 1040
1036 // The parameter is an NSNumber with the line number. 1041 // The parameter is an NSNumber with the line number.
1037 NSNumber lineNumberObj = new NSNumber(parameter.id); 1042 NSNumber lineNumberObj = new NSNumber(parameter.id);
1038 int lineNumber = lineNumberObj.intValue(); 1043 int lineNumber = lineNumberObj.intValue();
1039 System.Out.println("Line number = " ~ lineNumber); 1044 System.Out.println("Line number = " ~ Integer.toString(lineNumber));
1040 AccessibleControlEvent event = new AccessibleControlEvent(this); 1045 AccessibleControlEvent event = new AccessibleControlEvent(this);
1041 event.childID = childID; 1046 event.childID = childID;
1042 event.result = null; 1047 event.result = null;
1043 for (int i = 0; i < accessibleControlListeners.size(); i++) { 1048 for (int i = 0; i < accessibleControlListeners.size(); i++) {
1044 AccessibleControlListener listener = accessibleControlListeners.elementAt(i); 1049 AccessibleControlListener listener = accessibleControlListeners.elementAt(i);
1387 if (childID is ACC.CHILDID_SELF) { 1392 if (childID is ACC.CHILDID_SELF) {
1388 return control.view; 1393 return control.view;
1389 } 1394 }
1390 1395
1391 /* Check cache for childID, if found, return corresponding osChildID. */ 1396 /* Check cache for childID, if found, return corresponding osChildID. */
1392 SWTAccessibleDelegate childRef = children.get(childID); 1397 SWTAccessibleDelegate childRef = children[childID];
1393 1398
1394 if (childRef is null) { 1399 if (childRef is null) {
1395 childRef = new SWTAccessibleDelegate(this, childID); 1400 childRef = new SWTAccessibleDelegate(this, childID);
1396 children.put(childID, childRef); 1401 children.add(childID, childRef);
1397 } 1402 }
1398 1403
1399 return childRef; 1404 return childRef;
1400 } 1405 }
1401 1406
1494 if (control.isDisposed ()) DWT.error (DWT.ERROR_WIDGET_DISPOSED); 1499 if (control.isDisposed ()) DWT.error (DWT.ERROR_WIDGET_DISPOSED);
1495 } 1500 }
1496 1501
1497 /* isValidThread was copied from Widget, and rewritten to work in this package */ 1502 /* isValidThread was copied from Widget, and rewritten to work in this package */
1498 bool isValidThread () { 1503 bool isValidThread () {
1499 return control.getDisplay ().getThread () is Thread.currentThread (); 1504 return control.getDisplay ().getThread () is Thread.getThis ();
1500 } 1505 }
1501 1506
1502 } 1507 }