Mercurial > projects > dwt-mac
diff dwt/widgets/Sash.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | e831403a80a9 |
children | cfa563df4fdd |
line wrap: on
line diff
--- a/dwt/widgets/Sash.d Tue Oct 21 15:20:04 2008 +0200 +++ b/dwt/widgets/Sash.d Mon Dec 01 17:07:00 2008 +0100 @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,16 +14,24 @@ import dwt.DWT; import dwt.DWTException; +import dwt.accessibility.ACC; import dwt.events.SelectionEvent; import dwt.events.SelectionListener; import dwt.graphics.Cursor; import dwt.graphics.Point; import dwt.graphics.Rectangle; +import dwt.internal.cocoa.NSArray; import dwt.internal.cocoa.NSEvent; +import dwt.internal.cocoa.NSGraphicsContext; +import dwt.internal.cocoa.NSMutableArray; +import dwt.internal.cocoa.NSNumber; import dwt.internal.cocoa.NSPoint; import dwt.internal.cocoa.NSRect; +import dwt.internal.cocoa.NSString; +import dwt.internal.cocoa.NSView; import dwt.internal.cocoa.OS; import dwt.internal.cocoa.SWTView; +import dwt.internal.cocoa.id; /** * Instances of the receiver represent a selectable user interface object @@ -41,6 +49,10 @@ * IMPORTANT: This class is intended to be subclassed <em>only</em> * within the DWT implementation. * </p> + * + * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class Sash : Control { Cursor sizeCursor; @@ -48,7 +60,8 @@ int lastX, lastY, startX, startY; private final static int INCREMENT = 1; private final static int PAGE_INCREMENT = 9; - + NSArray accessibilityAttributes = null; + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -84,6 +97,127 @@ sizeCursor = new Cursor (display, cursorStyle); } +int accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) { + if (accessibilityAttributes is null) { + NSMutableArray ourAttributes = NSMutableArray.arrayWithCapacity(10); + ourAttributes.addObject(OS.NSAccessibilityRoleAttribute); + ourAttributes.addObject(OS.NSAccessibilityRoleDescriptionAttribute); + ourAttributes.addObject(OS.NSAccessibilityParentAttribute); + ourAttributes.addObject(OS.NSAccessibilityPositionAttribute); + ourAttributes.addObject(OS.NSAccessibilitySizeAttribute); + ourAttributes.addObject(OS.NSAccessibilityWindowAttribute); + ourAttributes.addObject(OS.NSAccessibilityTopLevelUIElementAttribute); + ourAttributes.addObject(OS.NSAccessibilityFocusedAttribute); + ourAttributes.addObject(OS.NSAccessibilityValueAttribute); + ourAttributes.addObject(OS.NSAccessibilityMaxValueAttribute); + ourAttributes.addObject(OS.NSAccessibilityMinValueAttribute); + // The accessibility documentation says that these next two are optional, but the + // Accessibility Verifier says they are required. + ourAttributes.addObject(OS.NSAccessibilityNextContentsAttribute); + ourAttributes.addObject(OS.NSAccessibilityPreviousContentsAttribute); + ourAttributes.addObject(OS.NSAccessibilityOrientationAttribute); + + if (accessible !is null) { + // See if the accessible will override or augment the standard list. + // Help, title, and description can be overridden. + NSMutableArray extraAttributes = NSMutableArray.arrayWithCapacity(3); + extraAttributes.addObject(OS.NSAccessibilityHelpAttribute); + extraAttributes.addObject(OS.NSAccessibilityDescriptionAttribute); + extraAttributes.addObject(OS.NSAccessibilityTitleAttribute); + + for (int i = extraAttributes.count() - 1; i >= 0; i--) { + NSString attribute = new NSString(extraAttributes.objectAtIndex(i).id); + if (accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF) !is null) { + ourAttributes.addObject(extraAttributes.objectAtIndex(i)); + } + } + } + + accessibilityAttributes = ourAttributes; + accessibilityAttributes.retain(); + } + + return accessibilityAttributes.id; +} + +public int accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { + int returnValue = 0; + NSString attributeName = new NSString(arg0); + + if (accessible !is null) { + id returnObject = accessible.internal_accessibilityAttributeValue(attributeName, ACC.CHILDID_SELF); + + if (returnObject !is null) returnValue = returnObject.id; + } + + if (returnValue !is 0) return returnValue; + + if (attributeName.isEqualToString (OS.NSAccessibilityRoleAttribute) || attributeName.isEqualToString (OS.NSAccessibilityRoleDescriptionAttribute)) { + NSString roleText = OS.NSAccessibilitySplitterRole; + + if (attributeName.isEqualToString (OS.NSAccessibilityRoleAttribute)) { + return roleText.id; + } else { // NSAccessibilityRoleDescriptionAttribute + return OS.NSAccessibilityRoleDescription (roleText.id, 0); + } + } else if (attributeName.isEqualToString (OS.NSAccessibilityEnabledAttribute)) { + return NSNumber.numberWithBool(isEnabled()).id; + } else if (attributeName.isEqualToString (OS.NSAccessibilityOrientationAttribute)) { + NSString orientation = (style & DWT.VERTICAL) !is 0 ? OS.NSAccessibilityVerticalOrientationValue : OS.NSAccessibilityHorizontalOrientationValue; + return orientation.id; + } else if (attributeName.isEqualToString (OS.NSAccessibilityValueAttribute)) { + Point location = getLocation(); + int value = (style & DWT.VERTICAL) !is 0 ? location.x : location.y; + return NSNumber.numberWithInt(value).id; + } else if (attributeName.isEqualToString (OS.NSAccessibilityMaxValueAttribute)) { + NSRect parentBounds = view.bounds(); + float maxValue = (style & DWT.VERTICAL) !is 0 ? + parentBounds.width : + parentBounds.height; + return NSNumber.numberWithInt((int)maxValue).id; + } else if (attributeName.isEqualToString (OS.NSAccessibilityMinValueAttribute)) { + return NSNumber.numberWithInt(0).id; + } else if (attributeName.isEqualToString (OS.NSAccessibilityNextContentsAttribute)) { + Control[] children = parent._getChildren(); + Control nextView = null; + for (int i = 0; i < children.length; i++) { + if (children[i] is this) { + if (i < children.length - 1) { + nextView = children[i + 1]; + break; + } + } + } + + if (nextView !is null) + return NSArray.arrayWithObject(nextView.view).id; + else + return NSArray.array().id; + } else if (attributeName.isEqualToString (OS.NSAccessibilityPreviousContentsAttribute)) { + Control[] children = parent._getChildren(); + Control nextView = null; + for (int i = 0; i < children.length; i++) { + if (children[i] is this) { + if (i > 0) { + nextView = children[i - 1]; + break; + } + } + } + + if (nextView !is null) + return NSArray.arrayWithObject(nextView.view).id; + else + return NSArray.array().id; + } + + return super.accessibilityAttributeValue(id, sel, arg0); +} + +bool accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) { + return false; +} + /** * Adds the listener to the collection of listeners who will * be notified when the control is selected by the user, by sending @@ -125,8 +259,8 @@ return checkBits (style, DWT.HORIZONTAL, DWT.VERTICAL, 0, 0, 0, 0); } -bool becomeFirstResponder () { - bool result = super.becomeFirstResponder(); +bool becomeFirstResponder (int /*long*/ id, int /*long*/ sel) { + bool result = super.becomeFirstResponder(id, sel); NSRect frame = view.frame(); lastX = cast(int)frame.x; lastY = cast(int)frame.y; @@ -147,11 +281,24 @@ } void createHandle () { - SWTView widget = cast(SWTView)new SWTView().alloc(); + NSView widget = cast(NSView)new SWTView().alloc(); widget.initWithFrame (new NSRect()); - widget.setTag(jniRef); view = widget; - parent.contentView().addSubview_(view); +} + +void drawWidget (int /*long*/ id, NSRect rect) { + NSGraphicsContext context = NSGraphicsContext.currentContext(); + fillBackground (view, context, rect); + super.drawWidget (id, rect); +} + +Cursor findCursor () { + Cursor cursor = super.findCursor (); + if (cursor is null) { + int cursorType = (style & DWT.HORIZONTAL) !is 0 ? DWT.CURSOR_SIZENS : DWT.CURSOR_SIZEWE; + cursor = display.getSystemCursor (cursorType); + } + return cursor; } bool sendKeyEvent(NSEvent nsEvent, int type) { @@ -164,7 +311,7 @@ case 124: /* Right arrow */ { int xChange = 0, yChange = 0; int stepSize = PAGE_INCREMENT; - int modifiers = nsEvent.modifierFlags(); + int /*long*/ modifiers = nsEvent.modifierFlags(); if ((modifiers & OS.NSControlKeyMask) !is 0) stepSize = INCREMENT; if ((style & DWT.VERTICAL) !is 0) { if (keyCode is 126 || keyCode is 125) break; @@ -213,8 +360,9 @@ return true; } -void mouseDown(int theEvent) { - super.mouseDown(theEvent); +void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { + //TODO use sendMouseEvent +// super.mouseDown(id, sel, theEvent); NSEvent nsEvent = new NSEvent(theEvent); if (nsEvent.clickCount() !is 1) return; NSPoint location = nsEvent.locationInWindow(); @@ -237,8 +385,9 @@ } } -void mouseDragged(int theEvent) { - super.mouseDragged(theEvent); +void mouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { + //TODO use sendMouseEvent +// super.mouseDragged(id, sel, theEvent); if (!dragging) return; NSEvent nsEvent = new NSEvent(theEvent); NSPoint location = nsEvent.locationInWindow(); @@ -266,14 +415,9 @@ } } -void mouseEntered(int theEvent) { - //TODO need to add tracking area - super.mouseEntered(theEvent); - sizeCursor.handle.set(); -} - -void mouseUp(int theEvent) { - super.mouseUp(theEvent); +void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { + //TODO use sendMouseEvent +// super.mouseUp(id, sel, theEvent); if (!dragging) return; dragging = false; NSRect frame = view.frame(); @@ -289,6 +433,12 @@ } } +void releaseHandle () { + super.releaseHandle (); + if (accessibilityAttributes !is null) accessibilityAttributes.release(); + accessibilityAttributes = null; +} + void releaseWidget () { super.releaseWidget (); if (sizeCursor !is null) sizeCursor.dispose ();