Logo Search packages:      
Sourcecode: xdaliclock version File versions


/* xdaliclock - a melting digital clock
 * Copyright (c) 1991-2007 Jamie Zawinski <jwz@jwz.org>
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation.  No representations are made about the suitability of this
 * software for any purpose.  It is provided "as is" without express or
 * implied warranty.

#import "DaliClockSaverView.h"

char *progname = "Dali Clock";   // digital.c wants this for error messages.

/* Note that this is a subclass of "ScreenSaverView", not of "DaliClockView".
   Note that this situation is exactly why multiple inheritance would be nice.

@implementation DaliClockSaverView

+ (void)initialize;
  static BOOL initialized_p = NO;
  if (initialized_p)
  initialized_p = YES;

  /* Figure out what the preferences module-name for this screen saver is,
     and create a preferences controller for it.
  NSBundle *nsb = [NSBundle bundleForClass:[self class]];
  NSAssert1 (nsb, @"no bundle for class %@", [self class]);
  NSString *name = [nsb bundleIdentifier];
  NSUserDefaults *defs = [ScreenSaverDefaults defaultsForModuleWithName:name];
  NSUserDefaultsController *controller =
    [[[NSUserDefaultsController alloc] initWithDefaults:defs
      retain];  // never freed

  /* Tell the DaliClockView class to initialize its preferences.
     This can't just happen in [DaliClockView:initialize], because
     we have to ensure that DaliClockView is using the same
     NSUserDefaultsController object that we are using here.
  [DaliClockView initializeDefaults:controller];

  /* Now that the DaliClockView class has initialized its preferences,
     set the defaults for those preferences handled by DaliClockSaverView
     rather than by DaliClockView.

     This stuff has to be done at class-initialization time so that
     it happens before the instances are deserialized from the nib file,
     or else the preferences don't end up hooked up properly to the
     preferences dialog in SaverPrefs.nib. I'm not entirely sure why.

     We only make one change here: we change the default background color
     to be slightly more opaque than the default value that DaliClockView
     had assigned.
  NSString *key = @"initialBackgroundColor";
  NSColor *defbg = [NSUnarchiver unarchiveObjectWithData:
                                   [[controller defaults] objectForKey:key]];
  defbg = [defbg colorWithAlphaComponent:0.95];
  NSDictionary* defaults = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSArchiver archivedDataWithRootObject:defbg], key,

  NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:100];
  [dict addEntriesFromDictionary: [controller initialValues]];
  [dict addEntriesFromDictionary:defaults];
  [controller setInitialValues:dict];
  [[controller defaults] registerDefaults:dict];

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
  self = [super initWithFrame:frame isPreview:isPreview];
  if (!self) return nil;

  NSRect r = frame;
  r.origin.x = r.origin.y = 0;
  clockView = [[[DaliClockView alloc] initWithFrame:r]

  // we may not overwrite the System Preferences window's background
  [clockView setOwnWindow: !isPreview];
  [clockView setConstrainSizes:YES];

  [self addSubview:clockView];

  return self;

- (void) startAnimation
  [[self window] setOpaque:NO];
  [super startAnimation];

  /* Display the date every minute-and-a-bit.  That way it doesn't show up
     on the same second each minute.  Also, only do this at all on the
     screen that contains the menubar.
  if ([self isPreview] ||
      [[self window] screen] == [[NSScreen screens] objectAtIndex:0])
    [clockView setAutoDate:67];

- (void)stopAnimation
  // Nothing to do here
  [super stopAnimation];

/*- (void) animateOneFrame
  // nothing to do here: DaliClockView has its own timers.

- (void)drawRect:(NSRect)rect
  // do nothing here: do not call super, because that fills with black.

/* Called when this View is resized.
- (void)setFrameSize:(NSSize)newSize
  [super setFrameSize:newSize];
  [clockView setFrameSize:newSize];

- (BOOL) hasConfigureSheet
  return YES;

- (NSWindow *) configureSheet
  if (!configSheet) {
    if (![NSBundle loadNibNamed:@"SaverPrefs" owner:self]) {
      NSAssert (0, @"unable to load prefs dialog");
  NSAssert (configSheet, @"loaded nib, but no prefs dialog");
  return configSheet;

// The Ok button in the preferences sheet
- (IBAction)okClick:(id)sender
  [[NSApplication sharedApplication] endSheet:configSheet];
  // [[[[clockView class] userDefaultsController] defaults] synchronize];

/* The About button in the preferences sheet.
- (IBAction)aboutClick:(id)sender
  [clockView aboutClick:sender];

/* When something tries to read or write preferences values in this object,
   just pass that along to the clockView, and also save it in the preferences.
- (id)valueForKey:(NSString *)key
  return [clockView valueForKey:key];

- (void)setValue:(id)value forKey:(NSString *)key
  [self willChangeValueForKey:key];

  [clockView setValue:value forKey:key];

  if ([value isKindOfClass:[NSColor class]])  // encode colors in prefs
    value = [NSArchiver archivedDataWithRootObject:value];

  NSUserDefaultsController *controller =
    [[clockView class] userDefaultsController];
  [[controller defaults] setValue:value forKey:key];

  [self didChangeValueForKey:key];


Generated by  Doxygen 1.6.0   Back to index