Revision: 4528
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4528&view=rev
Author:   hofman
Date:     2008-09-03 15:11:47 +0000 (Wed, 03 Sep 2008)

Log Message:
-----------
Handle remote control mostly from the main window controller. The app 
controller creates a custom event and sends it along the responder chain.

Modified Paths:
--------------
    trunk/SKApplication.h
    trunk/SKApplication.m
    trunk/SKApplicationController.m
    trunk/SKMainWindowController.m
    trunk/SKPDFDocument.m

Modified: trunk/SKApplication.h
===================================================================
--- trunk/SKApplication.h       2008-09-03 11:49:21 UTC (rev 4527)
+++ trunk/SKApplication.h       2008-09-03 15:11:47 UTC (rev 4528)
@@ -57,6 +57,11 @@
 @end
 
 
+enum {
+    SKRemoteButtonEvent = 1
+};
+
 @interface NSResponder (SKMagnifyWheel)
 - (void)magnifyWheel:(NSEvent *)theEvent;
+- (void)remoteButtonPressed:(NSEvent *)theEvent;
 @end

Modified: trunk/SKApplication.m
===================================================================
--- trunk/SKApplication.m       2008-09-03 11:49:21 UTC (rev 4527)
+++ trunk/SKApplication.m       2008-09-03 15:11:47 UTC (rev 4528)
@@ -71,6 +71,12 @@
             [target performSelector:@selector(magnifyWheel:) 
withObject:anEvent];
             return;
         }
+    } else if ([anEvent type] == NSApplicationDefined && [anEvent subtype] == 
SKRemoteButtonEvent) {
+        id target = [self targetForAction:@selector(remoteButtonPressed:)];
+        if (target) {
+            [target performSelector:@selector(remoteButtonPressed:) 
withObject:anEvent];
+            return;
+        }
     }
     [super sendEvent:anEvent];
 }

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2008-09-03 11:49:21 UTC (rev 4527)
+++ trunk/SKApplicationController.m     2008-09-03 15:11:47 UTC (rev 4528)
@@ -65,7 +65,6 @@
 #import "NSDocument_SKExtensions.h"
 #import "Files_SKExtensions.h"
 #import "NSTask_SKExtensions.h"
-#import "NSView_SKExtensions.h"
 #import "SKRuntime.h"
 #import <SkimNotes/SkimNotes.h>
 #import "PDFAnnotation_SKExtensions.h"
@@ -357,58 +356,27 @@
 }
 
 - (void)sendRemoteButtonEvent:(RemoteControlEventIdentifier)event 
pressedDown:(BOOL)pressedDown remoteControl:(RemoteControl *)remoteControl {
-    NSArray *docs = [NSApp orderedDocuments];
-    id document = [docs count] ? [docs objectAtIndex:0] : nil;
-    SKMainWindowController *controller = [document 
respondsToSelector:@selector(mainWindowController)]? [document 
mainWindowController] : nil;
-    
-    if (controller == nil || pressedDown == NO)
-        return;
-    
-    switch (event) {
-        case kRemoteButtonPlus:
-            if (remoteScrolling)
-                [[[controller pdfView] documentView] scrollLineUp];
-            else if ([controller isPresentation])
-                [controller doAutoScale:nil];
-            else
-                [controller doZoomIn:nil];
-            break;
-        case kRemoteButtonMinus:
-            if (remoteScrolling)
-                [[[controller pdfView] documentView] scrollLineDown];
-            else if ([controller isPresentation])
-                [controller doZoomToActualSize:nil];
-            else
-                [controller doZoomOut:nil];
-            break;
-        case kRemoteButtonRight_Hold:
-        case kRemoteButtonRight:
-            if (remoteScrolling)
-                [[[controller pdfView] documentView] scrollLineRight];
-            else 
-                [controller doGoToNextPage:nil];
-            break;
-        case kRemoteButtonLeft_Hold:
-        case kRemoteButtonLeft:
-            if (remoteScrolling)
-                [[[controller pdfView] documentView] scrollLineLeft];
-            else 
-                [controller doGoToPreviousPage:nil];
-            break;
-        case kRemoteButtonPlay:        
-            [controller togglePresentation:nil];
-            break;
-               case kRemoteButtonMenu:
+    if (pressedDown) {
+        if (event == kRemoteButtonMenu) {
             remoteScrolling = !remoteScrolling;
             if ([[NSUserDefaults standardUserDefaults] 
floatForKey:SKAppleRemoteSwitchIndicationTimeoutKey] > 0.0) {
-                NSRect rect = [[controller window] frame];
+                NSRect rect = [[NSScreen mainScreen] frame];
                 NSPoint point = NSMakePoint(NSMidX(rect), NSMidY(rect));
                 int type = remoteScrolling ? SKRemoteStateScroll : 
SKRemoteStateResize;
                 [SKRemoteStateWindow showWithType:type atPoint:point];
             }
-            break;
-        default:
-            break;
+        } else {
+            NSEvent *theEvent = [NSEvent 
otherEventWithType:NSApplicationDefined
+                                                   location:NSZeroPoint
+                                              modifierFlags:0
+                                                  
timestamp:GetCurrentEventTime()
+                                               windowNumber:0
+                                                    context:nil
+                                                    subtype:SKRemoteButtonEvent
+                                                      data1:event
+                                                      data2:remoteScrolling];
+            [NSApp sendEvent:theEvent];
+        }
     }
 }
 

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2008-09-03 11:49:21 UTC (rev 4527)
+++ trunk/SKMainWindowController.m      2008-09-03 15:11:47 UTC (rev 4528)
@@ -95,6 +95,8 @@
 #import "NSMenu_SKExtensions.h"
 #import "SKGroupedSearchResult.h"
 #import "SKUnarchiveFromDataArrayTransformer.h"
+#import "RemoteControl.h"
+#import "NSView_SKExtensions.h"
 
 #define MULTIPLICATION_SIGN_CHARACTER 0x00d7
 
@@ -3752,4 +3754,49 @@
     }
 }
 
+#pragma mark Remote Control
+
+- (void)remoteButtonPressed:(NSEvent *)theEvent {
+    RemoteControlEventIdentifier remoteButton = 
(RemoteControlEventIdentifier)[theEvent data1];
+    BOOL remoteScrolling = (BOOL)[theEvent data2];
+    
+    switch (remoteButton) {
+        case kRemoteButtonPlus:
+            if (remoteScrolling)
+                [[[self pdfView] documentView] scrollLineUp];
+            else if ([self isPresentation])
+                [self doAutoScale:nil];
+            else
+                [self doZoomIn:nil];
+            break;
+        case kRemoteButtonMinus:
+            if (remoteScrolling)
+                [[[self pdfView] documentView] scrollLineDown];
+            else if ([self isPresentation])
+                [self doZoomToActualSize:nil];
+            else
+                [self doZoomOut:nil];
+            break;
+        case kRemoteButtonRight_Hold:
+        case kRemoteButtonRight:
+            if (remoteScrolling)
+                [[[self pdfView] documentView] scrollLineRight];
+            else 
+                [self doGoToNextPage:nil];
+            break;
+        case kRemoteButtonLeft_Hold:
+        case kRemoteButtonLeft:
+            if (remoteScrolling)
+                [[[self pdfView] documentView] scrollLineLeft];
+            else 
+                [self doGoToPreviousPage:nil];
+            break;
+        case kRemoteButtonPlay:        
+            [self togglePresentation:nil];
+            break;
+        default:
+            break;
+    }
+}
+
 @end

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2008-09-03 11:49:21 UTC (rev 4527)
+++ trunk/SKPDFDocument.m       2008-09-03 15:11:47 UTC (rev 4528)
@@ -72,6 +72,7 @@
 #import "NSGeometry_SKExtensions.h"
 #import "SKSnapshotWindowController.h"
 #import "NSDocument_SKExtensions.h"
+#import "SKApplication.h"
 
 #define BUNDLE_DATA_FILENAME @"data"
 
@@ -1137,6 +1138,11 @@
     return [super validateUserInterfaceItem:anItem];
 }
 
+- (void)remoteButtonPressed:(NSEvent *)theEvent {
+    [[self mainWindowController] remoteButtonPressed:theEvent];
+}
+
+
 #pragma mark File update checking
 
 - (void)stopCheckingFileUpdates {


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