Revision: 3755
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3755&view=rev
Author:   hofman
Date:     2008-04-18 05:29:44 -0700 (Fri, 18 Apr 2008)

Log Message:
-----------
Notify focus changes for accessibility. Implement press actions for color 
elements. Rename element class.

Modified Paths:
--------------
    trunk/SKColorSwatch.m

Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m       2008-04-18 11:18:48 UTC (rev 3754)
+++ trunk/SKColorSwatch.m       2008-04-18 12:29:44 UTC (rev 3755)
@@ -50,7 +50,7 @@
 static NSString *SKColorSwatchColorsObservationContext = 
@"SKColorSwatchColorsObservationContext";
 
 
[EMAIL PROTECTED] SKAccessibilityColorWellElement : NSObject {
[EMAIL PROTECTED] SKAccessibilityColorSwatchElement : NSObject {
     int index;
     SKColorSwatch *colorSwatch;
 }
@@ -284,12 +284,14 @@
     if (++focusedIndex >= (int)[colors count])
         focusedIndex = [colors count] - 1;
     [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
+    NSAccessibilityPostNotification(self, 
NSAccessibilityFocusedUIElementChangedNotification);
 }
 
 - (void)moveLeft:(NSEvent *)theEvent {
     if (--focusedIndex < 0)
         focusedIndex = 0;
     [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
+    NSAccessibilityPostNotification(self, 
NSAccessibilityFocusedUIElementChangedNotification);
 }
 
 - (int)colorIndexAtPoint:(NSPoint)point {
@@ -565,7 +567,7 @@
         NSMutableArray *children = [NSMutableArray array];
         int i, count = [colors count];
         for (i = 0; i < count; i++)
-            [children addObject:[[[SKAccessibilityColorWellElement alloc] 
initWithIndex:i colorSwatch:self] autorelease]];
+            [children addObject:[[[SKAccessibilityColorSwatchElement alloc] 
initWithIndex:i colorSwatch:self] autorelease]];
         return NSAccessibilityUnignoredChildren(children);
     } else if ([attribute isEqualToString:NSAccessibilityParentAttribute]) {
         id parent = [self superview];
@@ -602,7 +604,7 @@
     NSPoint localPoint = [self convertPoint:[[self window] 
convertScreenToBase:point] fromView:nil];
     int i = [self colorIndexAtPoint:localPoint];
     if (i != -1) {
-        SKAccessibilityColorWellElement *color = 
[[[SKAccessibilityColorWellElement alloc] initWithIndex:i colorSwatch:self] 
autorelease];
+        SKAccessibilityColorSwatchElement *color = 
[[[SKAccessibilityColorSwatchElement alloc] initWithIndex:i colorSwatch:self] 
autorelease];
         return [color accessibilityHitTest:point];
     } else {
         return [super accessibilityHitTest:point];
@@ -611,20 +613,33 @@
 
 - (id)accessibilityFocusedUIElement {
     if (focusedIndex != -1 && focusedIndex < (int)[colors count])
-        return 
NSAccessibilityUnignoredAncestor([[[SKAccessibilityColorWellElement alloc] 
initWithIndex:focusedIndex colorSwatch:self] autorelease]);
+        return 
NSAccessibilityUnignoredAncestor([[[SKAccessibilityColorSwatchElement alloc] 
initWithIndex:focusedIndex colorSwatch:self] autorelease]);
     else
         return NSAccessibilityUnignoredAncestor(self);
 }
 
-- (BOOL)isElementFocused:(SKAccessibilityColorWellElement *)element {
+- (BOOL)isElementFocused:(SKAccessibilityColorSwatchElement *)element {
     return focusedIndex == [element index];
 }
 
+- (void)clickElement:(SKAccessibilityColorSwatchElement *)element {
+    int i = [element index];
+    if ([self isEnabled] && i != -1) {
+        clickedIndex = i;
+        [self sendAction:[self action] to:[self target]];
+        clickedIndex = -1;
+        highlightedIndex = focusedIndex;
+        [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
+        [self setNeedsDisplay:YES];
+        [self performSelector:@selector(unhighlight) withObject:nil 
afterDelay:0.2];
+    }
+}
+
 @end
 
 #pragma mark -
 
[EMAIL PROTECTED] SKAccessibilityColorWellElement
[EMAIL PROTECTED] SKAccessibilityColorSwatchElement
 
 - (id)initWithIndex:(int)anIndex colorSwatch:(SKColorSwatch *)aColorSwatch {
     if (self = [super init]) {
@@ -635,8 +650,8 @@
 }
 
 - (BOOL)isEqual:(id)object {
-    if ([object isKindOfClass:[SKAccessibilityColorWellElement class]]) {
-        SKAccessibilityColorWellElement *other = object;
+    if ([object isKindOfClass:[SKAccessibilityColorSwatchElement class]]) {
+        SKAccessibilityColorSwatchElement *other = object;
         return index == [other index] && [colorSwatch isEqual:[other 
colorSwatch]];
     } else {
         return NO;
@@ -727,4 +742,17 @@
     return NSAccessibilityUnignoredAncestor(self);
 }
 
+- (NSArray *)accessibilityActionNames {
+    return [NSArray arrayWithObject:NSAccessibilityPressAction];
+}
+
+- (NSString *)accessibilityActionDescription:(NSString *)anAction {
+    return NSAccessibilityActionDescription(anAction);
+}
+
+- (void)accessibilityPerformAction:(NSString *)anAction {
+    if ([anAction isEqualToString:NSAccessibilityPressAction])
+        [colorSwatch clickElement:self];
+}
+
 @end


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to