home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Examples / NEXTIME / SimplePlayer / Document.m < prev    next >
Encoding:
Text File  |  1995-08-30  |  2.1 KB  |  89 lines

  1.  
  2. #import "Document.h"
  3. #import <AppKit/NSApplication.h>
  4.  
  5. @implementation Document
  6.  
  7. - initByReferencingFile:(NSString *)file
  8. {
  9.     NSRect content = {{0., 0.}, {320., 240.}};
  10.         NSRect frame;
  11.     
  12.     self = [super init];
  13.     if ( self == nil )
  14.         return nil;
  15.         
  16.     // Create a window and DocumentView, set the window's contentView
  17.     // to be our document view, set the title and delegate.
  18.     docView = [[DocumentView alloc] initWithFrame:content];
  19.     if ( [docView setMovieFile:file] == NO )
  20.     {
  21.         [docView release];
  22.         [self dealloc];
  23.         return nil;
  24.     }
  25.     myWindow = [[NSWindow alloc] initWithContentRect:[docView frame]
  26.             styleMask: NSResizableWindowMask
  27.                 | NSClosableWindowMask
  28.                 | NSMiniaturizableWindowMask
  29.             backing:NSBackingStoreBuffered
  30.             defer:    YES];
  31.             
  32.     [myWindow setContentView:docView];
  33.  
  34.         // Window is now set up to display a movie frame at 'normal' size.
  35.         // Set this to also be the minimum size, so the user doesn't get
  36.         // exposed to weird clipping effects if the window is resized too
  37.         // small, and to provide an obvious way to restore a movie back to
  38.         // 'normal' size and scale.
  39.         frame = [myWindow frame];
  40.         [myWindow setMinSize:frame.size];
  41.  
  42.         // Allow our content view to be fully resizable
  43.     [docView setAutoresizingMask:
  44.             (NSViewWidthSizable | NSViewHeightSizable)];
  45.  
  46.         // We will act as the delegate for the document
  47.     [myWindow setDelegate:self];
  48.  
  49.         // Title based on the file name
  50.     [myWindow setTitleWithRepresentedFilename:file];
  51.     return self;
  52. }
  53.  
  54. - (void) dealloc
  55. {
  56.     [docView release];
  57.     [super dealloc];
  58. }
  59.  
  60. - (void)show
  61. {
  62.     NSPoint position;
  63.     NSWindow *mainWin;
  64.     
  65.     // Cascade from current window, if any.
  66.     mainWin = [[NSApplication sharedApplication] mainWindow];
  67.     if ( mainWin == nil )
  68.     {
  69.         position.x = position.y = 80.0;
  70.     }
  71.     else
  72.     {
  73.         position.x = position.y = 0.0;
  74.         position = [mainWin cascadeTopLeftFromPoint:position];
  75.     }
  76.     [myWindow cascadeTopLeftFromPoint:position];
  77.     [myWindow makeKeyAndOrderFront:self];
  78. }
  79.  
  80. /* Window delegate methods */
  81. - (void)windowWillClose:(NSNotification *)note
  82. {
  83.     [myWindow setDelegate:nil];
  84.         // Our window is closing. Time for us to go, too.
  85.     [self release];
  86. }
  87.  
  88. @end
  89.