From http://www.jwz.org/xscreensaver/xscreensaver-5.19.tar.gz
[xscreensaver] / OSX / SaverRunner.m
index a5eb429db9597d33c2cb370d5035e271310e5d3c..526f62eb0dc4071b3a0a8e19c1282a154cf7f207 100644 (file)
    of bundles that have executable code in them.  Bleh.
  */
 
+#import <TargetConditionals.h>
 #import "SaverRunner.h"
 #import "SaverListController.h"
 #import "XScreenSaverGLView.h"
-#import <TargetConditionals.h>
+#import "yarandom.h"
 
 #ifdef USE_IPHONE
 
@@ -341,32 +342,20 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
 }
 
 
-- (void) openPreferences: (id) sender
+- (void) openPreferences: (NSString *) saver
 {
-  NSString *saver = [listController selected];
-  if (! saver) return;
-
   [self loadSaver:saver launch:NO];
   if (! saverView) return;
 
+  NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
+  [prefs setObject:saver forKey:@"selectedSaverName"];
+  [prefs synchronize];
+
   [rootViewController pushViewController: [saverView configureView]
                       animated:YES];
 }
 
 
-- (void) loadSaverMenu: (id) sender
-{
-  NSString *saver = [listController selected];
-  NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
-  if (saver) {
-    [prefs setObject:saver forKey:@"selectedSaverName"];
-  } else {
-    [prefs removeObjectForKey:@"selectedSaverName"];
-  }
-  [self saveScreenshot];
-  [self selectedSaverDidChange:nil];
-}
-
 #endif // USE_IPHONE
 
 
@@ -424,20 +413,33 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
 
 # else  // USE_IPHONE
 
+  NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
+  [prefs setObject:name forKey:@"selectedSaverName"];
+  [prefs synchronize];
+
   if (saverName && [saverName isEqualToString: name]) {
-    if (launch && ![saverView isAnimating]) {
-      [window addSubview: saverView];
-      [saverView startAnimation];
-    }
-    return;
+    if ([saverView isAnimating])
+      return;
+    else
+      goto LAUNCH;
   }
 
   saverName = name;
 
+  if (! backgroundView) {
+    // This view is the parent of the XScreenSaverView, and exists only
+    // so that there is a black background behind it.  Without this, when
+    // rotation is in progresss, the scrolling-list window's corners show
+    // through in the corners.
+    backgroundView = [[[NSView class] alloc] initWithFrame:[window frame]];
+    [backgroundView setBackgroundColor:[NSColor blackColor]];
+  }
+
   if (saverView) {
     if ([saverView isAnimating])
       [saverView stopAnimation];
     [saverView removeFromSuperview];
+    [backgroundView removeFromSuperview];
   }
 
   NSSize size = [window frame].size;
@@ -460,8 +462,12 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
     selector:@selector(didRotate:)
     name:UIDeviceOrientationDidChangeNotification object:nil];
 
+ LAUNCH:
   if (launch) {
-    [window addSubview: saverView];
+    [self saveScreenshot];
+    [window addSubview: backgroundView];
+    [backgroundView addSubview: saverView];
+    [saverView becomeFirstResponder];
     [saverView startAnimation];
   }
 # endif // USE_IPHONE
@@ -474,9 +480,10 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
 }
 
 
+# ifndef USE_IPHONE
+
 - (void)aboutPanel:(id)sender
 {
-# ifndef USE_IPHONE
   NSDictionary *bd = [saverBundle infoDictionary];
   NSMutableDictionary *d = [NSMutableDictionary dictionaryWithCapacity:20];
 
@@ -492,28 +499,9 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
 
   [[NSApplication sharedApplication]
     orderFrontStandardAboutPanelWithOptions:d];
-
-# else  // USE_IPHONE
-
-  NSDictionary *bd = [[NSBundle mainBundle] infoDictionary];
-  NSString *body = [bd objectForKey:@"CFBundleGetInfoString"];
-
-  body = [body stringByReplacingOccurrencesOfString:@", " withString:@",\n"];
-  body = [body stringByAppendingString:
-               @"\n\n"
-               "Double-tap to run.\n\n"
-               "Double-tap again to\n"
-               "return to this list."];
-
-  [[[UIAlertView alloc] initWithTitle: @""
-                        message: body
-                        delegate: nil
-                        cancelButtonTitle: @"OK"
-                        otherButtonTitles: nil]
-    show];
+}
 
 # endif // USE_IPHONE
-}
 
 
 
@@ -746,41 +734,6 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
 }
 
 
-- (UIViewController *) makeMenu
-{
-  listController = [[[SaverListController alloc] 
-                      initWithNames:saverNames
-                      descriptions:[self makeDescTable]]
-                     retain];
-  UIBarButtonItem *run  = [[[UIBarButtonItem alloc]
-                             initWithTitle:@"Run"
-                             style: UIBarButtonItemStylePlain
-                             target: self
-                             action: @selector(loadSaverMenu:)]
-                            autorelease];
-  UIBarButtonItem *about = [[[UIBarButtonItem alloc]
-                             initWithTitle: @"About"
-                             style: UIBarButtonItemStylePlain
-                             target: self
-                             action: @selector(aboutPanel:)]
-                            autorelease];
-  UIBarButtonItem *pref = [[[UIBarButtonItem alloc]
-                             initWithTitle:@"Settings"
-                             style: UIBarButtonItemStylePlain
-                             target: self
-                             action: @selector(openPreferences:)]
-                            autorelease];
-  NSArray *a = [NSArray arrayWithObjects: pref, about, nil];
-
-  [run   setEnabled:NO];
-  [about setEnabled:YES];
-  [pref  setEnabled:NO];
-  listController.navigationItem.leftBarButtonItem  = run;
-  listController.navigationItem.rightBarButtonItems = a;
-
-  return listController;
-}
-
 #endif // USE_IPHONE
 
 
@@ -954,8 +907,12 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
 
   rootViewController = [[[RotateyViewController alloc] init] retain];
   [window setRootViewController: rootViewController];
-  [rootViewController pushViewController:[self makeMenu]
-                      animated:YES];
+
+  SaverListController *menu = [[SaverListController alloc] 
+                                initWithNames:saverNames
+                                descriptions:[self makeDescTable]];
+  [rootViewController pushViewController:menu animated:YES];
+  [menu becomeFirstResponder];
 
   [window makeKeyAndVisible];
   [window setAutoresizesSubviews:YES];
@@ -963,8 +920,7 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
             (UIViewAutoresizingFlexibleWidth | 
              UIViewAutoresizingFlexibleHeight)];
 
-  // Has to be after the list window is up, or we get black.
-  [self saveScreenshot];
+  application.applicationSupportsShakeToEdit = YES;
 
 # endif // USE_IPHONE
 
@@ -993,6 +949,7 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
 
 # ifdef USE_IPHONE
   NSString *prev = [prefs stringForKey:@"selectedSaverName"];
+
   if (forced)
     prev = forced;
 
@@ -1003,7 +960,7 @@ relabel_menus (NSObject *v, NSString *old_str, NSString *new_str)
     prev = [saverNames objectAtIndex: (random() % [saverNames count])];
 
   if (prev)
-    [listController scrollTo: prev];
+    [menu scrollTo: prev];
 # endif // USE_IPHONE
 
   if (forced)