Revision: 4285
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4285&view=rev
Author:   hofman
Date:     2008-07-23 17:35:36 +0000 (Wed, 23 Jul 2008)

Log Message:
-----------
Move some repeating code into static inline functions

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

Modified: trunk/PDFDisplayView_SKExtensions.m
===================================================================
--- trunk/PDFDisplayView_SKExtensions.m 2008-07-23 17:17:28 UTC (rev 4284)
+++ trunk/PDFDisplayView_SKExtensions.m 2008-07-23 17:35:36 UTC (rev 4285)
@@ -123,6 +123,25 @@
     }
 }
 
+static inline void generateAccessibilityTableIfNeeded(id pdfDisplayView) {
+    @try {
+        if ([[pdfDisplayView valueForKey:@"numAccessibilityLines"] 
unsignedIntValue] == 0 &&
+            [pdfDisplayView 
respondsToSelector:@selector(generateAccessibilityTable)])
+            [pdfDisplayView generateAccessibilityTable];
+    }
+    @catch (id exception) {}
+}
+
+static inline NSAttributedString *attributedStringForAccessibilityRange(id 
pdfDisplayView, NSRange range) {
+    NSAttributedString *attributedString = nil;
+    if ([pdfDisplayView 
respondsToSelector:@selector(selectionForAccessibilityRange:)]) {
+        PDFSelection *selection = [pdfDisplayView 
selectionForAccessibilityRange:range];
+        if ([selection respondsToSelector:@selector(attributedString)])
+            attributedString = [selection attributedString];
+    }
+    return attributedString;
+}
+
 static id replacementAccessibilityRangeForPositionAttributeForParameter(id 
self, SEL _cmd, id parameter) {
     id pdfView = SKGetPDFView(self);
     if (pdfView && [self 
respondsToSelector:@selector(accessibilityRangeForSelection:)]) {
@@ -131,11 +150,7 @@
         if (page) {
             int i = [page characterIndexAtPoint:[pdfView convertPoint:point 
toPage:page]];
             if (i != -1) {
-                @try {
-                    if ([[self valueForKey:@"numAccessibilityLines"] 
unsignedIntValue] == 0 && [self 
respondsToSelector:@selector(generateAccessibilityTable)])
-                        [self generateAccessibilityTable];
-                }
-                @catch (id exception) {}
+                generateAccessibilityTableIfNeeded(self);
                 return [NSValue valueWithRange:[self 
accessibilityRangeForSelection:[page selectionForRange:NSMakeRange(i, 1)]]];
             }
         }
@@ -145,13 +160,9 @@
 
 static id replacementAccessibilityRTFForRangeAttributeForParameter(id self, 
SEL _cmd, id parameter) {
     id pdfView = SKGetPDFView(self);
-    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];
+    if (pdfView) {
+        generateAccessibilityTableIfNeeded(self);
+        NSAttributedString *attributedString = 
attributedStringForAccessibilityRange(self, [parameter rangeValue]);
         return [attributedString RTFFromRange:NSMakeRange(0, [attributedString 
length]) documentAttributes:NULL];
     }
     return nil;
@@ -159,26 +170,17 @@
 
 static id 
replacementAccessibilityAttributedStringForRangeAttributeForParameter(id self, 
SEL _cmd, id parameter) {
     id pdfView = SKGetPDFView(self);
-    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];
+    if (pdfView) {
+        generateAccessibilityTableIfNeeded(self);
+        return [attributedStringForAccessibilityRange(self, [parameter 
rangeValue]) accessibilityAttributedString];
     }
     return nil;
 }
 
 static id replacementAccessibilityStyleRangeForIndexAttributeForParameter(id 
self, SEL _cmd, id parameter) {
     id pdfView = SKGetPDFView(self);
-    if (pdfView && [self 
respondsToSelector:@selector(selectionForAccessibilityRange:)]) {
-        @try {
-            if ([[self valueForKey:@"numAccessibilityLines"] unsignedIntValue] 
== 0 && [self respondsToSelector:@selector(generateAccessibilityTable)])
-                [self generateAccessibilityTable];
-        }
-        @catch (id exception) {}
+    if (pdfView) {
+        generateAccessibilityTableIfNeeded(self);
         int i = [parameter unsignedIntValue];
         int n = [[self 
accessibilityAttributeValue:NSAccessibilityNumberOfCharactersAttribute] 
intValue];
         int start = MAX(0, i - 25), end = MIN(n, i + 25);
@@ -186,7 +188,7 @@
         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)];
+            [attributedStringForAccessibilityRange(self, r) 
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);


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 Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to