Revision: 3847
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3847&view=rev
Author:   hofman
Date:     2008-05-05 02:41:24 -0700 (Mon, 05 May 2008)

Log Message:
-----------
Implement AXAttributedStringForRange and AXStyleRangeForIndex parametrized 
attributes.

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

Modified: trunk/PDFDisplayView_SKExtensions.m
===================================================================
--- trunk/PDFDisplayView_SKExtensions.m 2008-05-05 00:35:46 UTC (rev 3846)
+++ trunk/PDFDisplayView_SKExtensions.m 2008-05-05 09:41:24 UTC (rev 3847)
@@ -50,9 +50,16 @@
 - (void)generateAccessibilityTable;
 @end
 
+
 @interface PDFDisplayView (SKExtensions)
 @end
 
+
[EMAIL PROTECTED] NSAttributedString (SKExtensions)
+- (NSAttributedString *)accessibilityAttributedString;
[EMAIL PROTECTED]
+
+
 @implementation PDFDisplayView (SKExtensions)
 
 static IMP originalResetCursorRects = NULL;
@@ -101,7 +108,7 @@
 - (NSArray *)replacementAccessibilityParameterizedAttributeNames {
     static NSArray *attributes = nil;
     if (attributes == nil)
-        attributes = [[originalAccessibilityParameterizedAttributeNames(self, 
_cmd) arrayByAddingObjectsFromArray:[NSArray 
arrayWithObjects:NSAccessibilityRangeForPositionParameterizedAttribute, 
NSAccessibilityRTFForRangeParameterizedAttribute, nil]] retain];
+        attributes = [[originalAccessibilityParameterizedAttributeNames(self, 
_cmd) arrayByAddingObjectsFromArray:[NSArray 
arrayWithObjects:NSAccessibilityRangeForPositionParameterizedAttribute, 
NSAccessibilityRTFForRangeParameterizedAttribute, 
NSAccessibilityAttributedStringForRangeParameterizedAttribute, nil]] retain];
     return attributes;
 }
 
@@ -150,6 +157,52 @@
     return nil;
 }
 
+- 
(id)replacementAccessibilityAttributedStringForRangeAttributeForParameter:(id)parameter
 {
+    id pdfView = [self skPdfView];
+    if (pdfView && [self 
respondsToSelector:@selector(selectionForAccessibilityRange:)]) {
+        @try {
+            if ([[self valueForKey:@"numAccessibilityLines"] unsignedIntValue] 
== 0 && [self respondsToSelector:@selector(generateAccessibilityTable)])
+                [self generateAccessibilityTable];
+        }
+        @catch (id exception) {}
+        NSAttributedString *attributedString = [[self 
selectionForAccessibilityRange:[parameter rangeValue]] attributedString];
+        return [attributedString accessibilityAttributedString];
+    }
+    return nil;
+}
+
+- 
(id)replacementAccessibilityStyleRangeForIndexAttributeForParameter:(id)parameter
 {
+    id pdfView = [self skPdfView];
+    if (pdfView && [self 
respondsToSelector:@selector(selectionForAccessibilityRange:)]) {
+        @try {
+            if ([[self valueForKey:@"numAccessibilityLines"] unsignedIntValue] 
== 0 && [self respondsToSelector:@selector(generateAccessibilityTable)])
+                [self generateAccessibilityTable];
+        }
+        @catch (id exception) {}
+        int i = [parameter unsignedIntValue];
+        int n = [[self 
accessibilityAttributeValue:NSAccessibilityNumberOfCharactersAttribute] 
intValue];
+        int start = MAX(0, i - 25), end = MIN(n, i + 25);
+        NSRange range = NSMakeRange(i, 1);
+        NSRange r = NSMakeRange(start, end - start);
+        BOOL foundRange = NO;
+        while (foundRange == NO) {
+            [[[self selectionForAccessibilityRange:r] attributedString] 
attributesAtIndex:i - r.location longestEffectiveRange:&range 
inRange:NSMakeRange(0, r.length)];
+            foundRange = YES;
+            if (range.location == r.location && r.location > 0) {
+                start = MAX(0, (int)r.location - 25);
+                foundRange = NO;
+            }
+            if (NSMaxRange(range) == NSMaxRange(r) && (int)NSMaxRange(range) < 
n) {
+                end = MIN(n, (int)NSMaxRange(r) + 25);
+                foundRange = NO;
+            }
+            r = NSMakeRange(start, end - start);
+        }
+        return [NSValue valueWithRange:range];
+    }
+    return nil;
+}
+
 - (id)replacementAccessibilityHitTest:(NSPoint)point {
     id pdfView = [self skPdfView];
     id element = nil;
@@ -217,6 +270,23 @@
         OBAddMethodImplementationWithSelector(self, 
@selector(accessibilityRangeForPositionAttributeForParameter:), 
@selector(replacementAccessibilityRangeForPositionAttributeForParameter:));
     if ([self 
instancesRespondToSelector:@selector(accessibilityRTFForRangeAttributeForParameter:)]
 == NO)
         OBAddMethodImplementationWithSelector(self, 
@selector(accessibilityRTFForRangeAttributeForParameter:), 
@selector(replacementAccessibilityRTFForRangeAttributeForParameter:));
+    if ([self 
instancesRespondToSelector:@selector(accessibilityAttributedStringForRangeAttributeForParameter:)]
 == NO)
+        OBAddMethodImplementationWithSelector(self, 
@selector(accessibilityAttributedStringForRangeAttributeForParameter:), 
@selector(replacementAccessibilityAttributedStringForRangeAttributeForParameter:));
+    if ([self 
instancesRespondToSelector:@selector(accessibilityStyleRangeForIndexAttributeForParameter:)]
 == NO)
+        OBAddMethodImplementationWithSelector(self, 
@selector(accessibilityStyleRangeForIndexAttributeForParameter:), 
@selector(replacementAccessibilityStyleRangeForIndexAttributeForParameter:));
 }
 
 @end
+
+
[EMAIL PROTECTED] NSAttributedString (SKExtensions)
+
+- (NSAttributedString *)accessibilityAttributedString {
+    NSTextFieldCell *cell = nil;
+    if (cell == nil)
+        cell = [[NSTextFieldCell alloc] init];
+    [cell setAttributedStringValue:self];
+    return [cell 
accessibilityAttributeValue:NSAccessibilityAttributedStringForRangeParameterizedAttribute
 forParameter:[NSValue valueWithRange:NSMakeRange(0, [self length])]];
+}
+
[EMAIL PROTECTED]


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